]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
tsdemux: move PCR extraction to mpegts input
authorJaroslav Kysela <perex@perex.cz>
Fri, 13 Nov 2015 09:30:57 +0000 (10:30 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 13 Nov 2015 10:41:34 +0000 (11:41 +0100)
src/input/mpegts/mpegts_input.c
src/input/mpegts/tsdemux.c
src/input/mpegts/tsdemux.h

index 628352cd28832687ab3c9877445096a1140f50af..87132988b0da5031f09b144120099d8149362dd2 100644 (file)
@@ -926,6 +926,28 @@ mpegts_input_tuning_error ( mpegts_input_t *mi, mpegts_mux_t *mm )
  * Data processing
  * *************************************************************************/
 
+static int inline
+get_pcr ( const uint8_t *tsb, int64_t *rpcr )
+{
+  int_fast64_t pcr;
+
+  if (tsb[1] & 0x80) /* error bit */
+    return 0;
+
+  if ((tsb[3] & 0x20) == 0 ||
+      tsb[4] <= 5 ||
+      (tsb[5] & 0x10) == 0)
+    return 0;
+
+  pcr  = (uint64_t)tsb[6] << 25;
+  pcr |= (uint64_t)tsb[7] << 17;
+  pcr |= (uint64_t)tsb[8] << 9;
+  pcr |= (uint64_t)tsb[9] << 1;
+  pcr |= ((uint64_t)tsb[10] >> 7) & 0x01;
+  *rpcr = pcr;
+  return 1;
+}
+
 static int inline
 ts_sync_count ( const uint8_t *tsb, int len )
 {
@@ -982,14 +1004,16 @@ mpegts_input_recv_packets
   //       without the potential need to buffer data (since that would
   //       require per mmi buffers, where this is generally not required)
 
-  /* Extract PCR (used for tsfile playback) */
+  /* Extract PCR on demand */
   if (pcr && pcr_pid) {
-    uint8_t *tmp, *end;
-    for (tmp = tsb, end = tsb + len2; tmp < end; tmp += 188) {
+    uint8_t *tmp;
+    for (tmp = tsb + len2 - 188; tmp >= tsb; tmp -= 188) {
       uint16_t pid = ((tmp[1] & 0x1f) << 8) | tmp[2];
       if (*pcr_pid == MPEGTS_PID_NONE || *pcr_pid == pid) {
-        ts_recv_packet1(NULL, tmp, 188, pcr, 0);
-       if (*pcr != PTS_UNSET) *pcr_pid = pid;
+        if (get_pcr(tmp, pcr)) {
+          if (*pcr != PTS_UNSET) *pcr_pid = pid;
+          break;
+        }
       }
     }
   }
@@ -1232,7 +1256,7 @@ mpegts_input_process
           s = mps->mps_owner;
           f = (type & (MPS_TABLE|MPS_FTABLE)) ||
               (pid == s->s_pmt_pid) || (pid == s->s_pcr_pid);
-          ts_recv_packet1((mpegts_service_t*)s, tsb, llen, NULL, f);
+          ts_recv_packet1((mpegts_service_t*)s, tsb, llen, f);
         }
       } else
       /* Stream table data */
@@ -1241,7 +1265,7 @@ mpegts_input_process
           if (s->s_type != STYPE_STD) continue;
           f = (type & (MPS_TABLE|MPS_FTABLE)) ||
               (pid == s->s_pmt_pid) || (pid == s->s_pcr_pid);
-          ts_recv_packet1((mpegts_service_t*)s, tsb, llen, NULL, f);
+          ts_recv_packet1((mpegts_service_t*)s, tsb, llen, f);
         }
       }
 
index 05dca2bb9e308f719ad59ad32ff60ea8ad068127..8913316d39cfb31e28efe67c37264a2b59024dda 100644 (file)
@@ -173,12 +173,11 @@ ts_recv_skipped0
  */
 int
 ts_recv_packet1
-  (mpegts_service_t *t, const uint8_t *tsb, int len, int64_t *pcrp, int table)
+  (mpegts_service_t *t, const uint8_t *tsb, int len, int table)
 {
   elementary_stream_t *st;
   int pid, r;
   int error = 0;
-  int64_t pcr = PTS_UNSET;
   
   /* Error */
   if (tsb[1] & 0x80)
@@ -189,19 +188,6 @@ ts_recv_packet1
          tsb[0], tsb[1], tsb[2], tsb[3], tsb[4], tsb[5]);
 #endif
 
-  /* Extract PCR (do this early for tsfile) */
-  if((tsb[3] & 0x20) && (tsb[4] > 5) && (tsb[5] & 0x10) && !error) {
-    pcr  = (uint64_t)tsb[6] << 25;
-    pcr |= (uint64_t)tsb[7] << 17;
-    pcr |= (uint64_t)tsb[8] << 9;
-    pcr |= (uint64_t)tsb[9] << 1;
-    pcr |= ((uint64_t)tsb[10] >> 7) & 0x01;
-    if (pcrp) *pcrp = pcr;
-  }
-
-  /* Nothing - special case for tsfile to get PCR */
-  if (!t) return 0;
-
   /* Service inactive - ignore */
   if(t->s_status != SERVICE_RUNNING)
     return 0;
index da4e5a6248794fd10bc00422b013c0fd53cd0b2a..5fb82ac75d07b423c0783872b7db2fdab00580d0 100644 (file)
@@ -22,7 +22,7 @@
 int ts_resync ( const uint8_t *tsb, int *len, int *idx );
 
 int ts_recv_packet1
-  (struct mpegts_service *t, const uint8_t *tsb, int len, int64_t *pcrp, int table);
+  (struct mpegts_service *t, const uint8_t *tsb, int len, int table);
 
 void ts_recv_packet2(struct mpegts_service *t, const uint8_t *tsb, int len);