Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV: http - convert to http_priv_t
  • Loading branch information
perexg committed Nov 18, 2015
1 parent d912ecd commit fe571eb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
69 changes: 46 additions & 23 deletions src/input/mpegts/iptv/iptv_http.c
Expand Up @@ -22,17 +22,27 @@
#include "http.h"
#include "misc/m3u.h"

typedef struct http_priv {
iptv_mux_t *im;
http_client_t *hc;
int m3u_header;
} http_priv_t;

/*
* Connected
*/
static int
iptv_http_header ( http_client_t *hc )
{
iptv_mux_t *im = hc->hc_aux;
http_priv_t *hp = hc->hc_aux;
iptv_mux_t *im;
char *argv[3], *s;
int n;

if (hc->hc_aux == NULL)
if (hp == NULL)
return 0;
im = hp->im;
if (im == NULL)
return 0;

/* multiple headers for redirections */
Expand All @@ -48,18 +58,18 @@ iptv_http_header ( http_client_t *hc )
strcasecmp(s, "application/x-mpegurl") == 0 ||
strcasecmp(s, "application/apple.vnd.mpegurl") == 0 ||
strcasecmp(s, "application/vnd.apple.mpegurl") == 0)) {
if (im->im_m3u_header > 10) {
im->im_m3u_header = 0;
if (hp->m3u_header > 10) {
hp->m3u_header = 0;
return 0;
}
im->im_m3u_header++;
hp->m3u_header++;
return 0;
}
}

im->im_m3u_header = 0;
hp->m3u_header = 0;
pthread_mutex_lock(&global_lock);
iptv_input_mux_started(hc->hc_aux);
iptv_input_mux_started(hp->im);
pthread_mutex_unlock(&global_lock);
return 0;
}
Expand All @@ -71,12 +81,15 @@ static int
iptv_http_data
( http_client_t *hc, void *buf, size_t len )
{
iptv_mux_t *im = hc->hc_aux;
http_priv_t *hp = hc->hc_aux;
iptv_mux_t *im;

if (im == NULL || hc->hc_code != HTTP_STATUS_OK)
if (hp == NULL || hp->im == NULL || hc->hc_code != HTTP_STATUS_OK)
return 0;

if (im->im_m3u_header) {
im = hp->im;

if (hp->m3u_header) {
sbuf_append(&im->mm_iptv_buffer, buf, len);
return 0;
}
Expand All @@ -102,7 +115,8 @@ static int
iptv_http_complete
( http_client_t *hc )
{
iptv_mux_t *im = hc->hc_aux;
http_priv_t *hp = hc->hc_aux;
iptv_mux_t *im = hp->im;
const char *url, *host_url;
char *p;
htsmsg_t *m, *items, *item;
Expand All @@ -111,8 +125,8 @@ iptv_http_complete
size_t l;
int r;

if (im->im_m3u_header) {
im->im_m3u_header = 0;
if (hp->m3u_header) {
hp->m3u_header = 0;

sbuf_append(&im->mm_iptv_buffer, "", 1);

Expand Down Expand Up @@ -176,10 +190,10 @@ static void
iptv_http_create_header
( http_client_t *hc, http_arg_list_t *h, const url_t *url, int keepalive )
{
iptv_mux_t *im = hc->hc_aux;
http_priv_t *hp = hc->hc_aux;

http_client_basic_args(hc, h, url, keepalive);
http_client_add_args(hc, h, im->mm_iptv_hdr);
http_client_add_args(hc, h, hp->im->mm_iptv_hdr);
}

/*
Expand All @@ -189,12 +203,17 @@ static int
iptv_http_start
( iptv_mux_t *im, const char *raw, const url_t *u )
{
http_priv_t *hp;
http_client_t *hc;
int r;

if (!(hc = http_client_connect(im, HTTP_VERSION_1_1, u->scheme,
u->host, u->port, NULL)))
hp = calloc(1, sizeof(*hp));
hp->im = im;
if (!(hc = http_client_connect(hp, HTTP_VERSION_1_1, u->scheme,
u->host, u->port, NULL))) {
free(hp);
return SM_CODE_TUNING_FAILED;
}
hc->hc_hdr_create = iptv_http_create_header;
hc->hc_hdr_received = iptv_http_header;
hc->hc_data_received = iptv_http_data;
Expand All @@ -205,9 +224,11 @@ iptv_http_start
r = http_client_simple(hc, u);
if (r < 0) {
http_client_close(hc);
free(hp);
return SM_CODE_TUNING_FAILED;
}
im->im_data = hc;
hp->hc = hc;
im->im_data = hp;
sbuf_init_fixed(&im->mm_iptv_buffer, IPTV_BUF_SIZE);

return 0;
Expand All @@ -220,12 +241,14 @@ static void
iptv_http_stop
( iptv_mux_t *im )
{
http_client_t *hc = im->im_data;
http_priv_t *hp = im->im_data;

hc->hc_aux = NULL;
hp->hc->hc_aux = NULL;
pthread_mutex_unlock(&iptv_lock);
http_client_close(hc);
http_client_close(hp->hc);
pthread_mutex_lock(&iptv_lock);
im->im_data = NULL;
free(hp);
}


Expand All @@ -236,10 +259,10 @@ static void
iptv_http_pause
( iptv_mux_t *im, int pause )
{
http_client_t *hc = im->im_data;
http_priv_t *hp = im->im_data;

assert(pause == 0);
http_client_unpause(hc);
http_client_unpause(hp->hc);
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/input/mpegts/iptv/iptv_private.h
Expand Up @@ -150,7 +150,6 @@ struct iptv_mux
void *im_data;

int im_delete_flag;
int im_m3u_header;
};

iptv_mux_t* iptv_mux_create0
Expand Down

0 comments on commit fe571eb

Please sign in to comment.