Skip to content

Commit 39f726f

Browse files
authored
Add metadata for videoroom publishers (#3467)
1 parent 230f6e7 commit 39f726f

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

src/plugins/janus_videoroom.c

+78-5
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ room-<unique room ID>: {
459459
{ // Participant #1
460460
"id" : <unique numeric ID of the participant>,
461461
"display" : "<display name of the participant, if any; optional>",
462+
"metadata" : <valid json object of metadata, if any; optional>,
462463
"publisher" : "<true|false, whether user is an active publisher in the room>",
463464
"talking" : <true|false, whether user is talking or not (only if audio levels are used)>
464465
},
@@ -494,7 +495,8 @@ room-<unique room ID>: {
494495
"room" : <unique ID of the room to join>,
495496
"id" : <unique ID to register for the publisher; optional, will be chosen by the plugin if missing>,
496497
"display" : "<display name for the publisher; optional>",
497-
"token" : "<invitation token, in case the room has an ACL; optional>"
498+
"token" : "<invitation token, in case the room has an ACL; optional>",
499+
"metadata" : <valid json object with metadata; optional>
498500
}
499501
\endverbatim
500502
*
@@ -523,6 +525,7 @@ room-<unique room ID>: {
523525
{
524526
"id" : <unique ID of active publisher #1>,
525527
"display" : "<display name of active publisher #1, if any>",
528+
"metadata" : <valid json object of metadata, if any>,
526529
"dummy" : <true if this participant is a dummy publisher>,
527530
"streams" : [
528531
{
@@ -546,7 +549,8 @@ room-<unique room ID>: {
546549
"attendees" : [ // Only present when notify_joining is set to TRUE for rooms
547550
{
548551
"id" : <unique ID of attendee #1>,
549-
"display" : "<display name of attendee #1, if any>"
552+
"display" : "<display name of attendee #1, if any>",
553+
"metadata" : <valid json object of metadata, if any>
550554
},
551555
// Other attendees
552556
]
@@ -576,7 +580,8 @@ room-<unique room ID>: {
576580
"room" : <room ID>,
577581
"joining" : {
578582
"id" : <unique ID of the new participant>,
579-
"display" : "<display name of the new participant, if any>"
583+
"display" : "<display name of the new participant, if any>",
584+
"metadata" : <valid json object of metadata, if any>
580585
}
581586
}
582587
\endverbatim
@@ -601,6 +606,7 @@ room-<unique room ID>: {
601606
"record" : <true|false, whether this publisher should be recorded or not; optional>,
602607
"filename" : "<if recording, the base path/file to use for the recording files; optional>",
603608
"display" : "<display name to use in the room; optional>",
609+
"metadata" : <valid json object of metadata; optional>,
604610
"audio_level_average" : "<if provided, overrides the room audio_level_average for this user; optional>",
605611
"audio_active_packets" : "<if provided, overrides the room audio_active_packets for this user; optional>",
606612
"descriptions" : [ // Optional
@@ -668,6 +674,7 @@ room-<unique room ID>: {
668674
{
669675
"id" : <unique ID of the new publisher>,
670676
"display" : "<display name of the new publisher, if any>",
677+
"metadata" : <valid json object of metadata, if any>,
671678
"dummy" : <true if this participant is a dummy publisher>,
672679
"streams" : [
673680
{
@@ -740,6 +747,7 @@ room-<unique room ID>: {
740747
"record" : <true|false, whether this publisher should be recorded or not; optional>,
741748
"filename" : "<if recording, the base path/file to use for the recording files; optional>",
742749
"display" : "<new display name to use in the room; optional>",
750+
"metadata" : <new metadata json object; optional>,
743751
"audio_active_packets" : "<new audio_active_packets to overwrite in the room one; optional>",
744752
"audio_level_average" : "<new audio_level_average to overwrite the room one; optional>",
745753
"streams" : [
@@ -1648,6 +1656,7 @@ room-<unique room ID>: {
16481656
"id" : <unique ID of the remote publisher>,
16491657
"secret" : "<password required to edit the room, mandatory if configured in the room>",
16501658
"display" : "<new display name for the remote publisher; optional>",
1659+
"metadata" : <new valid json object of metadata; optional>,
16511660
"streams" : [
16521661
{
16531662
// Same syntax as add_remote_publisher: only needs to
@@ -2014,6 +2023,7 @@ static struct janus_json_parameter publish_parameters[] = {
20142023
{"record", JANUS_JSON_BOOL, 0},
20152024
{"filename", JSON_STRING, 0},
20162025
{"display", JSON_STRING, 0},
2026+
{"metadata", JSON_OBJECT, 0},
20172027
{"secret", JSON_STRING, 0},
20182028
{"audio_level_averge", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
20192029
{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
@@ -2088,7 +2098,8 @@ static struct janus_json_parameter stop_rtp_forward_parameters[] = {
20882098
{"stream_id", JSON_INTEGER, JANUS_JSON_PARAM_REQUIRED | JANUS_JSON_PARAM_POSITIVE}
20892099
};
20902100
static struct janus_json_parameter publisher_parameters[] = {
2091-
{"display", JSON_STRING, 0}
2101+
{"display", JSON_STRING, 0},
2102+
{"metadata", JSON_OBJECT, 0}
20922103
};
20932104
static struct janus_json_parameter configure_stream_parameters[] = {
20942105
{"mid", JANUS_JSON_STRING, 0},
@@ -2196,10 +2207,12 @@ static struct janus_json_parameter remote_publisher_parameters[] = {
21962207
{"iface", JANUS_JSON_STRING, 0},
21972208
{"port", JANUS_JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
21982209
{"streams", JANUS_JSON_ARRAY, JANUS_JSON_PARAM_REQUIRED},
2210+
{"metadata", JSON_OBJECT, 0}
21992211
};
22002212
static struct janus_json_parameter remote_publisher_update_parameters[] = {
22012213
{"secret", JSON_STRING, 0},
22022214
{"display", JANUS_JSON_STRING, 0},
2215+
{"metadata", JSON_OBJECT, 0},
22032216
{"streams", JANUS_JSON_ARRAY, JANUS_JSON_PARAM_REQUIRED}
22042217
};
22052218
static struct janus_json_parameter remote_publisher_stream_parameters[] = {
@@ -2432,6 +2445,7 @@ typedef struct janus_videoroom_publisher {
24322445
gboolean kicked; /* Whether this participant has been kicked */
24332446
gboolean e2ee; /* If media from this publisher is end-to-end encrypted */
24342447
janus_mutex mutex; /* Mutex to lock this instance */
2448+
json_t *metadata;
24352449
volatile gint destroyed;
24362450
janus_refcount ref;
24372451
} janus_videoroom_publisher;
@@ -2760,6 +2774,8 @@ static void janus_videoroom_publisher_free(const janus_refcount *p_ref) {
27602774
g_free(p->user_id_str);
27612775
g_free(p->display);
27622776
g_free(p->recording_base);
2777+
if(p->metadata != NULL)
2778+
json_decref(p->metadata);
27632779
/* Get rid of all the streams */
27642780
g_list_free_full(p->streams, (GDestroyNotify)(janus_videoroom_publisher_stream_destroy));
27652781
g_hash_table_unref(p->streams_byid);
@@ -4260,6 +4276,8 @@ static void janus_videoroom_notify_about_publisher(janus_videoroom_publisher *p,
42604276
json_object_set_new(pl, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
42614277
if(p->display)
42624278
json_object_set_new(pl, "display", json_string(p->display));
4279+
if(p->metadata)
4280+
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
42634281
/* Add proper info on all the streams */
42644282
gboolean audio_added = FALSE, video_added = FALSE;
42654283
json_t *media = json_array();
@@ -4333,6 +4351,8 @@ static void janus_videoroom_notify_about_publisher(janus_videoroom_publisher *p,
43334351
json_object_set_new(info, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
43344352
if(p->display)
43354353
json_object_set_new(info, "display", json_string(p->display));
4354+
if(p->metadata)
4355+
json_object_set_new(info, "metadata", json_deep_copy(p->metadata));
43364356
json_t *media = json_array();
43374357
GList *temp = p->streams;
43384358
while(temp) {
@@ -4377,6 +4397,9 @@ static void janus_videoroom_participant_joining(janus_videoroom_publisher *p) {
43774397
if (p->display) {
43784398
json_object_set_new(user, "display", json_string(p->display));
43794399
}
4400+
if (p->metadata) {
4401+
json_object_set_new(user, "metadata", json_deep_copy(p->metadata));
4402+
}
43804403
json_object_set_new(event, "videoroom", json_string("event"));
43814404
json_object_set_new(event, "room", string_ids ? json_string(p->room_id_str) : json_integer(p->room_id));
43824405
json_object_set_new(event, "joining", user);
@@ -4414,6 +4437,8 @@ static void janus_videoroom_leave_or_unpublish(janus_videoroom_publisher *partic
44144437
json_object_set_new(event, "room", string_ids ? json_string(participant->room_id_str) : json_integer(participant->room_id));
44154438
if(participant->display)
44164439
json_object_set_new(event, "display", json_string(participant->display));
4440+
if(participant->metadata)
4441+
json_object_set_new(event, "metadata", json_deep_copy(participant->metadata));
44174442
json_object_set_new(event, is_leaving ? (kicked ? "kicked" : "leaving") : "unpublished",
44184443
string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id));
44194444
janus_videoroom_notify_participants(participant, event, FALSE);
@@ -4425,6 +4450,8 @@ static void janus_videoroom_leave_or_unpublish(janus_videoroom_publisher *partic
44254450
json_object_set_new(info, "id", string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id));
44264451
if(participant->display)
44274452
json_object_set_new(info, "display", json_string(participant->display));
4453+
if(participant->metadata)
4454+
json_object_set_new(info, "metadata", json_deep_copy(participant->metadata));
44284455
gateway->notify_event(&janus_videoroom_plugin, NULL, info);
44294456
}
44304457
if(is_leaving) {
@@ -4536,6 +4563,8 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
45364563
json_object_set_new(info, "private_id", json_integer(participant->pvt_id));
45374564
if(participant->display)
45384565
json_object_set_new(info, "display", json_string(participant->display));
4566+
if(participant->metadata)
4567+
json_object_set_new(info, "metadata", json_deep_copy(participant->metadata));
45394568
/* TODO Fix the summary of viewers, since everything is stream based now */
45404569
//~ if(participant->subscribers)
45414570
//~ json_object_set_new(info, "viewers", json_integer(g_slist_length(participant->subscribers)));
@@ -6850,6 +6879,8 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
68506879
json_object_set_new(pl, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
68516880
if(p->display)
68526881
json_object_set_new(pl, "display", json_string(p->display));
6882+
if(p->metadata)
6883+
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
68536884
if(p->dummy)
68546885
json_object_set_new(pl, "dummy", json_true());
68556886
if(p->remote)
@@ -6933,6 +6964,8 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
69336964
json_object_set_new(pl, "publisher_id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
69346965
if(p->display)
69356966
json_object_set_new(pl, "display", json_string(p->display));
6967+
if(p->metadata)
6968+
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
69366969
json_t *flist = json_array();
69376970
/* Iterate on all media streams to see what's being forwarded */
69386971
janus_videoroom_publisher_stream *ps = NULL;
@@ -7579,6 +7612,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
75797612
char user_id_num[30], *user_id_str = NULL;
75807613
gboolean user_id_allocated = FALSE;
75817614
json_t *id = json_object_get(root, "id");
7615+
json_t *metadata = json_object_get(root, "metadata");
75827616
if(id) {
75837617
if(!string_ids) {
75847618
user_id = json_integer_value(id);
@@ -7709,6 +7743,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
77097743
publisher->remote_ssrc_offset = janus_random_uint32();
77107744
publisher->remote_fd = fd;
77117745
publisher->remote_rtcp_fd = rtcp_fd;
7746+
publisher->metadata = metadata ? json_deep_copy(metadata) : NULL;
77127747
pipe(publisher->pipefd);
77137748
janus_mutex_init(&publisher->subscribers_mutex);
77147749
janus_mutex_init(&publisher->own_subscriptions_mutex);
@@ -7973,14 +8008,22 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
79738008
goto prepare_response;
79748009
}
79758010
janus_refcount_increase(&publisher->ref);
7976-
/* Check if there's a new display, new streams, or changes to existing ones */
8011+
/* Check if there's a new display, new metadata, new streams, or changes to existing ones */
79778012
json_t *display = json_object_get(root, "display");
79788013
if(display) {
79798014
char *old_display = publisher->display;
79808015
char *new_display = g_strdup(json_string_value(display));
79818016
publisher->display = new_display;
79828017
g_free(old_display);
79838018
}
8019+
json_t *metadata = json_object_get(root, "metadata");
8020+
if(metadata) {
8021+
json_t *old_metadata = publisher->metadata;
8022+
json_t *new_metadata = json_deep_copy(metadata);
8023+
publisher->metadata = new_metadata;
8024+
if(old_metadata)
8025+
json_decref(old_metadata);
8026+
}
79848027
janus_mutex_lock(&publisher->streams_mutex);
79858028
janus_videoroom_publisher_stream *ps = NULL;
79868029
int changes = FALSE;
@@ -9447,6 +9490,7 @@ static void *janus_videoroom_handler(void *data) {
94479490
}
94489491
}
94499492
json_t *display = json_object_get(root, "display");
9493+
json_t *metadata= json_object_get(root, "metadata");
94509494
const char *display_text = display ? json_string_value(display) : NULL;
94519495
guint64 user_id = 0;
94529496
char user_id_num[30], *user_id_str = NULL;
@@ -9524,6 +9568,7 @@ static void *janus_videoroom_handler(void *data) {
95249568
publisher->user_id = user_id;
95259569
publisher->user_id_str = user_id_str ? g_strdup(user_id_str) : NULL;
95269570
publisher->display = display_text ? g_strdup(display_text) : NULL;
9571+
publisher->metadata = NULL;
95279572
publisher->recording_active = FALSE;
95289573
publisher->recording_base = NULL;
95299574
publisher->firefox = FALSE;
@@ -9629,6 +9674,11 @@ static void *janus_videoroom_handler(void *data) {
96299674
JANUS_LOG(LOG_VERB, "Setting user audio_level_average: %d (room %s, user %s)\n",
96309675
publisher->user_audio_level_average, publisher->room_id_str, publisher->user_id_str);
96319676
}
9677+
if(metadata) {
9678+
publisher->metadata = json_deep_copy(metadata);
9679+
JANUS_LOG(LOG_VERB, "Setting metadata: (room %s, user %s)\n",
9680+
publisher->room_id_str, publisher->user_id_str);
9681+
}
96329682
/* Done */
96339683
janus_mutex_lock(&session->mutex);
96349684
/* Make sure the session has not been destroyed in the meanwhile */
@@ -9676,6 +9726,8 @@ static void *janus_videoroom_handler(void *data) {
96769726
json_object_set_new(pl, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
96779727
if(p->display)
96789728
json_object_set_new(pl, "display", json_string(p->display));
9729+
if(p->metadata)
9730+
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
96799731
if(p->dummy)
96809732
json_object_set_new(pl, "dummy", json_true());
96819733
/* Add proper info on all the streams */
@@ -10527,6 +10579,7 @@ static void *janus_videoroom_handler(void *data) {
1052710579
json_t *record = json_object_get(root, "record");
1052810580
json_t *recfile = json_object_get(root, "filename");
1052910581
json_t *display = json_object_get(root, "display");
10582+
json_t *metadata = json_object_get(root, "metadata");
1053010583
json_t *update = json_object_get(root, "update");
1053110584
json_t *user_audio_active_packets = json_object_get(root, "audio_active_packets");
1053210585
json_t *user_audio_level_average = json_object_get(root, "audio_level_average");
@@ -10822,6 +10875,26 @@ static void *janus_videoroom_handler(void *data) {
1082210875
g_free(old_display);
1082310876
janus_mutex_unlock(&participant->room->mutex);
1082410877
}
10878+
if(metadata) {
10879+
janus_mutex_lock(&participant->room->mutex);
10880+
json_t *old_metadata = participant->metadata;
10881+
json_t *new_metadata = json_deep_copy(metadata);
10882+
participant->metadata = new_metadata;
10883+
if(old_metadata != NULL) {
10884+
/* The metadata changed, notify this */
10885+
json_t *metadata_event = json_object();
10886+
json_object_set_new(metadata_event, "videoroom", json_string("event"));
10887+
json_object_set_new(metadata_event, "id", string_ids ?
10888+
json_string(participant->user_id_str) : json_integer(participant->user_id));
10889+
json_object_set_new(metadata_event, "metadata", json_deep_copy(participant->metadata));
10890+
if(participant->room && !g_atomic_int_get(&participant->room->destroyed)) {
10891+
janus_videoroom_notify_participants(participant, metadata_event, FALSE);
10892+
}
10893+
json_decref(metadata_event);
10894+
json_decref(old_metadata);
10895+
}
10896+
janus_mutex_unlock(&participant->room->mutex);
10897+
}
1082510898
/* Are we updating the description? */
1082610899
if(descriptions != NULL && json_array_size(descriptions) > 0 && json_string_value(json_object_get(msg->jsep, "sdp")) == NULL) {
1082710900
/* We only do this here if this is an SDP-less configure: in case

0 commit comments

Comments
 (0)