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 "media/filters/decoder_base.h" | 8 #include <list> |
9 | |
10 #include "base/message_loop.h" | |
11 #include "media/base/filters.h" | |
9 | 12 |
10 struct AVCodecContext; | 13 struct AVCodecContext; |
11 | 14 |
12 namespace media { | 15 namespace media { |
13 | 16 |
14 // Forward declaration for scoped_ptr_malloc. | 17 class DataBuffer; |
15 class ScopedPtrAVFree; | |
16 | 18 |
17 class MEDIA_EXPORT FFmpegAudioDecoder | 19 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
18 : public DecoderBase<AudioDecoder, Buffer> { | |
19 public: | 20 public: |
20 explicit FFmpegAudioDecoder(MessageLoop* message_loop); | 21 explicit FFmpegAudioDecoder(MessageLoop* message_loop); |
21 virtual ~FFmpegAudioDecoder(); | 22 virtual ~FFmpegAudioDecoder(); |
22 | 23 |
24 // Filter implementation. | |
25 virtual void Flush(FilterCallback* callback); | |
acolwell GONE FROM CHROMIUM
2011/09/13 22:09:28
OVERRIDE this and methods below.
scherkus (not reviewing)
2011/09/16 18:10:13
Done.
| |
26 | |
23 // AudioDecoder implementation. | 27 // AudioDecoder implementation. |
28 virtual void Initialize(DemuxerStream* stream, FilterCallback* callback, | |
29 StatisticsCallback* stats_callback); | |
24 virtual AudioDecoderConfig config(); | 30 virtual AudioDecoderConfig config(); |
acolwell GONE FROM CHROMIUM
2011/09/13 22:09:28
const AudioDecoderConfig& config() const?
scherkus (not reviewing)
2011/09/16 18:10:13
this is going away in follow up CL
| |
25 virtual void ProduceAudioSamples(scoped_refptr<Buffer> output); | 31 virtual void ProduceAudioSamples(scoped_refptr<Buffer> buffer); |
26 | |
27 protected: | |
28 virtual void DoInitialize(DemuxerStream* demuxer_stream, bool* success, | |
29 Task* done_cb); | |
30 | |
31 virtual void DoSeek(base::TimeDelta time, Task* done_cb); | |
32 | |
33 virtual void DoDecode(Buffer* input); | |
34 | 32 |
35 private: | 33 private: |
36 // Calculates the duration of an audio buffer based on the sample rate, | 34 // Methods running on decoder thread. |
37 // channels and bits per sample given the size in bytes. | 35 void DoInitialize(DemuxerStream* stream, |
38 base::TimeDelta CalculateDuration(size_t size); | 36 FilterCallback* callback, |
37 StatisticsCallback* stats_callback); | |
38 void DoFlush(FilterCallback* callback); | |
39 void DoQueueOutput(scoped_refptr<Buffer> output); | |
40 void DoDecodeInput(scoped_refptr<Buffer> input); | |
39 | 41 |
40 // A FFmpeg defined structure that holds decoder information, this variable | 42 // Reads from the demuxer stream with corresponding callback method. |
41 // is initialized in OnInitialize(). | 43 void ReadFromDemuxerStream(); |
44 void OnReadComplete(Buffer* buffer); | |
45 | |
46 // Updates the output buffer's duration and timestamp based on the input | |
47 // buffer. Will fall back to an estimated timestamp if the input lacks a | |
48 // valid timestamp. | |
49 void UpdateDurationAndTimestamp(const Buffer* input, DataBuffer* output); | |
50 | |
51 // Calculates duration based on size of decoded audio bytes. | |
52 base::TimeDelta CalculateDuration(int size); | |
53 | |
54 MessageLoop* message_loop_; | |
55 | |
56 scoped_refptr<DemuxerStream> demuxer_stream_; | |
57 scoped_ptr<StatisticsCallback> stats_callback_; | |
42 AVCodecContext* codec_context_; | 58 AVCodecContext* codec_context_; |
43 | 59 |
44 AudioDecoderConfig config_; | 60 AudioDecoderConfig config_; |
45 | 61 |
46 // Estimated timestamp for next packet. Useful for packets without timestamps. | |
47 base::TimeDelta estimated_next_timestamp_; | 62 base::TimeDelta estimated_next_timestamp_; |
48 | 63 |
49 // Data buffer to carry decoded raw PCM samples. This buffer is created by | 64 // Holds decoded audio. |
50 // av_malloc() and is used throughout the lifetime of this class. | 65 const int decoded_audio_size_; |
51 scoped_ptr_malloc<uint8, ScopedPtrAVFree> output_buffer_; | 66 scoped_array<uint8> decoded_audio_; |
52 | 67 |
53 static const size_t kOutputBufferSize; | 68 // Holds downstream-provided buffers. |
69 std::list<scoped_refptr<Buffer> > output_buffers_; | |
54 | 70 |
55 DISALLOW_COPY_AND_ASSIGN(FFmpegAudioDecoder); | 71 // Tracks reads issued for compressed data. |
72 int pending_reads_; | |
73 | |
74 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | |
56 }; | 75 }; |
57 | 76 |
58 } // namespace media | 77 } // namespace media |
59 | 78 |
60 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 79 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
OLD | NEW |