]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
mpegts input: add CC restart for tables, too
authorJaroslav Kysela <perex@perex.cz>
Thu, 13 Dec 2018 12:33:15 +0000 (13:33 +0100)
committerJaroslav Kysela <perex@perex.cz>
Thu, 13 Dec 2018 12:33:15 +0000 (13:33 +0100)
src/input/mpegts.h
src/input/mpegts/mpegts_input.c

index a11bb501cc007acd98854f83fb9d10ec78d93eae..542640ce65d3f6a7d5ee781a86b7df68bae6b235 100644 (file)
@@ -61,7 +61,7 @@ typedef TAILQ_HEAD(mpegts_mux_queue,mpegts_mux) mpegts_mux_queue_t;
 typedef LIST_HEAD (,mpegts_mux)                 mpegts_mux_list_t;
 typedef LIST_HEAD (,mpegts_network_link)        mpegts_network_link_list_t;
 typedef TAILQ_HEAD(mpegts_table_feed_queue, mpegts_table_feed)
-  mpegts_table_feed_queue_t;
+                                                mpegts_table_feed_queue_t;
 
 /* Classes */
 extern const idclass_t mpegts_network_class;
@@ -287,6 +287,7 @@ struct mpegts_table
 
 struct mpegts_table_feed {
   TAILQ_ENTRY(mpegts_table_feed) mtf_link;
+  uint8_t mtf_cc_restart;
   int mtf_len;
   mpegts_mux_t *mtf_mux;
   uint8_t mtf_tsb[0];
index 65952aad60c045fbc2c2fe0de18756b01c4c258a..bc4b385c521e3869bf0fd07da34c17b0971243ae 100644 (file)
@@ -1303,7 +1303,7 @@ end:
 
 static void
 mpegts_input_table_dispatch
-  ( mpegts_mux_t *mm, const char *logprefix, const uint8_t *tsb, int tsb_len )
+  ( mpegts_mux_t *mm, const char *logprefix, const uint8_t *tsb, int tsb_len, int fast )
 {
   int i, len = 0, c = 0;
   const uint8_t *tsb2, *tsb2_end;
@@ -1318,6 +1318,10 @@ mpegts_input_table_dispatch
     c++;
     if (mt->mt_destroyed || !mt->mt_subscribed || mt->mt_pid != pid)
       continue;
+    if (fast && (mt->mt_flags & MT_FAST) == 0)
+      continue;
+    if (!fast && (mt->mt_flags & MT_FAST) != 0)
+      continue;
     mpegts_table_grab(mt);
     tprofile_start(&mt->mt_profile, "dispatch");
     if (len < i)
@@ -1342,6 +1346,38 @@ mpegts_input_table_dispatch
   }
 }
 
