Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qffmpegtime_p.h
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
ifndef
QFFMPEGTIME_P_H
5
#
define
QFFMPEGTIME_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
"qglobal.h"
19
20
#
include
<
QtCore
/
qdebug
.
h
>
21
#
include
<
QtMultimedia
/
private
/
qtaggedtime_p
.
h
>
22
#
include
<
QtFFmpegMediaPluginImpl
/
private
/
qffmpeg_p
.
h
>
23
24
#
include
<
chrono
>
25
26
#
ifdef
Q_OS_WIN
27
#
include
<
QtCore
/
qt_windows
.
h
>
28
#
include
<
QtCore
/
private
/
qwin32ticks_p
.
h
>
29
#
include
<
realtimeapiset
.
h
>
30
#
endif
31
32
QT_BEGIN_NAMESPACE
33
34
namespace
QFFmpeg
{
35
36
using
namespace
std
::chrono_literals;
37
38
struct
TrackTimeTag;
39
// track position in microseconds, used as
40
// a general time position in the playback engine
41
using
TrackPosition
=
QTaggedTimePoint
<
qint64
,
TrackTimeTag
>;
42
using
TrackDuration
=
QTaggedDuration
<
qint64
,
TrackTimeTag
>;
43
44
struct
UserTrackTimeTag;
45
// track position in milliseconds, that matches the postion in the public API
46
using
UserTrackPosition
=
QTaggedTimePoint
<
qint64
,
UserTrackTimeTag
>;
47
using
UserTrackDuration
=
QTaggedDuration
<
qint64
,
UserTrackTimeTag
>;
48
49
struct
AVStreamTimeTag;
50
// position in AVStream, in 'AVStream::time_base * 1sec' units
51
using
AVStreamPosition
=
QTaggedTimePoint
<
qint64
,
AVStreamTimeTag
>;
52
using
AVStreamDuration
=
QTaggedDuration
<
qint64
,
AVStreamTimeTag
>;
53
54
struct
AVContextTimeTag;
55
// position in the AVFormatContext, in '1sec / AV_TIME_BASE' units, which is actually
56
// microseconds. The position is shifted on AVFormatContext::start_time from TrackTime.
57
using
AVContextPosition
=
QTaggedTimePoint
<
qint64
,
AVContextTimeTag
>;
58
using
AVContextDuration
=
QTaggedDuration
<
qint64
,
AVContextTimeTag
>;
59
60
#
ifdef
Q_OS_WIN
61
// std::chrono::steady_clock is based on QueryPerformanceCounter on Windows, which keeps counting
62
// while the system is suspended. After wake-up the playback timeline would be ahead of the media
63
// by the whole sleeping time, and video-only media would play extremely fast. The interrupt time
64
// doesn't include the sleeping time, like CLOCK_MONOTONIC on Linux and CLOCK_UPTIME_RAW on macOS.
65
struct
UnbiasedInterruptClock
66
{
67
using
duration
=
QtPrivate
::
win32_ticks
;
68
using
time_point
=
std
::
chrono
::
time_point
<
UnbiasedInterruptClock
,
duration
>;
69
70
static
time_point
now
()
noexcept
71
{
72
ULONGLONG
interruptTime
= 0;
// 100 ns units, excludes the time in sleep/hibernation
73
QueryUnbiasedInterruptTimePrecise
(&
interruptTime
);
74
return
time_point
(
duration
(
static_cast
<
duration
::
rep
>(
interruptTime
)));
75
}
76
};
77
78
using
SteadyClock
=
UnbiasedInterruptClock
;
79
#
else
80
using
SteadyClock
=
std
::chrono::steady_clock;
81
#
endif
82
83
inline
std
::
optional
<
AVContextDuration
>
contextStartOffset
(
const
AVFormatContext *formatContext)
84
{
85
if
(formatContext->start_time == AV_NOPTS_VALUE)
86
return
std::nullopt;
87
return
AVContextDuration(formatContext->start_time);
88
}
89
90
inline
UserTrackPosition
toUserPosition
(TrackPosition trackPosition)
91
{
92
return
UserTrackPosition(trackPosition.get() / 1000);
93
}
94
95
inline
UserTrackDuration
toUserDuration
(TrackDuration trackDuration)
96
{
97
return
UserTrackDuration(trackDuration.get() / 1000);
98
}
99
100
inline
TrackDuration
toTrackDuration
(AVContextDuration contextDuration)
101
{
102
return
TrackDuration(contextDuration.get() * 1'000'000 / AV_TIME_BASE);
103
}
104
105
inline
TrackPosition
toTrackPosition
(UserTrackPosition userTrackPosition)
106
{
107
return
TrackPosition(userTrackPosition.get() * 1000);
108
}
109
110
inline
TrackDuration
toTrackDuration
(UserTrackDuration userTrackDuration)
111
{
112
return
TrackDuration(userTrackDuration.get() * 1000);
113
}
114
115
inline
TrackDuration
toTrackDuration
(AVStreamDuration streamDuration,
const
AVStream *avStream)
116
{
117
return
TrackDuration(timeStampUs(streamDuration.get(), avStream->time_base).value_or(0));
118
}
119
120
inline
TrackPosition
toTrackPosition
(AVStreamPosition streamPosition,
const
AVStream *avStream,
121
const
AVFormatContext *formatContext)
122
{
123
auto
duration = toTrackDuration(streamPosition.asDuration(), avStream);
124
if
(formatContext) {
125
std::optional contextStart = contextStartOffset(formatContext);
126
if
(contextStart)
127
duration -= toTrackDuration(*contextStart);
128
}
129
130
return
duration.asTimePoint();
131
}
132
133
inline
AVContextPosition
toContextPosition
(TrackPosition trackPosition,
134
const
AVFormatContext *formatContext)
135
{
136
return
AVContextPosition(trackPosition.get() * AV_TIME_BASE / 1'000'000)
137
+ contextStartOffset(formatContext).value_or(AVContextDuration::zero());
138
}
139
140
inline
QDebug
operator
<<(QDebug debug,
const
TrackPosition &position)
141
{
142
return
debug <<
"TrackPosition{"
<< position.get() <<
"us}"
;
143
}
144
145
inline
QDebug
operator
<<(QDebug debug,
const
TrackDuration &duration)
146
{
147
return
debug <<
"TrackDuration{"
<< duration.get() <<
"us}"
;
148
}
149
150
inline
QDebug
operator
<<(QDebug debug,
const
UserTrackPosition &position)
151
{
152
return
debug <<
"UserTrackPosition{"
<< position.get() <<
"ms}"
;
153
}
154
155
inline
QDebug
operator
<<(QDebug debug,
const
UserTrackDuration &duration)
156
{
157
return
debug <<
"UserTrackDuration{"
<< duration.get() <<
"ms}"
;
158
}
159
160
inline
QDebug
operator
<<(QDebug debug,
const
AVStreamPosition &position)
161
{
162
return
debug <<
"AVStreamPosition{"
<< position.get() <<
"stream units}"
;
163
}
164
165
inline
QDebug
operator
<<(QDebug debug,
const
AVStreamDuration &duration)
166
{
167
return
debug <<
"AVStreamDuration{"
<< duration.get() <<
"stream units}"
;
168
}
169
170
}
// namespace QFFmpeg
171
172
QT_END_NAMESPACE
173
174
#
endif
// QFFMPEGTIME_P_H
QFFmpeg
Definition
qandroidcacertificates.cpp:26
QFFmpeg::toUserDuration
UserTrackDuration toUserDuration(TrackDuration trackDuration)
Definition
qffmpegtime_p.h:95
QFFmpeg::operator<<
QDebug operator<<(QDebug debug, const TrackPosition &position)
Definition
qffmpegtime_p.h:140
QFFmpeg::toTrackDuration
TrackDuration toTrackDuration(AVStreamDuration streamDuration, const AVStream *avStream)
Definition
qffmpegtime_p.h:115
QFFmpeg::toContextPosition
AVContextPosition toContextPosition(TrackPosition trackPosition, const AVFormatContext *formatContext)
Definition
qffmpegtime_p.h:133
QFFmpeg::contextStartOffset
std::optional< AVContextDuration > contextStartOffset(const AVFormatContext *formatContext)
Definition
qffmpegtime_p.h:83
QFFmpeg::SteadyClock
std::chrono::steady_clock SteadyClock
Definition
qffmpegtime_p.h:80
QFFmpeg::toTrackDuration
TrackDuration toTrackDuration(AVContextDuration contextDuration)
Definition
qffmpegtime_p.h:100
QFFmpeg::toUserPosition
UserTrackPosition toUserPosition(TrackPosition trackPosition)
Definition
qffmpegtime_p.h:90
QFFmpeg::toTrackPosition
TrackPosition toTrackPosition(AVStreamPosition streamPosition, const AVStream *avStream, const AVFormatContext *formatContext)
Definition
qffmpegtime_p.h:120
QFFmpeg::toTrackPosition
TrackPosition toTrackPosition(UserTrackPosition userTrackPosition)
Definition
qffmpegtime_p.h:105
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtmultimedia
src
plugins
multimedia
ffmpeg
playbackengine
qffmpegtime_p.h
Generated on
for Qt by
1.18.0