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
evrvideowindowcontrol.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
7
9 : QPlatformVideoSink(parent)
10 , m_windowId(0)
11 , m_windowColor(RGB(0, 0, 0))
12 , m_dirtyValues(0)
13 , m_aspectRatioMode(Qt::KeepAspectRatio)
14 , m_brightness(0)
15 , m_contrast(0)
16 , m_hue(0)
17 , m_saturation(0)
18 , m_fullScreen(false)
19 , m_displayControl(0)
20 , m_processor(0)
21{
22}
23
28
30{
31 clear();
32
33 if (!evr)
34 return true;
35
36 IMFGetService *service = NULL;
37
38 if (SUCCEEDED(evr->QueryInterface(IID_PPV_ARGS(&service)))
39 && SUCCEEDED(service->GetService(MR_VIDEO_RENDER_SERVICE, IID_PPV_ARGS(&m_displayControl)))) {
40
41 service->GetService(MR_VIDEO_MIXER_SERVICE, IID_PPV_ARGS(&m_processor));
42
43 setWinId(m_windowId);
44 setDisplayRect(m_displayRect);
45 setAspectRatioMode(m_aspectRatioMode);
46 m_dirtyValues = DXVA2_ProcAmp_Brightness | DXVA2_ProcAmp_Contrast | DXVA2_ProcAmp_Hue | DXVA2_ProcAmp_Saturation;
48 }
49
50 if (service)
51 service->Release();
52
53 return m_displayControl != NULL;
54}
55
56void EvrVideoWindowControl::clear()
57{
58 if (m_displayControl)
59 m_displayControl->Release();
60 m_displayControl = NULL;
61
62 if (m_processor)
63 m_processor->Release();
64 m_processor = NULL;
65}
66
68{
69 m_windowId = id;
70
71 if (m_displayControl)
72 m_displayControl->SetVideoWindow(HWND(m_windowId));
73}
74
76{
77 m_displayRect = rect;
78
79 if (m_displayControl) {
80 RECT displayRect = { rect.left(), rect.top(), rect.right() + 1, rect.bottom() + 1 };
81 QSize sourceSize = nativeSize();
82
83 RECT sourceRect = { 0, 0, sourceSize.width(), sourceSize.height() };
84
85 if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) {
86 QSize clippedSize = rect.size();
87 clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio);
88
89 sourceRect.left = (sourceRect.right - clippedSize.width()) / 2;
90 sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2;
91 sourceRect.right = sourceRect.left + clippedSize.width();
92 sourceRect.bottom = sourceRect.top + clippedSize.height();
93 }
94
95 if (sourceSize.width() > 0 && sourceSize.height() > 0) {
96 MFVideoNormalizedRect sourceNormRect;
97 sourceNormRect.left = float(sourceRect.left) / float(sourceRect.right);
98 sourceNormRect.top = float(sourceRect.top) / float(sourceRect.bottom);
99 sourceNormRect.right = float(sourceRect.right) / float(sourceRect.right);
100 sourceNormRect.bottom = float(sourceRect.bottom) / float(sourceRect.bottom);
101 m_displayControl->SetVideoPosition(&sourceNormRect, &displayRect);
102 } else {
103 m_displayControl->SetVideoPosition(NULL, &displayRect);
104 }
105 }
106}
107
109{
110 if (m_fullScreen == fullScreen)
111 return;
112}
113
115{
116 m_aspectRatioMode = mode;
117
118 if (m_displayControl) {
119 switch (mode) {
121 //comment from MSDN: Do not maintain the aspect ratio of the video. Stretch the video to fit the output rectangle.
122 m_displayControl->SetAspectRatioMode(MFVideoARMode_None);
123 break;
125 //comment from MSDN: Preserve the aspect ratio of the video by letterboxing or within the output rectangle.
126 m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
127 break;
129 //for this mode, more adjustment will be done in setDisplayRect
130 m_displayControl->SetAspectRatioMode(MFVideoARMode_PreservePicture);
131 break;
132 default:
133 break;
134 }
135 setDisplayRect(m_displayRect);
136 }
137}
138
140{
141 if (m_brightness == brightness)
142 return;
143
144 m_brightness = brightness;
145
146 m_dirtyValues |= DXVA2_ProcAmp_Brightness;
147
149}
150
152{
153 if (m_contrast == contrast)
154 return;
155
156 m_contrast = contrast;
157
158 m_dirtyValues |= DXVA2_ProcAmp_Contrast;
159
161}
162
164{
165 if (m_hue == hue)
166 return;
167
168 m_hue = hue;
169
170 m_dirtyValues |= DXVA2_ProcAmp_Hue;
171
173}
174
176{
177 if (m_saturation == saturation)
178 return;
179
180 m_saturation = saturation;
181
182 m_dirtyValues |= DXVA2_ProcAmp_Saturation;
183
185}
186
188{
189 if (m_processor) {
190 DXVA2_ProcAmpValues values;
191 if (m_dirtyValues & DXVA2_ProcAmp_Brightness) {
192 values.Brightness = scaleProcAmpValue(DXVA2_ProcAmp_Brightness, m_brightness);
193 }
194 if (m_dirtyValues & DXVA2_ProcAmp_Contrast) {
195 values.Contrast = scaleProcAmpValue(DXVA2_ProcAmp_Contrast, m_contrast);
196 }
197 if (m_dirtyValues & DXVA2_ProcAmp_Hue) {
198 values.Hue = scaleProcAmpValue(DXVA2_ProcAmp_Hue, m_hue);
199 }
200 if (m_dirtyValues & DXVA2_ProcAmp_Saturation) {
201 values.Saturation = scaleProcAmpValue(DXVA2_ProcAmp_Saturation, m_saturation);
202 }
203
204 if (SUCCEEDED(m_processor->SetProcAmpValues(m_dirtyValues, &values))) {
205 m_dirtyValues = 0;
206 }
207 }
208}
209
210DXVA2_Fixed32 EvrVideoWindowControl::scaleProcAmpValue(DWORD prop, float value) const
211{
212 float scaledValue = 0.0;
213
214 DXVA2_ValueRange range;
215 if (SUCCEEDED(m_processor->GetProcAmpRange(prop, &range))) {
216 scaledValue = DXVA2FixedToFloat(range.DefaultValue);
217 if (value > 0)
218 scaledValue += float(value) * (DXVA2FixedToFloat(range.MaxValue) - DXVA2FixedToFloat(range.DefaultValue));
219 else if (value < 0)
220 scaledValue -= float(value) * (DXVA2FixedToFloat(range.MinValue) - DXVA2FixedToFloat(range.DefaultValue));
221 }
222
223 return DXVA2FloatToFixed(scaledValue);
224}
225
227
228#include "moc_evrvideowindowcontrol_p.cpp"
void setWinId(WId id) override
void setDisplayRect(const QRect &rect) override
void setHue(float hue) override
void setContrast(float contrast) override
void setFullScreen(bool fullScreen) override
EvrVideoWindowControl(QVideoSink *parent=0)
void setSaturation(float saturation) override
void setBrightness(float brightness) override
void setAspectRatioMode(Qt::AspectRatioMode mode) override
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
\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
void scale(int w, int h, Qt::AspectRatioMode mode) noexcept
Scales the size to a rectangle with the given width and height, according to the specified mode:
Definition qsize.h:145
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
rect
[4]
Combined button and popup list for selecting options.
Definition qcompare.h:63
AspectRatioMode
@ KeepAspectRatioByExpanding
@ KeepAspectRatio
@ IgnoreAspectRatio
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLsizei GLsizei GLint * values
[15]
GLenum mode
GLenum GLuint id
[7]
GLsizei range