Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 state_ = kNormal; | 373 state_ = kNormal; |
| 374 // PostTask() to avoid calling |closure| inmediately. | 374 // PostTask() to avoid calling |closure| inmediately. |
| 375 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 375 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
| 376 } | 376 } |
| 377 | 377 |
| 378 bool VpxVideoDecoder::ConfigureDecoder(const VideoDecoderConfig& config) { | 378 bool VpxVideoDecoder::ConfigureDecoder(const VideoDecoderConfig& config) { |
| 379 if (config.codec() != kCodecVP8 && config.codec() != kCodecVP9) | 379 if (config.codec() != kCodecVP8 && config.codec() != kCodecVP9) |
| 380 return false; | 380 return false; |
| 381 | 381 |
| 382 // These are the combinations of codec-pixel format supported in principle. | 382 // These are the combinations of codec-pixel format supported in principle. |
| 383 // Note that VP9 does not support Alpha in the current implementation. | |
| 384 DCHECK( | 383 DCHECK( |
| 385 (config.codec() == kCodecVP8 && config.format() == PIXEL_FORMAT_YV12) || | 384 (config.codec() == kCodecVP8 && config.format() == PIXEL_FORMAT_YV12) || |
| 386 (config.codec() == kCodecVP8 && config.format() == PIXEL_FORMAT_YV12A) || | 385 (config.codec() == kCodecVP8 && config.format() == PIXEL_FORMAT_YV12A) || |
| 387 (config.codec() == kCodecVP9 && config.format() == PIXEL_FORMAT_YV12) || | 386 (config.codec() == kCodecVP9 && config.format() == PIXEL_FORMAT_YV12) || |
| 387 (config.codec() == kCodecVP9 && config.format() == PIXEL_FORMAT_YV12A) || | |
| 388 (config.codec() == kCodecVP9 && config.format() == PIXEL_FORMAT_YV24)); | 388 (config.codec() == kCodecVP9 && config.format() == PIXEL_FORMAT_YV24)); |
| 389 | 389 |
| 390 #if !defined(DISABLE_FFMPEG_VIDEO_DECODERS) | 390 #if !defined(DISABLE_FFMPEG_VIDEO_DECODERS) |
| 391 // When FFmpegVideoDecoder is available it handles VP8 that doesn't have | 391 // When FFmpegVideoDecoder is available it handles VP8 that doesn't have |
| 392 // alpha, and VpxVideoDecoder will handle VP8 with alpha. | 392 // alpha, and VpxVideoDecoder will handle VP8 with alpha. |
| 393 if (config.codec() == kCodecVP8 && config.format() != PIXEL_FORMAT_YV12A) | 393 if (config.codec() == kCodecVP8 && config.format() != PIXEL_FORMAT_YV12A) |
| 394 return false; | 394 return false; |
| 395 #endif | 395 #endif |
| 396 | 396 |
| 397 CloseDecoder(); | 397 CloseDecoder(); |
| 398 | 398 |
| 399 vpx_codec_ = InitializeVpxContext(vpx_codec_, config); | 399 vpx_codec_ = InitializeVpxContext(vpx_codec_, config); |
| 400 if (!vpx_codec_) | 400 if (!vpx_codec_) |
| 401 return false; | 401 return false; |
| 402 | 402 |
| 403 // Configure VP9 to decode on our buffers to skip a data copy on decoding. | 403 // Configure non-YV12A VP9 to decode on our buffers to skip a data copy on |
|
DaleCurtis
2016/01/05 21:22:21
I guess we can't copy into one of the buffers sinc
vignesh
2016/01/06 00:07:49
The thing is that the Y, U and V planes come from
DaleCurtis
2016/01/06 00:18:02
Hmm, could you over allocate the first buffer and
vignesh
2016/01/08 17:53:40
Good point, i will try it out and update the CL.
vignesh
2016/01/08 19:21:33
ok, i looked into this and i'm a little confused.
DaleCurtis
2016/01/08 19:29:03
Yes, you'd need to add a WrapExternalYUVA method a
| |
| 404 if (config.codec() == kCodecVP9) { | 404 // decoding. We do not use our buffers for YV12A VP9 since it involves two |
| 405 DCHECK_NE(PIXEL_FORMAT_YV12A, config.format()); | 405 // different instances of the decoder. |
| 406 if (config.codec() == kCodecVP9 && config.format() != PIXEL_FORMAT_YV12A) { | |
| 406 DCHECK(vpx_codec_get_caps(vpx_codec_->iface) & | 407 DCHECK(vpx_codec_get_caps(vpx_codec_->iface) & |
| 407 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER); | 408 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER); |
| 408 | 409 |
| 409 memory_pool_ = new MemoryPool(); | 410 memory_pool_ = new MemoryPool(); |
| 410 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, | 411 if (vpx_codec_set_frame_buffer_functions(vpx_codec_, |
| 411 &MemoryPool::GetVP9FrameBuffer, | 412 &MemoryPool::GetVP9FrameBuffer, |
| 412 &MemoryPool::ReleaseVP9FrameBuffer, | 413 &MemoryPool::ReleaseVP9FrameBuffer, |
| 413 memory_pool_.get())) { | 414 memory_pool_.get())) { |
| 414 DLOG(ERROR) << "Failed to configure external buffers. " | 415 DLOG(ERROR) << "Failed to configure external buffers. " |
| 415 << vpx_codec_error(vpx_codec_); | 416 << vpx_codec_error(vpx_codec_); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 | 575 |
| 575 // The mixed |w|/|d_h| in |coded_size| is intentional. Setting the correct | 576 // The mixed |w|/|d_h| in |coded_size| is intentional. Setting the correct |
| 576 // coded width is necessary to allow coalesced memory access, which may avoid | 577 // coded width is necessary to allow coalesced memory access, which may avoid |
| 577 // frame copies. Setting the correct coded height however does not have any | 578 // frame copies. Setting the correct coded height however does not have any |
| 578 // benefit, and only risk copying too much data. | 579 // benefit, and only risk copying too much data. |
| 579 const gfx::Size coded_size(vpx_image->w, vpx_image->d_h); | 580 const gfx::Size coded_size(vpx_image->w, vpx_image->d_h); |
| 580 const gfx::Size visible_size(vpx_image->d_w, vpx_image->d_h); | 581 const gfx::Size visible_size(vpx_image->d_w, vpx_image->d_h); |
| 581 | 582 |
| 582 if (memory_pool_.get()) { | 583 if (memory_pool_.get()) { |
| 583 DCHECK_EQ(kCodecVP9, config_.codec()); | 584 DCHECK_EQ(kCodecVP9, config_.codec()); |
| 584 DCHECK(!vpx_codec_alpha_) << "Uh-oh, VP9 and Alpha shouldn't coexist."; | 585 DCHECK(!vpx_codec_alpha_); |
| 585 *video_frame = VideoFrame::WrapExternalYuvData( | 586 *video_frame = VideoFrame::WrapExternalYuvData( |
| 586 codec_format, | 587 codec_format, |
| 587 coded_size, gfx::Rect(visible_size), config_.natural_size(), | 588 coded_size, gfx::Rect(visible_size), config_.natural_size(), |
| 588 vpx_image->stride[VPX_PLANE_Y], | 589 vpx_image->stride[VPX_PLANE_Y], |
| 589 vpx_image->stride[VPX_PLANE_U], | 590 vpx_image->stride[VPX_PLANE_U], |
| 590 vpx_image->stride[VPX_PLANE_V], | 591 vpx_image->stride[VPX_PLANE_V], |
| 591 vpx_image->planes[VPX_PLANE_Y], | 592 vpx_image->planes[VPX_PLANE_Y], |
| 592 vpx_image->planes[VPX_PLANE_U], | 593 vpx_image->planes[VPX_PLANE_U], |
| 593 vpx_image->planes[VPX_PLANE_V], | 594 vpx_image->planes[VPX_PLANE_V], |
| 594 kNoTimestamp()); | 595 kNoTimestamp()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 620 (*video_frame)->visible_data(VideoFrame::kUPlane), | 621 (*video_frame)->visible_data(VideoFrame::kUPlane), |
| 621 (*video_frame)->stride(VideoFrame::kUPlane), | 622 (*video_frame)->stride(VideoFrame::kUPlane), |
| 622 (*video_frame)->visible_data(VideoFrame::kVPlane), | 623 (*video_frame)->visible_data(VideoFrame::kVPlane), |
| 623 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), | 624 (*video_frame)->stride(VideoFrame::kVPlane), coded_size.width(), |
| 624 coded_size.height()); | 625 coded_size.height()); |
| 625 | 626 |
| 626 return true; | 627 return true; |
| 627 } | 628 } |
| 628 | 629 |
| 629 } // namespace media | 630 } // namespace media |
| OLD | NEW |