]> git.sesse.net Git - nageru/commitdiff
Do not try to adjust the audio timer during HDMI/SDI output preroll.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Jan 2017 00:08:06 +0000 (01:08 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 29 Jan 2017 00:08:06 +0000 (01:08 +0100)
decklink_output.cpp
decklink_output.h
mixer.cpp
mixer.h

index b3c4c85457dedef75fd1a115fa9b82689ac27599..a826dfe22ee95c5588f86edebec1c2ad1ce64ed3 100644 (file)
@@ -242,7 +242,7 @@ void DeckLinkOutput::send_audio(int64_t pts, const std::vector<float> &samples)
        }
 }
 
-void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration)
+void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration, bool *is_preroll)
 {
        assert(!should_quit);
 
@@ -255,9 +255,12 @@ void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *f
 
        // While prerolling, we send out frames as quickly as we can.
        if (target_time < base_pts) {
+               *is_preroll = true;
                return;
        }
 
+       *is_preroll = !playback_started;
+
        if (!playback_started) {
                if (output->EndAudioPreroll() != S_OK) {
                        fprintf(stderr, "Could not end audio preroll\n");
index 122c8fe702445804088a2aaf71d81e3053f57b18..7bc9850d1ba8d5bd25ba016dedd6ba756ec235d9 100644 (file)
@@ -41,7 +41,7 @@ public:
 
        void send_frame(GLuint y_tex, GLuint cbcr_tex, const std::vector<RefCountedFrame> &input_frames, int64_t pts, int64_t duration);
        void send_audio(int64_t pts, const std::vector<float> &samples);
-       void wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration);
+       void wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration, bool *is_preroll);
 
        // Analogous to CaptureInterface. Will only return modes that have the right width/height.
        std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const { return video_modes; }
index 0a657276be068af0694fd5bfd288b32e4cb276b7..f77f6d48f7eb0fa4da4bbeb189d40ff24d5a85b6 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -613,7 +613,7 @@ void Mixer::thread_func()
                }
 
                OutputFrameInfo output_frame_info = get_one_frame_from_each_card(master_card_index, master_card_is_output, new_frames, has_new_frame);
-               schedule_audio_resampling_tasks(output_frame_info.dropped_frames, output_frame_info.num_samples, output_frame_info.frame_duration);
+               schedule_audio_resampling_tasks(output_frame_info.dropped_frames, output_frame_info.num_samples, output_frame_info.frame_duration, output_frame_info.is_preroll);
                stats_dropped_frames += output_frame_info.dropped_frames;
 
                handle_hotplugged_cards();
@@ -738,11 +738,12 @@ start:
        unique_lock<mutex> lock(card_mutex, defer_lock);
        if (master_card_is_output) {
                // Clocked to the output, so wait for it to be ready for the next frame.
-               cards[master_card_index].output->wait_for_frame(pts_int, &output_frame_info.dropped_frames, &output_frame_info.frame_duration);
+               cards[master_card_index].output->wait_for_frame(pts_int, &output_frame_info.dropped_frames, &output_frame_info.frame_duration, &output_frame_info.is_preroll);
                lock.lock();
        } else {
                // Wait for the master card to have a new frame.
                // TODO: Add a timeout.
+               output_frame_info.is_preroll = false;
                lock.lock();
                cards[master_card_index].new_frames_changed.wait(lock, [this, master_card_index]{ return !cards[master_card_index].new_frames.empty() || cards[master_card_index].capture->get_disconnected(); });
        }
@@ -846,7 +847,7 @@ void Mixer::handle_hotplugged_cards()
 }
 
 
-void Mixer::schedule_audio_resampling_tasks(unsigned dropped_frames, int num_samples_per_frame, int length_per_frame)
+void Mixer::schedule_audio_resampling_tasks(unsigned dropped_frames, int num_samples_per_frame, int length_per_frame, bool is_preroll)
 {
        // Resample the audio as needed, including from previously dropped frames.
        assert(num_cards > 0);
@@ -867,7 +868,7 @@ void Mixer::schedule_audio_resampling_tasks(unsigned dropped_frames, int num_sam
                        // since dropped frames are expected to be rare, and it might be
                        // better to just wait until we have a slightly more normal situation).
                        unique_lock<mutex> lock(audio_mutex);
-                       bool adjust_rate = !dropped_frame;
+                       bool adjust_rate = !dropped_frame && !is_preroll;
                        audio_task_queue.push(AudioTask{pts_int, num_samples_per_frame, adjust_rate});
                        audio_task_queue_changed.notify_one();
                }
diff --git a/mixer.h b/mixer.h
index 9e4c4d52a222e0d16a38693479f6e91859061269..045e9b1212fccb0f1392cd80fe87903c4079e898 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -323,7 +323,7 @@ private:
        void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1);
        void thread_func();
        void handle_hotplugged_cards();
-       void schedule_audio_resampling_tasks(unsigned dropped_frames, int num_samples_per_frame, int length_per_frame);
+       void schedule_audio_resampling_tasks(unsigned dropped_frames, int num_samples_per_frame, int length_per_frame, bool is_preroll);
        void render_one_frame(int64_t duration);
        void audio_thread_func();
        void release_display_frame(DisplayFrame *frame);
@@ -402,6 +402,7 @@ private:
                int dropped_frames;  // Since last frame.
                int num_samples;  // Audio samples needed for this output frame.
                int64_t frame_duration;  // In TIMEBASE units.
+               bool is_preroll;
        };
        OutputFrameInfo get_one_frame_from_each_card(unsigned master_card_index, bool master_card_is_output, CaptureCard::NewFrame new_frames[MAX_VIDEO_CARDS], bool has_new_frame[MAX_VIDEO_CARDS]);