From: Helge Norberg Date: Tue, 1 Mar 2016 17:41:59 +0000 (+0100) Subject: Removed unnecessary requirement of having an AVCodecContext instance when calling... X-Git-Tag: 2.1.0_Beta1~99 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=315b093159cf03180944d7a88d40f1ebdcf1c8e2;p=casparcg Removed unnecessary requirement of having an AVCodecContext instance when calling ffmpeg::get_audio_channel_layout() --- diff --git a/modules/ffmpeg/producer/audio/audio_decoder.cpp b/modules/ffmpeg/producer/audio/audio_decoder.cpp index f94a39c35..64930e77d 100644 --- a/modules/ffmpeg/producer/audio/audio_decoder.cpp +++ b/modules/ffmpeg/producer/audio/audio_decoder.cpp @@ -89,7 +89,10 @@ public: : input_(in) , format_desc_(format_desc) , buffer_(480000 * 4) - , channel_layout_(get_audio_channel_layout(*codec_context_, channel_layout_spec)) + , channel_layout_(get_audio_channel_layout( + codec_context_->channels, + codec_context_->channel_layout, + channel_layout_spec)) { if(!swr_) CASPAR_THROW_EXCEPTION(bad_alloc()); diff --git a/modules/ffmpeg/producer/util/util.cpp b/modules/ffmpeg/producer/util/util.cpp index f8b8894b4..e848c56ee 100644 --- a/modules/ffmpeg/producer/util/util.cpp +++ b/modules/ffmpeg/producer/util/util.cpp @@ -644,10 +644,8 @@ std::wstring probe_stem(const std::wstring& stem, bool only_video) return L""; } -core::audio_channel_layout get_audio_channel_layout(const AVCodecContext& codec_context, const std::wstring& channel_layout_spec) +core::audio_channel_layout get_audio_channel_layout(int num_channels, std::uint64_t layout, const std::wstring& channel_layout_spec) { - auto num_channels = codec_context.channels; - if (!channel_layout_spec.empty()) { if (boost::contains(channel_layout_spec, L":")) // Custom on the fly layout specified. @@ -661,18 +659,18 @@ core::audio_channel_layout get_audio_channel_layout(const AVCodecContext& codec_ } else // Preconfigured named channel layout selected. { - auto layout = core::audio_channel_layout_repository::get_default()->get_layout(channel_layout_spec); + auto channel_layout = core::audio_channel_layout_repository::get_default()->get_layout(channel_layout_spec); - if (!layout) + if (!channel_layout) CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"No channel layout with name " + channel_layout_spec + L" registered")); - layout->num_channels = num_channels; + channel_layout->num_channels = num_channels; - return *layout; + return *channel_layout; } } - if (!codec_context.channel_layout) + if (!layout) { if (num_channels == 1) return core::audio_channel_layout(num_channels, L"mono", L"FC"); @@ -688,7 +686,7 @@ core::audio_channel_layout get_audio_channel_layout(const AVCodecContext& codec_ // than the most common (5.1, mono and stereo) types. // Based on information in https://ffmpeg.org/ffmpeg-utils.html#Channel-Layout - switch (codec_context.channel_layout) + switch (layout) { case AV_CH_LAYOUT_MONO: return core::audio_channel_layout(num_channels, L"mono", L"FC"); diff --git a/modules/ffmpeg/producer/util/util.h b/modules/ffmpeg/producer/util/util.h index fd7aebae0..626cccfb4 100644 --- a/modules/ffmpeg/producer/util/util.h +++ b/modules/ffmpeg/producer/util/util.h @@ -80,7 +80,7 @@ std::wstring probe_stem(const std::wstring& stem, bool only_video); bool is_valid_file(const std::wstring& filename, bool only_video); bool try_get_duration(const std::wstring filename, std::int64_t& duration, boost::rational& time_base); -core::audio_channel_layout get_audio_channel_layout(const AVCodecContext& codec_context, const std::wstring& channel_layout_spec); +core::audio_channel_layout get_audio_channel_layout(int num_channels, std::uint64_t layout, const std::wstring& channel_layout_spec); // av_get_default_channel_layout does not work for layouts not predefined in ffmpeg. This is needed to support > 8 channels. std::int64_t create_channel_layout_bitmask(int num_channels);