Chromium Code Reviews| 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> |
| 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, bool skip_eos_append); |
| 63 bool skip_eos_append); | |
| 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 // Since multiple frames may be decoded from the same packet we need to queue |
| 91 // them up and hand them out as we receive Read() calls. | 85 // them up and hand them out as we receive Read() calls. |
| 92 std::list<QueuedAudioBuffer> queued_audio_; | 86 std::list<QueuedAudioBuffer> queued_audio_; |
| 93 | 87 |
| 94 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 88 int skip_samples_; |
| 89 int delay_; | |
|
fgalligan1
2012/12/13 22:30:14
You could remove this if we are not using it yet.
Tom Finegan
2012/12/13 23:20:00
Done.
| |
| 90 | |
| 91 // Buffer for output from libopus. | |
| 92 scoped_array<uint8> output_buffer_; | |
| 93 | |
| 94 DISALLOW_IMPLICIT_CONSTRUCTORS(OpusAudioDecoder); | |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 } // namespace media | 97 } // namespace media |
| 98 | 98 |
| 99 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 99 #endif // MEDIA_FILTERS_OPUS_AUDIO_DECODER_H_ |
| OLD | NEW |