]> git.sesse.net Git - casparcg/blobdiff - modules/decklink/producer/decklink_producer.cpp
[ffmpeg] Reimplemented support for playing all audio streams in a clip and treating...
[casparcg] / modules / decklink / producer / decklink_producer.cpp
index e08b3a6d5d52462f1051eabcf75f666dd3ff9780..0349f5bc15052610f7e14fd8516068aa48e73258 100644 (file)
@@ -93,6 +93,15 @@ std::wstring to_string(const T& cadence)
        return boost::join(cadence | boost::adaptors::transformed([](size_t i) { return boost::lexical_cast<std::wstring>(i); }), L", ");
 }
 
+ffmpeg::audio_input_pad create_input_pad(const core::video_format_desc& in_format, int num_channels)
+{
+       return ffmpeg::audio_input_pad(
+                       boost::rational<int>(1, in_format.audio_sample_rate),
+                       in_format.audio_sample_rate,
+                       AVSampleFormat::AV_SAMPLE_FMT_S32,
+                       av_get_default_channel_layout(num_channels));
+}
+
 class decklink_producer : boost::noncopyable, public IDeckLinkInputCallback
 {
        const int                                                                               device_index_;
@@ -113,7 +122,15 @@ class decklink_producer : boost::noncopyable, public IDeckLinkInputCallback
        boost::circular_buffer<size_t>                                  sync_buffer_            { audio_cadence_.size() };
        spl::shared_ptr<core::frame_factory>                    frame_factory_;
        core::audio_channel_layout                                              channel_layout_;
-       ffmpeg::frame_muxer                                                             muxer_                          { in_format_desc_.framerate, frame_factory_, out_format_desc_, channel_layout_, filter_, ffmpeg::filter::is_deinterlacing(filter_) };
+       ffmpeg::frame_muxer                                                             muxer_                          {
+                                                                                                                                                       in_format_desc_.framerate,
+                                                                                                                                                       { create_input_pad(in_format_desc_, channel_layout_.num_channels) },
+                                                                                                                                                       frame_factory_,
+                                                                                                                                                       out_format_desc_,
+                                                                                                                                                       channel_layout_,
+                                                                                                                                                       filter_,
+                                                                                                                                                       ffmpeg::filter::is_deinterlacing(filter_)
+                                                                                                                                               };
 
        core::constraints                                                               constraints_            { in_format_desc_.width, in_format_desc_.height };
 
@@ -171,6 +188,12 @@ public:
                                                                        << msg_info(print() + L" Failed to start input stream.")
                                                                        << boost::errinfo_api_function("StartStreams"));
 
+               // Wait for first frame until returning or give up after 2 seconds.
+               caspar::timer timeout_timer;
+
+               while (frame_buffer_.size() < 1 && timeout_timer.elapsed() < 2.0)
+                       boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
+
                CASPAR_LOG(info) << print() << L" Initialized";
        }
 
@@ -269,7 +292,7 @@ public:
 
                        // PUSH
 
-                       muxer_.push(audio_buffer);
+                       muxer_.push({ audio_buffer });
                        muxer_.push(static_cast<std::shared_ptr<AVFrame>>(video_frame));
 
                        // POLL