annotate ffmpeg/libavutil/time.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Copyright (c) 2000-2003 Fabrice Bellard
yading@11 3 *
yading@11 4 * This file is part of FFmpeg.
yading@11 5 *
yading@11 6 * FFmpeg is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * FFmpeg is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with FFmpeg; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 #include "config.h"
yading@11 22
yading@11 23 #include <stddef.h>
yading@11 24 #include <stdint.h>
yading@11 25 #include <time.h>
yading@11 26 #if HAVE_GETTIMEOFDAY
yading@11 27 #include <sys/time.h>
yading@11 28 #endif
yading@11 29 #if HAVE_UNISTD_H
yading@11 30 #include <unistd.h>
yading@11 31 #endif
yading@11 32 #if HAVE_WINDOWS_H
yading@11 33 #include <windows.h>
yading@11 34 #endif
yading@11 35
yading@11 36 #include "libavutil/time.h"
yading@11 37 #include "error.h"
yading@11 38
yading@11 39 int64_t av_gettime(void)
yading@11 40 {
yading@11 41 #if HAVE_GETTIMEOFDAY
yading@11 42 struct timeval tv;
yading@11 43 gettimeofday(&tv, NULL);
yading@11 44 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
yading@11 45 #elif HAVE_GETSYSTEMTIMEASFILETIME
yading@11 46 FILETIME ft;
yading@11 47 int64_t t;
yading@11 48 GetSystemTimeAsFileTime(&ft);
yading@11 49 t = (int64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
yading@11 50 return t / 10 - 11644473600000000; /* Jan 1, 1601 */
yading@11 51 #else
yading@11 52 return -1;
yading@11 53 #endif
yading@11 54 }
yading@11 55
yading@11 56 int av_usleep(unsigned usec)
yading@11 57 {
yading@11 58 #if HAVE_NANOSLEEP
yading@11 59 struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 };
yading@11 60 while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
yading@11 61 return 0;
yading@11 62 #elif HAVE_USLEEP
yading@11 63 return usleep(usec);
yading@11 64 #elif HAVE_SLEEP
yading@11 65 Sleep(usec / 1000);
yading@11 66 return 0;
yading@11 67 #else
yading@11 68 return AVERROR(ENOSYS);
yading@11 69 #endif
yading@11 70 }