#ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
#define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_
#include <list>
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "media/base/audio_decoder.h"
#include "media/base/demuxer_stream.h"
#include "media/base/sample_format.h"
#include "media/ffmpeg/ffmpeg_deleters.h"
struct AVCodecContext;
struct AVFrame;
namespace base {
class SingleThreadTaskRunner;
}
namespace media {
class AudioTimestampHelper;
class DecoderBuffer;
class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder {
public:
explicit FFmpegAudioDecoder(
const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
virtual ~FFmpegAudioDecoder();
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 scoped_refptr<AudioBuffer> GetDecodeOutput() OVERRIDE;
virtual void Reset(const base::Closure& closure) OVERRIDE;
virtual void Stop() OVERRIDE;
private:
enum DecoderState {
kUninitialized,
kNormal,
kFlushCodec,
kDecodeFinished,
kError
};
void DoReset();
void DecodeBuffer(const scoped_refptr<DecoderBuffer>& buffer,
const DecodeCB& decode_cb);
bool FFmpegDecode(const scoped_refptr<DecoderBuffer>& buffer);
bool ConfigureDecoder();
void ReleaseFFmpegResources();
void ResetTimestampState();
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
DecoderState state_;
scoped_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
scoped_ptr<AVFrame, ScopedPtrAVFreeFrame> av_frame_;
AudioDecoderConfig config_;
int av_sample_format_;
scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
base::TimeDelta last_input_timestamp_;
int output_frames_to_drop_;
std::list<scoped_refptr<AudioBuffer> > queued_audio_;
DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder);
};
}
#endif