Skip to content

Commit

Permalink
User talking (#2158)
Browse files Browse the repository at this point in the history
Per-user override of global room values of audio_active_packets and audio_level_average (AudioBridge and VideoRoom)
  • Loading branch information
do-not-set-2fa authored May 20, 2020
1 parent 6d2be20 commit 8986820
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
18 changes: 17 additions & 1 deletion plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ room-<unique room ID>: {
"quality" : <0-10, Opus-related complexity to use, the higher the value, the better the quality (but more CPU); optional, default is 4>,
"volume" : <percent value, <100 reduces volume, >100 increases volume; optional, default is 100 (no volume change)>,
"secret" : "<room management password; optional, if provided the user is an admin and can't be globally muted with mute_room>",
"audio_level_average" : "<overwrite, only for this user, global room value of average level of microphone activity>",
"audio_active_packets" : "<overwrite, only for this user, global room value of number of packets to be evaluated>",
}
\endverbatim
*
Expand Down Expand Up @@ -960,7 +962,9 @@ static struct janus_json_parameter join_parameters[] = {
{"prebuffer", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"quality", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"volume", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"secret", JSON_STRING, 0}
{"secret", JSON_STRING, 0},
{"audio_level_average", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE}
};
static struct janus_json_parameter configure_parameters[] = {
{"muted", JANUS_JSON_BOOL, 0},
Expand Down Expand Up @@ -1256,6 +1260,8 @@ typedef struct janus_audiobridge_participant {
int dBov_level; /* Value in dBov of the audio level (last value from extension) */
int audio_active_packets; /* Participant's number of audio packets to accumulate */
int audio_dBov_sum; /* Participant's accumulated dBov value for audio level */
int user_audio_active_packets; /* Participant's number of audio packets to evaluate */
int user_audio_level_average; /* Participant's average level of dBov value */
gboolean talking; /* Whether this participant is currently talking (uses audio levels extension) */
janus_rtp_switching_context context; /* Needed in case the participant changes room */
janus_audiocodec codec; /* Codec this participant is using (most often Opus, but G.711 is supported too) */
Expand Down Expand Up @@ -4602,6 +4608,12 @@ void janus_audiobridge_incoming_rtp(janus_plugin_session *handle, janus_plugin_r
/* We also need to detect who's talking: update our monitoring stuff */
int audio_active_packets = participant->room ? participant->room->audio_active_packets : 100;
int audio_level_average = participant->room ? participant->room->audio_level_average : 25;
/* Override with user join parameters*/
if (participant->user_audio_active_packets && participant->user_audio_active_packets > 0)
audio_active_packets = participant->user_audio_active_packets;
if (participant->user_audio_level_average && participant->user_audio_level_average > 0)
audio_level_average = participant->user_audio_level_average;
JANUS_LOG(LOG_ERR, "audio_active_packets: %d\n", audio_active_packets);
participant->audio_dBov_sum += level;
participant->audio_active_packets++;
participant->dBov_level = level;
Expand Down Expand Up @@ -5112,6 +5124,8 @@ static void *janus_audiobridge_handler(void *data) {
json_t *gain = json_object_get(root, "volume");
json_t *quality = json_object_get(root, "quality");
json_t *acodec = json_object_get(root, "codec");
json_t *user_audio_level_average = json_object_get(root, "audio_level_average");
json_t *user_audio_active_packets = json_object_get(root, "audio_active_packets");
uint prebuffer_count = prebuffer ? json_integer_value(prebuffer) : audiobridge->default_prebuffering;
if(prebuffer_count > MAX_PREBUFFERING) {
prebuffer_count = audiobridge->default_prebuffering;
Expand Down Expand Up @@ -5223,6 +5237,8 @@ static void *janus_audiobridge_handler(void *data) {
participant->prebuffer_count = prebuffer_count;
participant->volume_gain = volume;
participant->opus_complexity = complexity;
participant->user_audio_active_packets = json_integer_value(user_audio_active_packets);
participant->user_audio_level_average = json_integer_value(user_audio_level_average);
if(participant->outbuf == NULL)
participant->outbuf = g_async_queue_new();
g_atomic_int_set(&participant->active, g_atomic_int_get(&session->started));
Expand Down
59 changes: 53 additions & 6 deletions plugins/janus_videoroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ 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>"
"audio_active_packets" : "<audio_active_packets to overwrite in the room one; optional>",
"audio_level_average" : "<audio_level_average to overwrite the room one; optional>",
}
\endverbatim
*
Expand Down Expand Up @@ -623,7 +625,9 @@ room-<unique room ID>: {
"keyframe" : <true|false, whether we should send this publisher a keyframe request>,
"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>"
"display" : "<new display name to use in the room; 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>",
}
\endverbatim
*
Expand Down Expand Up @@ -1001,7 +1005,9 @@ room-<unique room ID>: {
"temporal" : <temporal layers to receive (0-2), in case simulcasting is enabled; optional>,
"fallback" : <How much time (in us, default 250000) without receiving packets will make us drop to the substream below>,
"spatial_layer" : <spatial layer to receive (0-2), in case VP9-SVC is enabled; optional>,
"temporal_layer" : <temporal layers to receive (0-2), in case VP9-SVC is enabled; optional>
"temporal_layer" : <temporal layers to receive (0-2), in case VP9-SVC is enabled; optional>,
"audio_level_average" : "<overwrite, only for this publisher, global room value of average level of microphone activity>",
"audio_active_packets" : "<overwrite, only for this publisher, global room value of number of packets to be evaluated>"
}
\endverbatim
*
Expand Down Expand Up @@ -1281,6 +1287,8 @@ static struct janus_json_parameter publish_parameters[] = {
{"filename", JSON_STRING, 0},
{"display", JSON_STRING, 0},
{"secret", JSON_STRING, 0},
{"audio_level_averge", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
/* The following are just to force a renegotiation and/or an ICE restart */
{"update", JANUS_JSON_BOOL, 0},
{"restart", JANUS_JSON_BOOL, 0}
Expand Down Expand Up @@ -1329,6 +1337,8 @@ static struct janus_json_parameter configure_parameters[] = {
{"temporal_layer", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
/* The following is to handle a renegotiation */
{"update", JANUS_JSON_BOOL, 0},
{"audio_level_averge", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE}
};
static struct janus_json_parameter subscriber_parameters[] = {
{"private_id", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
Expand Down Expand Up @@ -1546,7 +1556,9 @@ typedef struct janus_videoroom_publisher {
int audio_dBov_level; /* Value in dBov of the audio level (last value from extension) */
int audio_active_packets; /* Participant's number of audio packets to accumulate */
int audio_dBov_sum; /* Participant's accumulated dBov value for audio level*/
gboolean talking; /* Whether this participant is currently talking (uses audio levels extension) */
int user_audio_active_packets; /* Participant's audio_active_packets overwriting global room setting */
int user_audio_level_average; /* Participant's audio_level_average overwriting global room setting */
gboolean talking; /* Whether this participant is currently talking (uses audio levels extension) */
gboolean data_active;
gboolean firefox; /* We send Firefox users a different kind of FIR */
uint32_t bitrate;
Expand Down Expand Up @@ -4816,10 +4828,12 @@ void janus_videoroom_incoming_rtp(janus_plugin_session *handle, janus_plugin_rtp
participant->audio_dBov_sum += level;
participant->audio_active_packets++;
participant->audio_dBov_level = level;
if(participant->audio_active_packets > 0 && participant->audio_active_packets == videoroom->audio_active_packets) {
int audio_active_packets = participant->user_audio_active_packets ? participant->user_audio_active_packets : videoroom->audio_active_packets;
int audio_level_average = participant->user_audio_level_average ? participant->user_audio_level_average : videoroom->audio_level_average;
if(participant->audio_active_packets > 0 && participant->audio_active_packets == audio_active_packets) {
gboolean notify_talk_event = FALSE;
float audio_dBov_avg = (float)participant->audio_dBov_sum/(float)participant->audio_active_packets;
if(audio_dBov_avg < videoroom->audio_level_average) {
if(audio_dBov_avg < audio_level_average) {
/* Participant talking, should we notify all participants? */
if(!participant->talking)
notify_talk_event = TRUE;
Expand Down Expand Up @@ -5408,6 +5422,8 @@ static void janus_videoroom_hangup_media_internal(janus_plugin_session *handle)
participant->video_active = FALSE;
participant->data_active = FALSE;
participant->audio_active_packets = 0;
participant->user_audio_active_packets = 0;
participant->user_audio_level_average = 0;
participant->audio_dBov_sum = 0;
participant->audio_dBov_level = 0;
participant->talking = FALSE;
Expand Down Expand Up @@ -5648,7 +5664,8 @@ static void *janus_videoroom_handler(void *data) {
}
/* Process the request */
json_t *audio = NULL, *video = NULL, *data = NULL,
*bitrate = NULL, *record = NULL, *recfile = NULL;
*bitrate = NULL, *record = NULL, *recfile = NULL,
*user_audio_active_packets = NULL, *user_audio_level_average = NULL;
if(!strcasecmp(request_text, "joinandconfigure")) {
/* Also configure (or publish a new feed) audio/video/bitrate for this new publisher */
/* join_parameters were validated earlier. */
Expand All @@ -5659,6 +5676,8 @@ static void *janus_videoroom_handler(void *data) {
record = json_object_get(root, "record");
recfile = json_object_get(root, "filename");
}
user_audio_active_packets = json_object_get(root, "audio_active_packets");
user_audio_level_average = json_object_get(root, "audio_level_average");
janus_videoroom_publisher *publisher = g_malloc0(sizeof(janus_videoroom_publisher));
publisher->session = session;
publisher->room_id = videoroom->room_id;
Expand Down Expand Up @@ -5746,6 +5765,16 @@ static void *janus_videoroom_handler(void *data) {
JANUS_LOG(LOG_VERB, "Setting recording basename: %s (room %s, user %s)\n",
publisher->recording_base, publisher->room_id_str, publisher->user_id_str);
}
if(user_audio_active_packets) {
publisher->user_audio_active_packets = json_integer_value(user_audio_active_packets);
JANUS_LOG(LOG_ERR, "Setting user audio_active_packets: %d (room %s, user %s)\n",
publisher->user_audio_active_packets, publisher->room_id_str, publisher->user_id_str);
}
if(user_audio_level_average) {
publisher->user_audio_level_average = json_integer_value(user_audio_level_average);
JANUS_LOG(LOG_ERR, "Setting user audio_level_average: %d (room %s, user %s)\n",
publisher->user_audio_level_average, publisher->room_id_str, publisher->user_id_str);
}
/* Done */
janus_mutex_lock(&session->mutex);
session->participant_type = janus_videoroom_p_type_publisher;
Expand Down Expand Up @@ -5797,6 +5826,10 @@ static void *janus_videoroom_handler(void *data) {
json_object_set_new(event, "id", string_ids ? json_string(user_id_str) : json_integer(user_id));
json_object_set_new(event, "private_id", json_integer(publisher->pvt_id));
json_object_set_new(event, "publishers", list);
if (publisher->user_audio_active_packets)
json_object_set_new(event, "audio_active_packets", json_integer(publisher->user_audio_active_packets));
if (publisher->user_audio_level_average)
json_object_set_new(event, "audio_level_average", json_integer(publisher->user_audio_level_average));
if(attendees != NULL)
json_object_set_new(event, "attendees", attendees);
/* See if we need to notify about a new participant joined the room (by default, we don't). */
Expand All @@ -5812,6 +5845,10 @@ static void *janus_videoroom_handler(void *data) {
json_object_set_new(info, "private_id", json_integer(publisher->pvt_id));
if(display_text != NULL)
json_object_set_new(info, "display", json_string(display_text));
if (publisher->user_audio_active_packets)
json_object_set_new(info, "audio_active_packets", json_integer(publisher->user_audio_active_packets));
if (publisher->user_audio_level_average)
json_object_set_new(info, "audio_level_average", json_integer(publisher->user_audio_level_average));
gateway->notify_event(&janus_videoroom_plugin, session->handle, info);
}
janus_mutex_unlock(&publisher->room->mutex);
Expand Down Expand Up @@ -6125,6 +6162,8 @@ static void *janus_videoroom_handler(void *data) {
json_t *recfile = json_object_get(root, "filename");
json_t *display = json_object_get(root, "display");
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");
if(audio) {
gboolean audio_active = json_is_true(audio);
if(session->started && audio_active && !participant->audio_active) {
Expand Down Expand Up @@ -6216,6 +6255,14 @@ static void *janus_videoroom_handler(void *data) {
/* Send a FIR */
janus_videoroom_reqpli(participant, "Keyframe request");
}
if(user_audio_active_packets) {
participant->user_audio_active_packets = json_integer_value(user_audio_active_packets);
JANUS_LOG(LOG_ERR, "user_audio_active_packets: %llu \n", json_integer_value(user_audio_active_packets));
}
if(user_audio_level_average) {
participant->user_audio_level_average = json_integer_value(user_audio_level_average);
JANUS_LOG(LOG_ERR, "user_audio_level_average: %llu \n", json_integer_value(user_audio_level_average));
}
gboolean record_locked = FALSE;
if((record || recfile) && participant->room->lock_record && participant->room->room_secret) {
JANUS_CHECK_SECRET(participant->room->room_secret, root, "secret", error_code, error_cause,
Expand Down

0 comments on commit 8986820

Please sign in to comment.