| 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_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/callback.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "media/base/audio_decoder.h" | 12 #include "media/base/audio_decoder.h" |
| 12 | 13 |
| 13 struct AVCodecContext; | 14 struct AVCodecContext; |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 class DataBuffer; | 18 class DataBuffer; |
| 18 | 19 |
| 19 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { | 20 class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { |
| 20 public: | 21 public: |
| 21 explicit FFmpegAudioDecoder(MessageLoop* message_loop); | 22 FFmpegAudioDecoder(const base::Callback<MessageLoop*()>& message_loop_cb); |
| 22 virtual ~FFmpegAudioDecoder(); | 23 virtual ~FFmpegAudioDecoder(); |
| 23 | 24 |
| 24 // AudioDecoder implementation. | 25 // AudioDecoder implementation. |
| 25 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, | 26 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, |
| 26 const PipelineStatusCB& pipeline_status_cb, | 27 const PipelineStatusCB& pipeline_status_cb, |
| 27 const StatisticsCB& statistics_cb) OVERRIDE; | 28 const StatisticsCB& statistics_cb) OVERRIDE; |
| 28 virtual void Read(const ReadCB& read_cb) OVERRIDE; | 29 virtual void Read(const ReadCB& read_cb) OVERRIDE; |
| 29 virtual int bits_per_channel() OVERRIDE; | 30 virtual int bits_per_channel() OVERRIDE; |
| 30 virtual ChannelLayout channel_layout() OVERRIDE; | 31 virtual ChannelLayout channel_layout() OVERRIDE; |
| 31 virtual int samples_per_second() OVERRIDE; | 32 virtual int samples_per_second() OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 // 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 |
| 49 // valid timestamp. | 50 // valid timestamp. |
| 50 void UpdateDurationAndTimestamp(const Buffer* input, DataBuffer* output); | 51 void UpdateDurationAndTimestamp(const Buffer* input, DataBuffer* output); |
| 51 | 52 |
| 52 // Calculates duration based on size of decoded audio bytes. | 53 // Calculates duration based on size of decoded audio bytes. |
| 53 base::TimeDelta CalculateDuration(int size); | 54 base::TimeDelta CalculateDuration(int size); |
| 54 | 55 |
| 55 // Delivers decoded samples to |read_cb_| and resets the callback. | 56 // Delivers decoded samples to |read_cb_| and resets the callback. |
| 56 void DeliverSamples(const scoped_refptr<Buffer>& samples); | 57 void DeliverSamples(const scoped_refptr<Buffer>& samples); |
| 57 | 58 |
| 59 // This is !is_null() iff Initialize() hasn't been called. |
| 60 base::Callback<MessageLoop*()> message_loop_factory_cb_; |
| 58 MessageLoop* message_loop_; | 61 MessageLoop* message_loop_; |
| 59 | 62 |
| 60 scoped_refptr<DemuxerStream> demuxer_stream_; | 63 scoped_refptr<DemuxerStream> demuxer_stream_; |
| 61 StatisticsCB statistics_cb_; | 64 StatisticsCB statistics_cb_; |
| 62 AVCodecContext* codec_context_; | 65 AVCodecContext* codec_context_; |
| 63 | 66 |
| 64 // Decoded audio format. | 67 // Decoded audio format. |
| 65 int bits_per_channel_; | 68 int bits_per_channel_; |
| 66 ChannelLayout channel_layout_; | 69 ChannelLayout channel_layout_; |
| 67 int samples_per_second_; | 70 int samples_per_second_; |
| 68 | 71 |
| 69 base::TimeDelta estimated_next_timestamp_; | 72 base::TimeDelta estimated_next_timestamp_; |
| 70 | 73 |
| 71 // Holds decoded audio. As required by FFmpeg, input/output buffers should | 74 // Holds decoded audio. As required by FFmpeg, input/output buffers should |
| 72 // be allocated with suitable padding and alignment. av_malloc() provides | 75 // be allocated with suitable padding and alignment. av_malloc() provides |
| 73 // us that guarantee. | 76 // us that guarantee. |
| 74 const int decoded_audio_size_; | 77 const int decoded_audio_size_; |
| 75 uint8* decoded_audio_; // Allocated via av_malloc(). | 78 uint8* decoded_audio_; // Allocated via av_malloc(). |
| 76 | 79 |
| 77 ReadCB read_cb_; | 80 ReadCB read_cb_; |
| 78 | 81 |
| 79 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); | 82 DISALLOW_IMPLICIT_CONSTRUCTORS(FFmpegAudioDecoder); |
| 80 }; | 83 }; |
| 81 | 84 |
| 82 } // namespace media | 85 } // namespace media |
| 83 | 86 |
| 84 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ | 87 #endif // MEDIA_FILTERS_FFMPEG_AUDIO_DECODER_H_ |
| OLD | NEW |