From cbe56d233103ead3c731eaba03e0da8d90e178ed Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 19 Dec 2014 10:57:29 +0100 Subject: [PATCH] matroska-demux: Cache upstream length Instead of constantly querying upstream, just cache the last duration, and in the unlikelyness we might have gone over query again before deciding we are EOS. Cut 15% cpu off matroskademux streaming thread (srsly...) --- gst/matroska/matroska-demux.c | 15 ++++++++++----- gst/matroska/matroska-demux.h | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c index ddca9cdc82..cdecceb2d3 100644 --- a/gst/matroska/matroska-demux.c +++ b/gst/matroska/matroska-demux.c @@ -329,6 +329,8 @@ gst_matroska_demux_reset (GstElement * element) demux->invalid_duration = FALSE; + demux->cached_length = G_MAXUINT64; + gst_flow_combiner_clear (demux->flowcombiner); } @@ -4436,11 +4438,14 @@ gst_matroska_demux_loop (GstPad * pad) } next: - if (G_UNLIKELY (demux->common.offset == - gst_matroska_read_common_get_length (&demux->common))) { - GST_LOG_OBJECT (demux, "Reached end of stream"); - ret = GST_FLOW_EOS; - goto eos; + if (G_UNLIKELY (demux->cached_length == G_MAXUINT64 || + demux->common.offset >= demux->cached_length)) { + demux->cached_length = gst_matroska_read_common_get_length (&demux->common); + if (demux->common.offset == demux->cached_length) { + GST_LOG_OBJECT (demux, "Reached end of stream"); + ret = GST_FLOW_EOS; + goto eos; + } } return; diff --git a/gst/matroska/matroska-demux.h b/gst/matroska/matroska-demux.h index 36a686da9b..624d177304 100644 --- a/gst/matroska/matroska-demux.h +++ b/gst/matroska/matroska-demux.h @@ -107,6 +107,9 @@ typedef struct _GstMatroskaDemux { /* for non-finalized files, with invalid segment duration */ gboolean invalid_duration; + + /* Cached upstream length (default G_MAXUINT64) */ + guint64 cached_length; } GstMatroskaDemux; typedef struct _GstMatroskaDemuxClass {