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 "media/filters/vpx_video_decoder.h" | 5 #include "media/filters/vpx_video_decoder.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 if (!vpx_codec_) | 260 if (!vpx_codec_) |
261 return false; | 261 return false; |
262 | 262 |
263 // We use our own buffers for VP9 so that there is no need to copy data after | 263 // We use our own buffers for VP9 so that there is no need to copy data after |
264 // decoding. | 264 // decoding. |
265 if (config.codec() == kCodecVP9) { | 265 if (config.codec() == kCodecVP9) { |
266 memory_pool_ = new MemoryPool(); | 266 memory_pool_ = new MemoryPool(); |
267 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, | 267 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, |
268 &MemoryPool::GetVP9FrameBuffer, | 268 &MemoryPool::GetVP9FrameBuffer, |
269 &MemoryPool::ReleaseVP9FrameBuffer, | 269 &MemoryPool::ReleaseVP9FrameBuffer, |
270 memory_pool_)) { | 270 memory_pool_.get())) { |
ddorwin
2014/08/25 21:26:40
This parameter is "Callback's private data".
I did
dcheng
2014/08/25 21:33:25
It's worth noting this was already using the impli
Tom Finegan
2014/08/26 00:26:11
caveat: I did not write or review this part of Vpx
| |
271 LOG(ERROR) << "Failed to configure external buffers."; | 271 LOG(ERROR) << "Failed to configure external buffers."; |
272 return false; | 272 return false; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 if (config.format() == VideoFrame::YV12A) { | 276 if (config.format() == VideoFrame::YV12A) { |
277 vpx_codec_alpha_ = InitializeVpxContext(vpx_codec_alpha_, config); | 277 vpx_codec_alpha_ = InitializeVpxContext(vpx_codec_alpha_, config); |
278 if (!vpx_codec_alpha_) | 278 if (!vpx_codec_alpha_) |
279 return false; | 279 return false; |
280 } | 280 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 state_ = kNormal; | 326 state_ = kNormal; |
327 task_runner_->PostTask(FROM_HERE, closure); | 327 task_runner_->PostTask(FROM_HERE, closure); |
328 } | 328 } |
329 | 329 |
330 void VpxVideoDecoder::DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) { | 330 void VpxVideoDecoder::DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer) { |
331 DCHECK(task_runner_->BelongsToCurrentThread()); | 331 DCHECK(task_runner_->BelongsToCurrentThread()); |
332 DCHECK_NE(state_, kUninitialized); | 332 DCHECK_NE(state_, kUninitialized); |
333 DCHECK_NE(state_, kDecodeFinished); | 333 DCHECK_NE(state_, kDecodeFinished); |
334 DCHECK_NE(state_, kError); | 334 DCHECK_NE(state_, kError); |
335 DCHECK(!decode_cb_.is_null()); | 335 DCHECK(!decode_cb_.is_null()); |
336 DCHECK(buffer); | 336 DCHECK(buffer.get()); |
337 | 337 |
338 // Transition to kDecodeFinished on the first end of stream buffer. | 338 // Transition to kDecodeFinished on the first end of stream buffer. |
339 if (state_ == kNormal && buffer->end_of_stream()) { | 339 if (state_ == kNormal && buffer->end_of_stream()) { |
340 state_ = kDecodeFinished; | 340 state_ = kDecodeFinished; |
341 base::ResetAndReturn(&decode_cb_).Run(kOk); | 341 base::ResetAndReturn(&decode_cb_).Run(kOk); |
342 return; | 342 return; |
343 } | 343 } |
344 | 344 |
345 scoped_refptr<VideoFrame> video_frame; | 345 scoped_refptr<VideoFrame> video_frame; |
346 if (!VpxDecode(buffer, &video_frame)) { | 346 if (!VpxDecode(buffer, &video_frame)) { |
347 state_ = kError; | 347 state_ = kError; |
348 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); | 348 base::ResetAndReturn(&decode_cb_).Run(kDecodeError); |
349 return; | 349 return; |
350 } | 350 } |
351 | 351 |
352 base::ResetAndReturn(&decode_cb_).Run(kOk); | 352 base::ResetAndReturn(&decode_cb_).Run(kOk); |
353 | 353 |
354 if (video_frame) | 354 if (video_frame.get()) |
355 output_cb_.Run(video_frame); | 355 output_cb_.Run(video_frame); |
356 } | 356 } |
357 | 357 |
358 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, | 358 bool VpxVideoDecoder::VpxDecode(const scoped_refptr<DecoderBuffer>& buffer, |
359 scoped_refptr<VideoFrame>* video_frame) { | 359 scoped_refptr<VideoFrame>* video_frame) { |
360 DCHECK(video_frame); | 360 DCHECK(video_frame); |
361 DCHECK(!buffer->end_of_stream()); | 361 DCHECK(!buffer->end_of_stream()); |
362 | 362 |
363 // Pass |buffer| to libvpx. | 363 // Pass |buffer| to libvpx. |
364 int64 timestamp = buffer->timestamp().InMicroseconds(); | 364 int64 timestamp = buffer->timestamp().InMicroseconds(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 if (vpx_image->fmt == VPX_IMG_FMT_I444) { | 442 if (vpx_image->fmt == VPX_IMG_FMT_I444) { |
443 CHECK(!vpx_codec_alpha_); | 443 CHECK(!vpx_codec_alpha_); |
444 codec_format = VideoFrame::YV24; | 444 codec_format = VideoFrame::YV24; |
445 uv_rows = vpx_image->d_h; | 445 uv_rows = vpx_image->d_h; |
446 } else if (vpx_codec_alpha_) { | 446 } else if (vpx_codec_alpha_) { |
447 codec_format = VideoFrame::YV12A; | 447 codec_format = VideoFrame::YV12A; |
448 } | 448 } |
449 | 449 |
450 gfx::Size size(vpx_image->d_w, vpx_image->d_h); | 450 gfx::Size size(vpx_image->d_w, vpx_image->d_h); |
451 | 451 |
452 if (!vpx_codec_alpha_ && memory_pool_) { | 452 if (!vpx_codec_alpha_ && memory_pool_.get()) { |
453 *video_frame = VideoFrame::WrapExternalYuvData( | 453 *video_frame = VideoFrame::WrapExternalYuvData( |
454 codec_format, | 454 codec_format, |
455 size, gfx::Rect(size), config_.natural_size(), | 455 size, gfx::Rect(size), config_.natural_size(), |
456 vpx_image->stride[VPX_PLANE_Y], | 456 vpx_image->stride[VPX_PLANE_Y], |
457 vpx_image->stride[VPX_PLANE_U], | 457 vpx_image->stride[VPX_PLANE_U], |
458 vpx_image->stride[VPX_PLANE_V], | 458 vpx_image->stride[VPX_PLANE_V], |
459 vpx_image->planes[VPX_PLANE_Y], | 459 vpx_image->planes[VPX_PLANE_Y], |
460 vpx_image->planes[VPX_PLANE_U], | 460 vpx_image->planes[VPX_PLANE_U], |
461 vpx_image->planes[VPX_PLANE_V], | 461 vpx_image->planes[VPX_PLANE_V], |
462 kNoTimestamp(), | 462 kNoTimestamp(), |
(...skipping 27 matching lines...) Expand all Loading... | |
490 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); | 490 vpx_image->stride[VPX_PLANE_Y], vpx_image->d_h, video_frame->get()); |
491 return; | 491 return; |
492 } | 492 } |
493 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], | 493 CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
494 vpx_image->stride[VPX_PLANE_Y], | 494 vpx_image->stride[VPX_PLANE_Y], |
495 vpx_image->d_h, | 495 vpx_image->d_h, |
496 video_frame->get()); | 496 video_frame->get()); |
497 } | 497 } |
498 | 498 |
499 } // namespace media | 499 } // namespace media |
OLD | NEW |