• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * unit test for videoconvert
3  *
4  * Copyright (C) 2006-2012 Tim-Philipp Müller <tim centricular net>
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 #ifdef HAVE_VALGRIND
27 # include <valgrind/valgrind.h>
28 #endif
29 
30 #include <gst/check/gstcheck.h>
31 #include <gst/check/gstharness.h>
32 #include <gst/video/video.h>
33 
34 static guint
get_num_formats(void)35 get_num_formats (void)
36 {
37   guint i = 2;
38 
39   while (gst_video_format_to_string ((GstVideoFormat) i) != NULL)
40     ++i;
41 
42   return i;
43 }
44 
45 static void
check_pad_template(GstPadTemplate * tmpl)46 check_pad_template (GstPadTemplate * tmpl)
47 {
48   const GValue *list_val, *fmt_val;
49   GstStructure *s;
50   gboolean *formats_supported;
51   GstCaps *caps;
52   guint i, num_formats;
53 
54   num_formats = get_num_formats ();
55   formats_supported = g_new0 (gboolean, num_formats);
56 
57   caps = gst_pad_template_get_caps (tmpl);
58 
59   /* If this fails, we need to update this unit test */
60   fail_unless_equals_int (gst_caps_get_size (caps), 2);
61   /* Remove the ANY caps features structure */
62   caps = gst_caps_truncate (caps);
63   s = gst_caps_get_structure (caps, 0);
64 
65   fail_unless (gst_structure_has_name (s, "video/x-raw"));
66 
67   list_val = gst_structure_get_value (s, "format");
68   fail_unless (list_val != NULL);
69   /* If this fails, we need to update this unit test */
70   fail_unless (GST_VALUE_HOLDS_LIST (list_val));
71 
72   for (i = 0; i < gst_value_list_get_size (list_val); ++i) {
73     GstVideoFormat fmt;
74     const gchar *fmt_str;
75 
76     fmt_val = gst_value_list_get_value (list_val, i);
77     fail_unless (G_VALUE_HOLDS_STRING (fmt_val));
78     fmt_str = g_value_get_string (fmt_val);
79     GST_LOG ("format string: '%s'", fmt_str);
80     fmt = gst_video_format_from_string (fmt_str);
81     fail_unless (fmt != GST_VIDEO_FORMAT_UNKNOWN);
82     formats_supported[(guint) fmt] = TRUE;
83   }
84 
85   gst_caps_unref (caps);
86 
87   for (i = 2; i < num_formats; ++i) {
88     if (!formats_supported[i]) {
89       g_error ("videoconvert doesn't support format '%s'",
90           gst_video_format_to_string ((GstVideoFormat) i));
91     }
92   }
93 
94   g_free (formats_supported);
95 }
96 
GST_START_TEST(test_template_formats)97 GST_START_TEST (test_template_formats)
98 {
99   GstElementFactory *f;
100   GstPadTemplate *t;
101   const GList *pad_templates;
102 
103   f = gst_element_factory_find ("videoconvert");
104   fail_unless (f != NULL);
105 
106   pad_templates = gst_element_factory_get_static_pad_templates (f);
107   fail_unless_equals_int (g_list_length ((GList *) pad_templates), 2);
108 
109   t = gst_static_pad_template_get (pad_templates->data);
110   check_pad_template (GST_PAD_TEMPLATE (t));
111   gst_object_unref (t);
112   t = gst_static_pad_template_get (pad_templates->next->data);
113   check_pad_template (GST_PAD_TEMPLATE (t));
114   gst_object_unref (t);
115 
116   gst_object_unref (f);
117 }
118 
119 GST_END_TEST;
120 
GST_START_TEST(test_negotiate_alternate)121 GST_START_TEST (test_negotiate_alternate)
122 {
123   GstHarness *h;
124   GstBuffer *buffer;
125   GstMapInfo map;
126 
127   h = gst_harness_new ("videoconvert");
128 
129   buffer = gst_buffer_new_and_alloc (4);
130   gst_buffer_map (buffer, &map, GST_MAP_WRITE);
131   map.data[0] = 0x0;
132   map.data[1] = 0x0;
133   map.data[2] = 0x0;
134   map.data[3] = 0x0;
135   gst_buffer_unmap (buffer, &map);
136 
137   gst_harness_set_sink_caps_str (h,
138       "video/x-raw,interlace-mode=alternate,width=1,height=1,format=AYUV");
139   gst_harness_set_src_caps_str (h,
140       "video/x-raw(format:Interlaced),interlace-mode=alternate,width=1,height=1,format=ARGB");
141   fail_unless_equals_int (gst_harness_push (h, gst_buffer_ref (buffer)),
142       GST_FLOW_NOT_NEGOTIATED);
143 
144   gst_harness_set_sink_caps_str (h,
145       "video/x-raw(format:Interlaced),interlace-mode=alternate,width=1,height=1,format=AYUV");
146   gst_harness_set_src_caps_str (h,
147       "video/x-raw,interlace-mode=alternate,width=1,height=1,format=ARGB");
148   fail_unless_equals_int (gst_harness_push (h, gst_buffer_ref (buffer)),
149       GST_FLOW_NOT_NEGOTIATED);
150 
151   gst_harness_set_sink_caps_str (h,
152       "video/x-raw(format:Interlaced),interlace-mode=alternate,width=1,height=1,format=AYUV");
153   gst_harness_set_src_caps_str (h,
154       "video/x-raw(format:Interlaced),interlace-mode=alternate,width=1,height=1,format=ARGB");
155   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
156 
157   gst_harness_teardown (h);
158 }
159 
160 GST_END_TEST;
161 
162 static Suite *
videoconvert_suite(void)163 videoconvert_suite (void)
164 {
165   Suite *s = suite_create ("videoconvert");
166   TCase *tc_chain = tcase_create ("general");
167 
168   suite_add_tcase (s, tc_chain);
169 
170   tcase_add_test (tc_chain, test_template_formats);
171   tcase_add_test (tc_chain, test_negotiate_alternate);
172 
173   return s;
174 }
175 
176 GST_CHECK_MAIN (videoconvert);
177