OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "webkit/media/crypto/ppapi/libvpx_cdm_video_decoder.h" | 5 #include "webkit/media/crypto/ppapi/libvpx_cdm_video_decoder.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "media/base/buffers.h" | 9 #include "media/base/buffers.h" |
10 #include "media/base/limits.h" | 10 #include "media/base/limits.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "webkit/media/crypto/ppapi/cdm/content_decryption_module.h" | 21 #include "webkit/media/crypto/ppapi/cdm/content_decryption_module.h" |
22 | 22 |
23 // Enable USE_COPYPLANE_WITH_LIBVPX to use |CopyPlane()| instead of memcpy to | 23 // Enable USE_COPYPLANE_WITH_LIBVPX to use |CopyPlane()| instead of memcpy to |
24 // copy video frame data. | 24 // copy video frame data. |
25 // #define USE_COPYPLANE_WITH_LIBVPX 1 | 25 // #define USE_COPYPLANE_WITH_LIBVPX 1 |
26 | 26 |
27 namespace webkit_media { | 27 namespace webkit_media { |
28 | 28 |
29 static const int kDecodeThreads = 2; | 29 static const int kDecodeThreads = 2; |
30 | 30 |
31 #if defined(USE_COPYPLANE_WITH_LIBVPX) | |
32 static void CopyPlane(const uint8_t* source, | |
33 int32_t source_stride, | |
34 int32_t target_stride, | |
35 int32_t rows, | |
36 int32_t copy_bytes_per_row, | |
37 uint8_t* target) { | |
38 DCHECK(source); | |
39 DCHECK(target); | |
40 DCHECK_LE(copy_bytes_per_row, source_stride); | |
41 DCHECK_LE(copy_bytes_per_row, target_stride); | |
42 | |
43 for (int i = 0; i < rows; ++i) { | |
44 const int source_offset = i * source_stride; | |
45 const int target_offset = i * target_stride; | |
46 memcpy(target + target_offset, | |
47 source + source_offset, | |
48 copy_bytes_per_row); | |
49 } | |
50 } | |
51 #endif // USE_COPYPLANE_WITH_LIBVPX | |
52 | |
53 LibvpxCdmVideoDecoder::LibvpxCdmVideoDecoder(cdm::Host* host) | 31 LibvpxCdmVideoDecoder::LibvpxCdmVideoDecoder(cdm::Host* host) |
54 : is_initialized_(false), | 32 : is_initialized_(false), |
55 host_(host), | 33 host_(host), |
56 vpx_codec_(NULL), | 34 vpx_codec_(NULL), |
57 vpx_image_(NULL) { | 35 vpx_image_(NULL) { |
58 } | 36 } |
59 | 37 |
60 LibvpxCdmVideoDecoder::~LibvpxCdmVideoDecoder() { | 38 LibvpxCdmVideoDecoder::~LibvpxCdmVideoDecoder() { |
61 Deinitialize(); | 39 Deinitialize(); |
62 } | 40 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 140 |
163 return cdm::kSuccess; | 141 return cdm::kSuccess; |
164 } | 142 } |
165 | 143 |
166 bool LibvpxCdmVideoDecoder::CopyVpxImageTo(cdm::VideoFrame* cdm_video_frame) { | 144 bool LibvpxCdmVideoDecoder::CopyVpxImageTo(cdm::VideoFrame* cdm_video_frame) { |
167 DCHECK(cdm_video_frame); | 145 DCHECK(cdm_video_frame); |
168 DCHECK_EQ(vpx_image_->fmt, VPX_IMG_FMT_I420); | 146 DCHECK_EQ(vpx_image_->fmt, VPX_IMG_FMT_I420); |
169 DCHECK_EQ(vpx_image_->d_w % 2, 0U); | 147 DCHECK_EQ(vpx_image_->d_w % 2, 0U); |
170 DCHECK_EQ(vpx_image_->d_h % 2, 0U); | 148 DCHECK_EQ(vpx_image_->d_h % 2, 0U); |
171 | 149 |
172 #if defined(USE_COPYPLANE_WITH_LIBVPX) | |
173 const int y_size = vpx_image_->d_w * vpx_image_->d_h; | |
174 const int uv_size = y_size / 2; | |
175 const int space_required = y_size + (uv_size * 2); | |
176 | |
177 DCHECK(!cdm_video_frame->FrameBuffer()); | |
178 cdm_video_frame->SetFrameBuffer(host_->Allocate(space_required)); | |
179 if (!cdm_video_frame->FrameBuffer()) { | |
180 LOG(ERROR) << "CopyVpxImageTo() cdm::Host::Allocate failed."; | |
181 return false; | |
182 } | |
183 cdm_video_frame->FrameBuffer()->SetSize(space_required); | |
184 | |
185 CopyPlane(vpx_image_->planes[VPX_PLANE_Y], | |
186 vpx_image_->stride[VPX_PLANE_Y], | |
187 vpx_image_->d_w, | |
188 vpx_image_->d_h, | |
189 vpx_image_->d_w, | |
190 cdm_video_frame->FrameBuffer()->Data()); | |
191 | |
192 const int uv_stride = vpx_image_->d_w / 2; | |
193 const int uv_rows = vpx_image_->d_h / 2; | |
194 CopyPlane(vpx_image_->planes[VPX_PLANE_U], | |
195 vpx_image_->stride[VPX_PLANE_U], | |
196 uv_stride, | |
197 uv_rows, | |
198 uv_stride, | |
199 cdm_video_frame->FrameBuffer()->Data() + y_size); | |
200 | |
201 CopyPlane(vpx_image_->planes[VPX_PLANE_V], | |
202 vpx_image_->stride[VPX_PLANE_V], | |
203 uv_stride, | |
204 uv_rows, | |
205 uv_stride, | |
206 cdm_video_frame->FrameBuffer()->Data() + y_size + uv_size); | |
207 | |
208 cdm_video_frame->SetFormat(cdm::kYv12); | |
209 | |
210 cdm::Size video_frame_size; | |
211 video_frame_size.width = vpx_image_->d_w; | |
212 video_frame_size.height = vpx_image_->d_h; | |
213 cdm_video_frame->SetSize(video_frame_size); | |
214 | |
215 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kYPlane, 0); | |
216 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kUPlane, y_size); | |
217 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kVPlane, | |
218 y_size + uv_size); | |
219 | |
220 cdm_video_frame->SetStride(cdm::VideoFrame::kYPlane, vpx_image_->d_w); | |
221 cdm_video_frame->SetStride(cdm::VideoFrame::kUPlane, uv_stride); | |
222 cdm_video_frame->SetStride(cdm::VideoFrame::kVPlane, uv_stride); | |
223 #else | |
224 const int y_size = vpx_image_->stride[VPX_PLANE_Y] * vpx_image_->d_h; | 150 const int y_size = vpx_image_->stride[VPX_PLANE_Y] * vpx_image_->d_h; |
225 const int uv_rows = vpx_image_->d_h / 2; | 151 const int uv_rows = vpx_image_->d_h / 2; |
226 const int u_size = vpx_image_->stride[VPX_PLANE_U] * uv_rows; | 152 const int u_size = vpx_image_->stride[VPX_PLANE_U] * uv_rows; |
227 const int v_size = vpx_image_->stride[VPX_PLANE_V] * uv_rows; | 153 const int v_size = vpx_image_->stride[VPX_PLANE_V] * uv_rows; |
228 const int space_required = y_size + u_size + v_size; | 154 const int space_required = y_size + u_size + v_size; |
229 | 155 |
230 DCHECK(!cdm_video_frame->FrameBuffer()); | 156 DCHECK(!cdm_video_frame->FrameBuffer()); |
231 cdm_video_frame->SetFrameBuffer(host_->Allocate(space_required)); | 157 cdm_video_frame->SetFrameBuffer(host_->Allocate(space_required)); |
232 if (!cdm_video_frame->FrameBuffer()) { | 158 if (!cdm_video_frame->FrameBuffer()) { |
233 LOG(ERROR) << "CopyVpxImageTo() cdm::Host::Allocate failed."; | 159 LOG(ERROR) << "CopyVpxImageTo() cdm::Host::Allocate failed."; |
(...skipping 22 matching lines...) Expand all Loading... |
256 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kUPlane, y_size); | 182 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kUPlane, y_size); |
257 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kVPlane, | 183 cdm_video_frame->SetPlaneOffset(cdm::VideoFrame::kVPlane, |
258 y_size + u_size); | 184 y_size + u_size); |
259 | 185 |
260 cdm_video_frame->SetStride(cdm::VideoFrame::kYPlane, | 186 cdm_video_frame->SetStride(cdm::VideoFrame::kYPlane, |
261 vpx_image_->stride[VPX_PLANE_Y]); | 187 vpx_image_->stride[VPX_PLANE_Y]); |
262 cdm_video_frame->SetStride(cdm::VideoFrame::kUPlane, | 188 cdm_video_frame->SetStride(cdm::VideoFrame::kUPlane, |
263 vpx_image_->stride[VPX_PLANE_U]); | 189 vpx_image_->stride[VPX_PLANE_U]); |
264 cdm_video_frame->SetStride(cdm::VideoFrame::kVPlane, | 190 cdm_video_frame->SetStride(cdm::VideoFrame::kVPlane, |
265 vpx_image_->stride[VPX_PLANE_V]); | 191 vpx_image_->stride[VPX_PLANE_V]); |
266 #endif // USE_COPYPLANE_WITH_LIBVPX | |
267 | 192 |
268 return true; | 193 return true; |
269 } | 194 } |
270 | 195 |
271 } // namespace webkit_media | 196 } // namespace webkit_media |
OLD | NEW |