Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(899)

Side by Side Diff: media/cdm/ppapi/cdm_helpers.h

Issue 374353004: Encrypted Media: Fix PpbBuffer::Destroy(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/cdm/ppapi/cdm_adapter.cc ('k') | media/cdm/ppapi/cdm_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
43 // Note: The caller must ensure |allocator->Release()| is called later so that
44 // the buffer can be reused by the allocator.
45 // Since pp::Buffer_Dev is ref-counted, the caller now holds one reference to
46 // the buffer and this class holds no reference. Note that other references
47 // may still exist. For example, PpbBufferAllocator always holds a reference
48 // to all allocated buffers.
49 pp::Buffer_Dev TakeBuffer();
59 50
60 uint32_t buffer_id() const { return buffer_id_; } 51 uint32_t buffer_id() const { return buffer_id_; }
61 52
62 private: 53 private:
63 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) 54 PpbBuffer(pp::Buffer_Dev buffer,
64 : buffer_(buffer), 55 uint32_t buffer_id,
65 buffer_id_(buffer_id), 56 PpbBufferAllocator* allocator);
66 size_(0) {} 57 virtual ~PpbBuffer();
67 virtual ~PpbBuffer() {}
68 58
69 pp::Buffer_Dev buffer_; 59 pp::Buffer_Dev buffer_;
70 uint32_t buffer_id_; 60 uint32_t buffer_id_;
71 uint32_t size_; 61 uint32_t size_;
62 PpbBufferAllocator* allocator_;
72 63
73 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); 64 DISALLOW_COPY_AND_ASSIGN(PpbBuffer);
74 }; 65 };
75 66
76 class PpbBufferAllocator { 67 class PpbBufferAllocator {
77 public: 68 public:
78 explicit PpbBufferAllocator(pp::Instance* instance) 69 explicit PpbBufferAllocator(pp::Instance* instance)
79 : instance_(instance), 70 : instance_(instance),
80 next_buffer_id_(1) {} 71 next_buffer_id_(1) {}
81 ~PpbBufferAllocator() {} 72 ~PpbBufferAllocator() {}
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 private: 211 private:
221 PpbBuffer* buffer_; 212 PpbBuffer* buffer_;
222 cdm::AudioFormat format_; 213 cdm::AudioFormat format_;
223 214
224 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); 215 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl);
225 }; 216 };
226 217
227 } // namespace media 218 } // namespace media
228 219
229 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ 220 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_
OLDNEW
« no previous file with comments | « media/cdm/ppapi/cdm_adapter.cc ('k') | media/cdm/ppapi/cdm_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698