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