Revision c81c126e src/path_handlers.c

View differences:

src/path_handlers.c
26 26
#include<pschannel.h>
27 27
#include<context.h>
28 28
#include<mongoose.h>
29
#include<sdpfile.h>
29
#include<streamer_creation_callback.h>
30 30

  
31 31
void mg_connection_remote_ip(char * ip, const struct mg_connection *nc)
32 32
{
......
71 71
	free(channels);
72 72
}
73 73

  
74
int8_t streamer_creation_handler(struct mg_connection *nc, const struct pstreamer * ps, int8_t ret)
75
{
76
	char * json = NULL;
77
	int8_t res = -1;
78

  
79
	info("Inside creation handler\n");
80
	if (ps)
81
		json = pstreamer_to_json(ps);
82

  
83
	if (ret == 0 && json)
84
	{
85
		mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
86
		mg_printf_http_chunk(nc, json);
87
		res = 0;
88
		info("Stream created and served\n");
89
	} else {
90
		mg_printf(nc, "%s", "HTTP/1.1 500 Internal server error\r\nTransfer-Encoding: chunked\r\n\r\n");
91
		// destroy ps?
92
		info("Stream cannot be correctly served\n");
93
		if (ret)
94
			debug(json);
95
		else
96
			debug("PS does not exist");
97
	}
98
	if (json)
99
		free(json);
100
	mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */
101

  
102
	return res;
103
}
104

  
74 105
void streamer_create(struct mg_connection *nc, struct http_message *hm)
75 106
{
76 107
	const struct context * c;
77 108
	char ipaddr[MAX_IPADDR_LENGTH];
78 109
	char rtp_dst_ip[MAX_IPADDR_LENGTH];
79 110
	char port[MAX_PORT_LENGTH];
80
	char * id, *sdpuri;
81
	const struct pstreamer * ps;
82
	const struct pschannel * ch;
111
	char * id;
112
	const struct pstreamer * ps = NULL;
113
	const struct pschannel * ch = NULL;
83 114

  
84 115
	c = (const struct context *) nc->user_data;
85 116
	mg_get_http_var(&hm->body, "ipaddr", ipaddr, MAX_IPADDR_LENGTH);
......
94 125
	if (ch)
95 126
	{
96 127
		debug("Channel: %s\n", ch->name);
97
		ps = pstreamer_manager_create_streamer(c->psm, ipaddr, port, id, rtp_dst_ip); 
128
		ps = pstreamer_manager_create_streamer(c->psm, ipaddr, port, id, rtp_dst_ip, streamer_creation_callback_new(nc, streamer_creation_handler)); 
98 129
		if(ps)
99 130
		{
100 131
			pstreamer_schedule_tasks((struct pstreamer*)ps, c->tm);
101 132
			info("Streamer instance created\n");
102
			sdpuri = sdpfile_create(c, ch, ps, rtp_dst_ip);
103
			if (sdpuri)
104
			{
105
				mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
106
				mg_printf_http_chunk(nc, "{\"id\":\"%s\",\"name\":\"%s\",\"sdpfile\":\"%s\"}", id, ch->name, sdpuri);
107
				mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */
108
				free(sdpuri);
109
				info("SDPfile served\n");
110
			} else {
111
				info("SDPfile not available\n");
112
				mg_printf(nc, "%s", "HTTP/1.1 422 Unprocessable Entity\r\nTransfer-Encoding: chunked\r\n\r\n");
113
				mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */
114
			}
115 133
		} else {
116 134
			info("Streamer could not be launched\n");
117 135
			mg_printf(nc, "%s", "HTTP/1.1 409 Conflict\r\nTransfer-Encoding: chunked\r\n\r\n");

Also available in: Unified diff