From 0912e41e8f564970ef32acd2db75685e47de1f48 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 2 Apr 2016 17:36:55 +0200 Subject: [PATCH] Another split-out from thread_func; this time schedule_audio_resampling_tasks(). --- mixer.cpp | 41 ++++++++++++++++++++++------------------- mixer.h | 1 + 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index 5325437..50c93e8 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -609,25 +609,8 @@ void Mixer::thread_func() unsigned master_card_index = 0; get_one_frame_from_each_card(master_card_index, new_frames, has_new_frame, num_samples); - - // Resample the audio as needed, including from previously dropped frames. - assert(num_cards > 0); - for (unsigned frame_num = 0; frame_num < new_frames[master_card_index].dropped_frames + 1; ++frame_num) { - { - // Signal to the audio thread to process this frame. - unique_lock lock(audio_mutex); - audio_task_queue.push(AudioTask{pts_int, num_samples[master_card_index]}); - audio_task_queue_changed.notify_one(); - } - if (frame_num != new_frames[master_card_index].dropped_frames) { - // For dropped frames, increase the pts. Note that if the format changed - // in the meantime, we have no way of detecting that; we just have to - // assume the frame length is always the same. - ++stats_dropped_frames; - pts_int += new_frames[master_card_index].length; - } - } - + schedule_audio_resampling_tasks(new_frames[master_card_index].dropped_frames, num_samples[master_card_index], new_frames[master_card_index].length); + stats_dropped_frames += new_frames[master_card_index].dropped_frames; send_audio_level_callback(); for (unsigned card_index = 0; card_index < num_cards; ++card_index) { @@ -743,6 +726,26 @@ void Mixer::get_one_frame_from_each_card(unsigned master_card_index, CaptureCard } } +void Mixer::schedule_audio_resampling_tasks(unsigned dropped_frames, int num_samples_per_frame, int length_per_frame) +{ + // Resample the audio as needed, including from previously dropped frames. + assert(num_cards > 0); + for (unsigned frame_num = 0; frame_num < dropped_frames + 1; ++frame_num) { + { + // Signal to the audio thread to process this frame. + unique_lock lock(audio_mutex); + audio_task_queue.push(AudioTask{pts_int, num_samples_per_frame}); + audio_task_queue_changed.notify_one(); + } + if (frame_num != dropped_frames) { + // For dropped frames, increase the pts. Note that if the format changed + // in the meantime, we have no way of detecting that; we just have to + // assume the frame length is always the same. + pts_int += length_per_frame; + } + } +} + void Mixer::render_one_frame() { // Get the main chain from the theme, and set its state immediately. diff --git a/mixer.h b/mixer.h index f9d380d..c68ad1b 100644 --- a/mixer.h +++ b/mixer.h @@ -336,6 +336,7 @@ private: FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format); void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1); void thread_func(); + void schedule_audio_resampling_tasks(unsigned dropped_frames, int num_samples_per_frame, int length_per_frame); void render_one_frame(); void send_audio_level_callback(); void audio_thread_func(); -- 2.39.2