OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_ALLOCATOR_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_ALLOCATOR_H_ |
6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_ALLOCATOR_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_CDM_ALLOCATOR_H_ |
7 | 7 |
| 8 #include <stddef.h> |
8 #include <stdint.h> | 9 #include <stdint.h> |
9 | 10 |
10 #include <map> | 11 #include <map> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
15 #include "media/cdm/cdm_allocator.h" | 16 #include "media/cdm/cdm_allocator.h" |
16 #include "mojo/public/cpp/system/buffer.h" | 17 #include "mojo/public/cpp/system/buffer.h" |
17 | 18 |
18 namespace media { | 19 namespace media { |
19 | 20 |
20 // This is a CdmAllocator that creates buffers using mojo shared memory. | 21 // This is a CdmAllocator that creates buffers using mojo shared memory. |
21 // The internal logic is similar to ppapi_cdm_buffer.cc. | 22 // The internal logic is similar to ppapi_cdm_buffer.cc. |
22 class MojoCdmAllocator : public CdmAllocator { | 23 class MojoCdmAllocator : public CdmAllocator { |
23 public: | 24 public: |
24 MojoCdmAllocator(); | 25 MojoCdmAllocator(); |
25 ~MojoCdmAllocator() final; | 26 ~MojoCdmAllocator() final; |
26 | 27 |
27 // CdmAllocator implementation. | 28 // CdmAllocator implementation. |
28 cdm::Buffer* CreateCdmBuffer(uint32_t capacity) final; | 29 cdm::Buffer* CreateCdmBuffer(size_t capacity) final; |
29 scoped_ptr<VideoFrameImpl> CreateCdmVideoFrame() final; | 30 scoped_ptr<VideoFrameImpl> CreateCdmVideoFrame() final; |
30 | 31 |
31 private: | 32 private: |
32 friend class MojoCdmAllocatorTest; | 33 friend class MojoCdmAllocatorTest; |
33 | 34 |
34 // Map of available buffers. Done as a mapping of capacity to | 35 // Map of available buffers. Done as a mapping of capacity to |
35 // ScopedSharedBufferHandle so that we can efficiently find an available | 36 // ScopedSharedBufferHandle so that we can efficiently find an available |
36 // buffer of a particular size. Any buffers in the map are unmapped. | 37 // buffer of a particular size. Any buffers in the map are unmapped. |
37 using AvailableBufferMap = | 38 using AvailableBufferMap = |
38 std::multimap<uint32_t, mojo::ScopedSharedBufferHandle>; | 39 std::multimap<size_t, mojo::ScopedSharedBufferHandle>; |
39 | 40 |
40 // Allocates a mojo::SharedBufferHandle of at least |capacity| bytes. | 41 // Allocates a mojo::SharedBufferHandle of at least |capacity| bytes. |
41 // |capacity| will be changed to reflect the actual size of the buffer | 42 // |capacity| will be changed to reflect the actual size of the buffer |
42 // allocated. | 43 // allocated. |
43 mojo::ScopedSharedBufferHandle AllocateNewBuffer(uint32_t* capacity); | 44 mojo::ScopedSharedBufferHandle AllocateNewBuffer(size_t* capacity); |
44 | 45 |
45 // Returns |buffer| to the map of available buffers, ready to be used the | 46 // Returns |buffer| to the map of available buffers, ready to be used the |
46 // next time CreateCdmBuffer() is called. | 47 // next time CreateCdmBuffer() is called. |
47 void AddBufferToAvailableMap(mojo::ScopedSharedBufferHandle buffer, | 48 void AddBufferToAvailableMap(mojo::ScopedSharedBufferHandle buffer, |
48 uint32_t capacity); | 49 size_t capacity); |
49 | 50 |
50 // Returns the MojoHandle for a cdm::Buffer allocated by this class. | 51 // Returns the MojoHandle for a cdm::Buffer allocated by this class. |
51 MojoHandle GetHandleForTesting(cdm::Buffer* buffer); | 52 MojoHandle GetHandleForTesting(cdm::Buffer* buffer); |
52 | 53 |
53 // Returns the number of buffers in |available_buffers_|. | 54 // Returns the number of buffers in |available_buffers_|. |
54 size_t GetAvailableBufferCountForTesting(); | 55 size_t GetAvailableBufferCountForTesting(); |
55 | 56 |
56 // Map of available, already allocated buffers. | 57 // Map of available, already allocated buffers. |
57 AvailableBufferMap available_buffers_; | 58 AvailableBufferMap available_buffers_; |
58 | 59 |
59 // Confirms single-threaded access. | 60 // Confirms single-threaded access. |
60 base::ThreadChecker thread_checker_; | 61 base::ThreadChecker thread_checker_; |
61 | 62 |
62 // NOTE: Weak pointers must be invalidated before all other member variables. | 63 // NOTE: Weak pointers must be invalidated before all other member variables. |
63 base::WeakPtrFactory<MojoCdmAllocator> weak_ptr_factory_; | 64 base::WeakPtrFactory<MojoCdmAllocator> weak_ptr_factory_; |
64 | 65 |
65 DISALLOW_COPY_AND_ASSIGN(MojoCdmAllocator); | 66 DISALLOW_COPY_AND_ASSIGN(MojoCdmAllocator); |
66 }; | 67 }; |
67 | 68 |
68 } // namespace media | 69 } // namespace media |
69 | 70 |
70 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_ALLOCATOR_H_ | 71 #endif // MEDIA_MOJO_SERVICES_MOJO_CDM_ALLOCATOR_H_ |
OLD | NEW |