From cd5f31f7519479e7faea2baacbe8181e3acaed29 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 5 Oct 2010 10:40:15 +0200 Subject: [PATCH] goom: use adapter for timestamping Use the adapter timestamp code to get more accurate timestamps. Fix latency calculation, we add our own latency in the worst case. --- gst/goom/gstgoom.c | 31 +++++++++++++++---------------- gst/goom/gstgoom.h | 3 --- gst/goom2k1/gstgoom.c | 31 +++++++++++++++---------------- gst/goom2k1/gstgoom.h | 3 --- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/gst/goom/gstgoom.c b/gst/goom/gstgoom.c index 8895283..f75126d 100644 --- a/gst/goom/gstgoom.c +++ b/gst/goom/gstgoom.c @@ -210,7 +210,6 @@ gst_goom_finalize (GObject * object) static void gst_goom_reset (GstGoom * goom) { - goom->next_ts = -1; gst_adapter_clear (goom->adapter); gst_segment_init (&goom->segment, GST_FORMAT_UNDEFINED); @@ -433,9 +432,9 @@ gst_goom_src_query (GstPad * pad, GstQuery * query) /* we add some latency but only if we need to buffer more than what * upstream gives us */ - min_latency = MAX (our_latency, min_latency); + min_latency += our_latency; if (max_latency != -1) - max_latency = MAX (our_latency, max_latency); + max_latency += our_latency; GST_DEBUG_OBJECT (goom, "Calculated total latency : min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT, @@ -500,13 +499,8 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) /* don't try to combine samples from discont buffer */ if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { gst_adapter_clear (goom->adapter); - goom->next_ts = -1; } - /* Match timestamps from the incoming audio */ - if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE) - goom->next_ts = GST_BUFFER_TIMESTAMP (buffer); - GST_DEBUG_OBJECT (goom, "Input buffer has %d samples, time=%" G_GUINT64_FORMAT, GST_BUFFER_SIZE (buffer) / goom->bps, GST_BUFFER_TIMESTAMP (buffer)); @@ -522,6 +516,7 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) guchar *out_frame; gint i; guint avail, to_flush; + guint64 dist, timestamp; avail = gst_adapter_available (goom->adapter); GST_DEBUG_OBJECT (goom, "avail now %u", avail); @@ -536,11 +531,19 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) GST_DEBUG_OBJECT (goom, "processing buffer"); - if (goom->next_ts != -1) { + /* get timestamp of the current adapter byte */ + timestamp = gst_adapter_prev_timestamp (goom->adapter, &dist); + if (GST_CLOCK_TIME_IS_VALID (timestamp)) { + /* convert bytes to time */ + dist /= goom->bps; + timestamp += gst_util_uint64_scale_int (dist, GST_SECOND, goom->rate); + } + + if (timestamp != -1) { gint64 qostime; qostime = gst_segment_to_running_time (&goom->segment, GST_FORMAT_TIME, - goom->next_ts); + timestamp); GST_OBJECT_LOCK (goom); /* check for QoS, don't compute buffers that are known to be late */ @@ -581,7 +584,7 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) } } - GST_BUFFER_TIMESTAMP (outbuf) = goom->next_ts; + GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_DURATION (outbuf) = goom->duration; GST_BUFFER_SIZE (outbuf) = goom->outsize; @@ -589,17 +592,13 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) memcpy (GST_BUFFER_DATA (outbuf), out_frame, goom->outsize); GST_DEBUG ("Pushing frame with time=%" GST_TIME_FORMAT ", duration=%" - GST_TIME_FORMAT, GST_TIME_ARGS (goom->next_ts), + GST_TIME_FORMAT, GST_TIME_ARGS (timestamp), GST_TIME_ARGS (goom->duration)); ret = gst_pad_push (goom->srcpad, outbuf); outbuf = NULL; skip: - /* interpollate next timestamp */ - if (goom->next_ts != -1) - goom->next_ts += goom->duration; - /* Now flush the samples we needed for this frame, which might be more than * the samples we used (GOOM_SAMPLES). */ to_flush = goom->bpf; diff --git a/gst/goom/gstgoom.h b/gst/goom/gstgoom.h index e9ca83c..382d053 100644 --- a/gst/goom/gstgoom.h +++ b/gst/goom/gstgoom.h @@ -70,9 +70,6 @@ struct _GstGoom /* segment state */ GstSegment segment; - /* the timestamp of the next frame */ - GstClockTime next_ts; - /* QoS stuff *//* with LOCK */ gdouble proportion; GstClockTime earliest_time; diff --git a/gst/goom2k1/gstgoom.c b/gst/goom2k1/gstgoom.c index 8faee92..0b5da9a 100644 --- a/gst/goom2k1/gstgoom.c +++ b/gst/goom2k1/gstgoom.c @@ -208,7 +208,6 @@ gst_goom_finalize (GObject * object) static void gst_goom_reset (GstGoom * goom) { - goom->next_ts = -1; gst_adapter_clear (goom->adapter); gst_segment_init (&goom->segment, GST_FORMAT_UNDEFINED); @@ -431,9 +430,9 @@ gst_goom_src_query (GstPad * pad, GstQuery * query) /* we add some latency but only if we need to buffer more than what * upstream gives us */ - min_latency = MAX (our_latency, min_latency); + min_latency += our_latency; if (max_latency != -1) - max_latency = MAX (our_latency, max_latency); + max_latency += our_latency; GST_DEBUG_OBJECT (goom, "Calculated total latency : min %" GST_TIME_FORMAT " max %" GST_TIME_FORMAT, @@ -498,13 +497,8 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) /* don't try to combine samples from discont buffer */ if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { gst_adapter_clear (goom->adapter); - goom->next_ts = -1; } - /* Match timestamps from the incoming audio */ - if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE) - goom->next_ts = GST_BUFFER_TIMESTAMP (buffer); - GST_DEBUG_OBJECT (goom, "Input buffer has %d samples, time=%" G_GUINT64_FORMAT, GST_BUFFER_SIZE (buffer) / goom->bps, GST_BUFFER_TIMESTAMP (buffer)); @@ -520,6 +514,7 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) guchar *out_frame; gint i; guint avail, to_flush; + guint64 dist, timestamp; avail = gst_adapter_available (goom->adapter); GST_DEBUG_OBJECT (goom, "avail now %u", avail); @@ -534,11 +529,19 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) GST_DEBUG_OBJECT (goom, "processing buffer"); - if (goom->next_ts != -1) { + /* get timestamp of the current adapter byte */ + timestamp = gst_adapter_prev_timestamp (goom->adapter, &dist); + if (GST_CLOCK_TIME_IS_VALID (timestamp)) { + /* convert bytes to time */ + dist /= goom->bps; + timestamp += gst_util_uint64_scale_int (dist, GST_SECOND, goom->rate); + } + + if (timestamp != -1) { gint64 qostime; qostime = gst_segment_to_running_time (&goom->segment, GST_FORMAT_TIME, - goom->next_ts); + timestamp); GST_OBJECT_LOCK (goom); /* check for QoS, don't compute buffers that are known to be late */ @@ -579,7 +582,7 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) } } - GST_BUFFER_TIMESTAMP (outbuf) = goom->next_ts; + GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_DURATION (outbuf) = goom->duration; GST_BUFFER_SIZE (outbuf) = goom->outsize; @@ -587,17 +590,13 @@ gst_goom_chain (GstPad * pad, GstBuffer * buffer) memcpy (GST_BUFFER_DATA (outbuf), out_frame, goom->outsize); GST_DEBUG ("Pushing frame with time=%" GST_TIME_FORMAT ", duration=%" - GST_TIME_FORMAT, GST_TIME_ARGS (goom->next_ts), + GST_TIME_FORMAT, GST_TIME_ARGS (timestamp), GST_TIME_ARGS (goom->duration)); ret = gst_pad_push (goom->srcpad, outbuf); outbuf = NULL; skip: - /* interpollate next timestamp */ - if (goom->next_ts != -1) - goom->next_ts += goom->duration; - /* Now flush the samples we needed for this frame, which might be more than * the samples we used (GOOM_SAMPLES). */ to_flush = goom->bpf; diff --git a/gst/goom2k1/gstgoom.h b/gst/goom2k1/gstgoom.h index 9c25f45..3aeeafa 100644 --- a/gst/goom2k1/gstgoom.h +++ b/gst/goom2k1/gstgoom.h @@ -70,9 +70,6 @@ struct _GstGoom /* segment state */ GstSegment segment; - /* the timestamp of the next frame */ - GstClockTime next_ts; - /* QoS stuff *//* with LOCK */ gdouble proportion; GstClockTime earliest_time; -- 2.7.4