Skip to content

Commit

Permalink
Add metadata for videoroom publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Malaev committed Nov 4, 2024
1 parent cb10621 commit 35f15cf
Showing 1 changed file with 78 additions and 6 deletions.
84 changes: 78 additions & 6 deletions src/plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,10 @@ room-<unique room ID>: {
{ // Participant #1
"id" : <unique numeric ID of the participant>,
"display" : "<display name of the participant, if any; optional>",
"metadata" : <valid json object of metadata, if any; optional>,
"publisher" : "<true|false, whether user is an active publisher in the room>",
"talking" : <true|false, whether user is talking or not (only if audio levels are used)>
"metadata" : <valid json object with metadata>
},
// Other participants
]
Expand Down Expand Up @@ -494,7 +496,8 @@ room-<unique room ID>: {
"room" : <unique ID of the room to join>,
"id" : <unique ID to register for the publisher; optional, will be chosen by the plugin if missing>,
"display" : "<display name for the publisher; optional>",
"token" : "<invitation token, in case the room has an ACL; optional>"
"token" : "<invitation token, in case the room has an ACL; optional>",
"metadata" : <valid json object with metadata; optional>
}
\endverbatim
*
Expand Down Expand Up @@ -523,6 +526,7 @@ room-<unique room ID>: {
{
"id" : <unique ID of active publisher #1>,
"display" : "<display name of active publisher #1, if any>",
"metadata" : <valid json object of metadata, if any>,
"dummy" : <true if this participant is a dummy publisher>,
"streams" : [
{
Expand All @@ -546,7 +550,8 @@ room-<unique room ID>: {
"attendees" : [ // Only present when notify_joining is set to TRUE for rooms
{
"id" : <unique ID of attendee #1>,
"display" : "<display name of attendee #1, if any>"
"display" : "<display name of attendee #1, if any>",
"metadata" : <valid json object of metadata, if any>,
},
// Other attendees
]
Expand Down Expand Up @@ -576,7 +581,8 @@ room-<unique room ID>: {
"room" : <room ID>,
"joining" : {
"id" : <unique ID of the new participant>,
"display" : "<display name of the new participant, if any>"
"display" : "<display name of the new participant, if any>",
"metadata" : <valid json object of metadata, if any>
}
}
\endverbatim
Expand All @@ -601,6 +607,7 @@ room-<unique room ID>: {
"record" : <true|false, whether this publisher should be recorded or not; optional>,
"filename" : "<if recording, the base path/file to use for the recording files; optional>",
"display" : "<display name to use in the room; optional>",
"metadata" : <valid json object of metadata; optional>,
"audio_level_average" : "<if provided, overrides the room audio_level_average for this user; optional>",
"audio_active_packets" : "<if provided, overrides the room audio_active_packets for this user; optional>",
"descriptions" : [ // Optional
Expand Down Expand Up @@ -668,6 +675,7 @@ room-<unique room ID>: {
{
"id" : <unique ID of the new publisher>,
"display" : "<display name of the new publisher, if any>",
"metadata" : <valid json object of metadata, if any>,
"dummy" : <true if this participant is a dummy publisher>,
"streams" : [
{
Expand Down Expand Up @@ -740,6 +748,7 @@ room-<unique room ID>: {
"record" : <true|false, whether this publisher should be recorded or not; optional>,
"filename" : "<if recording, the base path/file to use for the recording files; optional>",
"display" : "<new display name to use in the room; optional>",
"metadata" : <new metadata json object; optional>,
"audio_active_packets" : "<new audio_active_packets to overwrite in the room one; optional>",
"audio_level_average" : "<new audio_level_average to overwrite the room one; optional>",
"streams" : [
Expand Down Expand Up @@ -1648,6 +1657,7 @@ room-<unique room ID>: {
"id" : <unique ID of the remote publisher>,
"secret" : "<password required to edit the room, mandatory if configured in the room>",
"display" : "<new display name for the remote publisher; optional>",
"metadata" : <new valid json object of metadata; optional>,
"streams" : [
{
// Same syntax as add_remote_publisher: only needs to
Expand Down Expand Up @@ -2003,7 +2013,7 @@ static struct janus_json_parameter join_parameters[] = {
{"bitrate", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"record", JANUS_JSON_BOOL, 0},
{"filename", JSON_STRING, 0},
{"token", JSON_STRING, 0}
{"token", JSON_STRING, 0},
};
static struct janus_json_parameter publish_parameters[] = {
{"descriptions", JANUS_JSON_ARRAY, 0},
Expand All @@ -2014,6 +2024,7 @@ static struct janus_json_parameter publish_parameters[] = {
{"record", JANUS_JSON_BOOL, 0},
{"filename", JSON_STRING, 0},
{"display", JSON_STRING, 0},
{"metadata", JSON_OBJECT, 0},
{"secret", JSON_STRING, 0},
{"audio_level_averge", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
Expand Down Expand Up @@ -2088,7 +2099,8 @@ static struct janus_json_parameter stop_rtp_forward_parameters[] = {
{"stream_id", JSON_INTEGER, JANUS_JSON_PARAM_REQUIRED | JANUS_JSON_PARAM_POSITIVE}
};
static struct janus_json_parameter publisher_parameters[] = {
{"display", JSON_STRING, 0}
{"display", JSON_STRING, 0},
{"metadata", JSON_OBJECT, 0}
};
static struct janus_json_parameter configure_stream_parameters[] = {
{"mid", JANUS_JSON_STRING, 0},
Expand Down Expand Up @@ -2196,10 +2208,12 @@ static struct janus_json_parameter remote_publisher_parameters[] = {
{"iface", JANUS_JSON_STRING, 0},
{"port", JANUS_JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"streams", JANUS_JSON_ARRAY, JANUS_JSON_PARAM_REQUIRED},
{"metadata", JSON_OBJECT, 0}
};
static struct janus_json_parameter remote_publisher_update_parameters[] = {
{"secret", JSON_STRING, 0},
{"display", JANUS_JSON_STRING, 0},
{"metadata", JSON_OBJECT, 0},
{"streams", JANUS_JSON_ARRAY, JANUS_JSON_PARAM_REQUIRED}
};
static struct janus_json_parameter remote_publisher_stream_parameters[] = {
Expand Down Expand Up @@ -2432,6 +2446,7 @@ typedef struct janus_videoroom_publisher {
gboolean kicked; /* Whether this participant has been kicked */
gboolean e2ee; /* If media from this publisher is end-to-end encrypted */
janus_mutex mutex; /* Mutex to lock this instance */
json_t *metadata;
volatile gint destroyed;
janus_refcount ref;
} janus_videoroom_publisher;
Expand Down Expand Up @@ -2760,6 +2775,8 @@ static void janus_videoroom_publisher_free(const janus_refcount *p_ref) {
g_free(p->user_id_str);
g_free(p->display);
g_free(p->recording_base);
if(p->metadata != NULL)
json_decref(p->metadata);
/* Get rid of all the streams */
g_list_free_full(p->streams, (GDestroyNotify)(janus_videoroom_publisher_stream_destroy));
g_hash_table_unref(p->streams_byid);
Expand Down Expand Up @@ -4257,6 +4274,8 @@ static void janus_videoroom_notify_about_publisher(janus_videoroom_publisher *p,
json_object_set_new(pl, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
if(p->display)
json_object_set_new(pl, "display", json_string(p->display));
if(p->metadata)
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
/* Add proper info on all the streams */
gboolean audio_added = FALSE, video_added = FALSE;
json_t *media = json_array();
Expand Down Expand Up @@ -4332,6 +4351,8 @@ static void janus_videoroom_notify_about_publisher(janus_videoroom_publisher *p,
json_object_set_new(info, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
if(p->display)
json_object_set_new(info, "display", json_string(p->display));
if(p->metadata)
json_object_set_new(info, "metadata", json_deep_copy(p->metadata));
json_t *media = json_array();
GList *temp = p->streams;
while(temp) {
Expand Down Expand Up @@ -4376,6 +4397,9 @@ static void janus_videoroom_participant_joining(janus_videoroom_publisher *p) {
if (p->display) {
json_object_set_new(user, "display", json_string(p->display));
}
if (p->metadata) {
json_object_set_new(user, "metadata", json_deep_copy(p->metadata));
}
json_object_set_new(event, "videoroom", json_string("event"));
json_object_set_new(event, "room", string_ids ? json_string(p->room_id_str) : json_integer(p->room_id));
json_object_set_new(event, "joining", user);
Expand Down Expand Up @@ -4424,6 +4448,8 @@ static void janus_videoroom_leave_or_unpublish(janus_videoroom_publisher *partic
json_object_set_new(info, "id", string_ids ? json_string(participant->user_id_str) : json_integer(participant->user_id));
if(participant->display)
json_object_set_new(info, "display", json_string(participant->display));
if(participant->metadata)
json_object_set_new(info, "metadata", json_deep_copy(participant->metadata));
gateway->notify_event(&janus_videoroom_plugin, NULL, info);
}
if(is_leaving) {
Expand Down Expand Up @@ -4535,6 +4561,8 @@ json_t *janus_videoroom_query_session(janus_plugin_session *handle) {
json_object_set_new(info, "private_id", json_integer(participant->pvt_id));
if(participant->display)
json_object_set_new(info, "display", json_string(participant->display));
if(participant->metadata)
json_object_set_new(info, "metadata", json_deep_copy(participant->metadata));
/* TODO Fix the summary of viewers, since everything is stream based now */
//~ if(participant->subscribers)
//~ json_object_set_new(info, "viewers", json_integer(g_slist_length(participant->subscribers)));
Expand Down Expand Up @@ -6848,6 +6876,8 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
json_object_set_new(pl, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
if(p->display)
json_object_set_new(pl, "display", json_string(p->display));
if(p->metadata)
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
if(p->dummy)
json_object_set_new(pl, "dummy", json_true());
if(p->remote)
Expand Down Expand Up @@ -6931,6 +6961,8 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
json_object_set_new(pl, "publisher_id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
if(p->display)
json_object_set_new(pl, "display", json_string(p->display));
if(p->metadata)
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
json_t *flist = json_array();
/* Iterate on all media streams to see what's being forwarded */
janus_videoroom_publisher_stream *ps = NULL;
Expand Down Expand Up @@ -7576,6 +7608,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
char user_id_num[30], *user_id_str = NULL;
gboolean user_id_allocated = FALSE;
json_t *id = json_object_get(root, "id");
json_t *metadata = json_object_get(root, "metadata");
if(id) {
if(!string_ids) {
user_id = json_integer_value(id);
Expand Down Expand Up @@ -7706,6 +7739,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
publisher->remote_ssrc_offset = janus_random_uint32();
publisher->remote_fd = fd;
publisher->remote_rtcp_fd = rtcp_fd;
publisher->metadata = metadata ? json_deep_copy(metadata) : NULL;
pipe(publisher->pipefd);
janus_mutex_init(&publisher->subscribers_mutex);
janus_mutex_init(&publisher->own_subscriptions_mutex);
Expand Down Expand Up @@ -7966,14 +8000,22 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi
goto prepare_response;
}
janus_refcount_increase(&publisher->ref);
/* Check if there's a new display, new streams, or changes to existing ones */
/* Check if there's a new display, new metadata, new streams, or changes to existing ones */
json_t *display = json_object_get(root, "display");
if(display) {
char *old_display = publisher->display;
char *new_display = g_strdup(json_string_value(display));
publisher->display = new_display;
g_free(old_display);
}
json_t *metadata = json_object_get(root, "metadata");
if(metadata) {
json_t *old_metadata = publisher->metadata;
json_t *new_metadata = json_deep_copy(metadata);
publisher->metadata = new_metadata;
if(old_metadata)
json_decref(old_metadata);
}
janus_mutex_unlock(&videoroom->mutex);
janus_mutex_lock(&publisher->streams_mutex);
janus_videoroom_publisher_stream *ps = NULL;
Expand Down Expand Up @@ -9429,6 +9471,7 @@ static void *janus_videoroom_handler(void *data) {
}
}
json_t *display = json_object_get(root, "display");
json_t *metadata= json_object_get(root, "metadata");
const char *display_text = display ? json_string_value(display) : NULL;
guint64 user_id = 0;
char user_id_num[30], *user_id_str = NULL;
Expand Down Expand Up @@ -9506,6 +9549,7 @@ static void *janus_videoroom_handler(void *data) {
publisher->user_id = user_id;
publisher->user_id_str = user_id_str ? g_strdup(user_id_str) : NULL;
publisher->display = display_text ? g_strdup(display_text) : NULL;
publisher->metadata = NULL;
publisher->recording_active = FALSE;
publisher->recording_base = NULL;
publisher->firefox = FALSE;
Expand Down Expand Up @@ -9611,6 +9655,11 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_VERB, "Setting user audio_level_average: %d (room %s, user %s)\n",
publisher->user_audio_level_average, publisher->room_id_str, publisher->user_id_str);
}
if(metadata) {
publisher->metadata = json_deep_copy(metadata);
JANUS_LOG(LOG_VERB, "Setting metadata: (room %s, user %s)\n",
publisher->room_id_str, publisher->user_id_str);
}
/* Done */
janus_mutex_lock(&session->mutex);
/* Make sure the session has not been destroyed in the meanwhile */
Expand Down Expand Up @@ -9658,6 +9707,8 @@ static void *janus_videoroom_handler(void *data) {
json_object_set_new(pl, "id", string_ids ? json_string(p->user_id_str) : json_integer(p->user_id));
if(p->display)
json_object_set_new(pl, "display", json_string(p->display));
if(p->metadata)
json_object_set_new(pl, "metadata", json_deep_copy(p->metadata));
if(p->dummy)
json_object_set_new(pl, "dummy", json_true());
/* Add proper info on all the streams */
Expand Down Expand Up @@ -10509,6 +10560,7 @@ static void *janus_videoroom_handler(void *data) {
json_t *record = json_object_get(root, "record");
json_t *recfile = json_object_get(root, "filename");
json_t *display = json_object_get(root, "display");
json_t *metadata = json_object_get(root, "metadata");
json_t *update = json_object_get(root, "update");
json_t *user_audio_active_packets = json_object_get(root, "audio_active_packets");
json_t *user_audio_level_average = json_object_get(root, "audio_level_average");
Expand Down Expand Up @@ -10804,6 +10856,26 @@ static void *janus_videoroom_handler(void *data) {
g_free(old_display);
janus_mutex_unlock(&participant->room->mutex);
}
if(metadata) {
janus_mutex_lock(&participant->room->mutex);
char *old_metadata = participant->metadata;
char *new_metadata = json_deep_copy(metadata);
participant->metadata = new_metadata;
if(old_metadata != NULL) {
/* The metadata changed, notify this */
json_t *metadata_event = json_object();
json_object_set_new(metadata_event, "videoroom", json_string("event"));
json_object_set_new(metadata_event, "id", string_ids ?
json_string(participant->user_id_str) : json_integer(participant->user_id));
json_object_set_new(metadata_event, "metadata", json_deep_copy(participant->metadata));
if(participant->room && !g_atomic_int_get(&participant->room->destroyed)) {
janus_videoroom_notify_participants(participant, metadata_event, FALSE);
}
json_decref(metadata_event);
json_decref(old_metadata);
}
janus_mutex_unlock(&participant->room->mutex);
}
/* Are we updating the description? */
if(descriptions != NULL && json_array_size(descriptions) > 0 && json_string_value(json_object_get(msg->jsep, "sdp")) == NULL) {
/* We only do this here if this is an SDP-less configure: in case
Expand Down

0 comments on commit 35f15cf

Please sign in to comment.