FFmpeg
timestamp.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * timestamp utils, mostly useful for debugging/logging purposes
22  */
23 
24 #ifndef AVUTIL_TIMESTAMP_H
25 #define AVUTIL_TIMESTAMP_H
26 
27 #include "avutil.h"
28 
29 #if defined(__cplusplus) && !defined(__STDC_FORMAT_MACROS) && !defined(PRId64)
30 #error missing -D__STDC_FORMAT_MACROS / #define __STDC_FORMAT_MACROS
31 #endif
32 
33 #define AV_TS_MAX_STRING_SIZE 32
34 
35 /**
36  * Fill the provided buffer with a string containing a timestamp
37  * representation.
38  *
39  * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
40  * @param ts the timestamp to represent
41  * @return the buffer in input
42  */
43 static inline char *av_ts_make_string(char *buf, int64_t ts)
44 {
45  if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
46  else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%" PRId64, ts);
47  return buf;
48 }
49 
50 /**
51  * Convenience macro, the return value should be used only directly in
52  * function arguments but never stand-alone.
53  */
54 #define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
55 
56 /**
57  * Fill the provided buffer with a string containing a timestamp time
58  * representation.
59  *
60  * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
61  * @param ts the timestamp to represent
62  * @param tb the timebase of the timestamp
63  * @return the buffer in input
64  */
65 char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb);
66 
67 /**
68  * Fill the provided buffer with a string containing a timestamp
69  * representation.
70  *
71  * @see av_ts_make_time_string2
72  */
73 static inline char *av_ts_make_time_string(char *buf, int64_t ts,
74  const AVRational *tb)
75 {
76  return av_ts_make_time_string2(buf, ts, *tb);
77 }
78 
79 /**
80  * Convenience macro, the return value should be used only directly in
81  * function arguments but never stand-alone.
82  */
83 #define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
84 
85 #endif /* AVUTIL_TIMESTAMP_H */
int64_t
long long int64_t
Definition: coverity.c:34
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
av_ts_make_time_string
static char * av_ts_make_time_string(char *buf, int64_t ts, const AVRational *tb)
Fill the provided buffer with a string containing a timestamp representation.
Definition: timestamp.h:73
tb
#define tb
Definition: regdef.h:68
av_ts_make_time_string2
char * av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb)
Fill the provided buffer with a string containing a timestamp time representation.
Definition: timestamp.c:21
av_ts_make_string
static char * av_ts_make_string(char *buf, int64_t ts)
Fill the provided buffer with a string containing a timestamp representation.
Definition: timestamp.h:43
avutil.h
AV_TS_MAX_STRING_SIZE
#define AV_TS_MAX_STRING_SIZE
Definition: timestamp.h:33
snprintf
#define snprintf
Definition: snprintf.h:34