janus: using generic logging system

This commit is contained in:
Maxim Devaev
2026-06-12 17:53:32 +03:00
parent 31b98f1d59
commit 0e0aef7b80
7 changed files with 74 additions and 80 deletions

View File

@@ -60,14 +60,14 @@ us_acap_s *us_acap_init(const char *name, uint pcm_hz) {
{ {
if ((err = snd_pcm_open(&acap->dev, name, SND_PCM_STREAM_CAPTURE, 0)) < 0) { if ((err = snd_pcm_open(&acap->dev, name, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
acap->dev = NULL; acap->dev = NULL;
US_JLOG_PERROR_ALSA(err, "acap", "Can't open PCM capture"); US_LOG_PERROR_ALSA(err, "Can't open PCM capture");
goto error; goto error;
} }
assert(!snd_pcm_hw_params_malloc(&acap->dev_params)); assert(!snd_pcm_hw_params_malloc(&acap->dev_params));
# define SET_PARAM(_msg, _func, ...) { \ # define SET_PARAM(_msg, _func, ...) { \
if ((err = _func(acap->dev, acap->dev_params, ##__VA_ARGS__)) < 0) { \ if ((err = _func(acap->dev, acap->dev_params, ##__VA_ARGS__)) < 0) { \
US_JLOG_PERROR_ALSA(err, "acap", _msg); \ US_LOG_PERROR_ALSA(err, _msg); \
goto error; \ goto error; \
} \ } \
} }
@@ -78,7 +78,7 @@ us_acap_s *us_acap_init(const char *name, uint pcm_hz) {
SET_PARAM("Can't set PCM sampling format", snd_pcm_hw_params_set_format, SND_PCM_FORMAT_S16_LE); SET_PARAM("Can't set PCM sampling format", snd_pcm_hw_params_set_format, SND_PCM_FORMAT_S16_LE);
SET_PARAM("Can't set PCM sampling rate", snd_pcm_hw_params_set_rate_near, &acap->pcm_hz, 0); SET_PARAM("Can't set PCM sampling rate", snd_pcm_hw_params_set_rate_near, &acap->pcm_hz, 0);
if (acap->pcm_hz < US_AU_MIN_PCM_HZ || acap->pcm_hz > US_AU_MAX_PCM_HZ) { if (acap->pcm_hz < US_AU_MIN_PCM_HZ || acap->pcm_hz > US_AU_MAX_PCM_HZ) {
US_JLOG_ERROR("acap", "Unsupported PCM freq: %u; should be: %u <= F <= %u", US_LOG_ERROR("Unsupported PCM freq: %u; should be: %u <= F <= %u",
acap->pcm_hz, US_AU_MIN_PCM_HZ, US_AU_MAX_PCM_HZ); acap->pcm_hz, US_AU_MIN_PCM_HZ, US_AU_MAX_PCM_HZ);
goto error; goto error;
} }
@@ -93,7 +93,7 @@ us_acap_s *us_acap_init(const char *name, uint pcm_hz) {
acap->res = speex_resampler_init(US_RTP_OPUS_CH, acap->pcm_hz, US_RTP_OPUS_HZ, SPEEX_RESAMPLER_QUALITY_DESKTOP, &err); acap->res = speex_resampler_init(US_RTP_OPUS_CH, acap->pcm_hz, US_RTP_OPUS_HZ, SPEEX_RESAMPLER_QUALITY_DESKTOP, &err);
if (err < 0) { if (err < 0) {
acap->res = NULL; acap->res = NULL;
US_JLOG_PERROR_RES(err, "acap", "Can't create resampler"); US_LOG_PERROR_RES(err, "Can't create resampler");
goto error; goto error;
} }
} }
@@ -110,7 +110,7 @@ us_acap_s *us_acap_init(const char *name, uint pcm_hz) {
// OPUS_SET_INBAND_FEC(1), OPUS_SET_PACKET_LOSS_PERC(10): see rtpa.c // OPUS_SET_INBAND_FEC(1), OPUS_SET_PACKET_LOSS_PERC(10): see rtpa.c
} }
US_JLOG_INFO("acap", "Capture configured on %uHz; capturing ...", acap->pcm_hz); US_LOG_INFO("Capture configured on %uHz; capturing ...", acap->pcm_hz);
acap->tids_created = true; acap->tids_created = true;
US_THREAD_CREATE(acap->enc_tid, _encoder_thread, acap); US_THREAD_CREATE(acap->enc_tid, _encoder_thread, acap);
US_THREAD_CREATE(acap->pcm_tid, _pcm_thread, acap); US_THREAD_CREATE(acap->pcm_tid, _pcm_thread, acap);
@@ -135,7 +135,7 @@ void us_acap_destroy(us_acap_s *acap) {
US_RING_DELETE_WITH_ITEMS(acap->enc_ring, us_au_encoded_destroy); US_RING_DELETE_WITH_ITEMS(acap->enc_ring, us_au_encoded_destroy);
US_RING_DELETE_WITH_ITEMS(acap->pcm_ring, us_au_pcm_destroy); US_RING_DELETE_WITH_ITEMS(acap->pcm_ring, us_au_pcm_destroy);
if (acap->tids_created) { if (acap->tids_created) {
US_JLOG_INFO("acap", "Capture closed"); US_LOG_INFO("Capture closed");
} }
free(acap); free(acap);
} }
@@ -161,7 +161,7 @@ int us_acap_get_encoded(us_acap_s *acap, u8 *data, uz *size, u64 *pts) {
} }
static void *_pcm_thread(void *v_acap) { static void *_pcm_thread(void *v_acap) {
US_THREAD_SETTLE("us_ac_pcm"); US_THREAD_SETTLE("us_acap_pcm");
us_acap_s *const acap = v_acap; us_acap_s *const acap = v_acap;
u8 in[US_AU_MAX_BUF8]; u8 in[US_AU_MAX_BUF8];
@@ -169,10 +169,10 @@ static void *_pcm_thread(void *v_acap) {
while (!atomic_load(&acap->stop)) { while (!atomic_load(&acap->stop)) {
const int frames = snd_pcm_readi(acap->dev, in, acap->pcm_frames); const int frames = snd_pcm_readi(acap->dev, in, acap->pcm_frames);
if (frames < 0) { if (frames < 0) {
US_JLOG_PERROR_ALSA(frames, "acap", "Fatal: Can't capture PCM frames"); US_LOG_PERROR_ALSA(frames, "Fatal: Can't capture PCM frames");
break; break;
} else if (frames < (int)acap->pcm_frames) { } else if (frames < (int)acap->pcm_frames) {
US_JLOG_ERROR("acap", "Fatal: Too few PCM frames captured"); US_LOG_ERROR("Fatal: Too few PCM frames captured");
break; break;
} }
@@ -182,7 +182,7 @@ static void *_pcm_thread(void *v_acap) {
memcpy(out->data, in, acap->pcm_size); memcpy(out->data, in, acap->pcm_size);
us_ring_producer_release(acap->pcm_ring, ri); us_ring_producer_release(acap->pcm_ring, ri);
} else { } else {
US_JLOG_ERROR("acap", "PCM ring is full"); US_LOG_ERROR("PCM ring is full");
} }
} }
@@ -191,7 +191,7 @@ static void *_pcm_thread(void *v_acap) {
} }
static void *_encoder_thread(void *v_acap) { static void *_encoder_thread(void *v_acap) {
US_THREAD_SETTLE("us_ac_enc"); US_THREAD_SETTLE("us_acap_enc");
us_acap_s *const acap = v_acap; us_acap_s *const acap = v_acap;
s16 in_res[US_AU_MAX_BUF16]; s16 in_res[US_AU_MAX_BUF16];
@@ -217,7 +217,7 @@ static void *_encoder_thread(void *v_acap) {
const int out_ri = us_ring_producer_acquire(acap->enc_ring, 0); const int out_ri = us_ring_producer_acquire(acap->enc_ring, 0);
if (out_ri < 0) { if (out_ri < 0) {
US_JLOG_ERROR("acap", "OPUS encoder queue is full"); US_LOG_ERROR("OPUS encoder queue is full");
us_ring_consumer_release(acap->pcm_ring, in_ri); us_ring_consumer_release(acap->pcm_ring, in_ri);
continue; continue;
} }
@@ -233,7 +233,7 @@ static void *_encoder_thread(void *v_acap) {
acap->pts += US_AU_HZ_TO_FRAMES(US_RTP_OPUS_HZ); acap->pts += US_AU_HZ_TO_FRAMES(US_RTP_OPUS_HZ);
} else { } else {
out->used = 0; out->used = 0;
US_JLOG_PERROR_OPUS(size, "acap", "Fatal: Can't encode PCM frame to OPUS"); US_LOG_PERROR_OPUS(size, "Fatal: Can't encode PCM frame to OPUS");
} }
us_ring_producer_release(acap->enc_ring, out_ri); us_ring_producer_release(acap->enc_ring, out_ri);
} }

View File

@@ -102,7 +102,7 @@ void us_janus_client_send(us_janus_client_s *client, const us_rtp_s *rtp) {
us_ring_s *const ring = (rtp->video ? client->video_ring : client->acap_ring); us_ring_s *const ring = (rtp->video ? client->video_ring : client->acap_ring);
const int ri = us_ring_producer_acquire(ring, 0); const int ri = us_ring_producer_acquire(ring, 0);
if (ri < 0) { if (ri < 0) {
US_JLOG_ERROR("client", "Session %p %s ring is full", US_LOG_ERROR("Session %p %s ring is full",
client->session, (rtp->video ? "video" : "acap")); client->session, (rtp->video ? "video" : "acap"));
return; return;
} }
@@ -142,7 +142,7 @@ void us_janus_client_recv(us_janus_client_s *client, janus_plugin_rtp *packet) {
us_ring_s *const ring = client->aplay_enc_ring; us_ring_s *const ring = client->aplay_enc_ring;
const int ri = us_ring_producer_acquire(ring, 0); const int ri = us_ring_producer_acquire(ring, 0);
if (ri < 0) { if (ri < 0) {
// US_JLOG_ERROR("client", "Session %p aplay ring is full", client->session); // US_LOG_ERROR("Session %p aplay ring is full", client->session);
return; return;
} }
us_au_encoded_s *enc = ring->items[ri]; us_au_encoded_s *enc = ring->items[ri];
@@ -157,12 +157,12 @@ void us_janus_client_recv(us_janus_client_s *client, janus_plugin_rtp *packet) {
} }
static void *_video_thread(void *v_client) { static void *_video_thread(void *v_client) {
US_THREAD_SETTLE("us_cx_vid"); US_THREAD_SETTLE("us_cx_vcap");
return _video_or_acap_thread(v_client, true); return _video_or_acap_thread(v_client, true);
} }
static void *_acap_thread(void *v_client) { static void *_acap_thread(void *v_client) {
US_THREAD_SETTLE("us_cx_ac"); US_THREAD_SETTLE("us_cx_acap");
return _video_or_acap_thread(v_client, false); return _video_or_acap_thread(v_client, false);
} }
@@ -236,7 +236,7 @@ static void *_video_or_acap_thread(void *v_client, bool video) {
} }
static void *_aplay_thread(void *v_client) { static void *_aplay_thread(void *v_client) {
US_THREAD_SETTLE("us_cx_ap"); US_THREAD_SETTLE("us_cx_aplay");
us_janus_client_s *const client = v_client; us_janus_client_s *const client = v_client;
@@ -258,7 +258,7 @@ static void *_aplay_thread(void *v_client) {
const int out_ri = us_ring_producer_acquire(client->aplay_pcm_ring, 0); const int out_ri = us_ring_producer_acquire(client->aplay_pcm_ring, 0);
if (out_ri < 0) { if (out_ri < 0) {
US_JLOG_ERROR("aplay", "OPUS decoder queue is full"); US_LOG_ERROR("OPUS decoder queue is full");
us_ring_consumer_release(client->aplay_enc_ring, in_ri); us_ring_consumer_release(client->aplay_enc_ring, in_ri);
continue; continue;
} }
@@ -271,7 +271,7 @@ static void *_aplay_thread(void *v_client) {
out->frames = frames; out->frames = frames;
} else { } else {
out->frames = 0; out->frames = 0;
US_JLOG_PERROR_OPUS(frames, "aplay", "Fatal: Can't decode OPUS to PCM frame"); US_LOG_PERROR_OPUS(frames, "Fatal: Can't decode OPUS to PCM frame");
} }
us_ring_producer_release(client->aplay_pcm_ring, out_ri); us_ring_producer_release(client->aplay_pcm_ring, out_ri);
} }

View File

@@ -48,24 +48,24 @@ us_config_s *us_config_init(const char *config_dir_path) {
janus_config *jcfg = NULL; janus_config *jcfg = NULL;
US_ASPRINTF(config_file_path, "%s/%s.jcfg", config_dir_path, US_PLUGIN_PACKAGE); US_ASPRINTF(config_file_path, "%s/%s.jcfg", config_dir_path, US_PLUGIN_PACKAGE);
US_JLOG_INFO("config", "Reading config file '%s' ...", config_file_path); US_LOG_INFO("Reading config file '%s' ...", config_file_path);
jcfg = janus_config_parse(config_file_path); jcfg = janus_config_parse(config_file_path);
if (jcfg == NULL) { if (jcfg == NULL) {
US_JLOG_ERROR("config", "Can't read config"); US_LOG_ERROR("Can't read config");
goto error; goto error;
} }
janus_config_print(jcfg); janus_config_print(jcfg);
if ((config->video_sink_name = _get_value(jcfg, "video", "sink")) == NULL) { if ((config->video_sink_name = _get_value(jcfg, "video", "sink")) == NULL) {
US_JLOG_ERROR("config", "Missing config value: video.sink"); US_LOG_ERROR("Missing config value: video.sink");
goto error; goto error;
} }
if ((config->acap_dev_name = _get_value(jcfg, "acap", "device")) != NULL) { if ((config->acap_dev_name = _get_value(jcfg, "acap", "device")) != NULL) {
config->acap_hz = _get_uint(jcfg, "acap", "sampling_rate", 0); config->acap_hz = _get_uint(jcfg, "acap", "sampling_rate", 0);
config->tc358743_dev_path = _get_value(jcfg, "acap", "tc358743"); config->tc358743_dev_path = _get_value(jcfg, "acap", "tc358743");
if (config->acap_hz == 0 && config->tc358743_dev_path == NULL) { if (config->acap_hz == 0 && config->tc358743_dev_path == NULL) {
US_JLOG_ERROR("config", "Either acap.sampling_rate or acap.tc358743 required"); US_LOG_ERROR("Either acap.sampling_rate or acap.tc358743 required");
goto error; goto error;
} }
} }

View File

@@ -41,14 +41,14 @@ int us_memsink_fd_wait_frame(int fd, us_memsink_shared_s *mem, u64 last_id) {
const int result = us_flock_timedwait_monotonic(fd, 1); // lock_timeout const int result = us_flock_timedwait_monotonic(fd, 1); // lock_timeout
now_ts = us_get_now_monotonic(); now_ts = us_get_now_monotonic();
if (result < 0 && errno != EWOULDBLOCK) { if (result < 0 && errno != EWOULDBLOCK) {
US_JLOG_PERROR("video", "Can't lock memsink"); US_LOG_PERROR("Can't lock memsink");
return -1; return -1;
} else if (result == 0) { } else if (result == 0) {
if (mem->magic == US_MEMSINK_MAGIC && mem->version == US_MEMSINK_VERSION && mem->id != last_id) { if (mem->magic == US_MEMSINK_MAGIC && mem->version == US_MEMSINK_VERSION && mem->id != last_id) {
return 0; return 0;
} }
if (flock(fd, LOCK_UN) < 0) { if (flock(fd, LOCK_UN) < 0) {
US_JLOG_PERROR("video", "Can't unlock memsink"); US_LOG_PERROR("Can't unlock memsink");
return -1; return -1;
} }
} }
@@ -68,11 +68,11 @@ int us_memsink_fd_get_frame(int fd, us_memsink_shared_s *mem, us_frame_s *frame,
bool retval = 0; bool retval = 0;
if (frame->format != V4L2_PIX_FMT_H264) { if (frame->format != V4L2_PIX_FMT_H264) {
US_JLOG_ERROR("video", "Got non-H264 frame from memsink"); US_LOG_ERROR("Got non-H264 frame from memsink");
retval = -1; retval = -1;
} }
if (flock(fd, LOCK_UN) < 0) { if (flock(fd, LOCK_UN) < 0) {
US_JLOG_PERROR("video", "Can't unlock memsink"); US_LOG_PERROR("Can't unlock memsink");
retval = -1; retval = -1;
} }
return retval; return retval;

View File

@@ -136,7 +136,7 @@ static void *_video_rtp_thread(void *arg) {
static void *_video_sink_thread(void *arg) { static void *_video_sink_thread(void *arg) {
(void)arg; (void)arg;
US_THREAD_SETTLE("us_p_vsink"); US_THREAD_SETTLE("us_p_vcap");
atomic_store(&_g_video_sink_tid_created, true); atomic_store(&_g_video_sink_tid_created, true);
us_frame_s *drop = us_frame_init(); us_frame_s *drop = us_frame_init();
@@ -145,7 +145,7 @@ static void *_video_sink_thread(void *arg) {
while (!_STOP) { while (!_STOP) {
if (!_HAS_WATCHERS) { if (!_HAS_WATCHERS) {
US_ONCE({ US_JLOG_INFO("video", "No active watchers, memsink disconnected"); }); US_ONCE({ US_LOG_INFO("No active watchers, memsink disconnected"); });
usleep(_g_watchers_polling); usleep(_g_watchers_polling);
continue; continue;
} }
@@ -155,23 +155,23 @@ static void *_video_sink_thread(void *arg) {
const uz data_size = us_memsink_calculate_size(_g_config->video_sink_name); const uz data_size = us_memsink_calculate_size(_g_config->video_sink_name);
if (data_size == 0) { if (data_size == 0) {
US_ONCE({ US_JLOG_ERROR("video", "Invalid memsink object suffix"); }); US_ONCE({ US_LOG_ERROR("Invalid memsink object suffix"); });
goto close_memsink; goto close_memsink;
} }
if ((fd = shm_open(_g_config->video_sink_name, O_RDWR, 0)) <= 0) { if ((fd = shm_open(_g_config->video_sink_name, O_RDWR, 0)) <= 0) {
US_ONCE({ US_JLOG_PERROR("video", "Can't open memsink"); }); US_ONCE({ US_LOG_PERROR("Can't open memsink"); });
goto close_memsink; goto close_memsink;
} }
if ((mem = us_memsink_shared_map(fd, data_size)) == NULL) { if ((mem = us_memsink_shared_map(fd, data_size)) == NULL) {
US_ONCE({ US_JLOG_PERROR("video", "Can't map memsink"); }); US_ONCE({ US_LOG_PERROR("Can't map memsink"); });
goto close_memsink; goto close_memsink;
} }
once = 0; once = 0;
US_JLOG_INFO("video", "Memsink opened; reading frames ..."); US_LOG_INFO("Memsink opened; reading frames ...");
while (!_STOP && _HAS_WATCHERS) { while (!_STOP && _HAS_WATCHERS) {
const int waited = us_memsink_fd_wait_frame(fd, mem, frame_id); const int waited = us_memsink_fd_wait_frame(fd, mem, frame_id);
if (waited == 0) { if (waited == 0) {
@@ -180,7 +180,7 @@ static void *_video_sink_thread(void *arg) {
if (ri >= 0) { if (ri >= 0) {
frame = _g_video_ring->items[ri]; frame = _g_video_ring->items[ri];
} else { } else {
US_ONCE({ US_JLOG_PERROR("video", "Video ring is full"); }); US_ONCE({ US_LOG_PERROR("Video ring is full"); });
frame = drop; frame = drop;
} }
@@ -206,7 +206,7 @@ static void *_video_sink_thread(void *arg) {
mem = NULL; mem = NULL;
} }
US_CLOSE_FD(fd); US_CLOSE_FD(fd);
US_JLOG_INFO("video", "Memsink closed"); US_LOG_INFO("Memsink closed");
sleep(1); // error_delay sleep(1); // error_delay
} }
@@ -220,17 +220,17 @@ static int _get_acap_hz(uint *hz) {
return 0; return 0;
} }
if (_g_config->tc358743_dev_path == NULL) { if (_g_config->tc358743_dev_path == NULL) {
US_JLOG_ERROR("acap", "No configured sampling rate"); US_LOG_ERROR("No configured sampling rate");
return -1; return -1;
} }
int fd; int fd;
if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) { if ((fd = open(_g_config->tc358743_dev_path, O_RDWR)) < 0) {
US_JLOG_PERROR("acap", "Can't open TC358743 V4L2 device"); US_LOG_PERROR("Can't open TC358743 V4L2 device");
return -1; return -1;
} }
const int checked = us_tc358743_xioctl_get_audio_hz(fd, hz); const int checked = us_tc358743_xioctl_get_audio_hz(fd, hz);
if (checked < 0) { if (checked < 0) {
US_JLOG_PERROR("acap", "Can't check TC358743 audio state (%d)", checked); US_LOG_PERROR("Can't check TC358743 audio state (%d)", checked);
close(fd); close(fd);
return -1; return -1;
} }
@@ -240,7 +240,7 @@ static int _get_acap_hz(uint *hz) {
static void *_acap_thread(void *arg) { static void *_acap_thread(void *arg) {
(void)arg; (void)arg;
US_THREAD_SETTLE("us_p_ac"); US_THREAD_SETTLE("us_p_acap");
atomic_store(&_g_acap_tid_created, true); atomic_store(&_g_acap_tid_created, true);
assert(_g_config->acap_dev_name != NULL); assert(_g_config->acap_dev_name != NULL);
@@ -258,17 +258,17 @@ static void *_acap_thread(void *arg) {
us_acap_s *acap = NULL; us_acap_s *acap = NULL;
if (!us_au_probe(_g_config->acap_dev_name)) { if (!us_au_probe(_g_config->acap_dev_name)) {
US_ONCE({ US_JLOG_ERROR("acap", "No PCM capture device"); }); US_ONCE({ US_LOG_ERROR("No PCM capture device"); });
goto close_acap; goto close_acap;
} }
if (_get_acap_hz(&hz) < 0) { if (_get_acap_hz(&hz) < 0) {
goto close_acap; goto close_acap;
} }
if (hz == 0) { if (hz == 0) {
US_ONCE({ US_JLOG_INFO("acap", "No audio presented from the host"); }); US_ONCE({ US_LOG_INFO("No audio presented from the host"); });
goto close_acap; goto close_acap;
} }
US_ONCE({ US_JLOG_INFO("acap", "Detected host audio"); }); US_ONCE({ US_LOG_INFO("Detected host audio"); });
if ((acap = us_acap_init(_g_config->acap_dev_name, hz)) == NULL) { if ((acap = us_acap_init(_g_config->acap_dev_name, hz)) == NULL) {
goto close_acap; goto close_acap;
} }
@@ -301,7 +301,7 @@ static void *_acap_thread(void *arg) {
static void *_aplay_thread(void *arg) { static void *_aplay_thread(void *arg) {
(void)arg; (void)arg;
US_THREAD_SETTLE("us_p_ap"); US_THREAD_SETTLE("us_p_aplay");
atomic_store(&_g_aplay_tid_created, true); atomic_store(&_g_aplay_tid_created, true);
assert(_g_config->aplay_dev_name != NULL); assert(_g_config->aplay_dev_name != NULL);
@@ -330,10 +330,10 @@ static void *_aplay_thread(void *arg) {
} }
} while (skip && !_STOP); } while (skip && !_STOP);
us_au_pcm_mix(&mixed, &last); us_au_pcm_mix(&mixed, &last);
// US_JLOG_INFO("++++++", "mixed %p", client); // US_LOG_INFO("++++++ mixed %p", client);
}); });
_UNLOCK_APLAY; _UNLOCK_APLAY;
// US_JLOG_INFO("++++++", "--------------"); // US_LOG_INFO("++++++ --------------");
if (skip) { if (skip) {
static uint skipped = 0; static uint skipped = 0;
@@ -351,13 +351,13 @@ static void *_aplay_thread(void *arg) {
if (dev == NULL) { if (dev == NULL) {
if (!us_au_probe(_g_config->aplay_dev_name)) { if (!us_au_probe(_g_config->aplay_dev_name)) {
US_ONCE({ US_JLOG_ERROR("aplay", "No PCM playback device"); }); US_ONCE({ US_LOG_ERROR("No PCM playback device"); });
goto close_aplay; goto close_aplay;
} }
int err = snd_pcm_open(&dev, _g_config->aplay_dev_name, SND_PCM_STREAM_PLAYBACK, 0); int err = snd_pcm_open(&dev, _g_config->aplay_dev_name, SND_PCM_STREAM_PLAYBACK, 0);
if (err < 0) { if (err < 0) {
US_ONCE({ US_JLOG_PERROR_ALSA(err, "aplay", "Can't open PCM playback"); }); US_ONCE({ US_LOG_PERROR_ALSA(err, "Can't open PCM playback"); });
goto close_aplay; goto close_aplay;
} }
@@ -365,11 +365,11 @@ static void *_aplay_thread(void *arg) {
US_RTP_OPUS_CH, US_RTP_OPUS_HZ, 1 /* soft resample */, 50000 /* 50000 = 0.05sec */ US_RTP_OPUS_CH, US_RTP_OPUS_HZ, 1 /* soft resample */, 50000 /* 50000 = 0.05sec */
); );
if (err < 0) { if (err < 0) {
US_ONCE({ US_JLOG_PERROR_ALSA(err, "aplay", "Can't configure PCM playback"); }); US_ONCE({ US_LOG_PERROR_ALSA(err, "Can't configure PCM playback"); });
goto close_aplay; goto close_aplay;
} }
US_JLOG_INFO("aplay", "Playback opened, playing ..."); US_LOG_INFO("Playback opened, playing ...");
once = 0; once = 0;
} }
@@ -379,20 +379,20 @@ static void *_aplay_thread(void *arg) {
frames = snd_pcm_recover(dev, frames, 1); frames = snd_pcm_recover(dev, frames, 1);
} else { } else {
if (once != 0) { if (once != 0) {
US_JLOG_INFO("aplay", "Playing resumed (snd_pcm_writei) ..."); US_LOG_INFO("Playing resumed (snd_pcm_writei) ...");
} }
once = 0; once = 0;
skip = false; skip = false;
} }
if (frames < 0) { if (frames < 0) {
US_ONCE({ US_JLOG_PERROR_ALSA(frames, "aplay", "Can't play to PCM playback"); }); US_ONCE({ US_LOG_PERROR_ALSA(frames, "Can't play to PCM playback"); });
if (frames == -ENODEV) { if (frames == -ENODEV) {
goto close_aplay; goto close_aplay;
} }
skip = true; skip = true;
} else { } else {
if (once != 0) { if (once != 0) {
US_JLOG_INFO("aplay", "Playing resumed (snd_pcm_recover) ..."); US_LOG_INFO("Playing resumed (snd_pcm_recover) ...");
} }
once = 0; once = 0;
skip = false; skip = false;
@@ -403,7 +403,7 @@ static void *_aplay_thread(void *arg) {
close_aplay: close_aplay:
if (dev != NULL) { if (dev != NULL) {
US_DELETE(dev, snd_pcm_close); US_DELETE(dev, snd_pcm_close);
US_JLOG_INFO("aplay", "Playback closed"); US_LOG_INFO("Playback closed");
} }
} }
return NULL; return NULL;
@@ -432,7 +432,7 @@ static int _plugin_init(janus_callbacks *gw, const char *config_dir_path) {
US_LOGGING_INIT; US_LOGGING_INIT;
US_JLOG_INFO("main", "Initializing PiKVM uStreamer plugin %s ...", US_VERSION); US_LOG_INFO("Initializing PiKVM uStreamer plugin %s ...", US_VERSION);
if (gw == NULL || config_dir_path == NULL || ((_g_config = us_config_init(config_dir_path)) == NULL)) { if (gw == NULL || config_dir_path == NULL || ((_g_config = us_config_init(config_dir_path)) == NULL)) {
return -1; return -1;
} }
@@ -457,7 +457,7 @@ static int _plugin_init(janus_callbacks *gw, const char *config_dir_path) {
} }
static void _plugin_destroy(void) { static void _plugin_destroy(void) {
US_JLOG_INFO("main", "Destroying plugin ..."); US_LOG_INFO("Destroying plugin ...");
atomic_store(&_g_stop, true); atomic_store(&_g_stop, true);
# define JOIN(_tid) { if (atomic_load(&_tid##_created)) { US_THREAD_JOIN(_tid); } } # define JOIN(_tid) { if (atomic_load(&_tid##_created)) { US_THREAD_JOIN(_tid); } }
@@ -484,7 +484,7 @@ static void _plugin_destroy(void) {
static void _plugin_create_session(janus_plugin_session *session, int *err) { static void _plugin_create_session(janus_plugin_session *session, int *err) {
_IF_DISABLED({ *err = -1; return; }); _IF_DISABLED({ *err = -1; return; });
_LOCK_ALL; _LOCK_ALL;
US_JLOG_INFO("main", "Creating session %p ...", session); US_LOG_INFO("Creating session %p ...", session);
us_janus_client_s *const client = us_janus_client_init(_g_gw, session); us_janus_client_s *const client = us_janus_client_init(_g_gw, session);
US_LIST_APPEND(_g_clients, client); US_LIST_APPEND(_g_clients, client);
atomic_store(&_g_has_watchers, true); atomic_store(&_g_has_watchers, true);
@@ -500,7 +500,7 @@ static void _plugin_destroy_session(janus_plugin_session* session, int *err) {
bool has_speakers = false; bool has_speakers = false;
US_LIST_ITERATE(_g_clients, client, { US_LIST_ITERATE(_g_clients, client, {
if (client->session == session) { if (client->session == session) {
US_JLOG_INFO("main", "Removing session %p ...", session); US_LOG_INFO("Removing session %p ...", session);
US_LIST_REMOVE(_g_clients, client); US_LIST_REMOVE(_g_clients, client);
us_janus_client_destroy(client); us_janus_client_destroy(client);
found = true; found = true;
@@ -511,7 +511,7 @@ static void _plugin_destroy_session(janus_plugin_session* session, int *err) {
} }
}); });
if (!found) { if (!found) {
US_JLOG_WARN("main", "No session %p", session); US_LOG_ERROR("No session %p", session);
*err = -2; *err = -2;
} }
atomic_store(&_g_has_watchers, has_watchers); atomic_store(&_g_has_watchers, has_watchers);
@@ -543,13 +543,13 @@ static void _set_transmit(janus_plugin_session *session, const char *msg, bool t
US_LIST_ITERATE(_g_clients, client, { US_LIST_ITERATE(_g_clients, client, {
if (client->session == session) { if (client->session == session) {
atomic_store(&client->transmit, transmit); atomic_store(&client->transmit, transmit);
// US_JLOG_INFO("main", "%s session %p", msg, session); // US_LOG_INFO("%s session %p", msg, session);
found = true; found = true;
} }
has_watchers = (has_watchers || atomic_load(&client->transmit)); has_watchers = (has_watchers || atomic_load(&client->transmit));
}); });
if (!found) { if (!found) {
US_JLOG_WARN("main", "No session %p", session); US_LOG_ERROR("No session %p", session);
} }
atomic_store(&_g_has_watchers, has_watchers); atomic_store(&_g_has_watchers, has_watchers);
_UNLOCK_ALL; _UNLOCK_ALL;
@@ -571,7 +571,7 @@ static struct janus_plugin_result *_plugin_handle_message(
} }
# define PUSH_ERROR(x_error, x_reason) { \ # define PUSH_ERROR(x_error, x_reason) { \
/*US_JLOG_ERROR("main", "Message error in session %p: %s", session, x_reason);*/ \ /*US_LOG_ERROR("Message error in session %p: %s", session, x_reason);*/ \
json_t *m_event = json_object(); \ json_t *m_event = json_object(); \
json_object_set_new(m_event, "ustreamer", json_string("event")); \ json_object_set_new(m_event, "ustreamer", json_string("event")); \
json_object_set_new(m_event, "error_code", json_integer(x_error)); \ json_object_set_new(m_event, "error_code", json_integer(x_error)); \
@@ -591,7 +591,7 @@ static struct janus_plugin_result *_plugin_handle_message(
PUSH_ERROR(400, "Request not a string"); PUSH_ERROR(400, "Request not a string");
goto done; goto done;
} }
// US_JLOG_INFO("main", "Message: %s", request_str); // US_LOG_INFO("Message: %s", request_str);
# define PUSH_STATUS(x_status, x_payload, x_jsep) { \ # define PUSH_STATUS(x_status, x_payload, x_jsep) { \
json_t *const m_event = json_object(); \ json_t *const m_event = json_object(); \
@@ -684,7 +684,7 @@ static struct janus_plugin_result *_plugin_handle_message(
json_decref(features); json_decref(features);
} else if (!strcmp(request_str, "key_required")) { } else if (!strcmp(request_str, "key_required")) {
// US_JLOG_INFO("main", "Got key_required message"); // US_LOG_INFO("Got key_required message");
atomic_store(&_g_key_required, true); atomic_store(&_g_key_required, true);
} else { } else {

View File

@@ -22,22 +22,11 @@
#include <janus/plugins/plugin.h> #include <janus/plugins/plugin.h>
#include "uslibs/tools.h" #include "threading.h"
#include "const.h"
#define US_JLOG_INFO(x_prefix, x_msg, ...) JANUS_LOG(LOG_INFO, "== %s/%-9s -- " x_msg "\n", US_PLUGIN_NAME, x_prefix, ##__VA_ARGS__) #define US_LOG_PRINTF_NOLOCK(x_label_color, x_label, x_msg_color, x_msg, ...) { \
#define US_JLOG_WARN(x_prefix, x_msg, ...) JANUS_LOG(LOG_WARN, "== %s/%-9s -- " x_msg "\n", US_PLUGIN_NAME, x_prefix, ##__VA_ARGS__) char m_tname_buf[US_THREAD_NAME_SIZE] = {0}; \
#define US_JLOG_ERROR(x_prefix, x_msg, ...) JANUS_LOG(LOG_ERR, "== %s/%-9s -- " x_msg "\n", US_PLUGIN_NAME, x_prefix, ##__VA_ARGS__) us_thread_get_name(m_tname_buf); \
JANUS_LOG(LOG_INFO, "== ustreamer/%-15s " x_label " -- " x_msg "\n", m_tname_buf, ##__VA_ARGS__); \
#define US_JLOG_PERROR(x_prefix, x_msg, ...) { \
char *const m_perror_str = us_errno_to_string(errno); \
JANUS_LOG(LOG_ERR, "[%s/%-9s] " x_msg ": %s\n", US_PLUGIN_NAME, x_prefix, ##__VA_ARGS__, m_perror_str); \
free(m_perror_str); \
} }
// We don't include alsa, speex and opus headers here
#define US_JLOG_PERROR_ALSA(_err, _prefix, _msg, ...) US_JLOG_ERROR(_prefix, _msg ": %s", ##__VA_ARGS__, snd_strerror(_err))
#define US_JLOG_PERROR_RES(_err, _prefix, _msg, ...) US_JLOG_ERROR(_prefix, _msg ": %s", ##__VA_ARGS__, speex_resampler_strerror(_err))
#define US_JLOG_PERROR_OPUS(_err, _prefix, _msg, ...) US_JLOG_ERROR(_prefix, _msg ": %s", ##__VA_ARGS__, opus_strerror(_err))

View File

@@ -95,6 +95,11 @@ extern pthread_mutex_t us_g_log_mutex;
free(m_perror_str); \ free(m_perror_str); \
} }
// We don't include alsa, speex and opus headers here
#define US_LOG_PERROR_ALSA(x_err, x_msg, ...) US_LOG_ERROR(x_msg ": %s", ##__VA_ARGS__, snd_strerror(x_err))
#define US_LOG_PERROR_RES(x_err, x_msg, ...) US_LOG_ERROR(x_msg ": %s", ##__VA_ARGS__, speex_resampler_strerror(x_err))
#define US_LOG_PERROR_OPUS(x_err, x_msg, ...) US_LOG_ERROR(x_msg ": %s", ##__VA_ARGS__, opus_strerror(x_err))
#define US_LOG_INFO(x_msg, ...) { \ #define US_LOG_INFO(x_msg, ...) { \
US_LOG_PRINTF(US_COLOR_GREEN, "INFO ", "", x_msg, ##__VA_ARGS__); \ US_LOG_PRINTF(US_COLOR_GREEN, "INFO ", "", x_msg, ##__VA_ARGS__); \
} }