fix: don't log errors while reconnecting
This commit is contained in:
+5
-4
@@ -85,7 +85,7 @@ static void init_inputs() {
|
||||
|
||||
for (unsigned int i = 0; i < init_params.video_in.length; i++) {
|
||||
video_init(&video_captures.values[i], init_params.video_in.values[i],
|
||||
init_params.video_size, init_params.video_buffers);
|
||||
init_params.video_size, init_params.video_buffers, true);
|
||||
|
||||
if (!video_captures.values[i].error) {
|
||||
context.input_resolutions[i][0] = video_captures.values[i].width;
|
||||
@@ -121,7 +121,7 @@ background_reconnect_video_captures(__attribute__((unused)) void *args) {
|
||||
if (video_captures.values[i].disconnected) {
|
||||
video_free(&video_captures.values[i]);
|
||||
video_init(&video_captures.values[i], init_params.video_in.values[i],
|
||||
init_params.video_size, init_params.video_buffers);
|
||||
init_params.video_size, init_params.video_buffers, false);
|
||||
|
||||
if (!video_captures.values[i].error) {
|
||||
context.input_resolutions[i][0] = video_captures.values[i].width;
|
||||
@@ -219,7 +219,8 @@ static void *background_reconnect_midi(__attribute__((unused)) void *args) {
|
||||
while (!context.stop) {
|
||||
sleep(1);
|
||||
if (!midi.connected) {
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"));
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"),
|
||||
false);
|
||||
if (midi.connected) {
|
||||
start_midi_background_listen();
|
||||
}
|
||||
@@ -231,7 +232,7 @@ static void *background_reconnect_midi(__attribute__((unused)) void *args) {
|
||||
static void init_midi() {
|
||||
pthread_t thread;
|
||||
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"));
|
||||
midi_open(&midi, config_file_get_str(&project.config, "MIDI_HW", "hw"), true);
|
||||
|
||||
if (midi.connected) {
|
||||
start_midi_background_listen();
|
||||
|
||||
+22
-5
@@ -6,19 +6,36 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void midi_open(MidiDevice *device, const char *name) {
|
||||
void snd_no_log(__attribute__((unused)) int prio,
|
||||
__attribute__((unused)) int interface,
|
||||
__attribute__((unused)) const char *file,
|
||||
__attribute__((unused)) int line,
|
||||
__attribute__((unused)) const char *function,
|
||||
__attribute__((unused)) int errcode,
|
||||
__attribute__((unused)) const char *fmt,
|
||||
__attribute__((unused)) va_list arg) {}
|
||||
|
||||
void midi_open(MidiDevice *device, const char *name, bool log_error) {
|
||||
strlcpy(device->name, name, STR_LEN);
|
||||
device->connected = false;
|
||||
device->input = NULL;
|
||||
device->output = NULL;
|
||||
|
||||
if (!log_error) {
|
||||
snd_lib_log_set_handler(snd_no_log);
|
||||
}
|
||||
|
||||
snd_rawmidi_open(&device->input, &device->output, name, SND_RAWMIDI_NONBLOCK);
|
||||
|
||||
device->connected = device->input != NULL && device->output != NULL;
|
||||
|
||||
if (device->connected) {
|
||||
log_info("(%s) MIDI open", name);
|
||||
if (log_error) {
|
||||
if (device->connected) {
|
||||
log_info("(%s) MIDI open", name);
|
||||
} else {
|
||||
log_warn("(%s) MIDI open failed", name);
|
||||
}
|
||||
} else {
|
||||
log_warn("(%s) MIDI open failed", name);
|
||||
snd_lib_log_set_handler(snd_lib_vlog);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
#ifndef MIDI_H
|
||||
#define MIDI_H
|
||||
|
||||
void midi_open(MidiDevice *device, const char *name);
|
||||
void midi_open(MidiDevice *device, const char *name, bool log_error);
|
||||
void midi_write(MidiDevice device, unsigned char code, unsigned char value);
|
||||
void *midi_background_listen(void *args);
|
||||
void midi_close(MidiDevice *device);
|
||||
|
||||
+8
-4
@@ -70,14 +70,17 @@ static void ioctl_error(VideoCapture *video_capture, const char *operation,
|
||||
video_capture->error = true;
|
||||
}
|
||||
|
||||
static void open_device(VideoCapture *video_capture, const char *name) {
|
||||
static void open_device(VideoCapture *video_capture, const char *name,
|
||||
bool log_error) {
|
||||
strlcpy(video_capture->name, name, STR_LEN);
|
||||
video_capture->error = false;
|
||||
video_capture->fd = -1;
|
||||
|
||||
video_capture->fd = open(name, O_RDWR | O_NONBLOCK);
|
||||
if (video_capture->fd == -1) {
|
||||
log_warn("(%s) Cannot open device", name);
|
||||
if (log_error) {
|
||||
log_warn("(%s) Cannot open device", name);
|
||||
}
|
||||
video_capture->error = true;
|
||||
}
|
||||
}
|
||||
@@ -305,8 +308,9 @@ static unsigned int read_video(VideoCapture *video_capture) {
|
||||
}
|
||||
|
||||
void video_init(VideoCapture *video_capture, const char *name,
|
||||
unsigned int preferred_height, unsigned int buffer_count) {
|
||||
open_device(video_capture, name);
|
||||
unsigned int preferred_height, unsigned int buffer_count,
|
||||
bool log_error) {
|
||||
open_device(video_capture, name, log_error);
|
||||
|
||||
if (video_capture->error) {
|
||||
return;
|
||||
|
||||
+2
-1
@@ -6,7 +6,8 @@
|
||||
#ifdef VIDEO_IN
|
||||
|
||||
void video_init(VideoCapture *video_capture, const char *name,
|
||||
unsigned int preferred_height, unsigned int buffer_count);
|
||||
unsigned int preferred_height, unsigned int buffer_count,
|
||||
bool log_error);
|
||||
|
||||
void *video_background_read(void *args);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user