Revision bd0e3260

View differences:

conf/janus.plugin.videoroom.cfg.sample
10 10
; audiocodec = opus|isac32|isac16|pcmu|pcma (audio codec to force on publishers, default=opus)
11 11
; videocodec = vp8|vp9|h264 (video codec to force on publishers, default=vp8)
12 12
; audiolevel_ext = yes|no (whether the ssrc-audio-level RTP extension must
13
; audiolevel_event = yes|no (whether to emit event to other users or not, default=no)
14
; audio_active_packets = 100 (number of packets with audio level, default=100, 2 seconds)
15
; audio_level_average = 25 (average value of audio level, 127=muted, 0='too loud', default=25)
13 16
;		be negotiated/used or not for new publishers, default=yes)
14 17
; videoorient_ext = yes|no (whether the video-orientation RTP extension must
15 18
;		be negotiated/used or not for new publishers, default=yes)
plugins/janus_videoroom.c
66 66
videocodec = vp8|vp9|h264 (video codec to force on publishers, default=vp8)
67 67
audiolevel_ext = yes|no (whether the ssrc-audio-level RTP extension must be
68 68
	negotiated/used or not for new publishers, default=yes)
69
audiolevel_event = yes|no (whether to emit event to other users or not)
70
audio_active_packets = 100 (number of packets with audio level, default=100, 2 seconds)
71
audio_level_average = 25 (average value of audio level, 127=muted, 0='too loud', default=25)
69 72
videoorientation_ext = yes|no (whether the video-orientation RTP extension must be
70 73
	negotiated/used or not for new publishers, default=yes)
71 74
playoutdelay_ext = yes|no (whether the playout-delay RTP extension must be
......
224 227
	{"audiocodec", JSON_STRING, 0},
225 228
	{"videocodec", JSON_STRING, 0},
226 229
	{"audiolevel_ext", JANUS_JSON_BOOL, 0},
230
	{"audiolevel_event", JANUS_JSON_BOOL, 0},
231
	{"audio_active_packets", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
232
	{"audio_level_average", JSON_INTEGER, JANUS_JSON_PARAM_POSITIVE},
227 233
	{"videoorient_ext", JANUS_JSON_BOOL, 0},
228 234
	{"playoutdelay_ext", JANUS_JSON_BOOL, 0},
229 235
	{"record", JANUS_JSON_BOOL, 0},
......
451 457
	janus_videoroom_audiocodec acodec;	/* Audio codec to force on publishers*/
452 458
	janus_videoroom_videocodec vcodec;	/* Video codec to force on publishers*/
453 459
	gboolean audiolevel_ext;	/* Whether the ssrc-audio-level extension must be negotiated or not for new publishers */
460
	gboolean audiolevel_event;	/* Whether to emit event to other users about audiolevel */
461
	int audio_active_packets;	/* amount of packets with audio level for checkup */
462
	int audio_level_average;	/* average audio level */
454 463
	gboolean videoorient_ext;	/* Whether the video-orientation extension must be negotiated or not for new publishers */
455 464
	gboolean playoutdelay_ext;	/* Whether the playout-delay extension must be negotiated or not for new publishers */
456 465
	gboolean record;			/* Whether the feeds from publishers in this room should be recorded */
......
507 516
	guint8 playout_delay_extmap_id;	/* Playout delay extmap ID */
508 517
	gboolean audio_active;
509 518
	gboolean video_active;
510
	int audio_active_packets; /* number of packets received with audio_levl extmap sdp header */
511
	int audio_dBov_sum;
519
	int audio_active_packets; /* participants number of audio packets to aqumulate*/
520
	int audio_dBov_sum;	/* participants aqumulated dBov value for audio level*/
512 521
	gboolean data_active;
513 522
	gboolean firefox;	/* We send Firefox users a different kind of FIR */
514 523
	uint64_t bitrate;
......
767 776
			janus_config_item *audiocodec = janus_config_get_item(cat, "audiocodec");
768 777
			janus_config_item *videocodec = janus_config_get_item(cat, "videocodec");
769 778
			janus_config_item *audiolevel_ext = janus_config_get_item(cat, "audiolevel_ext");
779
			janus_config_item *audiolevel_event = janus_config_get_item(cat, "audiolevel_event");
780
			janus_config_item *audio_active_packets = janus_config_get_item(cat, "audio_active_packets");
781
			janus_config_item *audio_level_average = janus_config_get_item(cat, "audio_level_average");
770 782
			janus_config_item *videoorient_ext = janus_config_get_item(cat, "videoorient_ext");
771 783
			janus_config_item *playoutdelay_ext = janus_config_get_item(cat, "playoutdelay_ext");
772 784
			janus_config_item *record = janus_config_get_item(cat, "record");
......
835 847
			videoroom->audiolevel_ext = TRUE;
836 848
			if(audiolevel_ext != NULL && audiolevel_ext->value != NULL)
837 849
				videoroom->audiolevel_ext = janus_is_true(audiolevel_ext->value);
850
			videoroom->audiolevel_event = FALSE;
851
			if(audiolevel_event != NULL && audiolevel_event->value != NULL)
852
				videoroom->audiolevel_event = janus_is_true(audiolevel_event->value);
853
			videoroom->audio_active_packets = 100;
854
			if(audio_active_packets != NULL && audio_active_packets->value != NULL)
855
				videoroom->audio_active_packets = janus_is_true(audio_active_packets->value);
856
			videoroom->audio_level_average = 25;
857
			if(audio_level_average != NULL && audio_level_average->value != NULL)
858
				videoroom->audio_level_average = janus_is_true(audio_level_average->value);
838 859
			videoroom->videoorient_ext = TRUE;
839 860
			if(videoorient_ext != NULL && videoorient_ext->value != NULL)
840 861
				videoroom->videoorient_ext = janus_is_true(videoorient_ext->value);
......
1278 1299
			}
1279 1300
		}
