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++) {
|
for (unsigned int i = 0; i < init_params.video_in.length; i++) {
|
||||||
video_init(&video_captures.values[i], init_params.video_in.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, true);
|
||||||
|
|
||||||
if (!video_captures.values[i].error) {
|
if (!video_captures.values[i].error) {
|
||||||
context.input_resolutions[i][0] = video_captures.values[i].width;
|
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) {
|
if (video_captures.values[i].disconnected) {
|
||||||
video_free(&video_captures.values[i]);
|
video_free(&video_captures.values[i]);
|
||||||
video_init(&video_captures.values[i], init_params.video_in.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) {
|
if (!video_captures.values[i].error) {
|
||||||
context.input_resolutions[i][0] = video_captures.values[i].width;
|
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) {
|
while (!context.stop) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
if (!midi.connected) {
|
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) {
|
if (midi.connected) {
|
||||||
start_midi_background_listen();
|
start_midi_background_listen();
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ static void *background_reconnect_midi(__attribute__((unused)) void *args) {
|
|||||||
static void init_midi() {
|
static void init_midi() {
|
||||||
pthread_t thread;
|
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) {
|
if (midi.connected) {
|
||||||
start_midi_background_listen();
|
start_midi_background_listen();
|
||||||
|
|||||||
+19
-2
@@ -6,20 +6,37 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#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);
|
strlcpy(device->name, name, STR_LEN);
|
||||||
|
device->connected = false;
|
||||||
device->input = NULL;
|
device->input = NULL;
|
||||||
device->output = 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);
|
snd_rawmidi_open(&device->input, &device->output, name, SND_RAWMIDI_NONBLOCK);
|
||||||
|
|
||||||
device->connected = device->input != NULL && device->output != NULL;
|
device->connected = device->input != NULL && device->output != NULL;
|
||||||
|
if (log_error) {
|
||||||
if (device->connected) {
|
if (device->connected) {
|
||||||
log_info("(%s) MIDI open", name);
|
log_info("(%s) MIDI open", name);
|
||||||
} else {
|
} else {
|
||||||
log_warn("(%s) MIDI open failed", name);
|
log_warn("(%s) MIDI open failed", name);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
snd_lib_log_set_handler(snd_lib_vlog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void midi_write(MidiDevice device, unsigned char code, unsigned char value) {
|
void midi_write(MidiDevice device, unsigned char code, unsigned char value) {
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
#ifndef MIDI_H
|
#ifndef MIDI_H
|
||||||
#define 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_write(MidiDevice device, unsigned char code, unsigned char value);
|
||||||
void *midi_background_listen(void *args);
|
void *midi_background_listen(void *args);
|
||||||
void midi_close(MidiDevice *device);
|
void midi_close(MidiDevice *device);
|
||||||
|
|||||||
+7
-3
@@ -70,14 +70,17 @@ static void ioctl_error(VideoCapture *video_capture, const char *operation,
|
|||||||
video_capture->error = true;
|
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);
|
strlcpy(video_capture->name, name, STR_LEN);
|
||||||
video_capture->error = false;
|
video_capture->error = false;
|
||||||
video_capture->fd = -1;
|
video_capture->fd = -1;
|
||||||
|
|
||||||
video_capture->fd = open(name, O_RDWR | O_NONBLOCK);
|
video_capture->fd = open(name, O_RDWR | O_NONBLOCK);
|
||||||
if (video_capture->fd == -1) {
|
if (video_capture->fd == -1) {
|
||||||
|
if (log_error) {
|
||||||
log_warn("(%s) Cannot open device", name);
|
log_warn("(%s) Cannot open device", name);
|
||||||
|
}
|
||||||
video_capture->error = true;
|
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,
|
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,
|
||||||
open_device(video_capture, name);
|
bool log_error) {
|
||||||
|
open_device(video_capture, name, log_error);
|
||||||
|
|
||||||
if (video_capture->error) {
|
if (video_capture->error) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-1
@@ -6,7 +6,8 @@
|
|||||||
#ifdef VIDEO_IN
|
#ifdef VIDEO_IN
|
||||||
|
|
||||||
void video_init(VideoCapture *video_capture, const char *name,
|
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);
|
void *video_background_read(void *args);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user