| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
#ifdef HAVE_CONFIG_H |
|---|
| 33 |
# include "config.h" |
|---|
| 34 |
#endif |
|---|
| 35 |
|
|---|
| 36 |
#include <vlc_common.h> |
|---|
| 37 |
|
|---|
| 38 |
#include <time.h> |
|---|
| 39 |
#include <assert.h> |
|---|
| 40 |
#include <errno.h> |
|---|
| 41 |
|
|---|
| 42 |
#ifdef HAVE_UNISTD_H |
|---|
| 43 |
# include <unistd.h> |
|---|
| 44 |
#endif |
|---|
| 45 |
|
|---|
| 46 |
#ifdef HAVE_KERNEL_OS_H |
|---|
| 47 |
# include <kernel/OS.h> |
|---|
| 48 |
#endif |
|---|
| 49 |
|
|---|
| 50 |
#if defined( WIN32 ) || defined( UNDER_CE ) |
|---|
| 51 |
# include <windows.h> |
|---|
| 52 |
# include <mmsystem.h> |
|---|
| 53 |
#endif |
|---|
| 54 |
|
|---|
| 55 |
#if defined( UNDER_CE ) |
|---|
| 56 |
# include <windows.h> |
|---|
| 57 |
#endif |
|---|
| 58 |
|
|---|
| 59 |
#if defined(HAVE_SYS_TIME_H) |
|---|
| 60 |
# include <sys/time.h> |
|---|
| 61 |
#endif |
|---|
| 62 |
|
|---|
| 63 |
#if !defined(HAVE_STRUCT_TIMESPEC) |
|---|
| 64 |
struct timespec |
|---|
| 65 |
{ |
|---|
| 66 |
time_t tv_sec; |
|---|
| 67 |
int32_t tv_nsec; |
|---|
| 68 |
}; |
|---|
| 69 |
#endif |
|---|
| 70 |
|
|---|
| 71 |
#if defined(HAVE_NANOSLEEP) && !defined(HAVE_DECL_NANOSLEEP) |
|---|
| 72 |
int nanosleep(struct timespec *, struct timespec *); |
|---|
| 73 |
#endif |
|---|
| 74 |
|
|---|
| 75 |
#if !defined (_POSIX_CLOCK_SELECTION) |
|---|
| 76 |
# define _POSIX_CLOCK_SELECTION (-1) |
|---|
| 77 |
#endif |
|---|
| 78 |
|
|---|
| 79 |
# if (_POSIX_CLOCK_SELECTION < 0) |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
# undef CLOCK_MONOTONIC |
|---|
| 87 |
# define CLOCK_MONOTONIC CLOCK_REALTIME |
|---|
| 88 |
#elif !defined (HAVE_CLOCK_NANOSLEEP) |
|---|
| 89 |
|
|---|
| 90 |
# error We have quite a situation here! Fix me if it ever happens. |
|---|
| 91 |
#endif |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
char *mstrtime( char *psz_buffer, mtime_t date ) |
|---|
| 104 |
{ |
|---|
| 105 |
static const mtime_t ll1000 = 1000, ll60 = 60, ll24 = 24; |
|---|
| 106 |
|
|---|
| 107 |
snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02d:%02d:%02d-%03d.%03d", |
|---|
| 108 |
(int) (date / (ll1000 * ll1000 * ll60 * ll60) % ll24), |
|---|
| 109 |
(int) (date / (ll1000 * ll1000 * ll60) % ll60), |
|---|
| 110 |
(int) (date / (ll1000 * ll1000) % ll60), |
|---|
| 111 |
(int) (date / ll1000 % ll1000), |
|---|
| 112 |
(int) (date % ll1000) ); |
|---|
| 113 |
return( psz_buffer ); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
char *secstotimestr( char *psz_buffer, int i_seconds ) |
|---|
| 127 |
{ |
|---|
| 128 |
int i_hours, i_mins; |
|---|
| 129 |
i_mins = i_seconds / 60; |
|---|
| 130 |
i_hours = i_mins / 60 ; |
|---|
| 131 |
if( i_hours ) |
|---|
| 132 |
{ |
|---|
| 133 |
snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%d:%2.2d:%2.2d", |
|---|
| 134 |
(int) i_hours, |
|---|
| 135 |
(int) (i_mins % 60), |
|---|
| 136 |
(int) (i_seconds % 60) ); |
|---|
| 137 |
} |
|---|
| 138 |
else |
|---|
| 139 |
{ |
|---|
| 140 |
snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%2.2d:%2.2d", |
|---|
| 141 |
(int) i_mins , |
|---|
| 142 |
(int) (i_seconds % 60) ); |
|---|
| 143 |
} |
|---|
| 144 |
return( psz_buffer ); |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
#if defined (HAVE_CLOCK_NANOSLEEP) |
|---|
| 148 |
static unsigned prec = 0; |
|---|
| 149 |
|
|---|
| 150 |
static void mprec_once( void ) |
|---|
| 151 |
{ |
|---|
| 152 |
struct timespec ts; |
|---|
| 153 |
if( clock_getres( CLOCK_MONOTONIC, &ts )) |
|---|
| 154 |
clock_getres( CLOCK_REALTIME, &ts ); |
|---|
| 155 |
|
|---|
| 156 |
prec = ts.tv_nsec / 1000; |
|---|
| 157 |
} |
|---|
| 158 |
#endif |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
static inline unsigned mprec( void ) |
|---|
| 165 |
{ |
|---|
| 166 |
#if defined (HAVE_CLOCK_NANOSLEEP) |
|---|
| 167 |
static pthread_once_t once = PTHREAD_ONCE_INIT; |
|---|
| 168 |
pthread_once( &once, mprec_once ); |
|---|
| 169 |
return prec; |
|---|
| 170 |
#else |
|---|
| 171 |
return 0; |
|---|
| 172 |
#endif |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
mtime_t mdate( void ) |
|---|
| 183 |
{ |
|---|
| 184 |
mtime_t res; |
|---|
| 185 |
|
|---|
| 186 |
#if defined (HAVE_CLOCK_NANOSLEEP) |
|---|
| 187 |
struct timespec ts; |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
if( clock_gettime( CLOCK_MONOTONIC, &ts ) == EINVAL ) |
|---|
| 191 |
|
|---|
| 192 |
(void)clock_gettime( CLOCK_REALTIME, &ts ); |
|---|
| 193 |
|
|---|
| 194 |
res = ((mtime_t)ts.tv_sec * (mtime_t)1000000) |
|---|
| 195 |
+ (mtime_t)(ts.tv_nsec / 1000); |
|---|
| 196 |
|
|---|
| 197 |
#elif defined( HAVE_KERNEL_OS_H ) |
|---|
| 198 |
res = real_time_clock_usecs(); |
|---|
| 199 |
|
|---|
| 200 |
#elif defined( WIN32 ) || defined( UNDER_CE ) |
|---|
| 201 |
|
|---|
| 202 |
static mtime_t freq = INT64_C(-1); |
|---|
| 203 |
|
|---|
| 204 |
if( freq == INT64_C(-1) ) |
|---|
| 205 |
{ |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
LARGE_INTEGER buf; |
|---|
| 225 |
|
|---|
| 226 |
freq = ( QueryPerformanceFrequency( &buf ) && |
|---|
| 227 |
(buf.QuadPart == INT64_C(1193182) || buf.QuadPart == INT64_C(3579545) ) ) |
|---|
| 228 |
? buf.QuadPart : 0; |
|---|
| 229 |
|
|---|
| 230 |
#if defined( WIN32 ) |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
HINSTANCE h_Kernel32 = LoadLibrary(_T("kernel32.dll")); |
|---|
| 238 |
if(h_Kernel32) |
|---|
| 239 |
{ |
|---|
| 240 |
void WINAPI (*pf_GetSystemInfo)(LPSYSTEM_INFO); |
|---|
| 241 |
pf_GetSystemInfo = (void WINAPI (*)(LPSYSTEM_INFO)) |
|---|
| 242 |
GetProcAddress(h_Kernel32, _T("GetSystemInfo")); |
|---|
| 243 |
if(pf_GetSystemInfo) |
|---|
| 244 |
{ |
|---|
| 245 |
SYSTEM_INFO system_info; |
|---|
| 246 |
pf_GetSystemInfo(&system_info); |
|---|
| 247 |
if(system_info.dwNumberOfProcessors > 1) |
|---|
| 248 |
freq = 0; |
|---|
| 249 |
} |
|---|
| 250 |
FreeLibrary(h_Kernel32); |
|---|
| 251 |
} |
|---|
| 252 |
#endif |
|---|
| 253 |
} |
|---|
| 254 |
|
|---|
| 255 |
if( freq != 0 ) |
|---|
| 256 |
{ |
|---|
| 257 |
LARGE_INTEGER counter; |
|---|
| 258 |
QueryPerformanceCounter (&counter); |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
lldiv_t d = lldiv (counter.QuadPart, freq); |
|---|
| 263 |
|
|---|
| 264 |
res = (d.quot * 1000000) + ((d.rem * 1000000) / freq); |
|---|
| 265 |
} |
|---|
| 266 |
else |
|---|
| 267 |
{ |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
static CRITICAL_SECTION date_lock; |
|---|
| 274 |
static mtime_t i_previous_time = INT64_C(-1); |
|---|
| 275 |
static int i_wrap_counts = -1; |
|---|
| 276 |
|
|---|
| 277 |
if( i_wrap_counts == -1 ) |
|---|
| 278 |
{ |
|---|
| 279 |
|
|---|
| 280 |
#if defined( WIN32 ) |
|---|
| 281 |
i_previous_time = INT64_C(1000) * timeGetTime(); |
|---|
| 282 |
#else |
|---|
| 283 |
i_previous_time = INT64_C(1000) * GetTickCount(); |
|---|
| 284 |
#endif |
|---|
| 285 |
InitializeCriticalSection( &date_lock ); |
|---|
| 286 |
i_wrap_counts = 0; |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
EnterCriticalSection( &date_lock ); |
|---|
| 290 |
#if defined( WIN32 ) |
|---|
| 291 |
res = INT64_C(1000) * |
|---|
| 292 |
(i_wrap_counts * INT64_C(0x100000000) + timeGetTime()); |
|---|
| 293 |
#else |
|---|
| 294 |
res = INT64_C(1000) * |
|---|
| 295 |
(i_wrap_counts * INT64_C(0x100000000) + GetTickCount()); |
|---|
| 296 |
#endif |
|---|
| 297 |
if( i_previous_time > res ) |
|---|
| 298 |
{ |
|---|
| 299 |
|
|---|
| 300 |
i_wrap_counts++; |
|---|
| 301 |
res += INT64_C(0x100000000) * 1000; |
|---|
| 302 |
} |
|---|
| 303 |
i_previous_time = res; |
|---|
| 304 |
LeaveCriticalSection( &date_lock ); |
|---|
| 305 |
} |
|---|
| 306 |
#else |
|---|
| 307 |
struct timeval tv_date; |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
(void)gettimeofday( &tv_date, NULL ); |
|---|
| 311 |
res = (mtime_t) tv_date.tv_sec * 1000000 + (mtime_t) tv_date.tv_usec; |
|---|
| 312 |
#endif |
|---|
| 313 |
|
|---|
| 314 |
return res; |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
#undef mwait |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
void mwait( mtime_t date ) |
|---|
| 327 |
{ |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
date -= mprec(); |
|---|
| 331 |
|
|---|
| 332 |
#if defined (HAVE_CLOCK_NANOSLEEP) |
|---|
| 333 |
lldiv_t d = lldiv( date, 1000000 ); |
|---|
| 334 |
struct timespec ts = { d.quot, d.rem * 1000 }; |
|---|
| 335 |
|
|---|
| 336 |
int val; |
|---|
| 337 |
while( ( val = clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, |
|---|
| 338 |
NULL ) ) == EINTR ); |
|---|
| 339 |
if( val == EINVAL ) |
|---|
| 340 |
{ |
|---|
| 341 |
ts.tv_sec = d.quot; ts.tv_nsec = d.rem * 1000; |
|---|
| 342 |
while( clock_nanosleep( CLOCK_REALTIME, 0, &ts, NULL ) == EINTR ); |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
#elif defined (WIN32) |
|---|
| 346 |
mtime_t i_total; |
|---|
| 347 |
|
|---|
| 348 |
while( (i_total = (date - mdate())) > 0 ) |
|---|
| 349 |
{ |
|---|
| 350 |
const mtime_t i_sleep = i_total / 1000; |
|---|
| 351 |
DWORD i_delay = (i_sleep > 0x7fffffff) ? 0x7fffffff : i_sleep; |
|---|
| 352 |
vlc_testcancel(); |
|---|
| 353 |
SleepEx( i_delay, TRUE ); |
|---|
| 354 |
} |
|---|
| 355 |
vlc_testcancel(); |
|---|
| 356 |
|
|---|
| 357 |
#else |
|---|
| 358 |
mtime_t delay = date - mdate(); |
|---|
| 359 |
if( delay > 0 ) |
|---|
| 360 |
msleep( delay ); |
|---|
| 361 |
|
|---|
| 362 |
#endif |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
#include "libvlc.h" |
|---|
| 367 |
#undef msleep |
|---|
| 368 |
|
|---|
| 369 |
#if defined(__APPLE__) && defined( HAVE_NANOSLEEP ) |
|---|
| 370 |
|
|---|
| 371 |
static inline int |
|---|
| 372 |
semi_testcancelable_nanosleep(const struct timespec *rqtp, struct timespec *rmtp) |
|---|
| 373 |
{ |
|---|
| 374 |
int ret; |
|---|
| 375 |
pthread_testcancel(); |
|---|
| 376 |
ret = nanosleep(rqtp, rmtp); |
|---|
| 377 |
pthread_testcancel(); |
|---|
| 378 |
return ret; |
|---|
| 379 |
} |
|---|
| 380 |
#define nanosleep semi_testcancelable_nanosleep |
|---|
| 381 |
#endif |
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
void msleep( mtime_t delay ) |
|---|
| 389 |
{ |
|---|
| 390 |
#if defined( HAVE_CLOCK_NANOSLEEP ) |
|---|
| 391 |
lldiv_t d = lldiv( delay, 1000000 ); |
|---|
| 392 |
struct timespec ts = { d.quot, d.rem * 1000 }; |
|---|
| 393 |
|
|---|
| 394 |
int val; |
|---|
| 395 |
while( ( val = clock_nanosleep( CLOCK_MONOTONIC, 0, &ts, &ts ) ) == EINTR ); |
|---|
| 396 |
if( val == EINVAL ) |
|---|
| 397 |
{ |
|---|
| 398 |
ts.tv_sec = d.quot; ts.tv_nsec = d.rem * 1000; |
|---|
| 399 |
while( clock_nanosleep( CLOCK_REALTIME, 0, &ts, &ts ) == EINTR ); |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
#elif defined( HAVE_KERNEL_OS_H ) |
|---|
| 403 |
snooze( delay ); |
|---|
| 404 |
|
|---|
| 405 |
#elif defined( WIN32 ) || defined( UNDER_CE ) |
|---|
| 406 |
mwait (mdate () + delay); |
|---|
| 407 |
|
|---|
| 408 |
#elif defined( HAVE_NANOSLEEP ) |
|---|
| 409 |
struct timespec ts_delay; |
|---|
| 410 |
|
|---|
| 411 |
ts_delay.tv_sec = delay / 1000000; |
|---|
| 412 |
ts_delay.tv_nsec = (delay % 1000000) * 1000; |
|---|
| 413 |
|
|---|
| 414 |
while( nanosleep( &ts_delay, &ts_delay ) && ( errno == EINTR ) ); |
|---|
| 415 |
|
|---|
| 416 |
#else |
|---|
| 417 |
struct timeval tv_delay; |
|---|
| 418 |
|
|---|
| 419 |
tv_delay.tv_sec = delay / 1000000; |
|---|
| 420 |
tv_delay.tv_usec = delay % 1000000; |
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
select( 0, NULL, NULL, NULL, &tv_delay ); |
|---|
| 425 |
#endif |
|---|
| 426 |
} |
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
void date_Init( date_t *p_date, uint32_t i_divider_n, uint32_t i_divider_d ) |
|---|
| 441 |
{ |
|---|
| 442 |
p_date->date = 0; |
|---|
| 443 |
p_date->i_divider_num = i_divider_n; |
|---|
| 444 |
p_date->i_divider_den = i_divider_d; |
|---|
| 445 |
p_date->i_remainder = 0; |
|---|
| 446 |
} |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
void date_Change( date_t *p_date, uint32_t i_divider_n, uint32_t i_divider_d ) |
|---|
| 457 |
{ |
|---|
| 458 |
|
|---|
| 459 |
p_date->i_remainder = p_date->i_remainder * i_divider_n / p_date->i_divider_num; |
|---|
| 460 |
p_date->i_divider_num = i_divider_n; |
|---|
| 461 |
p_date->i_divider_den = i_divider_d; |
|---|
| 462 |
} |
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
void date_Set( date_t *p_date, mtime_t i_new_date ) |
|---|
| 471 |
{ |
|---|
| 472 |
p_date->date = i_new_date; |
|---|
| 473 |
p_date->i_remainder = 0; |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
mtime_t date_Get( const date_t *p_date ) |
|---|
| 483 |
{ |
|---|
| 484 |
return p_date->date; |
|---|
| 485 |
} |
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
void date_Move( date_t *p_date, mtime_t i_difference ) |
|---|
| 494 |
{ |
|---|
| 495 |
p_date->date += i_difference; |
|---|
| 496 |
} |
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
mtime_t date_Increment( date_t *p_date, uint32_t i_nb_samples ) |
|---|
| 507 |
{ |
|---|
| 508 |
mtime_t i_dividend = (mtime_t)i_nb_samples * 1000000 * p_date->i_divider_den; |
|---|
| 509 |
p_date->date += i_dividend / p_date->i_divider_num; |
|---|
| 510 |
p_date->i_remainder += (int)(i_dividend % p_date->i_divider_num); |
|---|
| 511 |
|
|---|
| 512 |
if( p_date->i_remainder >= p_date->i_divider_num ) |
|---|
| 513 |
{ |
|---|
| 514 |
|
|---|
| 515 |
assert( p_date->i_remainder < 2*p_date->i_divider_num); |
|---|
| 516 |
p_date->date += 1; |
|---|
| 517 |
p_date->i_remainder -= p_date->i_divider_num; |
|---|
| 518 |
} |
|---|
| 519 |
|
|---|
| 520 |
return p_date->date; |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
#ifndef HAVE_GETTIMEOFDAY |
|---|
| 524 |
|
|---|
| 525 |
#ifdef WIN32 |
|---|
| 526 |
|
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) || defined(__WATCOMC__) |
|---|
| 534 |
# define DELTA_EPOCH_IN_USEC 11644473600000000Ui64 |
|---|
| 535 |
#else |
|---|
| 536 |
# define DELTA_EPOCH_IN_USEC 11644473600000000ULL |
|---|
| 537 |
#endif |
|---|
| 538 |
|
|---|
| 539 |
static uint64_t filetime_to_unix_epoch (const FILETIME *ft) |
|---|
| 540 |
{ |
|---|
| 541 |
uint64_t res = (uint64_t) ft->dwHighDateTime << 32; |
|---|
| 542 |
|
|---|
| 543 |
res |= ft->dwLowDateTime; |
|---|
| 544 |
res /= 10; |
|---|
| 545 |
res -= DELTA_EPOCH_IN_USEC; |
|---|
| 546 |
return (res); |
|---|
| 547 |
} |
|---|
| 548 |
|
|---|
| 549 |
static int gettimeofday (struct timeval *tv, void *tz ) |
|---|
| 550 |
{ |
|---|
| 551 |
FILETIME ft; |
|---|
| 552 |
uint64_t tim; |
|---|
| 553 |
|
|---|
| 554 |
if (!tv) { |
|---|
| 555 |
return VLC_EGENERIC; |
|---|
| 556 |
} |
|---|
| 557 |
GetSystemTimeAsFileTime (&ft); |
|---|
| 558 |
tim = filetime_to_unix_epoch (&ft); |
|---|
| 559 |
tv->tv_sec = (long) (tim / 1000000L); |
|---|
| 560 |
tv->tv_usec = (long) (tim % 1000000L); |
|---|
| 561 |
return (0); |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
#endif |
|---|
| 565 |
|
|---|
| 566 |
#endif |
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
uint64_t NTPtime64 (void) |
|---|
| 572 |
{ |
|---|
| 573 |
struct timespec ts; |
|---|
| 574 |
#if defined (CLOCK_REALTIME) |
|---|
| 575 |
clock_gettime (CLOCK_REALTIME, &ts); |
|---|
| 576 |
#else |
|---|
| 577 |
{ |
|---|
| 578 |
struct timeval tv; |
|---|
| 579 |
gettimeofday (&tv, NULL); |
|---|
| 580 |
ts.tv_sec = tv.tv_sec; |
|---|
| 581 |
ts.tv_nsec = tv.tv_usec * 1000; |
|---|
| 582 |
} |
|---|
| 583 |
#endif |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
uint64_t t = (uint64_t)(ts.tv_nsec) << 32; |
|---|
| 587 |
t /= 1000000000; |
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
assert (t < 0x100000000); |
|---|
| 594 |
t |= ((70LL * 365 + 17) * 24 * 60 * 60 + ts.tv_sec) << 32; |
|---|
| 595 |
return t; |
|---|
| 596 |
} |
|---|
| 597 |
|
|---|