[Mesa-dev] [Mesa-dev, kmscube 09/10] gst-decoder.c: Improve synchronicity of video output

Carlos Rafael Giani dv at pseudoterminal.org
Fri Apr 7 21:16:07 UTC 2017


sync=false causes a sink to output data as fast as it can. This explains
why without max-buffers=2 the pipeline used to use up 100's of MB of
buffers.

Instead, set sync to true, and enable frame dropping, to make sure the
video playback speed remains intact.

Signed-off-by: Carlos Rafael Giani <dv at pseudoterminal.org>
---
 gst-decoder.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gst-decoder.c b/gst-decoder.c
index 188fe4b..67efbfd 100644
--- a/gst-decoder.c
+++ b/gst-decoder.c
@@ -273,10 +273,19 @@ video_init(const struct egl *egl, const struct gbm *gbm, const char *filename)
 	g_object_set(G_OBJECT(src), "location", filename, NULL);
 	gst_object_unref(src);
 
-	/* if we don't limit max-buffers then we can let the decoder outrun
-	 * vsync and quickly chew up 100's of MB of buffers:
+	/* If frames cannot be displayed on time, drop them. This makes
+	 * sure playback speed remains intact even if the EGL display
+	 * intervals don't match the pipeline's decoding intervals.
+	 * sync=TRUE makes sure the sink blocks the pipeline until the
+	 * video frame is scheduled to be output (based on its PTS).
+	 * This also avoids excessive CPU usage, since the blocking
+	 * wait puts the streaming thread to sleep until the video
+	 * frame is due.
+	 * max-buffers=1 makes sure only one frame is queued (more are
+	 * not necessary).
 	 */
-	g_object_set(G_OBJECT(dec->sink), "max-buffers", 2, NULL);
+	g_object_set(G_OBJECT(dec->sink), "drop", (gboolean)TRUE, "max-buffers", 1,
+		"sync", (gboolean)TRUE, NULL);
 
 	gst_pad_add_probe(gst_element_get_static_pad(dec->sink, "sink"),
 			GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
-- 
2.7.4



More information about the mesa-dev mailing list