]> git.sesse.net Git - nageru/commitdiff
Another split-out from thread_func; this time schedule_audio_resampling_tasks().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 2 Apr 2016 15:36:55 +0000 (17:36 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 2 Apr 2016 15:36:55 +0000 (17:36 +0200)
mixer.cpp
mixer.h

index 5325437e0fddaa56d3044ad206b144340f696eee..50c93e8c018a9f3b077830b77788f8dffbee5b8c 100644 (file)
--- 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<mutex> 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<mutex> 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 f9d380db710ae3de13a37f0e99e185cfd509d983..c68ad1b81a1fd527a2c9a29c30337e724c9fd7a6 100644 (file)
--- 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();