Skip to content

Commit

Permalink
janus: rtp orientation support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 17, 2024
1 parent 69e7cbf commit 2f1264c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
9 changes: 9 additions & 0 deletions janus/src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions janus/src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions janus/src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "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;
}
}
}
}
}
Expand Down Expand Up @@ -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));
});
Expand Down
1 change: 1 addition & 0 deletions janus/src/rtpv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2f1264c

Please sign in to comment.