Chromium Code Reviews| 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_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
| 6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "media/base/audio_decoder.h" | 14 #include "media/base/audio_decoder.h" |
| 15 #include "media/base/demuxer_stream.h" | 15 #include "media/base/demuxer_stream.h" |
| 16 #include "media/base/sample_format.h" | 16 #include "media/base/sample_format.h" |
| 17 | 17 |
| 18 struct AVCodecContext; | 18 struct AVCodecContext; |
| 19 struct AVFrame; | 19 struct AVFrame; |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 | 26 |
| 27 class AudioTimestampHelper; | 27 class AudioTimestampHelper; |
| 28 class DecoderBuffer; | 28 class DecoderBuffer; |
| 29 struct QueuedAudioBuffer; | |
| 30 class ScopedPtrAVFreeContext; | 29 class ScopedPtrAVFreeContext; |
| 31 class ScopedPtrAVFreeFrame; | 30 class ScopedPtrAVFreeFrame; |
| 32 | 31 |
| 33 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { | 32 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
| 34 public: | 33 public: |
| 35 explicit FFmpegAudioDecoder( | 34 explicit FFmpegAudioDecoder( |
| 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
| 37 virtual ~FFmpegAudioDecoder(); | 36 virtual ~FFmpegAudioDecoder(); |
| 38 | 37 |
| 39 // AudioDecoder implementation. | 38 // AudioDecoder implementation. |
| 40 virtual void Initialize(DemuxerStream* stream, | 39 virtual void Initialize(const AudioDecoderConfig& config, |
| 41 const PipelineStatusCB& status_cb, | 40 const PipelineStatusCB& status_cb) OVERRIDE; |
| 42 const StatisticsCB& statistics_cb) OVERRIDE; | 41 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
| 43 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 42 const DecodeCB& decode_cb) OVERRIDE; |
| 43 virtual scoped_refptr<AudioBuffer> GetDecodeOutput() OVERRIDE; | |
| 44 virtual int bits_per_channel() OVERRIDE; | 44 virtual int bits_per_channel() OVERRIDE; |
| 45 virtual ChannelLayout channel_layout() OVERRIDE; | 45 virtual ChannelLayout channel_layout() OVERRIDE; |
| 46 virtual int samples_per_second() OVERRIDE; | 46 virtual int samples_per_second() OVERRIDE; |
| 47 virtual void Reset(const base::Closure& closure) OVERRIDE; | 47 virtual void Reset(const base::Closure& closure) OVERRIDE; |
| 48 virtual void Stop(const base::Closure& closure) OVERRIDE; | 48 virtual void Stop(const base::Closure& closure) OVERRIDE; |
| 49 | 49 |
| 50 // Callback called from within FFmpeg to allocate a buffer based on | 50 // Callback called from within FFmpeg to allocate a buffer based on |
| 51 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2 | 51 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2 |
| 52 // documentation inside FFmpeg. | 52 // documentation inside FFmpeg. |
| 53 int GetAudioBuffer(AVCodecContext* codec, AVFrame* frame, int flags); | 53 int GetAudioBuffer(AVCodecContext* codec, AVFrame* frame, int flags); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 void DoStop(); | 56 |
|
DaleCurtis
2014/03/04 01:01:33
Remove extra line.
rileya (GONE FROM CHROMIUM)
2014/03/04 02:03:01
Done.
| |
| 57 enum DecoderState { | |
| 58 kUninitialized, | |
| 59 kNormal, | |
| 60 kFlushCodec, | |
| 61 kDecodeFinished, | |
| 62 kError | |
| 63 }; | |
| 64 | |
| 65 // Reset decoder and call |reset_cb_|. | |
| 57 void DoReset(); | 66 void DoReset(); |
| 58 | 67 |
| 59 // Reads from the demuxer stream with corresponding callback method. | 68 // Handles decoding an unencrypted encoded buffer. |
| 60 void ReadFromDemuxerStream(); | 69 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer, |
| 61 void BufferReady(DemuxerStream::Status status, | 70 const DecodeCB& decode_cb); |
| 62 const scoped_refptr<DecoderBuffer>& input); | 71 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer); |
| 63 | 72 |
| 73 // Handles (re-)initializing the decoder with a (new) config. | |
| 74 // Returns true if initialization was successful. | |
| 64 bool ConfigureDecoder(); | 75 bool ConfigureDecoder(); |
| 76 | |
| 77 // Releases resources associated with |codec_context_| and |av_frame_| | |
| 78 // and resets them to NULL. | |
| 65 void ReleaseFFmpegResources(); | 79 void ReleaseFFmpegResources(); |
| 66 void ResetTimestampState(); | 80 void ResetTimestampState(); |
| 67 void RunDecodeLoop(const scoped_refptr<DecoderBuffer>& input, | |
| 68 bool skip_eos_append); | |
| 69 | 81 |
| 70 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 71 base::WeakPtrFactory<FFmpegAudioDecoder> weak_factory_; | 83 base::WeakPtrFactory<FFmpegAudioDecoder> weak_factory_; |
| 72 base::WeakPtr<FFmpegAudioDecoder> weak_this_; | 84 base::WeakPtr<FFmpegAudioDecoder> weak_this_; |
| 73 | 85 |
| 74 DemuxerStream* demuxer_stream_; | 86 DecoderState state_; |
| 75 StatisticsCB statistics_cb_; | 87 |
| 88 // FFmpeg structures owned by this object. | |
| 76 scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; | 89 scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; |
| 90 scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_; | |
| 77 | 91 |
| 78 // Decoded audio format. | 92 // Decoded audio format. |
| 79 int bytes_per_channel_; | 93 int bytes_per_channel_; |
| 80 ChannelLayout channel_layout_; | 94 ChannelLayout channel_layout_; |
| 81 int channels_; | 95 int channels_; |
| 82 int samples_per_second_; | 96 int samples_per_second_; |
| 83 | 97 |
| 84 // AVSampleFormat initially requested; not Chrome's SampleFormat. | 98 // AVSampleFormat initially requested; not Chrome's SampleFormat. |
| 85 int av_sample_format_; | 99 int av_sample_format_; |
| 86 SampleFormat sample_format_; | 100 SampleFormat sample_format_; |
| 87 | 101 |
| 102 AudioDecoderConfig config_; | |
| 103 | |
| 88 // Used for computing output timestamps. | 104 // Used for computing output timestamps. |
| 89 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_; | 105 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_; |
| 90 base::TimeDelta last_input_timestamp_; | 106 base::TimeDelta last_input_timestamp_; |
| 91 | 107 |
| 92 // Number of frames to drop before generating output buffers. | 108 // Number of frames to drop before generating output buffers. |
| 93 int output_frames_to_drop_; | 109 int output_frames_to_drop_; |
| 94 | 110 |
| 95 // Holds decoded audio. | |
| 96 scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_; | |
| 97 | |
| 98 ReadCB read_cb_; | |
|
rileya (GONE FROM CHROMIUM)
2014/03/04 00:14:27
Conveniently, all of init/decode/reset/stop functi
| |
| 99 base::Closure stop_cb_; | |
| 100 base::Closure reset_cb_; | |
| 101 | |
| 102 // Since multiple frames may be decoded from the same packet we need to queue | 111 // Since multiple frames may be decoded from the same packet we need to queue |
| 103 // them up and hand them out as we receive Read() calls. | 112 // them up. |
| 104 std::list<QueuedAudioBuffer> queued_audio_; | 113 std::list<scoped_refptr<AudioBuffer> > queued_audio_; |
| 105 | 114 |
| 106 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 115 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); |
| 107 }; | 116 }; |
| 108 | 117 |
| 109 } // namespace media | 118 } // namespace media |
| 110 | 119 |
| 111 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 120 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
| OLD | NEW |