| 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 #include "media/filters/ffmpeg_audio_decoder.h" | 5 #include "media/filters/ffmpeg_audio_decoder.h" |
| 6 | 6 |
| 7 #include "media/base/data_buffer.h" | 7 #include "media/base/data_buffer.h" |
| 8 #include "media/base/limits.h" | 8 #include "media/base/limits.h" |
| 9 #include "media/ffmpeg/ffmpeg_common.h" | 9 #include "media/ffmpeg/ffmpeg_common.h" |
| 10 #include "media/filters/ffmpeg_demuxer.h" | 10 #include "media/filters/ffmpeg_demuxer.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 // Size of the decoded audio buffer. | 25 // Size of the decoded audio buffer. |
| 26 const size_t FFmpegAudioDecoder::kOutputBufferSize = | 26 const size_t FFmpegAudioDecoder::kOutputBufferSize = |
| 27 AVCODEC_MAX_AUDIO_FRAME_SIZE; | 27 AVCODEC_MAX_AUDIO_FRAME_SIZE; |
| 28 | 28 |
| 29 FFmpegAudioDecoder::FFmpegAudioDecoder(MessageLoop* message_loop) | 29 FFmpegAudioDecoder::FFmpegAudioDecoder(MessageLoop* message_loop) |
| 30 : DecoderBase<AudioDecoder, Buffer>(message_loop), | 30 : DecoderBase<AudioDecoder, Buffer>(message_loop), |
| 31 codec_context_(NULL), | 31 codec_context_(NULL), |
| 32 config_(0, CHANNEL_LAYOUT_NONE, 0), | 32 bits_per_channel_(0), |
| 33 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 34 sample_rate_(0), |
| 33 estimated_next_timestamp_(kNoTimestamp) { | 35 estimated_next_timestamp_(kNoTimestamp) { |
| 34 } | 36 } |
| 35 | 37 |
| 36 FFmpegAudioDecoder::~FFmpegAudioDecoder() { | 38 FFmpegAudioDecoder::~FFmpegAudioDecoder() { |
| 37 } | 39 } |
| 38 | 40 |
| 39 void FFmpegAudioDecoder::DoInitialize(DemuxerStream* demuxer_stream, | 41 void FFmpegAudioDecoder::DoInitialize(DemuxerStream* demuxer_stream, |
| 40 bool* success, | 42 bool* success, |
| 41 Task* done_cb) { | 43 Task* done_cb) { |
| 42 base::ScopedTaskRunner done_runner(done_cb); | 44 base::ScopedTaskRunner done_runner(done_cb); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 63 << " sample rate: " << codec_context_->sample_rate; | 65 << " sample rate: " << codec_context_->sample_rate; |
| 64 return; | 66 return; |
| 65 } | 67 } |
| 66 | 68 |
| 67 // Serialize calls to avcodec_open(). | 69 // Serialize calls to avcodec_open(). |
| 68 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 70 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
| 69 if (!codec || avcodec_open(codec_context_, codec) < 0) { | 71 if (!codec || avcodec_open(codec_context_, codec) < 0) { |
| 70 return; | 72 return; |
| 71 } | 73 } |
| 72 | 74 |
| 73 config_.bits_per_channel = | 75 bits_per_channel_ = av_get_bits_per_sample_fmt(codec_context_->sample_fmt); |
| 74 av_get_bits_per_sample_fmt(codec_context_->sample_fmt); | 76 channel_layout_ = |
| 75 config_.channel_layout = | |
| 76 ChannelLayoutToChromeChannelLayout(codec_context_->channel_layout, | 77 ChannelLayoutToChromeChannelLayout(codec_context_->channel_layout, |
| 77 codec_context_->channels); | 78 codec_context_->channels); |
| 78 config_.sample_rate = codec_context_->sample_rate; | 79 sample_rate_ = codec_context_->sample_rate; |
| 79 | 80 |
| 80 // Prepare the output buffer. | 81 // Prepare the output buffer. |
| 81 output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); | 82 output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); |
| 82 if (!output_buffer_.get()) { | 83 if (!output_buffer_.get()) { |
| 83 host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); | 84 host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); |
| 84 return; | 85 return; |
| 85 } | 86 } |
| 86 *success = true; | 87 *success = true; |
| 87 } | 88 } |
| 88 | 89 |
| 89 AudioDecoderConfig FFmpegAudioDecoder::config() { | |
| 90 return config_; | |
| 91 } | |
| 92 | |
| 93 void FFmpegAudioDecoder::ProduceAudioSamples(scoped_refptr<Buffer> output) { | 90 void FFmpegAudioDecoder::ProduceAudioSamples(scoped_refptr<Buffer> output) { |
| 94 DecoderBase<AudioDecoder, Buffer>::PostReadTaskHack(output); | 91 DecoderBase<AudioDecoder, Buffer>::PostReadTaskHack(output); |
| 95 } | 92 } |
| 96 | 93 |
| 94 int FFmpegAudioDecoder::bits_per_channel() { |
| 95 return bits_per_channel_; |
| 96 } |
| 97 |
| 98 ChannelLayout FFmpegAudioDecoder::channel_layout() { |
| 99 return channel_layout_; |
| 100 } |
| 101 |
| 102 int FFmpegAudioDecoder::sample_rate() { |
| 103 return sample_rate_; |
| 104 } |
| 105 |
| 97 void FFmpegAudioDecoder::DoSeek(base::TimeDelta time, Task* done_cb) { | 106 void FFmpegAudioDecoder::DoSeek(base::TimeDelta time, Task* done_cb) { |
| 98 avcodec_flush_buffers(codec_context_); | 107 avcodec_flush_buffers(codec_context_); |
| 99 estimated_next_timestamp_ = kNoTimestamp; | 108 estimated_next_timestamp_ = kNoTimestamp; |
| 100 done_cb->Run(); | 109 done_cb->Run(); |
| 101 delete done_cb; | 110 delete done_cb; |
| 102 } | 111 } |
| 103 | 112 |
| 104 // ConvertAudioF32ToS32() converts float audio (F32) to int (S32) in place. | 113 // ConvertAudioF32ToS32() converts float audio (F32) to int (S32) in place. |
| 105 // This is a temporary solution. | 114 // This is a temporary solution. |
| 106 // The purpose of this short term fix is to enable WMApro, which decodes to | 115 // The purpose of this short term fix is to enable WMApro, which decodes to |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { | 261 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { |
| 253 int64 denominator = codec_context_->channels * | 262 int64 denominator = codec_context_->channels * |
| 254 av_get_bits_per_sample_fmt(codec_context_->sample_fmt) / 8 * | 263 av_get_bits_per_sample_fmt(codec_context_->sample_fmt) / 8 * |
| 255 codec_context_->sample_rate; | 264 codec_context_->sample_rate; |
| 256 double microseconds = size / | 265 double microseconds = size / |
| 257 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); | 266 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); |
| 258 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); | 267 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); |
| 259 } | 268 } |
| 260 | 269 |
| 261 } // namespace | 270 } // namespace |
| OLD | NEW |