X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mixer.cpp;h=38578f90ea7b85609531a63d5bc1bc3806a983b7;hb=01181e6e22e5cfc9d0cb17231f2c1866cc53b04a;hp=9d418c9942622d17ba8a71fe5544bdbd61e6cb6a;hpb=29cccb8cb0bb613b7f4b3e9d27a4a5c71a2f82e8;p=nageru diff --git a/mixer.cpp b/mixer.cpp index 9d418c9..38578f9 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -28,21 +29,19 @@ #include #include #include -#include -#include -#include #include "bmusb/bmusb.h" #include "bmusb/fake_capture.h" #include "context.h" +#include "db.h" #include "decklink_capture.h" #include "defs.h" #include "disk_space_estimator.h" #include "flags.h" -#include "video_encoder.h" #include "pbo_frame_allocator.h" #include "ref_counted_gl_sync.h" #include "timebase.h" +#include "video_encoder.h" class QOpenGLContext; @@ -282,11 +281,14 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, bool if (card->surface == nullptr) { card->surface = create_surface_with_same_format(mixer_surface); } - audio_mixer.reset_card(card_index); while (!card->new_frames.empty()) card->new_frames.pop(); card->fractional_samples = 0; card->last_timecode = -1; card->capture->configure_card(); + + DeviceSpec device{InputSourceType::CAPTURE_CARD, card_index}; + audio_mixer.reset_resampler(device); + audio_mixer.set_name(device, card->capture->get_description()); } @@ -332,6 +334,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format) { + DeviceSpec device{InputSourceType::CAPTURE_CARD, card_index}; CaptureCard *card = &cards[card_index]; if (is_mode_scanning[card_index]) { @@ -381,17 +384,20 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, if (dropped_frames > MAX_FPS * 2) { fprintf(stderr, "Card %d lost more than two seconds (or time code jumping around; from 0x%04x to 0x%04x), resetting resampler\n", card_index, card->last_timecode, timecode); - audio_mixer.reset_card(card_index); + audio_mixer.reset_resampler(device); dropped_frames = 0; } else if (dropped_frames > 0) { // Insert silence as needed. fprintf(stderr, "Card %d dropped %d frame(s) (before timecode 0x%04x), inserting silence.\n", card_index, dropped_frames, timecode); - audio_mixer.add_silence(card_index, silence_samples, dropped_frames, frame_length); + bool success; + do { + success = audio_mixer.add_silence(device, silence_samples, dropped_frames, frame_length); + } while (!success); } - audio_mixer.add_audio(card_index, audio_frame.data + audio_offset, num_samples, audio_format, frame_length); + audio_mixer.add_audio(device, audio_frame.data + audio_offset, num_samples, audio_format, frame_length); // Done with the audio, so release it. if (audio_frame.owner) { @@ -566,9 +572,9 @@ void Mixer::thread_func() int stats_dropped_frames = 0; while (!should_quit) { - CaptureCard::NewFrame new_frames[MAX_CARDS]; - bool has_new_frame[MAX_CARDS] = { false }; - int num_samples[MAX_CARDS] = { 0 }; + CaptureCard::NewFrame new_frames[MAX_VIDEO_CARDS]; + bool has_new_frame[MAX_VIDEO_CARDS] = { false }; + int num_samples[MAX_VIDEO_CARDS] = { 0 }; unsigned master_card_index = theme->map_signal(master_clock_channel); assert(master_card_index < num_cards); @@ -678,7 +684,7 @@ void Mixer::thread_func() resource_pool->clean_context(); } -void Mixer::get_one_frame_from_each_card(unsigned master_card_index, CaptureCard::NewFrame new_frames[MAX_CARDS], bool has_new_frame[MAX_CARDS], int num_samples[MAX_CARDS]) +void Mixer::get_one_frame_from_each_card(unsigned master_card_index, CaptureCard::NewFrame new_frames[MAX_VIDEO_CARDS], bool has_new_frame[MAX_VIDEO_CARDS], int num_samples[MAX_VIDEO_CARDS]) { start: // The first card is the master timer, so wait for it to have a new frame. @@ -878,7 +884,7 @@ void Mixer::send_audio_level_callback() double loudness_range_low = r128.range_min(); double loudness_range_high = r128.range_max(); - audio_level_callback(loudness_s, 20.0 * log10(peak), + audio_level_callback(loudness_s, to_db(peak), loudness_i, loudness_range_low, loudness_range_high, audio_mixer.get_gain_staging_db(), audio_mixer.get_final_makeup_gain_db(),