cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / filters / ffmpeg_audio_decoder.h
blob7ea8615c2edd1324029e086a609617c97e8870b5
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_
8 #include <list>
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;
18 struct AVFrame;
20 namespace base {
21 class MessageLoopProxy;
24 namespace media {
26 class AudioTimestampHelper;
27 class DecoderBuffer;
28 struct QueuedAudioBuffer;
30 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder {
31 public:
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;
46 // Callback called from within FFmpeg to allocate a buffer based on
47 // the dimensions of |codec_context|. See AVCodecContext.get_buffer2
48 // documentation inside FFmpeg.
49 int GetAudioBuffer(AVCodecContext* codec, AVFrame* frame, int flags);
51 private:
52 // Reads from the demuxer stream with corresponding callback method.
53 void ReadFromDemuxerStream();
54 void BufferReady(DemuxerStream::Status status,
55 const scoped_refptr<DecoderBuffer>& input);
57 bool ConfigureDecoder();
58 void ReleaseFFmpegResources();
59 void ResetTimestampState();
60 void RunDecodeLoop(const scoped_refptr<DecoderBuffer>& input,
61 bool skip_eos_append);
63 scoped_refptr<base::MessageLoopProxy> message_loop_;
64 base::WeakPtrFactory<FFmpegAudioDecoder> weak_factory_;
65 base::WeakPtr<FFmpegAudioDecoder> weak_this_;
67 DemuxerStream* demuxer_stream_;
68 StatisticsCB statistics_cb_;
69 AVCodecContext* codec_context_;
71 // Decoded audio format.
72 int bytes_per_channel_;
73 ChannelLayout channel_layout_;
74 int channels_;
75 int samples_per_second_;
77 // AVSampleFormat initially requested; not Chrome's SampleFormat.
78 int av_sample_format_;
79 SampleFormat sample_format_;
81 // Used for computing output timestamps.
82 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_;
83 base::TimeDelta last_input_timestamp_;
85 // Number of frames to drop before generating output buffers.
86 int output_frames_to_drop_;
88 // Holds decoded audio.
89 AVFrame* av_frame_;
91 ReadCB read_cb_;
93 // Since multiple frames may be decoded from the same packet we need to queue
94 // them up and hand them out as we receive Read() calls.
95 std::list<QueuedAudioBuffer> queued_audio_;
97 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder);
100 } // namespace media
102 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_