adaptivedemux: Fix tests for delayed pad exposure.

Make the unit tests handle the fact that pads don't appear
immediately. Before, the test assumed pads are exposed before the
internal source element is created, which is no longer true.
This commit is contained in:
Jan Schmidt 2017-02-08 22:59:49 +11:00
parent aca89aeeaa
commit 309368bac3
2 changed files with 39 additions and 10 deletions

View file

@ -40,6 +40,7 @@ adaptive_demux_engine_stream_state_finalize (gpointer data)
{
GstAdaptiveDemuxTestOutputStream *stream =
(GstAdaptiveDemuxTestOutputStream *) data;
g_free (stream->name);
if (stream->appsink)
gst_object_unref (stream->appsink);
if (stream->pad)
@ -86,6 +87,27 @@ getTestOutputDataByPad (GstAdaptiveDemuxTestEnginePrivate * priv,
return NULL;
}
/* get the output stream entry in corresponding to the given Pad */
static GstAdaptiveDemuxTestOutputStream *
getTestOutputDataByName (GstAdaptiveDemuxTestEnginePrivate * priv,
const gchar * name, gboolean abort_if_not_found)
{
guint i;
for (i = 0; i < priv->engine.output_streams->len; ++i) {
GstAdaptiveDemuxTestOutputStream *stream;
stream = g_ptr_array_index (priv->engine.output_streams, i);
if (strstr (stream->name, name) != NULL) {
return stream;
}
}
if (abort_if_not_found)
ck_abort_msg ("cannot find pad %s in the output data", name);
return NULL;
}
/* callback called when AppSink receives data */
/* callback called when AppSink receives data */
static GstFlowReturn
on_appSinkNewSample (GstAppSink * appsink, gpointer user_data)
@ -262,16 +284,17 @@ on_demuxElementAdded (GstBin * demux, GstElement * element, gpointer user_data)
GstAdaptiveDemuxTestOutputStream *stream = NULL;
GstPad *internal_pad;
gchar *srcbin_name;
gint i;
srcbin_name = GST_ELEMENT_NAME (element);
GST_TEST_LOCK (priv);
for (i = 0; i < priv->engine.output_streams->len; i++) {
stream = g_ptr_array_index (priv->engine.output_streams, i);
if (strstr (srcbin_name, GST_PAD_NAME (stream->pad)) != NULL)
break;
stream = getTestOutputDataByName (priv, srcbin_name, FALSE);
if (stream == NULL) {
/* Pad wasn't exposed yet, create the stream */
stream = g_slice_new0 (GstAdaptiveDemuxTestOutputStream);
stream->name = g_strdup (srcbin_name);
g_ptr_array_add (priv->engine.output_streams, stream);
}
fail_unless (stream != NULL);
/* keep the reference to the internal_pad.
* We will need it to identify the stream in the on_demuxReceivesEvent callback
@ -310,8 +333,14 @@ on_demuxNewPad (GstElement * demux, GstPad * pad, gpointer user_data)
fail_unless (priv != NULL);
name = gst_pad_get_name (pad);
GST_DEBUG ("demux created pad %p", pad);
stream = getTestOutputDataByName (priv, name, FALSE);
if (stream == NULL) {
stream = g_slice_new0 (GstAdaptiveDemuxTestOutputStream);
GST_DEBUG ("created pad %p", pad);
stream->name = g_strdup (name);
g_ptr_array_add (priv->engine.output_streams, stream);
}
sink = gst_element_factory_make ("appsink", name);
g_free (name);
@ -347,8 +376,6 @@ on_demuxNewPad (GstElement * demux, GstPad * pad, gpointer user_data)
}
stream->pad = gst_object_ref (pad);
g_ptr_array_add (priv->engine.output_streams, stream);
GST_TEST_UNLOCK (priv);
pipeline = GST_ELEMENT (gst_element_get_parent (demux));

View file

@ -30,6 +30,8 @@ G_BEGIN_DECLS
typedef struct _GstAdaptiveDemuxTestEngine GstAdaptiveDemuxTestEngine;
typedef struct _GstAdaptiveDemuxTestOutputStream {
gchar *name;
/* the GstAppSink element getting the data for this stream */
GstAppSink *appsink;
GstPad *pad;