Revision d223cef1 plugins/janus_echotest.c

View differences:

plugins/janus_echotest.c
185 185
	uint64_t bitrate;
186 186
	janus_recorder *arc;	/* The Janus recorder instance for this user's audio, if enabled */
187 187
	janus_recorder *vrc;	/* The Janus recorder instance for this user's video, if enabled */
188
	janus_mutex rec_mutex;	/* Mutex to protect the recorders from race conditions */
188 189
	guint16 slowlink_count;
189 190
	volatile gint hangingup;
190 191
	gint64 destroyed;	/* Time at which this session was marked as destroyed */
......
379 380
	session->has_video = FALSE;
380 381
	session->audio_active = TRUE;
381 382
	session->video_active = TRUE;
383
	janus_mutex_init(&session->rec_mutex);
382 384
	session->bitrate = 0;	/* No limit */
383 385
	session->destroyed = 0;
384 386
	g_atomic_int_set(&session->hangingup, 0);
......
491 493
			return;
492 494
		if((!video && session->audio_active) || (video && session->video_active)) {
493 495
			/* Save the frame if we're recording */
494
			if(video && session->vrc)
495
				janus_recorder_save_frame(session->vrc, buf, len);
496
			else if(!video && session->arc)
497
				janus_recorder_save_frame(session->arc, buf, len);
496
			janus_recorder_save_frame(video ? session->vrc : session->arc, buf, len);
498 497
			/* Send the frame back */
499 498
			gateway->relay_rtp(handle, video, buf, len);
500 499
		}
......
620 619
	JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
621 620
	g_free(event_text);
622 621
	/* Get rid of the recorders, if available */
622
	janus_mutex_lock(&session->rec_mutex);
623 623
	if(session->arc) {
624 624
		janus_recorder_close(session->arc);
625 625
		JANUS_LOG(LOG_INFO, "Closed audio recording %s\n", session->arc->filename ? session->arc->filename : "??");
......
632 632
		janus_recorder_free(session->vrc);
633 633
	}
634 634
	session->vrc = NULL;
635
	janus_mutex_unlock(&session->rec_mutex);
635 636
	/* Reset controls */
636 637
	session->has_audio = FALSE;
637 638
	session->has_video = FALSE;
......
774 775
			gboolean recording = json_is_true(record);
775 776
			const char *recording_base = json_string_value(recfile);
776 777
			JANUS_LOG(LOG_VERB, "Recording %s (base filename: %s)\n", recording ? "enabled" : "disabled", recording_base ? recording_base : "not provided");
778
			janus_mutex_lock(&session->rec_mutex);
777 779
			if(!recording) {
778 780
				/* Not recording (anymore?) */
779 781
				if(session->arc) {
......
841 843
					gateway->relay_rtcp(session->handle, 1, buf, 12);
842 844
				}
843 845
			}
846
			janus_mutex_unlock(&session->rec_mutex);
844 847
		}
845 848
		/* Any SDP to handle? */
846 849
		if(msg->sdp) {

Also available in: Unified diff