+static void
+mpegts_input_table_restart
+  ( mpegts_mux_t *mm, const char *logprefix, int fast )
+{
+  mpegts_table_t *mt;
+  tvh_mutex_lock(&mm->mm_tables_lock);
+  LIST_FOREACH(mt, &mm->mm_tables, mt_link) {
+    if (fast && (mt->mt_flags & MT_FAST) == 0)
+      continue;
+    if (!fast && (mt->mt_flags & MT_FAST) != 0)
+      continue;
+    mt->mt_sect.ps_cc = -1;
+  }
+  tvh_mutex_unlock(&mm->mm_tables_lock);
+}
+
+static mpegts_table_feed_t *
+mpegts_input_table_feed_create ( mpegts_input_t *mi, mpegts_mux_t *mm, uint8_t *tsb, int llen )
+{
+  mpegts_table_feed_t *mtf;
+
+  mtf = malloc(sizeof(mpegts_table_feed_t) + MAX(llen, MPEGTS_MTF_ALLOC_CHUNK));
+  mtf->mtf_cc_restart = 0;
+  mtf->mtf_len = llen;
+  memcpy(mtf->mtf_tsb, tsb, llen);
+  mtf->mtf_mux = mm;
+  mi->mi_table_queue_size += llen;
+  memoryinfo_alloc(&mpegts_input_table_memoryinfo, sizeof(mpegts_table_feed_t) + llen);
+  TAILQ_INSERT_TAIL(&mi->mi_table_queue, mtf, mtf_link);
+  return mtf;
+}
+
 static void
 mpegts_input_table_waiting ( mpegts_input_t *mi, mpegts_mux_t *mm )
 {
@@ -1397,6 +1433,7 @@ mpegts_input_process
   int table_wakeup = 0;
   mpegts_mux_t *mm = mpkt->mp_mux;
   mpegts_mux_instance_t *mmi;
+  mpegts_table_feed_t *mtf;
   uint64_t tspos;
 
   if (mm == NULL || (mmi = mm->mm_active) == NULL)
@@ -1404,6 +1441,21 @@ mpegts_input_process
 
   assert(mm == mmi->mmi_mux);
 
+  if (mpkt->mp_cc_restart) {
+    LIST_FOREACH(s, &mm->mm_transports, s_active_link)
+      TAILQ_FOREACH(st, &s->s_components.set_all, es_link)
+        st->es_cc = -1;
+    RB_FOREACH(mp, &mm->mm_pids, mp_link) {
+      mp->mp_cc = 0xff;
+      if (mp->mp_type & MPS_FTABLE) {
+        mpegts_input_table_restart(mm, mm->mm_nicename, 1);
+      } else {
+        mtf = mpegts_input_table_feed_create(mi, mm, NULL, 0);
+        mtf->mtf_cc_restart = 1;
+      }
+    }
+  }
+
   /* Process */
   tspos = mm->mm_input_pos;
   assert((len % 188) == 0);
@@ -1492,7 +1544,7 @@ mpegts_input_process
       if (type & (MPS_TABLE | MPS_FTABLE)) {
         if (!(tsb[1] & 0x80)) {
           if (type & MPS_FTABLE)
-            mpegts_input_table_dispatch(mm, mm->mm_nicename, tsb, llen);
+            mpegts_input_table_dispatch(mm, mm->mm_nicename, tsb, llen, 1);
           if (type & MPS_TABLE) {
             if (mi->mi_table_queue_size >= 2*1024*1024) {
               if (tvhlog_limit(&mi->mi_input_queue_loglimit, 10)) {
@@ -1501,7 +1553,7 @@ mpegts_input_process
                   mpegts_input_analyze_table_queue(mi);
               }
             } else {
-              mpegts_table_feed_t *mtf = TAILQ_LAST(&mi->mi_table_queue, mpegts_table_feed_queue);
+              mtf = TAILQ_LAST(&mi->mi_table_queue, mpegts_table_feed_queue);
               if (mtf && mtf->mtf_mux == mm && mtf->mtf_len + llen <= MPEGTS_MTF_ALLOC_CHUNK) {
                 pid2 = (mtf->mtf_tsb[1] << 8) | mtf->mtf_tsb[2];
                 if (pid == pid2) {
@@ -1516,15 +1568,8 @@ mpegts_input_process
               } else {
                 mtf = NULL;
               }
-              if (mtf == NULL) {
-                mtf = malloc(sizeof(mpegts_table_feed_t) + MAX(llen, MPEGTS_MTF_ALLOC_CHUNK));
-                mtf->mtf_len = llen;
-                memcpy(mtf->mtf_tsb, tsb, llen);
-                mtf->mtf_mux = mm;
-                mi->mi_table_queue_size += llen;
-                memoryinfo_alloc(&mpegts_input_table_memoryinfo, sizeof(mpegts_table_feed_t) + llen);
-                TAILQ_INSERT_TAIL(&mi->mi_table_queue, mtf, mtf_link);
-              }
+              if (mtf == NULL)
+                mpegts_input_table_feed_create(mi, mm, tsb, llen);
               table_wakeup = 1;
             }
           }
@@ -1560,12 +1605,6 @@ done:
     pktbuf_ref_dec(pb);
   }
 
-  if (mpkt->mp_cc_restart) {
-    LIST_FOREACH(s, &mm->mm_transports, s_active_link)
-      TAILQ_FOREACH(st, &s->s_components.set_all, es_link)
-        st->es_cc = -1;
-  }
-
   /* Wake table */
   if (table_wakeup)
     tvh_cond_signal(&mi->mi_table_cond, 0);
@@ -1771,8 +1810,11 @@ mpegts_input_table_thread ( void *aux )
     tvh_mutex_lock(&global_lock);
     if (atomic_get(&mi->mi_running)) {
       mm = mtf->mtf_mux;
-      if (mm && mm->mm_active)
-        mpegts_input_table_dispatch(mm, mm->mm_nicename, mtf->mtf_tsb, mtf->mtf_len);
+      if (mm && mm->mm_active) {
+        if (mtf->mtf_cc_restart)
+          mpegts_input_table_restart(mm, mm->mm_nicename, 0);
+        mpegts_input_table_dispatch(mm, mm->mm_nicename, mtf->mtf_tsb, mtf->mtf_len, 0);
+      }
     }
     tvh_mutex_unlock(&global_lock);