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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_
6 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/demuxer_stream.h"
11 #include "media/base/video_decoder.h"
13 struct AVCodecContext
;
17 class MessageLoopProxy
;
24 class MEDIA_EXPORT FFmpegVideoDecoder
: public VideoDecoder
{
26 explicit FFmpegVideoDecoder(
27 const scoped_refptr
<base::MessageLoopProxy
>& message_loop
);
29 // VideoDecoder implementation.
30 virtual void Initialize(const scoped_refptr
<DemuxerStream
>& stream
,
31 const PipelineStatusCB
& status_cb
,
32 const StatisticsCB
& statistics_cb
) OVERRIDE
;
33 virtual void Read(const ReadCB
& read_cb
) OVERRIDE
;
34 virtual void Reset(const base::Closure
& closure
) OVERRIDE
;
35 virtual void Stop(const base::Closure
& closure
) OVERRIDE
;
37 // Callback called from within FFmpeg to allocate a buffer based on
38 // the dimensions of |codec_context|. See AVCodecContext.get_buffer
39 // documentation inside FFmpeg.
40 int GetVideoBuffer(AVCodecContext
*codec_context
, AVFrame
* frame
);
43 virtual ~FFmpegVideoDecoder();
53 // Reads from the demuxer stream and corresponding read callback.
54 void ReadFromDemuxerStream();
55 void BufferReady(DemuxerStream::Status status
,
56 const scoped_refptr
<DecoderBuffer
>& buffer
);
58 // Handles decoding an unencrypted encoded buffer.
59 void DecodeBuffer(const scoped_refptr
<DecoderBuffer
>& buffer
);
60 bool Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
61 scoped_refptr
<VideoFrame
>* video_frame
);
63 // Handles (re-)initializing the decoder with a (new) config.
64 // Returns true if initialization was successful.
65 bool ConfigureDecoder();
67 // Releases resources associated with |codec_context_| and |av_frame_|
68 // and resets them to NULL.
69 void ReleaseFFmpegResources();
71 // Reset decoder and call |reset_cb_|.
74 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
78 StatisticsCB statistics_cb_
;
81 base::Closure reset_cb_
;
83 // FFmpeg structures owned by this object.
84 AVCodecContext
* codec_context_
;
87 // Pointer to the demuxer stream that will feed us compressed buffers.
88 scoped_refptr
<DemuxerStream
> demuxer_stream_
;
90 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder
);
95 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_