5 * Copyright (C) <2008> Thiago Santos <thiagoss@embedded.ufcg.edu.br>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
27 /* For ease of programming we use globals to keep refs for our floating
28 * src and sink pads we create; otherwise we always have to do get_pad,
29 * get_peer, and then remove references in every test function */
30 static GstPad *mysrcpad, *mysinkpad;
32 #define AUDIO_CAPS_STRING "audio/x-wma, " \
33 "channels = (int) 2, " \
34 "rate = (int) 8000, " \
35 "wmaversion = (int) 2, " \
36 "block-align = (int) 14, " \
37 "bitrate = (int) 64000"
39 #define VIDEO_CAPS_STRING "video/x-wmv, " \
40 "width = (int) 384, " \
41 "height = (int) 288, " \
42 "framerate = (fraction) 25/1, " \
43 "wmvversion = (int) 2"
45 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
48 GST_STATIC_CAPS ("video/x-ms-asf"));
49 static GstStaticPadTemplate srcvideotemplate = GST_STATIC_PAD_TEMPLATE ("src",
52 GST_STATIC_CAPS (VIDEO_CAPS_STRING));
53 static GstStaticPadTemplate srcaudiotemplate = GST_STATIC_PAD_TEMPLATE ("src",
56 GST_STATIC_CAPS (AUDIO_CAPS_STRING));
59 setup_src_pad (GstElement * element,
60 GstStaticPadTemplate * template, GstCaps * caps, const gchar * sinkname)
62 GstPad *srcpad, *sinkpad;
64 GST_DEBUG_OBJECT (element, "setting up sending pad");
66 srcpad = gst_pad_new_from_static_template (template, "src");
67 fail_if (srcpad == NULL, "Could not create a srcpad");
68 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
70 if (!(sinkpad = gst_element_get_static_pad (element, sinkname)))
71 sinkpad = gst_element_get_request_pad (element, sinkname);
72 fail_if (sinkpad == NULL, "Could not get sink pad from %s",
73 GST_ELEMENT_NAME (element));
74 /* references are owned by: 1) us, 2) asfmux, 3) collect pads */
75 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
77 fail_unless (gst_pad_set_caps (srcpad, caps));
78 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
79 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
80 gst_object_unref (sinkpad); /* because we got it higher up */
82 /* references are owned by: 1) asfmux, 2) collect pads */
83 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
89 teardown_src_pad (GstElement * element, const gchar * sinkname)
91 GstPad *srcpad, *sinkpad;
94 /* clean up floating src pad */
95 /* hm, asfmux uses _01 as suffixes for padnames */
96 padname = g_strdup (sinkname);
97 memcpy (strchr (padname, '%'), "01", 2);
98 if (!(sinkpad = gst_element_get_static_pad (element, padname)))
99 sinkpad = gst_element_get_request_pad (element, padname);
102 fail_if (sinkpad == NULL, "sinkpad is null");
104 /* pad refs held by 1) asfmux 2) collectpads and 3) us (through _get) */
105 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
106 fail_unless (gst_pad_is_linked (sinkpad));
107 srcpad = gst_pad_get_peer (sinkpad);
109 fail_if (srcpad == NULL, "Couldn't get srcpad");
110 gst_pad_unlink (srcpad, sinkpad);
112 /* after unlinking, pad refs still held by
113 * 1) asfmux and 2) collectpads and 3) us (through _get) */
114 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
115 gst_object_unref (sinkpad);
116 /* one more ref is held by element itself */
118 /* pad refs held by both creator and this function (through _get_peer) */
119 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 2);
120 gst_object_unref (srcpad);
121 gst_object_unref (srcpad);
125 setup_asfmux (GstStaticPadTemplate * srctemplate, const gchar * sinkname)
129 GST_DEBUG ("setup_asfmux");
130 asfmux = gst_check_setup_element ("asfmux");
132 mysrcpad = setup_src_pad (asfmux, srctemplate, NULL, sinkname);
133 mysinkpad = gst_check_setup_sink_pad (asfmux, &sinktemplate, NULL);
134 gst_pad_set_active (mysrcpad, TRUE);
135 gst_pad_set_active (mysinkpad, TRUE);
140 cleanup_asfmux (GstElement * asfmux, const gchar * sinkname)
142 GST_DEBUG ("cleanup_asfmux");
143 gst_element_set_state (asfmux, GST_STATE_NULL);
144 gst_pad_set_active (mysrcpad, FALSE);
145 gst_pad_set_active (mysinkpad, FALSE);
146 teardown_src_pad (asfmux, sinkname);
147 gst_check_teardown_sink_pad (asfmux);
148 gst_check_teardown_element (asfmux);
152 check_asfmux_pad (GstStaticPadTemplate * srctemplate,
153 const gchar * src_caps_string, const gchar * sinkname)
161 asfmux = setup_asfmux (srctemplate, sinkname);
162 fail_unless (gst_element_set_state (asfmux,
163 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
164 "could not set to playing");
166 inbuffer = gst_buffer_new_and_alloc (1);
167 caps = gst_caps_from_string (src_caps_string);
168 gst_buffer_set_caps (inbuffer, caps);
169 gst_caps_unref (caps);
170 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
171 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
172 ret = gst_pad_push (mysrcpad, inbuffer);
173 fail_unless (ret == GST_FLOW_OK, "Pad push returned: %d", ret);
175 cleanup_asfmux (asfmux, sinkname);
176 for (l = buffers; l; l = l->next)
177 gst_buffer_unref (l->data);
178 g_list_free (buffers);
182 GST_START_TEST (test_video_pad)
184 check_asfmux_pad (&srcvideotemplate, VIDEO_CAPS_STRING, "video_%d");
189 GST_START_TEST (test_audio_pad)
191 check_asfmux_pad (&srcaudiotemplate, AUDIO_CAPS_STRING, "audio_%d");
199 Suite *s = suite_create ("asfmux");
200 TCase *tc_chain = tcase_create ("general");
201 tcase_add_test (tc_chain, test_video_pad);
202 tcase_add_test (tc_chain, test_audio_pad);
204 suite_add_tcase (s, tc_chain);
210 main (int argc, char **argv)
214 Suite *s = asfmux_suite ();
215 SRunner *sr = srunner_create (s);
217 gst_check_init (&argc, &argv);
219 srunner_run_all (sr, CK_NORMAL);
220 nf = srunner_ntests_failed (sr);