1 /* GStreamer
2  *
3  * unit test for autovideoconvert element
4  * Copyright (C) 2009 Jan Schmidt <thaytan@noraisin.net>
5  * Copyright (C) 2010 ST-Ericsson SA
6  *  @author: Benjamin Gaignard <benjamin.gaignard@stericsson.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27 
28 #include <gst/gst.h>
29 #include <gst/check/gstcheck.h>
30 
31 typedef struct
32 {
33   GMainLoop *loop;
34   gboolean eos;
35 } OnMessageUserData;
36 
37 static void
on_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)38 on_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
39 {
40   OnMessageUserData *d = user_data;
41 
42   switch (GST_MESSAGE_TYPE (message)) {
43     case GST_MESSAGE_ERROR:
44     case GST_MESSAGE_WARNING:
45       g_assert_not_reached ();
46       break;
47     case GST_MESSAGE_EOS:
48       g_main_loop_quit (d->loop);
49       d->eos = TRUE;
50       break;
51     default:
52       break;
53   }
54 }
55 
56 static void
run_test(const gchar * pipeline_string)57 run_test (const gchar * pipeline_string)
58 {
59   GstElement *pipeline;
60   GstBus *bus;
61   GMainLoop *loop;
62   OnMessageUserData omud = { NULL, };
63   GstStateChangeReturn ret;
64 
65   GST_DEBUG ("Testing pipeline '%s'", pipeline_string);
66 
67   pipeline = gst_parse_launch (pipeline_string, NULL);
68   fail_unless (pipeline != NULL);
69   loop = g_main_loop_new (NULL, FALSE);
70 
71   bus = gst_element_get_bus (pipeline);
72   fail_unless (bus != NULL);
73   gst_bus_add_signal_watch (bus);
74 
75   omud.loop = loop;
76   omud.eos = FALSE;
77 
78   g_signal_connect (bus, "message", (GCallback) on_message_cb, &omud);
79 
80   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
81   fail_unless (ret == GST_STATE_CHANGE_SUCCESS
82       || ret == GST_STATE_CHANGE_ASYNC);
83 
84   g_main_loop_run (loop);
85 
86   fail_unless (gst_element_set_state (pipeline,
87           GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
88 
89   fail_unless (omud.eos == TRUE);
90 
91   gst_bus_remove_signal_watch (bus);
92   gst_object_unref (bus);
93   gst_object_unref (pipeline);
94   g_main_loop_unref (loop);
95 
96 }
97 
GST_START_TEST(test_autovideoconvert_rbg2bayer)98 GST_START_TEST (test_autovideoconvert_rbg2bayer)
99 {
100   gchar *pipeline;
101 
102   pipeline =
103       g_strdup_printf
104       ("videotestsrc num-buffers=1 ! video/x-raw,format=ARGB,depth=32,width=100,height=100,framerate=10/1 ! autovideoconvert ! video/x-bayer,width=100,height=100,format=bggr,framerate=10/1 ! fakesink");
105 
106   run_test (pipeline);
107   g_free (pipeline);
108 }
109 
110 GST_END_TEST;
111 
GST_START_TEST(test_autovideoconvert_videoconvert)112 GST_START_TEST (test_autovideoconvert_videoconvert)
113 {
114   gchar *pipeline;
115 
116   pipeline =
117       g_strdup_printf
118       ("videotestsrc num-buffers=1 ! video/x-raw, format=RGB,width=100,height=100,framerate=10/1 ! autovideoconvert ! video/x-raw,format=BGR,width=100,height=100,framerate=10/1 ! fakesink");
119 
120   run_test (pipeline);
121   g_free (pipeline);
122 }
123 
124 GST_END_TEST;
125 
126 static Suite *
autovideoconvert_suite(void)127 autovideoconvert_suite (void)
128 {
129   Suite *s = suite_create ("autovideoconvert");
130   TCase *tc_basic = tcase_create ("general");
131 
132   suite_add_tcase (s, tc_basic);
133   tcase_add_test (tc_basic, test_autovideoconvert_rbg2bayer);
134   tcase_add_test (tc_basic, test_autovideoconvert_videoconvert);
135 
136   return s;
137 }
138 
139 GST_CHECK_MAIN (autovideoconvert);
140