Skip to content

Commit

Permalink
Add per-participant recording options in AudioBridge to join API as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed May 7, 2021
1 parent 55519d1 commit 280e8e4
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion plugins/janus_audiobridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,9 @@ room-<unique room ID>: {
"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" : "<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>"
"audio_active_packets" : "<if provided, overrides the room audio_active_packets for this user; optional>",
"record": <true|false, whether to record this user's contribution to a .mjr file (mixer not involved),
"filename": "<basename of the file to record to, -audio.mjr will be added by the plugin>"
}
\endverbatim
*
Expand Down Expand Up @@ -1031,6 +1033,8 @@ static struct janus_json_parameter join_parameters[] = {
{"volume", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio_level_average", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
{"record", JANUS_JSON_BOOL, 0},
{"filename", JSON_STRING, 0},
{"generate_offer", JANUS_JSON_BOOL, 0},
{"rtp", JSON_OBJECT, 0},
{"secret", JSON_STRING, 0}
Expand Down Expand Up @@ -5431,6 +5435,8 @@ static void *janus_audiobridge_handler(void *data) {
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");
json_t *record = json_object_get(root, "record");
json_t *recfile = json_object_get(root, "filename");
json_t *gen_offer = json_object_get(root, "generate_offer");
uint prebuffer_count = prebuffer ? json_integer_value(prebuffer) : audiobridge->default_prebuffering;
if(prebuffer_count > MAX_PREBUFFERING) {
Expand Down Expand Up @@ -5621,6 +5627,46 @@ static void *janus_audiobridge_handler(void *data) {
}
}
participant->reset = FALSE;
/* Check if we need to record this participant right away */
if(record) {
janus_mutex_lock(&participant->rec_mutex);
if(json_is_true(record)) {
/* Start recording (ignore if recording already) */
if(participant->arc != NULL) {
JANUS_LOG(LOG_WARN, "Already recording participant's audio (room %s, user %s)\n",
participant->room->room_id_str, participant->user_id_str);
} else {
JANUS_LOG(LOG_INFO, "Starting recording of participant's audio (room %s, user %s)\n",
participant->room->room_id_str, participant->user_id_str);
char filename[255];
gint64 now = janus_get_real_time();
memset(filename, 0, 255);
const char *recording_base = json_string_value(recfile);
if(recording_base) {
/* Use the filename and path we have been provided */
g_snprintf(filename, 255, "%s-audio", recording_base);
participant->arc = janus_recorder_create(NULL, "opus", filename);
if(participant->arc == NULL) {
/* FIXME We should notify the fact the recorder could not be created */
JANUS_LOG(LOG_ERR, "Couldn't open an audio recording file for this participant!\n");
}
} else {
/* Build a filename */
g_snprintf(filename, 255, "audiobridge-%s-%s-%"SCNi64"-audio",
participant->room->room_id_str, participant->user_id_str, now);
participant->arc = janus_recorder_create(NULL, "opus", filename);
if(participant->arc == NULL) {
/* FIXME We should notify the fact the recorder could not be created */
JANUS_LOG(LOG_ERR, "Couldn't open an audio recording file for this participant!\n");
}
}
}
} else {
/* Stop recording (ignore if not recording) */
janus_audiobridge_recorder_close(participant);
}
janus_mutex_unlock(&participant->rec_mutex);
}
/* If this is a plain RTP participant, create the socket */
if(rtp != NULL) {
const char *ip = json_string_value(json_object_get(rtp, "ip"));
Expand Down

0 comments on commit 280e8e4

Please sign in to comment.