-
Notifications
You must be signed in to change notification settings - Fork 4
/
libavutil_timestamp.pas
156 lines (132 loc) · 4.52 KB
/
libavutil_timestamp.pas
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
(*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)
(**
* @file
* timestamp utils, mostly useful for debugging/logging purposes
*)
(*
* FFVCL - Delphi FFmpeg VCL Components
* http://www.DelphiFFmpeg.com
*
* Original file: libavutil/timestamp.h
* Ported by CodeCoolie@CNSW 2014/07/21 -> $Date:: 2017-02-09 #$
*)
(*
FFmpeg Delphi/Pascal Headers and Examples License Agreement
A modified part of FFVCL - Delphi FFmpeg VCL Components.
Copyright (c) 2008-2016 DelphiFFmpeg.com
All rights reserved.
http://www.DelphiFFmpeg.com
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This source code is provided "as is" by DelphiFFmpeg.com without
warranty of any kind, either expressed or implied, including but not
limited to the implied warranties of merchantability and/or fitness
for a particular purpose.
Please also notice the License agreement of FFmpeg libraries.
*)
unit libavutil_timestamp;
interface
{$I CompilerDefines.inc}
uses
{$IFDEF VCL_XE2_OR_ABOVE}
System.SysUtils,
{$ELSE}
SysUtils,
{$ENDIF}
libavutil,
libavutil_rational;
{$I libversion.inc}
//#define AV_TS_MAX_STRING_SIZE 32
(**
* Fill the provided buffer with a string containing a timestamp
* representation.
*
* @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
* @param ts the timestamp to represent
* @return the buffer in input
*)
function av_ts_make_string(ts: Int64): string; {$IFDEF USE_INLINE}inline;{$ENDIF}
{
if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%" PRId64, ts);
return buf;
}
(**
* Convenience macro, the return value should be used only directly in
* function arguments but never stand-alone.
*)
//#define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
function av_ts2str(ts: Int64): string; {$IFDEF USE_INLINE}inline;{$ENDIF}
(**
* Fill the provided buffer with a string containing a timestamp time
* representation.
*
* @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
* @param ts the timestamp to represent
* @param tb the timebase of the timestamp
* @return the buffer in input
*)
function av_ts_make_time_string(ts: Int64; tb: PAVRational): string; {$IFDEF USE_INLINE}inline;{$ENDIF}
{
if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6g", av_q2d(*tb) * ts);
return buf;
}
(**
* Convenience macro, the return value should be used only directly in
* function arguments but never stand-alone.
*)
//#define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
function av_ts2timestr(ts: Int64; tb: PAVRational): string; {$IFDEF USE_INLINE}inline;{$ENDIF}
implementation
function av_ts_make_string(ts: Int64): string;
begin
if ts = AV_NOPTS_VALUE then
Result := 'NOPTS'
else
Result := IntToStr(ts);
end;
function av_ts2str(ts: Int64): string;
begin
if ts = AV_NOPTS_VALUE then
Result := 'NOPTS'
else
Result := IntToStr(ts);
end;
function av_ts_make_time_string(ts: Int64; tb: PAVRational): string;
begin
if ts = AV_NOPTS_VALUE then
Result := 'NOPTS'
else
Result := Format('%.6g', [av_q2d(tb^) * ts]);
end;
function av_ts2timestr(ts: Int64; tb: PAVRational): string;
begin
if ts = AV_NOPTS_VALUE then
Result := 'NOPTS'
else
Result := Format('%.6g', [av_q2d(tb^) * ts]);
end;
end.