hlsdemux: Clear pending data when needed
authorSebastian Dröge <sebastian@centricular.com>
Thu, 31 Mar 2016 10:01:00 +0000 (13:01 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 1 Jul 2016 12:10:31 +0000 (14:10 +0200)
When switching fragments we don't want to keep any data around from the last
one, and also forget about all data when doing flushing seeks or selecting new
bitrates.

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

ext/hls/gsthlsdemux.c

index fed487ae3e39bbe050957e0c7740d644d43b937e..7afcfde5b302b6a176fe7e5bc47e7968af91e585 100644 (file)
@@ -229,6 +229,15 @@ gst_hls_demux_get_bitrate (GstHLSDemux * hlsdemux)
   return 0;
 }
 
+static void
+gst_hls_demux_clear_pending_data (GstHLSDemux * hlsdemux)
+{
+  gst_hls_demux_decrypt_end (hlsdemux);
+  gst_adapter_clear (hlsdemux->pending_encrypted_data);
+  gst_buffer_replace (&hlsdemux->pending_decrypted_buffer, NULL);
+  gst_buffer_replace (&hlsdemux->pending_typefind_buffer, NULL);
+}
+
 static gboolean
 gst_hls_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek)
 {
@@ -253,7 +262,7 @@ gst_hls_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek)
 
   /* properly cleanup pending decryption status */
   if (flags & GST_SEEK_FLAG_FLUSH) {
-    gst_hls_demux_decrypt_end (hlsdemux);
+    gst_hls_demux_clear_pending_data (hlsdemux);
   }
 
   /* Use I-frame variants for trick modes */
@@ -382,6 +391,7 @@ gst_hls_demux_setup_streams (GstAdaptiveDemux * demux)
   GstHLSDemux *hlsdemux = GST_HLS_DEMUX_CAST (demux);
 
   /* only 1 output supported */
+  gst_hls_demux_clear_pending_data (hlsdemux);
   gst_adaptive_demux_stream_new (demux, gst_hls_demux_create_pad (hlsdemux));
 
   hlsdemux->reset_pts = TRUE;
@@ -511,6 +521,8 @@ gst_hls_demux_start_fragment (GstAdaptiveDemux * demux,
     g_object_unref (key_fragment);
   }
 
+  gst_hls_demux_clear_pending_data (hlsdemux);
+
   return TRUE;
 
 key_failed:
@@ -610,10 +622,8 @@ gst_hls_demux_finish_fragment (GstAdaptiveDemux * demux,
           hlsdemux->pending_decrypted_buffer, TRUE);
       hlsdemux->pending_decrypted_buffer = NULL;
     }
-  } else {
-    gst_buffer_replace (&hlsdemux->pending_decrypted_buffer, NULL);
-    gst_adapter_clear (hlsdemux->pending_encrypted_data);
   }
+  gst_hls_demux_clear_pending_data (hlsdemux);
 
   if (ret == GST_FLOW_OK || ret == GST_FLOW_NOT_LINKED)
     return gst_adaptive_demux_stream_advance_fragment (demux, stream,
@@ -773,8 +783,7 @@ gst_hls_demux_reset (GstAdaptiveDemux * ademux)
   demux->client = gst_m3u8_client_new ("", NULL);
 
   demux->srcpad_counter = 0;
-  gst_adapter_clear (demux->pending_encrypted_data);
-  gst_buffer_replace (&demux->pending_decrypted_buffer, NULL);
+  gst_hls_demux_clear_pending_data (demux);
   gst_buffer_replace (&demux->pending_typefind_buffer, NULL);
   if (demux->current_key) {
     g_free (demux->current_key);