mpegtspacketizer: Fix flushing/sync handling
authorEdward Hervey <edward.hervey@collabora.co.uk>
Tue, 24 Jul 2012 18:39:41 +0000 (20:39 +0200)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Tue, 14 Aug 2012 17:07:58 +0000 (19:07 +0200)
There was a stray adapter_flush() now that we used a temporary buffer

gst/mpegtsdemux/mpegtspacketizer.c

index 7f62807c534d70a905823d7665cdd68751e9f96f..a5716c588ddb587f281c40e88ad1e3adeebc6a07 100644 (file)
@@ -2459,6 +2459,8 @@ mpegts_packetizer_clear (MpegTSPacketizer2 * packetizer)
 void
 mpegts_packetizer_flush (MpegTSPacketizer2 * packetizer)
 {
+  GST_DEBUG ("Flushing");
+
   if (packetizer->streams) {
     int i;
     for (i = 0; i < 8192; i++) {
@@ -2606,6 +2608,7 @@ MpegTSPacketizerPacketReturn
 mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
     MpegTSPacketizerPacket * packet)
 {
+  MpegTSPacketizerPrivate *priv = packetizer->priv;
   guint avail;
   int i;
 
@@ -2614,17 +2617,15 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
       return PACKET_NEED_MORE;
   }
 
-  while ((avail = packetizer->priv->available) >= packetizer->packet_size) {
-    if (packetizer->priv->mapped == NULL) {
-      packetizer->priv->mapped_size =
-          packetizer->priv->available -
-          (packetizer->priv->available % packetizer->packet_size);
-      packetizer->priv->mapped =
-          (guint8 *) gst_adapter_map (packetizer->adapter,
-          packetizer->priv->mapped_size);
-      packetizer->priv->offset = 0;
+  while ((avail = priv->available) >= packetizer->packet_size) {
+    if (priv->mapped == NULL) {
+      priv->mapped_size =
+          priv->available - (priv->available % packetizer->packet_size);
+      priv->mapped =
+          (guint8 *) gst_adapter_map (packetizer->adapter, priv->mapped_size);
+      priv->offset = 0;
     }
-    packet->data_start = packetizer->priv->mapped + packetizer->priv->offset;
+    packet->data_start = priv->mapped + priv->offset;
 
     /* M2TS packets don't start with the sync byte, all other variants do */
     if (packetizer->packet_size == MPEGTS_M2TS_PACKETSIZE)
@@ -2638,7 +2639,7 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
     GST_LOG ("offset %" G_GUINT64_FORMAT, packet->offset);
     packetizer->offset += packetizer->packet_size;
     GST_MEMDUMP ("data_start", packet->data_start, 16);
-    packet->origts = packetizer->priv->last_in_time;
+    packet->origts = priv->last_in_time;
 
     /* Check sync byte */
     if (G_LIKELY (packet->data_start[0] == 0x47))
@@ -2658,13 +2659,15 @@ mpegts_packetizer_next_packet (MpegTSPacketizer2 * packetizer,
         i += 188;
     }
 
-    gst_adapter_flush (packetizer->adapter, i);
+    GST_DEBUG ("Flushing %d bytes out", i);
+    /* gst_adapter_flush (packetizer->adapter, i); */
     /* Pop out the remaining data... */
-    packetizer->priv->offset += i;
-    packetizer->priv->available -= i;
-    if (G_UNLIKELY (packetizer->priv->available < packetizer->packet_size)) {
-      gst_adapter_flush (packetizer->adapter, packetizer->priv->offset);
-      packetizer->priv->mapped = NULL;
+    priv->offset += i;
+    priv->available -= i;
+    if (G_UNLIKELY (priv->available < packetizer->packet_size)) {
+      GST_DEBUG ("Flushing %d bytes out", priv->offset);
+      gst_adapter_flush (packetizer->adapter, priv->offset);
+      priv->mapped = NULL;
     }
     continue;
   }
@@ -2697,11 +2700,14 @@ void
 mpegts_packetizer_clear_packet (MpegTSPacketizer2 * packetizer,
     MpegTSPacketizerPacket * packet)
 {
-  packetizer->priv->offset += packetizer->packet_size;
-  packetizer->priv->available -= packetizer->packet_size;
-  if (G_UNLIKELY (packetizer->priv->available < packetizer->packet_size)) {
-    gst_adapter_flush (packetizer->adapter, packetizer->priv->offset);
-    packetizer->priv->mapped = NULL;
+  MpegTSPacketizerPrivate *priv = packetizer->priv;
+
+  priv->offset += packetizer->packet_size;
+  priv->available -= packetizer->packet_size;
+
+  if (G_UNLIKELY (priv->mapped && priv->available < packetizer->packet_size)) {
+    gst_adapter_flush (packetizer->adapter, priv->offset);
+    priv->mapped = NULL;
   }
 }