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);
41 fail_unless (update == TRUE);
43 /* configure segment to stop relative, should not do anything since
45 gst_segment_set_seek (&segment, 1.0,
48 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
49 fail_unless (segment.start == 100);
50 fail_unless (segment.stop == -1);
51 fail_unless (update == FALSE);
53 /* do some clipping on the open range */
54 /* completely outside */
55 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
56 fail_unless (res == FALSE);
58 /* touching lower bound, still outside of the segment */
59 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
60 fail_unless (res == FALSE);
62 /* partially inside */
63 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
64 fail_unless (res == TRUE);
65 fail_unless (cstart == 100);
66 fail_unless (cstop == 150);
68 /* inside, touching lower bound */
69 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
70 100, 150, &cstart, &cstop);
71 fail_unless (res == TRUE);
72 fail_unless (cstart == 100);
73 fail_unless (cstop == 150);
75 /* special case, 0 duration */
76 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
77 100, 100, &cstart, &cstop);
78 fail_unless (res == TRUE);
79 fail_unless (cstart == 100);
80 fail_unless (cstop == 100);
82 /* completely inside */
83 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
84 150, 200, &cstart, &cstop);
85 fail_unless (res == TRUE);
86 fail_unless (cstart == 150);
87 fail_unless (cstop == 200);
90 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
91 fail_unless (res == FALSE);
93 /* start outside, we don't know the stop */
94 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
95 fail_unless (res == TRUE);
96 fail_unless (cstart == 100);
97 fail_unless (cstop == -1);
99 /* start on lower bound */
100 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
101 fail_unless (res == TRUE);
102 fail_unless (cstart == 100);
103 fail_unless (cstop == -1);
106 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
107 fail_unless (res == TRUE);
108 fail_unless (cstart == 150);
109 fail_unless (cstop == -1);
111 /* add 100 to start, set stop to 300 */
112 gst_segment_set_seek (&segment, 1.0,
115 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
116 fail_unless (segment.start == 200);
117 fail_unless (segment.stop == 300);
118 fail_unless (update == TRUE);
121 /* add 100 to start (to 300), set stop to 200, this is not allowed.
122 * nothing should be updated in the segment. A g_warning is
124 ASSERT_CRITICAL (gst_segment_set_seek (&segment, 1.0,
127 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update));
128 fail_unless (segment.start == 200);
129 fail_unless (segment.stop == 300);
130 /* update didn't change */
131 fail_unless (update == FALSE);
134 /* seek relative to end, should not do anything since size is
136 gst_segment_set_seek (&segment, 1.0,
139 GST_SEEK_TYPE_END, -300, GST_SEEK_TYPE_END, -100, &update);
140 fail_unless (segment.start == 200);
141 fail_unless (segment.stop == 300);
142 fail_unless (update == FALSE);
144 /* completely outside */
145 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
146 fail_unless (res == FALSE);
148 /* touching lower bound */
149 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 200, &cstart, &cstop);
150 fail_unless (res == FALSE);
152 /* partially inside */
153 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 250, &cstart, &cstop);
154 fail_unless (res == TRUE);
155 fail_unless (cstart == 200);
156 fail_unless (cstop == 250);
158 /* inside, touching lower bound */
159 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
160 200, 250, &cstart, &cstop);
161 fail_unless (res == TRUE);
162 fail_unless (cstart == 200);
163 fail_unless (cstop == 250);
165 /* completely inside */
166 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
167 250, 290, &cstart, &cstop);
168 fail_unless (res == TRUE);
169 fail_unless (cstart == 250);
170 fail_unless (cstop == 290);
172 /* partially inside */
173 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
174 250, 350, &cstart, &cstop);
175 fail_unless (res == TRUE);
176 fail_unless (cstart == 250);
177 fail_unless (cstop == 300);
180 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
181 fail_unless (res == FALSE);
184 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
185 fail_unless (res == TRUE);
186 fail_unless (cstart == 200);
187 fail_unless (cstop == 300);
189 /* start on lower bound */
190 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 200, -1, &cstart, &cstop);
191 fail_unless (res == TRUE);
192 fail_unless (cstart == 200);
193 fail_unless (cstop == 300);
196 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
197 fail_unless (res == TRUE);
198 fail_unless (cstart == 250);
199 fail_unless (cstop == 300);
201 /* start outside on boundary */
202 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 300, -1, &cstart, &cstop);
203 fail_unless (res == FALSE);
205 /* start completely outside */
206 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 350, -1, &cstart, &cstop);
207 fail_unless (res == FALSE);
212 /* mess with the segment structure in the bytes format */
213 GST_START_TEST (segment_seek_size)
217 gint64 cstart, cstop;
220 gst_segment_init (&segment, GST_FORMAT_BYTES);
221 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
223 /* configure segment to start 100 */
224 gst_segment_set_seek (&segment, 1.0,
227 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
228 fail_unless (segment.start == 100);
229 fail_unless (segment.stop == -1);
230 fail_unless (update == TRUE);
232 /* configure segment to stop relative, does not update stop
233 * since we did not set it before. */
234 gst_segment_set_seek (&segment, 1.0,
237 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
238 fail_unless (segment.start == 100);
239 fail_unless (segment.stop == -1);
240 fail_unless (update == FALSE);
242 /* do some clipping on the open range */
243 /* completely outside */
244 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
245 fail_unless (res == FALSE);
247 /* touching lower bound */
248 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
249 fail_unless (res == FALSE);
251 /* partially inside */
252 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
253 fail_unless (res == TRUE);
254 fail_unless (cstart == 100);
255 fail_unless (cstop == 150);
257 /* inside, touching lower bound */
258 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
259 100, 150, &cstart, &cstop);
260 fail_unless (res == TRUE);
261 fail_unless (cstart == 100);
262 fail_unless (cstop == 150);
264 /* completely inside */
265 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
266 150, 200, &cstart, &cstop);
267 fail_unless (res == TRUE);
268 fail_unless (cstart == 150);
269 fail_unless (cstop == 200);
271 /* partially inside, clip to size */
272 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
273 150, 300, &cstart, &cstop);
274 fail_unless (res == TRUE);
275 fail_unless (cstart == 150);
276 fail_unless (cstop == 200);
279 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
280 fail_unless (res == FALSE);
283 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
284 fail_unless (res == TRUE);
285 fail_unless (cstart == 100);
286 fail_unless (cstop == -1);
288 /* start on lower bound */
289 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
290 fail_unless (res == TRUE);
291 fail_unless (cstart == 100);
292 fail_unless (cstop == -1);
295 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
296 fail_unless (res == TRUE);
297 fail_unless (cstart == 150);
298 fail_unless (cstop == -1);
300 /* add 100 to start, set stop to 300, stop clips to 200 */
301 gst_segment_set_seek (&segment, 1.0,
304 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
305 fail_unless (segment.start == 200);
306 fail_unless (segment.stop == 200);
308 /* add 100 to start (to 300), set stop to 200, this clips start
310 gst_segment_set_seek (&segment, 1.0,
313 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update);
314 fail_unless (segment.start == 200);
315 fail_unless (segment.stop == 200);
316 fail_unless (update == TRUE);
318 /* seek relative to end */
319 gst_segment_set_seek (&segment, 1.0,
322 GST_SEEK_TYPE_END, -100, GST_SEEK_TYPE_END, -20, &update);
323 fail_unless (segment.start == 100);
324 fail_unless (segment.stop == 180);
325 fail_unless (update == TRUE);
327 /* completely outside */
328 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
329 fail_unless (res == FALSE);
331 /* touching lower bound */
332 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
333 fail_unless (res == FALSE);
335 /* partially inside */
336 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
337 fail_unless (res == TRUE);
338 fail_unless (cstart == 100);
339 fail_unless (cstop == 150);
341 /* inside, touching lower bound */
342 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
343 100, 150, &cstart, &cstop);
344 fail_unless (res == TRUE);
345 fail_unless (cstart == 100);
346 fail_unless (cstop == 150);
348 /* completely inside */
349 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
350 150, 170, &cstart, &cstop);
351 fail_unless (res == TRUE);
352 fail_unless (cstart == 150);
353 fail_unless (cstop == 170);
355 /* partially inside */
356 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
357 150, 250, &cstart, &cstop);
358 fail_unless (res == TRUE);
359 fail_unless (cstart == 150);
360 fail_unless (cstop == 180);
363 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
364 fail_unless (res == FALSE);
367 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
368 fail_unless (res == TRUE);
369 fail_unless (cstart == 100);
370 fail_unless (cstop == 180);
372 /* start on lower bound */
373 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
374 fail_unless (res == TRUE);
375 fail_unless (cstart == 100);
376 fail_unless (cstop == 180);
379 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
380 fail_unless (res == TRUE);
381 fail_unless (cstart == 150);
382 fail_unless (cstop == 180);
384 /* start outside on boundary */
385 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 180, -1, &cstart, &cstop);
386 fail_unless (res == FALSE);
388 /* start completely outside */
389 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
390 fail_unless (res == FALSE);
395 GST_START_TEST (segment_seek_reverse)
400 gst_segment_init (&segment, GST_FORMAT_BYTES);
401 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
403 /* configure segment to stop 100 */
404 gst_segment_set_seek (&segment, -1.0,
407 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 100, &update);
408 fail_unless (segment.start == 0);
409 fail_unless (segment.stop == 100);
410 fail_unless (segment.time == 0);
411 fail_unless (segment.last_stop == 100);
412 fail_unless (update == TRUE);
415 gst_segment_set_seek (&segment, -1.0,
418 GST_SEEK_TYPE_SET, 10, GST_SEEK_TYPE_CUR, -20, &update);
419 fail_unless (segment.start == 10);
420 fail_unless (segment.stop == 80);
421 fail_unless (segment.time == 10);
422 fail_unless (segment.last_stop == 80);
423 fail_unless (update == TRUE);
425 gst_segment_set_seek (&segment, -1.0,
428 GST_SEEK_TYPE_SET, 20, GST_SEEK_TYPE_NONE, 0, &update);
429 fail_unless (segment.start == 20);
430 fail_unless (segment.stop == 80);
431 fail_unless (segment.time == 20);
432 fail_unless (segment.last_stop == 80);
433 fail_unless (update == TRUE);
438 /* mess with the segment structure in the bytes format */
439 GST_START_TEST (segment_newsegment_open)
443 gst_segment_init (&segment, GST_FORMAT_BYTES);
445 /* time should also work for starting from 0 */
446 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
448 fail_unless (segment.rate == 1.0);
449 fail_unless (segment.format == GST_FORMAT_BYTES);
450 fail_unless (segment.flags == 0);
451 fail_unless (segment.start == 0);
452 fail_unless (segment.stop == -1);
453 fail_unless (segment.time == 0);
454 fail_unless (segment.accum == 0);
455 fail_unless (segment.last_stop == 0);
456 fail_unless (segment.duration == -1);
458 /* we set stop but in the wrong format, stop stays open. */
459 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0);
461 fail_unless (segment.start == 0);
462 fail_unless (segment.stop == -1);
463 fail_unless (segment.time == 0);
464 fail_unless (segment.accum == 0);
466 /* update, nothing changes */
467 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
469 fail_unless (segment.start == 0);
470 fail_unless (segment.stop == -1);
471 fail_unless (segment.time == 0);
472 fail_unless (segment.accum == 0);
475 gst_segment_set_newsegment (&segment, TRUE, 1.0,
476 GST_FORMAT_BYTES, 100, -1, 100);
478 fail_unless (segment.start == 100);
479 fail_unless (segment.stop == -1);
480 fail_unless (segment.time == 100);
481 fail_unless (segment.accum == 100);
483 /* last_stop 0, accum does not change */
484 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
486 fail_unless (segment.start == 0);
487 fail_unless (segment.stop == -1);
488 fail_unless (segment.time == 0);
489 fail_unless (segment.accum == 100);
491 gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
493 /* last_stop 200, accum changes */
494 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
496 fail_unless (segment.start == 0);
497 fail_unless (segment.stop == -1);
498 fail_unless (segment.time == 0);
499 fail_unless (segment.accum == 300);
506 /* mess with the segment structure in the bytes format */
507 GST_START_TEST (segment_newsegment_closed)
511 gst_segment_init (&segment, GST_FORMAT_BYTES);
513 gst_segment_set_newsegment (&segment, FALSE, 1.0,
514 GST_FORMAT_BYTES, 0, 200, 0);
516 fail_unless (segment.rate == 1.0);
517 fail_unless (segment.format == GST_FORMAT_BYTES);
518 fail_unless (segment.flags == 0);
519 fail_unless (segment.start == 0);
520 fail_unless (segment.stop == 200);
521 fail_unless (segment.time == 0);
522 fail_unless (segment.accum == 0);
523 fail_unless (segment.last_stop == 0);
524 fail_unless (segment.duration == -1);
527 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, 300, 0);
529 fail_unless (segment.start == 0);
530 fail_unless (segment.stop == 300);
531 fail_unless (segment.time == 0);
532 fail_unless (segment.accum == 0);
534 /* and a new accumulated one */
535 gst_segment_set_newsegment (&segment, FALSE, 1.0,
536 GST_FORMAT_BYTES, 100, 400, 300);
538 fail_unless (segment.start == 100);
539 fail_unless (segment.stop == 400);
540 fail_unless (segment.time == 300);
541 fail_unless (segment.accum == 300);
543 /* and a new updated one */
544 gst_segment_set_newsegment (&segment, TRUE, 1.0,
545 GST_FORMAT_BYTES, 100, 500, 300);
547 fail_unless (segment.start == 100);
548 fail_unless (segment.stop == 500);
549 fail_unless (segment.time == 300);
550 fail_unless (segment.accum == 300);
552 /* and a new partially updated one */
553 gst_segment_set_newsegment (&segment, TRUE, 1.0,
554 GST_FORMAT_BYTES, 200, 500, 400);
556 fail_unless (segment.start == 200);
557 fail_unless (segment.stop == 500);
558 fail_unless (segment.time == 400);
559 fail_unless (segment.accum == 400);
564 /* mess with the segment structure in the time format */
565 GST_START_TEST (segment_newsegment_streamtime)
570 gst_segment_init (&segment, GST_FORMAT_TIME);
572 /***************************
574 ***************************/
575 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
576 GST_FORMAT_TIME, 0, 200, 0);
578 fail_unless (segment.rate == 1.0);
579 fail_unless (segment.applied_rate == 1.0);
580 fail_unless (segment.format == GST_FORMAT_TIME);
581 fail_unless (segment.flags == 0);
582 fail_unless (segment.start == 0);
583 fail_unless (segment.stop == 200);
584 fail_unless (segment.time == 0);
585 fail_unless (segment.accum == 0);
586 fail_unless (segment.last_stop == 0);
587 fail_unless (segment.duration == -1);
589 /* invalid time gives invalid result */
590 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
591 fail_unless (result == -1);
593 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
594 fail_unless (result == 0);
596 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
597 fail_unless (result == 100);
599 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
600 fail_unless (result == 200);
602 /* outside of the segment */
603 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
604 fail_unless (result == -1);
606 /*********************
607 * time shifted by 500
608 *********************/
609 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
610 GST_FORMAT_TIME, 0, 200, 500);
612 fail_unless (segment.accum == 200);
614 /* invalid time gives invalid result */
615 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
616 fail_unless (result == -1);
618 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
619 fail_unless (result == 500);
621 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
622 fail_unless (result == 600);
624 /* outside of the segment */
625 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
626 fail_unless (result == -1);
628 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
629 fail_unless (result == -1);
631 /*********************
633 *********************/
634 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
635 GST_FORMAT_TIME, 500, 700, 0);
637 fail_unless (segment.accum == 400);
639 /* invalid time gives invalid result */
640 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
641 fail_unless (result == -1);
643 /* before segment is invalid */
644 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
645 fail_unless (result == -1);
647 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
648 fail_unless (result == 0);
650 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600);
651 fail_unless (result == 100);
653 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700);
654 fail_unless (result == 200);
656 /* outside of the segment */
657 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800);
658 fail_unless (result == -1);
660 /*************************************
661 * time offset by 500, shifted by 200
662 *************************************/
663 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
664 GST_FORMAT_TIME, 500, 700, 200);
666 fail_unless (segment.accum == 600);
668 /* invalid time gives invalid result */
669 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
670 fail_unless (result == -1);
672 /* before segment is invalid */
673 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
674 fail_unless (result == -1);
676 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
677 fail_unless (result == 200);
679 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600);
680 fail_unless (result == 300);
682 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700);
683 fail_unless (result == 400);
685 /* outside of the segment */
686 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800);
687 fail_unless (result == -1);
692 /* mess with the segment structure in the time format */
693 GST_START_TEST (segment_newsegment_streamtime_rate)
698 gst_segment_init (&segment, GST_FORMAT_TIME);
700 /***************************
701 * Normal segment rate 2.0
702 ***************************/
703 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
704 GST_FORMAT_TIME, 0, 200, 0);
706 fail_unless (segment.rate == 2.0);
707 fail_unless (segment.applied_rate == 1.0);
708 fail_unless (segment.format == GST_FORMAT_TIME);
709 fail_unless (segment.flags == 0);
710 fail_unless (segment.start == 0);
711 fail_unless (segment.stop == 200);
712 fail_unless (segment.time == 0);
713 fail_unless (segment.accum == 0);
714 fail_unless (segment.last_stop == 0);
715 fail_unless (segment.duration == -1);
717 /* invalid time gives invalid result */
718 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
719 fail_unless (result == -1);
721 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
722 fail_unless (result == 0);
724 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
725 fail_unless (result == 100);
727 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
728 fail_unless (result == 150);
730 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
731 fail_unless (result == 200);
733 /* outside of the segment */
734 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
735 fail_unless (result == -1);
737 /***************************************
738 * Normal segment rate 2.0, offset
739 ***************************************/
740 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
741 GST_FORMAT_TIME, 100, 300, 0);
743 fail_unless (segment.accum == 100);
745 /* invalid time gives invalid result */
746 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
747 fail_unless (result == -1);
749 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
750 fail_unless (result == 0);
752 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
753 fail_unless (result == 100);
755 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 250);
756 fail_unless (result == 150);
758 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
759 fail_unless (result == 200);
761 /* outside of the segment */
762 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
763 fail_unless (result == -1);
765 /***************************************
766 * Normal segment rate -1.0, offset
767 ***************************************/
769 /* buffers will arrive from 300 to 100 in a sink, stream time
770 * calculation is unaffected by the rate */
771 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
772 GST_FORMAT_TIME, 100, 300, 0);
774 fail_unless (segment.accum == 200);
776 /* invalid time gives invalid result */
777 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
778 fail_unless (result == -1);
780 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
781 fail_unless (result == 0);
783 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
784 fail_unless (result == 100);
786 /***********************************************
787 * Normal segment rate -1.0, offset, time = 200
788 ***********************************************/
789 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
790 GST_FORMAT_TIME, 100, 300, 200);
792 /* invalid time gives invalid result */
793 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
794 fail_unless (result == -1);
796 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
797 fail_unless (result == 200);
799 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
800 fail_unless (result == 300);
802 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
803 fail_unless (result == 400);
805 /* outside of the segment */
806 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
807 fail_unless (result == -1);
812 /* mess with the segment structure in the time format */
813 GST_START_TEST (segment_newsegment_streamtime_applied_rate)
818 gst_segment_init (&segment, GST_FORMAT_TIME);
820 /***********************************************************
821 * Normal segment rate 1.0, applied rate -1.0
822 * This means the timestamps represents a stream going backwards
823 * starting from @time to 0.
824 ************************************************************/
825 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -1.0,
826 GST_FORMAT_TIME, 0, 200, 200);
828 fail_unless (segment.rate == 1.0);
829 fail_unless (segment.applied_rate == -1.0);
830 fail_unless (segment.format == GST_FORMAT_TIME);
831 fail_unless (segment.flags == 0);
832 fail_unless (segment.start == 0);
833 fail_unless (segment.stop == 200);
834 fail_unless (segment.time == 200);
835 fail_unless (segment.accum == 0);
836 fail_unless (segment.last_stop == 0);
837 fail_unless (segment.duration == -1);
839 /* invalid time gives invalid result */
840 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
841 fail_unless (result == -1);
843 /* we count backwards from 200 */
844 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
845 fail_unless (result == 200);
847 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
848 fail_unless (result == 100);
850 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
851 fail_unless (result == 50);
853 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
854 fail_unless (result == 0);
856 /* outside of the segment */
857 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
858 fail_unless (result == -1);
860 /***********************************************************
861 * Normal segment rate 1.0, applied rate 2.0
862 * This means the timestamps represents a stream at twice the
864 ************************************************************/
865 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
866 GST_FORMAT_TIME, 0, 200, 0);
868 fail_unless (segment.rate == 1.0);
869 fail_unless (segment.applied_rate == 2.0);
870 fail_unless (segment.format == GST_FORMAT_TIME);
871 fail_unless (segment.flags == 0);
872 fail_unless (segment.start == 0);
873 fail_unless (segment.stop == 200);
874 fail_unless (segment.time == 0);
875 fail_unless (segment.accum == 200);
876 fail_unless (segment.last_stop == 0);
877 fail_unless (segment.duration == -1);
879 /* invalid time gives invalid result */
880 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
881 fail_unless (result == -1);
883 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
884 fail_unless (result == 0);
886 /* the stream prepresents a stream going twice as fast, the position
887 * in the segment is therefore scaled by the applied rate */
888 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
889 fail_unless (result == 200);
891 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
892 fail_unless (result == 300);
894 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
895 fail_unless (result == 400);
897 /* outside of the segment */
898 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
899 fail_unless (result == -1);
901 /***********************************************************
902 * Normal segment rate 1.0, applied rate -2.0
903 * This means the timestamps represents a stream at twice the
905 ************************************************************/
906 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0,
907 GST_FORMAT_TIME, 0, 200, 400);
909 fail_unless (segment.rate == 1.0);
910 fail_unless (segment.applied_rate == -2.0);
911 fail_unless (segment.format == GST_FORMAT_TIME);
912 fail_unless (segment.flags == 0);
913 fail_unless (segment.start == 0);
914 fail_unless (segment.stop == 200);
915 fail_unless (segment.time == 400);
916 /* previous segment lasted 200, rate of 2.0 was already applied */
917 fail_unless (segment.accum == 400);
918 fail_unless (segment.last_stop == 0);
919 fail_unless (segment.duration == -1);
921 /* invalid time gives invalid result */
922 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
923 fail_unless (result == -1);
925 /* we count backwards from 400 */
926 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
927 fail_unless (result == 400);
929 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
930 fail_unless (result == 200);
932 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
933 fail_unless (result == 100);
935 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
936 fail_unless (result == 0);
938 /* outside of the segment */
939 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
940 fail_unless (result == -1);
942 /***********************************************************
943 * Normal segment rate 1.0, applied rate -2.0
944 * This means the timestamps represents a stream at twice the
945 * reverse rate, start time cannot compensate the complete
946 * duration of the segment so we stop at 0
947 ************************************************************/
948 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0,
949 GST_FORMAT_TIME, 0, 200, 200);
951 fail_unless (segment.rate == 1.0);
952 fail_unless (segment.applied_rate == -2.0);
953 fail_unless (segment.format == GST_FORMAT_TIME);
954 fail_unless (segment.flags == 0);
955 fail_unless (segment.start == 0);
956 fail_unless (segment.stop == 200);
957 fail_unless (segment.time == 200);
958 fail_unless (segment.accum == 600);
959 fail_unless (segment.last_stop == 0);
960 fail_unless (segment.duration == -1);
962 /* invalid time gives invalid result */
963 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
964 fail_unless (result == -1);
966 /* we count backwards from 200 */
967 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
968 fail_unless (result == 200);
970 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
971 fail_unless (result == 0);
974 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
975 fail_unless (result == 0);
977 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
978 fail_unless (result == 0);
980 /* outside of the segment */
981 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
982 fail_unless (result == -1);
987 /* mess with the segment structure in the time format */
988 GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate)
993 gst_segment_init (&segment, GST_FORMAT_TIME);
995 /***********************************************************
996 * Segment rate 2.0, applied rate 2.0
997 * this means we have a double speed stream that we should
998 * speed up by a factor of 2.0 some more. the resulting
999 * stream will be played at four times the speed.
1000 ************************************************************/
1001 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 2.0,
1002 GST_FORMAT_TIME, 0, 200, 0);
1004 fail_unless (segment.rate == 2.0);
1005 fail_unless (segment.applied_rate == 2.0);
1006 fail_unless (segment.format == GST_FORMAT_TIME);
1007 fail_unless (segment.flags == 0);
1008 fail_unless (segment.start == 0);
1009 fail_unless (segment.stop == 200);
1010 fail_unless (segment.time == 0);
1011 fail_unless (segment.accum == 0);
1012 fail_unless (segment.last_stop == 0);
1013 fail_unless (segment.duration == -1);
1015 /* invalid time gives invalid result */
1016 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1017 fail_unless (result == -1);
1019 /* only applied rate affects our calculation of the stream time */
1020 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1021 fail_unless (result == 0);
1023 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1024 fail_unless (result == 200);
1026 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1027 fail_unless (result == 300);
1029 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1030 fail_unless (result == 400);
1032 /* outside of the segment */
1033 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1034 fail_unless (result == -1);
1036 /***********************************************************
1037 * Segment rate 2.0, applied rate -1.0
1038 * this means we have a reverse stream that we should
1039 * speed up by a factor of 2.0
1040 ************************************************************/
1041 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, -1.0,
1042 GST_FORMAT_TIME, 0, 200, 200);
1044 fail_unless (segment.rate == 2.0);
1045 fail_unless (segment.applied_rate == -1.0);
1046 fail_unless (segment.format == GST_FORMAT_TIME);
1047 fail_unless (segment.flags == 0);
1048 fail_unless (segment.start == 0);
1049 fail_unless (segment.stop == 200);
1050 fail_unless (segment.time == 200);
1051 /* previous segment lasted 100 */
1052 fail_unless (segment.accum == 100);
1053 fail_unless (segment.last_stop == 0);
1054 fail_unless (segment.duration == -1);
1056 /* invalid time gives invalid result */
1057 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1058 fail_unless (result == -1);
1060 /* only applied rate affects our calculation of the stream time */
1061 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1062 fail_unless (result == 200);
1064 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1065 fail_unless (result == 100);
1067 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1068 fail_unless (result == 50);
1070 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1071 fail_unless (result == 0);
1073 /* outside of the segment */
1074 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1075 fail_unless (result == -1);
1077 /***********************************************************
1078 * Segment rate -1.0, applied rate -1.0
1079 * this means we have a reverse stream that we should
1080 * reverse to get the normal stream again.
1081 ************************************************************/
1082 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, -1.0,
1083 GST_FORMAT_TIME, 0, 200, 200);
1085 fail_unless (segment.rate == -1.0);
1086 fail_unless (segment.applied_rate == -1.0);
1087 fail_unless (segment.format == GST_FORMAT_TIME);
1088 fail_unless (segment.flags == 0);
1089 fail_unless (segment.start == 0);
1090 fail_unless (segment.stop == 200);
1091 fail_unless (segment.time == 200);
1092 /* accumulated 100 of previous segment to make 200 */
1093 fail_unless (segment.accum == 200);
1094 fail_unless (segment.last_stop == 0);
1095 fail_unless (segment.duration == -1);
1097 /* invalid time gives invalid result */
1098 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1099 fail_unless (result == -1);
1101 /* only applied rate affects our calculation of the stream time */
1102 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1103 fail_unless (result == 200);
1105 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1106 fail_unless (result == 100);
1108 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1109 fail_unless (result == 50);
1111 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1112 fail_unless (result == 0);
1114 /* outside of the segment */
1115 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1116 fail_unless (result == -1);
1118 /***********************************************************
1119 * Segment rate -1.0, applied rate -1.0
1120 * this means we have a reverse stream that we should
1121 * reverse to get the normal stream again.
1122 ************************************************************/
1123 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 2.0,
1124 GST_FORMAT_TIME, 0, 200, 0);
1126 fail_unless (segment.rate == -1.0);
1127 fail_unless (segment.applied_rate == 2.0);
1128 fail_unless (segment.format == GST_FORMAT_TIME);
1129 fail_unless (segment.flags == 0);
1130 fail_unless (segment.start == 0);
1131 fail_unless (segment.stop == 200);
1132 fail_unless (segment.time == 0);
1133 fail_unless (segment.accum == 400);
1134 fail_unless (segment.last_stop == 0);
1135 fail_unless (segment.duration == -1);
1137 /* invalid time gives invalid result */
1138 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1139 fail_unless (result == -1);
1141 /* only applied rate affects our calculation of the stream time */
1142 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1143 fail_unless (result == 0);
1145 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1146 fail_unless (result == 200);
1148 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1149 fail_unless (result == 300);
1151 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1152 fail_unless (result == 400);
1154 /* outside of the segment */
1155 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1156 fail_unless (result == -1);
1161 /* mess with the segment structure in the time format */
1162 GST_START_TEST (segment_newsegment_runningtime)
1167 gst_segment_init (&segment, GST_FORMAT_TIME);
1169 /***************************
1171 ***************************/
1172 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
1173 GST_FORMAT_TIME, 0, 200, 0);
1175 fail_unless (segment.rate == 1.0);
1176 fail_unless (segment.applied_rate == 1.0);
1177 fail_unless (segment.format == GST_FORMAT_TIME);
1178 fail_unless (segment.flags == 0);
1179 fail_unless (segment.start == 0);
1180 fail_unless (segment.stop == 200);
1181 fail_unless (segment.time == 0);
1182 fail_unless (segment.accum == 0);
1183 fail_unless (segment.last_stop == 0);
1184 fail_unless (segment.duration == -1);
1186 /* invalid time gives invalid result */
1187 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1188 fail_unless (result == -1);
1190 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0);
1191 fail_unless (result == 0);
1193 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1194 fail_unless (result == 100);
1196 /* at edge is exactly the segment duration */
1197 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200);
1198 fail_unless (result == 200);
1200 /* outside of the segment */
1201 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 300);
1202 fail_unless (result == -1);
1204 /***********************************************************
1205 * time shifted by 500, check if accumulation worked.
1206 * Rate convert to twice the speed which means scaling down
1207 * all positions by 2.0 in this segment.
1208 * Then time argument is not used at all here.
1209 ***********************************************************/
1210 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
1211 GST_FORMAT_TIME, 0, 200, 500);
1213 /* normal speed gives elapsed of 200 */
1214 fail_unless (segment.accum == 200);
1216 /* invalid time gives invalid result */
1217 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1218 fail_unless (result == -1);
1220 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0);
1221 fail_unless (result == 200);
1223 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1224 fail_unless (result == 250);
1226 /* outside of the segment */
1227 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1228 fail_unless (result == -1);
1230 /********************************************
1231 * time offset by 500
1232 * applied rate is not used for running time
1233 ********************************************/
1234 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
1235 GST_FORMAT_TIME, 500, 700, 0);
1237 /* previous segment played at double speed gives elapsed time of
1238 * 100 added to previous accum of 200 gives 300. */
1239 fail_unless (segment.accum == 300);
1241 /* invalid time gives invalid result */
1242 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1243 fail_unless (result == -1);
1245 /* before segment is invalid */
1246 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1247 fail_unless (result == -1);
1249 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1250 fail_unless (result == 300);
1252 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1253 fail_unless (result == 400);
1255 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1256 fail_unless (result == 500);
1258 /* outside of the segment */
1259 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1260 fail_unless (result == -1);
1262 /**********************************************************
1263 * time offset by 500, shifted by 200
1264 * Negative rate makes the running time go backwards
1265 * relative to the segment stop position. again time
1267 **********************************************************/
1268 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
1269 GST_FORMAT_TIME, 500, 700, 200);
1271 fail_unless (segment.accum == 500);
1273 /* invalid time gives invalid result */
1274 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1275 fail_unless (result == -1);
1277 /* before segment is invalid */
1278 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1279 fail_unless (result == -1);
1281 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1282 fail_unless (result == 700);
1284 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1285 fail_unless (result == 600);
1287 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1288 fail_unless (result == 500);
1290 /* outside of the segment */
1291 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1292 fail_unless (result == -1);
1294 /**********************************************************
1295 * time offset by 500, shifted by 200
1296 * Negative rate makes the running time go backwards at
1297 * twice speed relative to the segment stop position. again
1299 **********************************************************/
1300 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -2.0,
1301 GST_FORMAT_TIME, 500, 700, 200);
1303 fail_unless (segment.accum == 700);
1305 /* invalid time gives invalid result */
1306 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1307 fail_unless (result == -1);
1309 /* before segment is invalid */
1310 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1311 fail_unless (result == -1);
1313 /* total scaled segment time is 100, accum is 700, so we get 800 */
1314 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1315 fail_unless (result == 800);
1317 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1318 fail_unless (result == 750);
1320 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1321 fail_unless (result == 700);
1323 /* outside of the segment */
1324 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1325 fail_unless (result == -1);
1327 /* see if negative rate closed segment correctly */
1328 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -1.0,
1329 GST_FORMAT_TIME, 500, 700, 200);
1331 /* previous segment lasted 100, and was at 700 so we should get 800 */
1332 fail_unless (segment.accum == 800);
1338 gst_segment_suite (void)
1340 Suite *s = suite_create ("GstSegment");
1341 TCase *tc_chain = tcase_create ("segments");
1343 tcase_set_timeout (tc_chain, 20);
1345 suite_add_tcase (s, tc_chain);
1346 tcase_add_test (tc_chain, segment_seek_nosize);
1347 tcase_add_test (tc_chain, segment_seek_size);
1348 tcase_add_test (tc_chain, segment_seek_reverse);
1349 tcase_add_test (tc_chain, segment_newsegment_open);
1350 tcase_add_test (tc_chain, segment_newsegment_closed);
1351 tcase_add_test (tc_chain, segment_newsegment_streamtime);
1352 tcase_add_test (tc_chain, segment_newsegment_streamtime_rate);
1353 tcase_add_test (tc_chain, segment_newsegment_streamtime_applied_rate);
1354 tcase_add_test (tc_chain, segment_newsegment_streamtime_applied_rate_rate);
1355 tcase_add_test (tc_chain, segment_newsegment_runningtime);
1360 GST_CHECK_MAIN (gst_segment);