diff options
Diffstat (limited to 'chromium/media/filters/ffmpeg_video_decoder.cc')
-rw-r--r-- | chromium/media/filters/ffmpeg_video_decoder.cc | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/chromium/media/filters/ffmpeg_video_decoder.cc b/chromium/media/filters/ffmpeg_video_decoder.cc index d03648c9b13..b8757657548 100644 --- a/chromium/media/filters/ffmpeg_video_decoder.cc +++ b/chromium/media/filters/ffmpeg_video_decoder.cc @@ -58,9 +58,7 @@ FFmpegVideoDecoder::FFmpegVideoDecoder( const scoped_refptr<base::MessageLoopProxy>& message_loop) : message_loop_(message_loop), weak_factory_(this), - state_(kUninitialized), - codec_context_(NULL), - av_frame_(NULL) { + state_(kUninitialized) { } int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, @@ -71,9 +69,10 @@ int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, // updated width/height/pix_fmt, which can change for adaptive // content. VideoFrame::Format format = PixelFormatToVideoFormat(codec_context->pix_fmt); - if (format == VideoFrame::INVALID) + if (format == VideoFrame::UNKNOWN) return AVERROR(EINVAL); - DCHECK(format == VideoFrame::YV12 || format == VideoFrame::YV16); + DCHECK(format == VideoFrame::YV12 || format == VideoFrame::YV16 || + format == VideoFrame::YV12J); gfx::Size size(codec_context->width, codec_context->height); int ret; @@ -93,8 +92,8 @@ int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, return AVERROR(EINVAL); scoped_refptr<VideoFrame> video_frame = - VideoFrame::CreateFrame(format, size, gfx::Rect(size), natural_size, - kNoTimestamp()); + frame_pool_.CreateFrame(format, size, gfx::Rect(size), + natural_size, kNoTimestamp()); for (int i = 0; i < 3; i++) { frame->base[i] = video_frame->data(i); @@ -105,8 +104,6 @@ int FFmpegVideoDecoder::GetVideoBuffer(AVCodecContext* codec_context, frame->opaque = NULL; video_frame.swap(reinterpret_cast<VideoFrame**>(&frame->opaque)); frame->type = FF_BUFFER_TYPE_USER; - frame->pkt_pts = codec_context->pkt ? codec_context->pkt->pts : - AV_NOPTS_VALUE; frame->width = codec_context->width; frame->height = codec_context->height; frame->format = codec_context->pix_fmt; @@ -167,7 +164,7 @@ void FFmpegVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, // Return empty frames if decoding has finished. if (state_ == kDecodeFinished) { - base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEmptyFrame()); + base::ResetAndReturn(&decode_cb_).Run(kOk, VideoFrame::CreateEOSFrame()); return; } @@ -189,7 +186,7 @@ void FFmpegVideoDecoder::Reset(const base::Closure& closure) { void FFmpegVideoDecoder::DoReset() { DCHECK(decode_cb_.is_null()); - avcodec_flush_buffers(codec_context_); + avcodec_flush_buffers(codec_context_.get()); state_ = kNormal; base::ResetAndReturn(&reset_cb_).Run(); } @@ -273,7 +270,7 @@ void FFmpegVideoDecoder::DecodeBuffer( DCHECK(buffer->end_of_stream()); state_ = kDecodeFinished; base::ResetAndReturn(&decode_cb_) - .Run(kOk, VideoFrame::CreateEmptyFrame()); + .Run(kOk, VideoFrame::CreateEOSFrame()); return; } @@ -290,7 +287,7 @@ bool FFmpegVideoDecoder::FFmpegDecode( DCHECK(video_frame); // Reset frame to default values. - avcodec_get_frame_defaults(av_frame_); + avcodec_get_frame_defaults(av_frame_.get()); // Create a packet for input data. // Due to FFmpeg API changes we no longer have const read-only pointers. @@ -312,8 +309,8 @@ bool FFmpegVideoDecoder::FFmpegDecode( } int frame_decoded = 0; - int result = avcodec_decode_video2(codec_context_, - av_frame_, + int result = avcodec_decode_video2(codec_context_.get(), + av_frame_.get(), &frame_decoded, &packet); // Log the problem if we can't decode a video frame and exit early. @@ -356,16 +353,8 @@ bool FFmpegVideoDecoder::FFmpegDecode( } void FFmpegVideoDecoder::ReleaseFFmpegResources() { - if (codec_context_) { - av_free(codec_context_->extradata); - avcodec_close(codec_context_); - av_free(codec_context_); - codec_context_ = NULL; - } - if (av_frame_) { - av_free(av_frame_); - av_frame_ = NULL; - } + codec_context_.reset(); + av_frame_.reset(); } bool FFmpegVideoDecoder::ConfigureDecoder() { @@ -373,8 +362,8 @@ bool FFmpegVideoDecoder::ConfigureDecoder() { ReleaseFFmpegResources(); // Initialize AVCodecContext structure. - codec_context_ = avcodec_alloc_context3(NULL); - VideoDecoderConfigToAVCodecContext(config_, codec_context_); + codec_context_.reset(avcodec_alloc_context3(NULL)); + VideoDecoderConfigToAVCodecContext(config_, codec_context_.get()); // Enable motion vector search (potentially slow), strong deblocking filter // for damaged macroblocks, and set our error detection sensitivity. @@ -386,12 +375,12 @@ bool FFmpegVideoDecoder::ConfigureDecoder() { codec_context_->release_buffer = ReleaseVideoBufferImpl; AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); - if (!codec || avcodec_open2(codec_context_, codec, NULL) < 0) { + if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { ReleaseFFmpegResources(); return false; } - av_frame_ = avcodec_alloc_frame(); + av_frame_.reset(av_frame_alloc()); return true; } |