• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net>
3  *
4  * unit test for the baseaudiovisualizer class
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 
22 #undef GST_CAT_DEFAULT
23 
24 #include <gst/check/gstcheck.h>
25 #include <gst/pbutils/gstaudiovisualizer.h>
26 #include <string.h>
27 
28 /* dummy subclass for testing */
29 
30 #define GST_TYPE_TEST_SCOPE            (gst_test_scope_get_type())
31 #define GST_TEST_SCOPE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TEST_SCOPE,GstTestScope))
32 #define GST_TEST_SCOPE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TEST_SCOPE,GstTestScopeClass))
33 typedef struct _GstTestScope GstTestScope;
34 typedef struct _GstTestScopeClass GstTestScopeClass;
35 
36 struct _GstTestScope
37 {
38   GstAudioVisualizer parent;
39 };
40 
41 struct _GstTestScopeClass
42 {
43   GstAudioVisualizerClass parent_class;
44 };
45 
46 static GstStaticPadTemplate gst_test_scope_src_template =
47 GST_STATIC_PAD_TEMPLATE ("src",
48     GST_PAD_SRC,
49     GST_PAD_ALWAYS,
50     GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("xRGB"))
51     );
52 
53 static GstStaticPadTemplate gst_test_scope_sink_template =
54 GST_STATIC_PAD_TEMPLATE ("sink",
55     GST_PAD_SINK,
56     GST_PAD_ALWAYS,
57     GST_STATIC_CAPS ("audio/x-raw, "
58         "format = (string) " GST_AUDIO_NE (S16) ", "
59         "layout = (string) interleaved, "
60         "channels = (int) 2, "
61         "channel-mask = (bitmask) 3, " "rate = (int) 44100")
62     );
63 
64 static GType gst_test_scope_get_type (void);
65 
66 G_DEFINE_TYPE (GstTestScope, gst_test_scope, GST_TYPE_AUDIO_VISUALIZER);
67 
68 static void
gst_test_scope_class_init(GstTestScopeClass * g_class)69 gst_test_scope_class_init (GstTestScopeClass * g_class)
70 {
71   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
72 
73   gst_element_class_set_static_metadata (element_class, "test scope",
74       "Visualization",
75       "Dummy test scope", "Stefan Kost <ensonic@users.sf.net>");
76 
77   gst_element_class_add_static_pad_template (element_class,
78       &gst_test_scope_src_template);
79   gst_element_class_add_static_pad_template (element_class,
80       &gst_test_scope_sink_template);
81 }
82 
83 static void
gst_test_scope_init(GstTestScope * scope)84 gst_test_scope_init (GstTestScope * scope)
85 {
86   /* do nothing */
87 }
88 
89 /* tests */
90 #define CAPS "audio/x-raw, "  \
91         "format = (string) " GST_AUDIO_NE (S16) ", " \
92         "layout = (string) interleaved, " \
93         "rate = (int) 44100, " \
94         "channels = (int) 2, " \
95         "channel-mask = (bitmask) 3"
96 
97 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
98     GST_PAD_SINK,
99     GST_PAD_ALWAYS,
100     GST_STATIC_CAPS ("video/x-raw, "
101         "format = (string) xRGB, "
102         "width = (int) 320, "
103         "height = (int) 240, " "framerate = (fraction) 30/1")
104     );
105 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
106     GST_PAD_SRC,
107     GST_PAD_ALWAYS,
108     GST_STATIC_CAPS (CAPS)
109     );
110 
GST_START_TEST(count_in_out)111 GST_START_TEST (count_in_out)
112 {
113   GstElement *elem;
114   GstPad *srcpad, *sinkpad;
115   GstBuffer *buffer;
116   GstCaps *caps;
117 
118   /* setup up */
119   elem = gst_check_setup_element ("testscope");
120   srcpad = gst_check_setup_src_pad (elem, &srctemplate);
121   sinkpad = gst_check_setup_sink_pad (elem, &sinktemplate);
122   gst_pad_set_active (srcpad, TRUE);
123   gst_pad_set_active (sinkpad, TRUE);
124 
125   fail_unless (gst_element_set_state (elem,
126           GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
127       "could not set to playing");
128 
129   caps = gst_caps_from_string (CAPS);
130   gst_check_setup_events (srcpad, elem, caps, GST_FORMAT_TIME);
131   gst_caps_unref (caps);
132 
133   /* push 1s audio to get 30 video-frames */
134   buffer = gst_buffer_new_and_alloc (44100 * 2 * sizeof (gint16));
135   ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
136 
137   /* pushing gives away my reference ... */
138   fail_unless (gst_pad_push (srcpad, buffer) == GST_FLOW_OK);
139   /* ... but it ends up being collected on the global buffer list */
140   ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
141   fail_unless_equals_int (g_list_length (buffers), 30);
142 
143   /* clean up */
144   g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
145   g_list_free (buffers);
146   buffers = NULL;
147 
148   gst_pad_set_active (srcpad, FALSE);
149   gst_pad_set_active (sinkpad, FALSE);
150   gst_check_teardown_src_pad (elem);
151   gst_check_teardown_sink_pad (elem);
152   gst_check_teardown_element (elem);
153 }
154 
155 GST_END_TEST;
156 
157 static void
baseaudiovisualizer_init(void)158 baseaudiovisualizer_init (void)
159 {
160   gst_element_register (NULL, "testscope", GST_RANK_NONE, GST_TYPE_TEST_SCOPE);
161 }
162 
163 static Suite *
baseaudiovisualizer_suite(void)164 baseaudiovisualizer_suite (void)
165 {
166   Suite *s = suite_create ("baseaudiovisualizer");
167   TCase *tc_chain = tcase_create ("general");
168 
169   suite_add_tcase (s, tc_chain);
170   tcase_add_checked_fixture (tc_chain, baseaudiovisualizer_init, NULL);
171 
172   tcase_add_test (tc_chain, count_in_out);
173 
174   return s;
175 }
176 
177 
178 GST_CHECK_MAIN (baseaudiovisualizer);
179