Use the adapter timestamp code to get more accurate timestamps.
Fix latency calculation, we add our own latency in the worst case.
static void
gst_goom_reset (GstGoom * goom)
{
- goom->next_ts = -1;
gst_adapter_clear (goom->adapter);
gst_segment_init (&goom->segment, GST_FORMAT_UNDEFINED);
/* 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,
/* 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));
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);
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 */
}
}
- GST_BUFFER_TIMESTAMP (outbuf) = goom->next_ts;
+ GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = goom->duration;
GST_BUFFER_SIZE (outbuf) = goom->outsize;
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;
/* segment state */
GstSegment segment;
- /* the timestamp of the next frame */
- GstClockTime next_ts;
-
/* QoS stuff *//* with LOCK */
gdouble proportion;
GstClockTime earliest_time;
static void
gst_goom_reset (GstGoom * goom)
{
- goom->next_ts = -1;
gst_adapter_clear (goom->adapter);
gst_segment_init (&goom->segment, GST_FORMAT_UNDEFINED);
/* 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,
/* 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));
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);
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 */
}
}
- GST_BUFFER_TIMESTAMP (outbuf) = goom->next_ts;
+ GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = goom->duration;
GST_BUFFER_SIZE (outbuf) = goom->outsize;
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;
/* segment state */
GstSegment segment;
- /* the timestamp of the next frame */
- GstClockTime next_ts;
-
/* QoS stuff *//* with LOCK */
gdouble proportion;
GstClockTime earliest_time;