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/ffmpeg/ffmpeg_common.h" | 5 #include "media/ffmpeg/ffmpeg_common.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); | 278 DCHECK_EQ(codec_context->codec_type, AVMEDIA_TYPE_AUDIO); |
279 | 279 |
280 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); | 280 AudioCodec codec = CodecIDToAudioCodec(codec_context->codec_id); |
281 | 281 |
282 SampleFormat sample_format = | 282 SampleFormat sample_format = |
283 AVSampleFormatToSampleFormat(codec_context->sample_fmt); | 283 AVSampleFormatToSampleFormat(codec_context->sample_fmt); |
284 | 284 |
285 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( | 285 ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( |
286 codec_context->channel_layout, codec_context->channels); | 286 codec_context->channel_layout, codec_context->channels); |
287 | 287 |
| 288 int sample_rate = codec_context->sample_rate; |
288 if (codec == kCodecOpus) { | 289 if (codec == kCodecOpus) { |
289 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is | 290 // |codec_context->sample_fmt| is not set by FFmpeg because Opus decoding is |
290 // not enabled in FFmpeg. It doesn't matter what value is set here, so long | 291 // not enabled in FFmpeg. It doesn't matter what value is set here, so long |
291 // as it's valid, the true sample format is selected inside the decoder. | 292 // as it's valid, the true sample format is selected inside the decoder. |
292 sample_format = kSampleFormatF32; | 293 sample_format = kSampleFormatF32; |
| 294 |
| 295 // Always use 48kHz for OPUS. Technically we should match to the highest |
| 296 // supported hardware sample rate among [8, 12, 16, 24, 48] kHz, but we |
| 297 // don't know the hardware sample rate at this point and those rates are |
| 298 // rarely used for output. See the "Input Sample Rate" section of the spec: |
| 299 // http://tools.ietf.org/html/draft-terriberry-oggopus-01#page-11 |
| 300 sample_rate = 48000; |
293 } | 301 } |
294 | 302 |
295 base::TimeDelta seek_preroll; | 303 base::TimeDelta seek_preroll; |
296 if (codec_context->seek_preroll > 0) { | 304 if (codec_context->seek_preroll > 0) { |
297 seek_preroll = base::TimeDelta::FromMicroseconds( | 305 seek_preroll = base::TimeDelta::FromMicroseconds( |
298 codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate); | 306 codec_context->seek_preroll * 1000000.0 / codec_context->sample_rate); |
299 } | 307 } |
300 | 308 |
301 config->Initialize(codec, | 309 config->Initialize(codec, |
302 sample_format, | 310 sample_format, |
303 channel_layout, | 311 channel_layout, |
304 codec_context->sample_rate, | 312 sample_rate, |
305 codec_context->extradata, | 313 codec_context->extradata, |
306 codec_context->extradata_size, | 314 codec_context->extradata_size, |
307 is_encrypted, | 315 is_encrypted, |
308 record_stats, | 316 record_stats, |
309 seek_preroll, | 317 seek_preroll, |
310 codec_context->delay); | 318 codec_context->delay); |
311 if (codec != kCodecOpus) { | 319 if (codec != kCodecOpus) { |
312 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, | 320 DCHECK_EQ(av_get_bytes_per_sample(codec_context->sample_fmt) * 8, |
313 config->bits_per_channel()); | 321 config->bits_per_channel()); |
314 } | 322 } |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 return false; | 586 return false; |
579 | 587 |
580 *out = parsed_time; | 588 *out = parsed_time; |
581 return true; | 589 return true; |
582 } | 590 } |
583 | 591 |
584 return false; | 592 return false; |
585 } | 593 } |
586 | 594 |
587 } // namespace media | 595 } // namespace media |
OLD | NEW |