]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
mpegts input, iptv network: add 'Remove scrambled bits' option, fixes #4193
authorJaroslav Kysela <perex@perex.cz>
Thu, 23 Feb 2017 13:00:13 +0000 (14:00 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 23 Feb 2017 13:06:20 +0000 (14:06 +0100)
src/input/mpegts.h
src/input/mpegts/iptv/iptv.c
src/input/mpegts/iptv/iptv_private.h
src/input/mpegts/mpegts_input.c

index 0345a3edbc99189e161911c9effa734f36cdf91f..ca9250a9f378ec235ab0dec88e6a4f2463edba72 100644 (file)
@@ -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
index 61aabff3486a16c80c4bcd5a9c2b13d50e81c057..f3439a06d84c877e9a687fc6ac9eb4ee43698b5d 100644 (file)
@@ -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,
index 78f93999370e4ba6e0e0115060c76c70937cf383..c13bf9052fbddaac28f2357c922b3dac30dc22af 100644 (file)
@@ -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;
 
index 5f1b15ddbd3cb2a0c5695c57f4ef01c130d6f8b1..b7f9cae3b268aa4ead2396d1a73572821d21d942 100644 (file)
@@ -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;