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_AUDIO_DECODER_H_
6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "media/base/audio_decoder.h"
14 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_log.h"
16 #include "media/base/sample_format.h"
17 #include "media/ffmpeg/ffmpeg_deleters.h"
19 struct AVCodecContext;
23 class SingleThreadTaskRunner;
28 class AudioDiscardHelper;
31 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder {
34 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
36 virtual ~FFmpegAudioDecoder();
38 // AudioDecoder implementation.
39 virtual void Initialize(const AudioDecoderConfig& config,
40 const PipelineStatusCB& status_cb) OVERRIDE;
41 virtual void Decode(const scoped_refptr<DecoderBuffer>& buffer,
42 const DecodeCB& decode_cb) OVERRIDE;
43 virtual scoped_refptr<AudioBuffer> GetDecodeOutput() OVERRIDE;
44 virtual void Reset(const base::Closure& closure) OVERRIDE;
45 virtual void Stop() OVERRIDE;
56 // Reset decoder and call |reset_cb_|.
59 // Handles decoding an unencrypted encoded buffer.
60 void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer,
61 const DecodeCB& decode_cb);
62 bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer);
64 // Handles (re-)initializing the decoder with a (new) config.
65 // Returns true if initialization was successful.
66 bool ConfigureDecoder();
68 // Releases resources associated with |codec_context_| and |av_frame_|
69 // and resets them to NULL.
70 void ReleaseFFmpegResources();
71 void ResetTimestampState();
73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
77 // FFmpeg structures owned by this object.
78 scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
79 scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
81 AudioDecoderConfig config_;
83 // AVSampleFormat initially requested; not Chrome's SampleFormat.
84 int av_sample_format_;
86 scoped_ptr<AudioDiscardHelper> discard_helper_;
88 // Since multiple frames may be decoded from the same packet we need to queue
90 std::list<scoped_refptr<AudioBuffer> > queued_audio_;
94 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder);
99 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_