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 module ffmpeg.libavutil.timestamp;
25 
26 import std.stdint;
27 
28 public import ffmpeg.libavutil.avutil;
29 public import ffmpeg.libavutil.common;
30 public import ffmpeg.libavutil.rational;
31 public import ffmpeg.libavutil.avutil_version;
32 
33 extern(C):
34 
35 enum AV_TS_MAX_STRING_SIZE = 32;
36 
37 /**
38  * Fill the provided buffer with a string containing a timestamp time
39  * representation.
40  *
41  * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
42  * @param ts the timestamp to represent
43  * @param tb the timebase of the timestamp
44  * @return the buffer in input
45  */
46 string av_ts_make_string(int64_t ts)
47 {
48     import std.format : format;
49   if (ts == AV_NOPTS_VALUE) {
50     return "NOPTS";
51   } else {
52     return format!"%d"(ts);
53   }
54 }
55 
56 /**
57  * Convenience macro, the return value should be used only directly in
58  * function arguments but never stand-alone.
59  */
60 //#define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
61 
62 /**
63  * Fill the provided buffer with a string containing a timestamp time
64  * representation.
65  *
66  * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
67  * @param ts the timestamp to represent
68  * @param tb the timebase of the timestamp
69  * @return the buffer in input
70  */
71 string av_ts_make_time_string(int64_t ts, AVRational tb)
72 {
73   import std.format : format;
74   if (ts == 0x8000000000000000) {
75     return "NOPTS";
76   } else {
77     return format!"%.6g"(av_q2d(tb) * ts);
78   }
79 }
80 
81 /**
82  * Convenience macro, the return value should be used only directly in
83  * function arguments but never stand-alone.
84  */
85 //#define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
86 
87 // end avutil.h