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));
}
}
-Subproject commit 6a012a41c5422092cdac1f18a9019f37c0b85368
+Subproject commit e287f28087aef9cfd6aa47acd0d283bc177a9d70
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;
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);
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);
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;
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);
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)
{
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.
#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
VResampler vresampler;
- unsigned card_num;
+ DeviceSpec device_spec;
unsigned freq_in, freq_out, num_channels;
bool first_output = true;