| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/data_buffer.h" | 5 #include "media/base/data_buffer.h" |
| 6 #include "media/filters/ffmpeg_audio_decoder.h" | 6 #include "media/filters/ffmpeg_audio_decoder.h" |
| 7 #include "media/filters/ffmpeg_common.h" | 7 #include "media/filters/ffmpeg_common.h" |
| 8 #include "media/filters/ffmpeg_demuxer.h" | 8 #include "media/filters/ffmpeg_demuxer.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 media_format_.SetAsInteger(MediaFormat::kSampleBits, | 60 media_format_.SetAsInteger(MediaFormat::kSampleBits, |
| 61 av_get_bits_per_sample_format(codec_context_->sample_fmt)); | 61 av_get_bits_per_sample_format(codec_context_->sample_fmt)); |
| 62 media_format_.SetAsInteger(MediaFormat::kSampleRate, | 62 media_format_.SetAsInteger(MediaFormat::kSampleRate, |
| 63 codec_context_->sample_rate); | 63 codec_context_->sample_rate); |
| 64 media_format_.SetAsString(MediaFormat::kMimeType, | 64 media_format_.SetAsString(MediaFormat::kMimeType, |
| 65 mime_type::kUncompressedAudio); | 65 mime_type::kUncompressedAudio); |
| 66 | 66 |
| 67 // Prepare the output buffer. | 67 // Prepare the output buffer. |
| 68 output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); | 68 output_buffer_.reset(static_cast<uint8*>(av_malloc(kOutputBufferSize))); |
| 69 if (!output_buffer_.get()) { | 69 if (!output_buffer_.get()) { |
| 70 host()->Error(PIPELINE_ERROR_OUT_OF_MEMORY); | 70 host()->SetError(PIPELINE_ERROR_OUT_OF_MEMORY); |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void FFmpegAudioDecoder::OnStop() { | 76 void FFmpegAudioDecoder::OnStop() { |
| 77 } | 77 } |
| 78 | 78 |
| 79 void FFmpegAudioDecoder::OnDecode(Buffer* input) { | 79 void FFmpegAudioDecoder::OnDecode(Buffer* input) { |
| 80 // Check for discontinuous buffer. If we receive a discontinuous buffer here, | 80 // Check for discontinuous buffer. If we receive a discontinuous buffer here, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 94 int result = avcodec_decode_audio3(codec_context_, | 94 int result = avcodec_decode_audio3(codec_context_, |
| 95 output_buffer, | 95 output_buffer, |
| 96 &output_buffer_size, | 96 &output_buffer_size, |
| 97 &packet); | 97 &packet); |
| 98 | 98 |
| 99 // TODO(ajwong): Consider if kOutputBufferSize should just be an int instead | 99 // TODO(ajwong): Consider if kOutputBufferSize should just be an int instead |
| 100 // of a size_t. | 100 // of a size_t. |
| 101 if (result < 0 || | 101 if (result < 0 || |
| 102 output_buffer_size < 0 || | 102 output_buffer_size < 0 || |
| 103 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) { | 103 static_cast<size_t>(output_buffer_size) > kOutputBufferSize) { |
| 104 host()->Error(PIPELINE_ERROR_DECODE); | 104 host()->SetError(PIPELINE_ERROR_DECODE); |
| 105 return; | 105 return; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // If we have decoded something, enqueue the result. | 108 // If we have decoded something, enqueue the result. |
| 109 if (output_buffer_size) { | 109 if (output_buffer_size) { |
| 110 DataBuffer* result_buffer = new DataBuffer(output_buffer_size); | 110 DataBuffer* result_buffer = new DataBuffer(output_buffer_size); |
| 111 uint8* data = result_buffer->GetWritableData(); | 111 uint8* data = result_buffer->GetWritableData(); |
| 112 memcpy(data, output_buffer, output_buffer_size); | 112 memcpy(data, output_buffer, output_buffer_size); |
| 113 | 113 |
| 114 // Determine the duration if the demuxer couldn't figure it out, otherwise | 114 // Determine the duration if the demuxer couldn't figure it out, otherwise |
| (...skipping 26 matching lines...) Expand all Loading... |
| 141 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { | 141 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { |
| 142 int64 denominator = codec_context_->channels * | 142 int64 denominator = codec_context_->channels * |
| 143 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * | 143 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * |
| 144 codec_context_->sample_rate; | 144 codec_context_->sample_rate; |
| 145 double microseconds = size / | 145 double microseconds = size / |
| 146 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); | 146 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); |
| 147 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); | 147 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace | 150 } // namespace |
| OLD | NEW |