1280 1301
		json_t *audiolevel_ext = json_object_get(root, "audiolevel_ext");
1302
		json_t *audiolevel_event = json_object_get(root, "audiolevel_event");
1303
		json_t *audio_active_packets = json_object_get(root, "audio_active_packets");
1304
		json_t *audio_level_average = json_object_get(root, "audio_level_average");
1281 1305
		json_t *videoorient_ext = json_object_get(root, "videoorient_ext");
1282 1306
		json_t *playoutdelay_ext = json_object_get(root, "playoutdelay_ext");
1283 1307
		json_t *record = json_object_get(root, "record");
......
1405 1429
			}
1406 1430
		}
1407 1431
		videoroom->audiolevel_ext = audiolevel_ext ? json_is_true(audiolevel_ext) : TRUE;
1432
		videoroom->audiolevel_event = audiolevel_event ? json_is_true(audiolevel_event) : FALSE;
1433
		videoroom->audio_active_packets = audio_active_packets ? json_integer_value(audio_active_packets) : 100;
1434
		videoroom->audio_level_average = audio_level_average ? json_integer_value(audio_level_average) : 25;
1408 1435
		videoroom->videoorient_ext = videoorient_ext ? json_is_true(videoorient_ext) : TRUE;
1409 1436
		videoroom->playoutdelay_ext = playoutdelay_ext ? json_is_true(playoutdelay_ext) : TRUE;
