]> git.sesse.net Git - nageru/commitdiff
When outputting debug messages for an audio device, refer to the device spec instead...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 18 Apr 2018 20:08:09 +0000 (22:08 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 22 Apr 2018 13:17:32 +0000 (15:17 +0200)
audio_mixer.cpp
bmusb
input_mapping.cpp
input_mapping.h
mixer.cpp
resampling_queue.cpp
resampling_queue.h

index 468edd531859b75793750564bc6a29f433a1675b..887b1056ac1799c8ce8f2075041ff6ecf32bf4f1 100644 (file)
@@ -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 6a012a41c5422092cdac1f18a9019f37c0b85368..e287f28087aef9cfd6aa47acd0d283bc177a9d70 160000 (submodule)
--- a/bmusb
+++ b/bmusb
@@ -1 +1 @@
-Subproject commit 6a012a41c5422092cdac1f18a9019f37c0b85368
+Subproject commit e287f28087aef9cfd6aa47acd0d283bc177a9d70
index deef92343c75c542b5aa9ecc698e8a4d94dec591..f894c95643cd6940e088f047e8d005193d9ffcad 100644 (file)
 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 "<silence>";
+       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<DeviceSpec, DeviceInfo> &devices, const InputMapping &input_mapping, const string &filename)
 {
        InputMappingProto mapping_proto;
index 10c3ca2901be0afe870ec9cbefc40ec9c31e0a60..540fde39e0bb4c3378e9292e0d9ab23d496de508 100644 (file)
@@ -47,6 +47,10 @@ struct InputMapping {
        std::vector<Bus> 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<DeviceSpec, DeviceInfo> &devices,
                                 const InputMapping &mapping,
                                 const std::string &filename);
index 202617b9b718aae8b05ffb3872bafce980cc5b2a..cbc66d423ccd94682b3eb67304f0d04744961ba4 100644 (file)
--- 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);
index 06dc6fbf417bb1a13aae39f4cbf527e7740e5b6f..a1a2395533ae168abf1efe2a737cf710a9722e0a 100644 (file)
@@ -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.
index b46086df9d0954a4aebd3af0acb3937ca6e314de..f0e2499cbf3300e9b4340430b85bf33f25862006 100644 (file)
 #include <memory>
 
 #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;