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 e3560ff1b8bcf9d359f2a7c0ab06147b8e6b4e3f..7e7228991eb49820206487a2a65ac453637e6fbb 100644 |
| --- a/media/filters/ffmpeg_audio_decoder.cc |
| +++ b/media/filters/ffmpeg_audio_decoder.cc |
| @@ -84,6 +84,18 @@ static int GetAudioBuffer(struct AVCodecContext* s, AVFrame* frame, int flags) { |
| return AVERROR(EINVAL); |
| } |
| + // Use CHANNEL_LAYOUT_DISCRETE for Opus Ambisonics signals |
| + int is_opus_ambisonics = 0; |
|
DaleCurtis
2017/03/20 17:38:58
bool.
flim-chromium
2017/03/22 06:20:51
Done.
|
| + if (s->codec_id == AV_CODEC_ID_OPUS && s->extradata_size >= 19) { |
| + int mapping_family = s->extradata[18]; |
| + is_opus_ambisonics = mapping_family == 2; |
| + } |
| + ChannelLayout channel_layout = is_opus_ambisonics |
|
DaleCurtis
2017/03/20 17:38:58
&& channels > 8.
flim-chromium
2017/03/22 06:20:51
Ambisonics signals could also be < 8 channels. Or
DaleCurtis
2017/03/22 18:56:30
I mean I don't think DISCRETE will be passed or wo
flim-chromium
2017/03/29 03:15:25
Thanks for the explanation. I've added '&& channel
|
| + ? CHANNEL_LAYOUT_DISCRETE |
| + : ChannelLayoutToChromeChannelLayout( |
| + s->channel_layout, |
| + s->channels); |
| + |
| // Determine how big the buffer should be and allocate it. FFmpeg may adjust |
| // how big each channel data is in order to meet the alignment policy, so |
| // we need to take this into consideration. |
| @@ -97,7 +109,7 @@ static int GetAudioBuffer(struct AVCodecContext* s, AVFrame* frame, int flags) { |
| DCHECK_GE(frames_required, frame->nb_samples); |
| scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateBuffer( |
| sample_format, |
| - ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels), |
| + channel_layout, |
| channels, |
| s->sample_rate, |
| frames_required); |
| @@ -301,7 +313,7 @@ bool FFmpegAudioDecoder::FFmpegDecode( |
| av_frame_->sample_rate != config_.samples_per_second(); |
| bool is_config_stale = |
| is_sample_rate_change || |
| - channels != ChannelLayoutToChannelCount(config_.channel_layout()) || |
| + channels != config_.channels() || |
| av_frame_->format != av_sample_format_; |
| // Only consider channel layout changes for AAC. |
| @@ -323,7 +335,7 @@ bool FFmpegAudioDecoder::FFmpegDecode( |
| << ", ChannelLayout: " << channel_layout << " vs " |
| << config_.channel_layout() << ", Channels: " << channels |
| << " vs " |
| - << ChannelLayoutToChannelCount(config_.channel_layout()); |
| + << config_.channels(); |
| config_.Initialize(config_.codec(), config_.sample_format(), |
| channel_layout, av_frame_->sample_rate, |
| config_.extra_data(), config_.encryption_scheme(), |
| @@ -336,7 +348,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. |
| @@ -350,8 +362,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) |
| @@ -416,10 +427,10 @@ bool FFmpegAudioDecoder::ConfigureDecoder() { |
| av_frame_.reset(av_frame_alloc()); |
| av_sample_format_ = codec_context_->sample_fmt; |
| - if (codec_context_->channels != |
| - ChannelLayoutToChannelCount(config_.channel_layout())) { |
| + |
| + if (codec_context_->channels != config_.channels()) { |
| DLOG(ERROR) << "Audio configuration specified " |
| - << ChannelLayoutToChannelCount(config_.channel_layout()) |
| + << config_.channels() |
| << " channels, but FFmpeg thinks the file contains " |
| << codec_context_->channels << " channels"; |
| ReleaseFFmpegResources(); |