From: Jaroslav Kysela Date: Thu, 23 Feb 2017 13:00:13 +0000 (+0100) Subject: mpegts input, iptv network: add 'Remove scrambled bits' option, fixes #4193 X-Git-Tag: v4.2.1~100 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3525a9ca086c02d556d5d453813996b79587d435;p=thirdparty%2Ftvheadend.git mpegts input, iptv network: add 'Remove scrambled bits' option, fixes #4193 --- diff --git a/src/input/mpegts.h b/src/input/mpegts.h index 0345a3edb..ca9250a9f 100644 --- a/src/input/mpegts.h +++ b/src/input/mpegts.h @@ -134,7 +134,8 @@ struct mpegts_pcr { uint16_t pcr_pid; }; -#define MPEGTS_DATA_CC_RESTART (1<<0) +#define MPEGTS_DATA_CC_RESTART (1<<0) +#define MPEGTS_DATA_REMOVE_SCRAMBLED (1<<1) typedef int (*mpegts_table_callback_t) ( mpegts_table_t*, const uint8_t *buf, int len, int tableid ); @@ -710,6 +711,7 @@ struct mpegts_input TAILQ_HEAD(,mpegts_packet) mi_input_queue; uint64_t mi_input_queue_size; tvhlog_limit_t mi_input_queue_loglimit; + int mi_remove_scrambled_bits; /* Data processing/output */ // Note: this lock (mi_output_lock) protects all the remaining diff --git a/src/input/mpegts/iptv/iptv.c b/src/input/mpegts/iptv/iptv.c index 61aabff34..f3439a06d 100644 --- a/src/input/mpegts/iptv/iptv.c +++ b/src/input/mpegts/iptv/iptv.c @@ -570,7 +570,9 @@ iptv_input_recv_packets ( iptv_mux_t *im, ssize_t len ) return 1; } mpegts_input_recv_packets((mpegts_input_t*)iptv_input, mmi, - &im->mm_iptv_buffer, 0, &pcr); + &im->mm_iptv_buffer, + in->in_remove_scrambled_bits ? + MPEGTS_DATA_REMOVE_SCRAMBLED : 0, &pcr); if (pcr.pcr_first != PTS_UNSET && pcr.pcr_last != PTS_UNSET) { im->im_pcr_pid = pcr.pcr_pid; if (im->im_pcr == PTS_UNSET) { @@ -798,6 +800,17 @@ const idclass_t iptv_network_class = { .set = iptv_network_class_icon_url_set, .opts = PO_MULTILINE | PO_ADVANCED }, + { + .type = PT_BOOL, + .id = "remove_scrambled", + .name = N_("Remove scrambled bits"), + .desc = N_("The scrambled bits in MPEG-TS packets are always cleared. " + "It is a workaround for the special streams which are " + "descrambled, but these bits are not touched."), + .off = offsetof(iptv_network_t, in_remove_scrambled_bits), + .def.i = 1, + .opts = PO_EXPERT, + }, { .id = "autodiscovery", .type = PT_NONE, diff --git a/src/input/mpegts/iptv/iptv_private.h b/src/input/mpegts/iptv/iptv_private.h index 78f939993..c13bf9052 100644 --- a/src/input/mpegts/iptv/iptv_private.h +++ b/src/input/mpegts/iptv/iptv_private.h @@ -83,6 +83,7 @@ struct iptv_network int in_scan_create; int in_priority; int in_streaming_priority; + int in_remove_scrambled_bits; uint16_t in_service_id; diff --git a/src/input/mpegts/mpegts_input.c b/src/input/mpegts/mpegts_input.c index 5f1b15ddb..b7f9cae3b 100644 --- a/src/input/mpegts/mpegts_input.c +++ b/src/input/mpegts/mpegts_input.c @@ -309,6 +309,17 @@ const idclass_t mpegts_input_class = .def.i = 1, .opts = PO_ADVANCED, }, + { + .type = PT_BOOL, + .id = "remove_scrambled", + .name = N_("Remove scrambled bits"), + .desc = N_("The scrambled bits in MPEG-TS packets are always cleared. " + "It is a workaround for the special streams which are " + "descrambled, but these bits are not touched."), + .off = offsetof(mpegts_input_t, mi_remove_scrambled_bits), + .def.i = 1, + .opts = PO_EXPERT, + }, { .type = PT_STR, .id = "networks", @@ -1111,7 +1122,13 @@ retry: mp->mp_mux = mmi->mmi_mux; mp->mp_len = len2; mp->mp_cc_restart = (flags & MPEGTS_DATA_CC_RESTART) ? 1 : 0; + memcpy(mp->mp_data, tsb, len2); + if (mi->mi_remove_scrambled_bits || (flags & MPEGTS_DATA_REMOVE_SCRAMBLED) != 0) { + uint8_t *tmp, *end; + for (tmp = mp->mp_data, end = mp->mp_data + len2; tmp < end; tmp += 188) + tmp[3] &= ~0xc0; + } len -= len2; off += len2;