Revision c81c126e src/pstreamer.c

View differences:

src/pstreamer.c
42 42
	struct periodic_task * msg_task;
43 43
	struct task_manager * tm;
44 44
	timeout topology_interval;
45
	uint64_t janus_streaming_id;
45 46
};
46 47

  
47 48
struct pstreamer_manager {
48 49
	struct ord_set * streamers;
49 50
	uint16_t initial_streaming_port;
50 51
	char * streamer_opts;
52
	struct janus_instance const * janus;
51 53
};
52 54

  
53 55
int8_t pstreamer_init(struct pstreamer * ps, const char * rtp_dst_ip, const char * opts)
......
67 69
	ps->msg_task = NULL;
68 70
	ps->tm = NULL;
69 71
	ps->topology_interval = 400;
72
	ps->janus_streaming_id = 0;
70 73

  
71 74
	if (ps->psc)
72 75
		return 0;
......
104 107

  
105 108
char * pstreamer_to_json(const struct pstreamer * ps)
106 109
{
107
	char fmt[] = "{\"id\":\"%s\",\"source_ip\":\"%s\",\"source_port\":\"%d\"}";
110
	char fmt[] = "{\"id\":\"%s\",\"source_ip\":\"%s\",\"source_port\":\"%d\",\"janus_streaming_id\":\"%"PRId64"\"}";
108 111
	size_t reslength;
109 112
	char * res = NULL;
110 113

  
......
112 115
	{
113 116
		reslength = strlen(fmt) - 2*3 + PSID_LENGTH + MAX_IPADDR_LENGTH + MAX_PORT_LENGTH + 1;
114 117
		res = malloc(reslength * sizeof(char));
115
		sprintf(res, fmt, ps->id, ps->source_ip, ps->source_port);
118
		sprintf(res, fmt, ps->id, ps->source_ip, ps->source_port, ps->janus_streaming_id);
116 119
	}
117 120
	return res;
118 121
}
119 122

  
120
struct pstreamer_manager * pstreamer_manager_new(uint16_t starting_port)
123
struct pstreamer_manager * pstreamer_manager_new(uint16_t starting_port, const struct janus_instance *janus)
121 124
{
122 125
	struct pstreamer_manager * psm = NULL;
123 126

  
......
127 130
	 * (as the first one is the pstreamer port). So starting_port must be an odd number */
128 131
	psm->initial_streaming_port = (starting_port % 2 == 1) ? starting_port : starting_port + 1;
129 132
	psm->streamer_opts = NULL;
133
	psm->janus = janus;
130 134

  
131 135
	return psm;
132 136
}
......
162 166
	if (psm && *psm)
163 167
	{
164 168
		ord_set_for_each(ps, (*psm)->streamers)
169
		{
170
			if ((*psm)->janus)
171
				janus_instance_destroy_streaming_point((*psm)->janus, ((struct pstreamer*)ps)->janus_streaming_id);
165 172
			pstreamer_deinit((struct pstreamer *)ps);
173
		}
166 174

  
167 175
		ord_set_destroy(&((*psm)->streamers), 1);
168 176
		if((*psm)->streamer_opts)
......
230 238
	return (const struct pstreamer*) ptr;
231 239
}
232 240

  
233
const struct pstreamer * pstreamer_manager_create_streamer(struct pstreamer_manager * psm, const char * source_ip, const char * source_port, const char * id, const char * rtp_dst_ip)
241
const struct pstreamer * pstreamer_manager_create_streamer(struct pstreamer_manager * psm, const char * source_ip, const char * source_port, const char * id, const char * rtp_dst_ip, struct streamer_creation_callback * scc)
234 242
{
235 243
	struct pstreamer * ps = NULL;
236 244
	const void * ptr = NULL;
......
246 254
		if (ptr == NULL)
247 255
		{
248 256
			pstreamer_touch(ps);
257
			streamer_creation_set_pstreamer_ref(scc, ps);
258
			if (psm->janus)
259
			{
260
				debug("calling janus upon notification of perstreamer creation\n");
261
				janus_instance_create_streaming_point(psm->janus, &(ps->janus_streaming_id), ps->base_port+1, ps->base_port+3, scc);
262
			}
263
			else
264
				if (scc)
265
					streamer_creation_callback_trigger(scc, 0);
249 266
			pstreamer_init(ps, rtp_dst_ip, psm->streamer_opts);
250 267
			ord_set_insert(psm->streamers, ps, 0);
251 268
		} else
......
264 281

  
265 282
	if (psm && ps)
266 283
	{
284
		if(psm->janus)
285
			janus_instance_destroy_streaming_point(psm->janus, ps->janus_streaming_id);
267 286
		pstreamer_deinit((struct pstreamer *)ps);
268 287
		res = ord_set_remove(psm->streamers, ps, 1);
269 288
	}

Also available in: Unified diff