OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_OPUS_AUDIO_DECODER_H_ |
6 #define MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 6 #define MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
scherkus (not reviewing)
2012/12/14 23:39:28
are you using <list>?
Tom Finegan
2012/12/14 23:58:39
Done.
| |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "media/base/audio_decoder.h" | 11 #include "media/base/audio_decoder.h" |
12 #include "media/base/demuxer_stream.h" | 12 #include "media/base/demuxer_stream.h" |
13 | 13 |
14 struct AVCodecContext; | 14 struct OpusMSDecoder; |
15 struct AVFrame; | |
16 | 15 |
17 namespace base { | 16 namespace base { |
18 class MessageLoopProxy; | 17 class MessageLoopProxy; |
19 } | 18 } |
20 | 19 |
21 namespace media { | 20 namespace media { |
22 | 21 |
23 class AudioTimestampHelper; | 22 class AudioTimestampHelper; |
24 class DataBuffer; | 23 class DataBuffer; |
25 class DecoderBuffer; | 24 class DecoderBuffer; |
26 struct QueuedAudioBuffer; | 25 struct QueuedAudioBuffer; |
27 | 26 |
28 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { | 27 class MEDIA_EXPORT OpusAudioDecoder : public AudioDecoder { |
29 public: | 28 public: |
30 explicit FFmpegAudioDecoder( | 29 explicit OpusAudioDecoder( |
31 const scoped_refptr<base::MessageLoopProxy>& message_loop); | 30 const scoped_refptr<base::MessageLoopProxy>& message_loop); |
32 | 31 |
33 // AudioDecoder implementation. | 32 // AudioDecoder implementation. |
34 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, | 33 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, |
35 const PipelineStatusCB& status_cb, | 34 const PipelineStatusCB& status_cb, |
36 const StatisticsCB& statistics_cb) OVERRIDE; | 35 const StatisticsCB& statistics_cb) OVERRIDE; |
37 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 36 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
38 virtual int bits_per_channel() OVERRIDE; | 37 virtual int bits_per_channel() OVERRIDE; |
39 virtual ChannelLayout channel_layout() OVERRIDE; | 38 virtual ChannelLayout channel_layout() OVERRIDE; |
40 virtual int samples_per_second() OVERRIDE; | 39 virtual int samples_per_second() OVERRIDE; |
41 virtual void Reset(const base::Closure& closure) OVERRIDE; | 40 virtual void Reset(const base::Closure& closure) OVERRIDE; |
42 | 41 |
43 protected: | 42 protected: |
44 virtual ~FFmpegAudioDecoder(); | 43 virtual ~OpusAudioDecoder(); |
45 | 44 |
46 private: | 45 private: |
47 // Methods running on decoder thread. | 46 // Methods running on decoder thread. |
48 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, | 47 void DoInitialize(const scoped_refptr<DemuxerStream>& stream, |
49 const PipelineStatusCB& status_cb, | 48 const PipelineStatusCB& status_cb, |
50 const StatisticsCB& statistics_cb); | 49 const StatisticsCB& statistics_cb); |
51 void DoReset(const base::Closure& closure); | 50 void DoReset(const base::Closure& closure); |
52 void DoRead(const ReadCB& read_cb); | 51 void DoRead(const ReadCB& read_cb); |
53 void DoDecodeBuffer(DemuxerStream::Status status, | 52 void DoDecodeBuffer(DemuxerStream::Status status, |
54 const scoped_refptr<DecoderBuffer>& input); | 53 const scoped_refptr<DecoderBuffer>& input); |
55 | 54 |
56 // Reads from the demuxer stream with corresponding callback method. | 55 // Reads from the demuxer stream with corresponding callback method. |
57 void ReadFromDemuxerStream(); | 56 void ReadFromDemuxerStream(); |
58 | 57 |
59 bool ConfigureDecoder(); | 58 bool ConfigureDecoder(); |
60 void ReleaseFFmpegResources(); | 59 void CloseDecoder(); |
61 void ResetTimestampState(); | 60 void ResetTimestampState(); |
62 void RunDecodeLoop(const scoped_refptr<DecoderBuffer>& input, | 61 bool Decode(const scoped_refptr<DecoderBuffer>& input, |
63 bool skip_eos_append); | 62 bool skip_eos_append, |
63 scoped_refptr<DataBuffer>* output_buffer); | |
64 | 64 |
65 scoped_refptr<base::MessageLoopProxy> message_loop_; | 65 scoped_refptr<base::MessageLoopProxy> message_loop_; |
66 | 66 |
67 scoped_refptr<DemuxerStream> demuxer_stream_; | 67 scoped_refptr<DemuxerStream> demuxer_stream_; |
68 StatisticsCB statistics_cb_; | 68 StatisticsCB statistics_cb_; |
69 AVCodecContext* codec_context_; | 69 OpusMSDecoder* opus_decoder_; |
70 | 70 |
71 // Decoded audio format. | 71 // Decoded audio format. |
72 int bits_per_channel_; | 72 int bits_per_channel_; |
73 ChannelLayout channel_layout_; | 73 ChannelLayout channel_layout_; |
74 int samples_per_second_; | 74 int samples_per_second_; |
75 | 75 |
76 // Used for computing output timestamps. | 76 // Used for computing output timestamps. |
77 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_; | 77 scoped_ptr<AudioTimestampHelper> output_timestamp_helper_; |
78 int bytes_per_frame_; | |
79 base::TimeDelta last_input_timestamp_; | 78 base::TimeDelta last_input_timestamp_; |
80 | 79 |
81 // Number of output sample bytes to drop before generating | 80 // Number of output sample bytes to drop before generating |
82 // output buffers. | 81 // output buffers. |
83 int output_bytes_to_drop_; | 82 int output_bytes_to_drop_; |
84 | 83 |
85 // Holds decoded audio. | |
86 AVFrame* av_frame_; | |
87 | |
88 ReadCB read_cb_; | 84 ReadCB read_cb_; |
89 | 85 |
90 // Since multiple frames may be decoded from the same packet we need to queue | 86 int skip_samples_; |
91 // them up and hand them out as we receive Read() calls. | |
92 std::list<QueuedAudioBuffer> queued_audio_; | |
93 | 87 |
94 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 88 // Buffer for output from libopus. |
89 scoped_array<int16> output_buffer_; | |
90 | |
91 DISALLOW_IMPLICIT_CONSTRUCTORS(OpusAudioDecoder); | |
95 }; | 92 }; |
96 | 93 |
97 } // namespace media | 94 } // namespace media |
98 | 95 |
99 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 96 #endif // MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_ |
OLD | NEW |