From 1ddeee498397ab599d0ee131f7896f543486d0ad Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 18 Apr 2018 22:08:09 +0200 Subject: [PATCH] When outputting debug messages for an audio device, refer to the device spec instead of the internal card index. --- audio_mixer.cpp | 4 +--- bmusb | 2 +- input_mapping.cpp | 18 ++++++++++++++++++ input_mapping.h | 4 ++++ mixer.cpp | 16 ++++++++-------- resampling_queue.cpp | 8 ++++---- resampling_queue.h | 7 ++++--- 7 files changed, 40 insertions(+), 19 deletions(-) diff --git a/audio_mixer.cpp b/audio_mixer.cpp index 468edd5..887b105 100644 --- a/audio_mixer.cpp +++ b/audio_mixer.cpp @@ -236,10 +236,8 @@ void AudioMixer::reset_resampler_mutex_held(DeviceSpec device_spec) if (device->interesting_channels.empty()) { device->resampling_queue.reset(); } else { - // TODO: ResamplingQueue should probably take the full device spec. - // (It's only used for console output, though.) device->resampling_queue.reset(new ResamplingQueue( - device_spec.index, device->capture_frequency, OUTPUT_FREQUENCY, device->interesting_channels.size(), + device_spec, device->capture_frequency, OUTPUT_FREQUENCY, device->interesting_channels.size(), global_flags.audio_queue_length_ms * 0.001)); } } diff --git a/bmusb b/bmusb index 6a012a4..e287f28 160000 --- a/bmusb +++ b/bmusb @@ -1 +1 @@ -Subproject commit 6a012a41c5422092cdac1f18a9019f37c0b85368 +Subproject commit e287f28087aef9cfd6aa47acd0d283bc177a9d70 diff --git a/input_mapping.cpp b/input_mapping.cpp index deef923..f894c95 100644 --- a/input_mapping.cpp +++ b/input_mapping.cpp @@ -14,6 +14,24 @@ using namespace std; using namespace google::protobuf; +string spec_to_string(DeviceSpec device_spec) +{ + char buf[256]; + + switch (device_spec.type) { + case InputSourceType::SILENCE: + return ""; + case InputSourceType::CAPTURE_CARD: + snprintf(buf, sizeof(buf), "Capture card %u", device_spec.index); + return buf; + case InputSourceType::ALSA_INPUT: + snprintf(buf, sizeof(buf), "ALSA input %u", device_spec.index); + return buf; + default: + assert(false); + } +} + bool save_input_mapping_to_file(const map &devices, const InputMapping &input_mapping, const string &filename) { InputMappingProto mapping_proto; diff --git a/input_mapping.h b/input_mapping.h index 10c3ca2..540fde3 100644 --- a/input_mapping.h +++ b/input_mapping.h @@ -47,6 +47,10 @@ struct InputMapping { std::vector buses; }; +// This is perhaps not the most user-friendly output, but it's at least better +// than the raw index. +std::string spec_to_string(DeviceSpec device_spec); + bool save_input_mapping_to_file(const std::map &devices, const InputMapping &mapping, const std::string &filename); diff --git a/mixer.cpp b/mixer.cpp index 202617b..cbc66d4 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -724,8 +724,8 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, size_t num_samples = (audio_frame.len > audio_offset) ? (audio_frame.len - audio_offset) / audio_format.num_channels / (audio_format.bits_per_sample / 8) : 0; if (num_samples > OUTPUT_FREQUENCY / 10) { - printf("Card %d: Dropping frame with implausible audio length (len=%d, offset=%d) [timecode=0x%04x video_len=%d video_offset=%d video_format=%x)\n", - card_index, int(audio_frame.len), int(audio_offset), + printf("%s: Dropping frame with implausible audio length (len=%d, offset=%d) [timecode=0x%04x video_len=%d video_offset=%d video_format=%x)\n", + spec_to_string(device).c_str(), int(audio_frame.len), int(audio_offset), timecode, int(video_frame.len), int(video_offset), video_format.id); if (video_frame.owner) { video_frame.owner->release_frame(video_frame); @@ -746,15 +746,15 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, const int silence_samples = OUTPUT_FREQUENCY * video_format.frame_rate_den / video_format.frame_rate_nom; 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); + fprintf(stderr, "%s lost more than two seconds (or time code jumping around; from 0x%04x to 0x%04x), resetting resampler\n", + spec_to_string(device).c_str(), card->last_timecode, timecode); audio_mixer.reset_resampler(device); dropped_frames = 0; ++card->metric_input_resets; } 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); + fprintf(stderr, "%s dropped %d frame(s) (before timecode 0x%04x), inserting silence.\n", + spec_to_string(device).c_str(), dropped_frames, timecode); card->metric_input_dropped_frames_error += dropped_frames; bool success; @@ -799,8 +799,8 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, if (video_frame.len - video_offset == 0 || video_frame.len - video_offset != expected_length) { if (video_frame.len != 0) { - printf("Card %d: Dropping video frame with wrong length (%ld; expected %ld)\n", - card_index, video_frame.len - video_offset, expected_length); + printf("%s: Dropping video frame with wrong length (%ld; expected %ld)\n", + spec_to_string(device).c_str(), video_frame.len - video_offset, expected_length); } if (video_frame.owner) { video_frame.owner->release_frame(video_frame); diff --git a/resampling_queue.cpp b/resampling_queue.cpp index 06dc6fb..a1a2395 100644 --- a/resampling_queue.cpp +++ b/resampling_queue.cpp @@ -30,8 +30,8 @@ using namespace std; using namespace std::chrono; -ResamplingQueue::ResamplingQueue(unsigned card_num, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds) - : card_num(card_num), freq_in(freq_in), freq_out(freq_out), num_channels(num_channels), +ResamplingQueue::ResamplingQueue(DeviceSpec device_spec, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds) + : device_spec(device_spec), freq_in(freq_in), freq_out(freq_out), num_channels(num_channels), current_estimated_freq_in(freq_in), ratio(double(freq_out) / double(freq_in)), expected_delay(expected_delay_seconds * OUTPUT_FREQUENCY) { @@ -165,8 +165,8 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam if (buffer.empty()) { // This should never happen unless delay is set way too low, // or we're dropping a lot of data. - fprintf(stderr, "Card %u: PANIC: Out of input samples to resample, still need %d output samples! (correction factor is %f)\n", - card_num, int(vresampler.out_count), rcorr); + fprintf(stderr, "%s: PANIC: Out of input samples to resample, still need %d output samples! (correction factor is %f)\n", + spec_to_string(device_spec).c_str(), int(vresampler.out_count), rcorr); memset(vresampler.out_data, 0, vresampler.out_count * num_channels * sizeof(float)); // Reset the loop filter. diff --git a/resampling_queue.h b/resampling_queue.h index b46086d..f0e2499 100644 --- a/resampling_queue.h +++ b/resampling_queue.h @@ -45,11 +45,12 @@ #include #include "defs.h" +#include "input_mapping.h" class ResamplingQueue { public: - // card_num is for debugging outputs only. - ResamplingQueue(unsigned card_num, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds); + // device_spec is for debugging outputs only. + ResamplingQueue(DeviceSpec device_spec, unsigned freq_in, unsigned freq_out, unsigned num_channels, double expected_delay_seconds); // If policy is DO_NOT_ADJUST_RATE, the resampling rate will not be changed. // This is primarily useful if you have an extraordinary situation, such as @@ -68,7 +69,7 @@ private: VResampler vresampler; - unsigned card_num; + DeviceSpec device_spec; unsigned freq_in, freq_out, num_channels; bool first_output = true; -- 2.39.2