tsmux: maintain packet counters in a global array
authorMathieu Duponchelle <mathieu@centricular.com>
Wed, 22 May 2019 22:03:18 +0000 (00:03 +0200)
committerMathieu Duponchelle <mduponchelle1@gmail.com>
Thu, 30 May 2019 13:53:05 +0000 (13:53 +0000)
We can have multiple TsMuxPacketInfo objects for the same PID
with user-provided sections, for example ATSC requires multiple
tables with the same PID.

gst/mpegtsmux/tsmux/tsmux.c
gst/mpegtsmux/tsmux/tsmux.h
gst/mpegtsmux/tsmux/tsmuxcommon.h

index ad5c2d527c153ef3a53a985558b1aeb960d14534..290da032d679366bddb0338bbaa16d6420680bdb 100644 (file)
@@ -821,7 +821,7 @@ tsmux_write_adaptation_field (guint8 * buf,
 }
 
 static gboolean
-tsmux_write_ts_header (guint8 * buf, TsMuxPacketInfo * pi,
+tsmux_write_ts_header (TsMux * mux, guint8 * buf, TsMuxPacketInfo * pi,
     guint * payload_len_out, guint * payload_offset_out, guint stream_avail)
 {
   guint8 *tmp;
@@ -835,7 +835,7 @@ tsmux_write_ts_header (guint8 * buf, TsMuxPacketInfo * pi,
   buf[0] = TSMUX_SYNC_BYTE;
 
   TS_DEBUG ("PID 0x%04x, counter = 0x%01x, %u bytes avail", pi->pid,
-      pi->packet_count & 0x0f, stream_avail);
+      mux->pid_packet_counts[pi->pid] & 0x0f, stream_avail);
 
   /* 3 bits: 
    *   transport_error_indicator
@@ -893,10 +893,10 @@ tsmux_write_ts_header (guint8 * buf, TsMuxPacketInfo * pi,
     g_assert (payload_len <= stream_avail);
 
     /* Packet with payload, increment the continuity counter */
-    pi->packet_count++;
+    mux->pid_packet_counts[pi->pid]++;
   }
 
-  adaptation_flag |= pi->packet_count & 0x0f;
+  adaptation_flag |= mux->pid_packet_counts[pi->pid] & 0x0f;
 
   /* Write the byte of transport_scrambling_control, adaptation_field_control 
    * + continuity counter out */
@@ -960,7 +960,7 @@ tsmux_section_write_packet (GstMpegtsSectionType * type,
       /* Wee need room for a pointer byte */
       section->pi.stream_avail++;
 
-      if (!tsmux_write_ts_header (packet, &section->pi, &len, &offset,
+      if (!tsmux_write_ts_header (mux, packet, &section->pi, &len, &offset,
               section->pi.stream_avail))
         goto fail;
 
@@ -969,7 +969,7 @@ tsmux_section_write_packet (GstMpegtsSectionType * type,
       payload_len = len - 1;
 
     } else {
-      if (!tsmux_write_ts_header (packet, &section->pi, &len, &offset,
+      if (!tsmux_write_ts_header (mux, packet, &section->pi, &len, &offset,
               section->pi.stream_avail))
         goto fail;
       payload_len = len;
@@ -1218,7 +1218,7 @@ pad_stream (TsMux * mux, TsMuxStream * stream, gint64 cur_ts)
           if ((new_pcr =
                   write_new_pcr (mux, stream, get_current_pcr (mux,
                           cur_ts)) != -1))
-            tsmux_write_ts_header (map.data, &stream->pi, &payload_len,
+            tsmux_write_ts_header (mux, map.data, &stream->pi, &payload_len,
                 &payload_offs, 0);
           else
             tsmux_write_null_ts_header (map.data);
@@ -1297,7 +1297,7 @@ tsmux_write_stream_packet (TsMux * mux, TsMuxStream * stream)
 
   gst_buffer_map (buf, &map, GST_MAP_READ);
 
-  if (!tsmux_write_ts_header (map.data, pi, &payload_len, &payload_offs,
+  if (!tsmux_write_ts_header (mux, map.data, pi, &payload_len, &payload_offs,
           pi->stream_avail))
     goto fail;
 
index c622e89efb229dea85b86b655c586644372b6ca8..ba6db6303ce6efd7eb396963190712f9fb3fc2f7 100644 (file)
@@ -186,6 +186,9 @@ struct TsMux {
 
   guint64 bitrate;
   guint64 n_bytes;
+
+  /* For the per-PID continuity counter */
+  guint8 pid_packet_counts[8192];
 };
 
 /* create/free new muxer session */
index 2e7b35399690f3de60b6740cba778dad425f5f63..9f10499caa1fd6734021b90c5bcf9007ca587a68 100644 (file)
@@ -135,9 +135,6 @@ struct TsMuxPacketInfo {
 
   gboolean packet_start_unit_indicator;
 
-  /* continuity counter */
-  guint8 packet_count;
-
   /* payload bytes available
    * (including PES header if applicable) */
   guint stream_avail;