janus: rtp orientation support

This commit is contained in:
Maxim Devaev
2024-03-17 00:34:06 +02:00
parent 69e7cbf746
commit 2f1264c916
4 changed files with 28 additions and 3 deletions

View File

@@ -51,6 +51,7 @@ us_janus_client_s *us_janus_client_init(janus_callbacks *gw, janus_plugin_sessio
client->session = session; client->session = session;
atomic_init(&client->transmit, false); atomic_init(&client->transmit, false);
atomic_init(&client->transmit_audio, false); atomic_init(&client->transmit_audio, false);
atomic_init(&client->video_orient, 0);
atomic_init(&client->stop, false); atomic_init(&client->stop, false);
@@ -131,6 +132,7 @@ static void *_common_thread(void *v_client, bool video) {
# endif # endif
}; };
janus_plugin_rtp_extensions_reset(&packet.extensions); janus_plugin_rtp_extensions_reset(&packet.extensions);
/*if (rtp->zero_playout_delay) { /*if (rtp->zero_playout_delay) {
// https://github.com/pikvm/pikvm/issues/784 // https://github.com/pikvm/pikvm/issues/784
packet.extensions.min_delay = 0; 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 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); client->gw->relay_rtp(client->session, &packet);
} }
} }

View File

@@ -39,6 +39,7 @@ typedef struct us_janus_client_sx {
janus_plugin_session *session; janus_plugin_session *session;
atomic_bool transmit; atomic_bool transmit;
atomic_bool transmit_audio; atomic_bool transmit_audio;
atomic_uint video_orient;
pthread_t video_tid; pthread_t video_tid;
pthread_t audio_tid; pthread_t audio_tid;

View File

@@ -453,12 +453,25 @@ static struct janus_plugin_result *_plugin_handle_message(
} else if (!strcmp(request_str, "watch")) { } else if (!strcmp(request_str, "watch")) {
bool with_audio = false; bool with_audio = false;
uint video_orient = 0;
{ {
json_t *const params = json_object_get(msg, "params"); json_t *const params = json_object_get(msg, "params");
if (params != NULL) { if (params != NULL) {
json_t *const audio = json_object_get(params, "audio"); {
if (audio != NULL && json_is_boolean(audio)) { json_t *const obj = json_object_get(params, "audio");
with_audio = (_g_rtpa != NULL && json_boolean_value(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, "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, { US_LIST_ITERATE(_g_clients, client, {
if (client->session == session) { if (client->session == session) {
atomic_store(&client->transmit_audio, with_audio); atomic_store(&client->transmit_audio, with_audio);
atomic_store(&client->video_orient, video_orient);
} }
has_listeners = (has_listeners || atomic_load(&client->transmit_audio)); has_listeners = (has_listeners || atomic_load(&client->transmit_audio));
}); });

View File

@@ -71,6 +71,7 @@ char *us_rtpv_make_sdp(us_rtpv_s *rtpv) {
"a=rtcp-fb:%u goog-remb" RN "a=rtcp-fb:%u goog-remb" RN
"a=ssrc:%" PRIu32 " cname:ustreamer" RN "a=ssrc:%" PRIu32 " cname:ustreamer" RN
"a=extmap:1 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay" 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, "a=sendonly" RN,
pl, pl, pl, pl, pl, pl, pl, pl,
pl, pl, pl, pl, pl, pl,