| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| 6 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 6 #define MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder { | 28 class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder { |
| 29 public: | 29 public: |
| 30 explicit FFmpegVideoDecoder( | 30 explicit FFmpegVideoDecoder( |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 31 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 32 virtual ~FFmpegVideoDecoder(); | 32 virtual ~FFmpegVideoDecoder(); |
| 33 | 33 |
| 34 // VideoDecoder implementation. | 34 // VideoDecoder implementation. |
| 35 virtual void Initialize(const VideoDecoderConfig& config, | 35 virtual void Initialize(const VideoDecoderConfig& config, |
| 36 bool low_delay, | 36 bool low_delay, |
| 37 const PipelineStatusCB& status_cb) OVERRIDE; | 37 const PipelineStatusCB& status_cb, |
| 38 const OutputCB& output_cb) OVERRIDE; |
| 38 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, | 39 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 39 const DecodeCB& decode_cb) OVERRIDE; | 40 const DecodeCB& decode_cb) OVERRIDE; |
| 40 virtual void Reset(const base::Closure& closure) OVERRIDE; | 41 virtual void Reset(const base::Closure& closure) OVERRIDE; |
| 41 virtual void Stop() OVERRIDE; | 42 virtual void Stop() OVERRIDE; |
| 42 | 43 |
| 43 // Callback called from within FFmpeg to allocate a buffer based on | 44 // Callback called from within FFmpeg to allocate a buffer based on |
| 44 // the dimensions of |codec_context|. See AVCodecContext.get_buffer | 45 // the dimensions of |codec_context|. See AVCodecContext.get_buffer |
| 45 // documentation inside FFmpeg. | 46 // documentation inside FFmpeg. |
| 46 int GetVideoBuffer(AVCodecContext *codec_context, AVFrame* frame); | 47 int GetVideoBuffer(AVCodecContext *codec_context, AVFrame* frame); |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 enum DecoderState { | 50 enum DecoderState { |
| 50 kUninitialized, | 51 kUninitialized, |
| 51 kNormal, | 52 kNormal, |
| 52 kFlushCodec, | |
| 53 kDecodeFinished, | 53 kDecodeFinished, |
| 54 kError | 54 kError |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Handles decoding an unencrypted encoded buffer. | 57 // Handles decoding an unencrypted encoded buffer. |
| 58 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); | |
| 59 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer, | 58 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer, |
| 60 scoped_refptr<VideoFrame>* video_frame); | 59 bool* produced_frame); |
| 61 | 60 |
| 62 // Handles (re-)initializing the decoder with a (new) config. | 61 // Handles (re-)initializing the decoder with a (new) config. |
| 63 // Returns true if initialization was successful. | 62 // Returns true if initialization was successful. |
| 64 bool ConfigureDecoder(bool low_delay); | 63 bool ConfigureDecoder(bool low_delay); |
| 65 | 64 |
| 66 // Releases resources associated with |codec_context_| and |av_frame_| | 65 // Releases resources associated with |codec_context_| and |av_frame_| |
| 67 // and resets them to NULL. | 66 // and resets them to NULL. |
| 68 void ReleaseFFmpegResources(); | 67 void ReleaseFFmpegResources(); |
| 69 | 68 |
| 70 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 69 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 71 | 70 |
| 72 DecoderState state_; | 71 DecoderState state_; |
| 73 | 72 |
| 74 // TODO(xhwang): Merge DecodeBuffer() into Decode() and remove this. | 73 OutputCB output_cb_; |
| 75 DecodeCB decode_cb_; | |
| 76 | 74 |
| 77 // FFmpeg structures owned by this object. | 75 // FFmpeg structures owned by this object. |
| 78 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; | 76 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; |
| 79 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_; | 77 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_; |
| 80 | 78 |
| 81 VideoDecoderConfig config_; | 79 VideoDecoderConfig config_; |
| 82 | 80 |
| 83 VideoFramePool frame_pool_; | 81 VideoFramePool frame_pool_; |
| 84 | 82 |
| 85 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); | 83 DISALLOW_COPY_AND_ASSIGN(FFmpegVideoDecoder); |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 } // namespace media | 86 } // namespace media |
| 89 | 87 |
| 90 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ | 88 #endif // MEDIA_FILTERS_FFMPEG_VIDEO_DECODER_H_ |
| OLD | NEW |