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/weak_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/sample_format.h"
17 struct AVCodecContext
;
21 class MessageLoopProxy
;
26 class AudioTimestampHelper
;
28 struct QueuedAudioBuffer
;
30 class MEDIA_EXPORT FFmpegAudioDecoder
: public AudioDecoder
{
32 explicit FFmpegAudioDecoder(
33 const scoped_refptr
<base::MessageLoopProxy
>& message_loop
);
34 virtual ~FFmpegAudioDecoder();
36 // AudioDecoder implementation.
37 virtual void Initialize(DemuxerStream
* stream
,
38 const PipelineStatusCB
& status_cb
,
39 const StatisticsCB
& statistics_cb
) OVERRIDE
;
40 virtual void Read(const ReadCB
& read_cb
) OVERRIDE
;
41 virtual int bits_per_channel() OVERRIDE
;
42 virtual ChannelLayout
channel_layout() OVERRIDE
;
43 virtual int samples_per_second() OVERRIDE
;
44 virtual void Reset(const base::Closure
& closure
) OVERRIDE
;
47 // Reads from the demuxer stream with corresponding callback method.
48 void ReadFromDemuxerStream();
49 void BufferReady(DemuxerStream::Status status
,
50 const scoped_refptr
<DecoderBuffer
>& input
);
52 bool ConfigureDecoder();
53 void ReleaseFFmpegResources();
54 void ResetTimestampState();
55 void RunDecodeLoop(const scoped_refptr
<DecoderBuffer
>& input
,
56 bool skip_eos_append
);
58 scoped_refptr
<base::MessageLoopProxy
> message_loop_
;
59 base::WeakPtrFactory
<FFmpegAudioDecoder
> weak_factory_
;
60 base::WeakPtr
<FFmpegAudioDecoder
> weak_this_
;
62 DemuxerStream
* demuxer_stream_
;
63 StatisticsCB statistics_cb_
;
64 AVCodecContext
* codec_context_
;
66 // Decoded audio format.
67 int bits_per_channel_
;
68 ChannelLayout channel_layout_
;
70 int samples_per_second_
;
72 // AVSampleFormat initially requested; not Chrome's SampleFormat.
73 int av_sample_format_
;
74 SampleFormat sample_format_
;
76 // Used for computing output timestamps.
77 scoped_ptr
<AudioTimestampHelper
> output_timestamp_helper_
;
78 base::TimeDelta last_input_timestamp_
;
80 // Number of frames to drop before generating output buffers.
81 int output_frames_to_drop_
;
83 // Holds decoded audio.
88 // Since multiple frames may be decoded from the same packet we need to queue
89 // them up and hand them out as we receive Read() calls.
90 std::list
<QueuedAudioBuffer
> queued_audio_
;
92 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder
);
97 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_