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);
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);
57 * Pushes 4 buffers into appsrc and checks the caps on them on the output.
59 * Appsrc is configured with caps=SAMPLE_CAPS, so the buffers should have the
60 * same caps that they were pushed with.
62 * The 4 buffers have NULL, SAMPLE_CAPS, NULL, SAMPLE_CAPS caps,
65 GST_START_TEST (test_appsrc_non_null_caps)
69 GstCaps *caps, *ccaps;
71 src = setup_appsrc ();
73 caps = gst_caps_from_string (SAMPLE_CAPS);
74 g_object_set (src, "caps", caps, NULL);
76 ASSERT_SET_STATE (src, GST_STATE_PLAYING, GST_STATE_CHANGE_SUCCESS);
78 buffer = gst_buffer_new_and_alloc (4);
79 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
80 buffer) == GST_FLOW_OK);
82 buffer = gst_buffer_new_and_alloc (4);
83 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
84 buffer) == GST_FLOW_OK);
86 buffer = gst_buffer_new_and_alloc (4);
87 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
88 buffer) == GST_FLOW_OK);
90 buffer = gst_buffer_new_and_alloc (4);
91 fail_unless (gst_app_src_push_buffer (GST_APP_SRC (src),
92 buffer) == GST_FLOW_OK);
94 fail_unless (gst_app_src_end_of_stream (GST_APP_SRC (src)) == GST_FLOW_OK);
96 /* Give some time to the appsrc loop to push the buffers */
97 g_usleep (G_USEC_PER_SEC * 3);
99 /* Check the output caps */
100 fail_unless (g_list_length (buffers) == 4);
102 ccaps = gst_pad_get_current_caps (mysinkpad);
103 fail_unless (gst_caps_is_equal (ccaps, caps));
104 gst_caps_unref (ccaps);
106 ASSERT_SET_STATE (src, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS);
107 gst_caps_unref (caps);
108 cleanup_appsrc (src);
117 Suite *s = suite_create ("appsrc");
118 TCase *tc_chain = tcase_create ("general");
120 tcase_add_test (tc_chain, test_appsrc_non_null_caps);
122 suite_add_tcase (s, tc_chain);
127 GST_CHECK_MAIN (appsrc);