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
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
8EvrVideoWindowControl::EvrVideoWindowControl(QVideoSink *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
24EvrVideoWindowControl::~EvrVideoWindowControl()
25{
26 clear();
27}
28
29bool EvrVideoWindowControl::setEvr(IUnknown *evr)
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;
47 applyImageControls();
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
67void EvrVideoWindowControl::setWinId(WId id)
68{
69 m_windowId = id;
70
71 if (m_displayControl)
72 m_displayControl->SetVideoWindow(HWND(m_windowId));
73}
74
75void EvrVideoWindowControl::setDisplayRect(const QRect &rect)
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
108void EvrVideoWindowControl::setFullScreen(bool fullScreen)
109{
110 if (m_fullScreen == fullScreen)
111 return;
112}
113
114void EvrVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode)
115{
116 m_aspectRatioMode = mode;
117
118 if (m_displayControl) {
119 switch (mode) {
120 case Qt::IgnoreAspectRatio:
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;
124 case Qt::KeepAspectRatio:
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;
128 case Qt::KeepAspectRatioByExpanding:
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
139void EvrVideoWindowControl::setBrightness(float brightness)
140{
141 if (m_brightness == brightness)
142 return;
143
144 m_brightness = brightness;
145
146 m_dirtyValues |= DXVA2_ProcAmp_Brightness;
147
148 applyImageControls();
149}
150
151void EvrVideoWindowControl::setContrast(float contrast)
152{
153 if (m_contrast == contrast)
154 return;
155
156 m_contrast = contrast;
157
158 m_dirtyValues |= DXVA2_ProcAmp_Contrast;
159
160 applyImageControls();
161}
162
163void EvrVideoWindowControl::setHue(float hue)
164{
165 if (m_hue == hue)
166 return;
167
168 m_hue = hue;
169
170 m_dirtyValues |= DXVA2_ProcAmp_Hue;
171
172 applyImageControls();
173}
174
175void EvrVideoWindowControl::setSaturation(float saturation)
176{
177 if (m_saturation == saturation)
178 return;
179
180 m_saturation = saturation;
181
182 m_dirtyValues |= DXVA2_ProcAmp_Saturation;
183
184 applyImageControls();
185}
186
187void EvrVideoWindowControl::applyImageControls()
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
226QT_END_NAMESPACE
227
228#include "moc_evrvideowindowcontrol_p.cpp"
QObject * parent
Definition qobject.h:73
The QVideoSink class represents a generic sink for video data.
Definition qvideosink.h:22
Combined button and popup list for selecting options.