Revision d223cef1 plugins/janus_streaming.c

View differences:

plugins/janus_streaming.c
315 315
	in_addr_t video_mcast;
316 316
	janus_recorder *arc;	/* The Janus recorder instance for this streams's audio, if enabled */
317 317
	janus_recorder *vrc;	/* The Janus recorder instance for this streams's video, if enabled */
318
	janus_mutex rec_mutex;	/* Mutex to protect the recorders from race conditions */
318 319
	int audio_fd;
319 320
	int video_fd;
320 321
	gint64 last_received_video;
......
1699 1700
				g_snprintf(error_cause, 512, "Missing audio and/or video");
1700 1701
				goto error;
1701 1702
			}
1703
			janus_mutex_lock(&source->rec_mutex);
1702 1704
			if(audio && json_is_true(audio) && source->arc) {
1703 1705
				/* Close the audio recording */
1704 1706
				janus_recorder_close(source->arc);
......
1715 1717
				source->vrc = NULL;
1716 1718
				janus_recorder_free(tmp);
1717 1719
			}
1720
			janus_mutex_unlock(&source->rec_mutex);
1718 1721
			janus_mutex_unlock(&mountpoints_mutex);
1719 1722
			/* Send a success response back */
1720 1723
			response = json_object();
......
1757 1760
			mp->enabled = FALSE;
1758 1761
			/* Any recording to close? */
1759 1762
			janus_streaming_rtp_source *source = mp->source;
1763
			janus_mutex_lock(&source->rec_mutex);
1760 1764
			if(source->arc) {
1761 1765
				janus_recorder_close(source->arc);
1762 1766
				JANUS_LOG(LOG_INFO, "[%s] Closed audio recording %s\n", mp->name, source->arc->filename ? source->arc->filename : "??");
......
1771 1775
				source->vrc = NULL;
1772 1776
				janus_recorder_free(tmp);
1773 1777
			}
1778
			janus_mutex_unlock(&source->rec_mutex);
1774 1779
			/* FIXME: Should we notify the listeners, or is this up to the controller application? */
1775 1780
		}
1776 1781
		janus_mutex_unlock(&mountpoints_mutex);
......
2483 2488
	live_rtp_source->video_port = dovideo ? vport : -1;
2484 2489
	live_rtp_source->arc = NULL;
2485 2490
	live_rtp_source->vrc = NULL;
2491
	janus_mutex_init(&live_rtp_source->rec_mutex);
2486 2492
	live_rtp_source->audio_fd = audio_fd;
2487 2493
	live_rtp_source->video_fd = video_fd;
2488 2494
	live_rtp_source->last_received_audio = janus_get_monotonic_time();
......
3280 3286
						//~ ntohl(rtp->ssrc), rtp->type, ntohs(rtp->seq_number), ntohl(rtp->timestamp));
3281 3287
					packet.data->type = mountpoint->codecs.audio_pt;
3282 3288
					/* Is there a recorder? */
3283
					if(source->arc) {
3284
						JANUS_LOG(LOG_HUGE, "[%s] Saving audio frame (%d bytes)\n", name, bytes);
3285
						janus_recorder_save_frame(source->arc, buffer, bytes);
3286
					}
3289
					janus_recorder_save_frame(source->arc, buffer, bytes);
3287 3290
					/* Backup the actual timestamp and sequence number set by the restreamer, in case switching is involved */
3288 3291
					packet.timestamp = ntohl(packet.data->timestamp);
3289 3292
					packet.seq_number = ntohs(packet.data->seq_number);
......
3383 3386
						//~ ntohl(rtp->ssrc), rtp->type, ntohs(rtp->seq_number), ntohl(rtp->timestamp));
3384 3387
					packet.data->type = mountpoint->codecs.video_pt;
3385 3388
					/* Is there a recorder? */
3386
					if(source->vrc) {
3387
						JANUS_LOG(LOG_HUGE, "[%s] Saving video frame (%d bytes)\n", name, bytes);
3388
						janus_recorder_save_frame(source->vrc, buffer, bytes);
3389
					}
3389
					janus_recorder_save_frame(source->vrc, buffer, bytes);
3390 3390
					/* Backup the actual timestamp and sequence number set by the restreamer, in case switching is involved */
3391 3391
					packet.timestamp = ntohl(packet.data->timestamp);
3392 3392
					packet.seq_number = ntohs(packet.data->seq_number);

Also available in: Unified diff