summaryrefslogtreecommitdiff
path: root/tests/check/gst
diff options
context:
space:
mode:
authorEdward Hervey <edward@centricular.com>2015-06-12 10:53:23 +0200
committerEdward Hervey <bilboed@bilboed.com>2016-06-30 12:31:06 +0200
commit63f6f05d66537877365a1099ac176dc3afbb9f6b (patch)
treecfceacee50f7f534fec21aa30322664d5daa9858 /tests/check/gst
parent241d0f16f6fc363a17172a2cf1715af68182f2b5 (diff)
gst: New Stream listing/selection system
* GstStream * GstStreamCollection * GST_EVENT_SELECT_STREAMS * GST_MESSAGE_STREAM_COLLECTION
Diffstat (limited to 'tests/check/gst')
-rw-r--r--tests/check/gst/.gitignore1
-rw-r--r--tests/check/gst/gstevent.c56
-rw-r--r--tests/check/gst/gstmessage.c84
-rw-r--r--tests/check/gst/gststream.c225
-rw-r--r--tests/check/gst/gststream.h53
5 files changed, 419 insertions, 0 deletions
diff --git a/tests/check/gst/.gitignore b/tests/check/gst/.gitignore
index 623abeea3..865a4e52d 100644
--- a/tests/check/gst/.gitignore
+++ b/tests/check/gst/.gitignore
@@ -38,6 +38,7 @@ gstprintf
gstprotection
gstregistry
gstsegment
+gststream
gststructure
gstsystemclock
gsttag
diff --git a/tests/check/gst/gstevent.c b/tests/check/gst/gstevent.c
index 387f22985..ebb836ced 100644
--- a/tests/check/gst/gstevent.c
+++ b/tests/check/gst/gstevent.c
@@ -52,6 +52,31 @@ GST_START_TEST (create_events)
fail_unless (reset_time == TRUE);
gst_event_unref (event);
}
+ /* SELECT_STREAMS */
+ {
+ GList *streams = NULL;
+ GList *res = NULL;
+ GList *tmp;
+ streams = g_list_append (streams, (gpointer) "stream1");
+ streams = g_list_append (streams, (gpointer) "stream2");
+ event = gst_event_new_select_streams (streams);
+ fail_if (event == NULL);
+ fail_unless (GST_EVENT_TYPE (event) == GST_EVENT_SELECT_STREAMS);
+ fail_unless (GST_EVENT_IS_UPSTREAM (event));
+
+ gst_event_parse_select_streams (event, &res);
+ fail_if (res == NULL);
+ fail_unless_equals_int (g_list_length (res), 2);
+ tmp = res;
+ fail_unless_equals_string (tmp->data, "stream1");
+ tmp = tmp->next;
+ fail_unless_equals_string (tmp->data, "stream2");
+
+ gst_event_unref (event);
+
+ g_list_free (streams);
+ g_list_free_full (res, g_free);
+ }
/* EOS */
{
event = gst_event_new_eos ();
@@ -219,6 +244,37 @@ GST_START_TEST (create_events)
gst_event_unref (event);
}
+ /* STREAM_COLLECTION */
+ {
+ GstStreamCollection *collection, *res = NULL;
+ GstStream *stream1, *stream2;
+ GstCaps *caps1, *caps2;
+
+ /* Create a collection of two streams */
+ caps1 = gst_caps_from_string ("some/caps");
+ caps2 = gst_caps_from_string ("some/other-string");
+
+ stream1 = gst_stream_new ("stream-1", caps1, GST_STREAM_TYPE_AUDIO, 0);
+ stream2 = gst_stream_new ("stream-2", caps2, GST_STREAM_TYPE_VIDEO, 0);
+
+ collection = gst_stream_collection_new ("something");
+ fail_unless (gst_stream_collection_add_stream (collection, stream1));
+ fail_unless (gst_stream_collection_add_stream (collection, stream2));
+
+ event = gst_event_new_stream_collection (collection);
+ fail_unless (event != NULL);
+
+ gst_event_parse_stream_collection (event, &res);
+ fail_unless (res != NULL);
+ fail_unless (res == collection);
+
+ gst_event_unref (event);
+ gst_object_unref (res);
+ gst_object_unref (collection);
+ gst_caps_unref (caps1);
+ gst_caps_unref (caps2);
+ }
+
/* NAVIGATION */
{
structure = gst_structure_new ("application/x-gst-navigation", "event",
diff --git a/tests/check/gst/gstmessage.c b/tests/check/gst/gstmessage.c
index 94d5cdd16..8c404b29c 100644
--- a/tests/check/gst/gstmessage.c
+++ b/tests/check/gst/gstmessage.c
@@ -377,6 +377,90 @@ GST_START_TEST (test_parsing)
gst_message_unref (message);
}
+ /* GST_MESSAGE_STREAM_COLLECTION */
+ {
+ GstMessage *message;
+ GstStreamCollection *collection, *res = NULL;
+ GstStream *stream1, *stream2;
+ GstCaps *caps1, *caps2;
+
+ /* Create a collection of two streams */
+ caps1 = gst_caps_from_string ("some/caps");
+ caps2 = gst_caps_from_string ("some/other-string");
+
+ stream1 = gst_stream_new ("stream-1", caps1, GST_STREAM_TYPE_AUDIO, 0);
+ stream2 = gst_stream_new ("stream-2", caps2, GST_STREAM_TYPE_VIDEO, 0);
+
+ collection = gst_stream_collection_new ("something");
+ fail_unless (gst_stream_collection_add_stream (collection, stream1));
+ fail_unless (gst_stream_collection_add_stream (collection, stream2));
+
+ message = gst_message_new_stream_collection (NULL, collection);
+ fail_unless (message != NULL);
+
+ gst_message_parse_stream_collection (message, &res);
+ fail_unless (res != NULL);
+
+ gst_message_unref (message);
+ gst_object_unref (res);
+ gst_object_unref (collection);
+ gst_caps_unref (caps1);
+ gst_caps_unref (caps2);
+ }
+ /* GST_MESSAGE_STREAMS_SELECTED */
+ {
+ GstMessage *message;
+ GstStreamCollection *collection, *res = NULL;
+ GstStream *stream1, *stream2, *stream3;
+ GstCaps *caps1, *caps2;
+
+ /* Create a collection of two streams */
+ caps1 = gst_caps_from_string ("some/caps");
+ caps2 = gst_caps_from_string ("some/other-string");
+
+ stream1 = gst_stream_new ("stream-1", caps1, GST_STREAM_TYPE_AUDIO, 0);
+ stream2 = gst_stream_new ("stream-2", caps2, GST_STREAM_TYPE_VIDEO, 0);
+
+ collection = gst_stream_collection_new ("something");
+ fail_unless (gst_stream_collection_add_stream (collection, stream1));
+ fail_unless (gst_stream_collection_add_stream (collection, stream2));
+
+ message = gst_message_new_streams_selected (NULL, collection);
+ fail_unless (message != NULL);
+
+ gst_message_parse_streams_selected (message, &res);
+ fail_unless (res != NULL);
+
+ fail_unless (gst_message_streams_selected_get_size (message) == 0);
+ gst_object_unref (res);
+ gst_message_unref (message);
+
+ /* Once again, this time with a stream in it */
+ message = gst_message_new_streams_selected (NULL, collection);
+ fail_unless (message != NULL);
+
+ gst_message_streams_selected_add (message, stream1);
+
+ gst_message_parse_streams_selected (message, &res);
+ fail_unless (res != NULL);
+
+ /* There is only one stream ! */
+ fail_unless (gst_message_streams_selected_get_size (message) == 1);
+
+ stream3 = gst_message_streams_selected_get_stream (message, 0);
+ fail_unless (stream3 != NULL);
+ gst_object_unref (stream3);
+
+ /* Shoul fail */
+ ASSERT_CRITICAL (gst_message_streams_selected_get_stream (message, 1));
+
+ gst_object_unref (res);
+ gst_message_unref (message);
+
+ gst_object_unref (collection);
+ gst_caps_unref (caps1);
+ gst_caps_unref (caps2);
+ }
}
GST_END_TEST;
diff --git a/tests/check/gst/gststream.c b/tests/check/gst/gststream.c
new file mode 100644
index 000000000..aa09b2b7d
--- /dev/null
+++ b/tests/check/gst/gststream.c
@@ -0,0 +1,225 @@
+/* GStreamer
+ * Copyright (C) <2015> Edward Hervey <edward@centricular.com>
+ *
+ * gststructure.c: Unit tests for GstStream and GstStreamCollection
+ *
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+#include <gst/gst.h>
+#include <gst/check/gstcheck.h>
+
+GST_START_TEST (test_stream_creation)
+{
+ GstStream *stream;
+ GstCaps *caps;
+ GstCaps *caps2;
+ GstTagList *tags, *tags2;
+
+ caps = gst_caps_from_string ("some/caps");
+ stream = gst_stream_new ("stream-id", caps, GST_STREAM_TYPE_AUDIO, 0);
+ fail_unless (stream != NULL);
+
+ fail_unless_equals_string (gst_stream_get_stream_id (stream), "stream-id");
+ caps2 = gst_stream_get_caps (stream);
+ fail_unless (gst_caps_is_equal (caps, caps2));
+ gst_caps_unref (caps2);
+
+ fail_unless (gst_stream_get_stream_type (stream) == GST_STREAM_TYPE_AUDIO);
+
+ gst_caps_unref (caps);
+
+ tags = gst_tag_list_new (GST_TAG_ALBUM, "test-album", NULL);
+ g_object_set (stream, "tags", tags, NULL);
+ tags2 = gst_stream_get_tags (stream);
+ fail_unless (gst_tag_list_is_equal (tags, tags2));
+ gst_tag_list_unref (tags);
+ gst_tag_list_unref (tags2);
+
+ gst_object_unref (stream);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_stream_event)
+{
+ GstEvent *event;
+ GstStream *stream, *stream2 = NULL;
+ GstCaps *caps;
+ GstCaps *caps2;
+
+ event = gst_event_new_stream_start ("here/we/go");
+ /* By default a stream-start event has no stream */
+ gst_event_parse_stream (event, &stream2);
+ fail_if (stream2 != NULL);
+
+ /* Create and set stream on event */
+ caps = gst_caps_from_string ("some/caps");
+ stream = gst_stream_new ("here/we/go", caps, GST_STREAM_TYPE_AUDIO, 0);
+ fail_unless (stream != NULL);
+ gst_event_set_stream (event, stream);
+
+ /* Parse and check it's the same */
+ gst_event_parse_stream (event, &stream2);
+ fail_unless (stream2 != NULL);
+ fail_unless_equals_string (gst_stream_get_stream_id (stream2), "here/we/go");
+ caps2 = gst_stream_get_caps (stream);
+ fail_unless (gst_caps_is_equal (caps, caps2));
+ fail_unless (gst_stream_get_stream_type (stream) == GST_STREAM_TYPE_AUDIO);
+ gst_caps_unref (caps2);
+
+ gst_event_unref (event);
+ gst_caps_unref (caps);
+ gst_object_unref (stream);
+ gst_object_unref (stream2);
+}
+
+GST_END_TEST;
+
+struct NotifyStats
+{
+ guint collection_notify;
+ guint collection_notify_caps;
+ guint collection_notify_tags;
+ guint collection_notify_type;
+ guint collection_notify_flags;
+
+ guint stream_notify;
+ guint stream_notify_caps;
+ guint stream_notify_tags;
+ guint stream_notify_type;
+ guint stream_notify_flags;
+
+ guint stream2_notify;
+ guint stream2_notify_caps;
+ guint stream2_notify_tags;
+ guint stream2_notify_type;
+ guint stream2_notify_flags;
+};
+
+static void
+stream_notify_cb (GstStreamCollection * collection, GstStream * stream,
+ GParamSpec * pspec, guint * val)
+{
+ GST_LOG ("Got stream-notify from %" GST_PTR_FORMAT " for %s from %"
+ GST_PTR_FORMAT, stream, pspec->name, collection);
+ (*val)++;
+}
+
+static void
+notify_cb (GstStream * stream, GParamSpec * pspec, guint * val)
+{
+ GST_LOG ("Got notify from %" GST_PTR_FORMAT " for %s", stream, pspec->name);
+ (*val)++;
+}
+
+GST_START_TEST (test_notifies)
+{
+ GstStreamCollection *collection;
+ GstStream *stream, *stream2 = NULL;
+ GstCaps *caps;
+ struct NotifyStats stats = { 0, };
+ GstTagList *tags;
+
+ collection = gst_stream_collection_new ("check-collection");
+ g_signal_connect (collection, "stream-notify", (GCallback) stream_notify_cb,
+ &stats.collection_notify);
+ g_signal_connect (collection, "stream-notify::stream-type",
+ (GCallback) stream_notify_cb, &stats.collection_notify_type);
+ g_signal_connect (collection, "stream-notify::stream-flags",
+ (GCallback) stream_notify_cb, &stats.collection_notify_flags);
+ g_signal_connect (collection, "stream-notify::caps",
+ (GCallback) stream_notify_cb, &stats.collection_notify_caps);
+ g_signal_connect (collection, "stream-notify::tags",
+ (GCallback) stream_notify_cb, &stats.collection_notify_tags);
+
+ caps = gst_caps_from_string ("some/audio-caps");
+ stream = gst_stream_new ("here/we/go", caps, GST_STREAM_TYPE_AUDIO, 0);
+ gst_caps_unref (caps);
+ g_signal_connect (stream, "notify", (GCallback) notify_cb,
+ &stats.stream_notify);
+ g_signal_connect (stream, "notify::stream-type", (GCallback) notify_cb,
+ &stats.stream_notify_type);
+ g_signal_connect (stream, "notify::stream-flags", (GCallback) notify_cb,
+ &stats.stream_notify_flags);
+ g_signal_connect (stream, "notify::caps", (GCallback) notify_cb,
+ &stats.stream_notify_caps);
+ g_signal_connect (stream, "notify::tags", (GCallback) notify_cb,
+ &stats.stream_notify_tags);
+ gst_stream_collection_add_stream (collection, stream);
+
+ caps = gst_caps_from_string ("some/video-caps");
+ stream2 = gst_stream_new ("here/we/go/again", caps, GST_STREAM_TYPE_VIDEO, 0);
+ gst_caps_unref (caps);
+ g_signal_connect (stream2, "notify", (GCallback) notify_cb,
+ &stats.stream2_notify);
+ g_signal_connect (stream2, "notify::stream-type", (GCallback) notify_cb,
+ &stats.stream2_notify_type);
+ g_signal_connect (stream2, "notify::stream-flags", (GCallback) notify_cb,
+ &stats.stream2_notify_flags);
+ g_signal_connect (stream2, "notify::caps", (GCallback) notify_cb,
+ &stats.stream2_notify_caps);
+ g_signal_connect (stream2, "notify::tags", (GCallback) notify_cb,
+ &stats.stream2_notify_tags);
+ gst_stream_collection_add_stream (collection, stream2);
+
+ caps = gst_caps_from_string ("some/new-video-caps");
+ gst_stream_set_caps (stream2, caps);
+ gst_caps_unref (caps);
+
+ fail_unless (stats.collection_notify == 1);
+ fail_unless (stats.collection_notify_caps == 1);
+ fail_unless (stats.stream_notify == 0);
+ fail_unless (stats.stream_notify_caps == 0);
+ fail_unless (stats.stream_notify_tags == 0);
+ fail_unless (stats.stream2_notify == 1);
+ fail_unless (stats.stream2_notify_caps == 1);
+ fail_unless (stats.stream2_notify_tags == 0);
+
+ tags = gst_tag_list_new (GST_TAG_ALBUM, "test-album", NULL);
+ gst_stream_set_tags (stream, tags);
+ gst_tag_list_unref (tags);
+
+ fail_unless (stats.collection_notify == 2);
+ fail_unless (stats.collection_notify_caps == 1);
+ fail_unless (stats.collection_notify_tags == 1);
+ fail_unless (stats.stream_notify == 1);
+ fail_unless (stats.stream_notify_caps == 0);
+ fail_unless (stats.stream_notify_tags == 1);
+ fail_unless (stats.stream2_notify == 1);
+ fail_unless (stats.stream2_notify_caps == 1);
+ fail_unless (stats.stream2_notify_tags == 0);
+
+ gst_object_unref (collection);
+}
+
+GST_END_TEST;
+
+static Suite *
+gst_streams_suite (void)
+{
+ Suite *s = suite_create ("GstStream");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_stream_creation);
+ tcase_add_test (tc_chain, test_stream_event);
+ tcase_add_test (tc_chain, test_notifies);
+ return s;
+}
+
+GST_CHECK_MAIN (gst_streams);
diff --git a/tests/check/gst/gststream.h b/tests/check/gst/gststream.h
new file mode 100644
index 000000000..c2631bdff
--- /dev/null
+++ b/tests/check/gst/gststream.h
@@ -0,0 +1,53 @@
+/* GStreamer
+ * Copyright (C) <2015> Edward Hervey <edward@centricular.com>
+ *
+ * gststructure.c: Unit tests for GstStream and GstStreamCollection
+ *
+ * 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., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+#include <gst/gst.h>
+#include <gst/check/gstcheck.h>
+
+GST_START_TEST (test_stream_creation)
+{
+ GstStream *stream;
+ GstCaps *caps;
+
+ caps = gst_caps_from_string("some/caps");
+ stream = gst_stream_new ("upstream-id", caps, GST_STREAM_TYPE_AUDIO, 0);
+ fail_unless (stream != NULL);
+
+ fail_unless_equals_string (gst_stream_get_stream_id (stream), "upstream-id");
+
+ gst_object_unref (stream);
+}
+
+GST_END_TEST;
+
+static Suite *
+gst_streams_suite (void)
+{
+ Suite *s = suite_create ("GstStream");
+ TCase *tc_chain = tcase_create ("general");
+
+ suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_stream_creation);
+ return s;
+}
+
+GST_CHECK_MAIN (gst_streams);