2 * Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com>
4 * gstsegment.c: Unit test for segments
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <gst/check/gstcheck.h>
24 /* mess with the segment structure in the bytes format */
25 GST_START_TEST (segment_seek_nosize)
32 gst_segment_init (&segment, GST_FORMAT_BYTES);
34 /* configure segment to start 100 */
35 gst_segment_set_seek (&segment, 1.0,
38 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
39 fail_unless (segment.start == 100);
40 fail_unless (segment.stop == -1);
42 /* configure segment to stop relative, should not do anything since
44 gst_segment_set_seek (&segment, 1.0,
47 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
48 fail_unless (segment.start == 100);
49 fail_unless (segment.stop == -1);
51 /* do some clipping on the open range */
52 /* completely outside */
53 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
54 fail_unless (res == FALSE);
56 /* touching lower bound, still outside of the segment */
57 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
58 fail_unless (res == FALSE);
60 /* partially inside */
61 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
62 fail_unless (res == TRUE);
63 fail_unless (cstart == 100);
64 fail_unless (cstop == 150);
66 /* inside, touching lower bound */
67 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
68 100, 150, &cstart, &cstop);
69 fail_unless (res == TRUE);
70 fail_unless (cstart == 100);
71 fail_unless (cstop == 150);
73 /* special case, 0 duration */
74 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
75 100, 100, &cstart, &cstop);
76 fail_unless (res == TRUE);
77 fail_unless (cstart == 100);
78 fail_unless (cstop == 100);
80 /* completely inside */
81 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
82 150, 200, &cstart, &cstop);
83 fail_unless (res == TRUE);
84 fail_unless (cstart == 150);
85 fail_unless (cstop == 200);
88 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
89 fail_unless (res == FALSE);
91 /* start outside, we don't know the stop */
92 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
93 fail_unless (res == TRUE);
94 fail_unless (cstart == 100);
95 fail_unless (cstop == -1);
97 /* start on lower bound */
98 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
99 fail_unless (res == TRUE);
100 fail_unless (cstart == 100);
101 fail_unless (cstop == -1);
104 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
105 fail_unless (res == TRUE);
106 fail_unless (cstart == 150);
107 fail_unless (cstop == -1);
109 /* add 100 to start, set stop to 300 */
110 gst_segment_set_seek (&segment, 1.0,
113 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
114 fail_unless (segment.start == 200);
115 fail_unless (segment.stop == 300);
117 /* add 100 to start (to 300), set stop to 200, this is not allowed.
118 * nothing should be updated in the segment. A g_warning is
120 ASSERT_CRITICAL (gst_segment_set_seek (&segment, 1.0,
123 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update));
124 fail_unless (segment.start == 200);
125 fail_unless (segment.stop == 300);
127 /* seek relative to end, should not do anything since size is
129 gst_segment_set_seek (&segment, 1.0,
132 GST_SEEK_TYPE_END, -300, GST_SEEK_TYPE_END, -100, &update);
133 fail_unless (segment.start == 200);
134 fail_unless (segment.stop == 300);
136 /* completely outside */
137 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
138 fail_unless (res == FALSE);
140 /* touching lower bound */
141 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 200, &cstart, &cstop);
142 fail_unless (res == FALSE);
144 /* partially inside */
145 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 250, &cstart, &cstop);
146 fail_unless (res == TRUE);
147 fail_unless (cstart == 200);
148 fail_unless (cstop == 250);
150 /* inside, touching lower bound */
151 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
152 200, 250, &cstart, &cstop);
153 fail_unless (res == TRUE);
154 fail_unless (cstart == 200);
155 fail_unless (cstop == 250);
157 /* completely inside */
158 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
159 250, 290, &cstart, &cstop);
160 fail_unless (res == TRUE);
161 fail_unless (cstart == 250);
162 fail_unless (cstop == 290);
164 /* partially inside */
165 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
166 250, 350, &cstart, &cstop);
167 fail_unless (res == TRUE);
168 fail_unless (cstart == 250);
169 fail_unless (cstop == 300);
172 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
173 fail_unless (res == FALSE);
176 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
177 fail_unless (res == TRUE);
178 fail_unless (cstart == 200);
179 fail_unless (cstop == 300);
181 /* start on lower bound */
182 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 200, -1, &cstart, &cstop);
183 fail_unless (res == TRUE);
184 fail_unless (cstart == 200);
185 fail_unless (cstop == 300);
188 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
189 fail_unless (res == TRUE);
190 fail_unless (cstart == 250);
191 fail_unless (cstop == 300);
193 /* start outside on boundary */
194 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 300, -1, &cstart, &cstop);
195 fail_unless (res == FALSE);
197 /* start completely outside */
198 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 350, -1, &cstart, &cstop);
199 fail_unless (res == FALSE);
204 /* mess with the segment structure in the bytes format */
205 GST_START_TEST (segment_seek_size)
209 gint64 cstart, cstop;
212 gst_segment_init (&segment, GST_FORMAT_BYTES);
213 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
215 /* configure segment to start 100 */
216 gst_segment_set_seek (&segment, 1.0,
219 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
220 fail_unless (segment.start == 100);
221 fail_unless (segment.stop == -1);
223 /* configure segment to stop relative, does not update stop
224 * since we did not set it before. */
225 gst_segment_set_seek (&segment, 1.0,
228 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
229 fail_unless (segment.start == 100);
230 fail_unless (segment.stop == -1);
232 /* do some clipping on the open range */
233 /* completely outside */
234 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
235 fail_unless (res == FALSE);
237 /* touching lower bound */
238 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
239 fail_unless (res == FALSE);
241 /* partially inside */
242 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
243 fail_unless (res == TRUE);
244 fail_unless (cstart == 100);
245 fail_unless (cstop == 150);
247 /* inside, touching lower bound */
248 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
249 100, 150, &cstart, &cstop);
250 fail_unless (res == TRUE);
251 fail_unless (cstart == 100);
252 fail_unless (cstop == 150);
254 /* completely inside */
255 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
256 150, 200, &cstart, &cstop);
257 fail_unless (res == TRUE);
258 fail_unless (cstart == 150);
259 fail_unless (cstop == 200);
261 /* partially inside, clip to size */
262 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
263 150, 300, &cstart, &cstop);
264 fail_unless (res == TRUE);
265 fail_unless (cstart == 150);
266 fail_unless (cstop == 200);
269 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
270 fail_unless (res == FALSE);
273 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
274 fail_unless (res == TRUE);
275 fail_unless (cstart == 100);
276 fail_unless (cstop == -1);
278 /* start on lower bound */
279 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
280 fail_unless (res == TRUE);
281 fail_unless (cstart == 100);
282 fail_unless (cstop == -1);
285 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
286 fail_unless (res == TRUE);
287 fail_unless (cstart == 150);
288 fail_unless (cstop == -1);
290 /* add 100 to start, set stop to 300, stop clips to 200 */
291 gst_segment_set_seek (&segment, 1.0,
294 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
295 fail_unless (segment.start == 200);
296 fail_unless (segment.stop == 200);
298 /* add 100 to start (to 300), set stop to 200, this clips start
300 gst_segment_set_seek (&segment, 1.0,
303 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update);
304 fail_unless (segment.start == 200);
305 fail_unless (segment.stop == 200);
307 /* seek relative to end */
308 gst_segment_set_seek (&segment, 1.0,
311 GST_SEEK_TYPE_END, -100, GST_SEEK_TYPE_END, -20, &update);
312 fail_unless (segment.start == 100);
313 fail_unless (segment.stop == 180);
315 /* completely outside */
316 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
317 fail_unless (res == FALSE);
319 /* touching lower bound */
320 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
321 fail_unless (res == FALSE);
323 /* partially inside */
324 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
325 fail_unless (res == TRUE);
326 fail_unless (cstart == 100);
327 fail_unless (cstop == 150);
329 /* inside, touching lower bound */
330 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
331 100, 150, &cstart, &cstop);
332 fail_unless (res == TRUE);
333 fail_unless (cstart == 100);
334 fail_unless (cstop == 150);
336 /* completely inside */
337 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
338 150, 170, &cstart, &cstop);
339 fail_unless (res == TRUE);
340 fail_unless (cstart == 150);
341 fail_unless (cstop == 170);
343 /* partially inside */
344 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
345 150, 250, &cstart, &cstop);
346 fail_unless (res == TRUE);
347 fail_unless (cstart == 150);
348 fail_unless (cstop == 180);
351 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
352 fail_unless (res == FALSE);
355 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
356 fail_unless (res == TRUE);
357 fail_unless (cstart == 100);
358 fail_unless (cstop == 180);
360 /* start on lower bound */
361 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
362 fail_unless (res == TRUE);
363 fail_unless (cstart == 100);
364 fail_unless (cstop == 180);
367 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
368 fail_unless (res == TRUE);
369 fail_unless (cstart == 150);
370 fail_unless (cstop == 180);
372 /* start outside on boundary */
373 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 180, -1, &cstart, &cstop);
374 fail_unless (res == FALSE);
376 /* start completely outside */
377 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
378 fail_unless (res == FALSE);
383 GST_START_TEST (segment_seek_reverse)
388 gst_segment_init (&segment, GST_FORMAT_BYTES);
389 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
391 /* configure segment to stop 100 */
392 gst_segment_set_seek (&segment, -1.0,
395 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 100, &update);
396 fail_unless (segment.start == 0);
397 fail_unless (segment.stop == 100);
398 fail_unless (segment.time == 0);
399 fail_unless (segment.last_stop == 100);
402 gst_segment_set_seek (&segment, -1.0,
405 GST_SEEK_TYPE_SET, 10, GST_SEEK_TYPE_CUR, -20, &update);
406 fail_unless (segment.start == 10);
407 fail_unless (segment.stop == 80);
408 fail_unless (segment.time == 10);
409 fail_unless (segment.last_stop == 80);
411 gst_segment_set_seek (&segment, -1.0,
414 GST_SEEK_TYPE_SET, 20, GST_SEEK_TYPE_NONE, 0, &update);
415 fail_unless (segment.start == 20);
416 fail_unless (segment.stop == 80);
417 fail_unless (segment.time == 20);
418 fail_unless (segment.last_stop == 80);
423 /* mess with the segment structure in the bytes format */
424 GST_START_TEST (segment_newsegment_open)
428 gst_segment_init (&segment, GST_FORMAT_BYTES);
430 /* time should also work for starting from 0 */
431 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
433 fail_unless (segment.rate == 1.0);
434 fail_unless (segment.format == GST_FORMAT_BYTES);
435 fail_unless (segment.flags == 0);
436 fail_unless (segment.start == 0);
437 fail_unless (segment.stop == -1);
438 fail_unless (segment.time == 0);
439 fail_unless (segment.accum == 0);
440 fail_unless (segment.last_stop == 0);
441 fail_unless (segment.duration == -1);
443 /* we set stop but in the wrong format, stop stays open. */
444 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0);
446 fail_unless (segment.start == 0);
447 fail_unless (segment.stop == -1);
448 fail_unless (segment.time == 0);
449 fail_unless (segment.accum == 0);
451 /* update, nothing changes */
452 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
454 fail_unless (segment.start == 0);
455 fail_unless (segment.stop == -1);
456 fail_unless (segment.time == 0);
457 fail_unless (segment.accum == 0);
460 gst_segment_set_newsegment (&segment, TRUE, 1.0,
461 GST_FORMAT_BYTES, 100, -1, 100);
463 fail_unless (segment.start == 100);
464 fail_unless (segment.stop == -1);
465 fail_unless (segment.time == 100);
466 fail_unless (segment.accum == 100);
468 /* last_stop 0, accum does not change */
469 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
471 fail_unless (segment.start == 0);
472 fail_unless (segment.stop == -1);
473 fail_unless (segment.time == 0);
474 fail_unless (segment.accum == 100);
476 gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
478 /* last_stop 200, accum changes */
479 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
481 fail_unless (segment.start == 0);
482 fail_unless (segment.stop == -1);
483 fail_unless (segment.time == 0);
484 fail_unless (segment.accum == 300);
491 /* mess with the segment structure in the bytes format */
492 GST_START_TEST (segment_newsegment_closed)
496 gst_segment_init (&segment, GST_FORMAT_BYTES);
498 gst_segment_set_newsegment (&segment, FALSE, 1.0,
499 GST_FORMAT_BYTES, 0, 200, 0);
501 fail_unless (segment.rate == 1.0);
502 fail_unless (segment.format == GST_FORMAT_BYTES);
503 fail_unless (segment.flags == 0);
504 fail_unless (segment.start == 0);
505 fail_unless (segment.stop == 200);
506 fail_unless (segment.time == 0);
507 fail_unless (segment.accum == 0);
508 fail_unless (segment.last_stop == 0);
509 fail_unless (segment.duration == -1);
512 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0);
514 fail_unless (segment.start == 0);
515 fail_unless (segment.stop == 300);
516 fail_unless (segment.time == 0);
517 fail_unless (segment.accum == 0);
519 /* and a new accumulated one */
520 gst_segment_set_newsegment (&segment, FALSE, 1.0,
521 GST_FORMAT_BYTES, 100, 400, 300);
523 fail_unless (segment.start == 100);
524 fail_unless (segment.stop == 400);
525 fail_unless (segment.time == 300);
526 fail_unless (segment.accum == 300);
528 /* and a new updated one */
529 gst_segment_set_newsegment (&segment, TRUE, 1.0,
530 GST_FORMAT_BYTES, 100, 500, 300);
532 fail_unless (segment.start == 100);
533 fail_unless (segment.stop == 500);
534 fail_unless (segment.time == 300);
535 fail_unless (segment.accum == 300);
537 /* and a new partially updated one */
538 gst_segment_set_newsegment (&segment, TRUE, 1.0,
539 GST_FORMAT_BYTES, 200, 500, 400);
541 fail_unless (segment.start == 200);
542 fail_unless (segment.stop == 500);
543 fail_unless (segment.time == 400);
544 fail_unless (segment.accum == 400);
549 /* mess with the segment structure in the time format */
550 GST_START_TEST (segment_newsegment_streamtime)
555 gst_segment_init (&segment, GST_FORMAT_TIME);
557 /***************************
559 ***************************/
560 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
561 GST_FORMAT_TIME, 0, 200, 0);
563 fail_unless (segment.rate == 1.0);
564 fail_unless (segment.applied_rate == 1.0);
565 fail_unless (segment.format == GST_FORMAT_TIME);
566 fail_unless (segment.flags == 0);
567 fail_unless (segment.start == 0);
568 fail_unless (segment.stop == 200);
569 fail_unless (segment.time == 0);
570 fail_unless (segment.accum == 0);
571 fail_unless (segment.last_stop == 0);
572 fail_unless (segment.duration == -1);
574 /* invalid time gives invalid result */
575 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
576 fail_unless (result == -1);
578 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
579 fail_unless (result == 0);
581 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
582 fail_unless (result == 100);
584 /* outside of the segment */
585 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
586 fail_unless (result == -1);
588 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
589 fail_unless (result == -1);
591 /*********************
592 * time shifted by 500
593 *********************/
594 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
595 GST_FORMAT_TIME, 0, 200, 500);
597 fail_unless (segment.accum == 200);
599 /* invalid time gives invalid result */
600 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
601 fail_unless (result == -1);
603 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
604 fail_unless (result == 500);
606 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
607 fail_unless (result == 600);
609 /* outside of the segment */
610 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
611 fail_unless (result == -1);
613 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
614 fail_unless (result == -1);
616 /*********************
618 *********************/
619 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
620 GST_FORMAT_TIME, 500, 700, 0);
622 fail_unless (segment.accum == 400);
624 /* invalid time gives invalid result */
625 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
626 fail_unless (result == -1);
628 /* before segment is invalid */
629 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
630 fail_unless (result == -1);
632 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
633 fail_unless (result == 0);
635 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600);
636 fail_unless (result == 100);
638 /* outside of the segment */
639 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700);
640 fail_unless (result == -1);
642 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800);
643 fail_unless (result == -1);
645 /*************************************
646 * time offset by 500, shifted by 200
647 *************************************/
648 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
649 GST_FORMAT_TIME, 500, 700, 200);
651 fail_unless (segment.accum == 600);
653 /* invalid time gives invalid result */
654 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
655 fail_unless (result == -1);
657 /* before segment is invalid */
658 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
659 fail_unless (result == -1);
661 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
662 fail_unless (result == 200);
664 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600);
665 fail_unless (result == 300);
667 /* outside of the segment */
668 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700);
669 fail_unless (result == -1);
671 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800);
672 fail_unless (result == -1);
677 /* mess with the segment structure in the time format */
678 GST_START_TEST (segment_newsegment_streamtime_rate)
683 gst_segment_init (&segment, GST_FORMAT_TIME);
685 /***************************
686 * Normal segment rate 2.0
687 ***************************/
688 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
689 GST_FORMAT_TIME, 0, 200, 0);
691 fail_unless (segment.rate == 2.0);
692 fail_unless (segment.applied_rate == 1.0);
693 fail_unless (segment.format == GST_FORMAT_TIME);
694 fail_unless (segment.flags == 0);
695 fail_unless (segment.start == 0);
696 fail_unless (segment.stop == 200);
697 fail_unless (segment.time == 0);
698 fail_unless (segment.accum == 0);
699 fail_unless (segment.last_stop == 0);
700 fail_unless (segment.duration == -1);
702 /* invalid time gives invalid result */
703 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
704 fail_unless (result == -1);
706 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
707 fail_unless (result == 0);
709 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
710 fail_unless (result == 100);
712 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
713 fail_unless (result == 150);
715 /* outside of the segment */
716 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
717 fail_unless (result == -1);
719 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
720 fail_unless (result == -1);
722 /***************************************
723 * Normal segment rate 2.0, offset
724 ***************************************/
725 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
726 GST_FORMAT_TIME, 100, 300, 0);
728 fail_unless (segment.accum == 100);
730 /* invalid time gives invalid result */
731 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
732 fail_unless (result == -1);
734 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
735 fail_unless (result == 0);
737 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
738 fail_unless (result == 100);
740 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 250);
741 fail_unless (result == 150);
743 /* outside of the segment */
744 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
745 fail_unless (result == -1);
747 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
748 fail_unless (result == -1);
750 /***************************************
751 * Normal segment rate -1.0, offset
752 ***************************************/
754 /* buffers will arrive from 300 to 100 in a sink, stream time
755 * calculation is unaffected by the rate */
756 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
757 GST_FORMAT_TIME, 100, 300, 0);
759 fail_unless (segment.accum == 200);
761 /* invalid time gives invalid result */
762 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
763 fail_unless (result == -1);
765 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
766 fail_unless (result == 0);
768 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
769 fail_unless (result == 100);
771 /***********************************************
772 * Normal segment rate -1.0, offset, time = 200
773 ***********************************************/
774 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
775 GST_FORMAT_TIME, 100, 300, 200);
777 /* invalid time gives invalid result */
778 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
779 fail_unless (result == -1);
781 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
782 fail_unless (result == 200);
784 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
785 fail_unless (result == 300);
787 /* outside of the segment */
788 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
789 fail_unless (result == -1);
791 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
792 fail_unless (result == -1);
797 /* mess with the segment structure in the time format */
798 GST_START_TEST (segment_newsegment_streamtime_applied_rate)
803 gst_segment_init (&segment, GST_FORMAT_TIME);
805 /***********************************************************
806 * Normal segment rate 1.0, applied rate -1.0
807 * This means the timestamps represents a stream going backwards
808 * starting from @time to 0.
809 ************************************************************/
810 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -1.0,
811 GST_FORMAT_TIME, 0, 200, 200);
813 fail_unless (segment.rate == 1.0);
814 fail_unless (segment.applied_rate == -1.0);
815 fail_unless (segment.format == GST_FORMAT_TIME);
816 fail_unless (segment.flags == 0);
817 fail_unless (segment.start == 0);
818 fail_unless (segment.stop == 200);
819 fail_unless (segment.time == 200);
820 fail_unless (segment.accum == 0);
821 fail_unless (segment.last_stop == 0);
822 fail_unless (segment.duration == -1);
824 /* invalid time gives invalid result */
825 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
826 fail_unless (result == -1);
828 /* we count backwards from 200 */
829 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
830 fail_unless (result == 200);
832 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
833 fail_unless (result == 100);
835 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
836 fail_unless (result == 50);
838 /* outside of the segment */
839 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
840 fail_unless (result == -1);
842 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
843 fail_unless (result == -1);
845 /***********************************************************
846 * Normal segment rate 1.0, applied rate 2.0
847 * This means the timestamps represents a stream at twice the
849 ************************************************************/
850 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
851 GST_FORMAT_TIME, 0, 200, 0);
853 fail_unless (segment.rate == 1.0);
854 fail_unless (segment.applied_rate == 2.0);
855 fail_unless (segment.format == GST_FORMAT_TIME);
856 fail_unless (segment.flags == 0);
857 fail_unless (segment.start == 0);
858 fail_unless (segment.stop == 200);
859 fail_unless (segment.time == 0);
860 fail_unless (segment.accum == 200);
861 fail_unless (segment.last_stop == 0);
862 fail_unless (segment.duration == -1);
864 /* invalid time gives invalid result */
865 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
866 fail_unless (result == -1);
868 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
869 fail_unless (result == 0);
871 /* the stream prepresents a stream going twice as fast, the position
872 * in the segment is therefore scaled by the applied rate */
873 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
874 fail_unless (result == 200);
876 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
877 fail_unless (result == 300);
879 /* outside of the segment */
880 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
881 fail_unless (result == -1);
883 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
884 fail_unless (result == -1);
886 /***********************************************************
887 * Normal segment rate 1.0, applied rate -2.0
888 * This means the timestamps represents a stream at twice the
890 ************************************************************/
891 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0,
892 GST_FORMAT_TIME, 0, 200, 400);
894 fail_unless (segment.rate == 1.0);
895 fail_unless (segment.applied_rate == -2.0);
896 fail_unless (segment.format == GST_FORMAT_TIME);
897 fail_unless (segment.flags == 0);
898 fail_unless (segment.start == 0);
899 fail_unless (segment.stop == 200);
900 fail_unless (segment.time == 400);
901 /* previous segment lasted 200, rate of 2.0 was already applied */
902 fail_unless (segment.accum == 400);
903 fail_unless (segment.last_stop == 0);
904 fail_unless (segment.duration == -1);
906 /* invalid time gives invalid result */
907 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
908 fail_unless (result == -1);
910 /* we count backwards from 400 */
911 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
912 fail_unless (result == 400);
914 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
915 fail_unless (result == 200);
917 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
918 fail_unless (result == 100);
920 /* outside of the segment */
921 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
922 fail_unless (result == -1);
924 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
925 fail_unless (result == -1);
927 /***********************************************************
928 * Normal segment rate 1.0, applied rate -2.0
929 * This means the timestamps represents a stream at twice the
930 * reverse rate, start time cannot compensate the complete
931 * duration of the segment so we stop at 0
932 ************************************************************/
933 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0,
934 GST_FORMAT_TIME, 0, 200, 200);
936 fail_unless (segment.rate == 1.0);
937 fail_unless (segment.applied_rate == -2.0);
938 fail_unless (segment.format == GST_FORMAT_TIME);
939 fail_unless (segment.flags == 0);
940 fail_unless (segment.start == 0);
941 fail_unless (segment.stop == 200);
942 fail_unless (segment.time == 200);
943 fail_unless (segment.accum == 600);
944 fail_unless (segment.last_stop == 0);
945 fail_unless (segment.duration == -1);
947 /* invalid time gives invalid result */
948 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
949 fail_unless (result == -1);
951 /* we count backwards from 200 */
952 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
953 fail_unless (result == 200);
955 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
956 fail_unless (result == 0);
959 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
960 fail_unless (result == 0);
962 /* outside of the segment */
963 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
964 fail_unless (result == -1);
966 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
967 fail_unless (result == -1);
972 /* mess with the segment structure in the time format */
973 GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate)
978 gst_segment_init (&segment, GST_FORMAT_TIME);
980 /***********************************************************
981 * Segment rate 2.0, applied rate 2.0
982 * this means we have a double speed stream that we should
983 * speed up by a factor of 2.0 some more. the resulting
984 * stream will be played at four times the speed.
985 ************************************************************/
986 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 2.0,
987 GST_FORMAT_TIME, 0, 200, 0);
989 fail_unless (segment.rate == 2.0);
990 fail_unless (segment.applied_rate == 2.0);
991 fail_unless (segment.format == GST_FORMAT_TIME);
992 fail_unless (segment.flags == 0);
993 fail_unless (segment.start == 0);
994 fail_unless (segment.stop == 200);
995 fail_unless (segment.time == 0);
996 fail_unless (segment.accum == 0);
997 fail_unless (segment.last_stop == 0);
998 fail_unless (segment.duration == -1);
1000 /* invalid time gives invalid result */
1001 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1002 fail_unless (result == -1);
1004 /* only applied rate affects our calculation of the stream time */
1005 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1006 fail_unless (result == 0);
1008 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1009 fail_unless (result == 200);
1011 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1012 fail_unless (result == 300);
1014 /* outside of the segment */
1015 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1016 fail_unless (result == -1);
1018 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1019 fail_unless (result == -1);
1021 /***********************************************************
1022 * Segment rate 2.0, applied rate -1.0
1023 * this means we have a reverse stream that we should
1024 * speed up by a factor of 2.0
1025 ************************************************************/
1026 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, -1.0,
1027 GST_FORMAT_TIME, 0, 200, 200);
1029 fail_unless (segment.rate == 2.0);
1030 fail_unless (segment.applied_rate == -1.0);
1031 fail_unless (segment.format == GST_FORMAT_TIME);
1032 fail_unless (segment.flags == 0);
1033 fail_unless (segment.start == 0);
1034 fail_unless (segment.stop == 200);
1035 fail_unless (segment.time == 200);
1036 /* previous segment lasted 100 */
1037 fail_unless (segment.accum == 100);
1038 fail_unless (segment.last_stop == 0);
1039 fail_unless (segment.duration == -1);
1041 /* invalid time gives invalid result */
1042 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1043 fail_unless (result == -1);
1045 /* only applied rate affects our calculation of the stream time */
1046 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1047 fail_unless (result == 200);
1049 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1050 fail_unless (result == 100);
1052 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1053 fail_unless (result == 50);
1055 /* outside of the segment */
1056 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1057 fail_unless (result == -1);
1059 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1060 fail_unless (result == -1);
1062 /***********************************************************
1063 * Segment rate -1.0, applied rate -1.0
1064 * this means we have a reverse stream that we should
1065 * reverse to get the normal stream again.
1066 ************************************************************/
1067 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, -1.0,
1068 GST_FORMAT_TIME, 0, 200, 200);
1070 fail_unless (segment.rate == -1.0);
1071 fail_unless (segment.applied_rate == -1.0);
1072 fail_unless (segment.format == GST_FORMAT_TIME);
1073 fail_unless (segment.flags == 0);
1074 fail_unless (segment.start == 0);
1075 fail_unless (segment.stop == 200);
1076 fail_unless (segment.time == 200);
1077 /* accumulated 100 of previous segment to make 200 */
1078 fail_unless (segment.accum == 200);
1079 fail_unless (segment.last_stop == 0);
1080 fail_unless (segment.duration == -1);
1082 /* invalid time gives invalid result */
1083 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1084 fail_unless (result == -1);
1086 /* only applied rate affects our calculation of the stream time */
1087 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1088 fail_unless (result == 200);
1090 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1091 fail_unless (result == 100);
1093 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1094 fail_unless (result == 50);
1096 /* outside of the segment */
1097 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1098 fail_unless (result == -1);
1100 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1101 fail_unless (result == -1);
1103 /***********************************************************
1104 * Segment rate -1.0, applied rate -1.0
1105 * this means we have a reverse stream that we should
1106 * reverse to get the normal stream again.
1107 ************************************************************/
1108 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 2.0,
1109 GST_FORMAT_TIME, 0, 200, 0);
1111 fail_unless (segment.rate == -1.0);
1112 fail_unless (segment.applied_rate == 2.0);
1113 fail_unless (segment.format == GST_FORMAT_TIME);
1114 fail_unless (segment.flags == 0);
1115 fail_unless (segment.start == 0);
1116 fail_unless (segment.stop == 200);
1117 fail_unless (segment.time == 0);
1118 fail_unless (segment.accum == 400);
1119 fail_unless (segment.last_stop == 0);
1120 fail_unless (segment.duration == -1);
1122 /* invalid time gives invalid result */
1123 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1124 fail_unless (result == -1);
1126 /* only applied rate affects our calculation of the stream time */
1127 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1128 fail_unless (result == 0);
1130 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1131 fail_unless (result == 200);
1133 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1134 fail_unless (result == 300);
1136 /* outside of the segment */
1137 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1138 fail_unless (result == -1);
1140 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1141 fail_unless (result == -1);
1146 /* mess with the segment structure in the time format */
1147 GST_START_TEST (segment_newsegment_runningtime)
1152 gst_segment_init (&segment, GST_FORMAT_TIME);
1154 /***************************
1156 ***************************/
1157 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
1158 GST_FORMAT_TIME, 0, 200, 0);
1160 fail_unless (segment.rate == 1.0);
1161 fail_unless (segment.applied_rate == 1.0);
1162 fail_unless (segment.format == GST_FORMAT_TIME);
1163 fail_unless (segment.flags == 0);
1164 fail_unless (segment.start == 0);
1165 fail_unless (segment.stop == 200);
1166 fail_unless (segment.time == 0);
1167 fail_unless (segment.accum == 0);
1168 fail_unless (segment.last_stop == 0);
1169 fail_unless (segment.duration == -1);
1171 /* invalid time gives invalid result */
1172 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1173 fail_unless (result == -1);
1175 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0);
1176 fail_unless (result == 0);
1178 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1179 fail_unless (result == 100);
1181 /* outside of the segment */
1182 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200);
1183 fail_unless (result == -1);
1185 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 300);
1186 fail_unless (result == -1);
1188 /***********************************************************
1189 * time shifted by 500, check if accumulation worked.
1190 * Rate convert to twice the speed which means scaling down
1191 * all positions by 2.0 in this segment.
1192 * Then time argument is not used at all here.
1193 ***********************************************************/
1194 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
1195 GST_FORMAT_TIME, 0, 200, 500);
1197 /* normal speed gives elapsed of 200 */
1198 fail_unless (segment.accum == 200);
1200 /* invalid time gives invalid result */
1201 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1202 fail_unless (result == -1);
1204 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0);
1205 fail_unless (result == 200);
1207 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1208 fail_unless (result == 250);
1210 /* outside of the segment */
1211 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1212 fail_unless (result == -1);
1214 /********************************************
1215 * time offset by 500
1216 * applied rate is not used for running time
1217 ********************************************/
1218 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
1219 GST_FORMAT_TIME, 500, 700, 0);
1221 /* previous segment played at double speed gives elapsed time of
1222 * 100 added to previous accum of 200 gives 300. */
1223 fail_unless (segment.accum == 300);
1225 /* invalid time gives invalid result */
1226 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1227 fail_unless (result == -1);
1229 /* before segment is invalid */
1230 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1231 fail_unless (result == -1);
1233 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1234 fail_unless (result == 300);
1236 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1237 fail_unless (result == 400);
1239 /* outside of the segment */
1240 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1241 fail_unless (result == -1);
1243 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1244 fail_unless (result == -1);
1246 /**********************************************************
1247 * time offset by 500, shifted by 200
1248 * Negative rate makes the running time go backwards
1249 * relative to the segment stop position. again time
1251 **********************************************************/
1252 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
1253 GST_FORMAT_TIME, 500, 700, 200);
1255 fail_unless (segment.accum == 500);
1257 /* invalid time gives invalid result */
1258 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1259 fail_unless (result == -1);
1261 /* before segment is invalid */
1262 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1263 fail_unless (result == -1);
1265 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1266 fail_unless (result == 700);
1268 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1269 fail_unless (result == 600);
1271 /* outside of the segment */
1272 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1273 fail_unless (result == -1);
1275 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1276 fail_unless (result == -1);
1278 /**********************************************************
1279 * time offset by 500, shifted by 200
1280 * Negative rate makes the running time go backwards at
1281 * twice speed relative to the segment stop position. again
1283 **********************************************************/
1284 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -2.0,
1285 GST_FORMAT_TIME, 500, 700, 200);
1287 fail_unless (segment.accum == 700);
1289 /* invalid time gives invalid result */
1290 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1291 fail_unless (result == -1);
1293 /* before segment is invalid */
1294 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1295 fail_unless (result == -1);
1297 /* total scaled segment time is 100, accum is 700, so we get 800 */
1298 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1299 fail_unless (result == 800);
1301 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1302 fail_unless (result == 750);
1304 /* outside of the segment */
1305 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1306 fail_unless (result == -1);
1308 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1309 fail_unless (result == -1);
1311 /* see if negative rate closed segment correctly */
1312 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -1.0,
1313 GST_FORMAT_TIME, 500, 700, 200);
1315 /* previous segment lasted 100, and was at 700 so we should get 800 */
1316 fail_unless (segment.accum == 800);
1322 gst_segment_suite (void)
1324 Suite *s = suite_create ("GstSegment");
1325 TCase *tc_chain = tcase_create ("segments");
1327 tcase_set_timeout (tc_chain, 20);
1329 suite_add_tcase (s, tc_chain);
1330 tcase_add_test (tc_chain, segment_seek_nosize);
1331 tcase_add_test (tc_chain, segment_seek_size);
1332 tcase_add_test (tc_chain, segment_seek_reverse);
1333 tcase_add_test (tc_chain, segment_newsegment_open);
1334 tcase_add_test (tc_chain, segment_newsegment_closed);
1335 tcase_add_test (tc_chain, segment_newsegment_streamtime);
1336 tcase_add_test (tc_chain, segment_newsegment_streamtime_rate);
1337 tcase_add_test (tc_chain, segment_newsegment_streamtime_applied_rate);
1338 tcase_add_test (tc_chain, segment_newsegment_streamtime_applied_rate_rate);
1339 tcase_add_test (tc_chain, segment_newsegment_runningtime);
1344 GST_CHECK_MAIN (gst_segment);