demux: adaptive: missing es_format_Init
[vlc.git] / src / win32 / timer.c
blob707e9f581e8c1acb00842a97f14fe0bb68d6e7f3
1 /*****************************************************************************
2 * timer.c : Win32 timers for LibVLC
3 *****************************************************************************
4 * Copyright (C) 2009-2016 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * 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 <assert.h>
26 #include <stdlib.h>
27 #include <windows.h>
28 #include <vlc_common.h>
30 struct vlc_timer
32 HANDLE handle;
33 void (*func) (void *);
34 void *data;
37 static void CALLBACK vlc_timer_do (void *val, BOOLEAN timeout)
39 struct vlc_timer *timer = val;
41 assert (timeout);
42 timer->func (timer->data);
45 int vlc_timer_create (vlc_timer_t *id, void (*func) (void *), void *data)
47 struct vlc_timer *timer = malloc (sizeof (*timer));
49 if (timer == NULL)
50 return ENOMEM;
51 timer->func = func;
52 timer->data = data;
53 timer->handle = INVALID_HANDLE_VALUE;
54 *id = timer;
55 return 0;
58 void vlc_timer_destroy (vlc_timer_t timer)
60 if (timer->handle != INVALID_HANDLE_VALUE)
61 DeleteTimerQueueTimer (NULL, timer->handle, INVALID_HANDLE_VALUE);
62 free (timer);
65 void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
66 mtime_t value, mtime_t interval)
68 if (timer->handle != INVALID_HANDLE_VALUE)
70 DeleteTimerQueueTimer (NULL, timer->handle, INVALID_HANDLE_VALUE);
71 timer->handle = INVALID_HANDLE_VALUE;
73 if (value == 0)
74 return; /* Disarm */
76 if (absolute)
78 value -= mdate ();
79 if (value < 0)
80 value = 0;
82 value = (value + 999) / 1000;
83 interval = (interval + 999) / 1000;
85 if (!CreateTimerQueueTimer (&timer->handle, NULL, vlc_timer_do, timer,
86 value, interval, WT_EXECUTEDEFAULT))
87 abort ();
90 unsigned vlc_timer_getoverrun (vlc_timer_t timer)
92 (void)timer;
93 return 0;