Initial RTSP cleanup for multithreading
This commit is contained in:
parent
5c5c3ab2e4
commit
00c95cc9a1
1 changed files with 55 additions and 54 deletions
109
rtsp.c
109
rtsp.c
|
@ -44,8 +44,6 @@
|
||||||
|
|
||||||
#include <libavutil/random.h>
|
#include <libavutil/random.h>
|
||||||
|
|
||||||
#include <libhts/htscfg.h>
|
|
||||||
|
|
||||||
#define RTSP_STATUS_OK 200
|
#define RTSP_STATUS_OK 200
|
||||||
#define RTSP_STATUS_UNAUTHORIZED 401
|
#define RTSP_STATUS_UNAUTHORIZED 401
|
||||||
#define RTSP_STATUS_METHOD 405
|
#define RTSP_STATUS_METHOD 405
|
||||||
|
@ -58,6 +56,8 @@
|
||||||
|
|
||||||
#define rcprintf(c, fmt...) tcp_printf(&(rc)->rc_tcp_session, fmt)
|
#define rcprintf(c, fmt...) tcp_printf(&(rc)->rc_tcp_session, fmt)
|
||||||
|
|
||||||
|
#define rtsp_printf(hc, fmt...) htsbuf_qprintf(&(hc)->hc_reply, fmt)
|
||||||
|
|
||||||
static AVRandomState rtsp_rnd;
|
static AVRandomState rtsp_rnd;
|
||||||
|
|
||||||
static struct rtsp_session_head rtsp_sessions;
|
static struct rtsp_session_head rtsp_sessions;
|
||||||
|
@ -254,15 +254,14 @@ rtsp_reply_error(http_connection_t *hc, int error, const char *errstr)
|
||||||
if(errstr == NULL)
|
if(errstr == NULL)
|
||||||
errstr = rtsp_err2str(error);
|
errstr = rtsp_err2str(error);
|
||||||
|
|
||||||
tvhlog(LOG_INFO, "rtsp",
|
tvhlog(LOG_INFO, "rtsp", "%s", errstr);
|
||||||
"%s: %s", tcp_logname(&hc->hc_tcp_session), errstr);
|
|
||||||
|
|
||||||
http_printf(hc, "RTSP/1.0 %d %s\r\n", error, errstr);
|
rtsp_printf(hc, "RTSP/1.0 %d %s\r\n", error, errstr);
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
if(error == HTTP_STATUS_UNAUTHORIZED)
|
if(error == HTTP_STATUS_UNAUTHORIZED)
|
||||||
http_printf(hc, "WWW-Authenticate: Basic realm=\"tvheadend\"\r\n");
|
rtsp_printf(hc, "WWW-Authenticate: Basic realm=\"tvheadend\"\r\n");
|
||||||
http_printf(hc, "\r\n");
|
rtsp_printf(hc, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,17 +331,17 @@ rtsp_cmd_play(http_connection_t *hc)
|
||||||
if(rs->rs_s->ths_channel != NULL)
|
if(rs->rs_s->ths_channel != NULL)
|
||||||
tvhlog(LOG_INFO, "rtsp",
|
tvhlog(LOG_INFO, "rtsp",
|
||||||
"%s: Starting playback of %s",
|
"%s: Starting playback of %s",
|
||||||
tcp_logname(&hc->hc_tcp_session), rs->rs_s->ths_channel->ch_name);
|
hc->hc_peername, rs->rs_s->ths_channel->ch_name);
|
||||||
|
|
||||||
http_printf(hc,
|
rtsp_printf(hc,
|
||||||
"RTSP/1.0 200 OK\r\n"
|
"RTSP/1.0 200 OK\r\n"
|
||||||
"Session: %u\r\n",
|
"Session: %u\r\n",
|
||||||
rs->rs_id);
|
rs->rs_id);
|
||||||
|
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
|
|
||||||
http_printf(hc, "\r\n");
|
rtsp_printf(hc, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -370,17 +369,17 @@ rtsp_cmd_pause(http_connection_t *hc)
|
||||||
if(rs->rs_s->ths_channel != NULL)
|
if(rs->rs_s->ths_channel != NULL)
|
||||||
tvhlog(LOG_INFO, "rtsp",
|
tvhlog(LOG_INFO, "rtsp",
|
||||||
"%s: Pausing playback of %s",
|
"%s: Pausing playback of %s",
|
||||||
tcp_logname(&hc->hc_tcp_session), rs->rs_s->ths_channel->ch_name);
|
hc->hc_peername, rs->rs_s->ths_channel->ch_name);
|
||||||
|
|
||||||
http_printf(hc,
|
rtsp_printf(hc,
|
||||||
"RTSP/1.0 200 OK\r\n"
|
"RTSP/1.0 200 OK\r\n"
|
||||||
"Session: %u\r\n",
|
"Session: %u\r\n",
|
||||||
rs->rs_id);
|
rs->rs_id);
|
||||||
|
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
|
|
||||||
http_printf(hc, "\r\n");
|
rtsp_printf(hc, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -454,7 +453,7 @@ rtsp_cmd_setup(http_connection_t *hc)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&dst, &hc->hc_tcp_session.tcp_peer_addr, sizeof(struct sockaddr_in));
|
memcpy(&dst, hc->hc_peer, sizeof(struct sockaddr_in));
|
||||||
dst.sin_port = htons(client_ports[0]);
|
dst.sin_port = htons(client_ports[0]);
|
||||||
|
|
||||||
if((rs = rtsp_session_create(ch, &dst)) == NULL) {
|
if((rs = rtsp_session_create(ch, &dst)) == NULL) {
|
||||||
|
@ -464,7 +463,7 @@ rtsp_cmd_setup(http_connection_t *hc)
|
||||||
|
|
||||||
LIST_INSERT_HEAD(&hc->hc_rtsp_sessions, rs, rs_con_link);
|
LIST_INSERT_HEAD(&hc->hc_rtsp_sessions, rs, rs_con_link);
|
||||||
|
|
||||||
http_printf(hc,
|
rtsp_printf(hc,
|
||||||
"RTSP/1.0 200 OK\r\n"
|
"RTSP/1.0 200 OK\r\n"
|
||||||
"Session: %u\r\n"
|
"Session: %u\r\n"
|
||||||
"Transport: RTP/AVP/UDP;unicast;client_port=%d-%d;"
|
"Transport: RTP/AVP/UDP;unicast;client_port=%d-%d;"
|
||||||
|
@ -476,9 +475,9 @@ rtsp_cmd_setup(http_connection_t *hc)
|
||||||
rs->rs_server_port[1]);
|
rs->rs_server_port[1]);
|
||||||
|
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
|
|
||||||
http_printf(hc, "\r\n");
|
rtsp_printf(hc, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -508,16 +507,16 @@ rtsp_cmd_describe(http_connection_t *hc)
|
||||||
ch->ch_name);
|
ch->ch_name);
|
||||||
|
|
||||||
|
|
||||||
http_printf(hc,
|
rtsp_printf(hc,
|
||||||
"RTSP/1.0 200 OK\r\n"
|
"RTSP/1.0 200 OK\r\n"
|
||||||
"Content-Type: application/sdp\r\n"
|
"Content-Type: application/sdp\r\n"
|
||||||
"Content-Length: %d\r\n",
|
"Content-Length: %d\r\n",
|
||||||
strlen(sdpreply));
|
strlen(sdpreply));
|
||||||
|
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
|
|
||||||
http_printf(hc, "\r\n%s", sdpreply);
|
rtsp_printf(hc, "\r\n%s", sdpreply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -534,13 +533,13 @@ rtsp_cmd_options(http_connection_t *hc)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
http_printf(hc,
|
rtsp_printf(hc,
|
||||||
"RTSP/1.0 200 OK\r\n"
|
"RTSP/1.0 200 OK\r\n"
|
||||||
"Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE\r\n");
|
"Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE\r\n");
|
||||||
|
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
http_printf(hc, "\r\n");
|
rtsp_printf(hc, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -555,15 +554,15 @@ rtsp_cmd_teardown(http_connection_t *hc)
|
||||||
if((rs = rtsp_get_session(hc)) == NULL)
|
if((rs = rtsp_get_session(hc)) == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
http_printf(hc,
|
rtsp_printf(hc,
|
||||||
"RTSP/1.0 200 OK\r\n"
|
"RTSP/1.0 200 OK\r\n"
|
||||||
"Session: %u\r\n",
|
"Session: %u\r\n",
|
||||||
rs->rs_id);
|
rs->rs_id);
|
||||||
|
|
||||||
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
if((c = http_arg_get(&hc->hc_args, "cseq")) != NULL)
|
||||||
http_printf(hc, "CSeq: %s\r\n", c);
|
rtsp_printf(hc, "CSeq: %s\r\n", c);
|
||||||
|
|
||||||
http_printf(hc, "\r\n");
|
rtsp_printf(hc, "\r\n");
|
||||||
|
|
||||||
rtsp_session_destroy(rs);
|
rtsp_session_destroy(rs);
|
||||||
}
|
}
|
||||||
|
@ -580,7 +579,7 @@ rtsp_access_list(http_connection_t *hc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
x = access_verify(hc->hc_username, hc->hc_password,
|
x = access_verify(hc->hc_username, hc->hc_password,
|
||||||
(struct sockaddr *)&hc->hc_tcp_session.tcp_peer_addr,
|
(struct sockaddr *)hc->hc_peer,
|
||||||
ACCESS_STREAMING);
|
ACCESS_STREAMING);
|
||||||
if(x == 0)
|
if(x == 0)
|
||||||
hc->hc_authenticated = 1;
|
hc->hc_authenticated = 1;
|
||||||
|
@ -598,32 +597,34 @@ rtsp_process_request(http_connection_t *hc)
|
||||||
{
|
{
|
||||||
if(rtsp_access_list(hc)) {
|
if(rtsp_access_list(hc)) {
|
||||||
rtsp_reply_error(hc, RTSP_STATUS_UNAUTHORIZED, NULL);
|
rtsp_reply_error(hc, RTSP_STATUS_UNAUTHORIZED, NULL);
|
||||||
return 0;
|
} else {
|
||||||
|
switch(hc->hc_cmd) {
|
||||||
|
default:
|
||||||
|
rtsp_reply_error(hc, RTSP_STATUS_METHOD, NULL);
|
||||||
|
break;
|
||||||
|
case RTSP_CMD_DESCRIBE:
|
||||||
|
rtsp_cmd_describe(hc);
|
||||||
|
break;
|
||||||
|
case RTSP_CMD_SETUP:
|
||||||
|
rtsp_cmd_setup(hc);
|
||||||
|
break;
|
||||||
|
case RTSP_CMD_PLAY:
|
||||||
|
rtsp_cmd_play(hc);
|
||||||
|
break;
|
||||||
|
case RTSP_CMD_PAUSE:
|
||||||
|
rtsp_cmd_pause(hc);
|
||||||
|
break;
|
||||||
|
case RTSP_CMD_OPTIONS:
|
||||||
|
rtsp_cmd_options(hc);
|
||||||
|
break;
|
||||||
|
case RTSP_CMD_TEARDOWN:
|
||||||
|
rtsp_cmd_teardown(hc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(hc->hc_cmd) {
|
tcp_write_queue(hc->hc_fd, &hc->hc_reply);
|
||||||
default:
|
|
||||||
rtsp_reply_error(hc, RTSP_STATUS_METHOD, NULL);
|
|
||||||
break;
|
|
||||||
case RTSP_CMD_DESCRIBE:
|
|
||||||
rtsp_cmd_describe(hc);
|
|
||||||
break;
|
|
||||||
case RTSP_CMD_SETUP:
|
|
||||||
rtsp_cmd_setup(hc);
|
|
||||||
break;
|
|
||||||
case RTSP_CMD_PLAY:
|
|
||||||
rtsp_cmd_play(hc);
|
|
||||||
break;
|
|
||||||
case RTSP_CMD_PAUSE:
|
|
||||||
rtsp_cmd_pause(hc);
|
|
||||||
break;
|
|
||||||
case RTSP_CMD_OPTIONS:
|
|
||||||
rtsp_cmd_options(hc);
|
|
||||||
break;
|
|
||||||
case RTSP_CMD_TEARDOWN:
|
|
||||||
rtsp_cmd_teardown(hc);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue