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 19 matching lines...) Expand all Loading... |
30 static PpbBuffer* Create(const pp::Buffer_Dev& buffer, uint32_t buffer_id) { | 30 static PpbBuffer* Create(const pp::Buffer_Dev& buffer, uint32_t buffer_id) { |
31 PP_DCHECK(buffer.data()); | 31 PP_DCHECK(buffer.data()); |
32 PP_DCHECK(buffer.size()); | 32 PP_DCHECK(buffer.size()); |
33 PP_DCHECK(buffer_id); | 33 PP_DCHECK(buffer_id); |
34 return new PpbBuffer(buffer, buffer_id); | 34 return new PpbBuffer(buffer, buffer_id); |
35 } | 35 } |
36 | 36 |
37 // cdm::Buffer implementation. | 37 // cdm::Buffer implementation. |
38 virtual void Destroy() OVERRIDE { delete this; } | 38 virtual void Destroy() OVERRIDE { delete this; } |
39 | 39 |
40 virtual int32_t Capacity() const OVERRIDE { return buffer_.size(); } | 40 virtual uint32_t Capacity() const OVERRIDE { return buffer_.size(); } |
41 | 41 |
42 virtual uint8_t* Data() OVERRIDE { | 42 virtual uint8_t* Data() OVERRIDE { |
43 return static_cast<uint8_t*>(buffer_.data()); | 43 return static_cast<uint8_t*>(buffer_.data()); |
44 } | 44 } |
45 | 45 |
46 virtual void SetSize(int32_t size) OVERRIDE { | 46 virtual void SetSize(uint32_t size) OVERRIDE { |
47 PP_DCHECK(size >= 0); | |
48 PP_DCHECK(size < Capacity()); | 47 PP_DCHECK(size < Capacity()); |
49 if (size < 0 || size > Capacity()) { | 48 if (size > Capacity()) { |
50 size_ = 0; | 49 size_ = 0; |
51 return; | 50 return; |
52 } | 51 } |
53 | 52 |
54 size_ = size; | 53 size_ = size; |
55 } | 54 } |
56 | 55 |
57 virtual int32_t Size() const OVERRIDE { return size_; } | 56 virtual uint32_t Size() const OVERRIDE { return size_; } |
58 | 57 |
59 pp::Buffer_Dev buffer_dev() const { return buffer_; } | 58 pp::Buffer_Dev buffer_dev() const { return buffer_; } |
60 | 59 |
61 uint32_t buffer_id() const { return buffer_id_; } | 60 uint32_t buffer_id() const { return buffer_id_; } |
62 | 61 |
63 private: | 62 private: |
64 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) | 63 PpbBuffer(pp::Buffer_Dev buffer, uint32_t buffer_id) |
65 : buffer_(buffer), | 64 : buffer_(buffer), |
66 buffer_id_(buffer_id), | 65 buffer_id_(buffer_id), |
67 size_(0) {} | 66 size_(0) {} |
68 virtual ~PpbBuffer() {} | 67 virtual ~PpbBuffer() {} |
69 | 68 |
70 pp::Buffer_Dev buffer_; | 69 pp::Buffer_Dev buffer_; |
71 uint32_t buffer_id_; | 70 uint32_t buffer_id_; |
72 int32_t size_; | 71 uint32_t size_; |
73 | 72 |
74 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); | 73 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); |
75 }; | 74 }; |
76 | 75 |
77 class PpbBufferAllocator { | 76 class PpbBufferAllocator { |
78 public: | 77 public: |
79 explicit PpbBufferAllocator(pp::Instance* instance) | 78 explicit PpbBufferAllocator(pp::Instance* instance) |
80 : instance_(instance), | 79 : instance_(instance), |
81 next_buffer_id_(1) {} | 80 next_buffer_id_(1) {} |
82 ~PpbBufferAllocator() {} | 81 ~PpbBufferAllocator() {} |
83 | 82 |
84 cdm::Buffer* Allocate(int32_t capacity); | 83 cdm::Buffer* Allocate(uint32_t capacity); |
85 | 84 |
86 // Releases the buffer with |buffer_id|. A buffer can be recycled after | 85 // Releases the buffer with |buffer_id|. A buffer can be recycled after |
87 // it is released. | 86 // it is released. |
88 void Release(uint32_t buffer_id); | 87 void Release(uint32_t buffer_id); |
89 | 88 |
90 private: | 89 private: |
91 typedef std::map<uint32_t, pp::Buffer_Dev> AllocatedBufferMap; | 90 typedef std::map<uint32_t, pp::Buffer_Dev> AllocatedBufferMap; |
92 typedef std::multimap<int, std::pair<uint32_t, pp::Buffer_Dev> > | 91 typedef std::multimap<uint32_t, std::pair<uint32_t, pp::Buffer_Dev> > |
93 FreeBufferMap; | 92 FreeBufferMap; |
94 | 93 |
95 pp::Buffer_Dev AllocateNewBuffer(int capacity); | 94 pp::Buffer_Dev AllocateNewBuffer(uint32_t capacity); |
96 | 95 |
97 pp::Instance* const instance_; | 96 pp::Instance* const instance_; |
98 uint32_t next_buffer_id_; | 97 uint32_t next_buffer_id_; |
99 AllocatedBufferMap allocated_buffers_; | 98 AllocatedBufferMap allocated_buffers_; |
100 FreeBufferMap free_buffers_; | 99 FreeBufferMap free_buffers_; |
101 | 100 |
102 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); | 101 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); |
103 }; | 102 }; |
104 | 103 |
105 class DecryptedBlockImpl : public cdm::DecryptedBlock { | 104 class DecryptedBlockImpl : public cdm::DecryptedBlock { |
(...skipping 30 matching lines...) Expand all Loading... |
136 | 135 |
137 virtual void SetSize(cdm::Size size) OVERRIDE { size_ = size; } | 136 virtual void SetSize(cdm::Size size) OVERRIDE { size_ = size; } |
138 virtual cdm::Size Size() const OVERRIDE { return size_; } | 137 virtual cdm::Size Size() const OVERRIDE { return size_; } |
139 | 138 |
140 virtual void SetFrameBuffer(cdm::Buffer* frame_buffer) OVERRIDE { | 139 virtual void SetFrameBuffer(cdm::Buffer* frame_buffer) OVERRIDE { |
141 frame_buffer_ = static_cast<PpbBuffer*>(frame_buffer); | 140 frame_buffer_ = static_cast<PpbBuffer*>(frame_buffer); |
142 } | 141 } |
143 virtual cdm::Buffer* FrameBuffer() OVERRIDE { return frame_buffer_; } | 142 virtual cdm::Buffer* FrameBuffer() OVERRIDE { return frame_buffer_; } |
144 | 143 |
145 virtual void SetPlaneOffset(cdm::VideoFrame::VideoPlane plane, | 144 virtual void SetPlaneOffset(cdm::VideoFrame::VideoPlane plane, |
146 int32_t offset) OVERRIDE { | 145 uint32_t offset) OVERRIDE { |
147 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 146 PP_DCHECK(plane < kMaxPlanes); |
148 PP_DCHECK(offset >= 0); | |
149 plane_offsets_[plane] = offset; | 147 plane_offsets_[plane] = offset; |
150 } | 148 } |
151 virtual int32_t PlaneOffset(VideoPlane plane) OVERRIDE { | 149 virtual uint32_t PlaneOffset(VideoPlane plane) OVERRIDE { |
152 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 150 PP_DCHECK(plane < kMaxPlanes); |
153 return plane_offsets_[plane]; | 151 return plane_offsets_[plane]; |
154 } | 152 } |
155 | 153 |
156 virtual void SetStride(VideoPlane plane, int32_t stride) OVERRIDE { | 154 virtual void SetStride(VideoPlane plane, uint32_t stride) OVERRIDE { |
157 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 155 PP_DCHECK(plane < kMaxPlanes); |
158 strides_[plane] = stride; | 156 strides_[plane] = stride; |
159 } | 157 } |
160 virtual int32_t Stride(VideoPlane plane) OVERRIDE { | 158 virtual uint32_t Stride(VideoPlane plane) OVERRIDE { |
161 PP_DCHECK(0 <= plane && plane < kMaxPlanes); | 159 PP_DCHECK(plane < kMaxPlanes); |
162 return strides_[plane]; | 160 return strides_[plane]; |
163 } | 161 } |
164 | 162 |
165 virtual void SetTimestamp(int64_t timestamp) OVERRIDE { | 163 virtual void SetTimestamp(int64_t timestamp) OVERRIDE { |
166 timestamp_ = timestamp; | 164 timestamp_ = timestamp; |
167 } | 165 } |
168 virtual int64_t Timestamp() const OVERRIDE { return timestamp_; } | 166 virtual int64_t Timestamp() const OVERRIDE { return timestamp_; } |
169 | 167 |
170 private: | 168 private: |
171 // The video buffer format. | 169 // The video buffer format. |
172 cdm::VideoFormat format_; | 170 cdm::VideoFormat format_; |
173 | 171 |
174 // Width and height of the video frame. | 172 // Width and height of the video frame. |
175 cdm::Size size_; | 173 cdm::Size size_; |
176 | 174 |
177 // The video frame buffer. | 175 // The video frame buffer. |
178 PpbBuffer* frame_buffer_; | 176 PpbBuffer* frame_buffer_; |
179 | 177 |
180 // Array of data pointers to each plane in the video frame buffer. | 178 // Array of data pointers to each plane in the video frame buffer. |
181 int32_t plane_offsets_[kMaxPlanes]; | 179 uint32_t plane_offsets_[kMaxPlanes]; |
182 | 180 |
183 // Array of strides for each plane, typically greater or equal to the width | 181 // Array of strides for each plane, typically greater or equal to the width |
184 // of the surface divided by the horizontal sampling period. Note that | 182 // of the surface divided by the horizontal sampling period. Note that |
185 // strides can be negative. | 183 // strides can be negative. |
186 int32_t strides_[kMaxPlanes]; | 184 uint32_t strides_[kMaxPlanes]; |
187 | 185 |
188 // Presentation timestamp in microseconds. | 186 // Presentation timestamp in microseconds. |
189 int64_t timestamp_; | 187 int64_t timestamp_; |
190 | 188 |
191 DISALLOW_COPY_AND_ASSIGN(VideoFrameImpl); | 189 DISALLOW_COPY_AND_ASSIGN(VideoFrameImpl); |
192 }; | 190 }; |
193 | 191 |
194 class AudioFramesImpl : public cdm::AudioFrames_1, | 192 class AudioFramesImpl : public cdm::AudioFrames_1, |
195 public cdm::AudioFrames_2 { | 193 public cdm::AudioFrames_2 { |
196 public: | 194 public: |
(...skipping 26 matching lines...) Expand all Loading... |
223 private: | 221 private: |
224 PpbBuffer* buffer_; | 222 PpbBuffer* buffer_; |
225 cdm::AudioFormat format_; | 223 cdm::AudioFormat format_; |
226 | 224 |
227 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); | 225 DISALLOW_COPY_AND_ASSIGN(AudioFramesImpl); |
228 }; | 226 }; |
229 | 227 |
230 } // namespace media | 228 } // namespace media |
231 | 229 |
232 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ | 230 #endif // MEDIA_CDM_PPAPI_CDM_HELPERS_H_ |
OLD | NEW |