From 4ed1495550e603bfb7584e1b1b9a0c74e57de223 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 6 Nov 2015 00:40:41 +0100 Subject: [PATCH] Some the audio handling into its own function. --- mixer.cpp | 43 ++++++++++++++++++++++++------------------- mixer.h | 1 + 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/mixer.cpp b/mixer.cpp index d1a788b..3ebfbee 100644 --- 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 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 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 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 samples_out; + for (unsigned card_index = 0; card_index < num_cards; ++card_index) { + samples_out.resize((48000 / 60) * 2); + { + unique_lock 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 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 02c06ed..d7f50cf 100644 --- 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; } -- 2.39.2