Revision 47576630 plugins/janus_videoroom.c

View differences:

plugins/janus_videoroom.c
568 568
		}
569 569
		const char *request_text = json_string_value(request);
570 570
		json_t *event = NULL;
571
		if(!strcasecmp(request_text, "create")) {
572
			/* Create a new videoroom */
573
			JANUS_PRINT("Creating a new videoroom\n");
574
			json_t *desc = json_object_get(root, "description");
575
			if(desc && !json_is_string(desc)) {
576
				JANUS_DEBUG("JSON error: invalid element (desc)\n");
577
				sprintf(error_cause, "JSON error: invalid element (desc)");
578
				goto error;
579
			}
580
			json_t *bitrate = json_object_get(root, "bitrate");
581
			if(bitrate && !json_is_integer(bitrate)) {
582
				JANUS_DEBUG("JSON error: invalid element (bitrate)\n");
583
				sprintf(error_cause, "JSON error: invalid element (bitrate)");
584
				goto error;
585
			}
586
			json_t *publishers = json_object_get(root, "publishers");
587
			if(publishers && !json_is_integer(publishers)) {
588
				JANUS_DEBUG("JSON error: invalid element (publishers)\n");
589
				sprintf(error_cause, "JSON error: invalid element (publishers)");
590
				goto error;
591
			}
592
			/* Create the audio bridge room */
593
			janus_videoroom *videoroom = calloc(1, sizeof(janus_videoroom));
594
			if(videoroom == NULL) {
595
				JANUS_DEBUG("Memory error!\n");
596
				sprintf(error_cause, "Memory error");
597
				goto error;
598
			}
599
			/* Generate a random ID */
600
			guint64 room_id = 0;
601
			while(room_id == 0) {
602
				room_id = g_random_int();
603
				if(g_hash_table_lookup(rooms, GUINT_TO_POINTER(room_id)) != NULL) {
604
					/* Room ID already taken, try another one */
605
					room_id = 0;
606
				}
607
			}
608
			videoroom->room_id = room_id;
609
			char *description = NULL;
610
			if(desc != NULL) {
611
				description = g_strdup(json_string_value(desc));
612
			} else {
613
				char roomname[255];
614
				sprintf(roomname, "Room %"SCNu64"", videoroom->room_id);
615
				description = g_strdup(roomname);
616
			}
617
			if(description == NULL) {
618
				JANUS_DEBUG("Memory error!\n");
619
				continue;
620
			}
621
			videoroom->room_name = description;
622
			videoroom->max_publishers = 3;	/* FIXME How should we choose a default? */
623
			if(publishers)
624
				videoroom->max_publishers = json_integer_value(publishers);
625
			if(videoroom->max_publishers < 0)
626
				videoroom->max_publishers = 3;	/* FIXME How should we choose a default? */
627
			videoroom->bitrate = 0;
628
			if(bitrate)
629
				videoroom->bitrate = json_integer_value(bitrate);
630
			videoroom->destroy = 0;
631
			videoroom->participants = g_hash_table_new(NULL, NULL);
632
			g_hash_table_insert(rooms, GUINT_TO_POINTER(videoroom->room_id), videoroom);
633
			JANUS_PRINT("Created videoroom: %"SCNu64" (%s)\n", videoroom->room_id, videoroom->room_name);
634
			/* Show updated rooms list */
635
			GList *rooms_list = g_hash_table_get_values(rooms);
636
			GList *r = rooms_list;
637
			while(r) {
638
				janus_videoroom *vr = (janus_videoroom *)r->data;
639
				JANUS_PRINT("  ::: [%"SCNu64"][%s] %"SCNu64", max %d publishers\n", vr->room_id, vr->room_name, vr->bitrate, vr->max_publishers);
640
				r = r->next;
641
			}
642
			g_list_free(rooms_list);
643
			/* Send info back */
644
			event = json_object();
645
			json_object_set(event, "videoroom", json_string("created"));
646
			json_object_set(event, "room", json_integer(videoroom->room_id));
647
		} else
571 648
		/* What kind of participant is this session referring to? */
572 649
		if(session->participant_type == janus_videoroom_p_type_none) {
573 650
			JANUS_PRINT("Configuring new participant\n");

Also available in: Unified diff