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_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "media/base/video_decoder.h"
13 #include "media/base/video_decoder_config.h"
14 #include "media/base/video_frame_pool.h"
15 #include "media/ffmpeg/ffmpeg_deleters.h"
17 struct AVCodecContext
;
21 class SingleThreadTaskRunner
;
28 class MEDIA_EXPORT FFmpegVideoDecoder
: public VideoDecoder
{
30 explicit FFmpegVideoDecoder(
31 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
);
32 virtual ~FFmpegVideoDecoder();
34 // Allow decoding of individual NALU. Entire frames are required by default.
35 // Disables low-latency mode. Must be called before Initialize().
36 void set_decode_nalus(bool decode_nalus
) { decode_nalus_
= decode_nalus
; }
38 // VideoDecoder implementation.
39 virtual void Initialize(const VideoDecoderConfig
& config
,
41 const PipelineStatusCB
& status_cb
,
42 const OutputCB
& output_cb
) OVERRIDE
;
43 virtual void Decode(const scoped_refptr
<DecoderBuffer
>& buffer
,
44 const DecodeCB
& decode_cb
) OVERRIDE
;
45 virtual void Reset(const base::Closure
& closure
) OVERRIDE
;
47 // Callback called from within FFmpeg to allocate a buffer based on
48 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2
49 // documentation inside FFmpeg.
50 int GetVideoBuffer(struct AVCodecContext
* codec_context
,
62 // Handles decoding an unencrypted encoded buffer.
63 bool FFmpegDecode(const scoped_refptr
<DecoderBuffer
>& buffer
,
64 bool* has_produced_frame
);
66 // Handles (re-)initializing the decoder with a (new) config.
67 // Returns true if initialization was successful.
68 bool ConfigureDecoder(bool low_delay
);
70 // Releases resources associated with |codec_context_| and |av_frame_|
71 // and resets them to NULL.
72 void ReleaseFFmpegResources();
74 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
80 // FFmpeg structures owned by this object.
81 scoped_ptr
<AVCodecContext
, ScopedPtrAVFreeContext
> codec_context_
;
82 scoped_ptr
<AVFrame
, ScopedPtrAVFreeFrame
> av_frame_
;
84 VideoDecoderConfig config_
;
86 VideoFramePool frame_pool_
;
90 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder
);
95 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_