OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 5 #ifndef MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "media/base/filters.h" | 11 #include "media/base/filters.h" |
12 | 12 |
13 struct AVCodecContext; | 13 struct AVCodecContext; |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 class DataBuffer; | 17 class DataBuffer; |
18 | 18 |
19 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { | 19 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
20 public: | 20 public: |
21 explicit FFmpegAudioDecoder(MessageLoop* message_loop); | 21 explicit FFmpegAudioDecoder(MessageLoop* message_loop); |
22 virtual ~FFmpegAudioDecoder(); | 22 virtual ~FFmpegAudioDecoder(); |
23 | 23 |
24 // Filter implementation. | 24 // Filter implementation. |
25 virtual void Flush(const base::Closure& callback) OVERRIDE; | 25 virtual void Flush(const base::Closure& callback) OVERRIDE; |
26 | 26 |
27 // AudioDecoder implementation. | 27 // AudioDecoder implementation. |
28 virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, | 28 virtual void Initialize(DemuxerStream* stream, const base::Closure& callback, |
29 const StatisticsCallback& stats_callback) OVERRIDE; | 29 const StatisticsCallback& stats_callback) OVERRIDE; |
30 virtual void ProduceAudioSamples(scoped_refptr<Buffer> output) OVERRIDE; | 30 virtual void Read(const ReadCB& callback) OVERRIDE; |
31 virtual int bits_per_channel() OVERRIDE; | 31 virtual int bits_per_channel() OVERRIDE; |
32 virtual ChannelLayout channel_layout() OVERRIDE; | 32 virtual ChannelLayout channel_layout() OVERRIDE; |
33 virtual int samples_per_second() OVERRIDE; | 33 virtual int samples_per_second() OVERRIDE; |
34 | 34 |
35 private: | 35 private: |
36 // Methods running on decoder thread. | 36 // Methods running on decoder thread. |
37 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, | 37 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, |
38 const base::Closure& callback, | 38 const base::Closure& callback, |
39 const StatisticsCallback& stats_callback); | 39 const StatisticsCallback& stats_callback); |
40 void DoFlush(const base::Closure& callback); | 40 void DoFlush(const base::Closure& callback); |
41 void DoProduceAudioSamples(const scoped_refptr<Buffer>& output); | 41 void DoRead(const ReadCB& callback); |
42 void DoDecodeBuffer(const scoped_refptr<Buffer>& input); | 42 void DoDecodeBuffer(const scoped_refptr<Buffer>& input); |
43 | 43 |
44 // Reads from the demuxer stream with corresponding callback method. | 44 // Reads from the demuxer stream with corresponding callback method. |
45 void ReadFromDemuxerStream(); | 45 void ReadFromDemuxerStream(); |
46 void DecodeBuffer(const scoped_refptr<Buffer>& buffer); | 46 void DecodeBuffer(const scoped_refptr<Buffer>& buffer); |
47 | 47 |
48 // Updates the output buffer's duration and timestamp based on the input | 48 // Updates the output buffer's duration and timestamp based on the input |
49 // buffer. Will fall back to an estimated timestamp if the input lacks a | 49 // buffer. Will fall back to an estimated timestamp if the input lacks a |
50 // valid timestamp. | 50 // valid timestamp. |
51 void UpdateDurationAndTimestamp(const Buffer* input, DataBuffer* output); | 51 void UpdateDurationAndTimestamp(const Buffer* input, DataBuffer* output); |
52 | 52 |
53 // Calculates duration based on size of decoded audio bytes. | 53 // Calculates duration based on size of decoded audio bytes. |
54 base::TimeDelta CalculateDuration(int size); | 54 base::TimeDelta CalculateDuration(int size); |
55 | 55 |
| 56 // Delivers decoded samples to |read_cb_| and resets the callback. |
| 57 void DeliverSamples(const scoped_refptr<Buffer>& samples); |
| 58 |
56 MessageLoop* message_loop_; | 59 MessageLoop* message_loop_; |
57 | 60 |
58 scoped_refptr<DemuxerStream> demuxer_stream_; | 61 scoped_refptr<DemuxerStream> demuxer_stream_; |
59 StatisticsCallback stats_callback_; | 62 StatisticsCallback stats_callback_; |
60 AVCodecContext* codec_context_; | 63 AVCodecContext* codec_context_; |
61 | 64 |
62 // Decoded audio format. | 65 // Decoded audio format. |
63 int bits_per_channel_; | 66 int bits_per_channel_; |
64 ChannelLayout channel_layout_; | 67 ChannelLayout channel_layout_; |
65 int samples_per_second_; | 68 int samples_per_second_; |
66 | 69 |
67 base::TimeDelta estimated_next_timestamp_; | 70 base::TimeDelta estimated_next_timestamp_; |
68 | 71 |
69 // Holds decoded audio. As required by FFmpeg, input/output buffers should | 72 // Holds decoded audio. As required by FFmpeg, input/output buffers should |
70 // be allocated with suitable padding and alignment. av_malloc() provides | 73 // be allocated with suitable padding and alignment. av_malloc() provides |
71 // us that guarantee. | 74 // us that guarantee. |
72 const int decoded_audio_size_; | 75 const int decoded_audio_size_; |
73 uint8* decoded_audio_; // Allocated via av_malloc(). | 76 uint8* decoded_audio_; // Allocated via av_malloc(). |
74 | 77 |
75 // Holds downstream-provided buffers. | 78 ReadCB read_cb_; |
76 std::list<scoped_refptr<Buffer> > output_buffers_; | |
77 | |
78 // Tracks reads issued for compressed data. | |
79 int pending_reads_; | |
80 | 79 |
81 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 80 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); |
82 }; | 81 }; |
83 | 82 |
84 } // namespace media | 83 } // namespace media |
85 | 84 |
86 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 85 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
OLD | NEW |