2009-07-13 07:22:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit testing helper lib
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Edward Hervey <bilboed@bilboed.com>
|
2012-02-29 20:57:00 +00:00
|
|
|
* Copyright (C) 2012 Stefan Sauer <ensonic@users.sf.net>
|
2009-07-13 07:22:06 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-07-13 07:22:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gstcheckconsistencychecker
|
2017-01-16 14:26:16 +00:00
|
|
|
* @title: GstStreamConsistencyChecker
|
2009-07-13 07:22:06 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
2018-08-25 21:56:01 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2009-07-13 07:22:06 +00:00
|
|
|
|
|
|
|
#include "gstconsistencychecker.h"
|
|
|
|
|
2009-07-28 14:23:15 +00:00
|
|
|
struct _GstStreamConsistency
|
|
|
|
{
|
2012-02-29 20:57:00 +00:00
|
|
|
/* FIXME: do we want to track some states per pad? */
|
2021-03-18 03:46:15 +00:00
|
|
|
gboolean flushing;
|
|
|
|
gboolean segment;
|
|
|
|
gboolean eos;
|
|
|
|
gboolean expect_flush;
|
|
|
|
gboolean saw_serialized_event;
|
|
|
|
gboolean saw_stream_start;
|
2012-02-29 20:57:00 +00:00
|
|
|
GstObject *parent;
|
|
|
|
GList *pads;
|
2009-07-28 14:23:15 +00:00
|
|
|
};
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
typedef struct _GstStreamConsistencyProbe
|
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
gulong probeid;
|
|
|
|
} GstStreamConsistencyProbe;
|
|
|
|
|
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);
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "%p: %d %d %d %d", consist, consist->flushing,
|
2012-03-01 13:51:26 +00:00
|
|
|
consist->segment, consist->eos, consist->expect_flush);
|
2012-02-29 20:57:00 +00:00
|
|
|
|
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 */
|
2012-08-12 18:39:46 +00:00
|
|
|
fail_if (consist->eos, "Buffer received after EOS on pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2011-05-13 16:07:24 +00:00
|
|
|
/* Buffers need to be preceded by a segment event */
|
2012-08-12 18:39:46 +00:00
|
|
|
fail_unless (consist->segment, "Buffer received without segment "
|
|
|
|
"on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
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;
|
|
|
|
|
2012-07-06 09:38:58 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Event : %s", GST_EVENT_TYPE_NAME (event));
|
2009-07-13 07:22:06 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_START:
|
2012-03-02 11:16:03 +00:00
|
|
|
/* getting two flush_start in a row seems to be okay
|
|
|
|
fail_if (consist->flushing, "Received another FLUSH_START");
|
|
|
|
*/
|
2009-07-13 07:22:06 +00:00
|
|
|
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,
|
2012-08-12 18:39:46 +00:00
|
|
|
"Received a FLUSH_STOP without a FLUSH_START on pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
|
|
|
fail_if (consist->eos, "Received a FLUSH_STOP after an EOS on "
|
|
|
|
"pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
2012-02-29 20:57:00 +00:00
|
|
|
consist->flushing = consist->expect_flush = FALSE;
|
2009-07-13 07:22:06 +00:00
|
|
|
break;
|
2012-04-03 16:25:40 +00:00
|
|
|
case GST_EVENT_STREAM_START:
|
2012-07-06 09:38:58 +00:00
|
|
|
fail_if (consist->saw_serialized_event && !consist->saw_stream_start,
|
2012-08-12 18:39:46 +00:00
|
|
|
"Got a STREAM_START event after a serialized event on pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2012-07-06 09:38:58 +00:00
|
|
|
consist->saw_stream_start = TRUE;
|
|
|
|
break;
|
2012-04-03 16:25:40 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
/* ok to have these before segment event */
|
|
|
|
/* FIXME check order more precisely, if so spec'ed somehow ? */
|
|
|
|
break;
|
2011-05-13 16:07:24 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2012-02-29 20:57:00 +00:00
|
|
|
fail_if ((consist->expect_flush && consist->flushing),
|
2012-08-12 18:39:46 +00:00
|
|
|
"Received SEGMENT while in a flushing seek on pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2011-05-13 16:07:24 +00:00
|
|
|
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 */
|
2012-08-12 18:39:46 +00:00
|
|
|
fail_if (consist->eos, "Received EOS just after another EOS on "
|
|
|
|
"pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
2009-07-13 07:22:06 +00:00
|
|
|
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");
|
2012-08-12 18:39:46 +00:00
|
|
|
fail_unless (consist->segment, "Event %s received before segment "
|
|
|
|
"on pad %s:%s", GST_EVENT_TYPE_NAME (event),
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2009-07-13 07:22:06 +00:00
|
|
|
}
|
|
|
|
/* FIXME : Figure out what to do for other events */
|
|
|
|
break;
|
|
|
|
}
|
2012-07-06 09:38:58 +00:00
|
|
|
if (GST_EVENT_IS_SERIALIZED (event)) {
|
|
|
|
fail_if (!consist->saw_stream_start
|
|
|
|
&& GST_EVENT_TYPE (event) != GST_EVENT_STREAM_START,
|
2012-08-12 18:39:46 +00:00
|
|
|
"Got a serialized event (%s) before a STREAM_START on pad %s:%s",
|
|
|
|
GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (pad));
|
2012-07-06 09:38:58 +00:00
|
|
|
consist->saw_serialized_event = TRUE;
|
|
|
|
}
|
2009-07-13 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
static gboolean
|
2012-03-01 13:43:01 +00:00
|
|
|
sink_pad_data_cb (GstPad * pad, GstPadProbeInfo * info,
|
2012-02-29 20:57:00 +00:00
|
|
|
GstStreamConsistency * consist)
|
|
|
|
{
|
2012-03-01 13:43:01 +00:00
|
|
|
GstMiniObject *data = GST_PAD_PROBE_INFO_DATA (info);
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "%p: %d %d %d %d", consist, consist->flushing,
|
2012-03-01 13:51:26 +00:00
|
|
|
consist->segment, consist->eos, consist->expect_flush);
|
2012-02-29 20:57:00 +00:00
|
|
|
|
|
|
|
if (GST_IS_BUFFER (data)) {
|
|
|
|
GST_DEBUG_OBJECT (pad, "Buffer %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (GST_BUFFER (data))));
|
|
|
|
/* If an EOS went through, a buffer would be invalid */
|
2012-08-12 18:39:46 +00:00
|
|
|
fail_if (consist->eos, "Buffer received after EOS on pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2012-03-01 13:51:26 +00:00
|
|
|
/* Buffers need to be preceded by a segment event */
|
2012-08-12 18:39:46 +00:00
|
|
|
fail_unless (consist->segment, "Buffer received without segment "
|
|
|
|
"on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
2012-02-29 20:57:00 +00:00
|
|
|
} else if (GST_IS_EVENT (data)) {
|
|
|
|
GstEvent *event = (GstEvent *) data;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "%s", GST_EVENT_TYPE_NAME (event));
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
GstSeekFlags flags;
|
|
|
|
|
|
|
|
gst_event_parse_seek (event, NULL, NULL, &flags, NULL, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
consist->expect_flush =
|
|
|
|
((flags & GST_SEEK_FLAG_FLUSH) == GST_SEEK_FLAG_FLUSH);
|
|
|
|
break;
|
|
|
|
}
|
2012-03-01 13:43:01 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2012-02-29 20:57:00 +00:00
|
|
|
fail_if ((consist->expect_flush && consist->flushing),
|
2012-08-12 18:39:46 +00:00
|
|
|
"Received SEGMENT while in a flushing seek on pad %s:%s",
|
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2012-03-01 13:43:01 +00:00
|
|
|
consist->segment = TRUE;
|
2012-02-29 20:57:00 +00:00
|
|
|
consist->eos = FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* FIXME : Figure out what to do for other events */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_pad (GstStreamConsistency * consist, GstPad * pad)
|
|
|
|
{
|
|
|
|
GstStreamConsistencyProbe *p;
|
|
|
|
GstPadDirection dir;
|
|
|
|
|
|
|
|
p = g_new0 (GstStreamConsistencyProbe, 1);
|
|
|
|
p->pad = g_object_ref (pad);
|
|
|
|
dir = gst_pad_get_direction (pad);
|
|
|
|
if (dir == GST_PAD_SRC) {
|
2012-03-01 13:43:01 +00:00
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
p->probeid =
|
2012-03-01 13:43:01 +00:00
|
|
|
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
|
|
|
|
(GstPadProbeCallback) source_pad_data_cb, consist, NULL);
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
} else if (dir == GST_PAD_SINK) {
|
|
|
|
p->probeid =
|
2012-03-01 13:43:01 +00:00
|
|
|
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
|
|
|
|
(GstPadProbeCallback) sink_pad_data_cb, consist, NULL);
|
2012-02-29 20:57:00 +00:00
|
|
|
}
|
|
|
|
consist->pads = g_list_prepend (consist->pads, p);
|
|
|
|
}
|
|
|
|
|
2009-07-13 07:22:06 +00:00
|
|
|
/**
|
2015-06-13 23:47:45 +00:00
|
|
|
* gst_consistency_checker_new: (skip)
|
2009-07-13 07:22:06 +00:00
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* Returns: A #GstStreamConsistency structure used to track data flow.
|
|
|
|
*/
|
|
|
|
GstStreamConsistency *
|
|
|
|
gst_consistency_checker_new (GstPad * pad)
|
|
|
|
{
|
|
|
|
GstStreamConsistency *consist;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
|
|
|
|
consist = g_new0 (GstStreamConsistency, 1);
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
if (!consist->pads) {
|
|
|
|
consist->parent = GST_OBJECT_PARENT (pad);
|
|
|
|
}
|
|
|
|
add_pad (consist, pad);
|
2009-07-13 07:22:06 +00:00
|
|
|
return consist;
|
|
|
|
}
|
|
|
|
|
2012-02-29 20:57:00 +00:00
|
|
|
/**
|
|
|
|
* gst_consistency_checker_add_pad:
|
|
|
|
* @consist: The #GstStreamConsistency handle
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the pad was added
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_consistency_checker_add_pad (GstStreamConsistency * consist, GstPad * pad)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (consist != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (pad != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_OBJECT_PARENT (pad) == consist->parent, FALSE);
|
|
|
|
|
|
|
|
add_pad (consist, pad);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-13 07:22:06 +00:00
|
|
|
/**
|
|
|
|
* gst_consistency_checker_reset:
|
|
|
|
* @consist: The #GstStreamConsistency to reset.
|
|
|
|
*
|
|
|
|
* Reset the stream checker's internal variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_consistency_checker_reset (GstStreamConsistency * consist)
|
|
|
|
{
|
|
|
|
consist->flushing = FALSE;
|
2011-05-13 16:07:24 +00:00
|
|
|
consist->segment = FALSE;
|
2012-07-06 09:38:58 +00:00
|
|
|
consist->eos = FALSE;
|
|
|
|
consist->expect_flush = FALSE;
|
|
|
|
consist->saw_serialized_event = FALSE;
|
|
|
|
consist->saw_stream_start = FALSE;
|
2009-07-13 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_consistency_checker_free:
|
|
|
|
* @consist: The #GstStreamConsistency to free.
|
|
|
|
*
|
2012-02-29 20:57:00 +00:00
|
|
|
* Frees the allocated data and probes associated with @consist.
|
2009-07-13 07:22:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_consistency_checker_free (GstStreamConsistency * consist)
|
|
|
|
{
|
2012-02-29 20:57:00 +00:00
|
|
|
GList *node;
|
|
|
|
GstStreamConsistencyProbe *p;
|
|
|
|
|
|
|
|
/* Remove the data probes */
|
|
|
|
for (node = consist->pads; node; node = g_list_next (node)) {
|
|
|
|
p = (GstStreamConsistencyProbe *) node->data;
|
2012-03-01 13:43:01 +00:00
|
|
|
gst_pad_remove_probe (p->pad, p->probeid);
|
2012-04-12 12:59:31 +00:00
|
|
|
gst_object_unref (p->pad);
|
2012-02-29 20:57:00 +00:00
|
|
|
g_free (p);
|
|
|
|
}
|
|
|
|
g_list_free (consist->pads);
|
2009-07-13 07:22:06 +00:00
|
|
|
g_free (consist);
|
|
|
|
}
|