1410 1437
		if(record) {
......
1701 1728
		if(video_handle > 0) {
1702 1729
			/* Send a FIR to the new RTP forward publisher */
1703 1730
			char buf[20];
1704
			memset(buf, 0, 20);
1705 1731
			janus_rtcp_fir((char *)&buf, 20, &publisher->fir_seq);
1706 1732
			JANUS_LOG(LOG_VERB, "New RTP forward publisher, sending FIR to %"SCNu64" (%s)\n", publisher->user_id, publisher->display ? publisher->display : "??");
1707 1733
			gateway->relay_rtcp(publisher->session->handle, 1, buf, 20);
1708 1734
			/* Send a PLI too, just in case... */
1709
			memset(buf, 0, 12);
1710 1735
			janus_rtcp_pli((char *)&buf, 12);
1711 1736
			JANUS_LOG(LOG_VERB, "New RTP forward publisher, sending PLI to %"SCNu64" (%s)\n", publisher->user_id, publisher->display ? publisher->display : "??");
1712 1737
			gateway->relay_rtcp(publisher->session->handle, 1, buf, 12);
......
2169 2194
				if(p && p->session) {
2170 2195
					/* Send a FIR */
2171 2196
					char buf[20];
2172
					memset(buf, 0, 20);
2173 2197
					janus_rtcp_fir((char *)&buf, 20, &p->fir_seq);
2174 2198
					JANUS_LOG(LOG_VERB, "New listener available, sending FIR to %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
2175 2199
					gateway->relay_rtcp(p->session->handle, 1, buf, 20);
2176 2200
					/* Send a PLI too, just in case... */
2177
					memset(buf, 0, 12);
2178 2201
					janus_rtcp_pli((char *)&buf, 12);
2179 2202
					JANUS_LOG(LOG_VERB, "New listener available, sending PLI to %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
2180 2203
					gateway->relay_rtcp(p->session->handle, 1, buf, 12);
......
2199 2222
	if(!session || session->destroyed || !session->participant || session->participant_type != janus_videoroom_p_type_publisher)
2200 2223
		return;
2201 2224
	janus_videoroom_participant *participant = (janus_videoroom_participant *)session->participant;
2202
	if(participant->audio_active) {
2225
	janus_videoroom *videoroom = participant->room;
2226

  
2227
	if(videoroom->audiolevel_event) {
2203 2228
		int level = 0;
2204 2229
		if(janus_rtp_header_extension_parse_audio_level(buf, len, participant->audio_level_extmap_id, &level) == 0) {
2205 2230
			/* JANUS_LOG(LOG_INFO, "Audio level is %d\n", level); */
2206 2231
			participant->audio_dBov_sum = participant->audio_dBov_sum + level;
2207 2232
			participant->audio_active_packets = participant->audio_active_packets + 1;
2208 2233
			/* 2 seconds of talking (100 packets) with average of ~25 dBow */
2209
			if(participant->audio_active_packets == 100) {
2210
				if(participant->audio_dBov_sum < 2500) {
2234
			if(participant->audio_active_packets == videoroom->audio_active_packets) {
2235
				if((float)participant->audio_dBov_sum/(float)participant->audio_active_packets < videoroom->audio_level_average) {
2211 2236
					// Notify participants
2212 2237
					json_t *event = json_object();
2213 2238
					json_object_set_new(event, "event", json_string("talking"));
2214 2239
					json_object_set_new(event, "user", json_string(participant->display));
2215 2240
					janus_videoroom_notify_participants(participant, event);
2216 2241
					json_decref(event);
2217
					JANUS_LOG(LOG_ERR, "AVG audio_level %f\n", (float)participant->audio_dBov_sum/(float)participant->audio_active_packets);
2242
					/* JANUS_LOG(LOG_ERR, "AVG audio_level %f\n", (float)participant->audio_dBov_sum/(float)participant->audio_active_packets); */
2218 2243
					/* Also notify event handlers */
2219 2244
					if(notify_events && gateway->events_is_enabled()) {
2220 2245
						json_t *info = json_object();
......
2305 2330
					/* FIXME We send a FIR every tot seconds */
2306 2331
					participant->fir_latest = now;
2307 2332
					char rtcpbuf[24];
2308
					memset(rtcpbuf, 0, 24);
2309 2333
					janus_rtcp_fir((char *)&rtcpbuf, 20, &participant->fir_seq);
2310 2334
					JANUS_LOG(LOG_VERB, "Sending FIR to %"SCNu64" (%s)\n", participant->user_id, participant->display ? participant->display : "??");
2311 2335
					gateway->relay_rtcp(handle, video, rtcpbuf, 20);
2312 2336
					/* Send a PLI too, just in case... */
2313
					memset(rtcpbuf, 0, 12);
2314 2337
					janus_rtcp_pli((char *)&rtcpbuf, 12);
2315 2338
					JANUS_LOG(LOG_VERB, "Sending PLI to %"SCNu64" (%s)\n", participant->user_id, participant->display ? participant->display : "??");
2316 2339
					gateway->relay_rtcp(handle, video, rtcpbuf, 12);
......
2341 2364
				janus_videoroom_participant *p = l->feed;
2342 2365
				if(p && p->session) {
2343 2366
					char rtcpbuf[20];
2344
					memset(rtcpbuf, 0, 20);
2345 2367
					janus_rtcp_fir((char *)&rtcpbuf, 20, &p->fir_seq);
2346 2368
					JANUS_LOG(LOG_VERB, "Got a FIR from a listener, forwarding it to %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
2347 2369
					gateway->relay_rtcp(p->session->handle, 1, rtcpbuf, 20);
......
2354 2376
				janus_videoroom_participant *p = l->feed;
2355 2377
				if(p && p->session) {
2356 2378
					char rtcpbuf[12];
2357
					memset(rtcpbuf, 0, 12);
2358 2379
					janus_rtcp_pli((char *)&rtcpbuf, 12);
2359 2380
					JANUS_LOG(LOG_VERB, "Got a PLI from a listener, forwarding it to %"SCNu64" (%s)\n", p->user_id, p->display ? p->display : "??");
2360 2381
					gateway->relay_rtcp(p->session->handle, 1, rtcpbuf, 12);
......
3088 3109
								participant->user_id, participant->display ? participant->display : "??");
3089 3110
							gateway->relay_rtcp(participant->session->handle, 1, buf, 20);
3090 3111
							/* Send a PLI too, just in case... */
3091
							memset(buf, 0, 12);
3092 3112
							janus_rtcp_pli((char *)&buf, 12);
3093 3113
							JANUS_LOG(LOG_VERB, "Recording video, sending PLI to %"SCNu64" (%s)\n",
3094 3114
								participant->user_id, participant->display ? participant->display : "??");
......
3200 3220
				if(publisher) {
3201 3221
					/* Send a FIR */
3202 3222
					char buf[20];
3203
					memset(buf, 0, 20);
3204 3223
					janus_rtcp_fir((char *)&buf, 20, &publisher->fir_seq);
3205 3224
					JANUS_LOG(LOG_VERB, "Resuming publisher, sending FIR to %"SCNu64" (%s)\n", publisher->user_id, publisher->display ? publisher->display : "??");
3206 3225
					gateway->relay_rtcp(publisher->session->handle, 1, buf, 20);
3207 3226
					/* Send a PLI too, just in case... */
3208
					memset(buf, 0, 12);
3209 3227
					janus_rtcp_pli((char *)&buf, 12);
3210 3228
					JANUS_LOG(LOG_VERB, "Resuming publisher, sending PLI to %"SCNu64" (%s)\n", publisher->user_id, publisher->display ? publisher->display : "??");
3211 3229
					gateway->relay_rtcp(publisher->session->handle, 1, buf, 12);
......
3299 3317
				listener->feed = publisher;
3300 3318
				/* Send a FIR to the new publisher */
3301 3319
				char buf[20];
3302
				memset(buf, 0, 20);
3303 3320
				janus_rtcp_fir((char *)&buf, 20, &publisher->fir_seq);
3304 3321
				JANUS_LOG(LOG_VERB, "Switching existing listener to new publisher, sending FIR to %"SCNu64" (%s)\n", publisher->user_id, publisher->display ? publisher->display : "??");
3305 3322
				gateway->relay_rtcp(publisher->session->handle, 1, buf, 20);
3306 3323
				/* Send a PLI too, just in case... */
3307
				memset(buf, 0, 12);
3308 3324
				janus_rtcp_pli((char *)&buf, 12);
3309 3325
				JANUS_LOG(LOG_VERB, "Switching existing listener to new publisher, sending PLI to %"SCNu64" (%s)\n", publisher->user_id, publisher->display ? publisher->display : "??");
3310 3326
				gateway->relay_rtcp(publisher->session->handle, 1, buf, 12);

Also available in: Unified diff