Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qmultimediautils.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qvideoframe.h"
6#include "qvideoframeformat.h"
7
8#include <QtCore/qdir.h>
9
11
13{
14 int integral = int(floor(value));
15 value -= qreal(integral);
16 if (value == 0.)
17 return {integral, 1};
18
19 const int dMax = 1000;
20 int n1 = 0, d1 = 1, n2 = 1, d2 = 1;
21 qreal mid = 0.;
22 while (d1 <= dMax && d2 <= dMax) {
23 mid = qreal(n1 + n2) / (d1 + d2);
24
25 if (qAbs(value - mid) < 0.000001) {
26 break;
27 } else if (value > mid) {
28 n1 = n1 + n2;
29 d1 = d1 + d2;
30 } else {
31 n2 = n1 + n2;
32 d2 = d1 + d2;
33 }
34 }
35
36 if (d1 + d2 <= dMax)
37 return {n1 + n2 + integral * (d1 + d2), d1 + d2};
38 else if (d2 < d1)
39 return { n2 + integral * d2, d2 };
40 else
41 return { n1 + integral * d1, d1 };
42}
43
44QSize qCalculateFrameSize(QSize resolution, Fraction par)
45{
46 if (par.numerator == par.denominator || par.numerator < 1 || par.denominator < 1)
47 return resolution;
48
49 if (par.numerator > par.denominator)
50 return { resolution.width() * par.numerator / par.denominator, resolution.height() };
51
52 return { resolution.width(), resolution.height() * par.denominator / par.numerator };
53}
54
56{
57 Q_ASSERT(rotation % 90 == 0);
58 return rotation % 180 ? size.transposed() : size;
59}
60
62{
63 return qRotatedFrameSize(frame.size(), frame.rotation());
64}
65
67{
68 using namespace Qt::Literals;
69 if (url.scheme().isEmpty() || url.scheme() == "file"_L1)
71 return url;
72}
73
75{
76 static const bool autoHdrEnabled = qEnvironmentVariableIntValue("QT_MEDIA_AUTO_HDR");
77
78 return autoHdrEnabled;
79}
80
82{
83 constexpr auto sdrMaxLuminance = 100.0f;
84 const auto formatMaxLuminance = format.maxLuminance();
85
86 return formatMaxLuminance > sdrMaxLuminance ? QRhiSwapChain::HDRExtendedSrgbLinear
88}
89
91 QRhiSwapChain::Format requiredSwapChainFormat)
92{
93 if (!swapChain)
94 return false;
95
96 return qIsAutoHdrEnabled() && swapChain->format() != requiredSwapChainFormat
97 && swapChain->isFormatSupported(requiredSwapChainFormat);
98}
99
static QString currentPath()
Returns the absolute path of the application's current directory.
Definition qdir.cpp:2054
\inmodule QtGui
Definition qrhi.h:1549
Format format() const
Definition qrhi.h:1584
Format
Describes the swapchain format.
Definition qrhi.h:1561
@ HDRExtendedSrgbLinear
Definition qrhi.h:1563
virtual bool isFormatSupported(Format f)=0
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
\inmodule QtCore
Definition qurl.h:94
static QUrl fromUserInput(const QString &userInput, const QString &workingDirectory=QString(), UserInputResolutionOptions options=DefaultResolution)
Returns a valid URL from a user supplied userInput string if one can be deduced.
Definition qurl.cpp:3757
@ AssumeLocalFile
Definition qurl.h:175
QString scheme() const
Returns the scheme of the URL.
Definition qurl.cpp:1991
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2831
The QVideoFrameFormat class specifies the stream format of a video presentation surface.
The QVideoFrame class represents a frame of video data.
Definition qvideoframe.h:27
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QRhiSwapChain::Format qGetRequiredSwapChainFormat(const QVideoFrameFormat &format)
QUrl qMediaFromUserInput(QUrl url)
QSize qRotatedFrameSize(QSize size, int rotation)
bool qIsAutoHdrEnabled()
QT_BEGIN_NAMESPACE Fraction qRealToFraction(qreal value)
QSize qCalculateFrameSize(QSize resolution, Fraction par)
bool qShouldUpdateSwapChainFormat(QRhiSwapChain *swapChain, QRhiSwapChain::Format requiredSwapChainFormat)
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum format
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
double qreal
Definition qtypes.h:187
QUrl url("example.com")
[constructor-url-reference]
QDate d1(1995, 5, 17)
[0]
QDate d2(1995, 5, 20)
QFrame frame
[0]