Index: media/filters/ffmpeg_audio_decoder.h |
diff --git a/media/filters/ffmpeg_audio_decoder.h b/media/filters/ffmpeg_audio_decoder.h |
index 42bce45109ab5a5b82d2002a0356dac5fdc6660e..605ac9f763857357525132466c63317d2377202a 100644 |
--- a/media/filters/ffmpeg_audio_decoder.h |
+++ b/media/filters/ffmpeg_audio_decoder.h |
@@ -37,15 +37,16 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
virtual ~FFmpegAudioDecoder(); |
// AudioDecoder implementation. |
- virtual void Initialize(DemuxerStream* stream, |
- const PipelineStatusCB& status_cb, |
- const StatisticsCB& statistics_cb) OVERRIDE; |
- virtual void Read(const ReadCB& read_cb) OVERRIDE; |
+ virtual void Initialize(const AudioDecoderConfig& config, |
+ const PipelineStatusCB& status_cb) OVERRIDE; |
+ virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer, |
+ const DecodeCB& decode_cb) OVERRIDE; |
virtual int bits_per_channel() OVERRIDE; |
virtual ChannelLayout channel_layout() OVERRIDE; |
virtual int samples_per_second() OVERRIDE; |
virtual void Reset(const base::Closure& closure) OVERRIDE; |
virtual void Stop(const base::Closure& closure) OVERRIDE; |
+ virtual bool HasQueuedData() const OVERRIDE; |
// Callback called from within FFmpeg to allocate a buffer based on |
// the dimensions of |codec_context|. See AVCodecContext.get_buffer2 |
@@ -53,27 +54,43 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
int GetAudioBuffer(AVCodecContext* codec, AVFrame* frame, int flags); |
private: |
- void DoStop(); |
+ |
+ enum DecoderState { |
+ kUninitialized, |
+ kNormal, |
+ kFlushCodec, |
+ kDecodeFinished, |
+ kError |
+ }; |
+ |
+ // Reset decoder and call |reset_cb_|. |
void DoReset(); |
- // Reads from the demuxer stream with corresponding callback method. |
- void ReadFromDemuxerStream(); |
- void BufferReady(DemuxerStream::Status status, |
- const scoped_refptr<DecoderBuffer>& input); |
+ // Handles decoding an unencrypted encoded buffer. |
+ void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer); |
+ bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer); |
+ // Handles (re-)initializing the decoder with a (new) config. |
+ // Returns true if initialization was successful. |
bool ConfigureDecoder(); |
+ |
+ // Releases resources associated with |codec_context_| and |av_frame_| |
+ // and resets them to NULL. |
void ReleaseFFmpegResources(); |
void ResetTimestampState(); |
- void RunDecodeLoop(const scoped_refptr<DecoderBuffer>& input, |
- bool skip_eos_append); |
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
base::WeakPtrFactory<FFmpegAudioDecoder> weak_factory_; |
base::WeakPtr<FFmpegAudioDecoder> weak_this_; |
- DemuxerStream* demuxer_stream_; |
- StatisticsCB statistics_cb_; |
+ DecoderState state_; |
+ |
+ DecodeCB decode_cb_; |
+ base::Closure reset_cb_; |
+ |
+ // FFmpeg structures owned by this object. |
scoped_ptr_malloc<AVCodecContext, ScopedPtrAVFreeContext> codec_context_; |
+ scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_; |
// Decoded audio format. |
int bytes_per_channel_; |
@@ -85,6 +102,9 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
int av_sample_format_; |
SampleFormat sample_format_; |
+ |
+ AudioDecoderConfig config_; |
+ |
// Used for computing output timestamps. |
scoped_ptr<AudioTimestampHelper> output_timestamp_helper_; |
base::TimeDelta last_input_timestamp_; |
@@ -92,13 +112,6 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
// Number of frames to drop before generating output buffers. |
int output_frames_to_drop_; |
- // Holds decoded audio. |
- scoped_ptr_malloc<AVFrame, ScopedPtrAVFreeFrame> av_frame_; |
- |
- ReadCB read_cb_; |
- base::Closure stop_cb_; |
- base::Closure reset_cb_; |
- |
// Since multiple frames may be decoded from the same packet we need to queue |
// them up and hand them out as we receive Read() calls. |
std::list<QueuedAudioBuffer> queued_audio_; |