2009-07-13 07:22:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit testing helper lib
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstcheckconsistencychecker
|
|
|
|
* @short_description: Data flow consistency checker for GStreamer unit tests.
|
|
|
|
*
|
|
|
|
* These macros and functions are for internal use of the unit tests found
|
|
|
|
* inside the 'check' directories of various GStreamer packages.
|
|
|
|
*
|
|
|
|
* Since: 0.10.24
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gstconsistencychecker.h"
|
|
|
|
|
2009-07-28 14:23:15 +00:00
|
|
|
struct _GstStreamConsistency
|
|
|
|
{
|
|
|
|
gboolean flushing;
|
2011-05-13 16:07:24 +00:00
|
|
|
gboolean segment;
|
2009-07-28 14:23:15 +00:00
|
|
|
gboolean eos;
|
|
|
|
gulong probeid;
|
|
|
|
GstPad *pad;
|
|
|
|
};
|
|
|
|
|
2009-07-13 07:22:06 +00:00
|
|
|
static gboolean
|
2011-11-08 10:04:19 +00:00
|
|
|
source_pad_data_cb (GstPad * pad, GstPadProbeInfo * info,
|
2009-07-13 07:22:06 +00:00
|
|
|
GstStreamConsistency * consist)
|
|
|
|
{
|
2011-11-08 10:04:19 +00:00
|
|
|
GstMiniObject *data = GST_PAD_PROBE_INFO_DATA (info);
|
|
|
|
|
2009-07-13 07:22:06 +00:00
|
|
|
if (GST_IS_BUFFER (data)) {
|
2011-10-28 10:17:58 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
|
|
|
"Buffer pts %" GST_TIME_FORMAT ", dts %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_PTS (GST_BUFFER_CAST (data))),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_DTS (GST_BUFFER_CAST (data))));
|
2009-07-13 07:22:06 +00:00
|
|
|
/* If an EOS went through, a buffer would be invalid */
|
|
|
|
fail_if (consist->eos, "Buffer received after EOS");
|
2011-05-13 16:07:24 +00:00
|
|
|
/* Buffers need to be preceded by a segment event */
|
|
|
|
fail_unless (consist->segment, "Buffer received without segment");
|
2009-10-08 06:55:23 +00:00
|
|
|
} else if (GST_IS_EVENT (data)) {
|
2009-07-13 07:22:06 +00:00
|
|
|
GstEvent *event = (GstEvent *) data;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "%s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
consist->flushing = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
/* Receiving a flush-stop is only valid after receiving a flush-start */
|
|
|
|
fail_unless (consist->flushing,
|
|
|
|
"Received a FLUSH_STOP without a FLUSH_START");
|
|
|
|
fail_if (consist->eos, "Received a FLUSH_STOP after an EOS");
|
|
|
|
consist->flushing = FALSE;
|
|
|
|
break;
|
2011-05-13 16:07:24 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
consist->segment = TRUE;
|
2009-07-13 07:22:06 +00:00
|
|
|
consist->eos = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
/* FIXME : not 100% sure about whether two eos in a row is valid */
|
|
|
|
fail_if (consist->eos, "Received EOS just after another EOS");
|
|
|
|
consist->eos = TRUE;
|
2011-05-13 16:07:24 +00:00
|
|
|
consist->segment = FALSE;
|
2009-07-13 07:22:06 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_TAG:
|
2011-05-10 09:50:16 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "tag %" GST_PTR_FORMAT,
|
|
|
|
gst_event_get_structure (event));
|
2011-01-12 10:44:59 +00:00
|
|
|
/* fall through */
|
2009-07-13 07:22:06 +00:00
|
|
|
default:
|
|
|
|
if (GST_EVENT_IS_SERIALIZED (event) && GST_EVENT_IS_DOWNSTREAM (event)) {
|
|
|
|
fail_if (consist->eos, "Event received after EOS");
|
2011-05-13 16:07:24 +00:00
|
|
|
fail_unless (consist->segment, "Event received before segment");
|
2009-07-13 07:22:06 +00:00
|
|
|
}
|
|
|
|
/* FIXME : Figure out what to do for other events */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_consistency_checker_new:
|
|
|
|
* @pad: The #GstPad on which the dataflow will be checked.
|
|
|
|
*
|
|
|
|
* Sets up a data probe on the given pad which will raise assertions if the
|
|
|
|
* data flow is inconsistent.
|
|
|
|
*
|
|
|
|
* Currently only works for source pads.
|
|
|
|
*
|
|
|
|
* Returns: A #GstStreamConsistency structure used to track data flow.
|
|
|
|
*
|
|
|
|
* Since: 0.10.24
|
|
|
|
*/
|
|
|
|
|
|
|
|
GstStreamConsistency *
|
|
|
|
gst_consistency_checker_new (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstStreamConsistency *consist;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
|
|
|
|
consist = g_new0 (GstStreamConsistency, 1);
|
|
|
|
consist->pad = g_object_ref (pad);
|
|
|
|
consist->probeid =
|
2011-11-07 16:04:13 +00:00
|
|
|
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
|
2011-05-31 17:16:09 +00:00
|
|
|
(GstPadProbeCallback) source_pad_data_cb, consist, NULL);
|
2009-07-13 07:22:06 +00:00
|
|
|
|
|
|
|
return consist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_consistency_checker_reset:
|
|
|
|
* @consist: The #GstStreamConsistency to reset.
|
|
|
|
*
|
|
|
|
* Reset the stream checker's internal variables.
|
|
|
|
*
|
|
|
|
* Since: 0.10.24
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_consistency_checker_reset (GstStreamConsistency * consist)
|
|
|
|
{
|
|
|
|
consist->eos = FALSE;
|
|
|
|
consist->flushing = FALSE;
|
2011-05-13 16:07:24 +00:00
|
|
|
consist->segment = FALSE;
|
2009-07-13 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_consistency_checker_free:
|
|
|
|
* @consist: The #GstStreamConsistency to free.
|
|
|
|
*
|
|
|
|
* Frees the allocated data and probe associated with @consist.
|
|
|
|
*
|
|
|
|
* Since: 0.10.24
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_consistency_checker_free (GstStreamConsistency * consist)
|
|
|
|
{
|
|
|
|
/* Remove the data probe */
|
2011-05-31 17:16:09 +00:00
|
|
|
gst_pad_remove_probe (consist->pad, consist->probeid);
|
2009-07-13 07:22:06 +00:00
|
|
|
g_object_unref (consist->pad);
|
|
|
|
g_free (consist);
|
|
|
|
}
|