• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * unit test for interlace
3  *
4  * Copyright (C) 2021 Vivia Nikolaidou <vivia at ahiru dot eu>
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 #include <gst/check/gstcheck.h>
23 #include <gst/check/gstharness.h>
24 #include <gst/video/video.h>
25 
GST_START_TEST(test_passthrough)26 GST_START_TEST (test_passthrough)
27 {
28   GstBuffer *buffer;
29   GstHarness *h;
30 
31   h = gst_harness_new ("interlace");
32 
33   gst_harness_set (h, "interlace", "field-pattern", 1, "top-field-first", TRUE,
34       NULL);
35   gst_harness_set_src_caps_str (h,
36       "video/x-raw,interlace-mode=interleaved,field-order=top-field-first,format=AYUV,height=1,width=1,framerate=1/1");
37   buffer = gst_harness_create_buffer (h, 4);
38   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
39 
40   gst_harness_set (h, "interlace", "field-pattern", 1, "top-field-first", FALSE,
41       NULL);
42   gst_harness_set_src_caps_str (h,
43       "video/x-raw,interlace-mode=interleaved,field-order=bottom-field-first,format=AYUV,width=1,height=1,framerate=1/1");
44   buffer = gst_harness_create_buffer (h, 4);
45   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
46 
47   gst_harness_teardown (h);
48 }
49 
50 GST_END_TEST;
51 
GST_START_TEST(test_reject_passthrough_mixed)52 GST_START_TEST (test_reject_passthrough_mixed)
53 {
54   GstHarness *h;
55   GstBuffer *buffer;
56 
57   h = gst_harness_new ("interlace");
58   gst_harness_play (h);
59 
60   gst_harness_set (h, "interlace", "field-pattern", 3, NULL);
61   gst_harness_set_src_caps_str (h,
62       "video/x-raw,interlace-mode=mixed,format=AYUV,width=1,height=1,framerate=1/1");
63   buffer = gst_harness_create_buffer (h, 4);
64   fail_unless_equals_int (gst_harness_push (h, buffer),
65       GST_FLOW_NOT_NEGOTIATED);
66 
67   gst_harness_teardown (h);
68 }
69 
70 GST_END_TEST;
71 
GST_START_TEST(test_field_switch)72 GST_START_TEST (test_field_switch)
73 {
74   GstHarness *h;
75   GstBuffer *buffer;
76 
77   h = gst_harness_new ("interlace");
78 
79   gst_harness_set (h, "interlace", "field-pattern", 1, "top-field-first", FALSE,
80       NULL);
81   gst_harness_set_src_caps_str (h,
82       "video/x-raw,interlace-mode=interleaved,field-order=top-field-first,format=AYUV,width=1,height=1,framerate=1/1");
83   buffer = gst_harness_create_buffer (h, 4);
84   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
85 
86   gst_harness_set (h, "interlace", "field-pattern", 1, "top-field-first", TRUE,
87       NULL);
88   gst_harness_set_src_caps_str (h,
89       "video/x-raw,interlace-mode=interleaved,field-order=bottom-field-first,format=AYUV,width=1,height=1,framerate=1/1");
90   buffer = gst_harness_create_buffer (h, 4);
91   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
92 
93   gst_harness_teardown (h);
94 }
95 
96 GST_END_TEST;
97 
GST_START_TEST(test_framerate_2_2)98 GST_START_TEST (test_framerate_2_2)
99 {
100   GstHarness *h;
101   GstBuffer *buffer;
102 
103   h = gst_harness_new ("interlace");
104 
105   gst_harness_set (h, "interlace", "field-pattern", 1, "top-field-first", TRUE,
106       NULL);
107   gst_harness_set_sink_caps_str (h, "video/x-raw,framerate=1/1");
108   gst_harness_set_src_caps_str (h,
109       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=1/1");
110   buffer = gst_harness_create_buffer (h, 4);
111   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
112 
113   gst_harness_set_sink_caps_str (h, "video/x-raw,framerate=1/1");
114   gst_harness_set_src_caps_str (h,
115       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=2/1");
116   buffer = gst_harness_create_buffer (h, 4);
117   fail_unless_equals_int (gst_harness_push (h, buffer),
118       GST_FLOW_NOT_NEGOTIATED);
119 
120   gst_harness_teardown (h);
121 }
122 
123 GST_END_TEST;
124 
GST_START_TEST(test_framerate_1_1)125 GST_START_TEST (test_framerate_1_1)
126 {
127   GstHarness *h;
128   GstBuffer *buffer;
129 
130   h = gst_harness_new ("interlace");
131 
132   gst_harness_set (h, "interlace", "field-pattern", 0, "top-field-first", TRUE,
133       NULL);
134   gst_harness_set_sink_caps_str (h, "video/x-raw,framerate=1/1");
135   gst_harness_set_src_caps_str (h,
136       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=1/1");
137   buffer = gst_harness_create_buffer (h, 4);
138   fail_unless_equals_int (gst_harness_push (h, buffer),
139       GST_FLOW_NOT_NEGOTIATED);
140 
141   gst_harness_set_sink_caps_str (h, "video/x-raw,framerate=1/1");
142   gst_harness_set_src_caps_str (h,
143       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=2/1");
144   buffer = gst_harness_create_buffer (h, 4);
145   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
146 
147   gst_harness_teardown (h);
148 }
149 
150 GST_END_TEST;
151 
GST_START_TEST(test_framerate_3_2)152 GST_START_TEST (test_framerate_3_2)
153 {
154   GstHarness *h;
155   GstBuffer *buffer;
156 
157   h = gst_harness_new ("interlace");
158 
159   gst_harness_set (h, "interlace", "field-pattern", 2, NULL);
160   gst_harness_set_sink_caps_str (h, "video/x-raw,framerate=30/1");
161   gst_harness_set_src_caps_str (h,
162       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=24/1");
163   buffer = gst_harness_create_buffer (h, 4);
164   fail_unless_equals_int (gst_harness_push (h, buffer), GST_FLOW_OK);
165 
166   gst_harness_set_sink_caps_str (h, "video/x-raw,framerate=1/1");
167   gst_harness_set_src_caps_str (h,
168       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=1/1");
169   buffer = gst_harness_create_buffer (h, 4);
170   fail_unless_equals_int (gst_harness_push (h, buffer),
171       GST_FLOW_NOT_NEGOTIATED);
172 
173   gst_harness_teardown (h);
174 }
175 
176 GST_END_TEST;
177 
GST_START_TEST(test_framerate_empty_not_negotiated)178 GST_START_TEST (test_framerate_empty_not_negotiated)
179 {
180   GstHarness *h;
181   GstBuffer *buffer;
182 
183   h = gst_harness_new ("interlace");
184 
185   gst_harness_set_sink_caps_str (h, "EMPTY");
186   gst_harness_set_src_caps_str (h,
187       "video/x-raw,interlace-mode=progressive,format=AYUV,width=1,height=1,framerate=24/1");
188   buffer = gst_harness_create_buffer (h, 4);
189   fail_unless_equals_int (gst_harness_push (h, buffer),
190       GST_FLOW_NOT_NEGOTIATED);
191 
192   gst_harness_teardown (h);
193 }
194 
195 GST_END_TEST;
196 
197 static Suite *
interlace_suite(void)198 interlace_suite (void)
199 {
200   Suite *s = suite_create ("interlace");
201   TCase *tc_chain = tcase_create ("general");
202 
203   suite_add_tcase (s, tc_chain);
204 
205   tcase_add_test (tc_chain, test_passthrough);
206   tcase_add_test (tc_chain, test_reject_passthrough_mixed);
207   tcase_add_test (tc_chain, test_field_switch);
208   tcase_add_test (tc_chain, test_framerate_2_2);
209   tcase_add_test (tc_chain, test_framerate_1_1);
210   tcase_add_test (tc_chain, test_framerate_3_2);
211   tcase_add_test (tc_chain, test_framerate_empty_not_negotiated);
212 
213   return s;
214 }
215 
216 GST_CHECK_MAIN (interlace);
217