Chromium Code Reviews| Index: media/filters/vpx_video_decoder.cc |
| diff --git a/media/filters/vpx_video_decoder.cc b/media/filters/vpx_video_decoder.cc |
| index 0b92a7d8459c4e152bbd7261b56ce7dcc1c32ffe..bf6074168038f1254aeb2e3a432439b72e4c797e 100644 |
| --- a/media/filters/vpx_video_decoder.cc |
| +++ b/media/filters/vpx_video_decoder.cc |
| @@ -59,7 +59,8 @@ VpxVideoDecoder::VpxVideoDecoder( |
| const scoped_refptr<base::MessageLoopProxy>& message_loop) |
| : message_loop_(message_loop), |
| state_(kUninitialized), |
| - vpx_codec_(NULL) { |
| + vpx_codec_(NULL), |
| + vpx_codec_alpha_(NULL) { |
| } |
| VpxVideoDecoder::~VpxVideoDecoder() { |
| @@ -100,19 +101,33 @@ bool VpxVideoDecoder::ConfigureDecoder() { |
| return false; |
| } |
| - if (config.codec() != kCodecVP9) |
| - return false; |
| + format_ = config.format(); |
| + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| + bool can_handle = false; |
| + if(cmd_line->HasSwitch(switches::kEnableVp9Playback) && |
| + config.codec() == kCodecVP9) { |
|
fgalligan1
2013/02/12 01:20:58
Line up.
vigneshv
2013/02/14 19:06:14
Done.
|
| + can_handle = true; |
| + } |
| + if(cmd_line->HasSwitch(switches::kEnableVp8AlphaPlayback) && |
| + config.codec() == kCodecVP8 && format_ == VideoFrame::YV12A) { |
|
fgalligan1
2013/02/12 01:20:58
Line up.
vigneshv
2013/02/14 19:06:14
Done.
|
| + can_handle = true; |
| + } |
| + if(!can_handle) |
| + return false; |
| CloseDecoder(); |
| vpx_codec_ = new vpx_codec_ctx(); |
| vpx_codec_dec_cfg_t vpx_config = {0}; |
| + |
|
fgalligan1
2013/02/12 01:20:58
nit: Remove line
vigneshv
2013/02/14 19:06:14
Done.
|
| vpx_config.w = config.coded_size().width(); |
| vpx_config.h = config.coded_size().height(); |
| vpx_config.threads = GetThreadCount(); |
| vpx_codec_err_t status = vpx_codec_dec_init(vpx_codec_, |
| - vpx_codec_vp9_dx(), |
| + config.codec() == kCodecVP9 ? |
| + vpx_codec_vp9_dx() : |
|
fgalligan1
2013/02/12 01:20:58
nit: 4 space indent.
vigneshv
2013/02/14 19:06:14
Done.
|
| + vpx_codec_vp8_dx(), |
| &vpx_config, |
| 0); |
| if (status != VPX_CODEC_OK) { |
| @@ -122,6 +137,26 @@ bool VpxVideoDecoder::ConfigureDecoder() { |
| return false; |
| } |
| + if(format_ == VideoFrame::YV12A) { |
| + vpx_codec_alpha_ = new vpx_codec_ctx(); |
| + vpx_codec_dec_cfg_t vpx_config_alpha = {0}; |
| + |
| + vpx_config_alpha.w = config.coded_size().width(); |
| + vpx_config_alpha.h = config.coded_size().height(); |
| + vpx_config_alpha.threads = GetThreadCount(); |
| + |
| + status = vpx_codec_dec_init(vpx_codec_alpha_, |
| + vpx_codec_vp8_dx(), |
| + &vpx_config_alpha, |
| + 0); |
| + if (status != VPX_CODEC_OK) { |
| + LOG(ERROR) << "vpx_codec_dec_init failed, status=" << status; |
| + delete vpx_codec_alpha_; |
| + vpx_codec_alpha_ = NULL; |
| + return false; |
| + } |
| + } |
| + |
| return true; |
| } |
| @@ -131,6 +166,11 @@ void VpxVideoDecoder::CloseDecoder() { |
| delete vpx_codec_; |
| vpx_codec_ = NULL; |
| } |
| + if (vpx_codec_alpha_) { |
| + vpx_codec_destroy(vpx_codec_alpha_); |
| + delete vpx_codec_alpha_; |
| + vpx_codec_alpha_ = NULL; |
| + } |
| } |
| void VpxVideoDecoder::Read(const ReadCB& read_cb) { |
| @@ -246,7 +286,7 @@ void VpxVideoDecoder::DecodeBuffer( |
| } |
| // Any successful decode counts! |
| - if (buffer->GetDataSize()) { |
| + if (buffer->GetDataSize() && buffer->GetSideDataSize()) { |
| PipelineStatistics statistics; |
| statistics.video_bytes_decoded = buffer->GetDataSize(); |
| statistics_cb_.Run(statistics); |
| @@ -293,7 +333,42 @@ bool VpxVideoDecoder::Decode( |
| return false; |
| } |
| - CopyVpxImageTo(vpx_image, video_frame); |
| + const vpx_image_t* vpx_image_alpha = NULL; |
| + if(format_ == VideoFrame::YV12A) { |
| + |
| + // Pass alpha data to libvpx. |
| + int64 timestamp_alpha = buffer->GetTimestamp().InMicroseconds(); |
| + void *user_priv_alpha = reinterpret_cast<void*>(×tamp_alpha); |
|
fgalligan1
2013/02/12 01:20:58
nit: asterisk with type.
vigneshv
2013/02/14 19:06:14
Done.
|
| + uint64_t side_data_id = *((uint64_t*)buffer->GetSideData()); |
|
fgalligan1
2013/02/12 01:20:58
Use c++ cast.
vigneshv
2013/02/14 19:06:14
Done.
|
| + if(side_data_id == 1) { |
|
fgalligan1
2013/02/12 01:20:58
Space between if and (
vigneshv
2013/02/14 19:06:14
Done.
|
| + status = vpx_codec_decode(vpx_codec_alpha_, |
| + buffer->GetSideData() + sizeof(uint64_t), |
| + buffer->GetSideDataSize() - sizeof(uint64_t), |
| + user_priv_alpha, |
| + 0); |
| + |
| + if (status != VPX_CODEC_OK) { |
| + LOG(ERROR) << "vpx_codec_decode() failed on alpha, status=" << status; |
| + return false; |
| + } |
| + |
| + // Gets pointer to decoded data. |
| + vpx_codec_iter_t iter_alpha = NULL; |
| + vpx_image_alpha = vpx_codec_get_frame(vpx_codec_alpha_, &iter_alpha); |
| + if (!vpx_image_alpha) { |
| + *video_frame = NULL; |
| + return true; |
| + } |
| + |
| + if (vpx_image_alpha->user_priv != |
| + reinterpret_cast<void*>(×tamp_alpha)) { |
|
fgalligan1
2013/02/12 01:20:58
Line up.
vigneshv
2013/02/14 19:06:14
Done.
|
| + LOG(ERROR) << "Invalid output timestamp on alpha."; |
| + return false; |
| + } |
| + } |
| + } |
| + |
| + CopyVpxImageTo(vpx_image, vpx_image_alpha, video_frame); |
| (*video_frame)->SetTimestamp(base::TimeDelta::FromMicroseconds(timestamp)); |
| return true; |
| } |
| @@ -307,7 +382,8 @@ void VpxVideoDecoder::DoReset() { |
| } |
| void VpxVideoDecoder::CopyVpxImageTo( |
| - const vpx_image* vpx_image, |
| + const struct vpx_image* vpx_image, |
| + const struct vpx_image* vpx_image_alpha, |
| scoped_refptr<VideoFrame>* video_frame) { |
| CHECK(vpx_image); |
| CHECK_EQ(vpx_image->d_w % 2, 0U); |
| @@ -319,11 +395,12 @@ void VpxVideoDecoder::CopyVpxImageTo( |
| gfx::Size natural_size = |
| demuxer_stream_->video_decoder_config().natural_size(); |
| - *video_frame = VideoFrame::CreateFrame(VideoFrame::YV12, |
| + *video_frame = VideoFrame::CreateFrame(format_, |
| size, |
| gfx::Rect(size), |
| natural_size, |
| kNoTimestamp()); |
| + |
| CopyYPlane(vpx_image->planes[VPX_PLANE_Y], |
| vpx_image->stride[VPX_PLANE_Y], |
| vpx_image->d_h, |
| @@ -336,6 +413,25 @@ void VpxVideoDecoder::CopyVpxImageTo( |
| vpx_image->stride[VPX_PLANE_V], |
| vpx_image->d_h / 2, |
| *video_frame); |
| + if(format_ == VideoFrame::YV12A) { |
| + if(vpx_image_alpha) { |
| + CopyAPlane(vpx_image_alpha->planes[VPX_PLANE_Y], |
| + vpx_image->stride[VPX_PLANE_Y], |
| + vpx_image->d_h, |
| + *video_frame); |
| + } else { |
| + /* there is no alpha. set it to opaque */ |
| + uint64_t alpha_plane_size = vpx_image->stride[VPX_PLANE_Y] |
| + * vpx_image->d_h; |
|
fgalligan1
2013/02/12 01:20:58
I would put vpx_image->stride on the next line ind
vigneshv
2013/02/14 19:06:14
Done.
|
| + unsigned char *alpha_plane = (unsigned char*)malloc(alpha_plane_size); |
|
fgalligan1
2013/02/12 01:20:58
nit: asterisk with type. Use C++ cast.
vigneshv
2013/02/14 19:06:14
Done.
|
| + memset(alpha_plane, 255, alpha_plane_size); |
| + CopyAPlane(alpha_plane, |
| + vpx_image->stride[VPX_PLANE_Y], |
| + vpx_image->d_h, |
| + *video_frame); |
| + free(alpha_plane); |
| + } |
| + } |
| } |
| } // namespace media |