From e48966ecf1af601070fe9075349dd56bcd385ab4 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 8 Nov 2011 09:44:18 +0100 Subject: [PATCH] mpegtsbase: Query whether upstream is live or not --- gst/mpegtsdemux/mpegtsbase.c | 23 +++++++++++++++++++++++ gst/mpegtsdemux/mpegtsbase.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/gst/mpegtsdemux/mpegtsbase.c b/gst/mpegtsdemux/mpegtsbase.c index 886d6da3e1..2571577fec 100644 --- a/gst/mpegtsdemux/mpegtsbase.c +++ b/gst/mpegtsdemux/mpegtsbase.c @@ -216,6 +216,9 @@ mpegts_base_reset (MpegTSBase * base) base->in_gap = 0; base->first_buf_ts = GST_CLOCK_TIME_NONE; + base->upstream_live = FALSE; + base->query_latency = FALSE; + if (klass->reset) klass->reset (base); } @@ -1224,6 +1227,22 @@ mpegts_base_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) return res; } +static void +query_upstream_latency (MpegTSBase * base) +{ + GstQuery *query; + + query = gst_query_new_latency (); + if (gst_pad_peer_query (base->sinkpad, query)) { + gst_query_parse_latency (query, &base->upstream_live, NULL, NULL); + GST_DEBUG_OBJECT (base, "Upstream is %s", + base->upstream_live ? "LIVE" : "NOT LIVE"); + } else + GST_WARNING_OBJECT (base, "Failed to query upstream latency"); + gst_query_unref (query); + base->query_latency = TRUE; +} + static inline GstFlowReturn mpegts_base_push (MpegTSBase * base, MpegTSPacketizerPacket * packet, MpegTSPacketizerSection * section) @@ -1252,6 +1271,10 @@ mpegts_base_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) base = GST_MPEGTS_BASE (parent); packetizer = base->packetizer; + if (G_UNLIKELY (base->query_latency == FALSE)) { + query_upstream_latency (base); + } + if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (base->first_buf_ts)) && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) { base->first_buf_ts = GST_BUFFER_TIMESTAMP (buf); diff --git a/gst/mpegtsdemux/mpegtsbase.h b/gst/mpegtsdemux/mpegtsbase.h index 872e77ee87..499ea6a318 100644 --- a/gst/mpegtsdemux/mpegtsbase.h +++ b/gst/mpegtsdemux/mpegtsbase.h @@ -137,6 +137,11 @@ struct _MpegTSBase { GstClockTime in_gap; GstClockTime first_buf_ts; + /* Whether upstream is live or not */ + gboolean upstream_live; + /* Whether we queried the upstream latency or not */ + gboolean query_latency; + /* Upstream segment */ GstSegment segment; };