visual: use new adapter timestamp code

Use the new adapter timestamp tracking code to make things easier and produce
vastly better output timestamps.
This commit is contained in:
Wim Taymans 2009-05-13 19:24:15 +02:00
parent f2c2f6702a
commit 6eb549ab92

View file

@ -576,13 +576,8 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
/* resync on DISCONT */ /* resync on DISCONT */
if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) { if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT)) {
gst_adapter_clear (visual->adapter); gst_adapter_clear (visual->adapter);
visual->next_ts = -1;
} }
/* Match timestamps from the incoming audio */
if (GST_BUFFER_TIMESTAMP (buffer) != GST_CLOCK_TIME_NONE)
visual->next_ts = GST_BUFFER_TIMESTAMP (buffer);
GST_DEBUG_OBJECT (visual, GST_DEBUG_OBJECT (visual,
"Input buffer has %d samples, time=%" G_GUINT64_FORMAT, "Input buffer has %d samples, time=%" G_GUINT64_FORMAT,
GST_BUFFER_SIZE (buffer) / visual->bps, GST_BUFFER_TIMESTAMP (buffer)); GST_BUFFER_SIZE (buffer) / visual->bps, GST_BUFFER_TIMESTAMP (buffer));
@ -592,6 +587,7 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
while (TRUE) { while (TRUE) {
gboolean need_skip; gboolean need_skip;
const guint16 *data; const guint16 *data;
guint64 dist, timestamp;
GST_DEBUG_OBJECT (visual, "processing buffer"); GST_DEBUG_OBJECT (visual, "processing buffer");
@ -606,12 +602,20 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
if (avail < visual->spf * visual->bps) if (avail < visual->spf * visual->bps)
break; break;
if (visual->next_ts != -1) { /* get timestamp of the current adapter byte */
timestamp = gst_adapter_prev_timestamp (visual->adapter, &dist);
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
/* convert bytes to time */
dist /= visual->bps;
timestamp += gst_util_uint64_scale_int (dist, GST_SECOND, visual->rate);
}
if (timestamp != -1) {
gint64 qostime; gint64 qostime;
/* QoS is done on running time */ /* QoS is done on running time */
qostime = gst_segment_to_running_time (&visual->segment, GST_FORMAT_TIME, qostime = gst_segment_to_running_time (&visual->segment, GST_FORMAT_TIME,
visual->next_ts); timestamp);
GST_OBJECT_LOCK (visual); GST_OBJECT_LOCK (visual);
/* check for QoS, don't compute buffers that are known to be late */ /* check for QoS, don't compute buffers that are known to be late */
@ -722,17 +726,13 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
visual_video_set_buffer (visual->video, NULL); visual_video_set_buffer (visual->video, NULL);
GST_DEBUG_OBJECT (visual, "rendered one frame"); GST_DEBUG_OBJECT (visual, "rendered one frame");
GST_BUFFER_TIMESTAMP (outbuf) = visual->next_ts; GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = visual->duration; GST_BUFFER_DURATION (outbuf) = visual->duration;
ret = gst_pad_push (visual->srcpad, outbuf); ret = gst_pad_push (visual->srcpad, outbuf);
outbuf = NULL; outbuf = NULL;
skip: skip:
/* interpollate next timestamp */
if (visual->next_ts != -1)
visual->next_ts += visual->duration;
GST_DEBUG_OBJECT (visual, "finished frame, flushing %u samples from input", GST_DEBUG_OBJECT (visual, "finished frame, flushing %u samples from input",
visual->spf); visual->spf);