Revision d223cef1 plugins/janus_videoroom.c

View differences:

plugins/janus_videoroom.c
426 426
	gchar *recording_base;	/* Base name for the recording (e.g., /path/to/filename, will generate /path/to/filename-audio.mjr and/or /path/to/filename-video.mjr */
427 427
	janus_recorder *arc;	/* The Janus recorder instance for this publisher's audio, if enabled */
428 428
	janus_recorder *vrc;	/* The Janus recorder instance for this publisher's video, if enabled */
429
	janus_mutex rec_mutex;	/* Mutex to protect the recorders from race conditions */
429 430
	GSList *listeners;
430 431
	janus_mutex listeners_mutex;
431 432
	GHashTable *rtp_forwarders;
......
1995 1996
		}
1996 1997
		janus_mutex_unlock(&participant->rtp_forwarders_mutex);
1997 1998
		/* Save the frame if we're recording */
1998
		if(video && participant->vrc)
1999
			janus_recorder_save_frame(participant->vrc, buf, len);
2000
		else if(!video && participant->arc)
2001
			janus_recorder_save_frame(participant->arc, buf, len);
1999
		janus_recorder_save_frame(video ? participant->vrc : participant->arc, buf, len);
2002 2000
		/* Done, relay it */
2003 2001
		janus_videoroom_rtp_relay_packet packet;
2004 2002
		packet.data = rtp;
......
2194 2192
	if(session->participant_type == janus_videoroom_p_type_publisher) {
2195 2193
		/* This publisher just 'unpublished' */
2196 2194
		janus_videoroom_participant *participant = (janus_videoroom_participant *)session->participant;
2197
		/* Lock listeners_mutex to protect recorders from race conditions. */
2198
		/* This mutex doesn't have an appropriate name but it is less coarse than participant->room->participants_mutex. */
2199 2195
		janus_mutex_lock(&participant->listeners_mutex);
2200 2196
		if(participant->sdp)
2201 2197
			g_free(participant->sdp);
......
2208 2204
		participant->fir_latest = 0;
2209 2205
		participant->fir_seq = 0;
2210 2206
		/* Get rid of the recorders, if available */
2207
		janus_mutex_lock(&participant->rec_mutex);
2211 2208
		if(participant->arc) {
2212 2209
			janus_recorder_close(participant->arc);
2213 2210
			JANUS_LOG(LOG_INFO, "Closed audio recording %s\n", participant->arc->filename ? participant->arc->filename : "??");
......
2220 2217
			janus_recorder_free(participant->vrc);
2221 2218
		}
2222 2219
		participant->vrc = NULL;
2220
		janus_mutex_unlock(&participant->rec_mutex);
2223 2221
		while(participant->listeners) {
2224 2222
			janus_videoroom_listener *l = (janus_videoroom_listener *)participant->listeners->data;
2225 2223
			if(l) {
......
2452 2450
				publisher->recording_base = NULL;
2453 2451
				publisher->arc = NULL;
2454 2452
				publisher->vrc = NULL;
2453
				janus_mutex_init(&publisher->rec_mutex);
2455 2454
				publisher->firefox = FALSE;
2456 2455
				publisher->bitrate = videoroom->bitrate;
2457 2456
				publisher->listeners = NULL;
......
2765 2764
				json_t *bitrate = json_object_get(root, "bitrate");
2766 2765
				json_t *record = json_object_get(root, "record");
2767 2766
				json_t *recfile = json_object_get(root, "filename");
2768
				/* Lock listeners_mutex to protect recorders from race conditions. */
2769
				janus_mutex_lock(&participant->listeners_mutex);
2770 2767
				if(audio) {
2771 2768
					participant->audio_active = json_is_true(audio);
2772 2769
					JANUS_LOG(LOG_VERB, "Setting audio property: %s (room %"SCNu64", user %"SCNu64")\n", participant->audio_active ? "true" : "false", participant->room->room_id, participant->user_id);
......
2784 2781
					janus_rtcp_remb((char *)(&rtcpbuf), 24, participant->bitrate ? participant->bitrate : 256*1024);
2785 2782
					gateway->relay_rtcp(msg->handle, 1, rtcpbuf, 24);
2786 2783
				}
2784
				janus_mutex_lock(&participant->rec_mutex);
2787 2785
				gboolean prev_recording_active = participant->recording_active;
2788 2786
				if(record) {
2789 2787
					participant->recording_active = json_is_true(record);
......
2871 2869
						}
2872 2870
					}
2873 2871
				}
2874
				janus_mutex_unlock(&participant->listeners_mutex);
2872
				janus_mutex_unlock(&participant->rec_mutex);
2875 2873
				/* Done */
2876 2874
				event = json_object();
2877 2875
				json_object_set_new(event, "videoroom", json_string("event"));

Also available in: Unified diff