OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CDM_PPAPI_CDM_HELPERS_H_ | 5 #ifndef MEDIA_CDM_PPAPI_CDM_HELPERS_H_ |
6 #define MEDIA_CDM_PPAPI_CDM_HELPERS_H_ | 6 #define MEDIA_CDM_PPAPI_CDM_HELPERS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "media/cdm/ppapi/api/content_decryption_module.h" | 14 #include "media/cdm/ppapi/api/content_decryption_module.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/pp_stdint.h" | 16 #include "ppapi/c/pp_stdint.h" |
17 #include "ppapi/cpp/dev/buffer_dev.h" | 17 #include "ppapi/cpp/dev/buffer_dev.h" |
18 #include "ppapi/cpp/instance.h" | 18 #include "ppapi/cpp/instance.h" |
19 #include "ppapi/cpp/logging.h" | 19 #include "ppapi/cpp/logging.h" |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class PpbBufferAllocator; | |
24 | |
23 // cdm::Buffer implementation that provides access to memory owned by a | 25 // cdm::Buffer implementation that provides access to memory owned by a |
24 // pp::Buffer_Dev. | 26 // pp::Buffer_Dev. |
25 // This class holds a reference to the Buffer_Dev throughout its lifetime. | 27 // This class holds a reference to the Buffer_Dev throughout its lifetime. |
26 // TODO(xhwang): Find a better name. It's confusing to have PpbBuffer, | 28 // TODO(xhwang): Find a better name. It's confusing to have PpbBuffer, |
27 // pp::Buffer_Dev and PPB_Buffer_Dev. | 29 // pp::Buffer_Dev and PPB_Buffer_Dev. |
28 class PpbBuffer : public cdm::Buffer { | 30 class PpbBuffer : public cdm::Buffer { |
29 public: | 31 public: |
30 static PpbBuffer* Create(const pp::Buffer_Dev& buffer, uint32_t buffer_id) { | 32 static PpbBuffer* Create(const pp::Buffer_Dev& buffer, uint32_t buffer_id, |
31 PP_DCHECK(buffer.data()); | 33 PpbBufferAllocator* allocator); |
32 PP_DCHECK(buffer.size()); | |
33 PP_DCHECK(buffer_id); | |
34 return new PpbBuffer(buffer, buffer_id); | |
35 } | |
36 | 34 |
37 // cdm::Buffer implementation. | 35 // cdm::Buffer implementation. |
38 virtual void Destroy() OVERRIDE { delete this; } | 36 virtual void Destroy() OVERRIDE; |
39 | 37 virtual uint32_t Capacity() const OVERRIDE; |
40 virtual uint32_t Capacity() const OVERRIDE { return buffer_.size(); } | 38 virtual uint8_t* Data() OVERRIDE; |
41 | 39 virtual void SetSize(uint32_t size) OVERRIDE; |
42 virtual uint8_t* Data() OVERRIDE { | |
43 return static_cast<uint8_t*>(buffer_.data()); | |
44 } | |
45 | |
46 virtual void SetSize(uint32_t size) OVERRIDE { | |
47 PP_DCHECK(size <= Capacity()); | |
48 if (size > Capacity()) { | |
49 size_ = 0; | |
50 return; | |
51 } | |
52 | |
53 size_ = size; | |
54 } | |
55 | |
56 virtual uint32_t Size() const OVERRIDE { return size_; } | 40 virtual uint32_t Size() const OVERRIDE { return size_; } |
57 | 41 |
58 pp::Buffer_Dev buffer_dev() const { return buffer_; } | 42 // Takes the |buffer_| from this class and returns it. Since pp::Buffer_Dev is |
43 // ref-counted, the caller now holds one reference to the buffer and this | |
44 // class holds no reference. Note that other references may still exist. For | |
45 // example, PpbBufferAllocator always holds a reference to all allocated | |
46 // buffers. The caller must ensure |allocator->Release()| is called later so | |
ddorwin
2014/07/10 22:43:24
nit: Move this last sentence after the first one a
xhwang
2014/07/10 22:48:50
Done.
| |
47 // that the buffer can be reused by the allocator. | |
48 pp::Buffer_Dev TakeBuffer(); | |
59 | 49 |
60 uint32_t buffer_id() const { return buffer_id_; } | 50 uint32_t buffer_id() const { return buffer_id_; } |
61 | 51 |
62 private: | 52 private: |
63 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) | 53 PpbBuffer(pp::Buffer_Dev buffer, |
64 : buffer_(buffer), | 54 uint32_t buffer_id, |
65 buffer_id_(buffer_id), | 55 PpbBufferAllocator* allocator); |
66 size_(0) {} | 56 virtual ~PpbBuffer(); |
67 virtual ~PpbBuffer() {} | |
68 | 57 |
69 pp::Buffer_Dev buffer_; | 58 pp::Buffer_Dev buffer_; |
70 uint32_t buffer_id_; | 59 uint32_t buffer_id_; |
71 uint32_t size_; | 60 uint32_t size_; |
61 PpbBufferAllocator* allocator_; | |
72 | 62 |
73 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); | 63 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); |
74 }; | 64 }; |
75 | 65 |
76 class PpbBufferAllocator { | 66 class PpbBufferAllocator { |
77 public: | 67 public: |
78 explicit PpbBufferAllocator(pp::Instance* instance) | 68 explicit PpbBufferAllocator(pp::Instance* instance) |
79 : instance_(instance), | 69 : instance_(instance), |
80 next_buffer_id_(1) {} | 70 next_buffer_id_(1) {} |
81 ~PpbBufferAllocator() {} | 71 ~PpbBufferAllocator() {} |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 private: | 210 private: |
221 PpbBuffer* buffer_; | 211 PpbBuffer* buffer_; |
222 cdm::AudioFormat format_; | 212 cdm::AudioFormat format_; |
223 | 213 |
224 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); | 214 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); |
225 }; | 215 }; |
226 | 216 |
227 } // namespace media | 217 } // namespace media |
228 | 218 |
229 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ | 219 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ |
OLD | NEW |