hlsdemux: Properly keep track of current offset
authorSebastian Dröge <sebastian@centricular.com>
Thu, 31 Mar 2016 10:39:59 +0000 (13:39 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 1 Jul 2016 12:10:31 +0000 (14:10 +0200)
GstAdapter does not guarantee to pass through all the offsets, we have to keep
track of it ourselves.

https://bugzilla.gnome.org/show_bug.cgi?id=764684

ext/hls/gsthlsdemux.c
ext/hls/gsthlsdemux.h

index 7afcfde..14e8819 100644 (file)
@@ -236,6 +236,7 @@ gst_hls_demux_clear_pending_data (GstHLSDemux * hlsdemux)
   gst_adapter_clear (hlsdemux->pending_encrypted_data);
   gst_buffer_replace (&hlsdemux->pending_decrypted_buffer, NULL);
   gst_buffer_replace (&hlsdemux->pending_typefind_buffer, NULL);
+  hlsdemux->current_offset = -1;
 }
 
 static gboolean
@@ -586,8 +587,13 @@ gst_hls_demux_handle_buffer (GstAdaptiveDemux * demux,
 
   g_assert (hlsdemux->pending_typefind_buffer == NULL);
 
-  if (buffer)
+  if (buffer) {
+    buffer = gst_buffer_make_writable (buffer);
+    GST_BUFFER_OFFSET (buffer) = hlsdemux->current_offset;
+    hlsdemux->current_offset += gst_buffer_get_size (buffer);
+    GST_BUFFER_OFFSET_END (buffer) = hlsdemux->current_offset;
     return gst_adaptive_demux_stream_push_buffer (stream, buffer);
+  }
   return GST_FLOW_OK;
 }
 
@@ -637,6 +643,10 @@ gst_hls_demux_data_received (GstAdaptiveDemux * demux,
 {
   GstHLSDemux *hlsdemux = GST_HLS_DEMUX_CAST (demux);
 
+  if (hlsdemux->current_offset == -1)
+    hlsdemux->current_offset =
+        GST_BUFFER_OFFSET_IS_VALID (buffer) ? GST_BUFFER_OFFSET (buffer) : 0;
+
   /* Is it encrypted? */
   if (hlsdemux->current_key) {
     GError *err = NULL;
index da84069..f0c530e 100644 (file)
@@ -87,7 +87,8 @@ struct _GstHLSDemux
   GstAdapter *pending_encrypted_data;  /* for chunking data into 16 byte multiples for decryption */
   GstBuffer *pending_decrypted_buffer; /* last decrypted buffer for pkcs7 unpadding.
                                           We only know that it is the last at EOS */
-  GstBuffer *pending_typefind_buffer; /* for collecting data until typefind succeeds */
+  GstBuffer *pending_typefind_buffer;  /* for collecting data until typefind succeeds */
+  guint64 current_offset;              /* offset we're currently at */
   gboolean reset_pts;
 };