2009-03-01 13:13:25 +00:00
|
|
|
/*
|
|
|
|
* precise timer routines for Windows
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2003-04-25 10:00:18 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#include "timer.h"
|
|
|
|
|
2004-08-04 15:48:43 +00:00
|
|
|
const char *timer_name = "Windows native";
|
|
|
|
|
2003-04-25 10:00:18 +00:00
|
|
|
// Returns current time in microseconds
|
2009-01-05 14:48:03 +00:00
|
|
|
unsigned int GetTimer(void)
|
|
|
|
{
|
2003-04-25 10:00:18 +00:00
|
|
|
return timeGetTime() * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns current time in milliseconds
|
2009-01-05 18:05:34 +00:00
|
|
|
unsigned int GetTimerMS(void)
|
2009-01-05 14:48:03 +00:00
|
|
|
{
|
2003-04-25 10:00:18 +00:00
|
|
|
return timeGetTime() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usec_sleep(int usec_delay){
|
2009-05-13 02:58:57 +00:00
|
|
|
// Sleep(0) won't sleep for one clocktick as the unix usleep
|
2003-11-16 15:11:52 +00:00
|
|
|
// instead it will only make the thread ready
|
|
|
|
// it may take some time until it actually starts to run again
|
2009-05-13 02:58:57 +00:00
|
|
|
if(usec_delay<1000)usec_delay=1000;
|
2003-04-25 10:00:18 +00:00
|
|
|
Sleep( usec_delay/1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD RelativeTime = 0;
|
|
|
|
|
2009-01-05 14:48:03 +00:00
|
|
|
float GetRelativeTime(void)
|
|
|
|
{
|
2003-04-25 10:00:18 +00:00
|
|
|
DWORD t, r;
|
|
|
|
t = GetTimer();
|
|
|
|
r = t - RelativeTime;
|
|
|
|
RelativeTime = t;
|
|
|
|
return (float) r *0.000001F;
|
|
|
|
}
|
|
|
|
|
2009-01-05 14:48:03 +00:00
|
|
|
void InitTimer(void)
|
|
|
|
{
|
2003-04-25 10:00:18 +00:00
|
|
|
GetRelativeTime();
|
|
|
|
}
|