Add encoder support for Dirac using the Schroedinger library.
[vlc/asuraparaju-public.git] / src / test / timer.c
blobc50da1d7c794d4f81e5c1b1177486b24e4aa208f
1 /*****************************************************************************
2 * timer.c: Test for timer API
3 *****************************************************************************
4 * Copyright (C) 2009 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #undef NDEBUG
30 #include <assert.h>
32 struct timer_data
34 vlc_timer_t timer;
35 vlc_mutex_t lock;
36 unsigned count;
39 static void callback (void *ptr)
41 struct timer_data *data = ptr;
43 vlc_mutex_lock (&data->lock);
44 data->count += 1 + vlc_timer_getoverrun (data->timer);
45 vlc_mutex_unlock (&data->lock);
49 int main (void)
51 struct timer_data data;
52 int val;
54 vlc_mutex_init (&data.lock);
55 data.count = 0;
57 val = vlc_timer_create (&data.timer, callback, &data);
58 assert (val == 0);
60 /* Relative timer */
61 vlc_timer_schedule (data.timer, false, 1, CLOCK_FREQ / 10);
62 msleep (CLOCK_FREQ);
63 vlc_mutex_lock (&data.lock);
64 data.count += vlc_timer_getoverrun (data.timer);
65 printf ("Count = %u\n", data.count);
66 assert (data.count >= 10);
67 data.count = 0;
68 vlc_mutex_unlock (&data.lock);
69 vlc_timer_schedule (data.timer, false, 0, 0);
71 /* Absolute timer */
72 mtime_t now = mdate ();
74 vlc_timer_schedule (data.timer, true, now, CLOCK_FREQ / 10);
75 msleep (CLOCK_FREQ);
76 vlc_mutex_lock (&data.lock);
77 data.count += vlc_timer_getoverrun (data.timer);
78 printf ("Count = %u\n", data.count);
79 assert (data.count >= 10);
80 vlc_mutex_unlock (&data.lock);
82 vlc_timer_destroy (data.timer);
83 vlc_mutex_destroy (&data.lock);
85 return 0;