]> git.sesse.net Git - casparcg/commitdiff
Removed unnecessary requirement of having an AVCodecContext instance when calling...
authorHelge Norberg <helge.norberg@svt.se>
Tue, 1 Mar 2016 17:41:59 +0000 (18:41 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Tue, 1 Mar 2016 17:41:59 +0000 (18:41 +0100)
modules/ffmpeg/producer/audio/audio_decoder.cpp
modules/ffmpeg/producer/util/util.cpp
modules/ffmpeg/producer/util/util.h

index f94a39c35efed8f068b7760afd81b19921b5123f..64930e77dc633de2d7262ad66da0cf64b69d16eb 100644 (file)
@@ -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());
index f8b8894b436ea0a261da9d0d45200b3487241e3f..e848c56eeec3fe2a5ffd73e965022fa06f8dc053 100644 (file)
@@ -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");
index fd7aebae0ec58ad4e50797936d835a1ce7a261ca..626cccfb454639d6f6ed80c4838acf38fdcfecc3 100644 (file)
@@ -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<std::int64_t>& 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);