From 6367b03096fea2bd2be7b0d511f2c8551d7f278d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 6 Mar 2006 15:16:23 +0000 Subject: [PATCH] libs/gst/base/gstbasesink.c: Don't ever draw a frame that is >10ms late. Original commit message from CVS: * libs/gst/base/gstbasesink.c: (gst_base_sink_wait_clock), (gst_base_sink_do_sync), (gst_base_sink_render_object): Don't ever draw a frame that is >10ms late. --- ChangeLog | 6 ++++++ libs/gst/base/gstbasesink.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index afdd02015c..4dbd8f3a57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-03-06 Wim Taymans + + * libs/gst/base/gstbasesink.c: (gst_base_sink_wait_clock), + (gst_base_sink_do_sync), (gst_base_sink_render_object): + Don't ever draw a frame that is >10ms late. + 2006-03-06 Michael Smith * gst/gstmessage.c: (_gst_message_copy): diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index c0202a5a5b..818aaccab1 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -681,13 +681,16 @@ out_of_segment: * release the PREROLL_LOCK so that other threads can interrupt the entry. */ static GstClockReturn -gst_base_sink_wait_clock (GstBaseSink * basesink, GstClockTime time) +gst_base_sink_wait_clock (GstBaseSink * basesink, GstClockTime time, + GstClockTimeDiff * jitter) { GstClockID id; GstClockReturn ret; GstClock *clock; GstClockTime base_time; + *jitter = 0; + if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (time))) goto invalid_time; @@ -706,7 +709,7 @@ gst_base_sink_wait_clock (GstBaseSink * basesink, GstClockTime time) /* release the preroll lock while waiting */ GST_PAD_PREROLL_UNLOCK (basesink->sinkpad); - ret = gst_clock_id_wait (id, NULL); + ret = gst_clock_id_wait (id, jitter); GST_PAD_PREROLL_LOCK (basesink->sinkpad); gst_clock_id_unref (id); @@ -750,9 +753,10 @@ no_clock: */ static GstFlowReturn gst_base_sink_do_sync (GstBaseSink * basesink, GstPad * pad, - GstMiniObject * obj) + GstMiniObject * obj, gboolean * late) { GstClockTime start, stop; + GstClockTimeDiff jitter; gboolean syncable; GstClockReturn status = GST_CLOCK_OK; @@ -797,7 +801,7 @@ again: /* preroll done, we can sync since we ar in PLAYING now. */ GST_DEBUG_OBJECT (basesink, "waiting for clock"); basesink->end_time = stop; - status = gst_base_sink_wait_clock (basesink, start); + status = gst_base_sink_wait_clock (basesink, start, &jitter); GST_DEBUG_OBJECT (basesink, "clock returned %d", status); /* waiting could be interrupted and we can be flushing now */ @@ -811,7 +815,14 @@ again: goto again; } - /* FIXME, update clock stats here and do some QoS */ + if (status == GST_CLOCK_EARLY && jitter > (10 * GST_MSECOND)) { + /* FIXME, update clock stats here and do some QoS */ + GST_DEBUG_OBJECT (basesink, "late: jitter!! %" G_GINT64_FORMAT "\n", + jitter); + *late = TRUE; + } else { + *late = FALSE; + } return GST_FLOW_OK; @@ -845,14 +856,19 @@ gst_base_sink_render_object (GstBaseSink * basesink, GstPad * pad, { GstFlowReturn ret = GST_FLOW_OK; GstBaseSinkClass *bclass; + gboolean late = FALSE; /* synchronize this object */ - ret = gst_base_sink_do_sync (basesink, pad, obj); + ret = gst_base_sink_do_sync (basesink, pad, obj, &late); if (G_UNLIKELY (ret != GST_FLOW_OK)) goto sync_failed; /* and now render */ if (G_LIKELY (GST_IS_BUFFER (obj))) { + /* drop late messages unconditionally */ + if (late) + goto dropped; + bclass = GST_BASE_SINK_GET_CLASS (basesink); GST_DEBUG_OBJECT (basesink, "rendering buffer %p", obj); @@ -912,6 +928,12 @@ sync_failed: return ret; } +dropped: + { + GST_DEBUG_OBJECT (basesink, "buffer late, dropping, unref object %p", obj); + gst_mini_object_unref (obj); + return GST_FLOW_OK; + } } /* with STREAM_LOCK, PREROLL_LOCK