43 |
43 |
44 #include "directshowglobal.h" |
44 #include "directshowglobal.h" |
45 |
45 |
46 Vmr9VideoWindowControl::Vmr9VideoWindowControl(QObject *parent) |
46 Vmr9VideoWindowControl::Vmr9VideoWindowControl(QObject *parent) |
47 : QVideoWindowControl(parent) |
47 : QVideoWindowControl(parent) |
48 , m_filter(com_new<IBaseFilter>(CLSID_VideoMixingRenderer9)) |
48 , m_filter(com_new<IBaseFilter>(CLSID_VideoMixingRenderer9, IID_IBaseFilter)) |
49 , m_windowId(0) |
49 , m_windowId(0) |
50 , m_dirtyValues(0) |
50 , m_dirtyValues(0) |
|
51 , m_aspectRatioMode(Qt::KeepAspectRatio) |
51 , m_brightness(0) |
52 , m_brightness(0) |
52 , m_contrast(0) |
53 , m_contrast(0) |
53 , m_hue(0) |
54 , m_hue(0) |
54 , m_saturation(0) |
55 , m_saturation(0) |
55 , m_fullScreen(false) |
56 , m_fullScreen(false) |
56 { |
57 { |
57 if (IVMRFilterConfig9 *config = com_cast<IVMRFilterConfig9>(m_filter)) { |
58 if (IVMRFilterConfig9 *config = com_cast<IVMRFilterConfig9>(m_filter, IID_IVMRFilterConfig9)) { |
58 config->SetRenderingMode(VMR9Mode_Windowless); |
59 config->SetRenderingMode(VMR9Mode_Windowless); |
59 config->SetNumberOfStreams(1); |
60 config->SetNumberOfStreams(1); |
|
61 config->SetRenderingPrefs(RenderPrefs9_DoNotRenderBorder); |
60 config->Release(); |
62 config->Release(); |
61 } |
63 } |
62 } |
64 } |
63 |
65 |
64 Vmr9VideoWindowControl::~Vmr9VideoWindowControl() |
66 Vmr9VideoWindowControl::~Vmr9VideoWindowControl() |
76 |
78 |
77 void Vmr9VideoWindowControl::setWinId(WId id) |
79 void Vmr9VideoWindowControl::setWinId(WId id) |
78 { |
80 { |
79 m_windowId = id; |
81 m_windowId = id; |
80 |
82 |
81 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
83 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( |
|
84 m_filter, IID_IVMRWindowlessControl9)) { |
82 control->SetVideoClippingWindow(m_windowId); |
85 control->SetVideoClippingWindow(m_windowId); |
83 control->Release(); |
86 control->Release(); |
84 } |
87 } |
85 } |
88 } |
86 |
89 |
87 QRect Vmr9VideoWindowControl::displayRect() const |
90 QRect Vmr9VideoWindowControl::displayRect() const |
88 { |
91 { |
89 QRect rect; |
92 return m_displayRect; |
90 |
|
91 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
|
92 RECT sourceRect; |
|
93 RECT displayRect; |
|
94 |
|
95 if (control->GetVideoPosition(&sourceRect, &displayRect) == S_OK) { |
|
96 rect = QRect( |
|
97 displayRect.left, |
|
98 displayRect.bottom, |
|
99 displayRect.right - displayRect.left, |
|
100 displayRect.bottom - displayRect.top); |
|
101 } |
|
102 control->Release(); |
|
103 } |
|
104 return rect; |
|
105 } |
93 } |
106 |
94 |
107 void Vmr9VideoWindowControl::setDisplayRect(const QRect &rect) |
95 void Vmr9VideoWindowControl::setDisplayRect(const QRect &rect) |
108 { |
96 { |
109 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
97 m_displayRect = rect; |
|
98 |
|
99 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( |
|
100 m_filter, IID_IVMRWindowlessControl9)) { |
110 RECT sourceRect = { 0, 0, 0, 0 }; |
101 RECT sourceRect = { 0, 0, 0, 0 }; |
111 RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() }; |
102 RECT displayRect = { rect.left(), rect.top(), rect.right(), rect.bottom() }; |
112 |
103 |
113 control->GetNativeVideoSize(&sourceRect.right, &sourceRect.bottom, 0, 0); |
104 control->GetNativeVideoSize(&sourceRect.right, &sourceRect.bottom, 0, 0); |
|
105 |
|
106 if (m_aspectRatioMode == Qt::KeepAspectRatioByExpanding) { |
|
107 QSize clippedSize = rect.size(); |
|
108 clippedSize.scale(sourceRect.right, sourceRect.bottom, Qt::KeepAspectRatio); |
|
109 |
|
110 sourceRect.left = (sourceRect.right - clippedSize.width()) / 2; |
|
111 sourceRect.top = (sourceRect.bottom - clippedSize.height()) / 2; |
|
112 sourceRect.right = sourceRect.left + clippedSize.width(); |
|
113 sourceRect.bottom = sourceRect.top + clippedSize.height(); |
|
114 } |
|
115 |
114 control->SetVideoPosition(&sourceRect, &displayRect); |
116 control->SetVideoPosition(&sourceRect, &displayRect); |
115 control->Release(); |
117 control->Release(); |
116 } |
118 } |
117 } |
119 } |
118 |
120 |
126 emit fullScreenChanged(m_fullScreen = fullScreen); |
128 emit fullScreenChanged(m_fullScreen = fullScreen); |
127 } |
129 } |
128 |
130 |
129 void Vmr9VideoWindowControl::repaint() |
131 void Vmr9VideoWindowControl::repaint() |
130 { |
132 { |
131 |
|
132 if (QWidget *widget = QWidget::find(m_windowId)) { |
133 if (QWidget *widget = QWidget::find(m_windowId)) { |
133 HDC dc = widget->getDC(); |
134 HDC dc = widget->getDC(); |
134 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
135 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( |
|
136 m_filter, IID_IVMRWindowlessControl9)) { |
135 control->RepaintVideo(m_windowId, dc); |
137 control->RepaintVideo(m_windowId, dc); |
136 control->Release(); |
138 control->Release(); |
137 } |
139 } |
138 widget->releaseDC(dc); |
140 widget->releaseDC(dc); |
139 } |
141 } |
141 |
143 |
142 QSize Vmr9VideoWindowControl::nativeSize() const |
144 QSize Vmr9VideoWindowControl::nativeSize() const |
143 { |
145 { |
144 QSize size; |
146 QSize size; |
145 |
147 |
146 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
148 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( |
|
149 m_filter, IID_IVMRWindowlessControl9)) { |
147 LONG width; |
150 LONG width; |
148 LONG height; |
151 LONG height; |
149 |
152 |
150 if (control->GetNativeVideoSize(&width, &height, 0, 0) == S_OK) |
153 if (control->GetNativeVideoSize(&width, &height, 0, 0) == S_OK) |
151 size = QSize(width, height); |
154 size = QSize(width, height); |
152 control->Release(); |
155 control->Release(); |
153 } |
156 } |
154 return size; |
157 return size; |
155 } |
158 } |
156 |
159 |
157 QVideoWidget::AspectRatioMode Vmr9VideoWindowControl::aspectRatioMode() const |
160 Qt::AspectRatioMode Vmr9VideoWindowControl::aspectRatioMode() const |
158 { |
161 { |
159 QVideoWidget::AspectRatioMode mode = QVideoWidget::KeepAspectRatio; |
162 return m_aspectRatioMode; |
160 |
163 } |
161 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
164 |
162 DWORD arMode; |
165 void Vmr9VideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) |
163 |
166 { |
164 if (control->GetAspectRatioMode(&arMode) == S_OK && arMode == VMR9ARMode_None) |
167 m_aspectRatioMode = mode; |
165 mode = QVideoWidget::IgnoreAspectRatio; |
168 |
166 control->Release(); |
169 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>( |
167 } |
170 m_filter, IID_IVMRWindowlessControl9)) { |
168 return mode; |
|
169 } |
|
170 |
|
171 void Vmr9VideoWindowControl::setAspectRatioMode(QVideoWidget::AspectRatioMode mode) |
|
172 { |
|
173 if (IVMRWindowlessControl9 *control = com_cast<IVMRWindowlessControl9>(m_filter)) { |
|
174 switch (mode) { |
171 switch (mode) { |
175 case QVideoWidget::IgnoreAspectRatio: |
172 case Qt::IgnoreAspectRatio: |
176 control->SetAspectRatioMode(VMR9ARMode_None); |
173 control->SetAspectRatioMode(VMR9ARMode_None); |
177 break; |
174 break; |
178 case QVideoWidget::KeepAspectRatio: |
175 case Qt::KeepAspectRatio: |
179 control->SetAspectRatioMode(VMR9ARMode_LetterBox); |
176 control->SetAspectRatioMode(VMR9ARMode_LetterBox); |
|
177 break; |
|
178 case Qt::KeepAspectRatioByExpanding: |
|
179 control->SetAspectRatioMode(VMR9ARMode_LetterBox); |
|
180 setDisplayRect(m_displayRect); |
180 break; |
181 break; |
181 default: |
182 default: |
182 break; |
183 break; |
183 } |
184 } |
184 control->Release(); |
185 control->Release(); |
249 emit saturationChanged(saturation); |
250 emit saturationChanged(saturation); |
250 } |
251 } |
251 |
252 |
252 void Vmr9VideoWindowControl::setProcAmpValues() |
253 void Vmr9VideoWindowControl::setProcAmpValues() |
253 { |
254 { |
254 if (IVMRMixerControl9 *control = com_cast<IVMRMixerControl9>(m_filter)) { |
255 if (IVMRMixerControl9 *control = com_cast<IVMRMixerControl9>(m_filter, IID_IVMRMixerControl9)) { |
255 VMR9ProcAmpControl procAmp; |
256 VMR9ProcAmpControl procAmp; |
256 procAmp.dwSize = sizeof(VMR9ProcAmpControl); |
257 procAmp.dwSize = sizeof(VMR9ProcAmpControl); |
257 procAmp.dwFlags = m_dirtyValues; |
258 procAmp.dwFlags = m_dirtyValues; |
258 |
259 |
259 if (m_dirtyValues & ProcAmpControl9_Brightness) { |
260 if (m_dirtyValues & ProcAmpControl9_Brightness) { |