]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/audio_channel_remapper.cpp
[flash] Fixed bug where template-host copying didn't work.
[casparcg] / modules / ffmpeg / audio_channel_remapper.cpp
index 54de4386d5a336e808bd5e7569f6260c22f71f79..5b632690e5729543de7975f5a3df293794c9b789 100644 (file)
@@ -79,13 +79,13 @@ std::wstring generate_pan_filter_str(
                        for (int i = 0; i < output.num_channels; ++i)
                                result << L"|c" << i << L"=c" << i;
 
-                       CASPAR_LOG(trace) << "[audio_channel_remapper] Passthru " << input.num_channels << " channels into " << output.num_channels;
+                       CASPAR_LOG(debug) << "[audio_channel_remapper] Passthru " << input.num_channels << " channels into " << output.num_channels;
 
                        return result.str();
                }
        }
 
-       CASPAR_LOG(trace) << L"[audio_channel_remapper] Using mix config: " << *mix_config;
+       CASPAR_LOG(debug) << L"[audio_channel_remapper] Using mix config: " << *mix_config;
 
        // Split on | to find the output sections
        std::vector<std::wstring> output_sections;
@@ -138,28 +138,23 @@ struct audio_channel_remapper::impl
                if (output_layout_ == audio_channel_layout::invalid())
                        CASPAR_THROW_EXCEPTION(invalid_argument() << msg_info(L"Output audio channel layout is invalid"));
 
-               CASPAR_LOG(trace) << L"[audio_channel_remapper] Input:  " << input_layout_.print();
-               CASPAR_LOG(trace) << L"[audio_channel_remapper] Output: " << output_layout_.print();
+               CASPAR_LOG(debug) << L"[audio_channel_remapper] Input:  " << input_layout_.print();
+               CASPAR_LOG(debug) << L"[audio_channel_remapper] Output: " << output_layout_.print();
 
                if (!the_same_layouts_)
                {
                        auto mix_config = mix_repo->get_config(input_layout_.type, output_layout_.type);
-                       auto pan_filter = u8(generate_pan_filter_str(input_layout_, output_layout_, mix_config));
+                       auto pan_filter = "[a:0] " + u8(generate_pan_filter_str(input_layout_, output_layout_, mix_config)) + " [aout:0]";
 
-                       CASPAR_LOG(trace) << "[audio_channel_remapper] Using audio filter: " << pan_filter;
-                       auto logging_disabled = ffmpeg::temporary_disable_logging_for_thread(true);
+                       CASPAR_LOG(debug) << "[audio_channel_remapper] Using audio filter: " << pan_filter;
+                       auto quiet_logging = ffmpeg::temporary_enable_quiet_logging_for_thread(true);
                        filter_.reset(new ffmpeg::audio_filter(
-                                       boost::rational<int>(1, 1),
-                                       48000,
-                                       AV_SAMPLE_FMT_S32,
-                                       ffmpeg::create_channel_layout_bitmask(input_layout_.num_channels),
-                                       { 48000 },
-                                       { AV_SAMPLE_FMT_S32 },
-                                       { ffmpeg::create_channel_layout_bitmask(output_layout_.num_channels) },
+                                       { ffmpeg::audio_input_pad(boost::rational<int>(1, 1), 48000, AV_SAMPLE_FMT_S32, ffmpeg::create_channel_layout_bitmask(input_layout_.num_channels)) },
+                                       { ffmpeg::audio_output_pad({ 48000 }, { AV_SAMPLE_FMT_S32 }, { ffmpeg::create_channel_layout_bitmask(output_layout_.num_channels) }) },
                                        pan_filter));
                }
                else
-                       CASPAR_LOG(trace) << "[audio_channel_remapper] No remapping/mixing needed because the input and output layout is equal.";
+                       CASPAR_LOG(debug) << "[audio_channel_remapper] No remapping/mixing needed because the input and output layout is equal.";
        }
 
        audio_buffer mix_and_rearrange(audio_buffer input)
@@ -171,31 +166,10 @@ struct audio_channel_remapper::impl
 
                auto num_samples                        =       input.size() / input_layout_.num_channels;
                auto expected_output_size       =       num_samples * output_layout_.num_channels;
-               auto input_frame                        =       std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame* p)
-                                                                               {
-                                                                                       if (p)
-                                                                                               av_frame_free(&p);
-                                                                               });
-
-               input_frame->channels           =       input_layout_.num_channels;
-               input_frame->channel_layout     =       ffmpeg::create_channel_layout_bitmask(input_layout_.num_channels);
-               input_frame->sample_rate        =       48000;
-               input_frame->nb_samples         =       static_cast<int>(num_samples);
-               input_frame->format                     =       AV_SAMPLE_FMT_S32;
-               input_frame->pts                        =       0;
-
-               av_samples_fill_arrays(
-                               input_frame->extended_data,
-                               input_frame->linesize,
-                               reinterpret_cast<const std::uint8_t*>(input.data()),
-                               input_frame->channels,
-                               input_frame->nb_samples,
-                               static_cast<AVSampleFormat>(input_frame->format),
-                               16);
-
-               filter_->push(input_frame);
-
-               auto frames = filter_->poll_all();
+
+               filter_->push(0, boost::make_iterator_range(input));
+
+               auto frames = filter_->poll_all(0);
 
                CASPAR_ENSURE(frames.size() == 1); // Expect 1:1 from pan filter