diff --git a/plugins/janus_audiobridge.c b/plugins/janus_audiobridge.c index 99f64f26bb..40b5a88c63 100644 --- a/plugins/janus_audiobridge.c +++ b/plugins/janus_audiobridge.c @@ -647,7 +647,9 @@ room-: { "volume" : 100 increases volume; optional, default is 100 (no volume change)>, "secret" : "", "audio_level_average" : "", - "audio_active_packets" : "" + "audio_active_packets" : "", + "record": " } \endverbatim * @@ -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} @@ -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) { @@ -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"));