]> git.sesse.net Git - nageru/commitdiff
Some the audio handling into its own function.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 5 Nov 2015 23:40:41 +0000 (00:40 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 5 Nov 2015 23:40:41 +0000 (00:40 +0100)
mixer.cpp
mixer.h

index d1a788bab2e483eebc45edbfdb8e9b4373f6f5f1..3ebfbeeecdbd788695109ba3f385842d49e09df0 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -365,26 +365,8 @@ void Mixer::thread_func()
                }
 
                // Resample the audio as needed, including from previously dropped frames.
-               vector<float> samples_out;
-               // TODO: Allow using audio from the other card(s) as well.
                for (unsigned frame_num = 0; frame_num < card_copy[0].dropped_frames + 1; ++frame_num) {
-                       for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
-                               samples_out.resize((48000 / 60) * 2);
-                               {
-                                       unique_lock<mutex> lock(cards[card_index].audio_mutex);
-                                       if (!cards[card_index].resampler->get_output_samples(pts(), &samples_out[0], 48000 / 60)) {
-                                               printf("Card %d reported previous underrun.\n", card_index);
-                                       }
-                               }
-                               if (card_index == 0) {
-                                       vector<float> left, right;
-                                       peak = std::max(peak, find_peak(samples_out));
-                                       deinterleave_samples(samples_out, &left, &right);
-                                       float *ptrs[] = { left.data(), right.data() };
-                                       r128.process(left.size(), ptrs);
-                                       h264_encoder->add_audio(pts_int, move(samples_out));
-                               }
-                       }
+                       process_audio_one_frame();
                        if (frame_num != card_copy[0].dropped_frames) {
                                // For dropped frames, increase the pts.
                                ++dropped_frames;
@@ -537,6 +519,29 @@ void Mixer::thread_func()
        resource_pool->clean_context();
 }
 
+void Mixer::process_audio_one_frame()
+{
+       // TODO: Allow using audio from the other card(s) as well.
+       vector<float> samples_out;
+       for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+               samples_out.resize((48000 / 60) * 2);
+               {
+                       unique_lock<mutex> lock(cards[card_index].audio_mutex);
+                       if (!cards[card_index].resampler->get_output_samples(pts(), &samples_out[0], 48000 / 60)) {
+                               printf("Card %d reported previous underrun.\n", card_index);
+                       }
+               }
+               if (card_index == 0) {
+                       vector<float> left, right;
+                       peak = std::max(peak, find_peak(samples_out));
+                       deinterleave_samples(samples_out, &left, &right);
+                       float *ptrs[] = { left.data(), right.data() };
+                       r128.process(left.size(), ptrs);
+                       h264_encoder->add_audio(pts_int, move(samples_out));
+               }
+       }
+}
+
 void Mixer::subsample_chroma(GLuint src_tex, GLuint dst_tex)
 {
        GLuint vao;
diff --git a/mixer.h b/mixer.h
index 02c06edfa46f2d8ee12278dee03320efe979e673..d7f50cf61baf891c13c9cab3c201f40fed57694c 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -132,6 +132,7 @@ private:
                FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t 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 process_audio_one_frame();
        void subsample_chroma(GLuint src_tex, GLuint dst_dst);
        void release_display_frame(DisplayFrame *frame);
        double pts() { return double(pts_int) / TIMEBASE; }