Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV RTSP: send proper teardown on close
  • Loading branch information
perexg committed May 4, 2015
1 parent 8fa4d2e commit eb6cdcb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/http.h
Expand Up @@ -323,6 +323,8 @@ struct http_client {

struct http_client_ssl *hc_ssl; /* ssl internals */

gtimer_t hc_close_timer;

/* callbacks */
int (*hc_hdr_received) (http_client_t *hc);
int (*hc_data_received)(http_client_t *hc, void *buf, size_t len);
Expand Down
1 change: 0 additions & 1 deletion src/idnode.c
Expand Up @@ -215,7 +215,6 @@ idnode_handler(size_t off, idnode_t *in, const char *action)
}
idc = idc->ic_super;
}

}

void
Expand Down
45 changes: 36 additions & 9 deletions src/input/mpegts/iptv/iptv_rtsp.c
Expand Up @@ -20,15 +20,25 @@
#include "tvheadend.h"
#include "iptv_private.h"
#include "http.h"
#include "udp.h"

typedef struct {
http_client_t *hc;
udp_multirecv_t um;
char *url;
char *path;
char *query;
gtimer_t alive_timer;
int play;
} rtsp_priv_t;

/*
*
*/
static void
iptv_rtsp_close_cb ( void *aux )
{
http_client_close((http_client_t *)aux);
}

/*
* Alive timeout
*/
Expand All @@ -49,22 +59,33 @@ static int
iptv_rtsp_header ( http_client_t *hc )
{
iptv_mux_t *im = hc->hc_aux;
rtsp_priv_t *rp = im->im_data;
rtsp_priv_t *rp;
int r;

if (im == NULL)
if (im == NULL) {
/* teardown (or teardown timeout) */
if (hc->hc_cmd == RTSP_CMD_TEARDOWN) {
pthread_mutex_lock(&global_lock);
gtimer_arm(&hc->hc_close_timer, iptv_rtsp_close_cb, hc, 0);
pthread_mutex_unlock(&global_lock);
}
return 0;
}

if (hc->hc_code != HTTP_STATUS_OK) {
tvherror("iptv", "invalid error code %d for '%s'", hc->hc_code, im->mm_iptv_url);
return 0;
}

rp = im->im_data;

switch (hc->hc_cmd) {
case RTSP_CMD_SETUP:
r = rtsp_setup_decode(hc, 0);
if (r >= 0)
rtsp_play(hc, rp->url, "");
if (r >= 0) {
rtsp_play(hc, rp->path, rp->query);
rp->play = 1;
}
break;
case RTSP_CMD_PLAY:
hc->hc_cmd = HTTP_CMD_NONE;
Expand Down Expand Up @@ -139,7 +160,8 @@ iptv_rtsp_start
rp = calloc(1, sizeof(*rp));
rp->hc = hc;
udp_multirecv_init(&rp->um, IPTV_PKTS, IPTV_PKT_PAYLOAD);
rp->url = strdup(u->raw);
rp->path = strdup(u->path ?: "");
rp->query = strdup(u->query ?: "");

im->im_data = rp;
im->mm_iptv_fd = rtp->fd;
Expand All @@ -158,18 +180,23 @@ iptv_rtsp_stop
( iptv_mux_t *im )
{
rtsp_priv_t *rp = im->im_data;
int play = rp->play;

lock_assert(&global_lock);

if (rp == NULL)
return;
im->im_data = NULL;
rp->hc->hc_aux = NULL;
if (play)
rtsp_teardown(rp->hc, rp->path, "");
pthread_mutex_unlock(&iptv_lock);
gtimer_disarm(&rp->alive_timer);
udp_multirecv_free(&rp->um);
http_client_close(rp->hc);
free(rp->url);
if (!play)
http_client_close(rp->hc);
free(rp->path);
free(rp->query);
free(rp);
pthread_mutex_lock(&iptv_lock);
}
Expand Down

0 comments on commit eb6cdcb

Please sign in to comment.