pad-monitor: improve timestamp ranges check

Keep the full range stored by the element in the monitor and check
if outgoing timestamps are within that range. It is simple and
should generally work.
This commit is contained in:
Thiago Santos 2013-07-19 09:57:07 -03:00
parent a11cc64f90
commit a7353e988b
2 changed files with 34 additions and 49 deletions

View file

@ -237,6 +237,12 @@ static gboolean
gst_qa_pad_monitor_timestamp_is_in_received_range (GstQaPadMonitor * monitor,
GstClockTime ts)
{
GST_DEBUG_OBJECT (monitor, "Checking if timestamp %" GST_TIME_FORMAT
" is in range: %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT " for pad "
"%s:%s", GST_TIME_ARGS (ts),
GST_TIME_ARGS (monitor->timestamp_range_start),
GST_TIME_ARGS (monitor->timestamp_range_end),
GST_DEBUG_PAD_NAME (GST_QA_PAD_MONITOR_GET_PAD (monitor)));
return !GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_start) ||
!GST_CLOCK_TIME_IS_VALID (monitor->timestamp_range_end) ||
(monitor->timestamp_range_start <= ts
@ -311,38 +317,6 @@ gst_qa_pad_monitor_check_buffer_timestamp_in_received_range (GstQaPadMonitor *
}
}
static void
gst_qa_pad_monitor_notify_buffer_pushed (GstQaPadMonitor * monitor)
{
GstIterator *iter;
gboolean done;
GstPad *otherpad;
GstQaPadMonitor *othermonitor;
iter = gst_pad_iterate_internal_links (GST_QA_PAD_MONITOR_GET_PAD (monitor));
done = FALSE;
while (!done) {
switch (gst_iterator_next (iter, (gpointer *) & otherpad)) {
case GST_ITERATOR_OK:
othermonitor = g_object_get_data ((GObject *) otherpad, "qa-monitor");
othermonitor->buffer_pushed = TRUE;
gst_object_unref (otherpad);
break;
case GST_ITERATOR_RESYNC:
gst_iterator_resync (iter);
break;
case GST_ITERATOR_ERROR:
GST_WARNING_OBJECT (monitor, "Internal links pad iteration error");
done = TRUE;
break;
case GST_ITERATOR_DONE:
done = TRUE;
break;
}
}
gst_iterator_free (iter);
}
static void
gst_qa_pad_monitor_check_first_buffer (GstQaPadMonitor * pad_monitor,
GstBuffer * buffer)
@ -370,20 +344,33 @@ static void
gst_qa_pad_monitor_update_buffer_data (GstQaPadMonitor * pad_monitor,
GstBuffer * buffer)
{
/* TODO handle reverse playback too */
pad_monitor->current_timestamp = GST_BUFFER_TIMESTAMP (buffer);
pad_monitor->current_duration = GST_BUFFER_DURATION (buffer);
if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer)) &&
GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
if (pad_monitor->buffer_pushed) {
if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_TIMESTAMP (buffer))) {
if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_start)) {
pad_monitor->timestamp_range_start =
MIN (pad_monitor->timestamp_range_start,
GST_BUFFER_TIMESTAMP (buffer));
} else {
pad_monitor->timestamp_range_start = GST_BUFFER_TIMESTAMP (buffer);
}
pad_monitor->timestamp_range_end = GST_BUFFER_TIMESTAMP (buffer) +
GST_BUFFER_DURATION (buffer);
} else {
pad_monitor->timestamp_range_start = GST_CLOCK_TIME_NONE;
pad_monitor->timestamp_range_end = GST_CLOCK_TIME_NONE;
if (GST_CLOCK_TIME_IS_VALID (GST_BUFFER_DURATION (buffer))) {
GstClockTime endts =
GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer);
if (GST_CLOCK_TIME_IS_VALID (pad_monitor->timestamp_range_end)) {
pad_monitor->timestamp_range_end =
MAX (pad_monitor->timestamp_range_end, endts);
} else {
pad_monitor->timestamp_range_end = endts;
}
}
}
pad_monitor->buffer_pushed = FALSE;
GST_DEBUG_OBJECT (pad_monitor, "Current stored range: %" GST_TIME_FORMAT
" - %" GST_TIME_FORMAT,
GST_TIME_ARGS (pad_monitor->timestamp_range_start),
GST_TIME_ARGS (pad_monitor->timestamp_range_end));
}
static GstFlowReturn
@ -827,7 +814,6 @@ gst_qa_pad_monitor_buffer_probe (GstPad * pad, GstBuffer * buffer,
gst_qa_pad_monitor_update_buffer_data (monitor, buffer);
gst_qa_pad_monitor_check_buffer_timestamp_in_received_range (monitor, buffer);
gst_qa_pad_monitor_notify_buffer_pushed (monitor);
/* TODO should we assume that a pad-monitor should always have an
* element-monitor as a parent? */

View file

@ -88,17 +88,16 @@ struct _GstQaPadMonitor {
GstFlowReturn last_flow_return;
/* Stores the current timestamp range of data
* in this pad by using TIMESTAMP and TIMESTAMP+DURATION from
* incomming buffers.
/* Stores the timestamp range of data that has flown through
* this pad by using TIMESTAMP and TIMESTAMP+DURATION from
* incomming buffers. Every time a buffer is pushed, this range
* is extended.
*
* If the internally linked pads haven't pushed a buffer, it will
* update the end to the new TIMESTAMP+DURATION, in case a buffer
* was pushed, the start is also updated to be TIMESTMAP.
* When a buffer is pushed, the timestamp range is checked against
* the outgoing timestamp to check it is in the received boundaries.
*/
GstClockTime timestamp_range_start;
GstClockTime timestamp_range_end;
gboolean buffer_pushed;
};
/**