diff options
author | tomfinegan@chromium.org <tomfinegan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-31 01:29:35 +0000 |
---|---|---|
committer | tomfinegan@chromium.org <tomfinegan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-31 01:29:35 +0000 |
commit | ce24bcddc880734fbeba6861f1e51e5a2365febc (patch) | |
tree | b2b07d9edf52fe55fc7224be5bd19a3cb151d0b7 /media/ffmpeg | |
parent | 7dfa6863cff15dc33c49bb0e88f6cbff05b6399a (diff) | |
download | chromium_src-ce24bcddc880734fbeba6861f1e51e5a2365febc.zip chromium_src-ce24bcddc880734fbeba6861f1e51e5a2365febc.tar.gz chromium_src-ce24bcddc880734fbeba6861f1e51e5a2365febc.tar.bz2 |
media: Support multichannel Opus audio streams.
Add conversion code that supports going from a number of channels to a
channel layout for Opus audio, which prevents failure of
AudioDecoderConfig::IsValidConfig() for all multichannel Opus streams.
Also fixes audio channel layout for 6.1 (7) channel Opus streams.
BUG=172744
TEST=Opus streams with greater than 2 channels play.
Review URL: https://chromiumcodereview.appspot.com/12094019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/ffmpeg')
-rw-r--r-- | media/ffmpeg/ffmpeg_common.cc | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc index 800c027..b5e4100 100644 --- a/media/ffmpeg/ffmpeg_common.cc +++ b/media/ffmpeg/ffmpeg_common.cc @@ -261,6 +261,31 @@ static AVSampleFormat SampleFormatToAVSampleFormat(SampleFormat sample_format) { return AV_SAMPLE_FMT_NONE; } +ChannelLayout OpusChannelCountToChromeChannelLayout(int channels) { + switch (channels) { + case 1: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_MONO, channels); + case 2: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_STEREO, channels); + case 3: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_SURROUND, + channels); + case 4: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_QUAD, channels); + case 5: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_5POINT0, channels); + case 6: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_5POINT1, channels); + case 7: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_6POINT1, channels); + case 8: + return ChannelLayoutToChromeChannelLayout(AV_CH_LAYOUT_7POINT1, channels); + default: + LOG(ERROR) << "Unsupported Opus channel count: " << channels; + } + return CHANNEL_LAYOUT_UNSUPPORTED; +} + void AVCodecContextToAudioDecoderConfig( const AVCodecContext* codec_context, AudioDecoderConfig* config) { @@ -271,16 +296,20 @@ void AVCodecContextToAudioDecoderConfig( SampleFormat sample_format = AVSampleFormatToSampleFormat(codec_context->sample_fmt); + ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( + codec_context->channel_layout, codec_context->channels); + if (codec == kCodecOpus) { - // TODO(tomfinegan): |sample_fmt| in |codec_context| is -1... because - // libopusdec.c isn't built into ffmpegsumo...? Maybe it's not *that* big - // a deal since libopus will produce either float or S16 samples, and - // OpusAudioDecoder is the only provider of Opus support. + // |channel_layout| and |sample_fmt| in |codec_context| are not set by + // FFmpeg. This happens because Opus is not enabled in ffmpegsumo. This is + // not that big a deal, because: + // 1. OpusAudioDecoder always uses signed 16 bit samples, and... + // 2. OpusAudioDecoder outputs audio using the same channel order as FFmpeg. sample_format = kSampleFormatS16; + channel_layout = + OpusChannelCountToChromeChannelLayout(codec_context->channels); } - ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout( - codec_context->channel_layout, codec_context->channels); config->Initialize(codec, sample_format, channel_layout, |