2 * Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com>
3 * 2009 Wim Taymans <wim.taymans@gmail.com>
5 * gstsegment.c: Unit test for segments
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
25 /* mess with the segment structure in the bytes format */
26 GST_START_TEST (segment_seek_nosize)
33 gst_segment_init (&segment, GST_FORMAT_BYTES);
35 /* configure segment to start 100 */
36 gst_segment_set_seek (&segment, 1.0,
39 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
40 fail_unless (segment.start == 100);
41 fail_unless (segment.stop == -1);
42 fail_unless (update == TRUE);
44 /* configure segment to stop relative, should not do anything since
46 gst_segment_set_seek (&segment, 1.0,
49 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
50 fail_unless (segment.start == 100);
51 fail_unless (segment.stop == -1);
52 fail_unless (update == FALSE);
54 /* do some clipping on the open range */
55 /* completely outside */
56 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
57 fail_unless (res == FALSE);
59 /* touching lower bound, still outside of the segment */
60 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
61 fail_unless (res == FALSE);
63 /* partially inside */
64 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
65 fail_unless (res == TRUE);
66 fail_unless (cstart == 100);
67 fail_unless (cstop == 150);
69 /* inside, touching lower bound */
70 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
71 100, 150, &cstart, &cstop);
72 fail_unless (res == TRUE);
73 fail_unless (cstart == 100);
74 fail_unless (cstop == 150);
76 /* special case, 0 duration and outside segment */
77 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 90, 90, &cstart, &cstop);
78 fail_unless (res == FALSE);
80 /* special case, 0 duration and touching lower bound, i.e. inside segment */
81 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
82 100, 100, &cstart, &cstop);
83 fail_unless (res == TRUE);
84 fail_unless (cstart == 100);
85 fail_unless (cstop == 100);
87 /* special case, 0 duration and inside the segment */
88 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
89 120, 120, &cstart, &cstop);
90 fail_unless (res == TRUE);
91 fail_unless (cstart == 120);
92 fail_unless (cstop == 120);
94 /* completely inside */
95 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
96 150, 200, &cstart, &cstop);
97 fail_unless (res == TRUE);
98 fail_unless (cstart == 150);
99 fail_unless (cstop == 200);
102 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
103 fail_unless (res == FALSE);
105 /* start outside, we don't know the stop */
106 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
107 fail_unless (res == TRUE);
108 fail_unless (cstart == 100);
109 fail_unless (cstop == -1);
111 /* start on lower bound */
112 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
113 fail_unless (res == TRUE);
114 fail_unless (cstart == 100);
115 fail_unless (cstop == -1);
118 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
119 fail_unless (res == TRUE);
120 fail_unless (cstart == 150);
121 fail_unless (cstop == -1);
123 /* add 100 to start, set stop to 300 */
124 gst_segment_set_seek (&segment, 1.0,
127 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
128 fail_unless (segment.start == 200);
129 fail_unless (segment.stop == 300);
130 fail_unless (update == TRUE);
133 /* add 100 to start (to 300), set stop to 200, this is not allowed.
134 * nothing should be updated in the segment. A g_warning is
136 ASSERT_CRITICAL (gst_segment_set_seek (&segment, 1.0,
139 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update));
140 fail_unless (segment.start == 200);
141 fail_unless (segment.stop == 300);
142 /* update didn't change */
143 fail_unless (update == FALSE);
146 /* seek relative to end, should not do anything since size is
148 gst_segment_set_seek (&segment, 1.0,
151 GST_SEEK_TYPE_END, -300, GST_SEEK_TYPE_END, -100, &update);
152 fail_unless (segment.start == 200);
153 fail_unless (segment.stop == 300);
154 fail_unless (update == FALSE);
156 /* completely outside */
157 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
158 fail_unless (res == FALSE);
160 /* touching lower bound */
161 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 200, &cstart, &cstop);
162 fail_unless (res == FALSE);
164 /* partially inside */
165 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 250, &cstart, &cstop);
166 fail_unless (res == TRUE);
167 fail_unless (cstart == 200);
168 fail_unless (cstop == 250);
170 /* inside, touching lower bound */
171 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
172 200, 250, &cstart, &cstop);
173 fail_unless (res == TRUE);
174 fail_unless (cstart == 200);
175 fail_unless (cstop == 250);
177 /* completely inside */
178 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
179 250, 290, &cstart, &cstop);
180 fail_unless (res == TRUE);
181 fail_unless (cstart == 250);
182 fail_unless (cstop == 290);
184 /* partially inside */
185 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
186 250, 350, &cstart, &cstop);
187 fail_unless (res == TRUE);
188 fail_unless (cstart == 250);
189 fail_unless (cstop == 300);
192 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
193 fail_unless (res == FALSE);
196 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
197 fail_unless (res == TRUE);
198 fail_unless (cstart == 200);
199 fail_unless (cstop == 300);
201 /* start on lower bound */
202 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 200, -1, &cstart, &cstop);
203 fail_unless (res == TRUE);
204 fail_unless (cstart == 200);
205 fail_unless (cstop == 300);
208 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
209 fail_unless (res == TRUE);
210 fail_unless (cstart == 250);
211 fail_unless (cstop == 300);
213 /* start outside on boundary */
214 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 300, -1, &cstart, &cstop);
215 fail_unless (res == FALSE);
217 /* start completely outside */
218 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 350, -1, &cstart, &cstop);
219 fail_unless (res == FALSE);
224 /* mess with the segment structure in the bytes format */
225 GST_START_TEST (segment_seek_size)
229 gint64 cstart, cstop;
232 gst_segment_init (&segment, GST_FORMAT_BYTES);
233 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
235 /* configure segment to start 100 */
236 gst_segment_set_seek (&segment, 1.0,
239 GST_SEEK_TYPE_SET, 100, GST_SEEK_TYPE_NONE, -1, &update);
240 fail_unless (segment.start == 100);
241 fail_unless (segment.stop == -1);
242 fail_unless (update == TRUE);
244 /* configure segment to stop relative, does not update stop
245 * since we did not set it before. */
246 gst_segment_set_seek (&segment, 1.0,
249 GST_SEEK_TYPE_NONE, 200, GST_SEEK_TYPE_CUR, -100, &update);
250 fail_unless (segment.start == 100);
251 fail_unless (segment.stop == -1);
252 fail_unless (update == FALSE);
254 /* do some clipping on the open range */
255 /* completely outside */
256 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
257 fail_unless (res == FALSE);
259 /* touching lower bound */
260 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
261 fail_unless (res == FALSE);
263 /* partially inside */
264 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
265 fail_unless (res == TRUE);
266 fail_unless (cstart == 100);
267 fail_unless (cstop == 150);
269 /* inside, touching lower bound */
270 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
271 100, 150, &cstart, &cstop);
272 fail_unless (res == TRUE);
273 fail_unless (cstart == 100);
274 fail_unless (cstop == 150);
276 /* completely inside */
277 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
278 150, 200, &cstart, &cstop);
279 fail_unless (res == TRUE);
280 fail_unless (cstart == 150);
281 fail_unless (cstop == 200);
283 /* partially inside, clip to size */
284 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
285 150, 300, &cstart, &cstop);
286 fail_unless (res == TRUE);
287 fail_unless (cstart == 150);
288 fail_unless (cstop == 200);
291 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
292 fail_unless (res == FALSE);
295 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
296 fail_unless (res == TRUE);
297 fail_unless (cstart == 100);
298 fail_unless (cstop == -1);
300 /* start on lower bound */
301 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
302 fail_unless (res == TRUE);
303 fail_unless (cstart == 100);
304 fail_unless (cstop == -1);
307 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
308 fail_unless (res == TRUE);
309 fail_unless (cstart == 150);
310 fail_unless (cstop == -1);
312 /* add 100 to start, set stop to 300, stop clips to 200 */
313 gst_segment_set_seek (&segment, 1.0,
316 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 300, &update);
317 fail_unless (segment.start == 200);
318 fail_unless (segment.stop == 200);
320 /* add 100 to start (to 300), set stop to 200, this clips start
322 gst_segment_set_seek (&segment, 1.0,
325 GST_SEEK_TYPE_CUR, 100, GST_SEEK_TYPE_SET, 200, &update);
326 fail_unless (segment.start == 200);
327 fail_unless (segment.stop == 200);
328 fail_unless (update == FALSE);
330 /* seek relative to end */
331 gst_segment_set_seek (&segment, 1.0,
334 GST_SEEK_TYPE_END, -100, GST_SEEK_TYPE_END, -20, &update);
335 fail_unless (segment.start == 100);
336 fail_unless (segment.stop == 180);
337 fail_unless (update == TRUE);
339 /* completely outside */
340 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 0, 50, &cstart, &cstop);
341 fail_unless (res == FALSE);
343 /* touching lower bound */
344 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 100, &cstart, &cstop);
345 fail_unless (res == FALSE);
347 /* partially inside */
348 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, 150, &cstart, &cstop);
349 fail_unless (res == TRUE);
350 fail_unless (cstart == 100);
351 fail_unless (cstop == 150);
353 /* inside, touching lower bound */
354 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
355 100, 150, &cstart, &cstop);
356 fail_unless (res == TRUE);
357 fail_unless (cstart == 100);
358 fail_unless (cstop == 150);
360 /* completely inside */
361 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
362 150, 170, &cstart, &cstop);
363 fail_unless (res == TRUE);
364 fail_unless (cstart == 150);
365 fail_unless (cstop == 170);
367 /* partially inside */
368 res = gst_segment_clip (&segment, GST_FORMAT_BYTES,
369 150, 250, &cstart, &cstop);
370 fail_unless (res == TRUE);
371 fail_unless (cstart == 150);
372 fail_unless (cstop == 180);
375 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, -1, 100, &cstart, &cstop);
376 fail_unless (res == FALSE);
379 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 50, -1, &cstart, &cstop);
380 fail_unless (res == TRUE);
381 fail_unless (cstart == 100);
382 fail_unless (cstop == 180);
384 /* start on lower bound */
385 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 100, -1, &cstart, &cstop);
386 fail_unless (res == TRUE);
387 fail_unless (cstart == 100);
388 fail_unless (cstop == 180);
391 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 150, -1, &cstart, &cstop);
392 fail_unless (res == TRUE);
393 fail_unless (cstart == 150);
394 fail_unless (cstop == 180);
396 /* start outside on boundary */
397 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 180, -1, &cstart, &cstop);
398 fail_unless (res == FALSE);
400 /* start completely outside */
401 res = gst_segment_clip (&segment, GST_FORMAT_BYTES, 250, -1, &cstart, &cstop);
402 fail_unless (res == FALSE);
407 GST_START_TEST (segment_seek_reverse)
412 gst_segment_init (&segment, GST_FORMAT_BYTES);
413 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
415 /* configure segment to stop 100 */
416 gst_segment_set_seek (&segment, -1.0,
419 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, 100, &update);
420 fail_unless (segment.start == 0);
421 fail_unless (segment.stop == 100);
422 fail_unless (segment.time == 0);
423 fail_unless (segment.last_stop == 100);
424 fail_unless (update == TRUE);
427 gst_segment_set_seek (&segment, -1.0,
430 GST_SEEK_TYPE_SET, 10, GST_SEEK_TYPE_CUR, -20, &update);
431 fail_unless (segment.start == 10);
432 fail_unless (segment.stop == 80);
433 fail_unless (segment.time == 10);
434 fail_unless (segment.last_stop == 80);
435 fail_unless (update == TRUE);
437 gst_segment_set_seek (&segment, -1.0,
440 GST_SEEK_TYPE_SET, 20, GST_SEEK_TYPE_NONE, 0, &update);
441 fail_unless (segment.start == 20);
442 fail_unless (segment.stop == 80);
443 fail_unless (segment.time == 20);
444 fail_unless (segment.last_stop == 80);
445 fail_unless (update == FALSE);
450 /* mess with the segment structure in the bytes format */
451 GST_START_TEST (segment_seek_rate)
456 gst_segment_init (&segment, GST_FORMAT_BYTES);
458 /* configure segment to rate 2.0, format does not matter when we don't specify
459 * a start or stop position. */
460 gst_segment_set_seek (&segment, 2.0,
461 GST_FORMAT_UNDEFINED,
463 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1, &update);
464 fail_unless (segment.format == GST_FORMAT_BYTES);
465 fail_unless (segment.start == 0);
466 fail_unless (segment.stop == -1);
467 fail_unless (segment.rate == 2.0);
468 fail_unless (update == FALSE);
470 /* 0 is the same in all formats and should not fail */
471 gst_segment_set_seek (&segment, 2.0,
472 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
473 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1, &update);
474 fail_unless (segment.format == GST_FORMAT_BYTES);
476 /* set to -1 means start from 0 */
477 gst_segment_set_seek (&segment, 2.0,
478 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
479 GST_SEEK_TYPE_SET, -1, GST_SEEK_TYPE_NONE, -1, &update);
480 fail_unless (segment.format == GST_FORMAT_BYTES);
481 fail_unless (segment.start == 0);
483 gst_segment_set_seek (&segment, 2.0,
484 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
485 GST_SEEK_TYPE_CUR, 0, GST_SEEK_TYPE_NONE, -1, &update);
487 gst_segment_set_seek (&segment, 2.0,
488 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
489 GST_SEEK_TYPE_END, 0, GST_SEEK_TYPE_NONE, -1, &update);
491 /* -1 for end is fine too in all formats */
492 gst_segment_set_seek (&segment, 2.0,
493 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
494 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_SET, -1, &update);
496 /* 0 as relative end is fine too */
497 gst_segment_set_seek (&segment, 2.0,
498 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
499 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_CUR, 0, &update);
501 gst_segment_set_seek (&segment, 2.0,
502 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
503 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 0, &update);
505 /* set a real stop position, this must happen in bytes */
506 gst_segment_set_seek (&segment, 3.0,
509 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_SET, 100, &update);
510 fail_unless (segment.format == GST_FORMAT_BYTES);
511 fail_unless (segment.start == 0);
512 fail_unless (segment.stop == 100);
513 fail_unless (segment.rate == 3.0);
514 /* no seek should happen, we just updated the stop position in forward
516 fail_unless (update == FALSE);
518 /* 0 as relative end is fine too */
519 gst_segment_set_seek (&segment, 2.0,
520 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
521 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_CUR, 0, &update);
522 fail_unless (segment.stop == 100);
524 gst_segment_set_seek (&segment, 2.0,
525 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
526 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 0, &update);
527 fail_unless (segment.stop == 100);
529 /* -1 for end is fine too in all formats */
530 gst_segment_set_seek (&segment, 2.0,
531 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
532 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_SET, -1, &update);
533 fail_unless (segment.stop == -1);
535 /* set some duration, stop -1 END seeks will now work with the
536 * duration, if the formats match */
537 gst_segment_set_duration (&segment, GST_FORMAT_BYTES, 200);
538 fail_unless (segment.duration == 200);
540 /* seek to end in any format with 0 should set the stop to the
542 gst_segment_set_seek (&segment, 2.0,
543 GST_FORMAT_TIME, GST_SEEK_FLAG_NONE,
544 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 0, &update);
545 fail_unless (segment.stop == 200);
546 fail_unless (segment.duration == 200);
548 /* subtract 100 from the end */
549 gst_segment_set_seek (&segment, 2.0,
550 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE,
551 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, -100, &update);
552 fail_unless (segment.stop == 100);
553 fail_unless (segment.duration == 200);
555 /* add 100 to the duration, this should be clamped to the duration */
556 gst_segment_set_seek (&segment, 2.0,
557 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE,
558 GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_END, 100, &update);
559 fail_unless (segment.stop == 200);
560 fail_unless (segment.duration == 200);
562 /* add 300 to the start, this should be clamped to the duration */
563 gst_segment_set_seek (&segment, 2.0,
564 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE,
565 GST_SEEK_TYPE_CUR, 300, GST_SEEK_TYPE_END, 0, &update);
566 fail_unless (segment.start == 200);
567 fail_unless (segment.stop == 200);
568 fail_unless (segment.duration == 200);
570 /* subtract 300 from the start, this should be clamped to 0 */
571 gst_segment_set_seek (&segment, 2.0,
572 GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE,
573 GST_SEEK_TYPE_CUR, -300, GST_SEEK_TYPE_END, 0, &update);
574 fail_unless (segment.start == 0);
575 fail_unless (segment.stop == 200);
576 fail_unless (segment.duration == 200);
581 /* mess with the segment structure in the bytes format */
582 GST_START_TEST (segment_newsegment_open)
586 gst_segment_init (&segment, GST_FORMAT_BYTES);
588 /* time should also work for starting from 0 */
589 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0);
591 fail_unless (segment.rate == 1.0);
592 fail_unless (segment.format == GST_FORMAT_BYTES);
593 fail_unless (segment.flags == 0);
594 fail_unless (segment.start == 0);
595 fail_unless (segment.stop == -1);
596 fail_unless (segment.time == 0);
597 fail_unless (segment.accum == 0);
598 fail_unless (segment.last_stop == 0);
599 fail_unless (segment.duration == -1);
601 /* we set stop but in the wrong format, stop stays open. */
602 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_TIME, 0, 200, 0);
604 fail_unless (segment.start == 0);
605 fail_unless (segment.stop == -1);
606 fail_unless (segment.time == 0);
607 fail_unless (segment.accum == 0);
608 fail_unless (segment.last_stop == 0);
610 /* update, nothing changes */
611 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
613 fail_unless (segment.start == 0);
614 fail_unless (segment.stop == -1);
615 fail_unless (segment.time == 0);
616 fail_unless (segment.accum == 0);
617 fail_unless (segment.last_stop == 0);
620 gst_segment_set_newsegment (&segment, TRUE, 1.0,
621 GST_FORMAT_BYTES, 100, -1, 100);
623 fail_unless (segment.start == 100);
624 fail_unless (segment.stop == -1);
625 fail_unless (segment.time == 100);
626 fail_unless (segment.accum == 100);
627 fail_unless (segment.last_stop == 100);
629 /* last_stop 0, accum does not change */
630 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
632 fail_unless (segment.start == 0);
633 fail_unless (segment.stop == -1);
634 fail_unless (segment.time == 0);
635 fail_unless (segment.accum == 100);
637 gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 200);
639 fail_unless (segment.last_stop == 200);
641 /* last_stop 200, accum changes */
642 gst_segment_set_newsegment (&segment, FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0);
644 fail_unless (segment.start == 0);
645 fail_unless (segment.stop == -1);
646 fail_unless (segment.time == 0);
647 fail_unless (segment.accum == 300);
648 fail_unless (segment.last_stop == 0);
654 /* mess with the segment structure in the bytes format */
655 GST_START_TEST (segment_newsegment_closed)
659 gst_segment_init (&segment, GST_FORMAT_BYTES);
661 gst_segment_set_newsegment (&segment, FALSE, 1.0,
662 GST_FORMAT_BYTES, 0, 200, 0);
664 fail_unless (segment.rate == 1.0);
665 fail_unless (segment.format == GST_FORMAT_BYTES);
666 fail_unless (segment.flags == 0);
667 fail_unless (segment.start == 0);
668 fail_unless (segment.stop == 200);
669 fail_unless (segment.time == 0);
670 fail_unless (segment.accum == 0);
671 fail_unless (segment.last_stop == 0);
672 fail_unless (segment.duration == -1);
674 /* assume we advanced to position 40 */
675 gst_segment_set_last_stop (&segment, GST_FORMAT_BYTES, 40);
676 fail_unless (segment.last_stop == 40);
678 /* do an update to the start, last_stop is unchanged because it's bigger */
679 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 20, 200,
682 fail_unless (segment.start == 20);
683 fail_unless (segment.stop == 200);
684 fail_unless (segment.time == 20);
685 fail_unless (segment.accum == 20);
686 fail_unless (segment.last_stop == 40);
688 /* do an update past our last_stop, it should be updated now */
689 gst_segment_set_newsegment (&segment, TRUE, 1.0, GST_FORMAT_BYTES, 50, 300,
692 fail_unless (segment.start == 50);
693 fail_unless (segment.stop == 300);
694 fail_unless (segment.time == 50);
695 fail_unless (segment.accum == 50);
696 fail_unless (segment.last_stop == 50);
698 /* and a new accumulated one */
699 gst_segment_set_newsegment (&segment, FALSE, 1.0,
700 GST_FORMAT_BYTES, 100, 400, 300);
702 fail_unless (segment.start == 100);
703 fail_unless (segment.stop == 400);
704 fail_unless (segment.time == 300);
705 fail_unless (segment.accum == 300);
707 /* and a new updated one */
708 gst_segment_set_newsegment (&segment, TRUE, 1.0,
709 GST_FORMAT_BYTES, 100, 500, 300);
711 fail_unless (segment.start == 100);
712 fail_unless (segment.stop == 500);
713 fail_unless (segment.time == 300);
714 fail_unless (segment.accum == 300);
716 /* and a new partially updated one */
717 gst_segment_set_newsegment (&segment, TRUE, 1.0,
718 GST_FORMAT_BYTES, 200, 500, 400);
720 fail_unless (segment.start == 200);
721 fail_unless (segment.stop == 500);
722 fail_unless (segment.time == 400);
723 fail_unless (segment.accum == 400);
728 /* mess with the segment structure in the time format */
729 GST_START_TEST (segment_newsegment_streamtime)
734 gst_segment_init (&segment, GST_FORMAT_TIME);
736 /***************************
738 ***************************/
739 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
740 GST_FORMAT_TIME, 0, 200, 0);
742 fail_unless (segment.rate == 1.0);
743 fail_unless (segment.applied_rate == 1.0);
744 fail_unless (segment.format == GST_FORMAT_TIME);
745 fail_unless (segment.flags == 0);
746 fail_unless (segment.start == 0);
747 fail_unless (segment.stop == 200);
748 fail_unless (segment.time == 0);
749 fail_unless (segment.accum == 0);
750 fail_unless (segment.last_stop == 0);
751 fail_unless (segment.duration == -1);
753 /* invalid time gives invalid result */
754 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
755 fail_unless (result == -1);
757 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
758 fail_unless (result == 0);
760 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
761 fail_unless (result == 100);
763 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
764 fail_unless (result == 200);
766 /* outside of the segment */
767 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
768 fail_unless (result == -1);
770 /*********************
771 * time shifted by 500
772 *********************/
773 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
774 GST_FORMAT_TIME, 0, 200, 500);
776 fail_unless (segment.accum == 200);
778 /* invalid time gives invalid result */
779 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
780 fail_unless (result == -1);
782 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
783 fail_unless (result == 500);
785 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
786 fail_unless (result == 600);
788 /* outside of the segment */
789 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
790 fail_unless (result == -1);
792 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
793 fail_unless (result == -1);
795 /*********************
797 *********************/
798 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
799 GST_FORMAT_TIME, 500, 700, 0);
801 fail_unless (segment.accum == 400);
803 /* invalid time gives invalid result */
804 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
805 fail_unless (result == -1);
807 /* before segment is invalid */
808 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
809 fail_unless (result == -1);
811 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
812 fail_unless (result == 0);
814 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600);
815 fail_unless (result == 100);
817 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700);
818 fail_unless (result == 200);
820 /* outside of the segment */
821 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800);
822 fail_unless (result == -1);
824 /*************************************
825 * time offset by 500, shifted by 200
826 *************************************/
827 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
828 GST_FORMAT_TIME, 500, 700, 200);
830 fail_unless (segment.accum == 600);
832 /* invalid time gives invalid result */
833 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
834 fail_unless (result == -1);
836 /* before segment is invalid */
837 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
838 fail_unless (result == -1);
840 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 500);
841 fail_unless (result == 200);
843 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 600);
844 fail_unless (result == 300);
846 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 700);
847 fail_unless (result == 400);
849 /* outside of the segment */
850 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 800);
851 fail_unless (result == -1);
856 /* mess with the segment structure in the time format */
857 GST_START_TEST (segment_newsegment_streamtime_rate)
862 gst_segment_init (&segment, GST_FORMAT_TIME);
864 /***************************
865 * Normal segment rate 2.0
866 ***************************/
867 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
868 GST_FORMAT_TIME, 0, 200, 0);
870 fail_unless (segment.rate == 2.0);
871 fail_unless (segment.applied_rate == 1.0);
872 fail_unless (segment.format == GST_FORMAT_TIME);
873 fail_unless (segment.flags == 0);
874 fail_unless (segment.start == 0);
875 fail_unless (segment.stop == 200);
876 fail_unless (segment.time == 0);
877 fail_unless (segment.accum == 0);
878 fail_unless (segment.last_stop == 0);
879 fail_unless (segment.duration == -1);
881 /* invalid time gives invalid result */
882 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
883 fail_unless (result == -1);
885 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
886 fail_unless (result == 0);
888 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
889 fail_unless (result == 100);
891 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
892 fail_unless (result == 150);
894 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
895 fail_unless (result == 200);
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 2.0, offset
903 ***************************************/
904 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
905 GST_FORMAT_TIME, 100, 300, 0);
907 fail_unless (segment.accum == 100);
909 /* invalid time gives invalid result */
910 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
911 fail_unless (result == -1);
913 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
914 fail_unless (result == 0);
916 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
917 fail_unless (result == 100);
919 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 250);
920 fail_unless (result == 150);
922 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
923 fail_unless (result == 200);
925 /* outside of the segment */
926 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
927 fail_unless (result == -1);
929 /***************************************
930 * Normal segment rate -1.0, offset
931 ***************************************/
933 /* buffers will arrive from 300 to 100 in a sink, stream time
934 * calculation is unaffected by the rate */
935 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
936 GST_FORMAT_TIME, 100, 300, 0);
938 fail_unless (segment.accum == 200);
940 /* invalid time gives invalid result */
941 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
942 fail_unless (result == -1);
944 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
945 fail_unless (result == 0);
947 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
948 fail_unless (result == 100);
950 /***********************************************
951 * Normal segment rate -1.0, offset, time = 200
952 ***********************************************/
953 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
954 GST_FORMAT_TIME, 100, 300, 200);
956 /* invalid time gives invalid result */
957 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
958 fail_unless (result == -1);
960 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
961 fail_unless (result == 200);
963 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
964 fail_unless (result == 300);
966 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
967 fail_unless (result == 400);
969 /* outside of the segment */
970 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 400);
971 fail_unless (result == -1);
976 /* mess with the segment structure in the time format */
977 GST_START_TEST (segment_newsegment_streamtime_applied_rate)
982 gst_segment_init (&segment, GST_FORMAT_TIME);
984 /***********************************************************
985 * Normal segment rate 1.0, applied rate -1.0
986 * This means the timestamps represents a stream going backwards
987 * starting from @time to 0.
988 ************************************************************/
989 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -1.0,
990 GST_FORMAT_TIME, 0, 200, 200);
992 fail_unless (segment.rate == 1.0);
993 fail_unless (segment.applied_rate == -1.0);
994 fail_unless (segment.format == GST_FORMAT_TIME);
995 fail_unless (segment.flags == 0);
996 fail_unless (segment.start == 0);
997 fail_unless (segment.stop == 200);
998 fail_unless (segment.time == 200);
999 fail_unless (segment.accum == 0);
1000 fail_unless (segment.last_stop == 0);
1001 fail_unless (segment.duration == -1);
1003 /* invalid time gives invalid result */
1004 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1005 fail_unless (result == -1);
1007 /* we count backwards from 200 */
1008 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1009 fail_unless (result == 200);
1011 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1012 fail_unless (result == 100);
1014 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1015 fail_unless (result == 50);
1017 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1018 fail_unless (result == 0);
1020 /* outside of the segment */
1021 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1022 fail_unless (result == -1);
1024 /***********************************************************
1025 * Normal segment rate 1.0, applied rate 2.0
1026 * This means the timestamps represents a stream at twice the
1028 ************************************************************/
1029 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
1030 GST_FORMAT_TIME, 0, 200, 0);
1032 fail_unless (segment.rate == 1.0);
1033 fail_unless (segment.applied_rate == 2.0);
1034 fail_unless (segment.format == GST_FORMAT_TIME);
1035 fail_unless (segment.flags == 0);
1036 fail_unless (segment.start == 0);
1037 fail_unless (segment.stop == 200);
1038 fail_unless (segment.time == 0);
1039 fail_unless (segment.accum == 200);
1040 fail_unless (segment.last_stop == 0);
1041 fail_unless (segment.duration == -1);
1043 /* invalid time gives invalid result */
1044 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1045 fail_unless (result == -1);
1047 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1048 fail_unless (result == 0);
1050 /* the stream prepresents a stream going twice as fast, the position
1051 * in the segment is therefore scaled by the applied rate */
1052 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1053 fail_unless (result == 200);
1055 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1056 fail_unless (result == 300);
1058 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1059 fail_unless (result == 400);
1061 /* outside of the segment */
1062 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1063 fail_unless (result == -1);
1065 /***********************************************************
1066 * Normal segment rate 1.0, applied rate -2.0
1067 * This means the timestamps represents a stream at twice the
1069 ************************************************************/
1070 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0,
1071 GST_FORMAT_TIME, 0, 200, 400);
1073 fail_unless (segment.rate == 1.0);
1074 fail_unless (segment.applied_rate == -2.0);
1075 fail_unless (segment.format == GST_FORMAT_TIME);
1076 fail_unless (segment.flags == 0);
1077 fail_unless (segment.start == 0);
1078 fail_unless (segment.stop == 200);
1079 fail_unless (segment.time == 400);
1080 /* previous segment lasted 200, rate of 2.0 was already applied */
1081 fail_unless (segment.accum == 400);
1082 fail_unless (segment.last_stop == 0);
1083 fail_unless (segment.duration == -1);
1085 /* invalid time gives invalid result */
1086 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1087 fail_unless (result == -1);
1089 /* we count backwards from 400 */
1090 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1091 fail_unless (result == 400);
1093 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1094 fail_unless (result == 200);
1096 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1097 fail_unless (result == 100);
1099 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1100 fail_unless (result == 0);
1102 /* outside of the segment */
1103 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1104 fail_unless (result == -1);
1106 /***********************************************************
1107 * Normal segment rate 1.0, applied rate -2.0
1108 * This means the timestamps represents a stream at twice the
1109 * reverse rate, start time cannot compensate the complete
1110 * duration of the segment so we stop at 0
1111 ************************************************************/
1112 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, -2.0,
1113 GST_FORMAT_TIME, 0, 200, 200);
1115 fail_unless (segment.rate == 1.0);
1116 fail_unless (segment.applied_rate == -2.0);
1117 fail_unless (segment.format == GST_FORMAT_TIME);
1118 fail_unless (segment.flags == 0);
1119 fail_unless (segment.start == 0);
1120 fail_unless (segment.stop == 200);
1121 fail_unless (segment.time == 200);
1122 fail_unless (segment.accum == 600);
1123 fail_unless (segment.last_stop == 0);
1124 fail_unless (segment.duration == -1);
1126 /* invalid time gives invalid result */
1127 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1128 fail_unless (result == -1);
1130 /* we count backwards from 200 */
1131 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1132 fail_unless (result == 200);
1134 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1135 fail_unless (result == 0);
1138 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1139 fail_unless (result == 0);
1141 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1142 fail_unless (result == 0);
1144 /* outside of the segment */
1145 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1146 fail_unless (result == -1);
1151 /* mess with the segment structure in the time format */
1152 GST_START_TEST (segment_newsegment_streamtime_applied_rate_rate)
1157 gst_segment_init (&segment, GST_FORMAT_TIME);
1159 /***********************************************************
1160 * Segment rate 2.0, applied rate 2.0
1161 * this means we have a double speed stream that we should
1162 * speed up by a factor of 2.0 some more. the resulting
1163 * stream will be played at four times the speed.
1164 ************************************************************/
1165 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 2.0,
1166 GST_FORMAT_TIME, 0, 200, 0);
1168 fail_unless (segment.rate == 2.0);
1169 fail_unless (segment.applied_rate == 2.0);
1170 fail_unless (segment.format == GST_FORMAT_TIME);
1171 fail_unless (segment.flags == 0);
1172 fail_unless (segment.start == 0);
1173 fail_unless (segment.stop == 200);
1174 fail_unless (segment.time == 0);
1175 fail_unless (segment.accum == 0);
1176 fail_unless (segment.last_stop == 0);
1177 fail_unless (segment.duration == -1);
1179 /* invalid time gives invalid result */
1180 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1181 fail_unless (result == -1);
1183 /* only applied rate affects our calculation of the stream time */
1184 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1185 fail_unless (result == 0);
1187 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1188 fail_unless (result == 200);
1190 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1191 fail_unless (result == 300);
1193 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1194 fail_unless (result == 400);
1196 /* outside of the segment */
1197 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1198 fail_unless (result == -1);
1200 /***********************************************************
1201 * Segment rate 2.0, applied rate -1.0
1202 * this means we have a reverse stream that we should
1203 * speed up by a factor of 2.0
1204 ************************************************************/
1205 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, -1.0,
1206 GST_FORMAT_TIME, 0, 200, 200);
1208 fail_unless (segment.rate == 2.0);
1209 fail_unless (segment.applied_rate == -1.0);
1210 fail_unless (segment.format == GST_FORMAT_TIME);
1211 fail_unless (segment.flags == 0);
1212 fail_unless (segment.start == 0);
1213 fail_unless (segment.stop == 200);
1214 fail_unless (segment.time == 200);
1215 /* previous segment lasted 100 */
1216 fail_unless (segment.accum == 100);
1217 fail_unless (segment.last_stop == 0);
1218 fail_unless (segment.duration == -1);
1220 /* invalid time gives invalid result */
1221 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1222 fail_unless (result == -1);
1224 /* only applied rate affects our calculation of the stream time */
1225 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1226 fail_unless (result == 200);
1228 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1229 fail_unless (result == 100);
1231 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1232 fail_unless (result == 50);
1234 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1235 fail_unless (result == 0);
1237 /* outside of the segment */
1238 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1239 fail_unless (result == -1);
1241 /***********************************************************
1242 * Segment rate -1.0, applied rate -1.0
1243 * this means we have a reverse stream that we should
1244 * reverse to get the normal stream again.
1245 ************************************************************/
1246 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, -1.0,
1247 GST_FORMAT_TIME, 0, 200, 200);
1249 fail_unless (segment.rate == -1.0);
1250 fail_unless (segment.applied_rate == -1.0);
1251 fail_unless (segment.format == GST_FORMAT_TIME);
1252 fail_unless (segment.flags == 0);
1253 fail_unless (segment.start == 0);
1254 fail_unless (segment.stop == 200);
1255 fail_unless (segment.time == 200);
1256 /* accumulated 100 of previous segment to make 200 */
1257 fail_unless (segment.accum == 200);
1258 fail_unless (segment.last_stop == 200);
1259 fail_unless (segment.duration == -1);
1261 /* invalid time gives invalid result */
1262 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1263 fail_unless (result == -1);
1265 /* only applied rate affects our calculation of the stream time */
1266 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1267 fail_unless (result == 200);
1269 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1270 fail_unless (result == 100);
1272 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1273 fail_unless (result == 50);
1275 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1276 fail_unless (result == 0);
1278 /* outside of the segment */
1279 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1280 fail_unless (result == -1);
1282 /***********************************************************
1283 * Segment rate -1.0, applied rate -1.0
1284 * this means we have a reverse stream that we should
1285 * reverse to get the normal stream again.
1286 ************************************************************/
1287 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 2.0,
1288 GST_FORMAT_TIME, 0, 200, 0);
1290 fail_unless (segment.rate == -1.0);
1291 fail_unless (segment.applied_rate == 2.0);
1292 fail_unless (segment.format == GST_FORMAT_TIME);
1293 fail_unless (segment.flags == 0);
1294 fail_unless (segment.start == 0);
1295 fail_unless (segment.stop == 200);
1296 fail_unless (segment.time == 0);
1297 fail_unless (segment.accum == 400);
1298 fail_unless (segment.last_stop == 200);
1299 fail_unless (segment.duration == -1);
1301 /* invalid time gives invalid result */
1302 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, -1);
1303 fail_unless (result == -1);
1305 /* only applied rate affects our calculation of the stream time */
1306 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 0);
1307 fail_unless (result == 0);
1309 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 100);
1310 fail_unless (result == 200);
1312 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 150);
1313 fail_unless (result == 300);
1315 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 200);
1316 fail_unless (result == 400);
1318 /* outside of the segment */
1319 result = gst_segment_to_stream_time (&segment, GST_FORMAT_TIME, 300);
1320 fail_unless (result == -1);
1325 /* mess with the segment structure in the time format */
1326 GST_START_TEST (segment_newsegment_runningtime)
1331 gst_segment_init (&segment, GST_FORMAT_TIME);
1333 /***************************
1335 ***************************/
1336 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
1337 GST_FORMAT_TIME, 0, 200, 0);
1339 fail_unless (segment.rate == 1.0);
1340 fail_unless (segment.applied_rate == 1.0);
1341 fail_unless (segment.format == GST_FORMAT_TIME);
1342 fail_unless (segment.flags == 0);
1343 fail_unless (segment.start == 0);
1344 fail_unless (segment.stop == 200);
1345 fail_unless (segment.time == 0);
1346 fail_unless (segment.accum == 0);
1347 fail_unless (segment.last_stop == 0);
1348 fail_unless (segment.duration == -1);
1350 /* invalid time gives invalid result */
1351 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1352 fail_unless (result == -1);
1354 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0);
1355 fail_unless (result == 0);
1356 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1357 fail_unless (result == 0);
1359 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1360 fail_unless (result == 100);
1361 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1362 fail_unless (result == 100);
1364 /* at edge is exactly the segment duration */
1365 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200);
1366 fail_unless (result == 200);
1367 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1368 fail_unless (result == 200);
1370 /* outside of the segment */
1371 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 300);
1372 fail_unless (result == -1);
1373 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 300);
1374 fail_unless (result == -1);
1376 /***********************************************************
1377 * time shifted by 500, check if accumulation worked.
1378 * Rate convert to twice the speed which means scaling down
1379 * all positions by 2.0 in this segment.
1380 * Then time argument is not used at all here.
1381 ***********************************************************/
1382 gst_segment_set_newsegment_full (&segment, FALSE, 2.0, 1.0,
1383 GST_FORMAT_TIME, 0, 200, 500);
1385 /* normal speed gives elapsed of 200 */
1386 fail_unless (segment.accum == 200);
1388 /* invalid time gives invalid result */
1389 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1390 fail_unless (result == -1);
1392 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 0);
1393 fail_unless (result == 200);
1394 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1395 fail_unless (result == 0);
1397 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1398 fail_unless (result == 250);
1399 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1400 fail_unless (result == 100);
1402 /* outside of the segment */
1403 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1404 fail_unless (result == -1);
1405 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 310);
1406 fail_unless (result == -1);
1408 /********************************************
1409 * time offset by 500
1410 * applied rate is not used for running time
1411 ********************************************/
1412 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 2.0,
1413 GST_FORMAT_TIME, 500, 700, 0);
1415 /* previous segment played at double speed gives elapsed time of
1416 * 100 added to previous accum of 200 gives 300. */
1417 fail_unless (segment.accum == 300);
1419 /* invalid time gives invalid result */
1420 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1421 fail_unless (result == -1);
1423 /* before segment is invalid */
1424 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1425 fail_unless (result == -1);
1426 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 200);
1427 fail_unless (result == -1);
1429 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1430 fail_unless (result == 300);
1431 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1432 fail_unless (result == 500);
1434 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1435 fail_unless (result == 400);
1436 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1437 fail_unless (result == 600);
1439 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1440 fail_unless (result == 500);
1441 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1442 fail_unless (result == 700);
1444 /* outside of the segment */
1445 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1446 fail_unless (result == -1);
1447 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 600);
1448 fail_unless (result == -1);
1450 /**********************************************************
1451 * time offset by 500, shifted by 200
1452 * Negative rate makes the running time go backwards
1453 * relative to the segment stop position. again time
1455 **********************************************************/
1456 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
1457 GST_FORMAT_TIME, 500, 700, 200);
1459 fail_unless (segment.accum == 500);
1461 /* invalid time gives invalid result */
1462 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1463 fail_unless (result == -1);
1465 /* before segment is invalid */
1466 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1467 fail_unless (result == -1);
1468 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 400);
1469 fail_unless (result == -1);
1471 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1472 fail_unless (result == 700);
1473 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1474 fail_unless (result == 500);
1476 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1477 fail_unless (result == 600);
1478 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1479 fail_unless (result == 600);
1481 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1482 fail_unless (result == 500);
1483 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1484 fail_unless (result == 700);
1486 /* outside of the segment */
1487 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1488 fail_unless (result == -1);
1489 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 800);
1490 fail_unless (result == -1);
1492 /**********************************************************
1493 * time offset by 500, shifted by 200
1494 * Negative rate makes the running time go backwards at
1495 * twice speed relative to the segment stop position. again
1497 **********************************************************/
1498 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -2.0,
1499 GST_FORMAT_TIME, 500, 700, 200);
1501 fail_unless (segment.accum == 700);
1503 /* invalid time gives invalid result */
1504 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1505 fail_unless (result == -1);
1507 /* before segment is invalid */
1508 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 400);
1509 fail_unless (result == -1);
1510 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 600);
1511 fail_unless (result == -1);
1513 /* total scaled segment time is 100, accum is 700, so we get 800 */
1514 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 500);
1515 fail_unless (result == 800);
1516 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1517 fail_unless (result == 500);
1519 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 600);
1520 fail_unless (result == 750);
1521 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1522 fail_unless (result == 600);
1524 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 700);
1525 fail_unless (result == 700);
1526 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1527 fail_unless (result == 700);
1529 /* outside of the segment */
1530 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 800);
1531 fail_unless (result == -1);
1532 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 900);
1533 fail_unless (result == -1);
1535 /* see if negative rate closed segment correctly */
1536 gst_segment_set_newsegment_full (&segment, FALSE, -2.0, -1.0,
1537 GST_FORMAT_TIME, 500, 700, 200);
1539 /* previous segment lasted 100, and was at 700 so we should get 800 */
1540 fail_unless (segment.accum == 800);
1541 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, 800);
1542 fail_unless (result == 700);
1547 /* mess with the segment structure in the time format */
1548 GST_START_TEST (segment_newsegment_accum)
1553 gst_segment_init (&segment, GST_FORMAT_TIME);
1555 /***************************
1556 * Normal reverse segment
1557 ***************************/
1558 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
1559 GST_FORMAT_TIME, 0, 200, 0);
1561 fail_unless (segment.rate == -1.0);
1562 fail_unless (segment.applied_rate == 1.0);
1563 fail_unless (segment.format == GST_FORMAT_TIME);
1564 fail_unless (segment.flags == 0);
1565 fail_unless (segment.start == 0);
1566 fail_unless (segment.stop == 200);
1567 fail_unless (segment.time == 0);
1568 fail_unless (segment.accum == 0);
1569 fail_unless (segment.last_stop == 200);
1570 fail_unless (segment.duration == -1);
1572 /* invalid time gives invalid result */
1573 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1574 fail_unless (result == -1);
1576 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200);
1577 fail_unless (result == 0);
1578 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1579 fail_unless (result == 200);
1581 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150);
1582 fail_unless (result == 50);
1583 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1584 fail_unless (result == 150);
1586 /* update segment, this accumulates 50 from the previous segment. */
1587 gst_segment_set_newsegment_full (&segment, TRUE, -2.0, 1.0,
1588 GST_FORMAT_TIME, 0, 150, 0);
1590 fail_unless (segment.rate == -2.0);
1591 fail_unless (segment.applied_rate == 1.0);
1592 fail_unless (segment.format == GST_FORMAT_TIME);
1593 fail_unless (segment.flags == 0);
1594 fail_unless (segment.start == 0);
1595 fail_unless (segment.stop == 150);
1596 fail_unless (segment.time == 0);
1597 fail_unless (segment.accum == 50);
1598 fail_unless (segment.last_stop == 150);
1599 fail_unless (segment.duration == -1);
1601 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150);
1602 fail_unless (result == 50);
1603 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1604 fail_unless (result == 150);
1606 /* 50 accumulated + 50 / 2 */
1607 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1608 fail_unless (result == 75);
1609 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1610 fail_unless (result == 100);
1612 /* update segment, this does not accumulate anything. */
1613 gst_segment_set_newsegment_full (&segment, TRUE, 1.0, 1.0,
1614 GST_FORMAT_TIME, 100, 200, 100);
1616 fail_unless (segment.rate == 1.0);
1617 fail_unless (segment.applied_rate == 1.0);
1618 fail_unless (segment.format == GST_FORMAT_TIME);
1619 fail_unless (segment.flags == 0);
1620 fail_unless (segment.start == 100);
1621 fail_unless (segment.stop == 200);
1622 fail_unless (segment.time == 100);
1623 fail_unless (segment.accum == 50);
1624 fail_unless (segment.last_stop == 150);
1625 fail_unless (segment.duration == -1);
1627 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 100);
1628 fail_unless (result == 50);
1629 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1630 fail_unless (result == 100);
1632 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150);
1633 fail_unless (result == 100);
1634 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1635 fail_unless (result == 150);
1640 /* mess with the segment structure in the time format */
1641 GST_START_TEST (segment_newsegment_accum2)
1646 gst_segment_init (&segment, GST_FORMAT_TIME);
1648 /***************************
1649 * Normal reverse segment
1650 ***************************/
1651 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
1652 GST_FORMAT_TIME, 0, 200, 0);
1654 fail_unless (segment.rate == -1.0);
1655 fail_unless (segment.applied_rate == 1.0);
1656 fail_unless (segment.format == GST_FORMAT_TIME);
1657 fail_unless (segment.flags == 0);
1658 fail_unless (segment.start == 0);
1659 fail_unless (segment.stop == 200);
1660 fail_unless (segment.time == 0);
1661 fail_unless (segment.accum == 0);
1662 fail_unless (segment.last_stop == 200);
1663 fail_unless (segment.duration == -1);
1665 /* invalid time gives invalid result */
1666 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1667 fail_unless (result == -1);
1668 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1669 fail_unless (result == -1);
1671 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200);
1672 fail_unless (result == 0);
1673 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1674 fail_unless (result == 200);
1676 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150);
1677 fail_unless (result == 50);
1678 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1679 fail_unless (result == 150);
1681 /* close segment, this accumulates nothing. */
1682 gst_segment_set_newsegment_full (&segment, TRUE, -1.0, 1.0,
1683 GST_FORMAT_TIME, 150, 200, 0);
1685 fail_unless (segment.rate == -1.0);
1686 fail_unless (segment.applied_rate == 1.0);
1687 fail_unless (segment.format == GST_FORMAT_TIME);
1688 fail_unless (segment.flags == 0);
1689 fail_unless (segment.start == 150);
1690 fail_unless (segment.stop == 200);
1691 fail_unless (segment.time == 0);
1692 fail_unless (segment.accum == 0);
1693 fail_unless (segment.last_stop == 200);
1694 fail_unless (segment.duration == -1);
1696 /* new segment, this accumulates 50. */
1697 gst_segment_set_newsegment_full (&segment, FALSE, 1.0, 1.0,
1698 GST_FORMAT_TIME, 150, 300, 150);
1700 fail_unless (segment.rate == 1.0);
1701 fail_unless (segment.applied_rate == 1.0);
1702 fail_unless (segment.format == GST_FORMAT_TIME);
1703 fail_unless (segment.flags == 0);
1704 fail_unless (segment.start == 150);
1705 fail_unless (segment.stop == 300);
1706 fail_unless (segment.time == 150);
1707 fail_unless (segment.accum == 50);
1708 fail_unless (segment.last_stop == 150);
1709 fail_unless (segment.duration == -1);
1711 /* invalid time gives invalid result */
1712 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, -1);
1713 fail_unless (result == -1);
1715 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 150);
1716 fail_unless (result == 50);
1717 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1718 fail_unless (result == 150);
1720 result = gst_segment_to_running_time (&segment, GST_FORMAT_TIME, 200);
1721 fail_unless (result == 100);
1722 result = gst_segment_to_position (&segment, GST_FORMAT_TIME, result);
1723 fail_unless (result == 200);
1728 GST_START_TEST (segment_copy)
1731 GstSegment segment = { 0.0, };
1733 /* this is a boxed type copy function, we support copying NULL */
1734 fail_unless (gst_segment_copy (NULL) == NULL);
1736 gst_segment_init (&segment, GST_FORMAT_TIME);
1738 gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
1739 GST_FORMAT_TIME, 0, 200, 0);
1741 copy = gst_segment_copy (&segment);
1742 fail_unless (copy != NULL);
1743 /* we inited the struct on the stack to zeroes, so direct comparison should
1744 * be ok here despite the padding field and regardless of implementation */
1745 fail_unless (memcmp (copy, &segment, sizeof (GstSegment)) == 0);
1746 gst_segment_free (copy);
1752 gst_segment_suite (void)
1754 Suite *s = suite_create ("GstSegment");
1755 TCase *tc_chain = tcase_create ("segments");
1757 tcase_set_timeout (tc_chain, 20);
1759 suite_add_tcase (s, tc_chain);
1760 tcase_add_test (tc_chain, segment_seek_nosize);
1761 tcase_add_test (tc_chain, segment_seek_size);
1762 tcase_add_test (tc_chain, segment_seek_reverse);
1763 tcase_add_test (tc_chain, segment_seek_rate);
1764 tcase_add_test (tc_chain, segment_newsegment_open);
1765 tcase_add_test (tc_chain, segment_newsegment_closed);
1766 tcase_add_test (tc_chain, segment_newsegment_streamtime);
1767 tcase_add_test (tc_chain, segment_newsegment_streamtime_rate);
1768 tcase_add_test (tc_chain, segment_newsegment_streamtime_applied_rate);
1769 tcase_add_test (tc_chain, segment_newsegment_streamtime_applied_rate_rate);
1770 tcase_add_test (tc_chain, segment_newsegment_runningtime);
1771 tcase_add_test (tc_chain, segment_newsegment_accum);
1772 tcase_add_test (tc_chain, segment_newsegment_accum2);
1773 tcase_add_test (tc_chain, segment_copy);
1778 GST_CHECK_MAIN (gst_segment);