From 52dfa38a8f4c1428d1556b54f4d3faa49d63e583 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sun, 31 May 2026 18:28:53 +0300 Subject: [PATCH] janus: camera basics --- janus/src/config.c | 2 ++ janus/src/config.h | 1 + janus/src/plugin.c | 37 ++++++++++++++----------------------- janus/src/sdp.c | 7 ++++--- janus/src/sdp.h | 2 +- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/janus/src/config.c b/janus/src/config.c index 375e962..d4358e2 100644 --- a/janus/src/config.c +++ b/janus/src/config.c @@ -70,6 +70,7 @@ us_config_s *us_config_init(const char *config_dir_path) { } } config->aplay_dev_name = _get_value(jcfg, "aplay", "device"); + config->vplay_sink_name = _get_value(jcfg, "vplay", "sink"); goto ok; @@ -87,6 +88,7 @@ void us_config_destroy(us_config_s *config) { US_DELETE(config->acap_dev_name, free); US_DELETE(config->tc358743_dev_path, free); US_DELETE(config->aplay_dev_name, free); + US_DELETE(config->vplay_sink_name, free); free(config); } diff --git a/janus/src/config.h b/janus/src/config.h index d193a60..d568fc1 100644 --- a/janus/src/config.h +++ b/janus/src/config.h @@ -34,6 +34,7 @@ typedef struct { char *tc358743_dev_path; char *aplay_dev_name; + char *vplay_sink_name; } us_config_s; diff --git a/janus/src/plugin.c b/janus/src/plugin.c index d48a2f5..03bbd68 100644 --- a/janus/src/plugin.c +++ b/janus/src/plugin.c @@ -612,21 +612,20 @@ static struct janus_plugin_result *_plugin_handle_message( uint video_orient = 0; bool with_acap = false; bool with_aplay = false; + bool with_vplay = false; { json_t *const params = json_object_get(msg, "params"); if (params != NULL) { - { - json_t *const obj = json_object_get(params, "audio"); - if (obj != NULL && json_is_boolean(obj)) { - with_acap = (us_au_probe(_g_config->acap_dev_name) && json_boolean_value(obj)); +# define READ_BOOL(x_target, x_key, x_cond) { \ + json_t *const m_obj = json_object_get(params, x_key); \ + if (m_obj != NULL && json_is_boolean(m_obj)) { \ + x_target = (json_boolean_value(m_obj) && (x_cond)); \ + } \ } - } - { - json_t *const obj = json_object_get(params, "mic"); - if (obj != NULL && json_is_boolean(obj)) { - with_aplay = (us_au_probe(_g_config->aplay_dev_name) && json_boolean_value(obj)); - } - } + READ_BOOL(with_acap, "audio", us_au_probe(_g_config->acap_dev_name)); + READ_BOOL(with_aplay, "mic", us_au_probe(_g_config->aplay_dev_name)); + READ_BOOL(with_vplay, "camera", (_g_config->vplay_sink_name != NULL)); +# undef READ_BOOL { json_t *const obj = json_object_get(params, "orientation"); if (obj != NULL && json_is_integer(obj)) { @@ -642,29 +641,21 @@ static struct janus_plugin_result *_plugin_handle_message( { _LOCK_ALL; + bool has_listeners = false; + bool has_speakers = false; US_LIST_ITERATE(_g_clients, client, { if (client->session == session) { char *const sdp = us_sdp_create( client->video_ssrc, client->audio_ssrc, with_acap, - with_aplay); + with_aplay, + with_vplay); json_t *const offer_jsep = json_pack("{ssss}", "type", "offer", "sdp", sdp); PUSH_STATUS("started", NULL, offer_jsep); json_decref(offer_jsep); free(sdp); - break; - } - }); - _UNLOCK_ALL; - } - { - _LOCK_ALL; - bool has_listeners = false; - bool has_speakers = false; - US_LIST_ITERATE(_g_clients, client, { - if (client->session == session) { atomic_store(&client->transmit_acap, with_acap); atomic_store(&client->transmit_aplay, with_aplay); atomic_store(&client->video_orient, video_orient); diff --git a/janus/src/sdp.c b/janus/src/sdp.c index 03a36b7..47f3f56 100644 --- a/janus/src/sdp.c +++ b/janus/src/sdp.c @@ -34,7 +34,7 @@ #include "rtpa.h" -char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay) { +char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay, bool vplay) { char *video_sdp; { // https://tools.ietf.org/html/rfc6184 @@ -56,9 +56,10 @@ char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay) { "a=extmap:1/sendonly urn:3gpp:video-orientation" RN "a=extmap:2/sendonly http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" RN "a=extmap:3/sendonly http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time" RN - "a=sendonly" RN, + "a=%s" RN, pl, pl, pl, pl, pl, pl, pl, - video_ssrc); + video_ssrc, + (vplay ? "sendrecv" : "sendonly")); } char *audio_sdp; diff --git a/janus/src/sdp.h b/janus/src/sdp.h index 6f475f7..32dd477 100644 --- a/janus/src/sdp.h +++ b/janus/src/sdp.h @@ -25,4 +25,4 @@ #include "uslibs/types.h" -char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay); +char *us_sdp_create(u32 video_ssrc, u32 audio_ssrc, bool acap, bool aplay, bool vplay);