"Fossies" - the Fresh Open Source Software Archive

Member "gstreamer-1.16.1/tests/check/gst/gststream.c" (19 Apr 2019, 7606 Bytes) of package /linux/misc/gstreamer-1.16.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* GStreamer
    2  * Copyright (C) <2015> Edward Hervey <edward@centricular.com>
    3  *
    4  * gststructure.c: Unit tests for GstStream and GstStreamCollection
    5  *
    6  * This library is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU Library General Public
    8  * License as published by the Free Software Foundation; either
    9  * version 2 of the License, or (at your option) any later version.
   10  *
   11  * This library is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14  * Library General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU Library General Public
   17  * License along with this library; if not, write to the
   18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
   19  * Boston, MA 02110-1301, USA.
   20  */
   21 #ifdef HAVE_CONFIG_H
   22 #include "config.h"
   23 #endif
   24 
   25 #include <gst/gst.h>
   26 #include <gst/check/gstcheck.h>
   27 
   28 GST_START_TEST (test_stream_creation)
   29 {
   30   GstStream *stream;
   31   GstCaps *caps;
   32   GstCaps *caps2;
   33   GstTagList *tags, *tags2;
   34 
   35   caps = gst_caps_from_string ("some/caps");
   36   stream = gst_stream_new ("stream-id", caps, GST_STREAM_TYPE_AUDIO, 0);
   37   fail_unless (stream != NULL);
   38 
   39   fail_unless_equals_string (gst_stream_get_stream_id (stream), "stream-id");
   40   caps2 = gst_stream_get_caps (stream);
   41   fail_unless (gst_caps_is_equal (caps, caps2));
   42   gst_caps_unref (caps2);
   43 
   44   fail_unless (gst_stream_get_stream_type (stream) == GST_STREAM_TYPE_AUDIO);
   45 
   46   gst_caps_unref (caps);
   47 
   48   tags = gst_tag_list_new (GST_TAG_ALBUM, "test-album", NULL);
   49   g_object_set (stream, "tags", tags, NULL);
   50   tags2 = gst_stream_get_tags (stream);
   51   fail_unless (gst_tag_list_is_equal (tags, tags2));
   52   gst_tag_list_unref (tags);
   53   gst_tag_list_unref (tags2);
   54 
   55   gst_object_unref (stream);
   56 }
   57 
   58 GST_END_TEST;
   59 
   60 GST_START_TEST (test_stream_event)
   61 {
   62   GstEvent *event;
   63   GstStream *stream, *stream2 = NULL;
   64   GstCaps *caps;
   65   GstCaps *caps2;
   66 
   67   event = gst_event_new_stream_start ("here/we/go");
   68   /* By default a stream-start event has no stream */
   69   gst_event_parse_stream (event, &stream2);
   70   fail_if (stream2 != NULL);
   71 
   72   /* Create and set stream on event */
   73   caps = gst_caps_from_string ("some/caps");
   74   stream = gst_stream_new ("here/we/go", caps, GST_STREAM_TYPE_AUDIO, 0);
   75   fail_unless (stream != NULL);
   76   gst_event_set_stream (event, stream);
   77 
   78   /* Parse and check it's the same */
   79   gst_event_parse_stream (event, &stream2);
   80   fail_unless (stream2 != NULL);
   81   fail_unless_equals_string (gst_stream_get_stream_id (stream2), "here/we/go");
   82   caps2 = gst_stream_get_caps (stream);
   83   fail_unless (gst_caps_is_equal (caps, caps2));
   84   fail_unless (gst_stream_get_stream_type (stream) == GST_STREAM_TYPE_AUDIO);
   85   gst_caps_unref (caps2);
   86 
   87   gst_event_unref (event);
   88   gst_caps_unref (caps);
   89   gst_object_unref (stream);
   90   gst_object_unref (stream2);
   91 }
   92 
   93 GST_END_TEST;
   94 
   95 struct NotifyStats
   96 {
   97   guint collection_notify;
   98   guint collection_notify_caps;
   99   guint collection_notify_tags;
  100   guint collection_notify_type;
  101   guint collection_notify_flags;
  102 
  103   guint stream_notify;
  104   guint stream_notify_caps;
  105   guint stream_notify_tags;
  106   guint stream_notify_type;
  107   guint stream_notify_flags;
  108 
  109   guint stream2_notify;
  110   guint stream2_notify_caps;
  111   guint stream2_notify_tags;
  112   guint stream2_notify_type;
  113   guint stream2_notify_flags;
  114 };
  115 
  116 static void
  117 stream_notify_cb (GstStreamCollection * collection, GstStream * stream,
  118     GParamSpec * pspec, guint * val)
  119 {
  120   GST_LOG ("Got stream-notify from %" GST_PTR_FORMAT " for %s from %"
  121       GST_PTR_FORMAT, stream, pspec->name, collection);
  122   (*val)++;
  123 }
  124 
  125 static void
  126 notify_cb (GstStream * stream, GParamSpec * pspec, guint * val)
  127 {
  128   GST_LOG ("Got notify from %" GST_PTR_FORMAT " for %s", stream, pspec->name);
  129   (*val)++;
  130 }
  131 
  132 GST_START_TEST (test_notifies)
  133 {
  134   GstStreamCollection *collection;
  135   GstStream *stream, *stream2 = NULL;
  136   GstCaps *caps;
  137   struct NotifyStats stats = { 0, };
  138   GstTagList *tags;
  139 
  140   collection = gst_stream_collection_new ("check-collection");
  141   g_signal_connect (collection, "stream-notify", (GCallback) stream_notify_cb,
  142       &stats.collection_notify);
  143   g_signal_connect (collection, "stream-notify::stream-type",
  144       (GCallback) stream_notify_cb, &stats.collection_notify_type);
  145   g_signal_connect (collection, "stream-notify::stream-flags",
  146       (GCallback) stream_notify_cb, &stats.collection_notify_flags);
  147   g_signal_connect (collection, "stream-notify::caps",
  148       (GCallback) stream_notify_cb, &stats.collection_notify_caps);
  149   g_signal_connect (collection, "stream-notify::tags",
  150       (GCallback) stream_notify_cb, &stats.collection_notify_tags);
  151 
  152   caps = gst_caps_from_string ("some/audio-caps");
  153   stream = gst_stream_new ("here/we/go", caps, GST_STREAM_TYPE_AUDIO, 0);
  154   gst_caps_unref (caps);
  155   g_signal_connect (stream, "notify", (GCallback) notify_cb,
  156       &stats.stream_notify);
  157   g_signal_connect (stream, "notify::stream-type", (GCallback) notify_cb,
  158       &stats.stream_notify_type);
  159   g_signal_connect (stream, "notify::stream-flags", (GCallback) notify_cb,
  160       &stats.stream_notify_flags);
  161   g_signal_connect (stream, "notify::caps", (GCallback) notify_cb,
  162       &stats.stream_notify_caps);
  163   g_signal_connect (stream, "notify::tags", (GCallback) notify_cb,
  164       &stats.stream_notify_tags);
  165   gst_stream_collection_add_stream (collection, stream);
  166 
  167   caps = gst_caps_from_string ("some/video-caps");
  168   stream2 = gst_stream_new ("here/we/go/again", caps, GST_STREAM_TYPE_VIDEO, 0);
  169   gst_caps_unref (caps);
  170   g_signal_connect (stream2, "notify", (GCallback) notify_cb,
  171       &stats.stream2_notify);
  172   g_signal_connect (stream2, "notify::stream-type", (GCallback) notify_cb,
  173       &stats.stream2_notify_type);
  174   g_signal_connect (stream2, "notify::stream-flags", (GCallback) notify_cb,
  175       &stats.stream2_notify_flags);
  176   g_signal_connect (stream2, "notify::caps", (GCallback) notify_cb,
  177       &stats.stream2_notify_caps);
  178   g_signal_connect (stream2, "notify::tags", (GCallback) notify_cb,
  179       &stats.stream2_notify_tags);
  180   gst_stream_collection_add_stream (collection, stream2);
  181 
  182   caps = gst_caps_from_string ("some/new-video-caps");
  183   gst_stream_set_caps (stream2, caps);
  184   gst_caps_unref (caps);
  185 
  186   fail_unless (stats.collection_notify == 1);
  187   fail_unless (stats.collection_notify_caps == 1);
  188   fail_unless (stats.stream_notify == 0);
  189   fail_unless (stats.stream_notify_caps == 0);
  190   fail_unless (stats.stream_notify_tags == 0);
  191   fail_unless (stats.stream2_notify == 1);
  192   fail_unless (stats.stream2_notify_caps == 1);
  193   fail_unless (stats.stream2_notify_tags == 0);
  194 
  195   tags = gst_tag_list_new (GST_TAG_ALBUM, "test-album", NULL);
  196   gst_stream_set_tags (stream, tags);
  197   gst_tag_list_unref (tags);
  198 
  199   fail_unless (stats.collection_notify == 2);
  200   fail_unless (stats.collection_notify_caps == 1);
  201   fail_unless (stats.collection_notify_tags == 1);
  202   fail_unless (stats.stream_notify == 1);
  203   fail_unless (stats.stream_notify_caps == 0);
  204   fail_unless (stats.stream_notify_tags == 1);
  205   fail_unless (stats.stream2_notify == 1);
  206   fail_unless (stats.stream2_notify_caps == 1);
  207   fail_unless (stats.stream2_notify_tags == 0);
  208 
  209   gst_object_unref (collection);
  210 }
  211 
  212 GST_END_TEST;
  213 
  214 static Suite *
  215 gst_streams_suite (void)
  216 {
  217   Suite *s = suite_create ("GstStream");
  218   TCase *tc_chain = tcase_create ("general");
  219 
  220   suite_add_tcase (s, tc_chain);
  221   tcase_add_test (tc_chain, test_stream_creation);
  222   tcase_add_test (tc_chain, test_stream_event);
  223   tcase_add_test (tc_chain, test_notifies);
  224   return s;
  225 }
  226 
  227 GST_CHECK_MAIN (gst_streams);