| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()->Error(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 result_buffer->SetDataSize(output_buffer_size); |
| 111 uint8* data = result_buffer->GetWritableData(); | 112 uint8* data = result_buffer->GetWritableData(); |
| 112 memcpy(data, output_buffer, output_buffer_size); | 113 memcpy(data, output_buffer, output_buffer_size); |
| 113 | 114 |
| 114 // Determine the duration if the demuxer couldn't figure it out, otherwise | 115 // Determine the duration if the demuxer couldn't figure it out, otherwise |
| 115 // copy it over. | 116 // copy it over. |
| 116 if (input->GetDuration().InMicroseconds() == 0) { | 117 if (input->GetDuration().InMicroseconds() == 0) { |
| 117 result_buffer->SetDuration(CalculateDuration(output_buffer_size)); | 118 result_buffer->SetDuration(CalculateDuration(output_buffer_size)); |
| 118 } else { | 119 } else { |
| 119 result_buffer->SetDuration(input->GetDuration()); | 120 result_buffer->SetDuration(input->GetDuration()); |
| 120 } | 121 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 141 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { | 142 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { |
| 142 int64 denominator = codec_context_->channels * | 143 int64 denominator = codec_context_->channels * |
| 143 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * | 144 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * |
| 144 codec_context_->sample_rate; | 145 codec_context_->sample_rate; |
| 145 double microseconds = size / | 146 double microseconds = size / |
| 146 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); | 147 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); |
| 147 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); | 148 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); |
| 148 } | 149 } |
| 149 | 150 |
| 150 } // namespace | 151 } // namespace |
| OLD | NEW |