Report errors from ChromiumEnv::GetChildren in Posix.
[chromium-blink-merge.git] / media / filters / ffmpeg_video_decoder.h
blob9df5fa913a6d0b34d93228f2b8663c2b682febee
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 "base/memory/weak_ptr.h"
13 #include "media/base/video_decoder.h"
14 #include "media/base/video_decoder_config.h"
16 struct AVCodecContext;
17 struct AVFrame;
19 namespace base {
20 class MessageLoopProxy;
23 namespace media {
25 class DecoderBuffer;
26 class ScopedPtrAVFreeContext;
27 class ScopedPtrAVFreeFrame;
29 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
30 public:
31 explicit FFmpegVideoDecoder(
32 const scoped_refptr<base::MessageLoopProxy>& message_loop);
33 virtual ~FFmpegVideoDecoder();
35 // VideoDecoder implementation.
36 virtual void Initialize(const VideoDecoderConfig& config,
37 const PipelineStatusCB& status_cb) OVERRIDE;
38 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
39 const DecodeCB& decode_cb) OVERRIDE;
40 virtual void Reset(const base::Closure& closure) OVERRIDE;
41 virtual void Stop(const base::Closure& closure) OVERRIDE;
43 // Callback called from within FFmpeg to allocate a buffer based on
44 // the dimensions of |codec_context|. See AVCodecContext.get_buffer
45 // documentation inside FFmpeg.
46 int GetVideoBuffer(AVCodecContext *codec_context, AVFrame* frame);
48 private:
49 enum DecoderState {
50 kUninitialized,
51 kNormal,
52 kFlushCodec,
53 kDecodeFinished,
54 kError
57 // Handles decoding an unencrypted encoded buffer.
58 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer);
59 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer,
60 scoped_refptr<VideoFrame>* video_frame);
62 // Handles (re-)initializing the decoder with a (new) config.
63 // Returns true if initialization was successful.
64 bool ConfigureDecoder();
66 // Releases resources associated with |codec_context_| and |av_frame_|
67 // and resets them to NULL.
68 void ReleaseFFmpegResources();
70 // Reset decoder and call |reset_cb_|.
71 void DoReset();
73 scoped_refptr<base::MessageLoopProxy> message_loop_;
74 base::WeakPtrFactory<FFmpegVideoDecoder> weak_factory_;
75 base::WeakPtr<FFmpegVideoDecoder> weak_this_;
77 DecoderState state_;
79 DecodeCB decode_cb_;
80 base::Closure reset_cb_;
82 // FFmpeg structures owned by this object.
83 scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
84 scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
86 VideoDecoderConfig config_;
88 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder);
91 } // namespace media
93 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_