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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 // pp::Buffer_Dev. | 26 // pp::Buffer_Dev. |
27 // 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. |
28 // 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, |
29 // pp::Buffer_Dev and PPB_Buffer_Dev. | 29 // pp::Buffer_Dev and PPB_Buffer_Dev. |
30 class PpbBuffer : public cdm::Buffer { | 30 class PpbBuffer : public cdm::Buffer { |
31 public: | 31 public: |
32 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, |
33 PpbBufferAllocator* allocator); | 33 PpbBufferAllocator* allocator); |
34 | 34 |
35 // cdm::Buffer implementation. | 35 // cdm::Buffer implementation. |
36 virtual void Destroy() override; | 36 void Destroy() override; |
37 virtual uint32_t Capacity() const override; | 37 uint32_t Capacity() const override; |
38 virtual uint8_t* Data() override; | 38 uint8_t* Data() override; |
39 virtual void SetSize(uint32_t size) override; | 39 void SetSize(uint32_t size) override; |
40 virtual uint32_t Size() const override { return size_; } | 40 uint32_t Size() const override { return size_; } |
41 | 41 |
42 // Takes the |buffer_| from this class and returns it. | 42 // Takes the |buffer_| from this class and returns it. |
43 // Note: The caller must ensure |allocator->Release()| is called later so that | 43 // Note: The caller must ensure |allocator->Release()| is called later so that |
44 // the buffer can be reused by the allocator. | 44 // the buffer can be reused by the allocator. |
45 // Since pp::Buffer_Dev is ref-counted, the caller now holds one reference to | 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 | 46 // the buffer and this class holds no reference. Note that other references |
47 // may still exist. For example, PpbBufferAllocator always holds a reference | 47 // may still exist. For example, PpbBufferAllocator always holds a reference |
48 // to all allocated buffers. | 48 // to all allocated buffers. |
49 pp::Buffer_Dev TakeBuffer(); | 49 pp::Buffer_Dev TakeBuffer(); |
50 | 50 |
51 uint32_t buffer_id() const { return buffer_id_; } | 51 uint32_t buffer_id() const { return buffer_id_; } |
52 | 52 |
53 private: | 53 private: |
54 PpbBuffer(pp::Buffer_Dev buffer, | 54 PpbBuffer(pp::Buffer_Dev buffer, |
55 uint32_t buffer_id, | 55 uint32_t buffer_id, |
56 PpbBufferAllocator* allocator); | 56 PpbBufferAllocator* allocator); |
57 virtual ~PpbBuffer(); | 57 ~PpbBuffer() override; |
58 | 58 |
59 pp::Buffer_Dev buffer_; | 59 pp::Buffer_Dev buffer_; |
60 uint32_t buffer_id_; | 60 uint32_t buffer_id_; |
61 uint32_t size_; | 61 uint32_t size_; |
62 PpbBufferAllocator* allocator_; | 62 PpbBufferAllocator* allocator_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); | 64 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); |
65 }; | 65 }; |
66 | 66 |
67 class PpbBufferAllocator { | 67 class PpbBufferAllocator { |
(...skipping 20 matching lines...) Expand all Loading... |
88 uint32_t next_buffer_id_; | 88 uint32_t next_buffer_id_; |
89 AllocatedBufferMap allocated_buffers_; | 89 AllocatedBufferMap allocated_buffers_; |
90 FreeBufferMap free_buffers_; | 90 FreeBufferMap free_buffers_; |
91 | 91 |
92 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); | 92 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); |
93 }; | 93 }; |
94 | 94 |
95 class DecryptedBlockImpl : public cdm::DecryptedBlock { | 95 class DecryptedBlockImpl : public cdm::DecryptedBlock { |
96 public: | 96 public: |
97 DecryptedBlockImpl() : buffer_(NULL), timestamp_(0) {} | 97 DecryptedBlockImpl() : buffer_(NULL), timestamp_(0) {} |
98 virtual ~DecryptedBlockImpl() { if (buffer_) buffer_->Destroy(); } | 98 ~DecryptedBlockImpl() override { |
| 99 if (buffer_) |
| 100 buffer_->Destroy(); |
| 101 } |
99 | 102 |
100 virtual void SetDecryptedBuffer(cdm::Buffer* buffer) override { | 103 void SetDecryptedBuffer(cdm::Buffer* buffer) override { |
101 buffer_ = static_cast<PpbBuffer*>(buffer); | 104 buffer_ = static_cast<PpbBuffer*>(buffer); |
102 } | 105 } |
103 virtual cdm::Buffer* DecryptedBuffer() override { return buffer_; } | 106 cdm::Buffer* DecryptedBuffer() override { return buffer_; } |
104 | 107 |
105 virtual void SetTimestamp(int64_t timestamp) override { | 108 void SetTimestamp(int64_t timestamp) override { |
106 timestamp_ = timestamp; | 109 timestamp_ = timestamp; |
107 } | 110 } |
108 virtual int64_t Timestamp() const override { return timestamp_; } | 111 int64_t Timestamp() const override { return timestamp_; } |
109 | 112 |
110 private: | 113 private: |
111 PpbBuffer* buffer_; | 114 PpbBuffer* buffer_; |
112 int64_t timestamp_; | 115 int64_t timestamp_; |
113 | 116 |
114 DISALLOW_COPY_AND_ASSIGN(DecryptedBlockImpl); | 117 DISALLOW_COPY_AND_ASSIGN(DecryptedBlockImpl); |
115 }; | 118 }; |
116 | 119 |
117 class VideoFrameImpl : public cdm::VideoFrame { | 120 class VideoFrameImpl : public cdm::VideoFrame { |
118 public: | 121 public: |
119 VideoFrameImpl(); | 122 VideoFrameImpl(); |
120 virtual ~VideoFrameImpl(); | 123 ~VideoFrameImpl() override; |
121 | 124 |
122 virtual void SetFormat(cdm::VideoFormat format) override { | 125 void SetFormat(cdm::VideoFormat format) override { |
123 format_ = format; | 126 format_ = format; |
124 } | 127 } |
125 virtual cdm::VideoFormat Format() const override { return format_; } | 128 cdm::VideoFormat Format() const override { return format_; } |
126 | 129 |
127 virtual void SetSize(cdm::Size size) override { size_ = size; } | 130 void SetSize(cdm::Size size) override { size_ = size; } |
128 virtual cdm::Size Size() const override { return size_; } | 131 cdm::Size Size() const override { return size_; } |
129 | 132 |
130 virtual void SetFrameBuffer(cdm::Buffer* frame_buffer) override { | 133 void SetFrameBuffer(cdm::Buffer* frame_buffer) override { |
131 frame_buffer_ = static_cast<PpbBuffer*>(frame_buffer); | 134 frame_buffer_ = static_cast<PpbBuffer*>(frame_buffer); |
132 } | 135 } |
133 virtual cdm::Buffer* FrameBuffer() override { return frame_buffer_; } | 136 cdm::Buffer* FrameBuffer() override { return frame_buffer_; } |
134 | 137 |
135 virtual void SetPlaneOffset(cdm::VideoFrame::VideoPlane plane, | 138 void SetPlaneOffset(cdm::VideoFrame::VideoPlane plane, |
136 uint32_t offset) override { | 139 uint32_t offset) override { |
137 PP_DCHECK(plane < kMaxPlanes); | 140 PP_DCHECK(plane < kMaxPlanes); |
138 plane_offsets_[plane] = offset; | 141 plane_offsets_[plane] = offset; |
139 } | 142 } |
140 virtual uint32_t PlaneOffset(VideoPlane plane) override { | 143 uint32_t PlaneOffset(VideoPlane plane) override { |
141 PP_DCHECK(plane < kMaxPlanes); | 144 PP_DCHECK(plane < kMaxPlanes); |
142 return plane_offsets_[plane]; | 145 return plane_offsets_[plane]; |
143 } | 146 } |
144 | 147 |
145 virtual void SetStride(VideoPlane plane, uint32_t stride) override { | 148 void SetStride(VideoPlane plane, uint32_t stride) override { |
146 PP_DCHECK(plane < kMaxPlanes); | 149 PP_DCHECK(plane < kMaxPlanes); |
147 strides_[plane] = stride; | 150 strides_[plane] = stride; |
148 } | 151 } |
149 virtual uint32_t Stride(VideoPlane plane) override { | 152 uint32_t Stride(VideoPlane plane) override { |
150 PP_DCHECK(plane < kMaxPlanes); | 153 PP_DCHECK(plane < kMaxPlanes); |
151 return strides_[plane]; | 154 return strides_[plane]; |
152 } | 155 } |
153 | 156 |
154 virtual void SetTimestamp(int64_t timestamp) override { | 157 void SetTimestamp(int64_t timestamp) override { |
155 timestamp_ = timestamp; | 158 timestamp_ = timestamp; |
156 } | 159 } |
157 virtual int64_t Timestamp() const override { return timestamp_; } | 160 int64_t Timestamp() const override { return timestamp_; } |
158 | 161 |
159 private: | 162 private: |
160 // The video buffer format. | 163 // The video buffer format. |
161 cdm::VideoFormat format_; | 164 cdm::VideoFormat format_; |
162 | 165 |
163 // Width and height of the video frame. | 166 // Width and height of the video frame. |
164 cdm::Size size_; | 167 cdm::Size size_; |
165 | 168 |
166 // The video frame buffer. | 169 // The video frame buffer. |
167 PpbBuffer* frame_buffer_; | 170 PpbBuffer* frame_buffer_; |
168 | 171 |
169 // Array of data pointers to each plane in the video frame buffer. | 172 // Array of data pointers to each plane in the video frame buffer. |
170 uint32_t plane_offsets_[kMaxPlanes]; | 173 uint32_t plane_offsets_[kMaxPlanes]; |
171 | 174 |
172 // Array of strides for each plane, typically greater or equal to the width | 175 // Array of strides for each plane, typically greater or equal to the width |
173 // of the surface divided by the horizontal sampling period. Note that | 176 // of the surface divided by the horizontal sampling period. Note that |
174 // strides can be negative. | 177 // strides can be negative. |
175 uint32_t strides_[kMaxPlanes]; | 178 uint32_t strides_[kMaxPlanes]; |
176 | 179 |
177 // Presentation timestamp in microseconds. | 180 // Presentation timestamp in microseconds. |
178 int64_t timestamp_; | 181 int64_t timestamp_; |
179 | 182 |
180 DISALLOW_COPY_AND_ASSIGN(VideoFrameImpl); | 183 DISALLOW_COPY_AND_ASSIGN(VideoFrameImpl); |
181 }; | 184 }; |
182 | 185 |
183 class AudioFramesImpl : public cdm::AudioFrames { | 186 class AudioFramesImpl : public cdm::AudioFrames { |
184 public: | 187 public: |
185 AudioFramesImpl() : buffer_(NULL), format_(cdm::kUnknownAudioFormat) {} | 188 AudioFramesImpl() : buffer_(NULL), format_(cdm::kUnknownAudioFormat) {} |
186 virtual ~AudioFramesImpl() { | 189 ~AudioFramesImpl() override { |
187 if (buffer_) | 190 if (buffer_) |
188 buffer_->Destroy(); | 191 buffer_->Destroy(); |
189 } | 192 } |
190 | 193 |
191 // AudioFrames implementation. | 194 // AudioFrames implementation. |
192 virtual void SetFrameBuffer(cdm::Buffer* buffer) override { | 195 void SetFrameBuffer(cdm::Buffer* buffer) override { |
193 buffer_ = static_cast<PpbBuffer*>(buffer); | 196 buffer_ = static_cast<PpbBuffer*>(buffer); |
194 } | 197 } |
195 virtual cdm::Buffer* FrameBuffer() override { | 198 cdm::Buffer* FrameBuffer() override { |
196 return buffer_; | 199 return buffer_; |
197 } | 200 } |
198 virtual void SetFormat(cdm::AudioFormat format) override { | 201 void SetFormat(cdm::AudioFormat format) override { |
199 format_ = format; | 202 format_ = format; |
200 } | 203 } |
201 virtual cdm::AudioFormat Format() const override { | 204 cdm::AudioFormat Format() const override { |
202 return format_; | 205 return format_; |
203 } | 206 } |
204 | 207 |
205 cdm::Buffer* PassFrameBuffer() { | 208 cdm::Buffer* PassFrameBuffer() { |
206 PpbBuffer* temp_buffer = buffer_; | 209 PpbBuffer* temp_buffer = buffer_; |
207 buffer_ = NULL; | 210 buffer_ = NULL; |
208 return temp_buffer; | 211 return temp_buffer; |
209 } | 212 } |
210 | 213 |
211 private: | 214 private: |
212 PpbBuffer* buffer_; | 215 PpbBuffer* buffer_; |
213 cdm::AudioFormat format_; | 216 cdm::AudioFormat format_; |
214 | 217 |
215 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); | 218 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); |
216 }; | 219 }; |
217 | 220 |
218 } // namespace media | 221 } // namespace media |
219 | 222 |
220 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ | 223 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ |
OLD | NEW |