From: Jaroslav Kysela Date: Wed, 12 Dec 2018 09:03:00 +0000 (+0100) Subject: iptv http: remove the wrong si rewrite code, cleanup the free sequence X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2059cafb8337756a211ad958cf30a94ddfe36c49;p=thirdparty%2Ftvheadend.git iptv http: remove the wrong si rewrite code, cleanup the free sequence --- diff --git a/src/input/mpegts/iptv/iptv_http.c b/src/input/mpegts/iptv/iptv_http.c index 04ee87892..d2d390761 100644 --- a/src/input/mpegts/iptv/iptv_http.c +++ b/src/input/mpegts/iptv/iptv_http.c @@ -28,6 +28,8 @@ #error "Wrong openssl!" #endif +#define HLS_SI_TBL_ANALYZE (4*188) + typedef struct http_priv { iptv_input_t *mi; iptv_mux_t *im; @@ -50,8 +52,6 @@ typedef struct http_priv { char *hls_key_url; htsmsg_t *hls_m3u; htsmsg_t *hls_key; - uint8_t *hls_si; - int64_t hls_last_si; struct { char tmp[AES_BLOCK_SIZE]; int tmp_len; @@ -271,7 +271,7 @@ iptv_http_data http_priv_t *hp = hc->hc_aux; iptv_mux_t *im; int pause = 0, off, rem; - uint8_t tsbuf[188]; + sbuf_t *sb; if (hp == NULL || hp->shutdown || hp->im == NULL || hc->hc_code != HTTP_STATUS_OK) @@ -290,56 +290,38 @@ iptv_http_data tvh_mutex_lock(&iptv_lock); + sb = &im->mm_iptv_buffer; if (hp->hls_encrypted) { - off = im->mm_iptv_buffer.sb_ptr; + off = sb->sb_ptr; if (hp->hls_aes128.tmp_len + len >= AES_BLOCK_SIZE) { if (hp->hls_aes128.tmp_len) { - sbuf_append(&im->mm_iptv_buffer, hp->hls_aes128.tmp, hp->hls_aes128.tmp_len); + sbuf_append(sb, hp->hls_aes128.tmp, hp->hls_aes128.tmp_len); rem = AES_BLOCK_SIZE - hp->hls_aes128.tmp_len; hp->hls_aes128.tmp_len = 0; - sbuf_append(&im->mm_iptv_buffer, buf, rem); + sbuf_append(sb, buf, rem); len -= rem; buf += rem; } rem = len % AES_BLOCK_SIZE; - sbuf_append(&im->mm_iptv_buffer, buf, len - rem); + sbuf_append(sb, buf, len - rem); buf += len - rem; len = rem; } memcpy(hp->hls_aes128.tmp + hp->hls_aes128.tmp_len, buf, len); hp->hls_aes128.tmp_len += len; - if (off == im->mm_iptv_buffer.sb_ptr) { + if (off == sb->sb_ptr) { tvh_mutex_unlock(&iptv_lock); return 0; } - buf = im->mm_iptv_buffer.sb_data + im->mm_iptv_buffer.sb_ptr; - len = im->mm_iptv_buffer.sb_ptr - off; + buf = sb->sb_data + sb->sb_ptr; + len = sb->sb_ptr - off; assert((len % 16) == 0); - iptv_http_data_aes128(hp, &im->mm_iptv_buffer, off); + iptv_http_data_aes128(hp, sb, off); } else { - sbuf_append(&im->mm_iptv_buffer, buf, len); + sbuf_append(sb, buf, len); } hp->off += len; - if (hp->hls_url && hp->off == 0 && len >= 2*188) { - free(hp->hls_si); - hp->hls_si = malloc(2*188); - memcpy(hp->hls_si, buf, 2*188); - } - - if (hp->hls_last_si + sec2mono(1) <= mclk() && hp->hls_si) { - /* do rounding to start of the last MPEG-TS packet */ - rem = 188 - (hp->off % 188); - if (im->mm_iptv_buffer.sb_ptr >= rem) { - im->mm_iptv_buffer.sb_ptr -= rem; - memcpy(tsbuf, im->mm_iptv_buffer.sb_data + im->mm_iptv_buffer.sb_ptr, rem); - sbuf_append(&im->mm_iptv_buffer, hp->hls_si, 2*188); - hp->hls_last_si = mclk(); - sbuf_append(&im->mm_iptv_buffer, tsbuf, rem); - hp->off += rem; - } - } - if (len > 0) if (iptv_input_recv_packets(im, len) == 1) pause = hc->hc_pause = 1; @@ -505,6 +487,25 @@ iptv_http_create_header http_client_add_args(hc, h, hp->im->mm_iptv_hdr); } +/* + * + */ +static void +iptv_http_free( http_priv_t *hp ) +{ + if (hp->hc) + http_client_close(hp->hc); + sbuf_free(&hp->m3u_sbuf); + sbuf_free(&hp->key_sbuf); + htsmsg_destroy(hp->hls_m3u); + htsmsg_destroy(hp->hls_key); + free(hp->hls_url); + free(hp->hls_url_after_key); + free(hp->hls_key_url); + free(hp->host_url); + free(hp); +} + /* * Setup HTTP(S) connection */ @@ -523,7 +524,7 @@ iptv_http_start hp->im = im; if (!(hc = http_client_connect(hp, HTTP_VERSION_1_1, u->scheme, u->host, u->port, NULL))) { - free(hp); + iptv_http_free(hp); return SM_CODE_TUNING_FAILED; } hc->hc_hdr_create = iptv_http_create_header; @@ -540,9 +541,8 @@ iptv_http_start http_client_register(hc); /* register to the HTTP thread */ r = http_client_simple(hc, u); if (r < 0) { - http_client_close(hc); + iptv_http_free(hp); im->im_data = NULL; - free(hp); return SM_CODE_TUNING_FAILED; } @@ -563,17 +563,9 @@ iptv_http_stop tvh_mutex_unlock(&iptv_lock); http_client_close(hp->hc); tvh_mutex_lock(&iptv_lock); + hp->hc = NULL; im->im_data = NULL; - sbuf_free(&hp->m3u_sbuf); - sbuf_free(&hp->key_sbuf); - htsmsg_destroy(hp->hls_m3u); - htsmsg_destroy(hp->hls_key); - free(hp->hls_url); - free(hp->hls_url_after_key); - free(hp->hls_key_url); - free(hp->hls_si); - free(hp->host_url); - free(hp); + iptv_http_free(hp); }