Chromium Code Reviews| 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); |
|
ddorwin
2014/07/10 21:56:14
Minor issue, but it seems odd that the buffer (wra
xhwang
2014/07/10 22:37:33
We can't use base::Callback here and to pass a fun
| |
| 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; |
|
ddorwin
2014/07/10 21:56:14
unrelated nit: These should be GetCapacity() and G
xhwang
2014/07/10 22:37:33
This is in the CDM interface and we can update the
| |
| 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 ownership of |buffer_| and returns it. The caller makes sure |
|
ddorwin
2014/07/10 21:56:14
The caller must ensure... ?
xhwang
2014/07/10 22:37:33
Done.
| |
| 43 // |allocator->Release()| is called later so that the buffer can be reused in | |
| 44 // the allocator. | |
|
ddorwin
2014/07/10 21:56:14
As discussed offline, it's really taking ownership
xhwang
2014/07/10 22:37:33
Done.
| |
| 45 pp::Buffer_Dev TakeBufferDev(); | |
| 59 | 46 |
| 60 uint32_t buffer_id() const { return buffer_id_; } | 47 uint32_t buffer_id() const { return buffer_id_; } |
| 61 | 48 |
| 62 private: | 49 private: |
| 63 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) | 50 PpbBuffer(pp::Buffer_Dev buffer, |
| 64 : buffer_(buffer), | 51 uint32_t buffer_id, |
| 65 buffer_id_(buffer_id), | 52 PpbBufferAllocator* allocator); |
| 66 size_(0) {} | 53 virtual ~PpbBuffer(); |
| 67 virtual ~PpbBuffer() {} | |
| 68 | 54 |
| 69 pp::Buffer_Dev buffer_; | 55 pp::Buffer_Dev buffer_; |
| 70 uint32_t buffer_id_; | 56 uint32_t buffer_id_; |
| 71 uint32_t size_; | 57 uint32_t size_; |
| 58 PpbBufferAllocator* allocator_; | |
| 72 | 59 |
| 73 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); | 60 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); |
| 74 }; | 61 }; |
| 75 | 62 |
| 76 class PpbBufferAllocator { | 63 class PpbBufferAllocator { |
| 77 public: | 64 public: |
| 78 explicit PpbBufferAllocator(pp::Instance* instance) | 65 explicit PpbBufferAllocator(pp::Instance* instance) |
| 79 : instance_(instance), | 66 : instance_(instance), |
| 80 next_buffer_id_(1) {} | 67 next_buffer_id_(1) {} |
| 81 ~PpbBufferAllocator() {} | 68 ~PpbBufferAllocator() {} |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 private: | 207 private: |
| 221 PpbBuffer* buffer_; | 208 PpbBuffer* buffer_; |
| 222 cdm::AudioFormat format_; | 209 cdm::AudioFormat format_; |
| 223 | 210 |
| 224 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); | 211 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); |
| 225 }; | 212 }; |
| 226 | 213 |
| 227 } // namespace media | 214 } // namespace media |
| 228 | 215 |
| 229 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ | 216 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ |
| OLD | NEW |