FFmpeg
time.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2003 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 
23 #include <stddef.h>
24 #include <stdint.h>
25 #include <time.h>
26 #if HAVE_GETTIMEOFDAY
27 #include <sys/time.h>
28 #endif
29 #if HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32 #if HAVE_WINDOWS_H
33 #include <windows.h>
34 #endif
35 
36 #include "time.h"
37 #include "error.h"
38 
40 {
41 #if HAVE_GETTIMEOFDAY
42  struct timeval tv;
43  gettimeofday(&tv, NULL);
44  return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
45 #elif HAVE_GETSYSTEMTIMEASFILETIME
46  FILETIME ft;
47  int64_t t;
48  GetSystemTimeAsFileTime(&ft);
49  t = (int64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
50  return t / 10 - 11644473600000000; /* Jan 1, 1601 */
51 #else
52  return -1;
53 #endif
54 }
55 
57 {
58 #if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
59 #ifdef __APPLE__
60  if (&clock_gettime)
61 #endif
62  {
63  struct timespec ts;
64  clock_gettime(CLOCK_MONOTONIC, &ts);
65  return (int64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
66  }
67 #endif
68  return av_gettime() + 42 * 60 * 60 * INT64_C(1000000);
69 }
70 
72 {
73 #if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
74 #ifdef __APPLE__
75  if (!&clock_gettime)
76  return 0;
77 #endif
78  return 1;
79 #else
80  return 0;
81 #endif
82 }
83 
84 int av_usleep(unsigned usec)
85 {
86 #if HAVE_NANOSLEEP
87  struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 };
88  while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
89  return 0;
90 #elif HAVE_USLEEP
91  return usleep(usec);
92 #elif HAVE_SLEEP
93  Sleep(usec / 1000);
94  return 0;
95 #else
96  return AVERROR(ENOSYS);
97 #endif
98 }
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int64_t
long long int64_t
Definition: coverity.c:34
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
NULL
#define NULL
Definition: coverity.c:32
time.h
error.h
av_gettime_relative_is_monotonic
int av_gettime_relative_is_monotonic(void)
Indicates with a boolean result if the av_gettime_relative() time source is monotonic.
Definition: time.c:71
av_gettime
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39