From 3750a2209169727ae44a16a4a4d040900d07e027 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sun, 31 May 2026 05:33:42 +0300 Subject: [PATCH] janus: separate audio of mic --- janus/src/config.c | 2 +- janus/src/plugin.c | 13 ++++++------- janus/src/sdp.c | 25 ++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/janus/src/config.c b/janus/src/config.c index af36d8f..375e962 100644 --- a/janus/src/config.c +++ b/janus/src/config.c @@ -68,8 +68,8 @@ us_config_s *us_config_init(const char *config_dir_path) { US_JLOG_ERROR("config", "Either acap.sampling_rate or acap.tc358743 required"); goto error; } - config->aplay_dev_name = _get_value(jcfg, "aplay", "device"); } + config->aplay_dev_name = _get_value(jcfg, "aplay", "device"); goto ok; diff --git a/janus/src/plugin.c b/janus/src/plugin.c index 5d8782f..a0d0754 100644 --- a/janus/src/plugin.c +++ b/janus/src/plugin.c @@ -443,9 +443,9 @@ static int _plugin_init(janus_callbacks *gw, const char *config_dir_path) { if (_g_config->acap_dev_name != NULL) { _g_rtpa = us_rtpa_init(_relay_rtp_clients); US_THREAD_CREATE(_g_acap_tid, _acap_thread, NULL); - if (_g_config->aplay_dev_name != NULL) { - US_THREAD_CREATE(_g_aplay_tid, _aplay_thread, NULL); - } + } + if (_g_config->aplay_dev_name != NULL) { + US_THREAD_CREATE(_g_aplay_tid, _aplay_thread, NULL); } US_THREAD_CREATE(_g_video_rtp_tid, _video_rtp_thread, NULL); US_THREAD_CREATE(_g_video_sink_tid, _video_sink_thread, NULL); @@ -644,7 +644,7 @@ static struct janus_plugin_result *_plugin_handle_message( char *const sdp = us_sdp_create( _g_rtpv, (with_acap ? _g_rtpa : NULL), - (with_acap && with_aplay)); + with_aplay); json_t *const offer_jsep = json_pack("{ssss}", "type", "offer", "sdp", sdp); PUSH_STATUS("started", NULL, offer_jsep); json_decref(offer_jsep); @@ -671,11 +671,10 @@ static struct janus_plugin_result *_plugin_handle_message( } else if (!strcmp(request_str, "features")) { const char *const ice_url = getenv("JANUS_USTREAMER_WEB_ICE_URL"); - const bool acap_avail = us_au_probe(_g_config->acap_dev_name); json_t *const features = json_pack( "{s:b, s:b, s:{s:s?}}", - "audio", acap_avail, - "mic", (acap_avail && us_au_probe(_g_config->aplay_dev_name)), + "audio", us_au_probe(_g_config->acap_dev_name), + "mic", us_au_probe(_g_config->aplay_dev_name), "ice", "url", (ice_url != NULL ? ice_url : default_ice_url) ); PUSH_STATUS("features", features, NULL); diff --git a/janus/src/sdp.c b/janus/src/sdp.c index 710471f..4cf69ba 100644 --- a/janus/src/sdp.c +++ b/janus/src/sdp.c @@ -65,7 +65,26 @@ char *us_sdp_create(us_rtpv_s *rtpv, us_rtpa_s *rtpa, bool mic) { if (rtpa == NULL) { audio_sdp = us_strdup(""); } else { - const uint pl = rtpa->rtp->payload; + + + if (rtpa != NULL || mic) { + uint pl; + u32 ssrc; + if (rtpa != NULL) { + pl = rtpa->rtp->payload; + ssrc = rtpa->rtp->ssrc; + } else { + pl = US_RTP_OPUS_PAYLOAD; + ssrc = us_triple_u32(us_get_now_monotonic_u64()); + } + + char *dir = "sendrecv"; + if (rtpa == NULL) { + dir = "recvonly"; + } else if (!mic) { + dir = "sendonly"; + } + US_ASPRINTF( audio_sdp, "m=audio 1 RTP/SAVPF %u" RN @@ -79,8 +98,8 @@ char *us_sdp_create(us_rtpv_s *rtpv, us_rtpa_s *rtpa, bool mic) { pl, pl, US_RTP_OPUS_HZ, US_RTP_OPUS_CH, pl, - rtpa->rtp->ssrc, - (mic ? "sendrecv" : "sendonly")); + ssrc, + dir); } char *sdp;