cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / filters / ffmpeg_video_decoder.h
blob1f032266951b93583decd2a9fc87cf543c349109
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/weak_ptr.h"
12 #include "media/base/video_decoder.h"
13 #include "media/base/video_decoder_config.h"
15 struct AVCodecContext;
16 struct AVFrame;
18 namespace base {
19 class MessageLoopProxy;
22 namespace media {
24 class DecoderBuffer;
26 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
27 public:
28 explicit FFmpegVideoDecoder(
29 const scoped_refptr<base::MessageLoopProxy>& message_loop);
30 virtual ~FFmpegVideoDecoder();
32 // VideoDecoder implementation.
33 virtual void Initialize(const VideoDecoderConfig& config,
34 const PipelineStatusCB& status_cb) OVERRIDE;
35 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
36 const DecodeCB& decode_cb) OVERRIDE;
37 virtual void Reset(const base::Closure& closure) OVERRIDE;
38 virtual void Stop(const base::Closure& closure) OVERRIDE;
40 // Callback called from within FFmpeg to allocate a buffer based on
41 // the dimensions of |codec_context|. See AVCodecContext.get_buffer
42 // documentation inside FFmpeg.
43 int GetVideoBuffer(AVCodecContext *codec_context, AVFrame* frame);
45 private:
46 enum DecoderState {
47 kUninitialized,
48 kNormal,
49 kFlushCodec,
50 kDecodeFinished,
51 kError
54 // Handles decoding an unencrypted encoded buffer.
55 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer);
56 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer,
57 scoped_refptr<VideoFrame>* video_frame);
59 // Handles (re-)initializing the decoder with a (new) config.
60 // Returns true if initialization was successful.
61 bool ConfigureDecoder();
63 // Releases resources associated with |codec_context_| and |av_frame_|
64 // and resets them to NULL.
65 void ReleaseFFmpegResources();
67 // Reset decoder and call |reset_cb_|.
68 void DoReset();
70 scoped_refptr<base::MessageLoopProxy> message_loop_;
71 base::WeakPtrFactory<FFmpegVideoDecoder> weak_factory_;
72 base::WeakPtr<FFmpegVideoDecoder> weak_this_;
74 DecoderState state_;
76 DecodeCB decode_cb_;
77 base::Closure reset_cb_;
79 // FFmpeg structures owned by this object.
80 AVCodecContext* codec_context_;
81 AVFrame* av_frame_;
83 VideoDecoderConfig config_;
85 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder);
88 } // namespace media
90 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_