Revision d223cef1 plugins/janus_videocall.c

View differences:

plugins/janus_videocall.c
364 364
	struct janus_videocall_session *peer;
365 365
	janus_recorder *arc;	/* The Janus recorder instance for this user's audio, if enabled */
366 366
	janus_recorder *vrc;	/* The Janus recorder instance for this user's video, if enabled */
367
	janus_mutex rec_mutex;	/* Mutex to protect the recorders from race conditions */
367 368
	volatile gint hangingup;
368 369
	gint64 destroyed;	/* Time at which this session was marked as destroyed */
369 370
} janus_videocall_session;
......
552 553
	session->bitrate = 0;	/* No limit */
553 554
	session->peer = NULL;
554 555
	session->username = NULL;
556
	janus_mutex_init(&session->rec_mutex);
555 557
	session->destroyed = 0;
556 558
	g_atomic_int_set(&session->hangingup, 0);
557 559
	handle->plugin_handle = session;
......
672 674
			return;
673 675
		if((!video && session->audio_active) || (video && session->video_active)) {
674 676
			/* Save the frame if we're recording */
675
			if(video && session->vrc)
676
				janus_recorder_save_frame(session->vrc, buf, len);
677
			else if(!video && session->arc)
678
				janus_recorder_save_frame(session->arc, buf, len);
677
			janus_recorder_save_frame(video ? session->vrc : session->arc, buf, len);
679 678
			/* Forward the packet to the peer */
680 679
			gateway->relay_rtp(session->peer->handle, video, buf, len);
681 680
		}
......
803 802
	if(g_atomic_int_add(&session->hangingup, 1))
804 803
		return;
805 804
	/* Get rid of the recorders, if available */
805
	janus_mutex_lock(&session->rec_mutex);
806 806
	if(session->arc) {
807 807
		janus_recorder_close(session->arc);
808 808
		JANUS_LOG(LOG_INFO, "Closed audio recording %s\n", session->arc->filename ? session->arc->filename : "??");
......
815 815
		janus_recorder_free(session->vrc);
816 816
	}
817 817
	session->vrc = NULL;
818
	janus_mutex_unlock(&session->rec_mutex);
818 819
	if(session->peer) {
819 820
		/* Send event to our peer too */
820 821
		json_t *call = json_object();
......
1135 1136
				gboolean recording = json_is_true(record);
1136 1137
				const char *recording_base = json_string_value(recfile);
1137 1138
				JANUS_LOG(LOG_VERB, "Recording %s (base filename: %s)\n", recording ? "enabled" : "disabled", recording_base ? recording_base : "not provided");
1139
				janus_mutex_lock(&session->rec_mutex);
1138 1140
				if(!recording) {
1139 1141
					/* Not recording (anymore?) */
1140 1142
					if(session->arc) {
......
1208 1210
						gateway->relay_rtcp(session->handle, 1, buf, 12);
1209 1211
					}
1210 1212
				}
1213
				janus_mutex_unlock(&session->rec_mutex);
1211 1214
			}
1212 1215
			/* Send an ack back */
1213 1216
			result = json_object();

Also available in: Unified diff