Index: media/filters/ffmpeg_audio_decoder.h |
diff --git a/media/filters/ffmpeg_audio_decoder.h b/media/filters/ffmpeg_audio_decoder.h |
index e92a8517fcf74d4f714bc3fcac6222e3ae71617a..999e37ca2d01e922086a02d8d73ff2108ac635fc 100644 |
--- a/media/filters/ffmpeg_audio_decoder.h |
+++ b/media/filters/ffmpeg_audio_decoder.h |
@@ -5,42 +5,58 @@ |
#ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
#define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
-#include "media/filters/decoder_base.h" |
+#include <list> |
+ |
+#include "base/message_loop.h" |
+#include "media/base/filters.h" |
struct AVCodecContext; |
namespace media { |
-// Forward declaration for scoped_ptr_malloc. |
-class ScopedPtrAVFree; |
+class DataBuffer; |
-class MEDIA_EXPORT FFmpegAudioDecoder |
- : public DecoderBase<AudioDecoder, Buffer> { |
+class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
public: |
explicit FFmpegAudioDecoder(MessageLoop* message_loop); |
virtual ~FFmpegAudioDecoder(); |
- // AudioDecoder implementation. |
- virtual void ProduceAudioSamples(scoped_refptr<Buffer> output); |
- virtual int bits_per_channel(); |
- virtual ChannelLayout channel_layout(); |
- virtual int sample_rate(); |
- |
- protected: |
- virtual void DoInitialize(DemuxerStream* demuxer_stream, bool* success, |
- Task* done_cb); |
- |
- virtual void DoSeek(base::TimeDelta time, Task* done_cb); |
+ // Filter implementation. |
+ virtual void Flush(FilterCallback* callback) OVERRIDE; |
- virtual void DoDecode(Buffer* input); |
+ // AudioDecoder implementation. |
+ virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, |
+ StatisticsCallback* stats_callback) OVERRIDE; |
+ virtual void ProduceAudioSamples(scoped_refptr<Buffer> output) OVERRIDE; |
+ virtual int bits_per_channel() OVERRIDE; |
+ virtual ChannelLayout channel_layout() OVERRIDE; |
+ virtual int sample_rate() OVERRIDE; |
private: |
- // Calculates the duration of an audio buffer based on the sample rate, |
- // channels and bits per sample given the size in bytes. |
- base::TimeDelta CalculateDuration(size_t size); |
- |
- // A FFmpeg defined structure that holds decoder information, this variable |
- // is initialized in OnInitialize(). |
+ // Methods running on decoder thread. |
+ void DoInitialize(const scoped_refptr<DemuxerStream>& stream, |
+ FilterCallback* callback, |
+ StatisticsCallback* stats_callback); |
+ void DoFlush(FilterCallback* callback); |
+ void DoProduceAudioSamples(const scoped_refptr<Buffer>& output); |
+ void DoDecodeBuffer(const scoped_refptr<Buffer>& input); |
+ |
+ // Reads from the demuxer stream with corresponding callback method. |
+ void ReadFromDemuxerStream(); |
+ void DecodeBuffer(Buffer* buffer); |
+ |
+ // Updates the output buffer's duration and timestamp based on the input |
+ // buffer. Will fall back to an estimated timestamp if the input lacks a |
+ // valid timestamp. |
+ void UpdateDurationAndTimestamp(const Buffer* input, DataBuffer* output); |
+ |
+ // Calculates duration based on size of decoded audio bytes. |
+ base::TimeDelta CalculateDuration(int size); |
+ |
+ MessageLoop* message_loop_; |
+ |
+ scoped_refptr<DemuxerStream> demuxer_stream_; |
+ scoped_ptr<StatisticsCallback> stats_callback_; |
AVCodecContext* codec_context_; |
// Decoded audio format. |
@@ -48,16 +64,21 @@ class MEDIA_EXPORT FFmpegAudioDecoder |
ChannelLayout channel_layout_; |
int sample_rate_; |
- // Estimated timestamp for next packet. Useful for packets without timestamps. |
base::TimeDelta estimated_next_timestamp_; |
- // Data buffer to carry decoded raw PCM samples. This buffer is created by |
- // av_malloc() and is used throughout the lifetime of this class. |
- scoped_ptr_malloc<uint8, ScopedPtrAVFree> output_buffer_; |
+ // Holds decoded audio. As required by FFmpeg, input/output buffers should |
+ // be allocated with suitable padding and alignment. av_malloc() provides |
+ // us that guarantee. |
+ const int decoded_audio_size_; |
+ uint8* decoded_audio_; // Allocated via av_malloc(). |
+ |
+ // Holds downstream-provided buffers. |
+ std::list<scoped_refptr<Buffer> > output_buffers_; |
- static const size_t kOutputBufferSize; |
+ // Tracks reads issued for compressed data. |
+ int pending_reads_; |
- DISALLOW_COPY_AND_ASSIGN(FFmpegAudioDecoder); |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); |
}; |
} // namespace media |