decodebin: Keep the number of buffers after an adaptive streaming demuxer lower
authorSebastian Dröge <sebastian@centricular.com>
Thu, 6 Mar 2014 21:37:44 +0000 (22:37 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 6 Mar 2014 21:45:30 +0000 (22:45 +0100)
Usually these buffers are multiple seconds large, and having a maximum
of 5 buffers in the multiqueue there can use a lot of memory. Lower
this to 2 for adaptive streaming demuxers.

gst/playback/gstdecodebin2.c

index c059136..9ebebfa 100644 (file)
@@ -233,10 +233,11 @@ enum
 #define AUTO_PREROLL_NOT_SEEKABLE_SIZE_TIME      10 * GST_SECOND
 #define AUTO_PREROLL_SEEKABLE_SIZE_TIME          0
 
-/* whan playing, keep a max of 2MB of data but try to keep the number of buffers
+/* when playing, keep a max of 2MB of data but try to keep the number of buffers
  * as low as possible (try to aim for 5 buffers) */
 #define AUTO_PLAY_SIZE_BYTES        2 * 1024 * 1024
 #define AUTO_PLAY_SIZE_BUFFERS      5
+#define AUTO_PLAY_ADAPTIVE_SIZE_BUFFERS 2
 #define AUTO_PLAY_SIZE_TIME         0
 
 #define DEFAULT_SUBTITLE_ENCODING NULL
@@ -282,7 +283,8 @@ static void type_found (GstElement * typefind, guint probability,
     GstCaps * caps, GstDecodeBin * decode_bin);
 
 static void decodebin_set_queue_size (GstDecodeBin * dbin,
-    GstElement * multiqueue, gboolean preroll, gboolean seekable);
+    GstElement * multiqueue, gboolean preroll, gboolean seekable,
+    gboolean adaptive_streaming);
 
 static gboolean gst_decode_bin_autoplug_continue (GstElement * element,
     GstPad * pad, GstCaps * caps);
@@ -3174,7 +3176,7 @@ gst_decode_group_hide (GstDecodeGroup * group)
  * playing or prerolling. */
 static void
 decodebin_set_queue_size (GstDecodeBin * dbin, GstElement * multiqueue,
-    gboolean preroll, gboolean seekable)
+    gboolean preroll, gboolean seekable, gboolean adaptive_streaming)
 {
   guint max_bytes, max_buffers;
   guint64 max_time;
@@ -3202,8 +3204,13 @@ decodebin_set_queue_size (GstDecodeBin * dbin, GstElement * multiqueue,
       max_bytes = 0;
     else if ((max_bytes = dbin->max_size_bytes) == 0)
       max_bytes = AUTO_PLAY_SIZE_BYTES;
+    /* if we're after an adaptive streaming demuxer keep
+     * a lower number of buffers as they are usually very
+     * large */
     if ((max_buffers = dbin->max_size_buffers) == 0)
-      max_buffers = AUTO_PLAY_SIZE_BUFFERS;
+      max_buffers =
+          (adaptive_streaming ? AUTO_PLAY_ADAPTIVE_SIZE_BUFFERS :
+          AUTO_PLAY_SIZE_BUFFERS);
     /* this is a multiqueue with disabled buffering, don't limit max_time */
     if (dbin->use_buffering)
       max_time = 0;
@@ -3253,7 +3260,8 @@ gst_decode_group_new (GstDecodeBin * dbin, GstDecodeChain * parent)
       gst_object_unref (pad);
     }
   }
-  decodebin_set_queue_size (dbin, mq, TRUE, seekable);
+  decodebin_set_queue_size (dbin, mq, TRUE, seekable,
+      (parent ? parent->adaptive_demuxer : FALSE));
 
   group->overrunsig = g_signal_connect (mq, "overrun",
       G_CALLBACK (multi_queue_overrun_cb), group);
@@ -3668,7 +3676,8 @@ gst_decode_group_reset_buffering (GstDecodeGroup * group)
         "high-percent", group->dbin->high_percent, NULL);
   }
   decodebin_set_queue_size (group->dbin, group->multiqueue, FALSE,
-      (group->parent ? group->parent->seekable : TRUE));
+      (group->parent ? group->parent->seekable : TRUE),
+      (group->parent ? group->parent->adaptive_demuxer : FALSE));
 
   GST_DEBUG_OBJECT (group->dbin, "Setting %s buffering to %d",
       GST_ELEMENT_NAME (group->multiqueue), !ret);