From 8a4304de570af51c78efadf7341979365fd3c612 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Sun, 17 Mar 2024 00:34:06 +0200 Subject: [PATCH] janus: rtp orientation support --- janus/src/client.c | 9 +++++++++ janus/src/client.h | 1 + janus/src/plugin.c | 20 +++++++++++++++++--- janus/src/rtpv.c | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/janus/src/client.c b/janus/src/client.c index f30591071..a1fde4f30 100644 --- a/janus/src/client.c +++ b/janus/src/client.c @@ -51,6 +51,7 @@ us_janus_client_s *us_janus_client_init(janus_callbacks *gw, janus_plugin_sessio client->session = session; atomic_init(&client->transmit, false); atomic_init(&client->transmit_audio, false); + atomic_init(&client->video_orient, 0); atomic_init(&client->stop, false); @@ -131,6 +132,7 @@ static void *_common_thread(void *v_client, bool video) { # endif }; janus_plugin_rtp_extensions_reset(&packet.extensions); + /*if (rtp->zero_playout_delay) { // https://github.com/pikvm/pikvm/issues/784 packet.extensions.min_delay = 0; @@ -142,6 +144,13 @@ static void *_common_thread(void *v_client, bool video) { packet.extensions.max_delay = 300; // == 3s, i.e. 10ms granularity }*/ + if (rtp.video) { + const uint video_orient = atomic_load(&client->video_orient); + if (video_orient != 0) { + packet.extensions.video_rotation = video_orient; + } + } + client->gw->relay_rtp(client->session, &packet); } } diff --git a/janus/src/client.h b/janus/src/client.h index 25374c02b..ea76493be 100644 --- a/janus/src/client.h +++ b/janus/src/client.h @@ -39,6 +39,7 @@ typedef struct us_janus_client_sx { janus_plugin_session *session; atomic_bool transmit; atomic_bool transmit_audio; + atomic_uint video_orient; pthread_t video_tid; pthread_t audio_tid; diff --git a/janus/src/plugin.c b/janus/src/plugin.c index cec6db302..b5bfb4044 100644 --- a/janus/src/plugin.c +++ b/janus/src/plugin.c @@ -453,12 +453,25 @@ static struct janus_plugin_result *_plugin_handle_message( } else if (!strcmp(request_str, "watch")) { bool with_audio = false; + uint video_orient = 0; { json_t *const params = json_object_get(msg, "params"); if (params != NULL) { - json_t *const audio = json_object_get(params, "audio"); - if (audio != NULL && json_is_boolean(audio)) { - with_audio = (_g_rtpa != NULL && json_boolean_value(audio)); + { + json_t *const obj = json_object_get(params, "audio"); + if (obj != NULL && json_is_boolean(obj)) { + with_audio = (_g_rtpa != NULL && json_boolean_value(obj)); + } + } + { + json_t *const obj = json_object_get(params, "video_orientation"); + if (obj != NULL && json_is_integer(obj)) { + video_orient = json_integer_value(obj); + switch (video_orient) { + case 90: case 180: case 270: break; + default: video_orient = 0; break; + } + } } } } @@ -498,6 +511,7 @@ static struct janus_plugin_result *_plugin_handle_message( US_LIST_ITERATE(_g_clients, client, { if (client->session == session) { atomic_store(&client->transmit_audio, with_audio); + atomic_store(&client->video_orient, video_orient); } has_listeners = (has_listeners || atomic_load(&client->transmit_audio)); }); diff --git a/janus/src/rtpv.c b/janus/src/rtpv.c index 00d13b708..cbdc809ec 100644 --- a/janus/src/rtpv.c +++ b/janus/src/rtpv.c @@ -71,6 +71,7 @@ char *us_rtpv_make_sdp(us_rtpv_s *rtpv) { "a=rtcp-fb:%u goog-remb" RN "a=ssrc:%" PRIu32 " cname:ustreamer" RN "a=extmap:1 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" RN + "a=extmap:2 urn:3gpp:video-orientation" RN "a=sendonly" RN, pl, pl, pl, pl, pl, pl, pl,