| 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 #include "media/filters/ffmpeg_audio_decoder.h" | 5 #include "media/filters/ffmpeg_audio_decoder.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 if (s->sample_rate != frame->sample_rate) { | 81 if (s->sample_rate != frame->sample_rate) { |
| 82 DLOG(ERROR) << "AVCodecContext and AVFrame disagree on sample rate." | 82 DLOG(ERROR) << "AVCodecContext and AVFrame disagree on sample rate." |
| 83 << s->sample_rate << " vs " << frame->sample_rate; | 83 << s->sample_rate << " vs " << frame->sample_rate; |
| 84 return AVERROR(EINVAL); | 84 return AVERROR(EINVAL); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Determine how big the buffer should be and allocate it. FFmpeg may adjust | 87 // Determine how big the buffer should be and allocate it. FFmpeg may adjust |
| 88 // how big each channel data is in order to meet the alignment policy, so | 88 // how big each channel data is in order to meet the alignment policy, so |
| 89 // we need to take this into consideration. | 89 // we need to take this into consideration. |
| 90 int buffer_size_in_bytes = | 90 int buffer_size_in_bytes = av_samples_get_buffer_size( |
| 91 av_samples_get_buffer_size(&frame->linesize[0], | 91 &frame->linesize[0], channels, frame->nb_samples, format, |
| 92 channels, | 92 0 /* align, use ffmpeg default */); |
| 93 frame->nb_samples, | |
| 94 format, | |
| 95 AudioBuffer::kChannelAlignment); | |
| 96 // Check for errors from av_samples_get_buffer_size(). | 93 // Check for errors from av_samples_get_buffer_size(). |
| 97 if (buffer_size_in_bytes < 0) | 94 if (buffer_size_in_bytes < 0) |
| 98 return buffer_size_in_bytes; | 95 return buffer_size_in_bytes; |
| 99 int frames_required = buffer_size_in_bytes / bytes_per_channel / channels; | 96 int frames_required = buffer_size_in_bytes / bytes_per_channel / channels; |
| 100 DCHECK_GE(frames_required, frame->nb_samples); | 97 DCHECK_GE(frames_required, frame->nb_samples); |
| 101 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateBuffer( | 98 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateBuffer( |
| 102 sample_format, | 99 sample_format, |
| 103 ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels), | 100 ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels), |
| 104 channels, | 101 channels, |
| 105 s->sample_rate, | 102 s->sample_rate, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 return true; | 428 return true; |
| 432 } | 429 } |
| 433 | 430 |
| 434 void FFmpegAudioDecoder::ResetTimestampState() { | 431 void FFmpegAudioDecoder::ResetTimestampState() { |
| 435 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), | 432 discard_helper_.reset(new AudioDiscardHelper(config_.samples_per_second(), |
| 436 config_.codec_delay())); | 433 config_.codec_delay())); |
| 437 discard_helper_->Reset(config_.codec_delay()); | 434 discard_helper_->Reset(config_.codec_delay()); |
| 438 } | 435 } |
| 439 | 436 |
| 440 } // namespace media | 437 } // namespace media |
| OLD | NEW |