|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
3 * |
|
4 * This library is free software; you can redistribute it and/or |
|
5 * modify it under the terms of the GNU Lesser General Public |
|
6 * License as published by the Free Software Foundation; either |
|
7 * version 2 of the License, or (at your option) any later version. |
|
8 * |
|
9 * This library is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 * Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public |
|
15 * License along with this library; if not, write to the |
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
17 * Boston, MA 02111-1307, USA. |
|
18 * |
|
19 * Description: |
|
20 * |
|
21 */ |
|
22 |
|
23 /* GStreamer |
|
24 * Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com> |
|
25 * |
|
26 * gstsegment.c: Unit test for segments |
|
27 * |
|
28 * This library is free software; you can redistribute it and/or |
|
29 * modify it under the terms of the GNU Library General Public |
|
30 * License as published by the Free Software Foundation; either |
|
31 * version 2 of the License, or (at your option) any later version. |
|
32 * |
|
33 * This library is distributed in the hope that it will be useful, |
|
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
36 * Library General Public License for more details. |
|
37 * |
|
38 * You should have received a copy of the GNU Library General Public |
|
39 * License along with this library; if not, write to the |
|
40 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
41 * Boston, MA 02111-1307, USA. |
|
42 */ |
|
43 |
|
44 |
|
45 #include <gst/gst_global.h> |
|
46 #include <gst/check/gstcheck.h> |
|
47 |
|
48 #define LOG_FILE "c:\\logs\\gstsegment_logs.txt" |
|
49 #include "std_log_result.h" |
|
50 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
51 |
|
52 |
|
53 #if EMULATOR |
|
54 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean) |
|
55 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)()) |
|
56 #else |
|
57 extern gboolean _gst_check_raised_critical; |
|
58 #endif |
|
59 |
|
60 //gboolean _gst_check_expecting_log = FALSE; |
|
61 #if EMULATOR |
|
62 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean) |
|
63 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)()) |
|
64 #else |
|
65 extern gboolean _gst_check_expecting_log; |
|
66 #endif |
|
67 |
|
68 |
|
69 //char* xmlfile = "gstsegment"; |
|
70 |
|
71 void create_xml(int result) |
|
72 { |
|
73 if(result) |
|
74 assert_failed = 1; |
|
75 |
|
76 testResultXml(xmlfile); |
|
77 close_log_file(); |
|
78 } |
|
79 |
|
80 void segment_seek_nosize() |
|
81 { |
|
82 GstSegment segment; |
|
83 gboolean res; |
|
84 gint64 cstart, cstop; |
|
85 gboolean update; |
|
86 |
|
87 xmlfile = "segment_seek_nosize"; |
|
88 std_log(LOG_FILENAME_LINE, "Test Started segment_seek_nosize"); |
|
89 |
|
90 gst_segment_init (&segment, GST_FORMAT_BYTES); |
|
91 |
|
92 /* configure segment to start 100 */ |
|
93 gst_segment_set_seek (&segment, 1.0, |
|
94 GST_FORMAT_BYTES, |
|
95 GST_SEEK_FLAG_NONE, |
|
96 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update); |
|
97 fail_unless (segment.start == 100); |
|
98 fail_unless (segment.stop == -1); |
|
99 fail_unless (update == TRUE); |
|
100 |
|
101 /* configure segment to stop relative, should not do anything since |
|
102 * size is unknown. */ |
|
103 gst_segment_set_seek (&segment, 1.0, |
|
104 GST_FORMAT_BYTES, |
|
105 GST_SEEK_FLAG_NONE, |
|
106 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update); |
|
107 fail_unless (segment.start == 100); |
|
108 fail_unless (segment.stop == -1); |
|
109 fail_unless (update == FALSE); |
|
110 |
|
111 /* do some clipping on the open range */ |
|
112 /* completely outside */ |
|
113 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop); |
|
114 fail_unless (res == FALSE); |
|
115 |
|
116 /* touching lower bound, still outside of the segment */ |
|
117 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop); |
|
118 fail_unless (res == FALSE); |
|
119 |
|
120 /* partially inside */ |
|
121 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop); |
|
122 fail_unless (res == TRUE); |
|
123 fail_unless (cstart == 100); |
|
124 fail_unless (cstop == 150); |
|
125 |
|
126 /* inside, touching lower bound */ |
|
127 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
128 100, 150, &cstart, &cstop); |
|
129 fail_unless (res == TRUE); |
|
130 fail_unless (cstart == 100); |
|
131 fail_unless (cstop == 150); |
|
132 |
|
133 /* special case, 0 duration */ |
|
134 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
135 100, 100, &cstart, &cstop); |
|
136 fail_unless (res == TRUE); |
|
137 fail_unless (cstart == 100); |
|
138 fail_unless (cstop == 100); |
|
139 |
|
140 /* completely inside */ |
|
141 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
142 150, 200, &cstart, &cstop); |
|
143 fail_unless (res == TRUE); |
|
144 fail_unless (cstart == 150); |
|
145 fail_unless (cstop == 200); |
|
146 |
|
147 /* invalid start */ |
|
148 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop); |
|
149 fail_unless (res == FALSE); |
|
150 |
|
151 /* start outside, we don't know the stop */ |
|
152 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop); |
|
153 fail_unless (res == TRUE); |
|
154 fail_unless (cstart == 100); |
|
155 fail_unless (cstop == -1); |
|
156 |
|
157 /* start on lower bound */ |
|
158 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop); |
|
159 fail_unless (res == TRUE); |
|
160 fail_unless (cstart == 100); |
|
161 fail_unless (cstop == -1); |
|
162 |
|
163 /* start inside */ |
|
164 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop); |
|
165 fail_unless (res == TRUE); |
|
166 fail_unless (cstart == 150); |
|
167 fail_unless (cstop == -1); |
|
168 |
|
169 /* add 100 to start, set stop to 300 */ |
|
170 gst_segment_set_seek (&segment, 1.0, |
|
171 GST_FORMAT_BYTES, |
|
172 GST_SEEK_FLAG_NONE, |
|
173 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update); |
|
174 fail_unless (segment.start == 200); |
|
175 fail_unless (segment.stop == 300); |
|
176 fail_unless (update == TRUE); |
|
177 |
|
178 update = FALSE; |
|
179 /* add 100 to start (to 300), set stop to 200, this is not allowed. |
|
180 * nothing should be updated in the segment. A g_warning is |
|
181 * emited. */ |
|
182 ASSERT_CRITICAL(gst_segment_set_seek (&segment, 1.0, |
|
183 GST_FORMAT_BYTES, |
|
184 GST_SEEK_FLAG_NONE, |
|
185 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update)); |
|
186 |
|
187 fail_unless (segment.start == 200); |
|
188 fail_unless (segment.stop == 300); |
|
189 /* update didn't change */ |
|
190 fail_unless (update == FALSE); |
|
191 |
|
192 update = TRUE; |
|
193 /* seek relative to end, should not do anything since size is |
|
194 * unknown. */ |
|
195 gst_segment_set_seek (&segment, 1.0, |
|
196 GST_FORMAT_BYTES, |
|
197 GST_SEEK_FLAG_NONE, |
|
198 GST_SEEK_TYPE_END, -300, GST_SEEK_TYPE_END, -100, &update); |
|
199 fail_unless (segment.start == 200); |
|
200 fail_unless (segment.stop == 300); |
|
201 fail_unless (update == FALSE); |
|
202 |
|
203 /* completely outside */ |
|
204 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop); |
|
205 fail_unless (res == FALSE); |
|
206 |
|
207 /* touching lower bound */ |
|
208 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 200, &cstart, &cstop); |
|
209 fail_unless (res == FALSE); |
|
210 |
|
211 /* partially inside */ |
|
212 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 250, &cstart, &cstop); |
|
213 fail_unless (res == TRUE); |
|
214 fail_unless (cstart == 200); |
|
215 fail_unless (cstop == 250); |
|
216 |
|
217 /* inside, touching lower bound */ |
|
218 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
219 200, 250, &cstart, &cstop); |
|
220 fail_unless (res == TRUE); |
|
221 fail_unless (cstart == 200); |
|
222 fail_unless (cstop == 250); |
|
223 |
|
224 /* completely inside */ |
|
225 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
226 250, 290, &cstart, &cstop); |
|
227 fail_unless (res == TRUE); |
|
228 fail_unless (cstart == 250); |
|
229 fail_unless (cstop == 290); |
|
230 |
|
231 /* partially inside */ |
|
232 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
233 250, 350, &cstart, &cstop); |
|
234 fail_unless (res == TRUE); |
|
235 fail_unless (cstart == 250); |
|
236 fail_unless (cstop == 300); |
|
237 |
|
238 /* invalid start */ |
|
239 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop); |
|
240 fail_unless (res == FALSE); |
|
241 |
|
242 /* start outside */ |
|
243 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop); |
|
244 fail_unless (res == TRUE); |
|
245 fail_unless (cstart == 200); |
|
246 fail_unless (cstop == 300); |
|
247 |
|
248 /* start on lower bound */ |
|
249 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 200, -1, &cstart, &cstop); |
|
250 fail_unless (res == TRUE); |
|
251 fail_unless (cstart == 200); |
|
252 fail_unless (cstop == 300); |
|
253 |
|
254 /* start inside */ |
|
255 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop); |
|
256 fail_unless (res == TRUE); |
|
257 fail_unless (cstart == 250); |
|
258 fail_unless (cstop == 300); |
|
259 |
|
260 /* start outside on boundary */ |
|
261 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 300, -1, &cstart, &cstop); |
|
262 fail_unless (res == FALSE); |
|
263 |
|
264 /* start completely outside */ |
|
265 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 350, -1, &cstart, &cstop); |
|
266 fail_unless (res == FALSE); |
|
267 |
|
268 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
269 create_xml(0); |
|
270 } |
|
271 |
|
272 |
|
273 /* mess with the segment structure in the bytes format */ |
|
274 void segment_seek_size() |
|
275 { |
|
276 GstSegment segment; |
|
277 gboolean res; |
|
278 gint64 cstart, cstop; |
|
279 gboolean update; |
|
280 |
|
281 xmlfile = "segment_seek_size"; |
|
282 std_log(LOG_FILENAME_LINE, "Test Started segment_seek_size"); |
|
283 |
|
284 gst_segment_init (&segment, GST_FORMAT_BYTES); |
|
285 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200); |
|
286 |
|
287 /* configure segment to start 100 */ |
|
288 gst_segment_set_seek (&segment, 1.0, |
|
289 GST_FORMAT_BYTES, |
|
290 GST_SEEK_FLAG_NONE, |
|
291 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update); |
|
292 fail_unless (segment.start == 100); |
|
293 fail_unless (segment.stop == -1); |
|
294 fail_unless (update == TRUE); |
|
295 |
|
296 /* configure segment to stop relative, does not update stop |
|
297 * since we did not set it before. */ |
|
298 gst_segment_set_seek (&segment, 1.0, |
|
299 GST_FORMAT_BYTES, |
|
300 GST_SEEK_FLAG_NONE, |
|
301 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update); |
|
302 fail_unless (segment.start == 100); |
|
303 fail_unless (segment.stop == -1); |
|
304 fail_unless (update == FALSE); |
|
305 |
|
306 /* do some clipping on the open range */ |
|
307 /* completely outside */ |
|
308 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop); |
|
309 fail_unless (res == FALSE); |
|
310 |
|
311 /* touching lower bound */ |
|
312 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop); |
|
313 fail_unless (res == FALSE); |
|
314 |
|
315 /* partially inside */ |
|
316 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop); |
|
317 fail_unless (res == TRUE); |
|
318 fail_unless (cstart == 100); |
|
319 fail_unless (cstop == 150); |
|
320 |
|
321 /* inside, touching lower bound */ |
|
322 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
323 100, 150, &cstart, &cstop); |
|
324 fail_unless (res == TRUE); |
|
325 fail_unless (cstart == 100); |
|
326 fail_unless (cstop == 150); |
|
327 |
|
328 /* completely inside */ |
|
329 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
330 150, 200, &cstart, &cstop); |
|
331 fail_unless (res == TRUE); |
|
332 fail_unless (cstart == 150); |
|
333 fail_unless (cstop == 200); |
|
334 |
|
335 /* partially inside, clip to size */ |
|
336 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
337 150, 300, &cstart, &cstop); |
|
338 fail_unless (res == TRUE); |
|
339 fail_unless (cstart == 150); |
|
340 fail_unless (cstop == 200); |
|
341 |
|
342 /* invalid start */ |
|
343 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop); |
|
344 fail_unless (res == FALSE); |
|
345 |
|
346 /* start outside */ |
|
347 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop); |
|
348 fail_unless (res == TRUE); |
|
349 fail_unless (cstart == 100); |
|
350 fail_unless (cstop == -1); |
|
351 |
|
352 /* start on lower bound */ |
|
353 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop); |
|
354 fail_unless (res == TRUE); |
|
355 fail_unless (cstart == 100); |
|
356 fail_unless (cstop == -1); |
|
357 |
|
358 /* start inside */ |
|
359 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop); |
|
360 fail_unless (res == TRUE); |
|
361 fail_unless (cstart == 150); |
|
362 fail_unless (cstop == -1); |
|
363 |
|
364 /* add 100 to start, set stop to 300, stop clips to 200 */ |
|
365 gst_segment_set_seek (&segment, 1.0, |
|
366 GST_FORMAT_BYTES, |
|
367 GST_SEEK_FLAG_NONE, |
|
368 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update); |
|
369 fail_unless (segment.start == 200); |
|
370 fail_unless (segment.stop == 200); |
|
371 |
|
372 /* add 100 to start (to 300), set stop to 200, this clips start |
|
373 * to duration */ |
|
374 gst_segment_set_seek (&segment, 1.0, |
|
375 GST_FORMAT_BYTES, |
|
376 GST_SEEK_FLAG_NONE, |
|
377 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update); |
|
378 fail_unless (segment.start == 200); |
|
379 fail_unless (segment.stop == 200); |
|
380 fail_unless (update == FALSE); |
|
381 |
|
382 /* seek relative to end */ |
|
383 gst_segment_set_seek (&segment, 1.0, |
|
384 GST_FORMAT_BYTES, |
|
385 GST_SEEK_FLAG_NONE, |
|
386 GST_SEEK_TYPE_END, -100, GST_SEEK_TYPE_END, -20, &update); |
|
387 fail_unless (segment.start == 100); |
|
388 fail_unless (segment.stop == 180); |
|
389 fail_unless (update == TRUE); |
|
390 |
|
391 /* completely outside */ |
|
392 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop); |
|
393 fail_unless (res == FALSE); |
|
394 |
|
395 /* touching lower bound */ |
|
396 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop); |
|
397 fail_unless (res == FALSE); |
|
398 |
|
399 /* partially inside */ |
|
400 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop); |
|
401 fail_unless (res == TRUE); |
|
402 fail_unless (cstart == 100); |
|
403 fail_unless (cstop == 150); |
|
404 |
|
405 /* inside, touching lower bound */ |
|
406 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
407 100, 150, &cstart, &cstop); |
|
408 fail_unless (res == TRUE); |
|
409 fail_unless (cstart == 100); |
|
410 fail_unless (cstop == 150); |
|
411 |
|
412 /* completely inside */ |
|
413 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
414 150, 170, &cstart, &cstop); |
|
415 fail_unless (res == TRUE); |
|
416 fail_unless (cstart == 150); |
|
417 fail_unless (cstop == 170); |
|
418 |
|
419 /* partially inside */ |
|
420 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, |
|
421 150, 250, &cstart, &cstop); |
|
422 fail_unless (res == TRUE); |
|
423 fail_unless (cstart == 150); |
|
424 fail_unless (cstop == 180); |
|
425 |
|
426 /* invalid start */ |
|
427 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop); |
|
428 fail_unless (res == FALSE); |
|
429 |
|
430 /* start outside */ |
|
431 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop); |
|
432 fail_unless (res == TRUE); |
|
433 fail_unless (cstart == 100); |
|
434 fail_unless (cstop == 180); |
|
435 |
|
436 /* start on lower bound */ |
|
437 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop); |
|
438 fail_unless (res == TRUE); |
|
439 fail_unless (cstart == 100); |
|
440 fail_unless (cstop == 180); |
|
441 |
|
442 /* start inside */ |
|
443 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop); |
|
444 fail_unless (res == TRUE); |
|
445 fail_unless (cstart == 150); |
|
446 fail_unless (cstop == 180); |
|
447 |
|
448 /* start outside on boundary */ |
|
449 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 180, -1, &cstart, &cstop); |
|
450 fail_unless (res == FALSE); |
|
451 |
|
452 /* start completely outside */ |
|
453 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop); |
|
454 fail_unless (res == FALSE); |
|
455 |
|
456 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
457 create_xml(0); |
|
458 } |
|
459 |
|
460 |
|
461 void segment_seek_reverse() |
|
462 { |
|
463 GstSegment segment; |
|
464 gboolean update; |
|
465 |
|
466 xmlfile = "segment_seek_reverse"; |
|
467 std_log(LOG_FILENAME_LINE, "Test Started segment_seek_reverse"); |
|
468 |
|
469 gst_segment_init (&segment, GST_FORMAT_BYTES); |
|
470 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200); |
|
471 |
|
472 /* configure segment to stop 100 */ |
|
473 gst_segment_set_seek (&segment, -1.0, |
|
474 GST_FORMAT_BYTES, |
|
475 GST_SEEK_FLAG_NONE, |
|
476 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 100, &update); |
|
477 fail_unless (segment.start == 0); |
|
478 |
|
479 fail_unless (segment.stop == 100); |
|
480 |
|
481 fail_unless (segment.time == 0); |
|
482 |
|
483 fail_unless (segment.last_stop == 100); |
|
484 |
|
485 fail_unless (update == TRUE); |
|
486 |
|
487 |
|
488 /* update */ |
|
489 gst_segment_set_seek (&segment, -1.0, |
|
490 GST_FORMAT_BYTES, |
|
491 GST_SEEK_FLAG_NONE, |
|
492 GST_SEEK_TYPE_SET, 10, GST_SEEK_TYPE_CUR, -20, &update); |
|
493 fail_unless (segment.start == 10); |
|
494 |
|
495 fail_unless (segment.stop == 80); |
|
496 |
|
497 fail_unless (segment.time == 10); |
|
498 |
|
499 fail_unless (segment.last_stop == 80); |
|
500 |
|
501 fail_unless (update == TRUE); |
|
502 |
|
503 |
|
504 gst_segment_set_seek (&segment, -1.0, |
|
505 GST_FORMAT_BYTES, |
|
506 GST_SEEK_FLAG_NONE, |
|
507 GST_SEEK_TYPE_SET, 20, GST_SEEK_TYPE_NONE, 0, &update); |
|
508 fail_unless (segment.start == 20); |
|
509 |
|
510 fail_unless (segment.stop == 80); |
|
511 |
|
512 fail_unless (segment.time == 20); |
|
513 |
|
514 fail_unless (segment.last_stop == 80); |
|
515 |
|
516 fail_unless (update == FALSE); |
|
517 |
|
518 |
|
519 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
520 create_xml(0); |
|
521 } |
|
522 |
|
523 |
|
524 /* mess with the segment structure in the bytes format */ |
|
525 void segment_seek_rate() |
|
526 { |
|
527 GstSegment segment; |
|
528 gboolean update; |
|
529 |
|
530 xmlfile = "segment_seek_rate"; |
|
531 std_log(LOG_FILENAME_LINE, "Test Started segment_seek_rate"); |
|
532 |
|
533 gst_segment_init (&segment, GST_FORMAT_BYTES); |
|
534 |
|
535 /* configure segment to rate 2.0, format does not matter when we don't specify |
|
536 * a start or stop position. */ |
|
537 gst_segment_set_seek (&segment, 2.0, |
|
538 GST_FORMAT_UNDEFINED, |
|
539 GST_SEEK_FLAG_NONE, |
|
540 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1, &update); |
|
541 fail_unless (segment.format == GST_FORMAT_BYTES); |
|
542 |
|
543 fail_unless (segment.start == 0); |
|
544 |
|
545 fail_unless (segment.stop == -1); |
|
546 |
|
547 fail_unless (segment.rate == 2.0); |
|
548 |
|
549 fail_unless (update == FALSE); |
|
550 |
|
551 |
|
552 /* 0 is the same in all formats and should not fail */ |
|
553 gst_segment_set_seek (&segment, 2.0, |
|
554 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
555 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1, &update); |
|
556 fail_unless (segment.format == GST_FORMAT_BYTES); |
|
557 |
|
558 |
|
559 /* set to -1 means start from 0 */ |
|
560 gst_segment_set_seek (&segment, 2.0, |
|
561 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
562 GST_SEEK_TYPE_SET, -1, GST_SEEK_TYPE_NONE, -1, &update); |
|
563 fail_unless (segment.format == GST_FORMAT_BYTES); |
|
564 |
|
565 fail_unless (segment.start == 0); |
|
566 |
|
567 |
|
568 gst_segment_set_seek (&segment, 2.0, |
|
569 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
570 GST_SEEK_TYPE_CUR, 0, GST_SEEK_TYPE_NONE, -1, &update); |
|
571 |
|
572 gst_segment_set_seek (&segment, 2.0, |
|
573 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
574 GST_SEEK_TYPE_END, 0, GST_SEEK_TYPE_NONE, -1, &update); |
|
575 |
|
576 /* -1 for end is fine too in all formats */ |
|
577 gst_segment_set_seek (&segment, 2.0, |
|
578 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
579 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_SET, -1, &update); |
|
580 |
|
581 /* 0 as relative end is fine too */ |
|
582 gst_segment_set_seek (&segment, 2.0, |
|
583 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
584 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_CUR, 0, &update); |
|
585 |
|
586 gst_segment_set_seek (&segment, 2.0, |
|
587 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
588 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 0, &update); |
|
589 |
|
590 /* set a real stop position, this must happen in bytes */ |
|
591 gst_segment_set_seek (&segment, 3.0, |
|
592 GST_FORMAT_BYTES, |
|
593 GST_SEEK_FLAG_NONE, |
|
594 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_SET, 100, &update); |
|
595 fail_unless (segment.format == GST_FORMAT_BYTES); |
|
596 |
|
597 fail_unless (segment.start == 0); |
|
598 |
|
599 fail_unless (segment.stop == 100); |
|
600 |
|
601 fail_unless (segment.rate == 3.0); |
|
602 |
|
603 /* no seek should happen, we just updated the stop position in forward |
|
604 * playback mode.*/ |
|
605 fail_unless (update == FALSE); |
|
606 |
|
607 |
|
608 /* 0 as relative end is fine too */ |
|
609 gst_segment_set_seek (&segment, 2.0, |
|
610 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
611 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_CUR, 0, &update); |
|
612 fail_unless (segment.stop == 100); |
|
613 |
|
614 |
|
615 gst_segment_set_seek (&segment, 2.0, |
|
616 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
617 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 0, &update); |
|
618 fail_unless (segment.stop == 100); |
|
619 |
|
620 |
|
621 /* -1 for end is fine too in all formats */ |
|
622 gst_segment_set_seek (&segment, 2.0, |
|
623 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
624 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_SET, -1, &update); |
|
625 fail_unless (segment.stop == -1); |
|
626 |
|
627 |
|
628 /* set some duration, stop -1 END seeks will now work with the |
|
629 * duration, if the formats match */ |
|
630 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200); |
|
631 fail_unless (segment.duration == 200); |
|
632 |
|
633 |
|
634 /* seek to end in any format with 0 should set the stop to the |
|
635 * duration */ |
|
636 gst_segment_set_seek (&segment, 2.0, |
|
637 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE, |
|
638 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 0, &update); |
|
639 fail_unless (segment.stop == 200); |
|
640 |
|
641 fail_unless (segment.duration == 200); |
|
642 |
|
643 |
|
644 /* subtract 100 from the end */ |
|
645 gst_segment_set_seek (&segment, 2.0, |
|
646 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE, |
|
647 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, -100, &update); |
|
648 fail_unless (segment.stop == 100); |
|
649 |
|
650 fail_unless (segment.duration == 200); |
|
651 |
|
652 |
|
653 /* add 100 to the duration, this should be clamped to the duration */ |
|
654 gst_segment_set_seek (&segment, 2.0, |
|
655 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE, |
|
656 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 100, &update); |
|
657 fail_unless (segment.stop == 200); |
|
658 |
|
659 fail_unless (segment.duration == 200); |
|
660 |
|
661 |
|
662 /* add 300 to the start, this should be clamped to the duration */ |
|
663 gst_segment_set_seek (&segment, 2.0, |
|
664 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE, |
|
665 GST_SEEK_TYPE_CUR, 300, GST_SEEK_TYPE_END, 0, &update); |
|
666 fail_unless (segment.start == 200); |
|
667 |
|
668 fail_unless (segment.stop == 200); |
|
669 |
|
670 fail_unless (segment.duration == 200); |
|
671 |
|
672 |
|
673 /* subtract 300 from the start, this should be clamped to 0 */ |
|
674 gst_segment_set_seek (&segment, 2.0, |
|
675 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE, |
|
676 GST_SEEK_TYPE_CUR, -300, GST_SEEK_TYPE_END, 0, &update); |
|
677 fail_unless (segment.start == 0); |
|
678 |
|
679 fail_unless (segment.stop == 200); |
|
680 |
|
681 fail_unless (segment.duration == 200); |
|
682 |
|
683 |
|
684 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
685 create_xml(0); |
|
686 } |
|
687 |
|
688 |
|
689 /* mess with the segment structure in the bytes format */ |
|
690 void segment_newsegment_open() |
|
691 { |
|
692 GstSegment segment; |
|
693 |
|
694 xmlfile = "segment_newsegment_open"; |
|
695 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_open"); |
|
696 |
|
697 gst_segment_init (&segment, GST_FORMAT_BYTES); |
|
698 |
|
699 /* time should also work for starting from 0 */ |
|
700 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); |
|
701 |
|
702 fail_unless (segment.rate == 1.0); |
|
703 |
|
704 fail_unless (segment.format == GST_FORMAT_BYTES); |
|
705 |
|
706 fail_unless (segment.flags == 0); |
|
707 |
|
708 fail_unless (segment.start == 0); |
|
709 |
|
710 fail_unless (segment.stop == -1); |
|
711 |
|
712 fail_unless (segment.time == 0); |
|
713 |
|
714 fail_unless (segment.accum == 0); |
|
715 |
|
716 fail_unless (segment.last_stop == 0); |
|
717 |
|
718 fail_unless (segment.duration == -1); |
|
719 |
|
720 |
|
721 /* we set stop but in the wrong format, stop stays open. */ |
|
722 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0); |
|
723 |
|
724 fail_unless (segment.start == 0); |
|
725 |
|
726 fail_unless (segment.stop == -1); |
|
727 |
|
728 fail_unless (segment.time == 0); |
|
729 |
|
730 fail_unless (segment.accum == 0); |
|
731 |
|
732 |
|
733 /* update, nothing changes */ |
|
734 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0); |
|
735 |
|
736 fail_unless (segment.start == 0); |
|
737 |
|
738 fail_unless (segment.stop == -1); |
|
739 |
|
740 fail_unless (segment.time == 0); |
|
741 |
|
742 fail_unless (segment.accum == 0); |
|
743 |
|
744 |
|
745 /* update */ |
|
746 gst_segment_set_newsegment (&segment, TRUE, 1.0, |
|
747 GST_FORMAT_BYTES, 100, -1, 100); |
|
748 |
|
749 fail_unless (segment.start == 100); |
|
750 |
|
751 fail_unless (segment.stop == -1); |
|
752 |
|
753 fail_unless (segment.time == 100); |
|
754 |
|
755 fail_unless (segment.accum == 100); |
|
756 |
|
757 |
|
758 /* last_stop 0, accum does not change */ |
|
759 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0); |
|
760 |
|
761 fail_unless (segment.start == 0); |
|
762 |
|
763 fail_unless (segment.stop == -1); |
|
764 |
|
765 fail_unless (segment.time == 0); |
|
766 |
|
767 fail_unless (segment.accum == 100); |
|
768 |
|
769 |
|
770 gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200); |
|
771 |
|
772 /* last_stop 200, accum changes */ |
|
773 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0); |
|
774 |
|
775 fail_unless (segment.start == 0); |
|
776 |
|
777 fail_unless (segment.stop == -1); |
|
778 |
|
779 fail_unless (segment.time == 0); |
|
780 |
|
781 fail_unless (segment.accum == 300); |
|
782 |
|
783 |
|
784 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
785 create_xml(0); |
|
786 |
|
787 } |
|
788 |
|
789 |
|
790 /* mess with the segment structure in the bytes format */ |
|
791 void segment_newsegment_closed() |
|
792 { |
|
793 GstSegment segment; |
|
794 |
|
795 xmlfile = "segment_newsegment_closed"; |
|
796 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_closed"); |
|
797 |
|
798 gst_segment_init (&segment, GST_FORMAT_BYTES); |
|
799 |
|
800 gst_segment_set_newsegment (&segment, FALSE, 1.0, |
|
801 GST_FORMAT_BYTES, 0, 200, 0); |
|
802 |
|
803 fail_unless (segment.rate == 1.0); |
|
804 |
|
805 fail_unless (segment.format == GST_FORMAT_BYTES); |
|
806 |
|
807 fail_unless (segment.flags == 0); |
|
808 |
|
809 fail_unless (segment.start == 0); |
|
810 |
|
811 fail_unless (segment.stop == 200); |
|
812 |
|
813 fail_unless (segment.time == 0); |
|
814 |
|
815 fail_unless (segment.accum == 0); |
|
816 |
|
817 fail_unless (segment.last_stop == 0); |
|
818 |
|
819 fail_unless (segment.duration == -1); |
|
820 |
|
821 |
|
822 /* do an update */ |
|
823 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0); |
|
824 |
|
825 fail_unless (segment.start == 0); |
|
826 |
|
827 fail_unless (segment.stop == 300); |
|
828 |
|
829 fail_unless (segment.time == 0); |
|
830 |
|
831 fail_unless (segment.accum == 0); |
|
832 |
|
833 |
|
834 /* and a new accumulated one */ |
|
835 gst_segment_set_newsegment (&segment, FALSE, 1.0, |
|
836 GST_FORMAT_BYTES, 100, 400, 300); |
|
837 |
|
838 fail_unless (segment.start == 100); |
|
839 |
|
840 fail_unless (segment.stop == 400); |
|
841 |
|
842 fail_unless (segment.time == 300); |
|
843 |
|
844 fail_unless (segment.accum == 300); |
|
845 |
|
846 |
|
847 /* and a new updated one */ |
|
848 gst_segment_set_newsegment (&segment, TRUE, 1.0, |
|
849 GST_FORMAT_BYTES, 100, 500, 300); |
|
850 |
|
851 fail_unless (segment.start == 100); |
|
852 |
|
853 fail_unless (segment.stop == 500); |
|
854 |
|
855 fail_unless (segment.time == 300); |
|
856 |
|
857 fail_unless (segment.accum == 300); |
|
858 |
|
859 |
|
860 /* and a new partially updated one */ |
|
861 gst_segment_set_newsegment (&segment, TRUE, 1.0, |
|
862 GST_FORMAT_BYTES, 200, 500, 400); |
|
863 |
|
864 fail_unless (segment.start == 200); |
|
865 |
|
866 fail_unless (segment.stop == 500); |
|
867 |
|
868 fail_unless (segment.time == 400); |
|
869 |
|
870 fail_unless (segment.accum == 400); |
|
871 |
|
872 |
|
873 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
874 create_xml(0); |
|
875 } |
|
876 |
|
877 |
|
878 |
|
879 /* mess with the segment structure in the time format */ |
|
880 void segment_newsegment_streamtime() |
|
881 { |
|
882 GstSegment segment; |
|
883 gint64 result; |
|
884 |
|
885 xmlfile = "segment_newsegment_streamtime"; |
|
886 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_streamtime"); |
|
887 |
|
888 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
889 |
|
890 /*************************** |
|
891 * Normal segment |
|
892 ***************************/ |
|
893 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0, |
|
894 GST_FORMAT_TIME, 0, 200, 0); |
|
895 |
|
896 fail_unless (segment.rate == 1.0); |
|
897 |
|
898 fail_unless (segment.applied_rate == 1.0); |
|
899 |
|
900 fail_unless (segment.format == GST_FORMAT_TIME); |
|
901 |
|
902 fail_unless (segment.flags == 0); |
|
903 |
|
904 fail_unless (segment.start == 0); |
|
905 |
|
906 fail_unless (segment.stop == 200); |
|
907 |
|
908 fail_unless (segment.time == 0); |
|
909 |
|
910 fail_unless (segment.accum == 0); |
|
911 |
|
912 fail_unless (segment.last_stop == 0); |
|
913 |
|
914 fail_unless (segment.duration == -1); |
|
915 |
|
916 |
|
917 /* invalid time gives invalid result */ |
|
918 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
919 fail_unless (result == -1); |
|
920 |
|
921 |
|
922 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
923 fail_unless (result == 0); |
|
924 |
|
925 |
|
926 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
927 fail_unless (result == 100); |
|
928 |
|
929 |
|
930 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
931 fail_unless (result == 200); |
|
932 |
|
933 |
|
934 /* outside of the segment */ |
|
935 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
936 fail_unless (result == -1); |
|
937 |
|
938 |
|
939 /********************* |
|
940 * time shifted by 500 |
|
941 *********************/ |
|
942 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0, |
|
943 GST_FORMAT_TIME, 0, 200, 500); |
|
944 |
|
945 fail_unless (segment.accum == 200); |
|
946 |
|
947 |
|
948 /* invalid time gives invalid result */ |
|
949 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
950 fail_unless (result == -1); |
|
951 |
|
952 |
|
953 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
954 fail_unless (result == 500); |
|
955 |
|
956 |
|
957 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
958 fail_unless (result == 600); |
|
959 |
|
960 |
|
961 /* outside of the segment */ |
|
962 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500); |
|
963 fail_unless (result == -1); |
|
964 |
|
965 |
|
966 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
967 fail_unless (result == -1); |
|
968 |
|
969 |
|
970 /********************* |
|
971 * time offset by 500 |
|
972 *********************/ |
|
973 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0, |
|
974 GST_FORMAT_TIME, 500, 700, 0); |
|
975 |
|
976 fail_unless (segment.accum == 400); |
|
977 |
|
978 |
|
979 /* invalid time gives invalid result */ |
|
980 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
981 fail_unless (result == -1); |
|
982 |
|
983 |
|
984 /* before segment is invalid */ |
|
985 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400); |
|
986 fail_unless (result == -1); |
|
987 |
|
988 |
|
989 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500); |
|
990 fail_unless (result == 0); |
|
991 |
|
992 |
|
993 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600); |
|
994 fail_unless (result == 100); |
|
995 |
|
996 |
|
997 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700); |
|
998 fail_unless (result == 200); |
|
999 |
|
1000 |
|
1001 /* outside of the segment */ |
|
1002 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800); |
|
1003 fail_unless (result == -1); |
|
1004 |
|
1005 |
|
1006 /************************************* |
|
1007 * time offset by 500, shifted by 200 |
|
1008 *************************************/ |
|
1009 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0, |
|
1010 GST_FORMAT_TIME, 500, 700, 200); |
|
1011 |
|
1012 fail_unless (segment.accum == 600); |
|
1013 |
|
1014 |
|
1015 /* invalid time gives invalid result */ |
|
1016 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1017 fail_unless (result == -1); |
|
1018 |
|
1019 |
|
1020 /* before segment is invalid */ |
|
1021 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400); |
|
1022 fail_unless (result == -1); |
|
1023 |
|
1024 |
|
1025 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500); |
|
1026 fail_unless (result == 200); |
|
1027 |
|
1028 |
|
1029 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600); |
|
1030 fail_unless (result == 300); |
|
1031 |
|
1032 |
|
1033 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700); |
|
1034 fail_unless (result == 400); |
|
1035 |
|
1036 |
|
1037 /* outside of the segment */ |
|
1038 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800); |
|
1039 fail_unless (result == -1); |
|
1040 |
|
1041 |
|
1042 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
1043 create_xml(0); |
|
1044 } |
|
1045 |
|
1046 |
|
1047 /* mess with the segment structure in the time format */ |
|
1048 void segment_newsegment_streamtime_rate() |
|
1049 { |
|
1050 GstSegment segment; |
|
1051 gint64 result; |
|
1052 |
|
1053 xmlfile = "segment_newsegment_streamtime_rate"; |
|
1054 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_streamtime_rate"); |
|
1055 |
|
1056 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
1057 |
|
1058 /*************************** |
|
1059 * Normal segment rate 2.0 |
|
1060 ***************************/ |
|
1061 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0, |
|
1062 GST_FORMAT_TIME, 0, 200, 0); |
|
1063 |
|
1064 fail_unless (segment.rate == 2.0); |
|
1065 |
|
1066 fail_unless (segment.applied_rate == 1.0); |
|
1067 |
|
1068 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1069 |
|
1070 fail_unless (segment.flags == 0); |
|
1071 |
|
1072 fail_unless (segment.start == 0); |
|
1073 |
|
1074 fail_unless (segment.stop == 200); |
|
1075 |
|
1076 fail_unless (segment.time == 0); |
|
1077 |
|
1078 fail_unless (segment.accum == 0); |
|
1079 |
|
1080 fail_unless (segment.last_stop == 0); |
|
1081 |
|
1082 fail_unless (segment.duration == -1); |
|
1083 |
|
1084 |
|
1085 /* invalid time gives invalid result */ |
|
1086 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1087 fail_unless (result == -1); |
|
1088 |
|
1089 |
|
1090 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1091 fail_unless (result == 0); |
|
1092 |
|
1093 |
|
1094 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1095 fail_unless (result == 100); |
|
1096 |
|
1097 |
|
1098 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1099 fail_unless (result == 150); |
|
1100 |
|
1101 |
|
1102 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1103 fail_unless (result == 200); |
|
1104 |
|
1105 |
|
1106 /* outside of the segment */ |
|
1107 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1108 fail_unless (result == -1); |
|
1109 |
|
1110 |
|
1111 /*************************************** |
|
1112 * Normal segment rate 2.0, offset |
|
1113 ***************************************/ |
|
1114 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0, |
|
1115 GST_FORMAT_TIME, 100, 300, 0); |
|
1116 |
|
1117 fail_unless (segment.accum == 100); |
|
1118 |
|
1119 |
|
1120 /* invalid time gives invalid result */ |
|
1121 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1122 fail_unless (result == -1); |
|
1123 |
|
1124 |
|
1125 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1126 fail_unless (result == 0); |
|
1127 |
|
1128 |
|
1129 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1130 fail_unless (result == 100); |
|
1131 |
|
1132 |
|
1133 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 250); |
|
1134 fail_unless (result == 150); |
|
1135 |
|
1136 |
|
1137 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1138 fail_unless (result == 200); |
|
1139 |
|
1140 |
|
1141 /* outside of the segment */ |
|
1142 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400); |
|
1143 fail_unless (result == -1); |
|
1144 |
|
1145 |
|
1146 /*************************************** |
|
1147 * Normal segment rate -1.0, offset |
|
1148 ***************************************/ |
|
1149 |
|
1150 /* buffers will arrive from 300 to 100 in a sink, stream time |
|
1151 * calculation is unaffected by the rate */ |
|
1152 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0, |
|
1153 GST_FORMAT_TIME, 100, 300, 0); |
|
1154 |
|
1155 fail_unless (segment.accum == 200); |
|
1156 |
|
1157 |
|
1158 /* invalid time gives invalid result */ |
|
1159 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1160 fail_unless (result == -1); |
|
1161 |
|
1162 |
|
1163 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1164 fail_unless (result == 0); |
|
1165 |
|
1166 |
|
1167 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1168 fail_unless (result == 100); |
|
1169 |
|
1170 |
|
1171 /*********************************************** |
|
1172 * Normal segment rate -1.0, offset, time = 200 |
|
1173 ***********************************************/ |
|
1174 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0, |
|
1175 GST_FORMAT_TIME, 100, 300, 200); |
|
1176 |
|
1177 /* invalid time gives invalid result */ |
|
1178 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1179 fail_unless (result == -1); |
|
1180 |
|
1181 |
|
1182 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1183 fail_unless (result == 200); |
|
1184 |
|
1185 |
|
1186 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1187 fail_unless (result == 300); |
|
1188 |
|
1189 |
|
1190 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1191 fail_unless (result == 400); |
|
1192 |
|
1193 |
|
1194 /* outside of the segment */ |
|
1195 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400); |
|
1196 fail_unless (result == -1); |
|
1197 |
|
1198 |
|
1199 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
1200 create_xml(0); |
|
1201 } |
|
1202 |
|
1203 |
|
1204 /* mess with the segment structure in the time format */ |
|
1205 void segment_newsegment_streamtime_applied_rate() |
|
1206 { |
|
1207 GstSegment segment; |
|
1208 gint64 result; |
|
1209 |
|
1210 xmlfile = "segment_newsegment_streamtime_applied_rate"; |
|
1211 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_streamtime_applied_rate"); |
|
1212 |
|
1213 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
1214 |
|
1215 /*********************************************************** |
|
1216 * Normal segment rate 1.0, applied rate -1.0 |
|
1217 * This means the timestamps represents a stream going backwards |
|
1218 * starting from @time to 0. |
|
1219 ************************************************************/ |
|
1220 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -1.0, |
|
1221 GST_FORMAT_TIME, 0, 200, 200); |
|
1222 |
|
1223 fail_unless (segment.rate == 1.0); |
|
1224 |
|
1225 fail_unless (segment.applied_rate == -1.0); |
|
1226 |
|
1227 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1228 |
|
1229 fail_unless (segment.flags == 0); |
|
1230 |
|
1231 fail_unless (segment.start == 0); |
|
1232 |
|
1233 fail_unless (segment.stop == 200); |
|
1234 |
|
1235 fail_unless (segment.time == 200); |
|
1236 |
|
1237 fail_unless (segment.accum == 0); |
|
1238 |
|
1239 fail_unless (segment.last_stop == 0); |
|
1240 |
|
1241 fail_unless (segment.duration == -1); |
|
1242 |
|
1243 |
|
1244 /* invalid time gives invalid result */ |
|
1245 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1246 fail_unless (result == -1); |
|
1247 |
|
1248 |
|
1249 /* we count backwards from 200 */ |
|
1250 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1251 fail_unless (result == 200); |
|
1252 |
|
1253 |
|
1254 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1255 fail_unless (result == 100); |
|
1256 |
|
1257 |
|
1258 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1259 fail_unless (result == 50); |
|
1260 |
|
1261 |
|
1262 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1263 fail_unless (result == 0); |
|
1264 |
|
1265 |
|
1266 /* outside of the segment */ |
|
1267 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1268 fail_unless (result == -1); |
|
1269 |
|
1270 |
|
1271 /*********************************************************** |
|
1272 * Normal segment rate 1.0, applied rate 2.0 |
|
1273 * This means the timestamps represents a stream at twice the |
|
1274 * normal rate |
|
1275 ************************************************************/ |
|
1276 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0, |
|
1277 GST_FORMAT_TIME, 0, 200, 0); |
|
1278 |
|
1279 fail_unless (segment.rate == 1.0); |
|
1280 |
|
1281 fail_unless (segment.applied_rate == 2.0); |
|
1282 |
|
1283 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1284 |
|
1285 fail_unless (segment.flags == 0); |
|
1286 |
|
1287 fail_unless (segment.start == 0); |
|
1288 |
|
1289 fail_unless (segment.stop == 200); |
|
1290 |
|
1291 fail_unless (segment.time == 0); |
|
1292 |
|
1293 fail_unless (segment.accum == 200); |
|
1294 |
|
1295 fail_unless (segment.last_stop == 0); |
|
1296 |
|
1297 fail_unless (segment.duration == -1); |
|
1298 |
|
1299 |
|
1300 /* invalid time gives invalid result */ |
|
1301 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1302 fail_unless (result == -1); |
|
1303 |
|
1304 |
|
1305 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1306 fail_unless (result == 0); |
|
1307 |
|
1308 |
|
1309 /* the stream prepresents a stream going twice as fast, the position |
|
1310 * in the segment is therefore scaled by the applied rate */ |
|
1311 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1312 fail_unless (result == 200); |
|
1313 |
|
1314 |
|
1315 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1316 fail_unless (result == 300); |
|
1317 |
|
1318 |
|
1319 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1320 fail_unless (result == 400); |
|
1321 |
|
1322 |
|
1323 /* outside of the segment */ |
|
1324 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1325 fail_unless (result == -1); |
|
1326 |
|
1327 |
|
1328 /*********************************************************** |
|
1329 * Normal segment rate 1.0, applied rate -2.0 |
|
1330 * This means the timestamps represents a stream at twice the |
|
1331 * reverse rate |
|
1332 ************************************************************/ |
|
1333 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0, |
|
1334 GST_FORMAT_TIME, 0, 200, 400); |
|
1335 |
|
1336 fail_unless (segment.rate == 1.0); |
|
1337 |
|
1338 fail_unless (segment.applied_rate == -2.0); |
|
1339 |
|
1340 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1341 |
|
1342 fail_unless (segment.flags == 0); |
|
1343 |
|
1344 fail_unless (segment.start == 0); |
|
1345 |
|
1346 fail_unless (segment.stop == 200); |
|
1347 |
|
1348 fail_unless (segment.time == 400); |
|
1349 |
|
1350 /* previous segment lasted 200, rate of 2.0 was already applied */ |
|
1351 fail_unless (segment.accum == 400); |
|
1352 |
|
1353 fail_unless (segment.last_stop == 0); |
|
1354 |
|
1355 fail_unless (segment.duration == -1); |
|
1356 |
|
1357 |
|
1358 /* invalid time gives invalid result */ |
|
1359 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1360 fail_unless (result == -1); |
|
1361 |
|
1362 |
|
1363 /* we count backwards from 400 */ |
|
1364 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1365 fail_unless (result == 400); |
|
1366 |
|
1367 |
|
1368 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1369 fail_unless (result == 200); |
|
1370 |
|
1371 |
|
1372 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1373 fail_unless (result == 100); |
|
1374 |
|
1375 |
|
1376 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1377 fail_unless (result == 0); |
|
1378 |
|
1379 |
|
1380 /* outside of the segment */ |
|
1381 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1382 fail_unless (result == -1); |
|
1383 |
|
1384 |
|
1385 /*********************************************************** |
|
1386 * Normal segment rate 1.0, applied rate -2.0 |
|
1387 * This means the timestamps represents a stream at twice the |
|
1388 * reverse rate, start time cannot compensate the complete |
|
1389 * duration of the segment so we stop at 0 |
|
1390 ************************************************************/ |
|
1391 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0, |
|
1392 GST_FORMAT_TIME, 0, 200, 200); |
|
1393 |
|
1394 fail_unless (segment.rate == 1.0); |
|
1395 |
|
1396 fail_unless (segment.applied_rate == -2.0); |
|
1397 |
|
1398 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1399 |
|
1400 fail_unless (segment.flags == 0); |
|
1401 |
|
1402 fail_unless (segment.start == 0); |
|
1403 |
|
1404 fail_unless (segment.stop == 200); |
|
1405 |
|
1406 fail_unless (segment.time == 200); |
|
1407 |
|
1408 fail_unless (segment.accum == 600); |
|
1409 |
|
1410 fail_unless (segment.last_stop == 0); |
|
1411 |
|
1412 fail_unless (segment.duration == -1); |
|
1413 |
|
1414 |
|
1415 /* invalid time gives invalid result */ |
|
1416 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1417 fail_unless (result == -1); |
|
1418 |
|
1419 |
|
1420 /* we count backwards from 200 */ |
|
1421 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1422 fail_unless (result == 200); |
|
1423 |
|
1424 |
|
1425 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1426 fail_unless (result == 0); |
|
1427 |
|
1428 |
|
1429 /* clamp at 0 */ |
|
1430 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1431 fail_unless (result == 0); |
|
1432 |
|
1433 |
|
1434 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1435 fail_unless (result == 0); |
|
1436 |
|
1437 |
|
1438 /* outside of the segment */ |
|
1439 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1440 fail_unless (result == -1); |
|
1441 |
|
1442 |
|
1443 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
1444 create_xml(0); |
|
1445 } |
|
1446 |
|
1447 |
|
1448 /* mess with the segment structure in the time format */ |
|
1449 void segment_newsegment_streamtime_applied_rate_rate() |
|
1450 { |
|
1451 GstSegment segment; |
|
1452 gint64 result; |
|
1453 |
|
1454 xmlfile = "segment_newsegment_streamtime_applied_rate_rate"; |
|
1455 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_streamtime_applied_rate_rate"); |
|
1456 |
|
1457 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
1458 |
|
1459 /*********************************************************** |
|
1460 * Segment rate 2.0, applied rate 2.0 |
|
1461 * this means we have a double speed stream that we should |
|
1462 * speed up by a factor of 2.0 some more. the resulting |
|
1463 * stream will be played at four times the speed. |
|
1464 ************************************************************/ |
|
1465 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 2.0, |
|
1466 GST_FORMAT_TIME, 0, 200, 0); |
|
1467 |
|
1468 fail_unless (segment.rate == 2.0); |
|
1469 |
|
1470 fail_unless (segment.applied_rate == 2.0); |
|
1471 |
|
1472 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1473 |
|
1474 fail_unless (segment.flags == 0); |
|
1475 |
|
1476 fail_unless (segment.start == 0); |
|
1477 |
|
1478 fail_unless (segment.stop == 200); |
|
1479 |
|
1480 fail_unless (segment.time == 0); |
|
1481 |
|
1482 fail_unless (segment.accum == 0); |
|
1483 |
|
1484 fail_unless (segment.last_stop == 0); |
|
1485 |
|
1486 fail_unless (segment.duration == -1); |
|
1487 |
|
1488 |
|
1489 /* invalid time gives invalid result */ |
|
1490 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1491 fail_unless (result == -1); |
|
1492 |
|
1493 |
|
1494 /* only applied rate affects our calculation of the stream time */ |
|
1495 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1496 fail_unless (result == 0); |
|
1497 |
|
1498 |
|
1499 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1500 fail_unless (result == 200); |
|
1501 |
|
1502 |
|
1503 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1504 fail_unless (result == 300); |
|
1505 |
|
1506 |
|
1507 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1508 fail_unless (result == 400); |
|
1509 |
|
1510 |
|
1511 /* outside of the segment */ |
|
1512 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1513 fail_unless (result == -1); |
|
1514 |
|
1515 |
|
1516 /*********************************************************** |
|
1517 * Segment rate 2.0, applied rate -1.0 |
|
1518 * this means we have a reverse stream that we should |
|
1519 * speed up by a factor of 2.0 |
|
1520 ************************************************************/ |
|
1521 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, -1.0, |
|
1522 GST_FORMAT_TIME, 0, 200, 200); |
|
1523 |
|
1524 fail_unless (segment.rate == 2.0); |
|
1525 |
|
1526 fail_unless (segment.applied_rate == -1.0); |
|
1527 |
|
1528 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1529 |
|
1530 fail_unless (segment.flags == 0); |
|
1531 |
|
1532 fail_unless (segment.start == 0); |
|
1533 |
|
1534 fail_unless (segment.stop == 200); |
|
1535 |
|
1536 fail_unless (segment.time == 200); |
|
1537 |
|
1538 /* previous segment lasted 100 */ |
|
1539 fail_unless (segment.accum == 100); |
|
1540 |
|
1541 fail_unless (segment.last_stop == 0); |
|
1542 |
|
1543 fail_unless (segment.duration == -1); |
|
1544 |
|
1545 |
|
1546 /* invalid time gives invalid result */ |
|
1547 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1548 fail_unless (result == -1); |
|
1549 |
|
1550 |
|
1551 /* only applied rate affects our calculation of the stream time */ |
|
1552 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1553 fail_unless (result == 200); |
|
1554 |
|
1555 |
|
1556 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1557 fail_unless (result == 100); |
|
1558 |
|
1559 |
|
1560 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1561 fail_unless (result == 50); |
|
1562 |
|
1563 |
|
1564 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1565 fail_unless (result == 0); |
|
1566 |
|
1567 |
|
1568 /* outside of the segment */ |
|
1569 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1570 fail_unless (result == -1); |
|
1571 |
|
1572 |
|
1573 /*********************************************************** |
|
1574 * Segment rate -1.0, applied rate -1.0 |
|
1575 * this means we have a reverse stream that we should |
|
1576 * reverse to get the normal stream again. |
|
1577 ************************************************************/ |
|
1578 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, -1.0, |
|
1579 GST_FORMAT_TIME, 0, 200, 200); |
|
1580 |
|
1581 fail_unless (segment.rate == -1.0); |
|
1582 |
|
1583 fail_unless (segment.applied_rate == -1.0); |
|
1584 |
|
1585 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1586 |
|
1587 fail_unless (segment.flags == 0); |
|
1588 |
|
1589 fail_unless (segment.start == 0); |
|
1590 |
|
1591 fail_unless (segment.stop == 200); |
|
1592 |
|
1593 fail_unless (segment.time == 200); |
|
1594 |
|
1595 /* accumulated 100 of previous segment to make 200 */ |
|
1596 fail_unless (segment.accum == 200); |
|
1597 |
|
1598 fail_unless (segment.last_stop == 0); |
|
1599 |
|
1600 fail_unless (segment.duration == -1); |
|
1601 |
|
1602 |
|
1603 /* invalid time gives invalid result */ |
|
1604 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1605 fail_unless (result == -1); |
|
1606 |
|
1607 |
|
1608 /* only applied rate affects our calculation of the stream time */ |
|
1609 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1610 fail_unless (result == 200); |
|
1611 |
|
1612 |
|
1613 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1614 fail_unless (result == 100); |
|
1615 |
|
1616 |
|
1617 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1618 fail_unless (result == 50); |
|
1619 |
|
1620 |
|
1621 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1622 fail_unless (result == 0); |
|
1623 |
|
1624 |
|
1625 /* outside of the segment */ |
|
1626 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1627 fail_unless (result == -1); |
|
1628 |
|
1629 |
|
1630 /*********************************************************** |
|
1631 * Segment rate -1.0, applied rate -1.0 |
|
1632 * this means we have a reverse stream that we should |
|
1633 * reverse to get the normal stream again. |
|
1634 ************************************************************/ |
|
1635 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 2.0, |
|
1636 GST_FORMAT_TIME, 0, 200, 0); |
|
1637 |
|
1638 fail_unless (segment.rate == -1.0); |
|
1639 |
|
1640 fail_unless (segment.applied_rate == 2.0); |
|
1641 |
|
1642 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1643 |
|
1644 fail_unless (segment.flags == 0); |
|
1645 |
|
1646 fail_unless (segment.start == 0); |
|
1647 |
|
1648 fail_unless (segment.stop == 200); |
|
1649 |
|
1650 fail_unless (segment.time == 0); |
|
1651 |
|
1652 fail_unless (segment.accum == 400); |
|
1653 |
|
1654 fail_unless (segment.last_stop == 0); |
|
1655 |
|
1656 fail_unless (segment.duration == -1); |
|
1657 |
|
1658 |
|
1659 /* invalid time gives invalid result */ |
|
1660 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1); |
|
1661 fail_unless (result == -1); |
|
1662 |
|
1663 |
|
1664 /* only applied rate affects our calculation of the stream time */ |
|
1665 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0); |
|
1666 fail_unless (result == 0); |
|
1667 |
|
1668 |
|
1669 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100); |
|
1670 fail_unless (result == 200); |
|
1671 |
|
1672 |
|
1673 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150); |
|
1674 fail_unless (result == 300); |
|
1675 |
|
1676 |
|
1677 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200); |
|
1678 fail_unless (result == 400); |
|
1679 |
|
1680 |
|
1681 /* outside of the segment */ |
|
1682 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300); |
|
1683 fail_unless (result == -1); |
|
1684 |
|
1685 |
|
1686 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
1687 create_xml(0); |
|
1688 } |
|
1689 |
|
1690 |
|
1691 /* mess with the segment structure in the time format */ |
|
1692 void segment_newsegment_runningtime() |
|
1693 { |
|
1694 GstSegment segment; |
|
1695 gint64 result; |
|
1696 |
|
1697 xmlfile = "segment_newsegment_runningtime"; |
|
1698 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_runningtime"); |
|
1699 |
|
1700 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
1701 |
|
1702 /*************************** |
|
1703 * Normal segment |
|
1704 ***************************/ |
|
1705 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0, |
|
1706 GST_FORMAT_TIME, 0, 200, 0); |
|
1707 |
|
1708 fail_unless (segment.rate == 1.0); |
|
1709 |
|
1710 fail_unless (segment.applied_rate == 1.0); |
|
1711 |
|
1712 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1713 |
|
1714 fail_unless (segment.flags == 0); |
|
1715 |
|
1716 fail_unless (segment.start == 0); |
|
1717 |
|
1718 fail_unless (segment.stop == 200); |
|
1719 |
|
1720 fail_unless (segment.time == 0); |
|
1721 |
|
1722 fail_unless (segment.accum == 0); |
|
1723 |
|
1724 fail_unless (segment.last_stop == 0); |
|
1725 |
|
1726 fail_unless (segment.duration == -1); |
|
1727 |
|
1728 |
|
1729 /* invalid time gives invalid result */ |
|
1730 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
1731 fail_unless (result == -1); |
|
1732 |
|
1733 |
|
1734 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0); |
|
1735 fail_unless (result == 0); |
|
1736 |
|
1737 |
|
1738 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100); |
|
1739 fail_unless (result == 100); |
|
1740 |
|
1741 |
|
1742 /* at edge is exactly the segment duration */ |
|
1743 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200); |
|
1744 fail_unless (result == 200); |
|
1745 |
|
1746 |
|
1747 /* outside of the segment */ |
|
1748 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 300); |
|
1749 fail_unless (result == -1); |
|
1750 |
|
1751 |
|
1752 /*********************************************************** |
|
1753 * time shifted by 500, check if accumulation worked. |
|
1754 * Rate convert to twice the speed which means scaling down |
|
1755 * all positions by 2.0 in this segment. |
|
1756 * Then time argument is not used at all here. |
|
1757 ***********************************************************/ |
|
1758 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0, |
|
1759 GST_FORMAT_TIME, 0, 200, 500); |
|
1760 |
|
1761 /* normal speed gives elapsed of 200 */ |
|
1762 fail_unless (segment.accum == 200); |
|
1763 |
|
1764 |
|
1765 /* invalid time gives invalid result */ |
|
1766 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
1767 fail_unless (result == -1); |
|
1768 |
|
1769 |
|
1770 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0); |
|
1771 fail_unless (result == 200); |
|
1772 |
|
1773 |
|
1774 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100); |
|
1775 fail_unless (result == 250); |
|
1776 |
|
1777 |
|
1778 /* outside of the segment */ |
|
1779 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500); |
|
1780 fail_unless (result == -1); |
|
1781 |
|
1782 |
|
1783 /******************************************** |
|
1784 * time offset by 500 |
|
1785 * applied rate is not used for running time |
|
1786 ********************************************/ |
|
1787 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0, |
|
1788 GST_FORMAT_TIME, 500, 700, 0); |
|
1789 |
|
1790 /* previous segment played at double speed gives elapsed time of |
|
1791 * 100 added to previous accum of 200 gives 300. */ |
|
1792 fail_unless (segment.accum == 300); |
|
1793 |
|
1794 |
|
1795 /* invalid time gives invalid result */ |
|
1796 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
1797 fail_unless (result == -1); |
|
1798 |
|
1799 |
|
1800 /* before segment is invalid */ |
|
1801 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400); |
|
1802 fail_unless (result == -1); |
|
1803 |
|
1804 |
|
1805 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500); |
|
1806 fail_unless (result == 300); |
|
1807 |
|
1808 |
|
1809 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600); |
|
1810 fail_unless (result == 400); |
|
1811 |
|
1812 |
|
1813 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700); |
|
1814 fail_unless (result == 500); |
|
1815 |
|
1816 |
|
1817 /* outside of the segment */ |
|
1818 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800); |
|
1819 fail_unless (result == -1); |
|
1820 |
|
1821 |
|
1822 /********************************************************** |
|
1823 * time offset by 500, shifted by 200 |
|
1824 * Negative rate makes the running time go backwards |
|
1825 * relative to the segment stop position. again time |
|
1826 * is ignored. |
|
1827 **********************************************************/ |
|
1828 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0, |
|
1829 GST_FORMAT_TIME, 500, 700, 200); |
|
1830 |
|
1831 fail_unless (segment.accum == 500); |
|
1832 |
|
1833 |
|
1834 /* invalid time gives invalid result */ |
|
1835 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
1836 fail_unless (result == -1); |
|
1837 |
|
1838 |
|
1839 /* before segment is invalid */ |
|
1840 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400); |
|
1841 fail_unless (result == -1); |
|
1842 |
|
1843 |
|
1844 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500); |
|
1845 fail_unless (result == 700); |
|
1846 |
|
1847 |
|
1848 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600); |
|
1849 fail_unless (result == 600); |
|
1850 |
|
1851 |
|
1852 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700); |
|
1853 fail_unless (result == 500); |
|
1854 |
|
1855 |
|
1856 /* outside of the segment */ |
|
1857 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800); |
|
1858 fail_unless (result == -1); |
|
1859 |
|
1860 |
|
1861 /********************************************************** |
|
1862 * time offset by 500, shifted by 200 |
|
1863 * Negative rate makes the running time go backwards at |
|
1864 * twice speed relative to the segment stop position. again |
|
1865 * time is ignored. |
|
1866 **********************************************************/ |
|
1867 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -2.0, |
|
1868 GST_FORMAT_TIME, 500, 700, 200); |
|
1869 |
|
1870 fail_unless (segment.accum == 700); |
|
1871 |
|
1872 |
|
1873 /* invalid time gives invalid result */ |
|
1874 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
1875 fail_unless (result == -1); |
|
1876 |
|
1877 |
|
1878 /* before segment is invalid */ |
|
1879 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400); |
|
1880 fail_unless (result == -1); |
|
1881 |
|
1882 |
|
1883 /* total scaled segment time is 100, accum is 700, so we get 800 */ |
|
1884 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500); |
|
1885 fail_unless (result == 800); |
|
1886 |
|
1887 |
|
1888 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600); |
|
1889 fail_unless (result == 750); |
|
1890 |
|
1891 |
|
1892 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700); |
|
1893 fail_unless (result == 700); |
|
1894 |
|
1895 |
|
1896 /* outside of the segment */ |
|
1897 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800); |
|
1898 fail_unless (result == -1); |
|
1899 |
|
1900 |
|
1901 /* see if negative rate closed segment correctly */ |
|
1902 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -1.0, |
|
1903 GST_FORMAT_TIME, 500, 700, 200); |
|
1904 |
|
1905 /* previous segment lasted 100, and was at 700 so we should get 800 */ |
|
1906 fail_unless (segment.accum == 800); |
|
1907 |
|
1908 |
|
1909 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
1910 create_xml(0); |
|
1911 } |
|
1912 |
|
1913 |
|
1914 /* mess with the segment structure in the time format */ |
|
1915 void segment_newsegment_accum() |
|
1916 { |
|
1917 GstSegment segment; |
|
1918 gint64 result; |
|
1919 |
|
1920 xmlfile = "segment_newsegment_accum"; |
|
1921 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_accum"); |
|
1922 |
|
1923 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
1924 |
|
1925 /*************************** |
|
1926 * Normal reverse segment |
|
1927 ***************************/ |
|
1928 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0, |
|
1929 GST_FORMAT_TIME, 0, 200, 0); |
|
1930 |
|
1931 fail_unless (segment.rate == -1.0); |
|
1932 |
|
1933 fail_unless (segment.applied_rate == 1.0); |
|
1934 |
|
1935 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1936 |
|
1937 fail_unless (segment.flags == 0); |
|
1938 |
|
1939 fail_unless (segment.start == 0); |
|
1940 |
|
1941 fail_unless (segment.stop == 200); |
|
1942 |
|
1943 fail_unless (segment.time == 0); |
|
1944 |
|
1945 fail_unless (segment.accum == 0); |
|
1946 |
|
1947 fail_unless (segment.last_stop == 0); |
|
1948 |
|
1949 fail_unless (segment.duration == -1); |
|
1950 |
|
1951 |
|
1952 /* invalid time gives invalid result */ |
|
1953 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
1954 fail_unless (result == -1); |
|
1955 |
|
1956 |
|
1957 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200); |
|
1958 fail_unless (result == 0); |
|
1959 |
|
1960 |
|
1961 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150); |
|
1962 fail_unless (result == 50); |
|
1963 |
|
1964 |
|
1965 /* update segment, this accumulates 50 from the previous segment. */ |
|
1966 gst_segment_set_newsegment_full (&segment, TRUE, -2.0, 1.0, |
|
1967 GST_FORMAT_TIME, 0, 150, 0); |
|
1968 |
|
1969 fail_unless (segment.rate == -2.0); |
|
1970 |
|
1971 fail_unless (segment.applied_rate == 1.0); |
|
1972 |
|
1973 fail_unless (segment.format == GST_FORMAT_TIME); |
|
1974 |
|
1975 fail_unless (segment.flags == 0); |
|
1976 |
|
1977 fail_unless (segment.start == 0); |
|
1978 |
|
1979 fail_unless (segment.stop == 150); |
|
1980 |
|
1981 fail_unless (segment.time == 0); |
|
1982 |
|
1983 fail_unless (segment.accum == 50); |
|
1984 |
|
1985 fail_unless (segment.last_stop == 0); |
|
1986 |
|
1987 fail_unless (segment.duration == -1); |
|
1988 |
|
1989 |
|
1990 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150); |
|
1991 fail_unless (result == 50); |
|
1992 |
|
1993 |
|
1994 /* 50 accumulated + 50 / 2 */ |
|
1995 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100); |
|
1996 fail_unless (result == 75); |
|
1997 |
|
1998 |
|
1999 /* update segment, this does not accumulate anything. */ |
|
2000 gst_segment_set_newsegment_full (&segment, TRUE, 1.0, 1.0, |
|
2001 GST_FORMAT_TIME, 100, 200, 100); |
|
2002 |
|
2003 fail_unless (segment.rate == 1.0); |
|
2004 |
|
2005 fail_unless (segment.applied_rate == 1.0); |
|
2006 |
|
2007 fail_unless (segment.format == GST_FORMAT_TIME); |
|
2008 |
|
2009 fail_unless (segment.flags == 0); |
|
2010 |
|
2011 fail_unless (segment.start == 100); |
|
2012 |
|
2013 fail_unless (segment.stop == 200); |
|
2014 |
|
2015 fail_unless (segment.time == 100); |
|
2016 |
|
2017 fail_unless (segment.accum == 50); |
|
2018 |
|
2019 fail_unless (segment.last_stop == 100); |
|
2020 |
|
2021 fail_unless (segment.duration == -1); |
|
2022 |
|
2023 |
|
2024 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100); |
|
2025 fail_unless (result == 50); |
|
2026 |
|
2027 |
|
2028 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150); |
|
2029 fail_unless (result == 100); |
|
2030 |
|
2031 |
|
2032 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
2033 create_xml(0); |
|
2034 } |
|
2035 |
|
2036 |
|
2037 /* mess with the segment structure in the time format */ |
|
2038 void segment_newsegment_accum2() |
|
2039 { |
|
2040 GstSegment segment; |
|
2041 gint64 result; |
|
2042 |
|
2043 xmlfile = "segment_newsegment_accum2"; |
|
2044 std_log(LOG_FILENAME_LINE, "Test Started segment_newsegment_accum2"); |
|
2045 |
|
2046 gst_segment_init (&segment, GST_FORMAT_TIME); |
|
2047 |
|
2048 /*************************** |
|
2049 * Normal reverse segment |
|
2050 ***************************/ |
|
2051 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0, |
|
2052 GST_FORMAT_TIME, 0, 200, 0); |
|
2053 |
|
2054 fail_unless (segment.rate == -1.0); |
|
2055 |
|
2056 fail_unless (segment.applied_rate == 1.0); |
|
2057 |
|
2058 fail_unless (segment.format == GST_FORMAT_TIME); |
|
2059 |
|
2060 fail_unless (segment.flags == 0); |
|
2061 |
|
2062 fail_unless (segment.start == 0); |
|
2063 |
|
2064 fail_unless (segment.stop == 200); |
|
2065 |
|
2066 fail_unless (segment.time == 0); |
|
2067 |
|
2068 fail_unless (segment.accum == 0); |
|
2069 |
|
2070 fail_unless (segment.last_stop == 0); |
|
2071 |
|
2072 fail_unless (segment.duration == -1); |
|
2073 |
|
2074 |
|
2075 /* invalid time gives invalid result */ |
|
2076 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
2077 fail_unless (result == -1); |
|
2078 |
|
2079 |
|
2080 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200); |
|
2081 fail_unless (result == 0); |
|
2082 |
|
2083 |
|
2084 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150); |
|
2085 fail_unless (result == 50); |
|
2086 |
|
2087 |
|
2088 /* close segment, this accumulates nothing. */ |
|
2089 gst_segment_set_newsegment_full (&segment, TRUE, -1.0, 1.0, |
|
2090 GST_FORMAT_TIME, 150, 200, 0); |
|
2091 |
|
2092 fail_unless (segment.rate == -1.0); |
|
2093 |
|
2094 fail_unless (segment.applied_rate == 1.0); |
|
2095 |
|
2096 fail_unless (segment.format == GST_FORMAT_TIME); |
|
2097 |
|
2098 fail_unless (segment.flags == 0); |
|
2099 |
|
2100 fail_unless (segment.start == 150); |
|
2101 |
|
2102 fail_unless (segment.stop == 200); |
|
2103 |
|
2104 fail_unless (segment.time == 0); |
|
2105 |
|
2106 fail_unless (segment.accum == 0); |
|
2107 |
|
2108 fail_unless (segment.last_stop == 150); |
|
2109 |
|
2110 fail_unless (segment.duration == -1); |
|
2111 |
|
2112 |
|
2113 /* new segment, this accumulates 50. */ |
|
2114 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0, |
|
2115 GST_FORMAT_TIME, 150, 300, 150); |
|
2116 |
|
2117 fail_unless (segment.rate == 1.0); |
|
2118 |
|
2119 fail_unless (segment.applied_rate == 1.0); |
|
2120 |
|
2121 fail_unless (segment.format == GST_FORMAT_TIME); |
|
2122 |
|
2123 fail_unless (segment.flags == 0); |
|
2124 |
|
2125 fail_unless (segment.start == 150); |
|
2126 |
|
2127 fail_unless (segment.stop == 300); |
|
2128 |
|
2129 fail_unless (segment.time == 150); |
|
2130 |
|
2131 fail_unless (segment.accum == 50); |
|
2132 |
|
2133 fail_unless (segment.last_stop == 150); |
|
2134 |
|
2135 fail_unless (segment.duration == -1); |
|
2136 |
|
2137 |
|
2138 /* invalid time gives invalid result */ |
|
2139 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1); |
|
2140 fail_unless (result == -1); |
|
2141 |
|
2142 |
|
2143 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150); |
|
2144 fail_unless (result == 50); |
|
2145 |
|
2146 |
|
2147 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200); |
|
2148 fail_unless (result == 100); |
|
2149 |
|
2150 |
|
2151 std_log(LOG_FILENAME_LINE, "Test Successful"); |
|
2152 create_xml(0); |
|
2153 } |
|
2154 |
|
2155 |
|
2156 /*void main(int argc,char** argv) |
|
2157 { |
|
2158 gst_init(&argc,&argv); |
|
2159 segment_seek_reverse(); |
|
2160 segment_seek_rate(); |
|
2161 segment_newsegment_open(); |
|
2162 segment_newsegment_closed(); |
|
2163 segment_newsegment_streamtime(); |
|
2164 segment_newsegment_streamtime_rate(); |
|
2165 segment_newsegment_streamtime_applied_rate(); |
|
2166 segment_newsegment_streamtime_applied_rate_rate(); |
|
2167 segment_newsegment_runningtime(); |
|
2168 segment_newsegment_accum(); |
|
2169 segment_newsegment_accum2(); |
|
2170 }*/ |
|
2171 |
|
2172 |
|
2173 void (*fn[13]) (void) = { |
|
2174 segment_seek_reverse, |
|
2175 segment_seek_rate, |
|
2176 segment_newsegment_open, |
|
2177 segment_newsegment_closed, |
|
2178 segment_newsegment_streamtime, |
|
2179 segment_newsegment_streamtime_rate, |
|
2180 segment_newsegment_streamtime_applied_rate, |
|
2181 segment_newsegment_streamtime_applied_rate_rate, |
|
2182 segment_newsegment_runningtime, |
|
2183 segment_newsegment_accum, |
|
2184 segment_newsegment_accum2, |
|
2185 segment_seek_nosize, |
|
2186 segment_seek_size |
|
2187 }; |
|
2188 |
|
2189 char *args[] = { |
|
2190 "segment_seek_reverse", |
|
2191 "segment_seek_rate", |
|
2192 "segment_newsegment_open", |
|
2193 "segment_newsegment_closed", |
|
2194 "segment_newsegment_streamtime", |
|
2195 "segment_newsegment_streamtime_rate", |
|
2196 "segment_newsegment_streamtime_applied_rate", |
|
2197 "segment_newsegment_streamtime_applied_rate_rate", |
|
2198 "segment_newsegment_runningtime", |
|
2199 "segment_newsegment_accum", |
|
2200 "segment_newsegment_accum2", |
|
2201 "segment_seek_nosize", |
|
2202 "segment_seek_size" |
|
2203 }; |
|
2204 |
|
2205 GST_CHECK_MAIN (gst_segment); |