3 * Copyright (C) 2010, Thiago Santos <thiago.sousa.santos@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
22 #include <gst/app/gstappsrc.h>
24 #define SAMPLE_CAPS "application/x-gst-check-test"
26 static GstPad *mysinkpad;
28 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
38 GST_DEBUG ("setup_appsrc");
39 appsrc = gst_check_setup_element ("appsrc");
40 mysinkpad = gst_check_setup_sink_pad (appsrc, &sinktemplate, NULL);
42 gst_pad_set_active (mysinkpad, TRUE);
48 cleanup_appsrc (GstElement * appsrc)
50 GST_DEBUG ("cleanup_appsrc");
52 gst_check_teardown_sink_pad (appsrc);
53 gst_check_teardown_element (appsrc);
58 * Pushes 4 buffers into appsrc and checks the caps on them on the output.
60 * Appsrc is configured with caps=null, so the buffers should have the
61 * same caps that they were pushed with.
63 * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
66 GST_START_TEST (test_appsrc_null_caps)
73 src = setup_appsrc ();
75 g_object_set (src, "caps", NULL, NULL);
76 caps = gst_caps_from_string (SAMPLE_CAPS);
78 ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
80 buffer = gst_buffer_new_and_alloc (4);
81 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
82 buffer) == GST_FLOW_OK);
84 buffer = gst_buffer_new_and_alloc (4);
85 gst_buffer_set_caps (buffer, caps);
86 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
87 buffer) == GST_FLOW_OK);
89 fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
91 /* Give some time to the appsrc loop to push the buffers */
92 g_usleep (G_USEC_PER_SEC * 3);
94 /* Check the output caps */
95 fail_unless (g_list_length (buffers) == 2);
97 buffer = (GstBuffer *) iter->data;
98 fail_unless (GST_BUFFER_CAPS (buffer) == NULL);
100 iter = g_list_next (iter);
101 buffer = (GstBuffer *) iter->data;
102 fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buffer), caps));
104 ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
105 gst_caps_unref (caps);
106 cleanup_appsrc (src);
113 * Pushes 4 buffers into appsrc and checks the caps on them on the output.
115 * Appsrc is configured with caps=SAMPLE_CAPS, so the buffers should have the
116 * same caps that they were pushed with.
118 * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
121 GST_START_TEST (test_appsrc_non_null_caps)
128 src = setup_appsrc ();
130 caps = gst_caps_from_string (SAMPLE_CAPS);
131 g_object_set (src, "caps", caps, NULL);
133 ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
135 buffer = gst_buffer_new_and_alloc (4);
136 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
137 buffer) == GST_FLOW_OK);
139 buffer = gst_buffer_new_and_alloc (4);
140 gst_buffer_set_caps (buffer, caps);
141 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
142 buffer) == GST_FLOW_OK);
144 buffer = gst_buffer_new_and_alloc (4);
145 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
146 buffer) == GST_FLOW_OK);
148 buffer = gst_buffer_new_and_alloc (4);
149 gst_buffer_set_caps (buffer, caps);
150 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
151 buffer) == GST_FLOW_OK);
153 fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
155 /* Give some time to the appsrc loop to push the buffers */
156 g_usleep (G_USEC_PER_SEC * 3);
158 /* Check the output caps */
159 fail_unless (g_list_length (buffers) == 4);
160 for (iter = buffers; iter; iter = g_list_next (iter)) {
161 GstBuffer *buf = (GstBuffer *) iter->data;
163 fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (buf), caps));
166 ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
167 gst_caps_unref (caps);
168 cleanup_appsrc (src);
177 Suite *s = suite_create ("appsrc");
178 TCase *tc_chain = tcase_create ("general");
180 tcase_add_test (tc_chain, test_appsrc_null_caps);
181 tcase_add_test (tc_chain, test_appsrc_non_null_caps);
183 suite_add_tcase (s, tc_chain);
188 GST_CHECK_MAIN (appsrc);