Chromium Code Reviews| Index: media/filters/ffmpeg_audio_decoder.cc |
| diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc |
| index acccf2e595d9bf02d0b08ec128a0e0c81614d034..2d42550819c6928bd7112564053fbbb4c523efe9 100644 |
| --- a/media/filters/ffmpeg_audio_decoder.cc |
| +++ b/media/filters/ffmpeg_audio_decoder.cc |
| @@ -96,8 +96,15 @@ static int GetAudioBuffer(struct AVCodecContext* s, AVFrame* frame, int flags) { |
| int frames_required = buffer_size_in_bytes / bytes_per_channel / channels; |
| DCHECK_GE(frames_required, frame->nb_samples); |
| + bool is_opus_discrete = false; |
|
DaleCurtis
2017/03/29 22:46:55
Isn't this information already in the AudioDecoder
flim-chromium
2017/03/30 19:35:10
True, but this is a static function and the non-st
DaleCurtis
2017/03/30 20:22:21
Ah right, this isn't like FFmpegVideoDecoder where
flim-chromium
2017/03/31 00:12:14
I believe so - it includes the additional check th
DaleCurtis
2017/03/31 19:06:53
I'm moving this to be a class method in https://co
flim-chromium
2017/04/05 18:19:34
thanks, this has been updated to use config_
|
| + if (s->codec_id == AV_CODEC_ID_OPUS && s->extradata_size >= 19) { |
| + int mapping_family = s->extradata[18]; |
| + is_opus_discrete = mapping_family == 2; |
| + } |
| ChannelLayout channel_layout = |
| - ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels); |
| + is_opus_discrete && channels > 8 |
| + ? CHANNEL_LAYOUT_DISCRETE |
| + : ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels); |
| if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) { |
| DLOG(ERROR) << "Unsupported channel layout."; |
| @@ -304,10 +311,9 @@ bool FFmpegAudioDecoder::FFmpegDecode( |
| bool is_sample_rate_change = |
| av_frame_->sample_rate != config_.samples_per_second(); |
| - bool is_config_stale = |
| - is_sample_rate_change || |
| - channels != ChannelLayoutToChannelCount(config_.channel_layout()) || |
| - av_frame_->format != av_sample_format_; |
| + bool is_config_stale = is_sample_rate_change || |
| + channels != config_.channels() || |
| + av_frame_->format != av_sample_format_; |
| // Only consider channel layout changes for AAC. |
| // TODO(tguilbert, dalecurtis): Due to http://crbug.com/600538 we need to |
| @@ -327,8 +333,7 @@ bool FFmpegAudioDecoder::FFmpegDecode( |
| << config_.samples_per_second() |
| << ", ChannelLayout: " << channel_layout << " vs " |
| << config_.channel_layout() << ", Channels: " << channels |
| - << " vs " |
| - << ChannelLayoutToChannelCount(config_.channel_layout()); |
| + << " vs " << config_.channels(); |
| config_.Initialize(config_.codec(), config_.sample_format(), |
| channel_layout, av_frame_->sample_rate, |
| config_.extra_data(), config_.encryption_scheme(), |
| @@ -341,7 +346,7 @@ bool FFmpegAudioDecoder::FFmpegDecode( |
| << "Unsupported midstream configuration change!" |
| << " Sample Rate: " << av_frame_->sample_rate << " vs " |
| << config_.samples_per_second() << ", Channels: " << channels |
| - << " vs " << ChannelLayoutToChannelCount(config_.channel_layout()) |
| + << " vs " << config_.channels() |
| << ", Sample Format: " << av_frame_->format << " vs " |
| << av_sample_format_; |
| // This is an unrecoverable error, so bail out. |
| @@ -355,8 +360,7 @@ bool FFmpegAudioDecoder::FFmpegDecode( |
| output = reinterpret_cast<AudioBuffer*>( |
| av_buffer_get_opaque(av_frame_->buf[0])); |
| - DCHECK_EQ(ChannelLayoutToChannelCount(config_.channel_layout()), |
| - output->channel_count()); |
| + DCHECK_EQ(config_.channels(), output->channel_count()); |
| const int unread_frames = output->frame_count() - av_frame_->nb_samples; |
| DCHECK_GE(unread_frames, 0); |
| if (unread_frames > 0) |
| @@ -421,10 +425,8 @@ bool FFmpegAudioDecoder::ConfigureDecoder() { |
| av_frame_.reset(av_frame_alloc()); |
| av_sample_format_ = codec_context_->sample_fmt; |
| - if (codec_context_->channels != |
| - ChannelLayoutToChannelCount(config_.channel_layout())) { |
| - DLOG(ERROR) << "Audio configuration specified " |
| - << ChannelLayoutToChannelCount(config_.channel_layout()) |
| + if (codec_context_->channels != config_.channels()) { |
| + DLOG(ERROR) << "Audio configuration specified " << config_.channels() |
| << " channels, but FFmpeg thinks the file contains " |
| << codec_context_->channels << " channels"; |
| ReleaseFFmpegResources(); |