|
1 /* GStreamer |
|
2 * |
|
3 * unit test for videorate |
|
4 * |
|
5 * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org> |
|
6 * |
|
7 * This library is free software; you can redistribute it and/or |
|
8 * modify it under the terms of the GNU Library General Public |
|
9 * License as published by the Free Software Foundation; either |
|
10 * version 2 of the License, or (at your option) any later version. |
|
11 * |
|
12 * This library is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 * Library General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU Library General Public |
|
18 * License along with this library; if not, write to the |
|
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
20 * Boston, MA 02111-1307, USA. |
|
21 */ |
|
22 |
|
23 |
|
24 #include <gst/gst_global.h> |
|
25 |
|
26 #include <unistd.h> |
|
27 |
|
28 #include <gstcheck.h> |
|
29 #include <glib_global.h> |
|
30 |
|
31 |
|
32 #define LOG_FILE "c:\\logs\\adder_logs.txt" |
|
33 #include "std_log_result.h" |
|
34 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
35 |
|
36 void create_xml(int result) |
|
37 { |
|
38 if(result) |
|
39 assert_failed = 1; |
|
40 |
|
41 testResultXml(xmlfile); |
|
42 close_log_file(); |
|
43 } |
|
44 #include <gst/check/gstcheck.h> |
|
45 #include "libgstreamer_wsd_solution.h" |
|
46 |
|
47 #if EMULATOR |
|
48 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*) |
|
49 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)()) |
|
50 #else |
|
51 extern GList *buffers; |
|
52 #endif |
|
53 |
|
54 |
|
55 #if EMULATOR |
|
56 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
|
57 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
|
58 #else |
|
59 extern gboolean _gst_check_raised_critical ; |
|
60 #endif |
|
61 //gboolean _gst_check_raised_warning = FALSE; |
|
62 #if EMULATOR |
|
63 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean) |
|
64 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)()) |
|
65 #else |
|
66 extern gboolean _gst_check_raised_warning ; |
|
67 #endif |
|
68 //gboolean _gst_check_expecting_log = FALSE; |
|
69 #if EMULATOR |
|
70 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean) |
|
71 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)()) |
|
72 #else |
|
73 extern gboolean _gst_check_expecting_log ; |
|
74 #endif |
|
75 |
|
76 //gboolean _gst_check_expecting_log = FALSE; |
|
77 #if EMULATOR |
|
78 static GET_GLOBAL_VAR_FROM_TLS(threads_running,gstcheck,gboolean) |
|
79 #define _gst_check_threads_running (*GET_GSTREAMER_WSD_VAR_NAME(threads_running,gstcheck,g)()) |
|
80 #else |
|
81 extern gboolean _gst_check_threads_running ; |
|
82 #endif |
|
83 |
|
84 /* For ease of programming we use globals to keep refs for our floating |
|
85 * src and sink pads we create; otherwise we always have to do get_pad, |
|
86 * get_peer, and then remove references in every test function */ |
|
87 static GstPad *mysrcpad, *mysinkpad; |
|
88 |
|
89 |
|
90 #define VIDEO_CAPS_TEMPLATE_STRING \ |
|
91 "video/x-raw-yuv" |
|
92 |
|
93 #define VIDEO_CAPS_STRING \ |
|
94 "video/x-raw-yuv, " \ |
|
95 "width = (int) 320, " \ |
|
96 "height = (int) 240, " \ |
|
97 "framerate = (fraction) 25/1 , " \ |
|
98 "format = (fourcc) I420" |
|
99 |
|
100 #define VIDEO_CAPS_NO_FRAMERATE_STRING \ |
|
101 "video/x-raw-yuv, " \ |
|
102 "width = (int) 320, " \ |
|
103 "height = (int) 240, " \ |
|
104 "format = (fourcc) I420" |
|
105 |
|
106 #define VIDEO_CAPS_NEWSIZE_STRING \ |
|
107 "video/x-raw-yuv, " \ |
|
108 "width = (int) 240, " \ |
|
109 "height = (int) 120, " \ |
|
110 "framerate = (fraction) 25/1 , " \ |
|
111 "format = (fourcc) I420" |
|
112 |
|
113 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
|
114 GST_PAD_SINK, |
|
115 GST_PAD_ALWAYS, |
|
116 GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING) |
|
117 ); |
|
118 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
|
119 GST_PAD_SRC, |
|
120 GST_PAD_ALWAYS, |
|
121 GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING) |
|
122 ); |
|
123 |
|
124 static void |
|
125 assert_videorate_stats (GstElement * videorate, gchar * reason, |
|
126 guint64 xin, guint64 xout, guint64 xdropped, guint64 xduplicated) |
|
127 { |
|
128 guint64 in, out, dropped, duplicated; |
|
129 |
|
130 g_object_get (videorate, "in", &in, "out", &out, "drop", &dropped, |
|
131 "duplicate", &duplicated, NULL); |
|
132 #define _assert_equals_uint64(a, b) \ |
|
133 G_STMT_START { \ |
|
134 guint64 first = a; \ |
|
135 guint64 second = b; \ |
|
136 fail_unless(first == second, \ |
|
137 "%s: '" #a "' (%" G_GUINT64_FORMAT ") is not equal to " \ |
|
138 "expected '" #a"' (%" G_GUINT64_FORMAT ")", reason, first, second); \ |
|
139 } G_STMT_END; |
|
140 |
|
141 |
|
142 _assert_equals_uint64 (in, xin); |
|
143 _assert_equals_uint64 (out, xout); |
|
144 _assert_equals_uint64 (dropped, xdropped); |
|
145 _assert_equals_uint64 (duplicated, xduplicated); |
|
146 } |
|
147 |
|
148 static GstElement * |
|
149 setup_videorate (void) |
|
150 { |
|
151 GstElement *videorate; |
|
152 |
|
153 GST_DEBUG ("setup_videorate"); |
|
154 videorate = gst_check_setup_element ("videorate"); |
|
155 mysrcpad = gst_check_setup_src_pad (videorate, &srctemplate, NULL); |
|
156 mysinkpad = gst_check_setup_sink_pad (videorate, &sinktemplate, NULL); |
|
157 gst_pad_set_active (mysrcpad, TRUE); |
|
158 gst_pad_set_active (mysinkpad, TRUE); |
|
159 |
|
160 return videorate; |
|
161 } |
|
162 |
|
163 static void |
|
164 cleanup_videorate (GstElement * videorate) |
|
165 { |
|
166 GST_DEBUG ("cleanup_videorate"); |
|
167 |
|
168 g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); |
|
169 g_list_free (buffers); |
|
170 buffers = NULL; |
|
171 |
|
172 gst_element_set_state (videorate, GST_STATE_NULL); |
|
173 gst_element_get_state (videorate, NULL, NULL, GST_CLOCK_TIME_NONE); |
|
174 gst_pad_set_active (mysrcpad, FALSE); |
|
175 gst_pad_set_active (mysinkpad, FALSE); |
|
176 gst_check_teardown_src_pad (videorate); |
|
177 gst_check_teardown_sink_pad (videorate); |
|
178 gst_check_teardown_element (videorate); |
|
179 } |
|
180 |
|
181 void test_one() |
|
182 { |
|
183 GstElement *videorate; |
|
184 GstBuffer *inbuffer; |
|
185 GstCaps *caps; |
|
186 //gst_init(NULL,NULL); |
|
187 videorate = setup_videorate (); |
|
188 fail_unless (gst_element_set_state (videorate, |
|
189 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
190 "could not set to playing"); |
|
191 |
|
192 inbuffer = gst_buffer_new_and_alloc (4); |
|
193 memset (GST_BUFFER_DATA (inbuffer), 0, 4); |
|
194 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
195 gst_buffer_set_caps (inbuffer, caps); |
|
196 GST_BUFFER_TIMESTAMP (inbuffer) = 0; |
|
197 gst_caps_unref (caps); |
|
198 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); |
|
199 |
|
200 /* pushing gives away my reference ... */ |
|
201 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); |
|
202 /* ... and it is now stuck inside videorate */ |
|
203 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); |
|
204 fail_unless_equals_int (g_list_length (buffers), 0); |
|
205 |
|
206 /* cleanup */ |
|
207 cleanup_videorate (videorate); |
|
208 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
209 create_xml(0); |
|
210 } |
|
211 |
|
212 //GST_END_TEST; |
|
213 |
|
214 void test_more() |
|
215 { |
|
216 GstElement *videorate; |
|
217 GstBuffer *first, *second, *third, *outbuffer; |
|
218 GList *l; |
|
219 GstCaps *caps; |
|
220 GRand *rand; |
|
221 |
|
222 videorate = setup_videorate (); |
|
223 fail_unless (gst_element_set_state (videorate, |
|
224 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
225 "could not set to playing"); |
|
226 assert_videorate_stats (videorate, "creation", 0, 0, 0, 0); |
|
227 |
|
228 rand = g_rand_new (); |
|
229 |
|
230 /* first buffer */ |
|
231 first = gst_buffer_new_and_alloc (4); |
|
232 GST_BUFFER_TIMESTAMP (first) = 0; |
|
233 /* it shouldn't matter what the offsets are, videorate produces perfect |
|
234 streams */ |
|
235 GST_BUFFER_OFFSET (first) = g_rand_int (rand); |
|
236 GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); |
|
237 memset (GST_BUFFER_DATA (first), 1, 4); |
|
238 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
239 gst_buffer_set_caps (first, caps); |
|
240 gst_caps_unref (caps); |
|
241 ASSERT_BUFFER_REFCOUNT (first, "first", 1); |
|
242 gst_buffer_ref (first); |
|
243 |
|
244 /* pushing gives away my reference ... */ |
|
245 fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); |
|
246 /* ... and it is now stuck inside videorate */ |
|
247 ASSERT_BUFFER_REFCOUNT (first, "first", 2); |
|
248 fail_unless_equals_int (g_list_length (buffers), 0); |
|
249 assert_videorate_stats (videorate, "first buffer", 1, 0, 0, 0); |
|
250 |
|
251 /* second buffer; inbetween second and third output frame's timestamp */ |
|
252 second = gst_buffer_new_and_alloc (4); |
|
253 GST_BUFFER_TIMESTAMP (second) = GST_SECOND * 3 / 50; |
|
254 GST_BUFFER_OFFSET (first) = g_rand_int (rand); |
|
255 GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); |
|
256 memset (GST_BUFFER_DATA (second), 2, 4); |
|
257 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
258 gst_buffer_set_caps (second, caps); |
|
259 gst_caps_unref (caps); |
|
260 ASSERT_BUFFER_REFCOUNT (second, "second", 1); |
|
261 gst_buffer_ref (second); |
|
262 |
|
263 /* pushing gives away one of my references ... */ |
|
264 fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); |
|
265 /* ... and it is now stuck inside videorate */ |
|
266 ASSERT_BUFFER_REFCOUNT (second, "second", 2); |
|
267 |
|
268 /* ... and the first one is pushed out, with timestamp 0 */ |
|
269 fail_unless_equals_int (g_list_length (buffers), 1); |
|
270 assert_videorate_stats (videorate, "second buffer", 2, 1, 0, 0); |
|
271 ASSERT_BUFFER_REFCOUNT (first, "first", 2); |
|
272 |
|
273 outbuffer = buffers->data; |
|
274 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), 0); |
|
275 |
|
276 /* third buffer */ |
|
277 third = gst_buffer_new_and_alloc (4); |
|
278 GST_BUFFER_TIMESTAMP (third) = GST_SECOND * 12 / 50; |
|
279 GST_BUFFER_OFFSET (first) = g_rand_int (rand); |
|
280 GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); |
|
281 memset (GST_BUFFER_DATA (third), 3, 4); |
|
282 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
283 gst_buffer_set_caps (third, caps); |
|
284 gst_caps_unref (caps); |
|
285 ASSERT_BUFFER_REFCOUNT (third, "third", 1); |
|
286 gst_buffer_ref (third); |
|
287 |
|
288 /* pushing gives away my reference ... */ |
|
289 fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); |
|
290 /* ... and it is now stuck inside videorate */ |
|
291 ASSERT_BUFFER_REFCOUNT (third, "third", 2); |
|
292 |
|
293 /* submitting the third buffer has triggered flushing of three more frames */ |
|
294 assert_videorate_stats (videorate, "third buffer", 3, 4, 0, 2); |
|
295 |
|
296 /* check timestamp and source correctness */ |
|
297 l = buffers; |
|
298 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), 0); |
|
299 fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 1); |
|
300 fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 0); |
|
301 fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 1); |
|
302 |
|
303 l = g_list_next (l); |
|
304 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), GST_SECOND / 25); |
|
305 fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); |
|
306 fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 1); |
|
307 fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 2); |
|
308 |
|
309 l = g_list_next (l); |
|
310 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), |
|
311 GST_SECOND * 2 / 25); |
|
312 fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); |
|
313 fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 2); |
|
314 fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 3); |
|
315 |
|
316 l = g_list_next (l); |
|
317 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), |
|
318 GST_SECOND * 3 / 25); |
|
319 fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); |
|
320 fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 3); |
|
321 fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 4); |
|
322 |
|
323 fail_unless_equals_int (g_list_length (buffers), 4); |
|
324 /* one held by us, three held by each output frame taken from the second */ |
|
325 ASSERT_BUFFER_REFCOUNT (second, "second", 4); |
|
326 |
|
327 /* now send EOS */ |
|
328 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ())); |
|
329 |
|
330 /* submitting eos should flush out two more frames for tick 8 and 10 */ |
|
331 /* FIXME: right now it only flushes out one, so out is 5 instead of 6 ! */ |
|
332 assert_videorate_stats (videorate, "eos", 3, 5, 0, 2); |
|
333 fail_unless_equals_int (g_list_length (buffers), 5); |
|
334 |
|
335 /* cleanup */ |
|
336 g_rand_free (rand); |
|
337 gst_buffer_unref (first); |
|
338 gst_buffer_unref (second); |
|
339 gst_buffer_unref (third); |
|
340 cleanup_videorate (videorate); |
|
341 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
342 create_xml(0); |
|
343 } |
|
344 |
|
345 //GST_END_TEST; |
|
346 |
|
347 /* frames at 1, 0, 2 -> second one should be ignored */ |
|
348 void test_wrong_order_from_zero() |
|
349 { |
|
350 GstElement *videorate; |
|
351 GstBuffer *first, *second, *third, *outbuffer; |
|
352 GstCaps *caps; |
|
353 |
|
354 videorate = setup_videorate (); |
|
355 fail_unless (gst_element_set_state (videorate, |
|
356 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
357 "could not set to playing"); |
|
358 assert_videorate_stats (videorate, "start", 0, 0, 0, 0); |
|
359 |
|
360 /* first buffer */ |
|
361 first = gst_buffer_new_and_alloc (4); |
|
362 GST_BUFFER_TIMESTAMP (first) = GST_SECOND; |
|
363 memset (GST_BUFFER_DATA (first), 0, 4); |
|
364 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
365 gst_buffer_set_caps (first, caps); |
|
366 gst_caps_unref (caps); |
|
367 ASSERT_BUFFER_REFCOUNT (first, "first", 1); |
|
368 gst_buffer_ref (first); |
|
369 |
|
370 GST_DEBUG ("pushing first buffer"); |
|
371 /* pushing gives away my reference ... */ |
|
372 fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); |
|
373 /* ... and it is now stuck inside videorate */ |
|
374 ASSERT_BUFFER_REFCOUNT (first, "first", 2); |
|
375 fail_unless_equals_int (g_list_length (buffers), 0); |
|
376 assert_videorate_stats (videorate, "first", 1, 0, 0, 0); |
|
377 |
|
378 /* second buffer */ |
|
379 second = gst_buffer_new_and_alloc (4); |
|
380 GST_BUFFER_TIMESTAMP (second) = 0; |
|
381 memset (GST_BUFFER_DATA (second), 0, 4); |
|
382 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
383 gst_buffer_set_caps (second, caps); |
|
384 gst_caps_unref (caps); |
|
385 ASSERT_BUFFER_REFCOUNT (second, "second", 1); |
|
386 gst_buffer_ref (second); |
|
387 |
|
388 /* pushing gives away my reference ... */ |
|
389 fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); |
|
390 /* ... and it is now dropped because it is too old */ |
|
391 ASSERT_BUFFER_REFCOUNT (second, "second", 1); |
|
392 fail_unless_equals_int (g_list_length (buffers), 0); |
|
393 |
|
394 /* ... and the first one is still there */ |
|
395 assert_videorate_stats (videorate, "second", 2, 0, 1, 0); |
|
396 ASSERT_BUFFER_REFCOUNT (first, "first", 2); |
|
397 |
|
398 /* third buffer */ |
|
399 third = gst_buffer_new_and_alloc (4); |
|
400 GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND; |
|
401 memset (GST_BUFFER_DATA (third), 0, 4); |
|
402 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
403 gst_buffer_set_caps (third, caps); |
|
404 gst_caps_unref (caps); |
|
405 ASSERT_BUFFER_REFCOUNT (third, "third", 1); |
|
406 gst_buffer_ref (third); |
|
407 |
|
408 /* pushing gives away my reference ... */ |
|
409 fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); |
|
410 /* ... and it is now stuck inside videorate */ |
|
411 ASSERT_BUFFER_REFCOUNT (third, "third", 2); |
|
412 |
|
413 /* and now the first one should be pushed once and dupped 24 + 13 times, to |
|
414 * reach the half point between 1 s (first) and 2 s (third) */ |
|
415 fail_unless_equals_int (g_list_length (buffers), 38); |
|
416 ASSERT_BUFFER_REFCOUNT (first, "first", 39); |
|
417 ASSERT_BUFFER_REFCOUNT (second, "second", 1); |
|
418 ASSERT_BUFFER_REFCOUNT (third, "third", 2); |
|
419 assert_videorate_stats (videorate, "third", 3, 38, 1, 37); |
|
420 |
|
421 /* verify last buffer */ |
|
422 outbuffer = g_list_last (buffers)->data; |
|
423 fail_unless (GST_IS_BUFFER (outbuffer)); |
|
424 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), |
|
425 GST_SECOND * 37 / 25); |
|
426 |
|
427 /* cleanup */ |
|
428 gst_buffer_unref (first); |
|
429 gst_buffer_unref (second); |
|
430 gst_buffer_unref (third); |
|
431 cleanup_videorate (videorate); |
|
432 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
433 create_xml(0); |
|
434 } |
|
435 |
|
436 //GST_END_TEST; |
|
437 |
|
438 /* send frames with 0, 1, 2, 0 seconds */ |
|
439 void test_wrong_order() |
|
440 { |
|
441 GstElement *videorate; |
|
442 GstBuffer *first, *second, *third, *fourth, *outbuffer; |
|
443 GstCaps *caps; |
|
444 |
|
445 videorate = setup_videorate (); |
|
446 fail_unless (gst_element_set_state (videorate, |
|
447 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
448 "could not set to playing"); |
|
449 assert_videorate_stats (videorate, "start", 0, 0, 0, 0); |
|
450 |
|
451 /* first buffer */ |
|
452 first = gst_buffer_new_and_alloc (4); |
|
453 GST_BUFFER_TIMESTAMP (first) = 0; |
|
454 memset (GST_BUFFER_DATA (first), 0, 4); |
|
455 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
456 gst_buffer_set_caps (first, caps); |
|
457 gst_caps_unref (caps); |
|
458 ASSERT_BUFFER_REFCOUNT (first, "first", 1); |
|
459 gst_buffer_ref (first); |
|
460 |
|
461 GST_DEBUG ("pushing first buffer"); |
|
462 /* pushing gives away my reference ... */ |
|
463 fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); |
|
464 /* ... and it is now stuck inside videorate */ |
|
465 ASSERT_BUFFER_REFCOUNT (first, "first", 2); |
|
466 fail_unless_equals_int (g_list_length (buffers), 0); |
|
467 assert_videorate_stats (videorate, "first", 1, 0, 0, 0); |
|
468 |
|
469 /* second buffer */ |
|
470 second = gst_buffer_new_and_alloc (4); |
|
471 GST_BUFFER_TIMESTAMP (second) = GST_SECOND; |
|
472 memset (GST_BUFFER_DATA (second), 0, 4); |
|
473 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
474 gst_buffer_set_caps (second, caps); |
|
475 gst_caps_unref (caps); |
|
476 ASSERT_BUFFER_REFCOUNT (second, "second", 1); |
|
477 gst_buffer_ref (second); |
|
478 |
|
479 /* pushing gives away my reference ... */ |
|
480 fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); |
|
481 /* ... and it is now stuck inside videorate */ |
|
482 ASSERT_BUFFER_REFCOUNT (second, "second", 2); |
|
483 /* and it created 13 output buffers as copies of the first frame */ |
|
484 fail_unless_equals_int (g_list_length (buffers), 13); |
|
485 assert_videorate_stats (videorate, "second", 2, 13, 0, 12); |
|
486 ASSERT_BUFFER_REFCOUNT (first, "first", 14); |
|
487 |
|
488 /* third buffer */ |
|
489 third = gst_buffer_new_and_alloc (4); |
|
490 GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND; |
|
491 memset (GST_BUFFER_DATA (third), 0, 4); |
|
492 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
493 gst_buffer_set_caps (third, caps); |
|
494 gst_caps_unref (caps); |
|
495 ASSERT_BUFFER_REFCOUNT (third, "third", 1); |
|
496 gst_buffer_ref (third); |
|
497 |
|
498 /* pushing gives away my reference ... */ |
|
499 fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); |
|
500 /* ... and it is now stuck inside videorate */ |
|
501 ASSERT_BUFFER_REFCOUNT (third, "third", 2); |
|
502 |
|
503 /* submitting a frame with 2 seconds triggers output of 25 more frames */ |
|
504 fail_unless_equals_int (g_list_length (buffers), 38); |
|
505 ASSERT_BUFFER_REFCOUNT (first, "first", 14); |
|
506 ASSERT_BUFFER_REFCOUNT (second, "second", 26); |
|
507 /* three frames submitted; two of them output as is, and 36 duplicated */ |
|
508 assert_videorate_stats (videorate, "third", 3, 38, 0, 36); |
|
509 |
|
510 /* fourth buffer */ |
|
511 fourth = gst_buffer_new_and_alloc (4); |
|
512 GST_BUFFER_TIMESTAMP (fourth) = 0; |
|
513 memset (GST_BUFFER_DATA (fourth), 0, 4); |
|
514 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
515 gst_buffer_set_caps (fourth, caps); |
|
516 gst_caps_unref (caps); |
|
517 ASSERT_BUFFER_REFCOUNT (fourth, "fourth", 1); |
|
518 gst_buffer_ref (fourth); |
|
519 |
|
520 /* pushing gives away my reference ... */ |
|
521 fail_unless (gst_pad_push (mysrcpad, fourth) == GST_FLOW_OK); |
|
522 /* ... and it is dropped */ |
|
523 ASSERT_BUFFER_REFCOUNT (fourth, "fourth", 1); |
|
524 |
|
525 fail_unless_equals_int (g_list_length (buffers), 38); |
|
526 ASSERT_BUFFER_REFCOUNT (first, "first", 14); |
|
527 ASSERT_BUFFER_REFCOUNT (second, "second", 26); |
|
528 assert_videorate_stats (videorate, "fourth", 4, 38, 1, 36); |
|
529 |
|
530 /* verify last buffer */ |
|
531 outbuffer = g_list_last (buffers)->data; |
|
532 fail_unless (GST_IS_BUFFER (outbuffer)); |
|
533 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), |
|
534 GST_SECOND * 37 / 25); |
|
535 |
|
536 |
|
537 /* cleanup */ |
|
538 gst_buffer_unref (first); |
|
539 gst_buffer_unref (second); |
|
540 gst_buffer_unref (third); |
|
541 gst_buffer_unref (fourth); |
|
542 cleanup_videorate (videorate); |
|
543 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
544 create_xml(0); |
|
545 } |
|
546 |
|
547 //GST_END_TEST; |
|
548 |
|
549 |
|
550 /* if no framerate is negotiated, we should not be able to push a buffer */ |
|
551 void test_no_framerate() |
|
552 { |
|
553 GstElement *videorate; |
|
554 GstBuffer *inbuffer; |
|
555 GstCaps *caps; |
|
556 |
|
557 videorate = setup_videorate (); |
|
558 fail_unless (gst_element_set_state (videorate, |
|
559 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
560 "could not set to playing"); |
|
561 |
|
562 inbuffer = gst_buffer_new_and_alloc (4); |
|
563 memset (GST_BUFFER_DATA (inbuffer), 0, 4); |
|
564 caps = gst_caps_from_string (VIDEO_CAPS_NO_FRAMERATE_STRING); |
|
565 gst_buffer_set_caps (inbuffer, caps); |
|
566 gst_caps_unref (caps); |
|
567 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); |
|
568 |
|
569 /* take a ref so we can later check refcount */ |
|
570 gst_buffer_ref (inbuffer); |
|
571 |
|
572 /* no framerate is negotiated so pushing should fail */ |
|
573 fail_if (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); |
|
574 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); |
|
575 gst_buffer_unref (inbuffer); |
|
576 fail_unless_equals_int (g_list_length (buffers), 0); |
|
577 |
|
578 /* cleanup */ |
|
579 cleanup_videorate (videorate); |
|
580 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
581 create_xml(0); |
|
582 } |
|
583 |
|
584 //GST_END_TEST; |
|
585 |
|
586 /* This test outputs 2 buffers of same dimensions (320x240), then 1 buffer of |
|
587 * differing dimensions (240x120), and then another buffer of previous |
|
588 * dimensions (320x240) and checks that the 3 buffers output as a result have |
|
589 * correct caps (first 2 with 320x240 and 3rd with 240x120). |
|
590 */ |
|
591 void test_changing_size() |
|
592 { |
|
593 GstElement *videorate; |
|
594 GstBuffer *first; |
|
595 GstBuffer *second; |
|
596 GstBuffer *third; |
|
597 GstBuffer *fourth; |
|
598 GstBuffer *fifth; |
|
599 GstBuffer *outbuf; |
|
600 GstEvent *newsegment; |
|
601 GstCaps *caps, *caps_newsize; |
|
602 |
|
603 videorate = setup_videorate (); |
|
604 fail_unless (gst_element_set_state (videorate, |
|
605 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
606 "could not set to playing"); |
|
607 |
|
608 newsegment = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, |
|
609 0); |
|
610 fail_unless (gst_pad_push_event (mysrcpad, newsegment) == TRUE); |
|
611 |
|
612 first = gst_buffer_new_and_alloc (4); |
|
613 memset (GST_BUFFER_DATA (first), 0, 4); |
|
614 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
615 GST_BUFFER_TIMESTAMP (first) = 0; |
|
616 gst_buffer_set_caps (first, caps); |
|
617 |
|
618 GST_DEBUG ("pushing first buffer"); |
|
619 fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); |
|
620 |
|
621 /* second buffer */ |
|
622 second = gst_buffer_new_and_alloc (4); |
|
623 GST_BUFFER_TIMESTAMP (second) = GST_SECOND / 25; |
|
624 memset (GST_BUFFER_DATA (second), 0, 4); |
|
625 gst_buffer_set_caps (second, caps); |
|
626 |
|
627 fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); |
|
628 fail_unless_equals_int (g_list_length (buffers), 1); |
|
629 outbuf = buffers->data; |
|
630 /* first buffer should be output here */ |
|
631 fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (outbuf), caps)); |
|
632 fail_unless (GST_BUFFER_TIMESTAMP (outbuf) == 0); |
|
633 |
|
634 /* third buffer with new size */ |
|
635 third = gst_buffer_new_and_alloc (4); |
|
636 GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND / 25; |
|
637 memset (GST_BUFFER_DATA (third), 0, 4); |
|
638 caps_newsize = gst_caps_from_string (VIDEO_CAPS_NEWSIZE_STRING); |
|
639 gst_buffer_set_caps (third, caps_newsize); |
|
640 |
|
641 fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); |
|
642 /* new caps flushed the internal state, no new output yet */ |
|
643 fail_unless_equals_int (g_list_length (buffers), 1); |
|
644 outbuf = g_list_last (buffers)->data; |
|
645 /* first buffer should be output here */ |
|
646 fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (outbuf), caps)); |
|
647 fail_unless (GST_BUFFER_TIMESTAMP (outbuf) == 0); |
|
648 |
|
649 /* fourth buffer with original size */ |
|
650 fourth = gst_buffer_new_and_alloc (4); |
|
651 GST_BUFFER_TIMESTAMP (fourth) = 3 * GST_SECOND / 25; |
|
652 memset (GST_BUFFER_DATA (fourth), 0, 4); |
|
653 gst_buffer_set_caps (fourth, caps); |
|
654 |
|
655 fail_unless (gst_pad_push (mysrcpad, fourth) == GST_FLOW_OK); |
|
656 fail_unless_equals_int (g_list_length (buffers), 1); |
|
657 |
|
658 /* fifth buffer with original size */ |
|
659 fifth = gst_buffer_new_and_alloc (4); |
|
660 GST_BUFFER_TIMESTAMP (fifth) = 4 * GST_SECOND / 25; |
|
661 memset (GST_BUFFER_DATA (fifth), 0, 4); |
|
662 gst_buffer_set_caps (fifth, caps); |
|
663 |
|
664 fail_unless (gst_pad_push (mysrcpad, fifth) == GST_FLOW_OK); |
|
665 /* all four missing buffers here, dups of fourth buffer */ |
|
666 fail_unless_equals_int (g_list_length (buffers), 4); |
|
667 outbuf = g_list_last (buffers)->data; |
|
668 /* third buffer should be output here */ |
|
669 fail_unless (GST_BUFFER_TIMESTAMP (outbuf) == 3 * GST_SECOND / 25); |
|
670 fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (outbuf), caps)); |
|
671 |
|
672 gst_caps_unref (caps); |
|
673 gst_caps_unref (caps_newsize); |
|
674 cleanup_videorate (videorate); |
|
675 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
676 create_xml(0); |
|
677 } |
|
678 |
|
679 //GST_END_TEST; |
|
680 |
|
681 void test_non_ok_flow() |
|
682 { |
|
683 GstElement *videorate; |
|
684 GstClockTime ts; |
|
685 GstBuffer *buf; |
|
686 GstCaps *caps; |
|
687 |
|
688 videorate = setup_videorate (); |
|
689 fail_unless (gst_element_set_state (videorate, |
|
690 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, |
|
691 "could not set to playing"); |
|
692 |
|
693 buf = gst_buffer_new_and_alloc (4); |
|
694 memset (GST_BUFFER_DATA (buf), 0, 4); |
|
695 caps = gst_caps_from_string (VIDEO_CAPS_STRING); |
|
696 gst_buffer_set_caps (buf, caps); |
|
697 gst_caps_unref (caps); |
|
698 ASSERT_BUFFER_REFCOUNT (buf, "inbuffer", 1); |
|
699 |
|
700 /* push a few 'normal' buffers */ |
|
701 for (ts = 0; ts < 100 * GST_SECOND; ts += GST_SECOND / 33) { |
|
702 GstBuffer *inbuf; |
|
703 |
|
704 inbuf = gst_buffer_copy (buf); |
|
705 GST_BUFFER_TIMESTAMP (inbuf) = ts; |
|
706 |
|
707 fail_unless_equals_int (gst_pad_push (mysrcpad, inbuf), GST_FLOW_OK); |
|
708 } |
|
709 |
|
710 /* we should have buffers according to the output framerate of 25/1 */ |
|
711 fail_unless_equals_int (g_list_length (buffers), 100 * 25); |
|
712 |
|
713 /* now deactivate pad so we get a WRONG_STATE flow return */ |
|
714 gst_pad_set_active (mysinkpad, FALSE); |
|
715 |
|
716 /* push buffer on deactivated pad */ |
|
717 fail_unless (gst_buffer_is_metadata_writable (buf)); |
|
718 GST_BUFFER_TIMESTAMP (buf) = ts; |
|
719 |
|
720 /* pushing gives away our reference */ |
|
721 fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_WRONG_STATE); |
|
722 |
|
723 /* cleanup */ |
|
724 cleanup_videorate (videorate); |
|
725 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
726 create_xml(0); |
|
727 } |
|
728 |
|
729 //GST_END_TEST; |
|
730 |
|
731 /*static Suite * |
|
732 videorate_suite (void) |
|
733 { |
|
734 Suite *s = suite_create ("videorate"); |
|
735 TCase *tc_chain = tcase_create ("general"); |
|
736 |
|
737 suite_add_tcase (s, tc_chain); |
|
738 tcase_add_test (tc_chain, test_one); |
|
739 tcase_add_test (tc_chain, test_more); |
|
740 tcase_add_test (tc_chain, test_wrong_order_from_zero); |
|
741 tcase_add_test (tc_chain, test_wrong_order); |
|
742 tcase_add_test (tc_chain, test_no_framerate); |
|
743 tcase_add_test (tc_chain, test_changing_size); |
|
744 tcase_add_test (tc_chain, test_non_ok_flow); |
|
745 |
|
746 return s; |
|
747 }*/ |
|
748 |
|
749 void (*fn[]) (void) = { |
|
750 test_one, |
|
751 test_more, |
|
752 test_wrong_order_from_zero, |
|
753 test_wrong_order, |
|
754 test_no_framerate, |
|
755 test_changing_size, |
|
756 test_non_ok_flow |
|
757 |
|
758 |
|
759 }; |
|
760 |
|
761 char *args[] = { |
|
762 "test_one", |
|
763 "test_more", |
|
764 "test_wrong_order_from_zero", |
|
765 "test_wrong_order", |
|
766 "test_no_framerate", |
|
767 "test_changing_size", |
|
768 "test_non_ok_flow" |
|
769 |
|
770 }; |
|
771 |
|
772 GST_CHECK_MAIN (videorate) |
|
773 /*void main() |
|
774 { |
|
775 gst_init(NULL,NULL); |
|
776 test_one(); |
|
777 test_more(); |
|
778 test_wrong_order_from_zero(); |
|
779 test_wrong_order(); |
|
780 test_no_framerate(); |
|
781 test_changing_size(); |
|
782 test_non_ok_flow(); |
|
783 }*/ |