[MD settings] moving attached() code
[chromium-blink-merge.git] / media / filters / ffmpeg_video_decoder.h
blob53999aae2d75e110e02f15a762e51273018c64aa
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 <list>
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;
18 struct AVFrame;
20 namespace base {
21 class SingleThreadTaskRunner;
24 namespace media {
26 class DecoderBuffer;
28 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
29 public:
30 static bool IsCodecSupported(VideoCodec codec);
32 explicit FFmpegVideoDecoder(
33 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
34 ~FFmpegVideoDecoder() override;
36 // Allow decoding of individual NALU. Entire frames are required by default.
37 // Disables low-latency mode. Must be called before Initialize().
38 void set_decode_nalus(bool decode_nalus) { decode_nalus_ = decode_nalus; }
40 // VideoDecoder implementation.
41 std::string GetDisplayName() const override;
42 void Initialize(const VideoDecoderConfig& config,
43 bool low_delay,
44 const InitCB& init_cb,
45 const OutputCB& output_cb) override;
46 void Decode(const scoped_refptr<DecoderBuffer>& buffer,
47 const DecodeCB& decode_cb) override;
48 void Reset(const base::Closure& closure) override;
50 // Callback called from within FFmpeg to allocate a buffer based on
51 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2
52 // documentation inside FFmpeg.
53 int GetVideoBuffer(struct AVCodecContext* codec_context,
54 AVFrame* frame,
55 int flags);
57 private:
58 enum DecoderState {
59 kUninitialized,
60 kNormal,
61 kDecodeFinished,
62 kError
65 // Handles decoding an unencrypted encoded buffer.
66 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer,
67 bool* has_produced_frame);
69 // Handles (re-)initializing the decoder with a (new) config.
70 // Returns true if initialization was successful.
71 bool ConfigureDecoder(bool low_delay);
73 // Releases resources associated with |codec_context_| and |av_frame_|
74 // and resets them to NULL.
75 void ReleaseFFmpegResources();
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
79 DecoderState state_;
81 OutputCB output_cb_;
83 // FFmpeg structures owned by this object.
84 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
85 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
87 VideoDecoderConfig config_;
89 VideoFramePool frame_pool_;
91 bool decode_nalus_;
93 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder);
96 } // namespace media
98 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_