• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * unit test for the videobox element
3  *
4  * Copyright (C) 2006 Ravi Kiran K N <ravi.kiran@samsung.com>
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 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif
25 
26 #include <gst/check/gstcheck.h>
27 
28 typedef struct _GstVideoBoxTestContext
29 {
30   GstElement *pipeline;
31   GstElement *src;
32   GstElement *filter;
33   GstElement *box;
34   GstElement *filter2;
35   GstElement *sink;
36 } GstVideoBoxTestContext;
37 
38 typedef struct _FormatConversion
39 {
40   const gchar *in_caps;
41   const gchar *out_caps;
42   gboolean expected_result;
43 } FormatConversion;
44 
45 
46 /*
47  * Update this table as and when the conversion is supported(or unsupported) in videobox
48  */
49 static const FormatConversion conversion_table[] = {
50   {"video/x-raw,format={RGBA}", "video/x-raw,format={AYUV}", TRUE},
51   {"video/x-raw,format={AYUV}", "video/x-raw,format={RGBA}", TRUE},
52   {"video/x-raw,format={I420}", "video/x-raw,format={AYUV}", TRUE},
53   {"video/x-raw,format={AYUV}", "video/x-raw,format={I420}", TRUE},
54   {"video/x-raw,format={I420}", "video/x-raw,format={YV12}", TRUE},
55   {"video/x-raw,format={YV12}", "video/x-raw,format={AYUV}", TRUE},
56   {"video/x-raw,format={YV12}", "video/x-raw,format={I420}", TRUE},
57   {"video/x-raw,format={AYUV}", "video/x-raw,format={YV12}", TRUE},
58   {"video/x-raw,format={AYUV}", "video/x-raw,format={xRGB}", TRUE},
59   {"video/x-raw,format={xRGB}", "video/x-raw,format={xRGB}", TRUE},
60   {"video/x-raw,format={xRGB}", "video/x-raw,format={AYUV}", TRUE},
61   {"video/x-raw,format={GRAY8}", "video/x-raw,format={GRAY16_LE}", FALSE},
62   {"video/x-raw,format={GRAY8}", "video/x-raw,format={GRAY16_BE}", FALSE},
63   {"video/x-raw,format={Y444}", "video/x-raw,format={Y42B}", FALSE},
64   {"video/x-raw,format={Y444}", "video/x-raw,format={Y41B}", FALSE},
65   {"video/x-raw,format={Y42B}", "video/x-raw,format={Y41B}", FALSE}
66 };
67 
68 
69 static gboolean
bus_handler(GstBus * bus,GstMessage * message,gpointer data)70 bus_handler (GstBus * bus, GstMessage * message, gpointer data)
71 {
72   GMainLoop *loop = (GMainLoop *) data;
73 
74   switch (message->type) {
75     case GST_MESSAGE_EOS:{
76       GST_LOG ("EOS event received");
77       g_main_loop_quit (loop);
78       break;
79     }
80     case GST_MESSAGE_ERROR:{
81       GError *gerror;
82       gchar *debug;
83       gst_message_parse_error (message, &gerror, &debug);
84       g_error ("Error from %s: %s (%s)\n",
85           GST_ELEMENT_NAME (GST_MESSAGE_SRC (message)), gerror->message,
86           GST_STR_NULL (debug));
87       g_error_free (gerror);
88       g_free (debug);
89       g_main_loop_quit (loop);
90       break;
91     }
92     case GST_MESSAGE_WARNING:{
93       g_main_loop_quit (loop);
94       break;
95     }
96     default:
97       break;
98   }
99 
100   return TRUE;
101 }
102 
103 static void
videobox_test_init_context(GstVideoBoxTestContext * ctx)104 videobox_test_init_context (GstVideoBoxTestContext * ctx)
105 {
106   fail_unless (ctx != NULL);
107 
108   ctx->pipeline = gst_pipeline_new ("pipeline");
109   fail_unless (ctx->pipeline != NULL);
110   ctx->src = gst_element_factory_make ("videotestsrc", "src");
111   fail_unless (ctx->src != NULL, "Failed to create videotestsrc element");
112   ctx->filter = gst_element_factory_make ("capsfilter", "filter");
113   fail_unless (ctx->filter != NULL, "Failed to create capsfilter element");
114   ctx->box = gst_element_factory_make ("videobox", "box");
115   fail_unless (ctx->box != NULL, "Failed to create videobox element");
116   ctx->filter2 = gst_element_factory_make ("capsfilter", "filter2");
117   fail_unless (ctx->filter2 != NULL,
118       "Failed to create second capsfilter element");
119   ctx->sink = gst_element_factory_make ("fakesink", "sink");
120   fail_unless (ctx->sink != NULL, "Failed to create fakesink element");
121 
122   gst_bin_add_many (GST_BIN (ctx->pipeline), ctx->src, ctx->filter,
123       ctx->box, ctx->filter2, ctx->sink, NULL);
124   fail_unless (gst_element_link_many (ctx->src, ctx->filter, ctx->box,
125           ctx->filter2, ctx->sink, NULL) == TRUE, "Can not link elements");
126 
127   fail_unless (gst_element_set_state (ctx->pipeline,
128           GST_STATE_READY) != GST_STATE_CHANGE_FAILURE,
129       "couldn't set pipeline to READY state");
130 
131   GST_LOG ("videobox context inited");
132 }
133 
134 static void
videobox_test_deinit_context(GstVideoBoxTestContext * ctx)135 videobox_test_deinit_context (GstVideoBoxTestContext * ctx)
136 {
137   GST_LOG ("deiniting videobox context");
138 
139   gst_element_set_state (ctx->pipeline, GST_STATE_NULL);
140   gst_object_unref (ctx->pipeline);
141   memset (ctx, 0x00, sizeof (GstVideoBoxTestContext));
142 }
143 
GST_START_TEST(test_caps_transform)144 GST_START_TEST (test_caps_transform)
145 {
146   GstStateChangeReturn state_ret;
147   GstVideoBoxTestContext ctx;
148   guint conversions_test_size;
149   guint itr;
150   gboolean link_res;
151   GMainLoop *loop;
152   GstBus *bus;
153 
154   videobox_test_init_context (&ctx);
155   gst_util_set_object_arg (G_OBJECT (ctx.src), "num-buffers", "1");
156 
157   loop = g_main_loop_new (NULL, TRUE);
158   fail_unless (loop != NULL);
159 
160   bus = gst_element_get_bus (ctx.pipeline);
161   fail_unless (bus != NULL);
162 
163   gst_bus_add_watch (bus, bus_handler, loop);
164 
165   conversions_test_size = G_N_ELEMENTS (conversion_table);
166   for (itr = 0; itr < conversions_test_size; itr++) {
167     gst_element_unlink_many (ctx.src, ctx.filter, ctx.box, ctx.filter2,
168         ctx.sink, NULL);
169     gst_util_set_object_arg (G_OBJECT (ctx.filter), "caps",
170         conversion_table[itr].in_caps);
171     gst_util_set_object_arg (G_OBJECT (ctx.filter2), "caps",
172         conversion_table[itr].out_caps);
173 
174     /* Link with new input and output format from conversion table */
175     link_res =
176         gst_element_link_many (ctx.src, ctx.filter, ctx.box, ctx.filter2,
177         ctx.sink, NULL);
178 
179     /* Check if the specified format conversion is supported or not by videobox */
180     fail_unless (link_res == conversion_table[itr].expected_result,
181         "videobox can not convert from '%s'' to '%s'",
182         conversion_table[itr].in_caps, conversion_table[itr].out_caps);
183 
184     if (link_res == FALSE) {
185       GST_LOG ("elements linking failed");
186       continue;
187     }
188 
189     state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_PLAYING);
190     fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
191         "couldn't set pipeline to PLAYING state");
192 
193     g_main_loop_run (loop);
194 
195     state_ret = gst_element_set_state (ctx.pipeline, GST_STATE_READY);
196     fail_unless (state_ret != GST_STATE_CHANGE_FAILURE,
197         "couldn't set pipeline to READY state");
198   }
199 
200   gst_bus_remove_watch (bus);
201   gst_object_unref (bus);
202   g_main_loop_unref (loop);
203 
204   videobox_test_deinit_context (&ctx);
205 }
206 
207 GST_END_TEST;
208 
209 
210 static Suite *
videobox_suite(void)211 videobox_suite (void)
212 {
213   Suite *s = suite_create ("videobox");
214   TCase *tc_chain = tcase_create ("general");
215 
216   suite_add_tcase (s, tc_chain);
217   tcase_add_test (tc_chain, test_caps_transform);
218 
219   return s;
220 }
221 
222 GST_CHECK_MAIN (videobox);
223