Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplaybackoptions.cpp
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
5#include <chrono>
6
7QT_BEGIN_NAMESPACE
8
9using namespace std::chrono_literals;
10
12{
13public:
15
16 friend bool comparesEqual(const QPlaybackOptionsPrivate &lhs,
17 const QPlaybackOptionsPrivate &rhs)
18 {
19 return lhs.m_networkTimeout == rhs.m_networkTimeout
20 && lhs.m_playbackIntent == rhs.m_playbackIntent
22 }
23
25 const QPlaybackOptionsPrivate &rhs)
26 {
27 if (lhs.m_networkTimeout != rhs.m_networkTimeout)
28 return qCompareThreeWay(lhs.m_networkTimeout.count(), rhs.m_networkTimeout.count());
29 if (lhs.m_playbackIntent != rhs.m_playbackIntent)
30 return qCompareThreeWay(lhs.m_playbackIntent, rhs.m_playbackIntent);
31 return qCompareThreeWay(lhs.m_probeSizeBytes, rhs.m_probeSizeBytes);
32 }
33
34 std::chrono::milliseconds m_networkTimeout = 20s;
37};
38
39QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QPlaybackOptionsPrivate)
40
41/*!
42 \class QPlaybackOptions
43 \brief The QPlaybackOptions class enables low-level control of media playback options.
44 \inmodule QtMultimedia
45 \ingroup multimedia
46 \ingroup multimedia_playback
47 \ingroup multimedia_video
48 \since 6.10
49
50 QPlaybackOptions gives low-level control of media playback options. Although we strongly
51 recommend to rely on the default settings of \l QMediaPlayer, QPlaybackOptions can be used to
52 optimize media playback to specific use cases where the default options are not ideal.
53
54 Note that options are hints to the media backend, and may be ignored if they are not supported
55 by the current media format or codec.
56
57 Playback options rely on support in the media backend. Availability is documented per option.
58
59 \sa QMediaPlayer
60*/
61
62/*!
63 \qmltype playbackOptions
64 \nativetype QPlaybackOptions
65 \brief Low level media playback options.
66
67 \inqmlmodule QtMultimedia
68 \ingroup multimedia_qml
69 \ingroup multimedia_audio_qml
70 \ingroup multimedia_video_qml
71 \since 6.10
72
73 Playback options gives low-level control of media playback options. Although we strongly
74 recommend to rely on the default settings of \l MediaPlayer, playbackOptions can be used to
75 optimize media playback to specific use cases where the default options are not ideal.
76
77 Note that options are hints to the media backend, and may be ignored if they are not supported
78 by the current media format or codec.
79
80 Playback options rely on support in the media backend. Availability is documented per option.
81
82 \sa MediaPlayer
83*/
84
85QPlaybackOptions::QPlaybackOptions() : d{ new QPlaybackOptionsPrivate } { }
86QPlaybackOptions::QPlaybackOptions(const QPlaybackOptions &) = default;
87QPlaybackOptions &QPlaybackOptions::operator=(const QPlaybackOptions &) = default;
88QPlaybackOptions::~QPlaybackOptions() = default;
89
90bool comparesEqual(const QPlaybackOptions &lhs, const QPlaybackOptions &rhs) noexcept
91{
92 if (lhs.d == rhs.d)
93 return true;
94
95 return comparesEqual(*lhs.d, *rhs.d);
96}
97
99{
100 return compareThreeWay(*lhs.d, *rhs.d);
101}
102
103/*!
104 \property QPlaybackOptions::networkTimeout
105 \since 6.10
106
107 Determines the network timeout used for socket I/O operations with some
108 network formats.
109
110 This option is only supported with the FFmpeg media backend.
111*/
112
113/*!
114 \qmlproperty qint64 playbackOptions::networkTimeoutMs
115 \since 6.10
116
117 Determines the network timeout (in milliseconds) used for socket I/O operations with some
118 network formats.
119
120 This option is only supported with the FFmpeg media backend.
121*/
122
123std::chrono::milliseconds QPlaybackOptions::networkTimeout() const
124{
125 return d->m_networkTimeout;
126}
127
128void QPlaybackOptions::setNetworkTimeout(std::chrono::milliseconds timeout)
129{
130 d.detach();
131 d->m_networkTimeout = timeout;
132}
133
135{
136 d.detach();
137 d->m_networkTimeout = QPlaybackOptionsPrivate{}.m_networkTimeout;
138}
139
140/*!
141 \enum QPlaybackOptions::PlaybackIntent
142 \since 6.10
143
144 Configures the intent of media playback, to focus on either high quality playback or
145 low latency media streaming.
146
147 \value Playback The intent is robust and high quality media playback, enabling sufficient
148 buffering to prevent glitches during playback.
149 \value LowLatencyStreaming Buffering is reduced to optimize for low latency streaming, but
150 with a higher likelihood of lost frames or other glitches during playback.
151*/
152
153/*!
154 \property QPlaybackOptions::playbackIntent
155 \since 6.10
156
157 Determines if \l QMediaPlayer should optimize for robust high quality video playback (default),
158 or low latency streaming.
159
160 This option is only supported with the FFmpeg media backend.
161*/
162
163/*!
164 \qmlproperty PlaybackOptions::PlaybackIntent PlaybackOptions::playbackIntent
165 \since 6.10
166
167 Determines if \l MediaPlayer should optimize for robust high quality video playback (default),
168 or low latency streaming.
169
170 This option is only supported with the FFmpeg media backend.
171
172 \qmlenumeratorsfrom QPlaybackOptions::PlaybackIntent
173*/
174
175QPlaybackOptions::PlaybackIntent QPlaybackOptions::playbackIntent() const
176{
177 return d->m_playbackIntent;
178}
179
180void QPlaybackOptions::setPlaybackIntent(PlaybackIntent intent)
181{
182 d.detach();
183 d->m_playbackIntent = intent;
184}
185
187{
188 d.detach();
189 d->m_playbackIntent = QPlaybackOptionsPrivate{}.m_playbackIntent;
190}
191
192/*!
193 \property QPlaybackOptions::probeSize
194 \since 6.10
195
196 Probesize defines the amount of data (in bytes) to analyze in order to gather stream
197 information before media playback starts.
198
199 A larger probesize value can give more robust playback but may increase latency. Conversely,
200 a smaller probesize can reduce latency but might miss some stream details. The default
201 probesize is -1, and the actual probesize is determined by the media backend.
202
203 This option is only supported with the FFmpeg media backend.
204*/
205
206/*!
207 \qmlproperty qsizetype PlaybackOptions::probeSize
208 \since 6.10
209
210 Probesize defines the amount of data (in bytes) to analyze in order to gather stream
211 information before media playback starts.
212
213 A larger probesize value can give more robust playback but may increase latency. Conversely,
214 a smaller probesize can reduce latency but might miss some stream details. The default
215 probesize is -1, and the actual probesize is then determined by the media backend.
216
217 Note that a too small probeSize can result in failure to play the media, while a too high
218 probeSize can increase latency.
219
220 This option is only supported with the FFmpeg media backend.
221*/
222
223qsizetype QPlaybackOptions::probeSize() const
224{
225 return d->m_probeSizeBytes;
226}
227
228void QPlaybackOptions::setProbeSize(qsizetype probeSizeBytes)
229{
230 d.detach();
231 d->m_probeSizeBytes = static_cast<int>(probeSizeBytes);
232}
233
235{
236 d.detach();
237 d->m_probeSizeBytes = QPlaybackOptionsPrivate{}.m_probeSizeBytes;
238}
239
240QT_END_NAMESPACE
241
242#include "moc_qplaybackoptions.cpp"
QPlaybackOptionsPrivate()=default
std::chrono::milliseconds m_networkTimeout
friend Qt::strong_ordering compareThreeWay(const QPlaybackOptionsPrivate &lhs, const QPlaybackOptionsPrivate &rhs)
QPlaybackOptions::PlaybackIntent m_playbackIntent
friend bool comparesEqual(const QPlaybackOptionsPrivate &lhs, const QPlaybackOptionsPrivate &rhs)
The QPlaybackOptions class enables low-level control of media playback options.
Q_MULTIMEDIA_EXPORT void resetPlaybackIntent()
Q_MULTIMEDIA_EXPORT void setProbeSize(qsizetype probeSizeBytes)
Q_MULTIMEDIA_EXPORT void resetNetworkTimeout()
Q_MULTIMEDIA_EXPORT void setNetworkTimeout(std::chrono::milliseconds timeout)
Q_MULTIMEDIA_EXPORT void resetProbeSize()
Q_MULTIMEDIA_EXPORT void setPlaybackIntent(PlaybackIntent intent)
bool comparesEqual(const QPlaybackOptions &lhs, const QPlaybackOptions &rhs) noexcept
Qt::strong_ordering compareThreeWay(const QPlaybackOptions &lhs, const QPlaybackOptions &rhs) noexcept