quartz/vmr9: Don't expose IVMRFilterConfig from the VMR9.
[wine.git] / dlls / quartz / tests / vmr9.c
blobb682aa10adff876f16960365d553c21b788e6f47
1 /*
2 * Video Mixing Renderer 9 unit tests
4 * Copyright 2019 Zebediah Figura
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdint.h>
22 #define COBJMACROS
23 #include "ocidl.h"
24 #include "olectl.h"
25 #include "initguid.h"
26 #include "dshow.h"
27 #include "qedit.h"
28 #include "d3d9.h"
29 #include "vmr9.h"
30 #include "wmcodecdsp.h"
31 #include "wine/heap.h"
32 #include "wine/strmbase.h"
33 #include "wine/test.h"
35 static IBaseFilter *create_vmr9(DWORD mode)
37 IBaseFilter *filter = NULL;
38 IVMRFilterConfig9 *config;
39 HRESULT hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
40 &IID_IBaseFilter, (void **)&filter);
41 ok(hr == S_OK, "Got hr %#x.\n", hr);
42 if (mode)
44 hr = IBaseFilter_QueryInterface(filter, &IID_IVMRFilterConfig9, (void **)&config);
45 ok(hr == S_OK, "Got hr %#x.\n", hr);
46 hr = IVMRFilterConfig9_SetRenderingMode(config, mode);
47 ok(hr == S_OK || broken(hr == E_FAIL), "Got hr %#x.\n", hr);
48 IVMRFilterConfig9_Release(config);
50 return filter;
53 static HRESULT set_mixing_mode(IBaseFilter *filter, DWORD count)
55 IVMRFilterConfig9 *config;
56 HRESULT hr;
58 hr = IBaseFilter_QueryInterface(filter, &IID_IVMRFilterConfig9, (void **)&config);
59 ok(hr == S_OK, "Got hr %#x.\n", hr);
61 hr = IVMRFilterConfig9_SetNumberOfStreams(config, count);
62 ok(hr == S_OK, "Got hr %#x.\n", hr);
64 IVMRFilterConfig9_Release(config);
65 return hr;
68 static inline BOOL compare_media_types(const AM_MEDIA_TYPE *a, const AM_MEDIA_TYPE *b)
70 return !memcmp(a, b, offsetof(AM_MEDIA_TYPE, pbFormat))
71 && !memcmp(a->pbFormat, b->pbFormat, a->cbFormat);
74 static BOOL compare_double(double f, double g, unsigned int ulps)
76 uint64_t x = *(ULONGLONG *)&f;
77 uint64_t y = *(ULONGLONG *)&g;
79 if (f < 0)
80 x = ~x + 1;
81 else
82 x |= ((ULONGLONG)1)<<63;
83 if (g < 0)
84 y = ~y + 1;
85 else
86 y |= ((ULONGLONG)1)<<63;
88 return (x>y ? x-y : y-x) <= ulps;
91 static IFilterGraph2 *create_graph(void)
93 IFilterGraph2 *ret;
94 HRESULT hr;
95 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterGraph2, (void **)&ret);
96 ok(hr == S_OK, "Failed to create FilterGraph: %#x\n", hr);
97 return ret;
100 static ULONG get_refcount(void *iface)
102 IUnknown *unknown = iface;
103 IUnknown_AddRef(unknown);
104 return IUnknown_Release(unknown);
107 static void test_filter_config(void)
109 IVMRFilterConfig9 *config;
110 DWORD count, mode;
111 HRESULT hr;
112 ULONG ref;
114 hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
115 &IID_IVMRFilterConfig9, (void **)&config);
116 ok(hr == S_OK, "Got hr %#x.\n", hr);
118 hr = IVMRFilterConfig9_GetRenderingMode(config, &mode);
119 ok(hr == S_OK, "Got hr %#x.\n", hr);
120 ok(mode == VMRMode_Windowed, "Got mode %#x.\n", mode);
122 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Windowed);
123 ok(hr == S_OK || broken(hr == E_FAIL), "Got hr %#x.\n", hr);
125 hr = IVMRFilterConfig9_GetRenderingMode(config, &mode);
126 ok(hr == S_OK, "Got hr %#x.\n", hr);
127 ok(mode == VMR9Mode_Windowed, "Got mode %#x.\n", mode);
129 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Windowed);
130 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
132 ref = IVMRFilterConfig9_Release(config);
133 ok(!ref, "Got outstanding refcount %d.\n", ref);
135 hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
136 &IID_IVMRFilterConfig9, (void **)&config);
137 ok(hr == S_OK, "Got hr %#x.\n", hr);
139 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Windowless);
140 ok(hr == S_OK || broken(hr == E_FAIL), "Got hr %#x.\n", hr);
142 hr = IVMRFilterConfig9_GetRenderingMode(config, &mode);
143 ok(hr == S_OK, "Got hr %#x.\n", hr);
144 ok(mode == VMR9Mode_Windowless, "Got mode %#x.\n", mode);
146 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Windowed);
147 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
149 ref = IVMRFilterConfig9_Release(config);
150 ok(!ref, "Got outstanding refcount %d.\n", ref);
152 hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
153 &IID_IVMRFilterConfig9, (void **)&config);
154 ok(hr == S_OK, "Got hr %#x.\n", hr);
156 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Renderless);
157 ok(hr == S_OK, "Got hr %#x.\n", hr);
159 hr = IVMRFilterConfig9_GetRenderingMode(config, &mode);
160 ok(hr == S_OK, "Got hr %#x.\n", hr);
161 ok(mode == VMR9Mode_Renderless, "Got mode %#x.\n", mode);
163 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Windowless);
164 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
166 ref = IVMRFilterConfig9_Release(config);
167 ok(!ref, "Got outstanding refcount %d.\n", ref);
169 hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER,
170 &IID_IVMRFilterConfig9, (void **)&config);
171 ok(hr == S_OK, "Got hr %#x.\n", hr);
173 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &count);
174 ok(hr == VFW_E_VMR_NOT_IN_MIXER_MODE, "Got hr %#x.\n", hr);
176 hr = IVMRFilterConfig9_SetNumberOfStreams(config, 3);
177 ok(hr == S_OK, "Got hr %#x.\n", hr);
179 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &count);
180 ok(hr == S_OK, "Got hr %#x.\n", hr);
181 ok(count == 3, "Got count %u.\n", count);
183 hr = IVMRFilterConfig9_GetRenderingMode(config, &mode);
184 ok(hr == S_OK, "Got hr %#x.\n", hr);
185 ok(mode == VMR9Mode_Windowed, "Got mode %#x.\n", mode);
187 /* Despite MSDN, you can still change the rendering mode after setting the
188 * stream count. */
189 hr = IVMRFilterConfig9_SetRenderingMode(config, VMR9Mode_Windowless);
190 ok(hr == S_OK || broken(hr == E_FAIL), "Got hr %#x.\n", hr);
192 hr = IVMRFilterConfig9_GetRenderingMode(config, &mode);
193 ok(hr == S_OK, "Got hr %#x.\n", hr);
194 ok(mode == VMR9Mode_Windowless, "Got mode %#x.\n", mode);
196 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &count);
197 ok(hr == S_OK, "Got hr %#x.\n", hr);
198 ok(count == 3, "Got count %u.\n", count);
200 ref = IVMRFilterConfig9_Release(config);
201 ok(!ref, "Got outstanding refcount %d.\n", ref);
204 #define check_interface_broken(a, b, c) check_interface_(__LINE__, a, b, c, TRUE)
205 #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c, FALSE)
206 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
208 HRESULT hr, expected_hr, broken_hr;
209 IUnknown *unknown = iface, *out;
211 if (supported)
213 expected_hr = S_OK;
214 broken_hr = E_NOINTERFACE;
216 else
218 expected_hr = E_NOINTERFACE;
219 broken_hr = S_OK;
222 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
223 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
224 "Got hr %#x, expected %#x.\n", hr, expected_hr);
225 if (SUCCEEDED(hr))
226 IUnknown_Release(out);
227 return hr;
230 static void test_common_interfaces(IBaseFilter *filter)
232 IPin *pin;
234 check_interface(filter, &IID_IAMCertifiedOutputProtection, TRUE);
235 check_interface(filter, &IID_IAMFilterMiscFlags, TRUE);
236 check_interface(filter, &IID_IBaseFilter, TRUE);
237 todo_wine check_interface(filter, &IID_IKsPropertySet, TRUE);
238 check_interface(filter, &IID_IMediaFilter, TRUE);
239 check_interface(filter, &IID_IMediaPosition, TRUE);
240 check_interface(filter, &IID_IMediaSeeking, TRUE);
241 check_interface(filter, &IID_IPersist, TRUE);
242 check_interface(filter, &IID_IQualityControl, TRUE);
243 todo_wine check_interface(filter, &IID_IQualProp, TRUE);
244 check_interface(filter, &IID_IUnknown, TRUE);
245 todo_wine check_interface(filter, &IID_IVMRAspectRatioControl9, TRUE);
246 todo_wine check_interface(filter, &IID_IVMRDeinterlaceControl9, TRUE);
247 check_interface(filter, &IID_IVMRFilterConfig9, TRUE);
248 check_interface(filter, &IID_IVMRMixerBitmap9, TRUE);
250 check_interface(filter, &IID_IBasicAudio, FALSE);
251 check_interface(filter, &IID_IDirectDrawVideo, FALSE);
252 check_interface(filter, &IID_IPersistPropertyBag, FALSE);
253 check_interface(filter, &IID_IPin, FALSE);
254 check_interface(filter, &IID_IReferenceClock, FALSE);
255 check_interface(filter, &IID_IVMRAspectRatioControl, FALSE);
256 check_interface(filter, &IID_IVMRDeinterlaceControl, FALSE);
257 check_interface(filter, &IID_IVMRFilterConfig, FALSE);
258 check_interface(filter, &IID_IVMRMixerBitmap, FALSE);
259 check_interface(filter, &IID_IVMRMixerControl, FALSE);
260 todo_wine check_interface(filter, &IID_IVMRMonitorConfig, FALSE);
261 check_interface(filter, &IID_IVMRSurfaceAllocatorNotify, FALSE);
262 check_interface(filter, &IID_IVMRWindowlessControl, FALSE);
264 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
266 check_interface(pin, &IID_IMemInputPin, TRUE);
267 check_interface(pin, &IID_IOverlay, TRUE);
268 check_interface(pin, &IID_IPin, TRUE);
269 todo_wine check_interface(pin, &IID_IQualityControl, TRUE);
270 check_interface(pin, &IID_IUnknown, TRUE);
272 check_interface(pin, &IID_IKsPropertySet, FALSE);
273 check_interface(pin, &IID_IMediaPosition, FALSE);
274 check_interface(pin, &IID_IMediaSeeking, FALSE);
276 IPin_Release(pin);
279 static void test_interfaces(void)
281 IBaseFilter *filter = create_vmr9(0);
282 ULONG ref;
284 test_common_interfaces(filter);
286 check_interface(filter, &IID_IBasicVideo, TRUE);
287 todo_wine check_interface(filter, &IID_IBasicVideo2, TRUE);
288 check_interface(filter, &IID_IVideoWindow, TRUE);
289 /* IVMRMonitorConfig9 may not be available if the d3d9 device has
290 * insufficient support. */
291 check_interface_broken(filter, &IID_IVMRMonitorConfig9, TRUE);
293 check_interface(filter, &IID_IVMRMixerControl9, FALSE);
294 check_interface(filter, &IID_IVMRSurfaceAllocatorNotify9, FALSE);
295 check_interface(filter, &IID_IVMRWindowlessControl9, FALSE);
297 ref = IBaseFilter_Release(filter);
298 ok(!ref, "Got outstanding refcount %d.\n", ref);
300 filter = create_vmr9(VMR9Mode_Windowless);
301 test_common_interfaces(filter);
303 /* IVMRMonitorConfig9 may not be available if the d3d9 device has
304 * insufficient support. */
305 check_interface_broken(filter, &IID_IVMRMonitorConfig9, TRUE);
306 check_interface(filter, &IID_IVMRWindowlessControl9, TRUE);
308 todo_wine check_interface(filter, &IID_IBasicVideo, FALSE);
309 check_interface(filter, &IID_IBasicVideo2, FALSE);
310 todo_wine check_interface(filter, &IID_IVideoWindow, FALSE);
311 check_interface(filter, &IID_IVMRMixerControl9, FALSE);
312 check_interface(filter, &IID_IVMRSurfaceAllocatorNotify9, FALSE);
314 ref = IBaseFilter_Release(filter);
315 ok(!ref, "Got outstanding refcount %d.\n", ref);
317 filter = create_vmr9(VMR9Mode_Renderless);
318 test_common_interfaces(filter);
320 check_interface(filter, &IID_IVMRSurfaceAllocatorNotify9, TRUE);
322 todo_wine check_interface(filter, &IID_IBasicVideo, FALSE);
323 check_interface(filter, &IID_IBasicVideo2, FALSE);
324 todo_wine check_interface(filter, &IID_IVideoWindow, FALSE);
325 check_interface(filter, &IID_IVMRMonitorConfig9, FALSE);
326 check_interface(filter, &IID_IVMRWindowlessControl9, FALSE);
328 ref = IBaseFilter_Release(filter);
329 ok(!ref, "Got outstanding refcount %d.\n", ref);
331 filter = create_vmr9(VMR9Mode_Windowed);
332 set_mixing_mode(filter, 1);
333 test_common_interfaces(filter);
335 check_interface(filter, &IID_IBasicVideo, TRUE);
336 todo_wine check_interface(filter, &IID_IBasicVideo2, TRUE);
337 check_interface(filter, &IID_IVideoWindow, TRUE);
338 check_interface(filter, &IID_IVMRMixerControl9, TRUE);
339 /* IVMRMonitorConfig9 may not be available if the d3d9 device has
340 * insufficient support. */
341 check_interface_broken(filter, &IID_IVMRMonitorConfig9, TRUE);
343 check_interface(filter, &IID_IVMRSurfaceAllocatorNotify9, FALSE);
344 check_interface(filter, &IID_IVMRWindowlessControl9, FALSE);
346 ref = IBaseFilter_Release(filter);
347 ok(!ref, "Got outstanding refcount %d.\n", ref);
350 static const GUID test_iid = {0x33333333};
351 static LONG outer_ref = 1;
353 static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
355 if (IsEqualGUID(iid, &IID_IUnknown)
356 || IsEqualGUID(iid, &IID_IBaseFilter)
357 || IsEqualGUID(iid, &test_iid))
359 *out = (IUnknown *)0xdeadbeef;
360 return S_OK;
362 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
363 return E_NOINTERFACE;
366 static ULONG WINAPI outer_AddRef(IUnknown *iface)
368 return InterlockedIncrement(&outer_ref);
371 static ULONG WINAPI outer_Release(IUnknown *iface)
373 return InterlockedDecrement(&outer_ref);
376 static const IUnknownVtbl outer_vtbl =
378 outer_QueryInterface,
379 outer_AddRef,
380 outer_Release,
383 static IUnknown test_outer = {&outer_vtbl};
385 static void test_aggregation(void)
387 IBaseFilter *filter, *filter2;
388 IUnknown *unk, *unk2;
389 HRESULT hr;
390 ULONG ref;
392 filter = (IBaseFilter *)0xdeadbeef;
393 hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, &test_outer, CLSCTX_INPROC_SERVER,
394 &IID_IBaseFilter, (void **)&filter);
395 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
396 ok(!filter, "Got interface %p.\n", filter);
398 hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, &test_outer, CLSCTX_INPROC_SERVER,
399 &IID_IUnknown, (void **)&unk);
400 ok(hr == S_OK, "Got hr %#x.\n", hr);
401 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
402 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
403 ref = get_refcount(unk);
404 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
406 ref = IUnknown_AddRef(unk);
407 ok(ref == 2, "Got unexpected refcount %d.\n", ref);
408 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
410 ref = IUnknown_Release(unk);
411 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
412 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
414 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
415 ok(hr == S_OK, "Got hr %#x.\n", hr);
416 ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
417 IUnknown_Release(unk2);
419 hr = IUnknown_QueryInterface(unk, &IID_IBaseFilter, (void **)&filter);
420 ok(hr == S_OK, "Got hr %#x.\n", hr);
422 hr = IBaseFilter_QueryInterface(filter, &IID_IUnknown, (void **)&unk2);
423 ok(hr == S_OK, "Got hr %#x.\n", hr);
424 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
426 hr = IBaseFilter_QueryInterface(filter, &IID_IBaseFilter, (void **)&filter2);
427 ok(hr == S_OK, "Got hr %#x.\n", hr);
428 ok(filter2 == (IBaseFilter *)0xdeadbeef, "Got unexpected IBaseFilter %p.\n", filter2);
430 hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
431 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
432 ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
434 hr = IBaseFilter_QueryInterface(filter, &test_iid, (void **)&unk2);
435 ok(hr == S_OK, "Got hr %#x.\n", hr);
436 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
438 IBaseFilter_Release(filter);
439 ref = IUnknown_Release(unk);
440 ok(!ref, "Got unexpected refcount %d.\n", ref);
441 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
444 static void test_enum_pins(void)
446 IBaseFilter *filter = create_vmr9(0);
447 IEnumPins *enum1, *enum2;
448 ULONG count, ref;
449 IPin *pins[3];
450 HRESULT hr;
452 ref = get_refcount(filter);
453 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
455 hr = IBaseFilter_EnumPins(filter, NULL);
456 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
458 hr = IBaseFilter_EnumPins(filter, &enum1);
459 ok(hr == S_OK, "Got hr %#x.\n", hr);
460 ref = get_refcount(filter);
461 ok(ref == 2, "Got unexpected refcount %d.\n", ref);
462 ref = get_refcount(enum1);
463 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
465 hr = IEnumPins_Next(enum1, 1, NULL, NULL);
466 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
468 hr = IEnumPins_Next(enum1, 1, pins, NULL);
469 ok(hr == S_OK, "Got hr %#x.\n", hr);
470 ref = get_refcount(filter);
471 ok(ref == 3, "Got unexpected refcount %d.\n", ref);
472 ref = get_refcount(pins[0]);
473 ok(ref == 3, "Got unexpected refcount %d.\n", ref);
474 ref = get_refcount(enum1);
475 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
476 IPin_Release(pins[0]);
477 ref = get_refcount(filter);
478 ok(ref == 2, "Got unexpected refcount %d.\n", ref);
480 hr = IEnumPins_Next(enum1, 1, pins, NULL);
481 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
483 hr = IEnumPins_Reset(enum1);
484 ok(hr == S_OK, "Got hr %#x.\n", hr);
486 hr = IEnumPins_Next(enum1, 1, pins, &count);
487 ok(hr == S_OK, "Got hr %#x.\n", hr);
488 ok(count == 1, "Got count %u.\n", count);
489 IPin_Release(pins[0]);
491 hr = IEnumPins_Next(enum1, 1, pins, &count);
492 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
493 ok(!count, "Got count %u.\n", count);
495 hr = IEnumPins_Reset(enum1);
496 ok(hr == S_OK, "Got hr %#x.\n", hr);
498 hr = IEnumPins_Next(enum1, 2, pins, NULL);
499 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
501 hr = IEnumPins_Next(enum1, 2, pins, &count);
502 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
503 ok(count == 1, "Got count %u.\n", count);
504 IPin_Release(pins[0]);
506 hr = IEnumPins_Reset(enum1);
507 ok(hr == S_OK, "Got hr %#x.\n", hr);
509 hr = IEnumPins_Clone(enum1, &enum2);
510 ok(hr == S_OK, "Got hr %#x.\n", hr);
512 hr = IEnumPins_Skip(enum1, 2);
513 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
515 hr = IEnumPins_Skip(enum1, 1);
516 ok(hr == S_OK, "Got hr %#x.\n", hr);
518 hr = IEnumPins_Skip(enum1, 1);
519 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
521 hr = IEnumPins_Next(enum1, 1, pins, NULL);
522 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
524 hr = IEnumPins_Next(enum2, 1, pins, NULL);
525 ok(hr == S_OK, "Got hr %#x.\n", hr);
526 IPin_Release(pins[0]);
528 IEnumPins_Release(enum2);
530 set_mixing_mode(filter, 2);
532 hr = IEnumPins_Next(enum1, 1, pins, NULL);
533 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
535 hr = IEnumPins_Reset(enum1);
536 ok(hr == S_OK, "Got hr %#x.\n", hr);
538 hr = IEnumPins_Next(enum1, 1, pins, NULL);
539 ok(hr == S_OK, "Got hr %#x.\n", hr);
540 IPin_Release(pins[0]);
542 hr = IEnumPins_Next(enum1, 1, pins, NULL);
543 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
544 if (hr == S_OK) IPin_Release(pins[0]);
546 hr = IEnumPins_Next(enum1, 1, pins, NULL);
547 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
549 hr = IEnumPins_Reset(enum1);
550 ok(hr == S_OK, "Got hr %#x.\n", hr);
552 hr = IEnumPins_Next(enum1, 2, pins, &count);
553 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
554 todo_wine ok(count == 2, "Got count %u.\n", count);
555 IPin_Release(pins[0]);
556 if (count > 1) IPin_Release(pins[1]);
558 hr = IEnumPins_Reset(enum1);
559 ok(hr == S_OK, "Got hr %#x.\n", hr);
561 hr = IEnumPins_Next(enum1, 3, pins, &count);
562 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
563 todo_wine ok(count == 2, "Got count %u.\n", count);
564 IPin_Release(pins[0]);
565 if (count > 1) IPin_Release(pins[1]);
567 IEnumPins_Release(enum1);
568 ref = IBaseFilter_Release(filter);
569 ok(!ref, "Got outstanding refcount %d.\n", ref);
572 static void test_find_pin(void)
574 IBaseFilter *filter = create_vmr9(0);
575 IEnumPins *enum_pins;
576 IPin *pin, *pin2;
577 HRESULT hr;
578 ULONG ref;
580 IBaseFilter_EnumPins(filter, &enum_pins);
582 hr = IBaseFilter_FindPin(filter, L"input pin", &pin);
583 ok(hr == VFW_E_NOT_FOUND, "Got hr %#x.\n", hr);
585 hr = IBaseFilter_FindPin(filter, L"In", &pin);
586 ok(hr == VFW_E_NOT_FOUND, "Got hr %#x.\n", hr);
588 hr = IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
589 ok(hr == S_OK, "Got hr %#x.\n", hr);
590 hr = IEnumPins_Next(enum_pins, 1, &pin2, NULL);
591 ok(hr == S_OK, "Got hr %#x.\n", hr);
592 ok(pin == pin2, "Pins did not match.\n");
593 IPin_Release(pin);
594 IPin_Release(pin2);
596 hr = IBaseFilter_FindPin(filter, L"VMR Input1", &pin);
597 ok(hr == VFW_E_NOT_FOUND, "Got hr %#x.\n", hr);
599 set_mixing_mode(filter, 2);
601 IEnumPins_Reset(enum_pins);
603 hr = IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
604 ok(hr == S_OK, "Got hr %#x.\n", hr);
605 hr = IEnumPins_Next(enum_pins, 1, &pin2, NULL);
606 ok(hr == S_OK, "Got hr %#x.\n", hr);
607 ok(pin == pin2, "Pins did not match.\n");
608 IPin_Release(pin);
609 IPin_Release(pin2);
611 hr = IBaseFilter_FindPin(filter, L"VMR Input1", &pin);
612 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
613 if (hr == S_OK)
615 hr = IEnumPins_Next(enum_pins, 1, &pin2, NULL);
616 ok(hr == S_OK, "Got hr %#x.\n", hr);
617 ok(pin == pin2, "Pins did not match.\n");
618 IPin_Release(pin);
619 IPin_Release(pin2);
622 hr = IBaseFilter_FindPin(filter, L"VMR Input2", &pin);
623 ok(hr == VFW_E_NOT_FOUND, "Got hr %#x.\n", hr);
625 IEnumPins_Release(enum_pins);
626 ref = IBaseFilter_Release(filter);
627 ok(!ref, "Got outstanding refcount %d.\n", ref);
630 static void test_pin_info(void)
632 IBaseFilter *filter = create_vmr9(0);
633 PIN_DIRECTION dir;
634 ULONG count, ref;
635 PIN_INFO info;
636 HRESULT hr;
637 WCHAR *id;
638 IPin *pin;
640 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
641 hr = IPin_QueryPinInfo(pin, &info);
642 ok(info.pFilter == filter, "Expected filter %p, got %p.\n", filter, info.pFilter);
643 ok(info.dir == PINDIR_INPUT, "Got direction %d.\n", info.dir);
644 ok(!wcscmp(info.achName, L"VMR Input0"), "Got name %s.\n", wine_dbgstr_w(info.achName));
645 IBaseFilter_Release(info.pFilter);
647 hr = IPin_QueryDirection(pin, &dir);
648 ok(hr == S_OK, "Got hr %#x.\n", hr);
649 ok(dir == PINDIR_INPUT, "Got direction %d.\n", dir);
651 hr = IPin_QueryId(pin, &id);
652 ok(hr == S_OK, "Got hr %#x.\n", hr);
653 ok(!wcscmp(id, L"VMR Input0"), "Got id %s.\n", wine_dbgstr_w(id));
654 CoTaskMemFree(id);
656 hr = IPin_QueryInternalConnections(pin, NULL, &count);
657 ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
659 IPin_Release(pin);
661 set_mixing_mode(filter, 2);
663 hr = IBaseFilter_FindPin(filter, L"VMR Input1", &pin);
664 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
665 if (hr == S_OK)
667 hr = IPin_QueryPinInfo(pin, &info);
668 ok(info.pFilter == filter, "Expected filter %p, got %p.\n", filter, info.pFilter);
669 ok(info.dir == PINDIR_INPUT, "Got direction %d.\n", info.dir);
670 ok(!wcscmp(info.achName, L"VMR Input1"), "Got name %s.\n", wine_dbgstr_w(info.achName));
671 IBaseFilter_Release(info.pFilter);
673 hr = IPin_QueryDirection(pin, &dir);
674 ok(hr == S_OK, "Got hr %#x.\n", hr);
675 ok(dir == PINDIR_INPUT, "Got direction %d.\n", dir);
677 hr = IPin_QueryId(pin, &id);
678 ok(hr == S_OK, "Got hr %#x.\n", hr);
679 ok(!wcscmp(id, L"VMR Input1"), "Got id %s.\n", wine_dbgstr_w(id));
680 CoTaskMemFree(id);
682 hr = IPin_QueryInternalConnections(pin, NULL, &count);
683 ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
685 IPin_Release(pin);
688 ref = IBaseFilter_Release(filter);
689 ok(!ref, "Got outstanding refcount %d.\n", ref);
692 static void test_media_types(void)
694 IBaseFilter *filter = create_vmr9(0);
695 AM_MEDIA_TYPE *mt, req_mt = {{0}};
696 VIDEOINFOHEADER vih =
698 {0}, {0}, 0, 0, 0,
699 {sizeof(BITMAPINFOHEADER), 32, 24, 1, 0, 0xdeadbeef}
701 IEnumMediaTypes *enummt;
702 unsigned int i;
703 HRESULT hr;
704 ULONG ref;
705 IPin *pin;
707 static const GUID *subtype_tests[] =
709 &MEDIASUBTYPE_RGB565,
710 &MEDIASUBTYPE_RGB24,
711 &MEDIASUBTYPE_RGB32,
714 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
716 hr = IPin_EnumMediaTypes(pin, &enummt);
717 ok(hr == S_OK, "Got hr %#x.\n", hr);
719 hr = IEnumMediaTypes_Next(enummt, 1, &mt, NULL);
720 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
722 IEnumMediaTypes_Release(enummt);
724 req_mt.majortype = MEDIATYPE_Video;
725 req_mt.formattype = FORMAT_VideoInfo;
726 req_mt.cbFormat = sizeof(VIDEOINFOHEADER);
727 req_mt.pbFormat = (BYTE *)&vih;
729 for (i = 0; i < ARRAY_SIZE(subtype_tests); ++i)
731 req_mt.subtype = *subtype_tests[i];
732 hr = IPin_QueryAccept(pin, &req_mt);
733 ok(hr == S_OK, "Got hr %#x for subtype %s.\n", hr, wine_dbgstr_guid(subtype_tests[i]));
736 req_mt.subtype = MEDIASUBTYPE_RGB8;
737 hr = IPin_QueryAccept(pin, &req_mt);
738 todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr);
739 req_mt.subtype = MEDIASUBTYPE_NULL;
740 hr = IPin_QueryAccept(pin, &req_mt);
741 todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr);
742 req_mt.subtype = MEDIASUBTYPE_RGB24;
744 req_mt.majortype = MEDIATYPE_NULL;
745 hr = IPin_QueryAccept(pin, &req_mt);
746 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
747 req_mt.majortype = MEDIATYPE_Video;
749 req_mt.formattype = FORMAT_None;
750 hr = IPin_QueryAccept(pin, &req_mt);
751 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
753 req_mt.formattype = GUID_NULL;
754 hr = IPin_QueryAccept(pin, &req_mt);
755 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
757 IPin_Release(pin);
758 ref = IBaseFilter_Release(filter);
759 ok(!ref, "Got outstanding refcount %d.\n", ref);
762 static void test_enum_media_types(void)
764 IBaseFilter *filter = create_vmr9(0);
765 IEnumMediaTypes *enum1, *enum2;
766 AM_MEDIA_TYPE *mts[2];
767 ULONG ref, count;
768 HRESULT hr;
769 IPin *pin;
771 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
773 hr = IPin_EnumMediaTypes(pin, &enum1);
774 ok(hr == S_OK, "Got hr %#x.\n", hr);
776 hr = IEnumMediaTypes_Next(enum1, 1, mts, NULL);
777 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
779 hr = IEnumMediaTypes_Next(enum1, 1, mts, &count);
780 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
781 ok(!count, "Got count %u.\n", count);
783 hr = IEnumMediaTypes_Reset(enum1);
784 ok(hr == S_OK, "Got hr %#x.\n", hr);
786 hr = IEnumMediaTypes_Next(enum1, 1, mts, NULL);
787 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
789 hr = IEnumMediaTypes_Clone(enum1, &enum2);
790 ok(hr == S_OK, "Got hr %#x.\n", hr);
792 hr = IEnumMediaTypes_Skip(enum1, 1);
793 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
795 hr = IEnumMediaTypes_Next(enum2, 1, mts, NULL);
796 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
798 IEnumMediaTypes_Release(enum1);
799 IEnumMediaTypes_Release(enum2);
800 IPin_Release(pin);
802 ref = IBaseFilter_Release(filter);
803 ok(!ref, "Got outstanding refcount %d.\n", ref);
806 static void test_unconnected_filter_state(void)
808 IBaseFilter *filter = create_vmr9(0);
809 FILTER_STATE state;
810 HRESULT hr;
811 ULONG ref;
813 hr = IBaseFilter_GetState(filter, 0, &state);
814 ok(hr == S_OK, "Got hr %#x.\n", hr);
815 ok(state == State_Stopped, "Got state %u.\n", state);
817 hr = IBaseFilter_Pause(filter);
818 ok(hr == S_OK, "Got hr %#x.\n", hr);
820 hr = IBaseFilter_GetState(filter, 0, &state);
821 ok(hr == S_OK, "Got hr %#x.\n", hr);
822 ok(state == State_Paused, "Got state %u.\n", state);
824 hr = IBaseFilter_Run(filter, 0);
825 ok(hr == S_OK, "Got hr %#x.\n", hr);
827 hr = IBaseFilter_GetState(filter, 0, &state);
828 ok(hr == S_OK, "Got hr %#x.\n", hr);
829 ok(state == State_Running, "Got state %u.\n", state);
831 hr = IBaseFilter_Pause(filter);
832 ok(hr == S_OK, "Got hr %#x.\n", hr);
834 hr = IBaseFilter_GetState(filter, 0, &state);
835 ok(hr == S_OK, "Got hr %#x.\n", hr);
836 ok(state == State_Paused, "Got state %u.\n", state);
838 hr = IBaseFilter_Stop(filter);
839 ok(hr == S_OK, "Got hr %#x.\n", hr);
841 hr = IBaseFilter_GetState(filter, 0, &state);
842 ok(hr == S_OK, "Got hr %#x.\n", hr);
843 ok(state == State_Stopped, "Got state %u.\n", state);
845 hr = IBaseFilter_Run(filter, 0);
846 ok(hr == S_OK, "Got hr %#x.\n", hr);
848 hr = IBaseFilter_GetState(filter, 0, &state);
849 ok(hr == S_OK, "Got hr %#x.\n", hr);
850 ok(state == State_Running, "Got state %u.\n", state);
852 hr = IBaseFilter_Stop(filter);
853 ok(hr == S_OK, "Got hr %#x.\n", hr);
855 hr = IBaseFilter_GetState(filter, 0, &state);
856 ok(hr == S_OK, "Got hr %#x.\n", hr);
857 ok(state == State_Stopped, "Got state %u.\n", state);
859 ref = IBaseFilter_Release(filter);
860 ok(!ref, "Got outstanding refcount %d.\n", ref);
863 struct testfilter
865 struct strmbase_filter filter;
866 struct strmbase_source source;
869 static inline struct testfilter *impl_from_strmbase_filter(struct strmbase_filter *iface)
871 return CONTAINING_RECORD(iface, struct testfilter, filter);
874 static struct strmbase_pin *testfilter_get_pin(struct strmbase_filter *iface, unsigned int index)
876 struct testfilter *filter = impl_from_strmbase_filter(iface);
877 if (!index)
878 return &filter->source.pin;
879 return NULL;
882 static void testfilter_destroy(struct strmbase_filter *iface)
884 struct testfilter *filter = impl_from_strmbase_filter(iface);
885 strmbase_source_cleanup(&filter->source);
886 strmbase_filter_cleanup(&filter->filter);
889 static const struct strmbase_filter_ops testfilter_ops =
891 .filter_get_pin = testfilter_get_pin,
892 .filter_destroy = testfilter_destroy,
895 static HRESULT WINAPI testsource_DecideAllocator(struct strmbase_source *iface,
896 IMemInputPin *peer, IMemAllocator **allocator)
898 return S_OK;
901 static const struct strmbase_source_ops testsource_ops =
903 .pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
904 .pfnDecideAllocator = testsource_DecideAllocator,
907 static void testfilter_init(struct testfilter *filter)
909 static const GUID clsid = {0xabacab};
910 strmbase_filter_init(&filter->filter, NULL, &clsid, &testfilter_ops);
911 strmbase_source_init(&filter->source, &filter->filter, L"", &testsource_ops);
914 static void test_allocator(IMemInputPin *input)
916 IMemAllocator *req_allocator, *ret_allocator;
917 ALLOCATOR_PROPERTIES props, req_props;
918 HRESULT hr;
920 hr = IMemInputPin_GetAllocatorRequirements(input, &props);
921 ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
923 hr = IMemInputPin_GetAllocator(input, &ret_allocator);
924 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
926 if (hr == S_OK)
928 hr = IMemAllocator_GetProperties(ret_allocator, &props);
929 ok(hr == S_OK, "Got hr %#x.\n", hr);
930 ok(!props.cBuffers, "Got %d buffers.\n", props.cBuffers);
931 ok(!props.cbBuffer, "Got size %d.\n", props.cbBuffer);
932 ok(!props.cbAlign, "Got alignment %d.\n", props.cbAlign);
933 ok(!props.cbPrefix, "Got prefix %d.\n", props.cbPrefix);
935 hr = IMemInputPin_NotifyAllocator(input, ret_allocator, TRUE);
936 ok(hr == S_OK, "Got hr %#x.\n", hr);
938 req_props.cBuffers = 1;
939 req_props.cbBuffer = 32 * 16 * 4;
940 req_props.cbAlign = 1;
941 req_props.cbPrefix = 0;
942 hr = IMemAllocator_SetProperties(ret_allocator, &req_props, &props);
943 ok(hr == S_OK, "Got hr %#x.\n", hr);
944 ok(props.cBuffers == 1, "Got %d buffers.\n", props.cBuffers);
945 ok(props.cbBuffer == 32 * 16 * 4, "Got size %d.\n", props.cbBuffer);
946 ok(props.cbAlign == 1, "Got alignment %d.\n", props.cbAlign);
947 ok(!props.cbPrefix, "Got prefix %d.\n", props.cbPrefix);
949 IMemAllocator_Release(ret_allocator);
952 hr = IMemInputPin_NotifyAllocator(input, NULL, TRUE);
953 todo_wine ok(hr == E_FAIL, "Got hr %#x.\n", hr);
955 CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER,
956 &IID_IMemAllocator, (void **)&req_allocator);
958 hr = IMemInputPin_NotifyAllocator(input, req_allocator, TRUE);
959 todo_wine ok(hr == E_FAIL, "Got hr %#x.\n", hr);
961 IMemAllocator_Release(req_allocator);
964 struct frame_thread_params
966 IMemInputPin *sink;
967 IMediaSample *sample;
970 static DWORD WINAPI frame_thread(void *arg)
972 struct frame_thread_params *params = arg;
973 HRESULT hr;
975 if (winetest_debug > 1) trace("%04x: Sending frame.\n", GetCurrentThreadId());
976 hr = IMemInputPin_Receive(params->sink, params->sample);
977 if (winetest_debug > 1) trace("%04x: Returned %#x.\n", GetCurrentThreadId(), hr);
978 IMediaSample_Release(params->sample);
979 heap_free(params);
980 return hr;
983 static HANDLE send_frame_time(IMemInputPin *sink, REFERENCE_TIME start_time, DWORD color)
985 struct frame_thread_params *params = heap_alloc(sizeof(*params));
986 IMemAllocator *allocator;
987 REFERENCE_TIME end_time;
988 IMediaSample *sample;
989 HANDLE thread;
990 LONG size, i;
991 HRESULT hr;
992 BYTE *data;
994 hr = IMemInputPin_GetAllocator(sink, &allocator);
995 ok(hr == S_OK, "Got hr %#x.\n", hr);
997 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
998 ok(hr == S_OK, "Got hr %#x.\n", hr);
1000 size = IMediaSample_GetSize(sample);
1001 hr = IMediaSample_GetPointer(sample, &data);
1002 ok(hr == S_OK, "Got hr %#x.\n", hr);
1003 for (i = 0; i < size / sizeof(DWORD); ++i)
1004 ((DWORD *)data)[i] = color;
1006 hr = IMediaSample_SetActualDataLength(sample, size);
1007 ok(hr == S_OK, "Got hr %#x.\n", hr);
1009 start_time *= 10000000;
1010 end_time = start_time + 10000000;
1011 hr = IMediaSample_SetTime(sample, &start_time, &end_time);
1012 ok(hr == S_OK, "Got hr %#x.\n", hr);
1014 hr = IMediaSample_SetPreroll(sample, TRUE);
1015 ok(hr == S_OK, "Got hr %#x.\n", hr);
1017 params->sink = sink;
1018 params->sample = sample;
1019 thread = CreateThread(NULL, 0, frame_thread, params, 0, NULL);
1021 IMemAllocator_Release(allocator);
1022 return thread;
1025 static HANDLE send_frame(IMemInputPin *sink)
1027 return send_frame_time(sink, 0, 0x007f007f);
1030 static HRESULT join_thread_(int line, HANDLE thread)
1032 DWORD ret;
1033 ok_(__FILE__, line)(!WaitForSingleObject(thread, 1000), "Wait failed.\n");
1034 GetExitCodeThread(thread, &ret);
1035 CloseHandle(thread);
1036 return ret;
1038 #define join_thread(a) join_thread_(__LINE__, a)
1040 static void commit_allocator(IMemInputPin *input)
1042 IMemAllocator *allocator;
1043 HRESULT hr;
1045 hr = IMemInputPin_GetAllocator(input, &allocator);
1046 ok(hr == S_OK, "Got hr %#x.\n", hr);
1047 hr = IMemAllocator_Commit(allocator);
1048 ok(hr == S_OK, "Got hr %#x.\n", hr);
1049 IMemAllocator_Release(allocator);
1052 static void test_filter_state(IMemInputPin *input, IMediaControl *control)
1054 IMemAllocator *allocator;
1055 IMediaSample *sample;
1056 OAFilterState state;
1057 HANDLE thread;
1058 HRESULT hr;
1060 thread = send_frame(input);
1061 hr = join_thread(thread);
1062 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
1064 /* The renderer is not fully paused until it receives a sample. The thread
1065 * sending the sample blocks in IMemInputPin_Receive() until the filter is
1066 * stopped or run. */
1068 hr = IMediaControl_Pause(control);
1069 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1071 hr = IMediaControl_GetState(control, 0, &state);
1072 ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1074 thread = send_frame(input);
1076 hr = IMediaControl_GetState(control, 1000, &state);
1077 ok(hr == S_OK, "Got hr %#x.\n", hr);
1079 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1081 hr = IMediaControl_Stop(control);
1082 ok(hr == S_OK, "Got hr %#x.\n", hr);
1084 hr = join_thread(thread);
1085 ok(hr == S_OK, "Got hr %#x.\n", hr);
1087 /* The sink will decommit our allocator for us when stopping, however it
1088 * will not recommit it when pausing. */
1089 hr = IMemInputPin_GetAllocator(input, &allocator);
1090 ok(hr == S_OK, "Got hr %#x.\n", hr);
1091 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
1092 todo_wine ok(hr == VFW_E_NOT_COMMITTED, "Got hr %#x.\n", hr);
1093 if (hr == S_OK) IMediaSample_Release(sample);
1095 hr = IMemAllocator_Commit(allocator);
1096 ok(hr == S_OK, "Got hr %#x.\n", hr);
1097 thread = send_frame(input);
1098 hr = join_thread(thread);
1099 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
1101 hr = IMediaControl_Pause(control);
1102 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1104 hr = IMediaControl_GetState(control, 0, &state);
1105 ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1107 thread = send_frame(input);
1109 hr = IMediaControl_GetState(control, 1000, &state);
1110 ok(hr == S_OK, "Got hr %#x.\n", hr);
1112 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1114 hr = IMediaControl_Run(control);
1115 ok(hr == S_OK, "Got hr %#x.\n", hr);
1117 hr = IMediaControl_GetState(control, 0, &state);
1118 ok(hr == S_OK, "Got hr %#x.\n", hr);
1120 hr = join_thread(thread);
1121 ok(hr == S_OK, "Got hr %#x.\n", hr);
1123 thread = send_frame(input);
1124 hr = join_thread(thread);
1125 ok(hr == S_OK, "Got hr %#x.\n", hr);
1127 hr = IMediaControl_Pause(control);
1128 todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1130 hr = IMediaControl_GetState(control, 0, &state);
1131 todo_wine ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1133 thread = send_frame(input);
1135 hr = IMediaControl_GetState(control, 1000, &state);
1136 ok(hr == S_OK, "Got hr %#x.\n", hr);
1138 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1140 hr = IMediaControl_Run(control);
1141 ok(hr == S_OK, "Got hr %#x.\n", hr);
1143 hr = IMediaControl_GetState(control, 0, &state);
1144 ok(hr == S_OK, "Got hr %#x.\n", hr);
1146 hr = join_thread(thread);
1147 ok(hr == S_OK, "Got hr %#x.\n", hr);
1149 hr = IMediaControl_Pause(control);
1150 todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1152 hr = IMediaControl_GetState(control, 0, &state);
1153 todo_wine ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1155 hr = IMediaControl_Stop(control);
1156 ok(hr == S_OK, "Got hr %#x.\n", hr);
1158 hr = IMediaControl_GetState(control, 0, &state);
1159 ok(hr == S_OK, "Got hr %#x.\n", hr);
1161 commit_allocator(input);
1162 hr = IMediaControl_Pause(control);
1163 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1165 hr = IMediaControl_GetState(control, 0, &state);
1166 ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1168 hr = IMediaControl_Run(control);
1169 todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1171 hr = IMediaControl_GetState(control, 0, &state);
1172 todo_wine ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1174 thread = send_frame(input);
1175 hr = join_thread(thread);
1176 ok(hr == S_OK, "Got hr %#x.\n", hr);
1178 hr = IMediaControl_GetState(control, 0, &state);
1179 ok(hr == S_OK, "Got hr %#x.\n", hr);
1181 hr = IMediaControl_Stop(control);
1182 ok(hr == S_OK, "Got hr %#x.\n", hr);
1184 hr = IMediaControl_GetState(control, 0, &state);
1185 ok(hr == S_OK, "Got hr %#x.\n", hr);
1187 IMemAllocator_Release(allocator);
1190 static void test_flushing(IPin *pin, IMemInputPin *input, IMediaControl *control)
1192 OAFilterState state;
1193 HANDLE thread;
1194 HRESULT hr;
1196 commit_allocator(input);
1197 hr = IMediaControl_Pause(control);
1198 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1200 thread = send_frame(input);
1201 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1203 hr = IMediaControl_GetState(control, 0, &state);
1204 ok(hr == S_OK, "Got hr %#x.\n", hr);
1206 hr = IPin_BeginFlush(pin);
1207 ok(hr == S_OK, "Got hr %#x.\n", hr);
1209 hr = join_thread(thread);
1210 ok(hr == S_OK, "Got hr %#x.\n", hr);
1212 thread = send_frame(input);
1213 hr = join_thread(thread);
1214 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1216 hr = IPin_EndFlush(pin);
1217 ok(hr == S_OK, "Got hr %#x.\n", hr);
1219 /* We dropped the sample we were holding, so now we need a new one... */
1221 hr = IMediaControl_GetState(control, 0, &state);
1222 todo_wine ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1224 thread = send_frame(input);
1225 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1227 hr = IMediaControl_Run(control);
1228 ok(hr == S_OK, "Got hr %#x.\n", hr);
1229 hr = join_thread(thread);
1230 ok(hr == S_OK, "Got hr %#x.\n", hr);
1232 hr = IPin_BeginFlush(pin);
1233 ok(hr == S_OK, "Got hr %#x.\n", hr);
1235 thread = send_frame(input);
1236 hr = join_thread(thread);
1237 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1239 hr = IPin_EndFlush(pin);
1240 ok(hr == S_OK, "Got hr %#x.\n", hr);
1242 thread = send_frame(input);
1243 hr = join_thread(thread);
1244 ok(hr == S_OK, "Got hr %#x.\n", hr);
1246 hr = IMediaControl_Stop(control);
1247 ok(hr == S_OK, "Got hr %#x.\n", hr);
1250 static unsigned int check_ec_complete(IMediaEvent *eventsrc, DWORD timeout)
1252 LONG_PTR param1, param2;
1253 unsigned int ret = 0;
1254 HRESULT hr;
1255 LONG code;
1257 while ((hr = IMediaEvent_GetEvent(eventsrc, &code, &param1, &param2, timeout)) == S_OK)
1259 if (code == EC_COMPLETE)
1261 ok(param1 == S_OK, "Got param1 %#lx.\n", param1);
1262 ok(!param2, "Got param2 %#lx.\n", param2);
1263 ret++;
1265 IMediaEvent_FreeEventParams(eventsrc, code, param1, param2);
1266 timeout = 0;
1268 ok(hr == E_ABORT, "Got hr %#x.\n", hr);
1270 return ret;
1273 static void test_eos(IPin *pin, IMemInputPin *input, IMediaControl *control)
1275 IMediaEvent *eventsrc;
1276 OAFilterState state;
1277 HRESULT hr;
1278 BOOL ret;
1280 IMediaControl_QueryInterface(control, &IID_IMediaEvent, (void **)&eventsrc);
1282 commit_allocator(input);
1283 hr = IMediaControl_Pause(control);
1284 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1285 ret = check_ec_complete(eventsrc, 0);
1286 ok(!ret, "Got unexpected EC_COMPLETE.\n");
1288 hr = IPin_EndOfStream(pin);
1289 ok(hr == S_OK, "Got hr %#x.\n", hr);
1291 hr = IMediaControl_GetState(control, 1000, &state);
1292 ok(hr == S_OK, "Got hr %#x.\n", hr);
1293 ret = check_ec_complete(eventsrc, 0);
1294 todo_wine ok(!ret, "Got unexpected EC_COMPLETE.\n");
1296 hr = join_thread(send_frame(input));
1297 todo_wine ok(hr == E_UNEXPECTED, "Got hr %#x.\n", hr);
1299 hr = IMediaControl_Run(control);
1300 ok(hr == S_OK, "Got hr %#x.\n", hr);
1301 ret = check_ec_complete(eventsrc, 0);
1302 todo_wine ok(ret == 1, "Expected EC_COMPLETE.\n");
1304 hr = IMediaControl_Stop(control);
1305 ok(hr == S_OK, "Got hr %#x.\n", hr);
1306 ret = check_ec_complete(eventsrc, 0);
1307 ok(!ret, "Got unexpected EC_COMPLETE.\n");
1309 /* We do not receive an EC_COMPLETE notification until the last sample is
1310 * done rendering. */
1312 commit_allocator(input);
1313 hr = IMediaControl_Run(control);
1314 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1315 hr = join_thread(send_frame(input));
1316 ok(hr == S_OK, "Got hr %#x.\n", hr);
1317 hr = IMediaControl_GetState(control, 1000, &state);
1318 ok(hr == S_OK, "Got hr %#x.\n", hr);
1319 ret = check_ec_complete(eventsrc, 0);
1320 ok(!ret, "Got unexpected EC_COMPLETE.\n");
1322 hr = IPin_EndOfStream(pin);
1323 ok(hr == S_OK, "Got hr %#x.\n", hr);
1324 ret = check_ec_complete(eventsrc, 0);
1325 todo_wine ok(!ret, "Got unexpected EC_COMPLETE.\n");
1326 ret = check_ec_complete(eventsrc, 1600);
1327 todo_wine ok(ret == 1, "Expected EC_COMPLETE.\n");
1329 hr = IMediaControl_Stop(control);
1330 ok(hr == S_OK, "Got hr %#x.\n", hr);
1331 ret = check_ec_complete(eventsrc, 0);
1332 ok(!ret, "Got unexpected EC_COMPLETE.\n");
1334 /* Test sending EOS while flushing. */
1336 commit_allocator(input);
1337 hr = IMediaControl_Run(control);
1338 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1339 hr = join_thread(send_frame(input));
1340 ok(hr == S_OK, "Got hr %#x.\n", hr);
1342 hr = IPin_BeginFlush(pin);
1343 ok(hr == S_OK, "Got hr %#x.\n", hr);
1344 hr = IPin_EndOfStream(pin);
1345 todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1346 hr = IPin_EndFlush(pin);
1347 ok(hr == S_OK, "Got hr %#x.\n", hr);
1349 hr = IMediaControl_Stop(control);
1350 ok(hr == S_OK, "Got hr %#x.\n", hr);
1351 ret = check_ec_complete(eventsrc, 0);
1352 todo_wine ok(!ret, "Got unexpected EC_COMPLETE.\n");
1354 /* Test sending EOS and then flushing or stopping. */
1356 commit_allocator(input);
1357 hr = IMediaControl_Run(control);
1358 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1359 hr = join_thread(send_frame(input));
1360 ok(hr == S_OK, "Got hr %#x.\n", hr);
1361 hr = IMediaControl_GetState(control, 1000, &state);
1362 ok(hr == S_OK, "Got hr %#x.\n", hr);
1364 hr = IPin_EndOfStream(pin);
1365 ok(hr == S_OK, "Got hr %#x.\n", hr);
1366 ret = check_ec_complete(eventsrc, 0);
1367 todo_wine ok(!ret, "Got unexpected EC_COMPLETE.\n");
1369 hr = IPin_BeginFlush(pin);
1370 ok(hr == S_OK, "Got hr %#x.\n", hr);
1371 hr = IPin_EndFlush(pin);
1372 ok(hr == S_OK, "Got hr %#x.\n", hr);
1374 hr = join_thread(send_frame(input));
1375 ok(hr == S_OK, "Got hr %#x.\n", hr);
1376 hr = IPin_EndOfStream(pin);
1377 ok(hr == S_OK, "Got hr %#x.\n", hr);
1378 ret = check_ec_complete(eventsrc, 0);
1379 ok(!ret, "Got unexpected EC_COMPLETE.\n");
1381 hr = IMediaControl_Stop(control);
1382 ok(hr == S_OK, "Got hr %#x.\n", hr);
1383 ret = check_ec_complete(eventsrc, 0);
1384 ok(!ret, "Got unexpected EC_COMPLETE.\n");
1386 IMediaEvent_Release(eventsrc);
1389 static void test_sample_time(IPin *pin, IMemInputPin *input, IMediaControl *control)
1391 OAFilterState state;
1392 HANDLE thread;
1393 HRESULT hr;
1395 commit_allocator(input);
1396 hr = IMediaControl_Pause(control);
1397 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1399 hr = IMediaControl_GetState(control, 0, &state);
1400 ok(hr == VFW_S_STATE_INTERMEDIATE, "Got hr %#x.\n", hr);
1402 thread = send_frame_time(input, 1, 0x000000ff); /* blue */
1404 hr = IMediaControl_GetState(control, 1000, &state);
1405 ok(hr == S_OK, "Got hr %#x.\n", hr);
1407 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1409 hr = IMediaControl_Run(control);
1410 ok(hr == S_OK, "Got hr %#x.\n", hr);
1412 ok(WaitForSingleObject(thread, 500) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1414 hr = join_thread(thread);
1415 ok(hr == S_OK, "Got hr %#x.\n", hr);
1417 /* Sample time is relative to the time passed to Run(). Thus a sample
1418 * stamped at or earlier than 1s will now be displayed immediately, because
1419 * that time has already passed.
1420 * One may manually verify that all of the frames in this function are
1421 * rendered, including (by adding a Sleep() after sending the frame) the
1422 * cyan and green frames. Thus the VMR does not attempt to drop any frames
1423 * that it considers late. This remains true if the frames are marked as
1424 * discontinuous. */
1426 hr = join_thread(send_frame_time(input, 1, 0x0000ffff)); /* cyan */
1427 ok(hr == S_OK, "Got hr %#x.\n", hr);
1429 hr = join_thread(send_frame_time(input, 0, 0x0000ff00)); /* green */
1430 ok(hr == S_OK, "Got hr %#x.\n", hr);
1432 hr = join_thread(send_frame_time(input, -2, 0x00ff0000)); /* red */
1433 ok(hr == S_OK, "Got hr %#x.\n", hr);
1435 thread = send_frame_time(input, 2, 0x00ff00ff); /* magenta */
1436 ok(WaitForSingleObject(thread, 500) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1437 hr = join_thread(thread);
1438 ok(hr == S_OK, "Got hr %#x.\n", hr);
1440 thread = send_frame_time(input, 1000000, 0x00ffffff); /* white */
1441 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1443 hr = IPin_BeginFlush(pin);
1444 ok(hr == S_OK, "Got hr %#x.\n", hr);
1445 hr = join_thread(thread);
1446 ok(hr == S_OK, "Got hr %#x.\n", hr);
1447 hr = IPin_EndFlush(pin);
1448 ok(hr == S_OK, "Got hr %#x.\n", hr);
1450 thread = send_frame_time(input, 1000000, 0x00ffff00); /* yellow */
1451 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block in Receive().\n");
1453 hr = IMediaControl_Stop(control);
1454 ok(hr == S_OK, "Got hr %#x.\n", hr);
1455 hr = join_thread(thread);
1456 ok(hr == S_OK, "Got hr %#x.\n", hr);
1459 static void test_current_image(IBaseFilter *filter, IMemInputPin *input,
1460 IMediaControl *control, const BITMAPINFOHEADER *req_bih)
1462 LONG buffer[(sizeof(BITMAPINFOHEADER) + 32 * 16 * 4) / 4];
1463 const BITMAPINFOHEADER *bih = (BITMAPINFOHEADER *)buffer;
1464 const DWORD *data = (DWORD *)((char *)buffer + sizeof(BITMAPINFOHEADER));
1465 BITMAPINFOHEADER expect_bih = *req_bih;
1466 OAFilterState state;
1467 IBasicVideo *video;
1468 unsigned int i;
1469 HANDLE thread;
1470 HRESULT hr;
1471 LONG size;
1473 expect_bih.biSizeImage = 32 * 16 * 4;
1475 IBaseFilter_QueryInterface(filter, &IID_IBasicVideo, (void **)&video);
1477 hr = IBasicVideo_GetCurrentImage(video, NULL, NULL);
1478 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
1480 hr = IBasicVideo_GetCurrentImage(video, NULL, buffer);
1481 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
1483 size = 0xdeadbeef;
1484 hr = IBasicVideo_GetCurrentImage(video, &size, NULL);
1485 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
1486 todo_wine ok(size == sizeof(BITMAPINFOHEADER) + 32 * 16 * 4, "Got size %d.\n", size);
1488 size = sizeof(buffer);
1489 hr = IBasicVideo_GetCurrentImage(video, &size, buffer);
1490 ok(hr == S_OK, "Got hr %#x.\n", hr);
1491 ok(size == sizeof(buffer), "Got size %d.\n", size);
1492 ok(!memcmp(bih, &expect_bih, sizeof(BITMAPINFOHEADER)), "Bitmap headers didn't match.\n");
1493 /* The contents seem to reflect the last frame rendered. */
1495 commit_allocator(input);
1496 hr = IMediaControl_Pause(control);
1497 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1499 size = sizeof(buffer);
1500 hr = IBasicVideo_GetCurrentImage(video, &size, buffer);
1501 ok(hr == S_OK, "Got hr %#x.\n", hr);
1502 ok(size == sizeof(buffer), "Got size %d.\n", size);
1503 ok(!memcmp(bih, &expect_bih, sizeof(BITMAPINFOHEADER)), "Bitmap headers didn't match.\n");
1504 /* The contents seem to reflect the last frame rendered. */
1506 thread = send_frame(input);
1507 hr = IMediaControl_GetState(control, 1000, &state);
1508 ok(hr == S_OK, "Got hr %#x.\n", hr);
1510 size = 1;
1511 memset(buffer, 0xcc, sizeof(buffer));
1512 hr = IBasicVideo_GetCurrentImage(video, &size, buffer);
1513 ok(hr == S_OK, "Got hr %#x.\n", hr);
1514 ok(size == 1, "Got size %d.\n", size);
1516 size = sizeof(buffer);
1517 memset(buffer, 0xcc, sizeof(buffer));
1518 hr = IBasicVideo_GetCurrentImage(video, &size, buffer);
1519 ok(hr == S_OK, "Got hr %#x.\n", hr);
1520 ok(size == sizeof(buffer), "Got size %d.\n", size);
1521 ok(!memcmp(bih, &expect_bih, sizeof(BITMAPINFOHEADER)), "Bitmap headers didn't match.\n");
1522 for (i = 0; i < 32 * 16; ++i)
1523 ok((data[i] & 0xffffff) == 0x7f007f, "Got unexpected color %08x at %u.\n", data[i], i);
1525 hr = IMediaControl_Run(control);
1526 ok(hr == S_OK, "Got hr %#x.\n", hr);
1527 join_thread(thread);
1529 size = sizeof(buffer);
1530 memset(buffer, 0xcc, sizeof(buffer));
1531 hr = IBasicVideo_GetCurrentImage(video, &size, buffer);
1532 ok(hr == S_OK, "Got hr %#x.\n", hr);
1533 ok(size == sizeof(buffer), "Got size %d.\n", size);
1534 ok(!memcmp(bih, &expect_bih, sizeof(BITMAPINFOHEADER)), "Bitmap headers didn't match.\n");
1535 for (i = 0; i < 32 * 16; ++i)
1536 ok((data[i] & 0xffffff) == 0x7f007f, "Got unexpected color %08x at %u.\n", data[i], i);
1538 hr = IMediaControl_Stop(control);
1539 ok(hr == S_OK, "Got hr %#x.\n", hr);
1541 IBasicVideo_Release(video);
1544 static void test_connect_pin(void)
1546 VIDEOINFOHEADER vih =
1548 .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
1549 .bmiHeader.biBitCount = 32,
1550 .bmiHeader.biWidth = 32,
1551 .bmiHeader.biHeight = 16,
1552 .bmiHeader.biPlanes = 1,
1553 .bmiHeader.biCompression = BI_RGB,
1555 AM_MEDIA_TYPE req_mt =
1557 .majortype = MEDIATYPE_Video,
1558 .formattype = FORMAT_VideoInfo,
1559 .cbFormat = sizeof(vih),
1560 .pbFormat = (BYTE *)&vih,
1562 ALLOCATOR_PROPERTIES req_props = {1, 32 * 16 * 4, 1, 0}, ret_props;
1563 IBaseFilter *filter = create_vmr9(VMR9Mode_Windowed);
1564 IFilterGraph2 *graph = create_graph();
1565 struct testfilter source;
1566 IMemAllocator *allocator;
1567 IMediaControl *control;
1568 IMemInputPin *input;
1569 unsigned int i, j;
1570 AM_MEDIA_TYPE mt;
1571 IPin *pin, *peer;
1572 HRESULT hr;
1573 ULONG ref;
1575 static const GUID *subtype_tests[] =
1577 &MEDIASUBTYPE_RGB555,
1578 &MEDIASUBTYPE_RGB565,
1579 &MEDIASUBTYPE_RGB24,
1580 &MEDIASUBTYPE_RGB32,
1582 static const WORD bpp_tests[] = {15, 16, 24, 32};
1584 testfilter_init(&source);
1586 IFilterGraph2_AddFilter(graph, &source.filter.IBaseFilter_iface, NULL);
1587 IFilterGraph2_AddFilter(graph, filter, NULL);
1588 IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
1590 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
1591 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input);
1593 for (i = 0; i < ARRAY_SIZE(subtype_tests); ++i)
1595 req_mt.subtype = *subtype_tests[i];
1597 for (j = 0; j < ARRAY_SIZE(bpp_tests); ++j)
1599 vih.bmiHeader.biBitCount = bpp_tests[j];
1601 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
1602 if (hr == E_FAIL)
1604 skip("Got E_FAIL when connecting.\n");
1605 goto out;
1607 ok(hr == S_OK, "Got hr %#x for subtype %s and bpp %u.\n", hr,
1608 wine_dbgstr_guid(subtype_tests[i]), bpp_tests[j]);
1610 hr = IFilterGraph2_Disconnect(graph, &source.source.pin.IPin_iface);
1611 ok(hr == S_OK, "Got hr %#x.\n", hr);
1612 hr = IFilterGraph2_Disconnect(graph, pin);
1613 ok(hr == S_OK, "Got hr %#x.\n", hr);
1617 req_mt.formattype = FORMAT_None;
1618 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
1619 ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr);
1620 req_mt.formattype = FORMAT_VideoInfo;
1622 req_mt.subtype = MEDIASUBTYPE_RGB8;
1623 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
1624 ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr);
1625 req_mt.subtype = MEDIASUBTYPE_WAVE;
1626 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
1627 ok(hr == VFW_E_TYPE_NOT_ACCEPTED, "Got hr %#x.\n", hr);
1628 req_mt.subtype = MEDIASUBTYPE_RGB32;
1630 peer = (IPin *)0xdeadbeef;
1631 hr = IPin_ConnectedTo(pin, &peer);
1632 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
1633 ok(!peer, "Got peer %p.\n", peer);
1635 hr = IPin_ConnectionMediaType(pin, &mt);
1636 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
1638 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
1639 ok(hr == S_OK, "Got hr %#x.\n", hr);
1641 hr = IPin_ConnectedTo(pin, &peer);
1642 ok(hr == S_OK, "Got hr %#x.\n", hr);
1643 ok(peer == &source.source.pin.IPin_iface, "Got peer %p.\n", peer);
1644 IPin_Release(peer);
1646 hr = IPin_ConnectionMediaType(pin, &mt);
1647 ok(hr == S_OK, "Got hr %#x.\n", hr);
1648 ok(compare_media_types(&mt, &req_mt), "Media types didn't match.\n");
1650 test_allocator(input);
1652 hr = IMemInputPin_GetAllocator(input, &allocator);
1653 ok(hr == S_OK, "Got hr %#x.\n", hr);
1654 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
1655 ok(hr == S_OK, "Got hr %#x.\n", hr);
1656 ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
1657 hr = IMemAllocator_Commit(allocator);
1658 ok(hr == S_OK, "Got hr %#x.\n", hr);
1659 IMemAllocator_Release(allocator);
1661 hr = IMemInputPin_ReceiveCanBlock(input);
1662 ok(hr == S_OK, "Got hr %#x.\n", hr);
1664 test_filter_state(input, control);
1665 test_flushing(pin, input, control);
1666 test_eos(pin, input, control);
1667 test_sample_time(pin, input, control);
1668 test_current_image(filter, input, control, &vih.bmiHeader);
1670 hr = IFilterGraph2_Disconnect(graph, pin);
1671 ok(hr == S_OK, "Got hr %#x.\n", hr);
1672 hr = IFilterGraph2_Disconnect(graph, pin);
1673 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
1674 ok(source.source.pin.peer == pin, "Got peer %p.\n", source.source.pin.peer);
1675 IFilterGraph2_Disconnect(graph, &source.source.pin.IPin_iface);
1677 peer = (IPin *)0xdeadbeef;
1678 hr = IPin_ConnectedTo(pin, &peer);
1679 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
1680 ok(!peer, "Got peer %p.\n", peer);
1682 hr = IPin_ConnectionMediaType(pin, &mt);
1683 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
1685 out:
1686 IMediaControl_Release(control);
1687 ref = IFilterGraph2_Release(graph);
1688 ok(!ref, "Got outstanding refcount %d.\n", ref);
1689 IMemInputPin_Release(input);
1690 IPin_Release(pin);
1691 ref = IBaseFilter_Release(filter);
1692 ok(!ref, "Got outstanding refcount %d.\n", ref);
1693 ref = IBaseFilter_Release(&source.filter.IBaseFilter_iface);
1694 ok(!ref, "Got outstanding refcount %d.\n", ref);
1697 static void test_overlay(void)
1699 IBaseFilter *filter = create_vmr9(0);
1700 IOverlay *overlay;
1701 HRESULT hr;
1702 ULONG ref;
1703 IPin *pin;
1704 HWND hwnd;
1706 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
1708 hr = IPin_QueryInterface(pin, &IID_IOverlay, (void **)&overlay);
1709 ok(hr == S_OK, "Got hr %#x.\n", hr);
1711 hwnd = (HWND)0xdeadbeef;
1712 hr = IOverlay_GetWindowHandle(overlay, &hwnd);
1713 ok(hr == S_OK, "Got hr %#x.\n", hr);
1714 ok(hwnd && hwnd != (HWND)0xdeadbeef, "Got invalid window %p.\n", hwnd);
1716 IOverlay_Release(overlay);
1717 IPin_Release(pin);
1718 ref = IBaseFilter_Release(filter);
1719 ok(!ref, "Got outstanding refcount %d.\n", ref);
1721 filter = create_vmr9(VMR9Mode_Windowless);
1722 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
1724 hr = IPin_QueryInterface(pin, &IID_IOverlay, (void **)&overlay);
1725 ok(hr == S_OK, "Got hr %#x.\n", hr);
1727 hwnd = (HWND)0xdeadbeef;
1728 hr = IOverlay_GetWindowHandle(overlay, &hwnd);
1729 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
1730 ok(hwnd == (HWND)0xdeadbeef, "Got window %p.\n", hwnd);
1732 IOverlay_Release(overlay);
1733 IPin_Release(pin);
1734 ref = IBaseFilter_Release(filter);
1735 ok(!ref, "Got outstanding refcount %d.\n", ref);
1737 filter = create_vmr9(VMR9Mode_Renderless);
1738 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
1740 hr = IPin_QueryInterface(pin, &IID_IOverlay, (void **)&overlay);
1741 ok(hr == S_OK, "Got hr %#x.\n", hr);
1743 hwnd = (HWND)0xdeadbeef;
1744 hr = IOverlay_GetWindowHandle(overlay, &hwnd);
1745 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
1746 ok(hwnd == (HWND)0xdeadbeef, "Got window %p.\n", hwnd);
1748 IOverlay_Release(overlay);
1749 IPin_Release(pin);
1750 ref = IBaseFilter_Release(filter);
1751 ok(!ref, "Got outstanding refcount %d.\n", ref);
1754 /* try to make sure pending X events have been processed before continuing */
1755 static void flush_events(void)
1757 int diff = 200;
1758 DWORD time;
1759 MSG msg;
1761 time = GetTickCount() + diff;
1762 while (diff > 0)
1764 if (MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT) == WAIT_TIMEOUT)
1765 break;
1766 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
1767 DispatchMessageA(&msg);
1768 diff = time - GetTickCount();
1772 static LRESULT CALLBACK window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1774 if (winetest_debug > 1)
1775 trace("hwnd %p, msg %#x, wparam %#lx, lparam %#lx.\n", hwnd, msg, wparam, lparam);
1777 if (wparam == 0xdeadbeef)
1778 return 0;
1780 return DefWindowProcA(hwnd, msg, wparam, lparam);
1783 static void test_video_window_caption(IVideoWindow *window, HWND hwnd)
1785 WCHAR text[50];
1786 BSTR caption;
1787 HRESULT hr;
1789 hr = IVideoWindow_get_Caption(window, &caption);
1790 ok(hr == S_OK, "Got hr %#x.\n", hr);
1791 ok(!wcscmp(caption, L"ActiveMovie Window"), "Got caption %s.\n", wine_dbgstr_w(caption));
1792 SysFreeString(caption);
1794 GetWindowTextW(hwnd, text, ARRAY_SIZE(text));
1795 ok(!wcscmp(text, L"ActiveMovie Window"), "Got caption %s.\n", wine_dbgstr_w(text));
1797 caption = SysAllocString(L"foo");
1798 hr = IVideoWindow_put_Caption(window, caption);
1799 ok(hr == S_OK, "Got hr %#x.\n", hr);
1800 SysFreeString(caption);
1802 hr = IVideoWindow_get_Caption(window, &caption);
1803 ok(hr == S_OK, "Got hr %#x.\n", hr);
1804 ok(!wcscmp(caption, L"foo"), "Got caption %s.\n", wine_dbgstr_w(caption));
1805 SysFreeString(caption);
1807 GetWindowTextW(hwnd, text, ARRAY_SIZE(text));
1808 ok(!wcscmp(text, L"foo"), "Got caption %s.\n", wine_dbgstr_w(text));
1811 static void test_video_window_style(IVideoWindow *window, HWND hwnd, HWND our_hwnd)
1813 HRESULT hr;
1814 LONG style;
1816 hr = IVideoWindow_get_WindowStyle(window, &style);
1817 ok(hr == S_OK, "Got hr %#x.\n", hr);
1818 ok(style == (WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW),
1819 "Got style %#x.\n", style);
1821 style = GetWindowLongA(hwnd, GWL_STYLE);
1822 ok(style == (WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW),
1823 "Got style %#x.\n", style);
1825 hr = IVideoWindow_put_WindowStyle(window, style | WS_DISABLED);
1826 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
1827 hr = IVideoWindow_put_WindowStyle(window, style | WS_HSCROLL);
1828 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
1829 hr = IVideoWindow_put_WindowStyle(window, style | WS_VSCROLL);
1830 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
1831 hr = IVideoWindow_put_WindowStyle(window, style | WS_MAXIMIZE);
1832 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
1833 hr = IVideoWindow_put_WindowStyle(window, style | WS_MINIMIZE);
1834 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
1836 hr = IVideoWindow_put_WindowStyle(window, style & ~WS_CLIPCHILDREN);
1837 ok(hr == S_OK, "Got hr %#x.\n", hr);
1839 hr = IVideoWindow_get_WindowStyle(window, &style);
1840 ok(hr == S_OK, "Got hr %#x.\n", hr);
1841 ok(style == (WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW), "Got style %#x.\n", style);
1843 style = GetWindowLongA(hwnd, GWL_STYLE);
1844 ok(style == (WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW), "Got style %#x.\n", style);
1846 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
1848 hr = IVideoWindow_get_WindowStyleEx(window, &style);
1849 ok(hr == S_OK, "Got hr %#x.\n", hr);
1850 ok(style == WS_EX_WINDOWEDGE, "Got style %#x.\n", style);
1852 style = GetWindowLongA(hwnd, GWL_EXSTYLE);
1853 ok(style == WS_EX_WINDOWEDGE, "Got style %#x.\n", style);
1855 hr = IVideoWindow_put_WindowStyleEx(window, style | WS_EX_TRANSPARENT);
1856 ok(hr == S_OK, "Got hr %#x.\n", hr);
1858 hr = IVideoWindow_get_WindowStyleEx(window, &style);
1859 ok(hr == S_OK, "Got hr %#x.\n", hr);
1860 ok(style == (WS_EX_WINDOWEDGE | WS_EX_TRANSPARENT), "Got style %#x.\n", style);
1862 style = GetWindowLongA(hwnd, GWL_EXSTYLE);
1863 ok(style == (WS_EX_WINDOWEDGE | WS_EX_TRANSPARENT), "Got style %#x.\n", style);
1866 static BOOL CALLBACK top_window_cb(HWND hwnd, LPARAM ctx)
1868 DWORD pid;
1869 GetWindowThreadProcessId(hwnd, &pid);
1870 if (pid == GetCurrentProcessId() && (GetWindowLongW(hwnd, GWL_STYLE) & WS_VISIBLE))
1872 *(HWND *)ctx = hwnd;
1873 return FALSE;
1875 return TRUE;
1878 static HWND get_top_window(void)
1880 HWND hwnd;
1881 EnumWindows(top_window_cb, (LPARAM)&hwnd);
1882 return hwnd;
1885 static void test_video_window_state(IVideoWindow *window, HWND hwnd, HWND our_hwnd)
1887 HRESULT hr;
1888 LONG state;
1889 HWND top;
1891 SetWindowPos(our_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
1893 hr = IVideoWindow_get_WindowState(window, &state);
1894 ok(hr == S_OK, "Got hr %#x.\n", hr);
1895 ok(state == SW_HIDE, "Got state %d.\n", state);
1897 hr = IVideoWindow_get_Visible(window, &state);
1898 ok(state == OAFALSE, "Got state %d.\n", state);
1900 ok(!IsWindowVisible(hwnd), "Window should not be visible.\n");
1901 ok(!IsIconic(hwnd), "Window should not be minimized.\n");
1902 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
1904 hr = IVideoWindow_put_WindowState(window, SW_SHOWNA);
1905 ok(hr == S_OK, "Got hr %#x.\n", hr);
1907 hr = IVideoWindow_get_WindowState(window, &state);
1908 ok(hr == S_OK, "Got hr %#x.\n", hr);
1909 ok(state == SW_SHOW, "Got state %d.\n", state);
1911 hr = IVideoWindow_get_Visible(window, &state);
1912 ok(state == OATRUE, "Got state %d.\n", state);
1914 ok(IsWindowVisible(hwnd), "Window should be visible.\n");
1915 ok(!IsIconic(hwnd), "Window should not be minimized.\n");
1916 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
1917 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
1918 top = get_top_window();
1919 ok(top == hwnd, "Got top window %p.\n", top);
1921 hr = IVideoWindow_put_WindowState(window, SW_MINIMIZE);
1922 ok(hr == S_OK, "Got hr %#x.\n", hr);
1924 hr = IVideoWindow_get_WindowState(window, &state);
1925 ok(hr == S_OK, "Got hr %#x.\n", hr);
1926 ok(state == SW_MINIMIZE, "Got state %d.\n", state);
1928 hr = IVideoWindow_get_Visible(window, &state);
1929 ok(state == OATRUE, "Got state %d.\n", state);
1931 ok(IsWindowVisible(hwnd), "Window should be visible.\n");
1932 ok(IsIconic(hwnd), "Window should be minimized.\n");
1933 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
1934 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
1936 hr = IVideoWindow_put_WindowState(window, SW_RESTORE);
1937 ok(hr == S_OK, "Got hr %#x.\n", hr);
1939 hr = IVideoWindow_get_WindowState(window, &state);
1940 ok(hr == S_OK, "Got hr %#x.\n", hr);
1941 ok(state == SW_SHOW, "Got state %d.\n", state);
1943 hr = IVideoWindow_get_Visible(window, &state);
1944 ok(state == OATRUE, "Got state %d.\n", state);
1946 ok(IsWindowVisible(hwnd), "Window should be visible.\n");
1947 ok(!IsIconic(hwnd), "Window should not be minimized.\n");
1948 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
1949 ok(GetActiveWindow() == hwnd, "Got active window %p.\n", GetActiveWindow());
1951 hr = IVideoWindow_put_WindowState(window, SW_MAXIMIZE);
1952 ok(hr == S_OK, "Got hr %#x.\n", hr);
1954 hr = IVideoWindow_get_WindowState(window, &state);
1955 ok(hr == S_OK, "Got hr %#x.\n", hr);
1956 ok(state == SW_MAXIMIZE, "Got state %d.\n", state);
1958 hr = IVideoWindow_get_Visible(window, &state);
1959 ok(state == OATRUE, "Got state %d.\n", state);
1961 ok(IsWindowVisible(hwnd), "Window should be visible.\n");
1962 ok(!IsIconic(hwnd), "Window should be minimized.\n");
1963 ok(IsZoomed(hwnd), "Window should not be maximized.\n");
1964 ok(GetActiveWindow() == hwnd, "Got active window %p.\n", GetActiveWindow());
1966 hr = IVideoWindow_put_WindowState(window, SW_RESTORE);
1967 ok(hr == S_OK, "Got hr %#x.\n", hr);
1969 hr = IVideoWindow_put_WindowState(window, SW_HIDE);
1970 ok(hr == S_OK, "Got hr %#x.\n", hr);
1972 hr = IVideoWindow_get_WindowState(window, &state);
1973 ok(hr == S_OK, "Got hr %#x.\n", hr);
1974 ok(state == SW_HIDE, "Got state %d.\n", state);
1976 hr = IVideoWindow_get_Visible(window, &state);
1977 ok(state == OAFALSE, "Got state %d.\n", state);
1979 ok(!IsWindowVisible(hwnd), "Window should not be visible.\n");
1980 ok(!IsIconic(hwnd), "Window should not be minimized.\n");
1981 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
1982 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
1984 hr = IVideoWindow_put_Visible(window, OATRUE);
1985 ok(hr == S_OK, "Got hr %#x.\n", hr);
1987 hr = IVideoWindow_get_WindowState(window, &state);
1988 ok(hr == S_OK, "Got hr %#x.\n", hr);
1989 ok(state == SW_SHOW, "Got state %d.\n", state);
1991 hr = IVideoWindow_get_Visible(window, &state);
1992 ok(state == OATRUE, "Got state %d.\n", state);
1994 ok(IsWindowVisible(hwnd), "Window should be visible.\n");
1995 ok(!IsIconic(hwnd), "Window should not be minimized.\n");
1996 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
1997 ok(GetActiveWindow() == hwnd, "Got active window %p.\n", GetActiveWindow());
1999 hr = IVideoWindow_put_Visible(window, OAFALSE);
2000 ok(hr == S_OK, "Got hr %#x.\n", hr);
2002 hr = IVideoWindow_get_WindowState(window, &state);
2003 ok(hr == S_OK, "Got hr %#x.\n", hr);
2004 ok(state == SW_HIDE, "Got state %d.\n", state);
2006 hr = IVideoWindow_get_Visible(window, &state);
2007 ok(state == OAFALSE, "Got state %d.\n", state);
2009 ok(!IsWindowVisible(hwnd), "Window should not be visible.\n");
2010 ok(!IsIconic(hwnd), "Window should not be minimized.\n");
2011 ok(!IsZoomed(hwnd), "Window should not be maximized.\n");
2012 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
2014 hr = IVideoWindow_put_WindowState(window, SW_SHOWNA);
2015 ok(hr == S_OK, "Got hr %#x.\n", hr);
2017 hr = IVideoWindow_SetWindowForeground(window, TRUE);
2018 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
2020 SetWindowPos(our_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2021 hr = IVideoWindow_SetWindowForeground(window, OATRUE);
2022 ok(hr == S_OK, "Got hr %#x.\n", hr);
2023 ok(GetActiveWindow() == hwnd, "Got active window %p.\n", GetActiveWindow());
2024 ok(GetFocus() == hwnd, "Got focus window %p.\n", GetFocus());
2025 ok(GetForegroundWindow() == hwnd, "Got foreground window %p.\n", GetForegroundWindow());
2026 top = get_top_window();
2027 ok(top == hwnd, "Got top window %p.\n", top);
2029 hr = IVideoWindow_SetWindowForeground(window, OAFALSE);
2030 ok(hr == S_OK, "Got hr %#x.\n", hr);
2031 ok(GetActiveWindow() == hwnd, "Got active window %p.\n", GetActiveWindow());
2032 ok(GetFocus() == hwnd, "Got focus window %p.\n", GetFocus());
2033 ok(GetForegroundWindow() == hwnd, "Got foreground window %p.\n", GetForegroundWindow());
2034 top = get_top_window();
2035 ok(top == hwnd, "Got top window %p.\n", top);
2037 SetWindowPos(our_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2038 hr = IVideoWindow_SetWindowForeground(window, OAFALSE);
2039 ok(hr == S_OK, "Got hr %#x.\n", hr);
2040 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
2041 ok(GetFocus() == our_hwnd, "Got focus window %p.\n", GetFocus());
2042 ok(GetForegroundWindow() == our_hwnd, "Got foreground window %p.\n", GetForegroundWindow());
2043 top = get_top_window();
2044 ok(top == hwnd, "Got top window %p.\n", top);
2047 static void test_video_window_position(IVideoWindow *window, HWND hwnd, HWND our_hwnd)
2049 LONG left, width, top, height, expect_width, expect_height;
2050 RECT rect = {0, 0, 600, 400};
2051 HWND top_hwnd;
2052 HRESULT hr;
2054 SetWindowPos(our_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2056 AdjustWindowRect(&rect, GetWindowLongA(hwnd, GWL_STYLE), FALSE);
2057 expect_width = rect.right - rect.left;
2058 expect_height = rect.bottom - rect.top;
2060 hr = IVideoWindow_put_Left(window, 0);
2061 ok(hr == S_OK, "Got hr %#x.\n", hr);
2062 hr = IVideoWindow_put_Top(window, 0);
2063 ok(hr == S_OK, "Got hr %#x.\n", hr);
2065 hr = IVideoWindow_get_Left(window, &left);
2066 ok(hr == S_OK, "Got hr %#x.\n", hr);
2067 ok(left == 0, "Got left %d.\n", left);
2068 hr = IVideoWindow_get_Top(window, &top);
2069 ok(hr == S_OK, "Got hr %#x.\n", hr);
2070 ok(top == 0, "Got top %d.\n", top);
2071 hr = IVideoWindow_get_Width(window, &width);
2072 ok(hr == S_OK, "Got hr %#x.\n", hr);
2073 ok(width == expect_width, "Got width %d.\n", width);
2074 hr = IVideoWindow_get_Height(window, &height);
2075 ok(hr == S_OK, "Got hr %#x.\n", hr);
2076 ok(height == expect_height, "Got height %d.\n", height);
2077 hr = IVideoWindow_GetWindowPosition(window, &left, &top, &width, &height);
2078 ok(hr == S_OK, "Got hr %#x.\n", hr);
2079 ok(left == 0, "Got left %d.\n", left);
2080 ok(top == 0, "Got top %d.\n", top);
2081 ok(width == expect_width, "Got width %d.\n", width);
2082 ok(height == expect_height, "Got height %d.\n", height);
2083 GetWindowRect(hwnd, &rect);
2084 ok(rect.left == 0, "Got window left %d.\n", rect.left);
2085 ok(rect.top == 0, "Got window top %d.\n", rect.top);
2086 ok(rect.right == expect_width, "Got window right %d.\n", rect.right);
2087 ok(rect.bottom == expect_height, "Got window bottom %d.\n", rect.bottom);
2089 hr = IVideoWindow_put_Left(window, 10);
2090 ok(hr == S_OK, "Got hr %#x.\n", hr);
2092 hr = IVideoWindow_get_Left(window, &left);
2093 ok(hr == S_OK, "Got hr %#x.\n", hr);
2094 ok(left == 10, "Got left %d.\n", left);
2095 hr = IVideoWindow_get_Top(window, &top);
2096 ok(hr == S_OK, "Got hr %#x.\n", hr);
2097 ok(top == 0, "Got top %d.\n", top);
2098 hr = IVideoWindow_get_Width(window, &width);
2099 ok(hr == S_OK, "Got hr %#x.\n", hr);
2100 ok(width == expect_width, "Got width %d.\n", width);
2101 hr = IVideoWindow_get_Height(window, &height);
2102 ok(hr == S_OK, "Got hr %#x.\n", hr);
2103 ok(height == expect_height, "Got height %d.\n", height);
2104 hr = IVideoWindow_GetWindowPosition(window, &left, &top, &width, &height);
2105 ok(hr == S_OK, "Got hr %#x.\n", hr);
2106 ok(left == 10, "Got left %d.\n", left);
2107 ok(top == 0, "Got top %d.\n", top);
2108 ok(width == expect_width, "Got width %d.\n", width);
2109 ok(height == expect_height, "Got height %d.\n", height);
2110 GetWindowRect(hwnd, &rect);
2111 ok(rect.left == 10, "Got window left %d.\n", rect.left);
2112 ok(rect.top == 0, "Got window top %d.\n", rect.top);
2113 ok(rect.right == 10 + expect_width, "Got window right %d.\n", rect.right);
2114 ok(rect.bottom == expect_height, "Got window bottom %d.\n", rect.bottom);
2116 hr = IVideoWindow_put_Height(window, 200);
2117 ok(hr == S_OK, "Got hr %#x.\n", hr);
2119 hr = IVideoWindow_get_Left(window, &left);
2120 ok(hr == S_OK, "Got hr %#x.\n", hr);
2121 ok(left == 10, "Got left %d.\n", left);
2122 hr = IVideoWindow_get_Top(window, &top);
2123 ok(hr == S_OK, "Got hr %#x.\n", hr);
2124 ok(top == 0, "Got top %d.\n", top);
2125 hr = IVideoWindow_get_Width(window, &width);
2126 ok(hr == S_OK, "Got hr %#x.\n", hr);
2127 ok(width == expect_width, "Got width %d.\n", width);
2128 hr = IVideoWindow_get_Height(window, &height);
2129 ok(hr == S_OK, "Got hr %#x.\n", hr);
2130 ok(height == 200, "Got height %d.\n", height);
2131 hr = IVideoWindow_GetWindowPosition(window, &left, &top, &width, &height);
2132 ok(hr == S_OK, "Got hr %#x.\n", hr);
2133 ok(left == 10, "Got left %d.\n", left);
2134 ok(top == 0, "Got top %d.\n", top);
2135 ok(width == expect_width, "Got width %d.\n", width);
2136 ok(height == 200, "Got height %d.\n", height);
2137 GetWindowRect(hwnd, &rect);
2138 ok(rect.left == 10, "Got window left %d.\n", rect.left);
2139 ok(rect.top == 0, "Got window top %d.\n", rect.top);
2140 ok(rect.right == 10 + expect_width, "Got window right %d.\n", rect.right);
2141 ok(rect.bottom == 200, "Got window bottom %d.\n", rect.bottom);
2143 hr = IVideoWindow_SetWindowPosition(window, 100, 200, 300, 400);
2144 ok(hr == S_OK, "Got hr %#x.\n", hr);
2146 hr = IVideoWindow_get_Left(window, &left);
2147 ok(hr == S_OK, "Got hr %#x.\n", hr);
2148 ok(left == 100, "Got left %d.\n", left);
2149 hr = IVideoWindow_get_Top(window, &top);
2150 ok(hr == S_OK, "Got hr %#x.\n", hr);
2151 ok(top == 200, "Got top %d.\n", top);
2152 hr = IVideoWindow_get_Width(window, &width);
2153 ok(hr == S_OK, "Got hr %#x.\n", hr);
2154 ok(width == 300, "Got width %d.\n", width);
2155 hr = IVideoWindow_get_Height(window, &height);
2156 ok(hr == S_OK, "Got hr %#x.\n", hr);
2157 ok(height == 400, "Got height %d.\n", height);
2158 hr = IVideoWindow_GetWindowPosition(window, &left, &top, &width, &height);
2159 ok(hr == S_OK, "Got hr %#x.\n", hr);
2160 ok(left == 100, "Got left %d.\n", left);
2161 ok(top == 200, "Got top %d.\n", top);
2162 ok(width == 300, "Got width %d.\n", width);
2163 ok(height == 400, "Got height %d.\n", height);
2164 GetWindowRect(hwnd, &rect);
2165 ok(rect.left == 100, "Got window left %d.\n", rect.left);
2166 ok(rect.top == 200, "Got window top %d.\n", rect.top);
2167 ok(rect.right == 400, "Got window right %d.\n", rect.right);
2168 ok(rect.bottom == 600, "Got window bottom %d.\n", rect.bottom);
2170 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
2171 top_hwnd = get_top_window();
2172 ok(top_hwnd == our_hwnd, "Got top window %p.\n", top_hwnd);
2175 static void test_video_window_owner(IVideoWindow *window, HWND hwnd, HWND our_hwnd)
2177 HWND parent, top_hwnd;
2178 LONG style, state;
2179 OAHWND oahwnd;
2180 HRESULT hr;
2182 SetWindowPos(our_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
2184 hr = IVideoWindow_get_Owner(window, &oahwnd);
2185 ok(hr == S_OK, "Got hr %#x.\n", hr);
2186 ok(!oahwnd, "Got owner %#lx.\n", oahwnd);
2188 parent = GetAncestor(hwnd, GA_PARENT);
2189 ok(parent == GetDesktopWindow(), "Got parent %p.\n", parent);
2190 style = GetWindowLongA(hwnd, GWL_STYLE);
2191 ok(!(style & WS_CHILD), "Got style %#x.\n", style);
2193 hr = IVideoWindow_put_Owner(window, (OAHWND)our_hwnd);
2194 ok(hr == S_OK, "Got hr %#x.\n", hr);
2196 hr = IVideoWindow_get_Owner(window, &oahwnd);
2197 ok(hr == S_OK, "Got hr %#x.\n", hr);
2198 ok(oahwnd == (OAHWND)our_hwnd, "Got owner %#lx.\n", oahwnd);
2200 parent = GetAncestor(hwnd, GA_PARENT);
2201 ok(parent == our_hwnd, "Got parent %p.\n", parent);
2202 style = GetWindowLongA(hwnd, GWL_STYLE);
2203 ok((style & WS_CHILD), "Got style %#x.\n", style);
2205 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
2206 top_hwnd = get_top_window();
2207 ok(top_hwnd == our_hwnd, "Got top window %p.\n", top_hwnd);
2209 ShowWindow(our_hwnd, SW_HIDE);
2211 hr = IVideoWindow_put_Visible(window, OATRUE);
2212 ok(hr == S_OK, "Got hr %#x.\n", hr);
2214 hr = IVideoWindow_get_Visible(window, &state);
2215 ok(hr == S_OK, "Got hr %#x.\n", hr);
2216 ok(state == OAFALSE, "Got state %d.\n", state);
2218 hr = IVideoWindow_put_Owner(window, 0);
2219 ok(hr == S_OK, "Got hr %#x.\n", hr);
2221 hr = IVideoWindow_get_Owner(window, &oahwnd);
2222 ok(hr == S_OK, "Got hr %#x.\n", hr);
2223 ok(!oahwnd, "Got owner %#lx.\n", oahwnd);
2225 parent = GetAncestor(hwnd, GA_PARENT);
2226 ok(parent == GetDesktopWindow(), "Got parent %p.\n", parent);
2227 style = GetWindowLongA(hwnd, GWL_STYLE);
2228 ok(!(style & WS_CHILD), "Got style %#x.\n", style);
2230 ok(GetActiveWindow() == hwnd, "Got active window %p.\n", GetActiveWindow());
2231 top_hwnd = get_top_window();
2232 ok(top_hwnd == hwnd, "Got top window %p.\n", top_hwnd);
2234 hr = IVideoWindow_get_Visible(window, &state);
2235 ok(hr == S_OK, "Got hr %#x.\n", hr);
2236 ok(state == OATRUE, "Got state %d.\n", state);
2239 struct notify_message_params
2241 IVideoWindow *window;
2242 HWND hwnd;
2243 UINT message;
2246 static DWORD CALLBACK notify_message_proc(void *arg)
2248 const struct notify_message_params *params = arg;
2249 HRESULT hr = IVideoWindow_NotifyOwnerMessage(params->window, (OAHWND)params->hwnd, params->message, 0, 0);
2250 ok(hr == S_OK, "Got hr %#x.\n", hr);
2251 return 0;
2254 static void test_video_window_messages(IVideoWindow *window, HWND hwnd, HWND our_hwnd)
2256 struct notify_message_params params;
2257 unsigned int i;
2258 OAHWND oahwnd;
2259 HANDLE thread;
2260 HRESULT hr;
2261 BOOL ret;
2262 MSG msg;
2264 static UINT drain_tests[] =
2266 WM_MOUSEACTIVATE,
2267 WM_NCLBUTTONDOWN,
2268 WM_NCLBUTTONUP,
2269 WM_NCLBUTTONDBLCLK,
2270 WM_NCRBUTTONDOWN,
2271 WM_NCRBUTTONUP,
2272 WM_NCRBUTTONDBLCLK,
2273 WM_NCMBUTTONDOWN,
2274 WM_NCMBUTTONUP,
2275 WM_NCMBUTTONDBLCLK,
2276 WM_KEYDOWN,
2277 WM_KEYUP,
2278 WM_MOUSEMOVE,
2279 WM_LBUTTONDOWN,
2280 WM_LBUTTONUP,
2281 WM_LBUTTONDBLCLK,
2282 WM_RBUTTONDOWN,
2283 WM_RBUTTONUP,
2284 WM_RBUTTONDBLCLK,
2285 WM_MBUTTONDOWN,
2286 WM_MBUTTONUP,
2287 WM_MBUTTONDBLCLK,
2290 flush_events();
2292 hr = IVideoWindow_get_MessageDrain(window, &oahwnd);
2293 ok(hr == S_OK, "Got hr %#x.\n", hr);
2294 ok(!oahwnd, "Got window %#lx.\n", oahwnd);
2296 hr = IVideoWindow_put_MessageDrain(window, (OAHWND)our_hwnd);
2297 ok(hr == S_OK, "Got hr %#x.\n", hr);
2299 hr = IVideoWindow_get_MessageDrain(window, &oahwnd);
2300 ok(hr == S_OK, "Got hr %#x.\n", hr);
2301 ok(oahwnd == (OAHWND)our_hwnd, "Got window %#lx.\n", oahwnd);
2303 for (i = 0; i < ARRAY_SIZE(drain_tests); ++i)
2305 SendMessageA(hwnd, drain_tests[i], 0xdeadbeef, 0);
2306 ret = PeekMessageA(&msg, 0, drain_tests[i], drain_tests[i], PM_REMOVE);
2307 ok(ret, "Expected a message.\n");
2308 ok(msg.hwnd == our_hwnd, "Got hwnd %p.\n", msg.hwnd);
2309 ok(msg.message == drain_tests[i], "Got message %#x.\n", msg.message);
2310 ok(msg.wParam == 0xdeadbeef, "Got wparam %#lx.\n", msg.wParam);
2311 ok(!msg.lParam, "Got lparam %#lx.\n", msg.lParam);
2312 DispatchMessageA(&msg);
2314 ret = PeekMessageA(&msg, 0, drain_tests[i], drain_tests[i], PM_REMOVE);
2315 ok(!ret, "Got unexpected message %#x.\n", msg.message);
2318 hr = IVideoWindow_put_MessageDrain(window, 0);
2319 ok(hr == S_OK, "Got hr %#x.\n", hr);
2321 hr = IVideoWindow_put_Owner(window, (OAHWND)our_hwnd);
2322 ok(hr == S_OK, "Got hr %#x.\n", hr);
2324 flush_events();
2326 hr = IVideoWindow_NotifyOwnerMessage(window, (OAHWND)our_hwnd, WM_SYSCOLORCHANGE, 0, 0);
2327 ok(hr == S_OK, "Got hr %#x.\n", hr);
2329 ret = GetQueueStatus(QS_SENDMESSAGE | QS_POSTMESSAGE);
2330 ok(!ret, "Got unexpected status %#x.\n", ret);
2332 hr = IVideoWindow_NotifyOwnerMessage(window, (OAHWND)our_hwnd, WM_SETCURSOR,
2333 (WPARAM)hwnd, MAKELONG(HTCLIENT, WM_MOUSEMOVE));
2334 ok(hr == S_OK, "Got hr %#x.\n", hr);
2336 ret = GetQueueStatus(QS_SENDMESSAGE | QS_POSTMESSAGE);
2337 ok(!ret, "Got unexpected status %#x.\n", ret);
2339 params.window = window;
2340 params.hwnd = our_hwnd;
2341 params.message = WM_SYSCOLORCHANGE;
2342 thread = CreateThread(NULL, 0, notify_message_proc, &params, 0, NULL);
2343 ok(WaitForSingleObject(thread, 100) == WAIT_TIMEOUT, "Thread should block.\n");
2344 ret = GetQueueStatus(QS_SENDMESSAGE | QS_POSTMESSAGE);
2345 ok(ret == ((QS_SENDMESSAGE << 16) | QS_SENDMESSAGE), "Got unexpected status %#x.\n", ret);
2347 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2348 ok(!WaitForSingleObject(thread, 1000), "Wait timed out.\n");
2349 CloseHandle(thread);
2351 params.message = WM_SETCURSOR;
2352 thread = CreateThread(NULL, 0, notify_message_proc, &params, 0, NULL);
2353 ok(!WaitForSingleObject(thread, 1000), "Thread should not block.\n");
2354 CloseHandle(thread);
2355 ret = GetQueueStatus(QS_SENDMESSAGE | QS_POSTMESSAGE);
2356 ok(!ret, "Got unexpected status %#x.\n", ret);
2358 hr = IVideoWindow_put_Owner(window, 0);
2359 ok(hr == S_OK, "Got hr %#x.\n", hr);
2362 static void test_video_window_autoshow(IVideoWindow *window, IFilterGraph2 *graph, HWND hwnd)
2364 IMediaControl *control;
2365 HRESULT hr;
2366 LONG l;
2368 IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
2370 hr = IVideoWindow_get_AutoShow(window, &l);
2371 ok(hr == S_OK, "Got hr %#x.\n", hr);
2372 ok(l == OATRUE, "Got %d.\n", l);
2374 hr = IVideoWindow_put_Visible(window, OAFALSE);
2375 ok(hr == S_OK, "Got hr %#x.\n", hr);
2377 hr = IMediaControl_Pause(control);
2378 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
2380 hr = IVideoWindow_get_Visible(window, &l);
2381 ok(hr == S_OK, "Got hr %#x.\n", hr);
2382 ok(l == OATRUE, "Got %d.\n", l);
2384 hr = IMediaControl_Stop(control);
2385 ok(hr == S_OK, "Got hr %#x.\n", hr);
2387 hr = IVideoWindow_get_Visible(window, &l);
2388 ok(hr == S_OK, "Got hr %#x.\n", hr);
2389 ok(l == OATRUE, "Got %d.\n", l);
2391 hr = IVideoWindow_put_AutoShow(window, OAFALSE);
2392 ok(hr == S_OK, "Got hr %#x.\n", hr);
2394 hr = IVideoWindow_put_Visible(window, OAFALSE);
2395 ok(hr == S_OK, "Got hr %#x.\n", hr);
2397 hr = IMediaControl_Pause(control);
2398 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
2400 hr = IVideoWindow_get_Visible(window, &l);
2401 ok(hr == S_OK, "Got hr %#x.\n", hr);
2402 ok(l == OAFALSE, "Got %d.\n", l);
2404 hr = IMediaControl_Stop(control);
2405 ok(hr == S_OK, "Got hr %#x.\n", hr);
2407 IMediaControl_Release(control);
2410 static void test_video_window(void)
2412 ALLOCATOR_PROPERTIES req_props = {1, 600 * 400 * 4, 1, 0}, ret_props;
2413 VIDEOINFOHEADER vih =
2415 .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
2416 .bmiHeader.biBitCount = 32,
2417 .bmiHeader.biWidth = 600,
2418 .bmiHeader.biHeight = 400,
2419 .bmiHeader.biPlanes = 1,
2420 .bmiHeader.biCompression = BI_RGB,
2422 AM_MEDIA_TYPE req_mt =
2424 .majortype = MEDIATYPE_Video,
2425 .subtype = MEDIASUBTYPE_RGB32,
2426 .formattype = FORMAT_VideoInfo,
2427 .cbFormat = sizeof(vih),
2428 .pbFormat = (BYTE *)&vih,
2430 IFilterGraph2 *graph = create_graph();
2431 WNDCLASSA window_class = {0};
2432 struct testfilter source;
2433 IMemAllocator *allocator;
2434 MONITORINFO monitorinfo;
2435 IMediaControl *control;
2436 LONG width, height, l;
2437 IVideoWindow *window;
2438 IMemInputPin *input;
2439 IBaseFilter *filter;
2440 HWND hwnd, our_hwnd;
2441 IOverlay *overlay;
2442 BSTR caption;
2443 HRESULT hr;
2444 DWORD tid;
2445 ULONG ref;
2446 IPin *pin;
2447 RECT rect;
2449 window_class.lpszClassName = "wine_test_class";
2450 window_class.lpfnWndProc = window_proc;
2451 RegisterClassA(&window_class);
2452 our_hwnd = CreateWindowA("wine_test_class", "test window", WS_VISIBLE | WS_OVERLAPPEDWINDOW,
2453 100, 200, 300, 400, NULL, NULL, NULL, NULL);
2454 flush_events();
2456 filter = create_vmr9(VMR9Mode_Windowed);
2457 flush_events();
2459 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
2461 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
2462 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input);
2464 hr = IPin_QueryInterface(pin, &IID_IOverlay, (void **)&overlay);
2465 ok(hr == S_OK, "Got hr %#x.\n", hr);
2467 hr = IOverlay_GetWindowHandle(overlay, &hwnd);
2468 ok(hr == S_OK, "Got hr %#x.\n", hr);
2469 if (winetest_debug > 1) trace("ours %p, theirs %p\n", our_hwnd, hwnd);
2470 GetWindowRect(hwnd, &rect);
2472 tid = GetWindowThreadProcessId(hwnd, NULL);
2473 ok(tid == GetCurrentThreadId(), "Expected tid %#x, got %#x.\n", GetCurrentThreadId(), tid);
2475 hr = IBaseFilter_QueryInterface(filter, &IID_IVideoWindow, (void **)&window);
2476 ok(hr == S_OK, "Got hr %#x.\n", hr);
2478 hr = IVideoWindow_get_Caption(window, &caption);
2479 todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
2481 hr = IVideoWindow_get_WindowStyle(window, &l);
2482 todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
2484 hr = IVideoWindow_get_AutoShow(window, &l);
2485 todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
2487 testfilter_init(&source);
2488 IFilterGraph2_AddFilter(graph, &source.filter.IBaseFilter_iface, NULL);
2489 IFilterGraph2_AddFilter(graph, filter, NULL);
2490 IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
2491 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
2492 if (hr == E_FAIL)
2494 skip("Got E_FAIL when connecting.\n");
2495 goto out;
2497 ok(hr == S_OK, "Got hr %#x.\n", hr);
2499 hr = IMemInputPin_GetAllocator(input, &allocator);
2500 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
2501 if (hr == S_OK)
2503 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
2504 ok(hr == S_OK, "Got hr %#x.\n", hr);
2505 ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
2506 hr = IMemAllocator_Commit(allocator);
2507 ok(hr == S_OK, "Got hr %#x.\n", hr);
2508 IMemAllocator_Release(allocator);
2511 ok(GetActiveWindow() == our_hwnd, "Got active window %p.\n", GetActiveWindow());
2513 test_video_window_caption(window, hwnd);
2514 test_video_window_style(window, hwnd, our_hwnd);
2515 test_video_window_state(window, hwnd, our_hwnd);
2516 test_video_window_position(window, hwnd, our_hwnd);
2517 test_video_window_autoshow(window, graph, hwnd);
2518 test_video_window_owner(window, hwnd, our_hwnd);
2519 test_video_window_messages(window, hwnd, our_hwnd);
2521 hr = IVideoWindow_put_FullScreenMode(window, OATRUE);
2522 ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
2523 hr = IVideoWindow_get_FullScreenMode(window, &l);
2524 ok(hr == E_NOTIMPL, "Got hr %#x.\n", hr);
2526 hr = IVideoWindow_GetMinIdealImageSize(window, &width, &height);
2527 todo_wine ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
2528 hr = IVideoWindow_GetMaxIdealImageSize(window, &width, &height);
2529 todo_wine ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
2531 hr = IMediaControl_Pause(control);
2532 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
2534 monitorinfo.cbSize = sizeof(monitorinfo);
2535 GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &monitorinfo);
2537 hr = IVideoWindow_GetMinIdealImageSize(window, &width, &height);
2538 ok(hr == S_OK, "Got hr %#x.\n", hr);
2539 todo_wine ok(width == 1, "Got width %d.\n", width);
2540 todo_wine ok(height == 1, "Got height %d.\n", height);
2541 hr = IVideoWindow_GetMaxIdealImageSize(window, &width, &height);
2542 ok(hr == S_OK, "Got hr %#x.\n", hr);
2543 todo_wine ok(width == monitorinfo.rcMonitor.right + 1, "Expected width %d, got %d.\n",
2544 monitorinfo.rcMonitor.right + 1, width);
2545 todo_wine ok(height == monitorinfo.rcMonitor.bottom + 1, "Expected height %d, got %d.\n",
2546 monitorinfo.rcMonitor.bottom + 1, height);
2548 hr = IMediaControl_Stop(control);
2549 ok(hr == S_OK, "Got hr %#x.\n", hr);
2551 out:
2552 IMediaControl_Release(control);
2553 IFilterGraph2_Release(graph);
2554 IVideoWindow_Release(window);
2555 IOverlay_Release(overlay);
2556 IMemInputPin_Release(input);
2557 IPin_Release(pin);
2558 ref = IBaseFilter_Release(filter);
2559 ok(!ref, "Got outstanding refcount %d.\n", ref);
2560 ref = IBaseFilter_Release(&source.filter.IBaseFilter_iface);
2561 ok(!ref, "Got outstanding refcount %d.\n", ref);
2562 DestroyWindow(our_hwnd);
2565 static IDirect3DDevice9 *create_device(HWND window)
2567 D3DPRESENT_PARAMETERS present_parameters =
2569 .Windowed = TRUE,
2570 .hDeviceWindow = window,
2571 .SwapEffect = D3DSWAPEFFECT_DISCARD,
2572 .BackBufferWidth = 640,
2573 .BackBufferHeight = 480,
2574 .BackBufferFormat = D3DFMT_A8R8G8B8,
2576 IDirect3DDevice9 *device;
2577 IDirect3D9 *d3d;
2578 HRESULT hr;
2580 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2581 ok(!!d3d, "Failed to create a D3D object.\n");
2583 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
2584 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
2585 IDirect3D9_Release(d3d);
2586 if (FAILED(hr))
2588 skip("Failed to create a 3D device, hr %#x.\n", hr);
2589 return NULL;
2591 return device;
2594 static void test_allocate_surface_helper(void)
2596 VMR9AllocationInfo info =
2598 .dwFlags = VMR9AllocFlag_OffscreenSurface,
2599 .dwWidth = 32,
2600 .dwHeight = 16,
2601 .Format = D3DFMT_X8R8G8B8,
2602 .Pool = D3DPOOL_DEFAULT,
2603 .MinBuffers = 2,
2604 .szAspectRatio = {32, 16},
2605 .szNativeSize = {32, 16},
2607 IBaseFilter *filter = create_vmr9(VMR9Mode_Renderless);
2608 IVMRSurfaceAllocatorNotify9 *notify;
2609 IDirect3DSurface9 *surfaces[2] = {};
2610 IDirect3DDevice9 *device, *device2;
2611 RECT rect = {0, 0, 640, 480};
2612 IDirect3DTexture9 *container;
2613 D3DSURFACE_DESC desc;
2614 DWORD count;
2615 HWND window;
2616 HRESULT hr;
2617 ULONG ref;
2619 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
2620 window = CreateWindowA("static", "quartz_test", WS_OVERLAPPEDWINDOW, 0, 0,
2621 rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
2622 if (!(device = create_device(window)))
2624 IBaseFilter_Release(filter);
2625 DestroyWindow(window);
2626 return;
2629 IBaseFilter_QueryInterface(filter, &IID_IVMRSurfaceAllocatorNotify9, (void **)&notify);
2631 count = 2;
2632 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2633 todo_wine ok(hr == E_FAIL, "Got hr %#x.\n", hr);
2635 hr = IVMRSurfaceAllocatorNotify9_SetD3DDevice(notify, device, MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY));
2636 if (hr == E_NOINTERFACE)
2638 win_skip("Direct3D does not support video rendering.\n");
2639 goto out;
2641 ok(hr == S_OK, "Got hr %#x.\n", hr);
2643 if (0) /* crashes on Windows */
2645 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, NULL, &count, surfaces);
2646 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
2648 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, NULL, surfaces);
2649 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
2652 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, NULL);
2653 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
2655 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2656 ok(hr == S_OK, "Got hr %#x.\n", hr);
2657 ok(count == 2, "Got count %u.\n", count);
2658 ok(!!surfaces[0], "Surface 0 was not allocated.\n");
2659 ok(!!surfaces[1], "Surface 1 was not allocated.\n");
2661 hr = IDirect3DSurface9_GetDevice(surfaces[0], &device2);
2662 ok(hr == D3D_OK, "Got hr %#x.\n", hr);
2663 ok(device2 == device, "Devices did not match.\n");
2664 IDirect3DDevice9_Release(device2);
2666 hr = IDirect3DSurface9_GetContainer(surfaces[0], &IID_IDirect3DTexture9, (void **)&container);
2667 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
2669 hr = IDirect3DSurface9_GetDesc(surfaces[0], &desc);
2670 ok(hr == D3D_OK, "Got hr %#x.\n", hr);
2671 ok(desc.Format == info.Format, "Got format %#x.\n", desc.Format);
2672 ok(desc.Type == D3DRTYPE_SURFACE, "Got type %u.\n", desc.Type);
2673 ok(!desc.Usage, "Got usage %#x.\n", desc.Usage);
2674 ok(desc.Pool == D3DPOOL_DEFAULT, "Got pool %u.\n", desc.Pool);
2675 ok(desc.MultiSampleType == D3DMULTISAMPLE_NONE, "Got multisample type %u.\n", desc.MultiSampleType);
2676 ok(!desc.MultiSampleQuality, "Got multisample quality %u.\n", desc.MultiSampleQuality);
2677 ok(desc.Width == 32, "Got width %u.\n", desc.Width);
2678 ok(desc.Height == 16, "Got height %u.\n", desc.Height);
2680 IDirect3DSurface9_Release(surfaces[0]);
2681 IDirect3DSurface9_Release(surfaces[1]);
2683 surfaces[0] = surfaces[1] = NULL;
2684 count = 1;
2685 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2686 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
2687 todo_wine ok(!count, "Got count %u.\n", count);
2688 ok(!surfaces[0], "Surface 0 was allocated.\n");
2689 ok(!surfaces[1], "Surface 1 was allocated.\n");
2691 count = 2;
2692 info.MinBuffers = 1;
2693 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2694 ok(hr == S_OK, "Got hr %#x.\n", hr);
2695 ok(count == 2, "Got count %u.\n", count);
2696 ok(!!surfaces[0], "Surface 0 was not allocated.\n");
2697 ok(!!surfaces[1], "Surface 1 was not allocated.\n");
2698 IDirect3DSurface9_Release(surfaces[0]);
2699 IDirect3DSurface9_Release(surfaces[1]);
2701 count = 2;
2702 info.dwFlags = VMR9AllocFlag_TextureSurface;
2703 surfaces[0] = surfaces[1] = NULL;
2704 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2705 ok(hr == S_OK, "Got hr %#x.\n", hr);
2706 ok(count == 2, "Got count %u.\n", count);
2707 ok(!!surfaces[0], "Surface 0 was not allocated.\n");
2708 ok(!!surfaces[1], "Surface 1 was not allocated.\n");
2710 hr = IDirect3DSurface9_GetDevice(surfaces[0], &device2);
2711 ok(hr == D3D_OK, "Got hr %#x.\n", hr);
2712 ok(device2 == device, "Devices did not match.\n");
2713 IDirect3DDevice9_Release(device2);
2715 hr = IDirect3DSurface9_GetContainer(surfaces[0], &IID_IDirect3DTexture9, (void **)&container);
2716 ok(hr == D3D_OK, "Got hr %#x.\n", hr);
2717 IDirect3DTexture9_Release(container);
2719 hr = IDirect3DSurface9_GetDesc(surfaces[1], &desc);
2720 ok(hr == D3D_OK, "Got hr %#x.\n", hr);
2721 ok(desc.Format == info.Format, "Got format %#x.\n", desc.Format);
2722 ok(desc.Type == D3DRTYPE_SURFACE, "Got type %u.\n", desc.Type);
2723 ok(desc.Usage == D3DUSAGE_DYNAMIC, "Got usage %#x.\n", desc.Usage);
2724 ok(desc.Pool == D3DPOOL_DEFAULT, "Got pool %u.\n", desc.Pool);
2725 ok(desc.MultiSampleType == D3DMULTISAMPLE_NONE, "Got multisample type %u.\n", desc.MultiSampleType);
2726 ok(!desc.MultiSampleQuality, "Got multisample quality %u.\n", desc.MultiSampleQuality);
2727 ok(desc.Width == 32, "Got width %u.\n", desc.Width);
2728 ok(desc.Height == 16, "Got height %u.\n", desc.Height);
2730 IDirect3DSurface9_Release(surfaces[0]);
2731 IDirect3DSurface9_Release(surfaces[1]);
2733 info.Format = D3DFMT_R8G8B8;
2734 surfaces[0] = surfaces[1] = NULL;
2735 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2736 ok(hr == D3DERR_INVALIDCALL, "Got hr %#x.\n", hr);
2737 ok(!count, "Got count %u.\n", count);
2738 ok(!surfaces[0], "Surface 0 was allocated.\n");
2739 ok(!surfaces[1], "Surface 1 was allocated.\n");
2741 info.Format = 0;
2742 info.dwFlags = VMR9AllocFlag_3DRenderTarget;
2743 count = 1;
2744 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2745 ok(hr == S_OK, "Got hr %#x.\n", hr);
2746 ok(count == 1, "Got count %u.\n", count);
2747 ok(!!surfaces[0], "Surface 0 was not allocated.\n");
2748 ok(info.Format != 0, "Expected a format.\n");
2750 hr = IDirect3DSurface9_GetDesc(surfaces[0], &desc);
2751 ok(hr == D3D_OK, "Got hr %#x.\n", hr);
2752 ok(desc.Format == info.Format, "Expected format %#x, got %#x.\n", info.Format, desc.Format);
2753 ok(desc.Type == D3DRTYPE_SURFACE, "Got type %u.\n", desc.Type);
2754 ok(desc.Usage == D3DUSAGE_RENDERTARGET, "Got usage %#x.\n", desc.Usage);
2755 ok(desc.Pool == D3DPOOL_DEFAULT, "Got pool %u.\n", desc.Pool);
2756 ok(desc.MultiSampleType == D3DMULTISAMPLE_NONE, "Got multisample type %u.\n", desc.MultiSampleType);
2757 ok(!desc.MultiSampleQuality, "Got multisample quality %u.\n", desc.MultiSampleQuality);
2758 ok(desc.Width == 32, "Got width %u.\n", desc.Width);
2759 ok(desc.Height == 16, "Got height %u.\n", desc.Height);
2761 IDirect3DSurface9_Release(surfaces[0]);
2763 info.Format = D3DFMT_A8R8G8B8;
2764 info.dwFlags = VMR9AllocFlag_OffscreenSurface | VMR9AllocFlag_TextureSurface;
2765 count = 1;
2766 hr = IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(notify, &info, &count, surfaces);
2767 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
2768 ok(count == 1, "Got count %u.\n", count);
2770 out:
2771 IVMRSurfaceAllocatorNotify9_Release(notify);
2772 ref = IBaseFilter_Release(filter);
2773 ok(!ref, "Got outstanding refcount %d.\n", ref);
2774 ref = IDirect3DDevice9_Release(device);
2775 ok(!ref, "Got outstanding refcount %d.\n", ref);
2776 DestroyWindow(window);
2779 struct presenter
2781 IVMRSurfaceAllocator9 IVMRSurfaceAllocator9_iface;
2782 IVMRImagePresenter9 IVMRImagePresenter9_iface;
2783 LONG refcount;
2785 D3DFORMAT format;
2786 DWORD accept_flags;
2787 IDirect3DSurface9 *surfaces[5];
2788 IVMRSurfaceAllocatorNotify9 *notify;
2789 unsigned int got_PresentImage, got_TerminateDevice;
2792 static struct presenter *impl_from_IVMRImagePresenter9(IVMRImagePresenter9 *iface)
2794 return CONTAINING_RECORD(iface, struct presenter, IVMRImagePresenter9_iface);
2797 static HRESULT WINAPI presenter_QueryInterface(IVMRImagePresenter9 *iface, REFIID iid, void **out)
2799 struct presenter *presenter = impl_from_IVMRImagePresenter9(iface);
2800 return IVMRSurfaceAllocator9_QueryInterface(&presenter->IVMRSurfaceAllocator9_iface, iid, out);
2803 static ULONG WINAPI presenter_AddRef(IVMRImagePresenter9 *iface)
2805 struct presenter *presenter = impl_from_IVMRImagePresenter9(iface);
2806 return IVMRSurfaceAllocator9_AddRef(&presenter->IVMRSurfaceAllocator9_iface);
2809 static ULONG WINAPI presenter_Release(IVMRImagePresenter9 *iface)
2811 struct presenter *presenter = impl_from_IVMRImagePresenter9(iface);
2812 return IVMRSurfaceAllocator9_Release(&presenter->IVMRSurfaceAllocator9_iface);
2815 static HRESULT WINAPI presenter_StartPresenting(IVMRImagePresenter9 *iface, DWORD_PTR cookie)
2817 if (winetest_debug > 1) trace("StartPresenting()\n");
2818 ok(cookie == 0xabacab, "Got cookie %#lx.\n", cookie);
2819 return E_NOTIMPL;
2822 static HRESULT WINAPI presenter_StopPresenting(IVMRImagePresenter9 *iface, DWORD_PTR cookie)
2824 if (winetest_debug > 1) trace("StopPresenting()\n");
2825 ok(cookie == 0xabacab, "Got cookie %#lx.\n", cookie);
2826 return E_NOTIMPL;
2829 static HRESULT WINAPI presenter_PresentImage(IVMRImagePresenter9 *iface, DWORD_PTR cookie, VMR9PresentationInfo *info)
2831 struct presenter *presenter = impl_from_IVMRImagePresenter9(iface);
2832 static const RECT rect;
2834 if (winetest_debug > 1) trace("PresentImage()\n");
2835 ok(cookie == 0xabacab, "Got cookie %#lx.\n", cookie);
2836 todo_wine ok(info->dwFlags == VMR9Sample_TimeValid, "Got flags %#x.\n", info->dwFlags);
2837 ok(!info->rtStart, "Got start time %s.\n", wine_dbgstr_longlong(info->rtStart));
2838 ok(info->rtEnd == 10000000, "Got end time %s.\n", wine_dbgstr_longlong(info->rtEnd));
2839 todo_wine ok(info->szAspectRatio.cx == 120, "Got aspect ratio width %d.\n", info->szAspectRatio.cx);
2840 todo_wine ok(info->szAspectRatio.cy == 60, "Got aspect ratio height %d.\n", info->szAspectRatio.cy);
2841 ok(EqualRect(&info->rcSrc, &rect), "Got source rect %s.\n", wine_dbgstr_rect(&info->rcSrc));
2842 ok(EqualRect(&info->rcDst, &rect), "Got dest rect %s.\n", wine_dbgstr_rect(&info->rcDst));
2843 ok(!info->dwReserved1, "Got dwReserved1 %#x.\n", info->dwReserved1);
2844 ok(!info->dwReserved2, "Got dwReserved2 %#x.\n", info->dwReserved2);
2846 ++presenter->got_PresentImage;
2847 return S_OK;
2850 static const IVMRImagePresenter9Vtbl presenter_vtbl =
2852 presenter_QueryInterface,
2853 presenter_AddRef,
2854 presenter_Release,
2855 presenter_StartPresenting,
2856 presenter_StopPresenting,
2857 presenter_PresentImage,
2860 static struct presenter *impl_from_IVMRSurfaceAllocator9(IVMRSurfaceAllocator9 *iface)
2862 return CONTAINING_RECORD(iface, struct presenter, IVMRSurfaceAllocator9_iface);
2865 static HRESULT WINAPI allocator_QueryInterface(IVMRSurfaceAllocator9 *iface, REFIID iid, void **out)
2867 struct presenter *presenter = impl_from_IVMRSurfaceAllocator9(iface);
2869 if (winetest_debug > 1) trace("QueryInterface(%s)\n", wine_dbgstr_guid(iid));
2871 if (IsEqualGUID(iid, &IID_IVMRImagePresenter9))
2873 *out = &presenter->IVMRImagePresenter9_iface;
2874 IVMRImagePresenter9_AddRef(&presenter->IVMRImagePresenter9_iface);
2875 return S_OK;
2877 ok(!IsEqualGUID(iid, &IID_IVMRSurfaceAllocatorEx9), "Unexpected query for IVMRSurfaceAllocatorEx9.\n");
2878 *out = NULL;
2879 return E_NOTIMPL;
2882 static ULONG WINAPI allocator_AddRef(IVMRSurfaceAllocator9 *iface)
2884 struct presenter *presenter = impl_from_IVMRSurfaceAllocator9(iface);
2885 return InterlockedIncrement(&presenter->refcount);
2888 static ULONG WINAPI allocator_Release(IVMRSurfaceAllocator9 *iface)
2890 struct presenter *presenter = impl_from_IVMRSurfaceAllocator9(iface);
2891 return InterlockedDecrement(&presenter->refcount);
2894 static HRESULT WINAPI allocator_InitializeDevice(IVMRSurfaceAllocator9 *iface,
2895 DWORD_PTR cookie, VMR9AllocationInfo *info, DWORD *buffer_count)
2897 struct presenter *presenter = impl_from_IVMRSurfaceAllocator9(iface);
2899 if (winetest_debug > 1) trace("InitializeDevice(flags %#x, format %u)\n",
2900 info->dwFlags, info->Format);
2901 ok(cookie == 0xabacab, "Got cookie %#lx.\n", cookie);
2902 ok(info->dwWidth == 32, "Got width %u.\n", info->dwWidth);
2903 ok(info->dwHeight == 16, "Got height %u.\n", info->dwHeight);
2904 todo_wine ok(info->MinBuffers == 5, "Got buffer count %u.\n", info->MinBuffers);
2905 ok(info->Pool == D3DPOOL_DEFAULT, "Got pool %u\n", info->Pool);
2906 todo_wine ok(info->szAspectRatio.cx == 120, "Got aspect ratio width %d.\n", info->szAspectRatio.cx);
2907 todo_wine ok(info->szAspectRatio.cy == 60, "Got aspect ratio height %d.\n", info->szAspectRatio.cy);
2908 ok(info->szNativeSize.cx == 32, "Got native width %d.\n", info->szNativeSize.cx);
2909 ok(info->szNativeSize.cy == 16, "Got native height %d.\n", info->szNativeSize.cy);
2910 todo_wine ok(*buffer_count == 5, "Got buffer count %u.\n", *buffer_count);
2912 presenter->format = info->Format;
2914 if (info->dwFlags != presenter->accept_flags)
2915 return 0xdeadbeef;
2916 return IVMRSurfaceAllocatorNotify9_AllocateSurfaceHelper(presenter->notify,
2917 info, buffer_count, presenter->surfaces);
2920 static HRESULT WINAPI allocator_TerminateDevice(IVMRSurfaceAllocator9 *iface, DWORD_PTR cookie)
2922 struct presenter *presenter = impl_from_IVMRSurfaceAllocator9(iface);
2924 if (winetest_debug > 1) trace("TerminateDevice()\n");
2925 ok(cookie == 0xabacab, "Got cookie %#lx.\n", cookie);
2926 /* Don't dereference the surfaces here, to mimic How to Survive. */
2927 ++presenter->got_TerminateDevice;
2928 return E_NOTIMPL;
2931 static HRESULT WINAPI allocator_GetSurface(IVMRSurfaceAllocator9 *iface,
2932 DWORD_PTR cookie, DWORD index, DWORD flags, IDirect3DSurface9 **surface)
2934 struct presenter *presenter = impl_from_IVMRSurfaceAllocator9(iface);
2936 if (winetest_debug > 1) trace("GetSurface(index %u)\n", index);
2937 ok(cookie == 0xabacab, "Got cookie %#lx.\n", cookie);
2938 ok(!flags, "Got flags %#x.\n", flags);
2939 ok(index < 5, "Got index %u.\n", index);
2941 /* Don't reference the surface here, to mimic How to Survive. */
2942 *surface = presenter->surfaces[index];
2943 return S_OK;
2946 static HRESULT WINAPI allocator_AdviseNotify(IVMRSurfaceAllocator9 *iface, IVMRSurfaceAllocatorNotify9 *notify)
2948 ok(0, "Unexpected call.\n");
2949 return E_NOTIMPL;
2952 static const IVMRSurfaceAllocator9Vtbl allocator_vtbl =
2954 allocator_QueryInterface,
2955 allocator_AddRef,
2956 allocator_Release,
2957 allocator_InitializeDevice,
2958 allocator_TerminateDevice,
2959 allocator_GetSurface,
2960 allocator_AdviseNotify,
2963 static void test_renderless_present(struct presenter *presenter,
2964 IFilterGraph2 *graph, IMemInputPin *input)
2966 IMediaControl *control;
2967 OAFilterState state;
2968 HANDLE thread;
2969 HRESULT hr;
2971 IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
2973 presenter->got_PresentImage = 0;
2975 hr = IMediaControl_Pause(control);
2976 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
2977 thread = send_frame(input);
2978 hr = IMediaControl_GetState(control, 1000, &state);
2979 ok(hr == S_OK, "Got hr %#x.\n", hr);
2980 /* Atelier Sophie uses the VMR in renderless mode, calls
2981 * IMediaControl::Run() from a stopped state and expects that
2982 * IMediaControl::GetState() returns S_OK only after PresentImage() has
2983 * been called. */
2984 ok(presenter->got_PresentImage == 1, "Got %u calls to PresentImage().\n", presenter->got_PresentImage);
2986 hr = IMediaControl_Run(control);
2987 ok(hr == S_OK, "Got hr %#x.\n", hr);
2988 hr = join_thread(thread);
2989 ok(hr == S_OK, "Got hr %#x.\n", hr);
2990 ok(presenter->got_PresentImage == 1, "Got %u calls to PresentImage().\n", presenter->got_PresentImage);
2992 hr = IMediaControl_Stop(control);
2993 ok(hr == S_OK, "Got hr %#x.\n", hr);
2995 IMediaControl_Release(control);
2998 static void test_renderless_formats(void)
3000 VIDEOINFOHEADER vih =
3002 .rcSource = {4, 6, 16, 12},
3003 .rcTarget = {40, 60, 160, 120},
3004 .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
3005 .bmiHeader.biWidth = 32,
3006 .bmiHeader.biHeight = 16,
3008 AM_MEDIA_TYPE req_mt =
3010 .majortype = MEDIATYPE_Video,
3011 .formattype = FORMAT_VideoInfo,
3012 .cbFormat = sizeof(vih),
3013 .pbFormat = (BYTE *)&vih,
3015 ALLOCATOR_PROPERTIES req_props = {5, 32 * 16 * 4, 1, 0}, ret_props;
3016 struct presenter presenter =
3018 .IVMRSurfaceAllocator9_iface.lpVtbl = &allocator_vtbl,
3019 .IVMRImagePresenter9_iface.lpVtbl = &presenter_vtbl,
3020 .refcount = 1,
3022 struct presenter presenter2 = presenter;
3023 IVMRSurfaceAllocatorNotify9 *notify;
3024 RECT rect = {0, 0, 640, 480};
3025 struct testfilter source;
3026 IDirect3DDevice9 *device;
3027 IMemAllocator *allocator;
3028 IFilterGraph2 *graph;
3029 IMemInputPin *input;
3030 IBaseFilter *filter;
3031 unsigned int i;
3032 HWND window;
3033 HRESULT hr;
3034 ULONG ref;
3035 IPin *pin;
3037 static const struct
3039 const GUID *subtype;
3040 D3DFORMAT format;
3041 DWORD flags;
3043 tests[] =
3045 {&MEDIASUBTYPE_ARGB1555, D3DFMT_A1R5G5B5, VMR9AllocFlag_TextureSurface},
3046 {&MEDIASUBTYPE_ARGB32, D3DFMT_A8R8G8B8, VMR9AllocFlag_TextureSurface},
3047 {&MEDIASUBTYPE_ARGB4444, D3DFMT_A4R4G4B4, VMR9AllocFlag_TextureSurface},
3049 {&MEDIASUBTYPE_RGB555, D3DFMT_X1R5G5B5, VMR9AllocFlag_OffscreenSurface},
3050 {&MEDIASUBTYPE_RGB555, D3DFMT_X1R5G5B5, VMR9AllocFlag_TextureSurface},
3051 {&MEDIASUBTYPE_RGB565, D3DFMT_R5G6B5, VMR9AllocFlag_OffscreenSurface},
3052 {&MEDIASUBTYPE_RGB565, D3DFMT_R5G6B5, VMR9AllocFlag_TextureSurface},
3053 {&MEDIASUBTYPE_RGB24, D3DFMT_R8G8B8, VMR9AllocFlag_OffscreenSurface},
3054 {&MEDIASUBTYPE_RGB24, D3DFMT_R8G8B8, VMR9AllocFlag_TextureSurface},
3055 {&MEDIASUBTYPE_RGB32, D3DFMT_X8R8G8B8, VMR9AllocFlag_OffscreenSurface},
3056 {&MEDIASUBTYPE_RGB32, D3DFMT_X8R8G8B8, VMR9AllocFlag_TextureSurface},
3058 {&MEDIASUBTYPE_NV12, MAKEFOURCC('N','V','1','2'), VMR9AllocFlag_OffscreenSurface},
3059 {&MEDIASUBTYPE_UYVY, D3DFMT_UYVY, VMR9AllocFlag_OffscreenSurface},
3060 {&MEDIASUBTYPE_YUY2, D3DFMT_YUY2, VMR9AllocFlag_OffscreenSurface},
3061 {&MEDIASUBTYPE_YV12, MAKEFOURCC('Y','V','1','2'), VMR9AllocFlag_OffscreenSurface},
3064 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
3065 window = CreateWindowA("static", "quartz_test", WS_OVERLAPPEDWINDOW, 0, 0,
3066 rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
3067 if (!(device = create_device(window)))
3069 DestroyWindow(window);
3070 return;
3073 filter = create_vmr9(VMR9Mode_Renderless);
3074 IBaseFilter_QueryInterface(filter, &IID_IVMRSurfaceAllocatorNotify9, (void **)&notify);
3076 hr = IVMRSurfaceAllocatorNotify9_SetD3DDevice(notify, device, MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY));
3077 if (hr == E_NOINTERFACE)
3079 win_skip("Direct3D does not support video rendering.\n");
3080 goto out;
3082 ok(hr == S_OK, "Got hr %#x.\n", hr);
3084 hr = IVMRSurfaceAllocatorNotify9_AdviseSurfaceAllocator(notify, 0xabacab,
3085 &presenter.IVMRSurfaceAllocator9_iface);
3086 ok(hr == S_OK, "Got hr %#x.\n", hr);
3088 presenter.notify = notify;
3090 testfilter_init(&source);
3091 graph = create_graph();
3092 IFilterGraph2_AddFilter(graph, &source.filter.IBaseFilter_iface, NULL);
3093 IFilterGraph2_AddFilter(graph, filter, NULL);
3094 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
3095 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input);
3097 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3099 req_mt.subtype = *tests[i].subtype;
3100 presenter.accept_flags = tests[i].flags;
3102 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
3103 /* Connection never fails on Native, but Wine currently creates D3D
3104 * surfaces during IPin::ReceiveConnection() instead of
3105 * IMemAllocator::SetProperties(), so let that fail here for now. */
3106 if (hr != S_OK)
3108 skip("Format %u (%#x), flags %#x are not supported, hr %#x.\n",
3109 tests[i].format, tests[i].format, tests[i].flags, hr);
3110 continue;
3112 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3114 hr = IMemInputPin_GetAllocator(input, &allocator);
3115 todo_wine ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3116 if (hr != S_OK)
3118 test_allocator(input);
3119 hr = IMemInputPin_GetAllocator(input, &allocator);
3122 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
3123 if (hr != S_OK)
3125 skip("Format %u (%#x), flags %#x are not supported, hr %#x.\n",
3126 tests[i].format, tests[i].format, tests[i].flags, hr);
3127 IMemAllocator_Release(allocator);
3128 hr = IFilterGraph2_Disconnect(graph, &source.source.pin.IPin_iface);
3129 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3130 hr = IFilterGraph2_Disconnect(graph, pin);
3131 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3132 continue;
3134 ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
3135 hr = IMemAllocator_Commit(allocator);
3136 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3138 hr = IVMRSurfaceAllocatorNotify9_AdviseSurfaceAllocator(notify, 0xabacab,
3139 &presenter2.IVMRSurfaceAllocator9_iface);
3140 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
3142 ok(presenter.format == tests[i].format, "Test %u: Got format %u (%#x).\n",
3143 i, presenter.format, presenter.format);
3145 test_renderless_present(&presenter, graph, input);
3147 hr = IMemAllocator_Decommit(allocator);
3148 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3149 IMemAllocator_Release(allocator);
3151 hr = IFilterGraph2_Disconnect(graph, &source.source.pin.IPin_iface);
3152 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3153 hr = IFilterGraph2_Disconnect(graph, pin);
3154 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
3157 hr = IVMRSurfaceAllocatorNotify9_AdviseSurfaceAllocator(notify, 0xabacab, &presenter2.IVMRSurfaceAllocator9_iface);
3158 ok(hr == S_OK, "Got hr %#x.\n", hr);
3160 ref = IFilterGraph2_Release(graph);
3161 ok(!ref, "Got outstanding refcount %d.\n", ref);
3162 IMemInputPin_Release(input);
3163 IPin_Release(pin);
3165 out:
3166 IVMRSurfaceAllocatorNotify9_Release(notify);
3167 ref = IBaseFilter_Release(filter);
3168 ok(!ref, "Got outstanding refcount %d.\n", ref);
3169 ok(presenter.refcount == 1, "Got outstanding refcount %d.\n", presenter.refcount);
3170 ok(presenter2.refcount == 1, "Got outstanding refcount %d.\n", presenter2.refcount);
3171 ref = IDirect3DDevice9_Release(device);
3172 ok(!ref, "Got outstanding refcount %d.\n", ref);
3173 DestroyWindow(window);
3176 static void test_mixing_mode(void)
3178 IVMRWindowlessControl9 *windowless_control;
3179 IVMRMixerControl9 *mixer_control;
3180 IVMRFilterConfig9 *config;
3181 DWORD stream_count = 0;
3182 IBaseFilter *filter;
3183 unsigned int i;
3184 HWND window;
3185 HRESULT hr;
3186 ULONG ref;
3188 static const VMR9Mode modes[] =
3191 VMR9Mode_Windowed,
3192 VMR9Mode_Windowless,
3193 VMR9Mode_Renderless,
3196 for (i = 0; i < ARRAY_SIZE(modes); ++i)
3198 filter = create_vmr9(modes[i]);
3199 IBaseFilter_QueryInterface(filter, &IID_IVMRFilterConfig9, (void **)&config);
3201 hr = IBaseFilter_QueryInterface(filter, &IID_IVMRMixerControl9, (void **)&mixer_control);
3202 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
3204 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &stream_count);
3205 ok(hr == VFW_E_VMR_NOT_IN_MIXER_MODE, "Got hr %#x.\n", hr);
3207 hr = IVMRFilterConfig9_SetNumberOfStreams(config, 1);
3208 ok(hr == S_OK, "Got hr %#x.\n", hr);
3210 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &stream_count);
3211 ok(hr == S_OK, "Got hr %#x.\n", hr);
3212 ok(stream_count == 1, "Got %u streams.\n", stream_count);
3214 hr = IBaseFilter_QueryInterface(filter, &IID_IVMRMixerControl9, (void **)&mixer_control);
3215 ok(hr == S_OK, "Got hr %#x.\n", hr);
3216 IVMRMixerControl9_Release(mixer_control);
3218 hr = IVMRFilterConfig9_SetNumberOfStreams(config, 2);
3219 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
3221 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &stream_count);
3222 ok(hr == S_OK, "Got hr %#x.\n", hr);
3223 ok(stream_count == 1, "Got %u streams.\n", stream_count);
3225 IVMRFilterConfig9_Release(config);
3226 ref = IBaseFilter_Release(filter);
3227 ok(!ref, "Got outstanding refcount %d.\n", ref);
3230 filter = create_vmr9(VMR9Mode_Windowless);
3231 IBaseFilter_QueryInterface(filter, &IID_IVMRFilterConfig9, (void **)&config);
3232 IBaseFilter_QueryInterface(filter, &IID_IVMRWindowlessControl9, (void **)&windowless_control);
3234 window = CreateWindowA("static", "quartz_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
3235 ok(!!window, "Failed to create a window.\n");
3236 hr = IVMRWindowlessControl9_SetVideoClippingWindow(windowless_control, window);
3237 ok(hr == S_OK, "Got hr %#x.\n", hr);
3239 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &stream_count);
3240 ok(hr == S_OK, "Got hr %#x.\n", hr);
3241 ok(stream_count == 4, "Got %u streams.\n", stream_count);
3243 hr = IBaseFilter_QueryInterface(filter, &IID_IVMRMixerControl9, (void **)&mixer_control);
3244 ok(hr == S_OK, "Got hr %#x.\n", hr);
3245 IVMRMixerControl9_Release(mixer_control);
3247 hr = IVMRFilterConfig9_SetNumberOfStreams(config, 2);
3248 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
3250 hr = IVMRFilterConfig9_GetNumberOfStreams(config, &stream_count);
3251 ok(hr == S_OK, "Got hr %#x.\n", hr);
3252 ok(stream_count == 4, "Got %u streams.\n", stream_count);
3254 IVMRWindowlessControl9_Release(windowless_control);
3255 IVMRFilterConfig9_Release(config);
3256 ref = IBaseFilter_Release(filter);
3257 ok(!ref, "Got outstanding refcount %d.\n", ref);
3258 DestroyWindow(window);
3261 static void test_clipping_window(void)
3263 VIDEOINFOHEADER vih =
3265 .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
3266 .bmiHeader.biWidth = 32,
3267 .bmiHeader.biHeight = 16,
3268 .bmiHeader.biBitCount = 32,
3270 AM_MEDIA_TYPE mt =
3272 .majortype = MEDIATYPE_Video,
3273 .subtype = MEDIASUBTYPE_RGB32,
3274 .formattype = FORMAT_VideoInfo,
3275 .cbFormat = sizeof(vih),
3276 .pbFormat = (BYTE *)&vih,
3278 IBaseFilter *filter = create_vmr9(VMR9Mode_Windowless);
3279 IVMRWindowlessControl9 *windowless_control;
3280 IFilterGraph2 *graph = create_graph();
3281 struct testfilter source;
3282 HWND window;
3283 HRESULT hr;
3284 ULONG ref;
3285 IPin *pin;
3287 IBaseFilter_QueryInterface(filter, &IID_IVMRWindowlessControl9, (void **)&windowless_control);
3288 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
3289 testfilter_init(&source);
3290 IFilterGraph2_AddFilter(graph, &source.filter.IBaseFilter_iface, L"source");
3291 IFilterGraph2_AddFilter(graph, filter, L"vmr9");
3292 window = CreateWindowA("static", "quartz_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
3293 ok(!!window, "Failed to create a window.\n");
3295 hr = IVMRWindowlessControl9_SetVideoClippingWindow(windowless_control, NULL);
3296 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3297 hr = IVMRWindowlessControl9_SetVideoClippingWindow(windowless_control, (HWND)0xdeadbeef);
3298 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3300 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt);
3301 ok(hr == S_OK, "Got hr %#x.\n", hr);
3303 hr = IVMRWindowlessControl9_SetVideoClippingWindow(windowless_control, window);
3304 ok(hr == VFW_E_WRONG_STATE, "Got hr %#x.\n", hr);
3306 hr = IFilterGraph2_Disconnect(graph, &source.source.pin.IPin_iface);
3307 ok(hr == S_OK, "Got hr %#x.\n", hr);
3308 hr = IFilterGraph2_Disconnect(graph, pin);
3309 ok(hr == S_OK, "Got hr %#x.\n", hr);
3311 hr = IVMRWindowlessControl9_SetVideoClippingWindow(windowless_control, window);
3312 ok(hr == S_OK, "Got hr %#x.\n", hr);
3314 ref = IFilterGraph2_Release(graph);
3315 ok(!ref, "Got outstanding refcount %d.\n", ref);
3316 IPin_Release(pin);
3317 IVMRWindowlessControl9_Release(windowless_control);
3318 ref = IBaseFilter_Release(filter);
3319 ok(!ref, "Got outstanding refcount %d.\n", ref);
3320 DestroyWindow(window);
3323 static void test_surface_allocator_notify_refcount(void)
3325 struct presenter presenter =
3327 .IVMRSurfaceAllocator9_iface.lpVtbl = &allocator_vtbl,
3328 .IVMRImagePresenter9_iface.lpVtbl = &presenter_vtbl,
3329 .refcount = 1,
3331 IBaseFilter *filter = create_vmr9(VMR9Mode_Renderless);
3332 IVMRSurfaceAllocatorNotify9 *notify;
3333 HRESULT hr;
3334 ULONG ref;
3336 set_mixing_mode(filter, 2);
3338 IBaseFilter_QueryInterface(filter, &IID_IVMRSurfaceAllocatorNotify9, (void **)&notify);
3340 hr = IVMRSurfaceAllocatorNotify9_AdviseSurfaceAllocator(notify, 0xabacab,
3341 &presenter.IVMRSurfaceAllocator9_iface);
3342 ok(hr == S_OK, "Got hr %#x.\n", hr);
3344 ref = IBaseFilter_Release(filter);
3345 ok(!ref, "Got outstanding refcount %d.\n", ref);
3346 ok(presenter.got_TerminateDevice == 1, "Got %u calls to TerminateDevice().\n",
3347 presenter.got_TerminateDevice);
3348 ok(presenter.refcount == 1, "Got outstanding refcount %d.\n", presenter.refcount);
3350 ref = IVMRSurfaceAllocatorNotify9_Release(notify);
3351 ok(!ref, "Got outstanding refcount %d.\n", ref);
3354 static void check_source_position_(int line, IBasicVideo *video,
3355 LONG expect_left, LONG expect_top, LONG expect_width, LONG expect_height)
3357 LONG left, top, width, height, l;
3358 HRESULT hr;
3360 left = top = width = height = 0xdeadbeef;
3361 hr = IBasicVideo_GetSourcePosition(video, &left, &top, &width, &height);
3362 ok_(__FILE__,line)(hr == S_OK, "Got hr %#x.\n", hr);
3363 ok_(__FILE__,line)(left == expect_left, "Got left %d.\n", left);
3364 ok_(__FILE__,line)(top == expect_top, "Got top %d.\n", top);
3365 ok_(__FILE__,line)(width == expect_width, "Got width %d.\n", width);
3366 ok_(__FILE__,line)(height == expect_height, "Got height %d.\n", height);
3368 l = 0xdeadbeef;
3369 hr = IBasicVideo_get_SourceLeft(video, &l);
3370 ok_(__FILE__,line)(hr == S_OK, "Failed to get left, hr %#x.\n", hr);
3371 ok_(__FILE__,line)(l == left, "Got left %d.\n", l);
3373 l = 0xdeadbeef;
3374 hr = IBasicVideo_get_SourceTop(video, &l);
3375 ok_(__FILE__,line)(hr == S_OK, "Failed to get top, hr %#x.\n", hr);
3376 ok_(__FILE__,line)(l == top, "Got top %d.\n", l);
3378 l = 0xdeadbeef;
3379 hr = IBasicVideo_get_SourceWidth(video, &l);
3380 ok_(__FILE__,line)(hr == S_OK, "Failed to get width, hr %#x.\n", hr);
3381 ok_(__FILE__,line)(l == width, "Got width %d.\n", l);
3383 l = 0xdeadbeef;
3384 hr = IBasicVideo_get_SourceHeight(video, &l);
3385 ok_(__FILE__,line)(hr == S_OK, "Failed to get height, hr %#x.\n", hr);
3386 ok_(__FILE__,line)(l == height, "Got height %d.\n", l);
3388 #define check_source_position(a,b,c,d,e) check_source_position_(__LINE__,a,b,c,d,e)
3390 static void test_basic_video_source(IBasicVideo *video)
3392 HRESULT hr;
3394 check_source_position(video, 0, 0, 600, 400);
3395 hr = IBasicVideo_IsUsingDefaultSource(video);
3396 ok(hr == S_OK, "Got hr %#x.\n", hr);
3398 hr = IBasicVideo_put_SourceLeft(video, -10);
3399 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3400 hr = IBasicVideo_put_SourceLeft(video, 10);
3401 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3403 hr = IBasicVideo_put_SourceTop(video, -10);
3404 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3405 hr = IBasicVideo_put_SourceTop(video, 10);
3406 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3408 hr = IBasicVideo_put_SourceWidth(video, -500);
3409 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3410 hr = IBasicVideo_put_SourceWidth(video, 0);
3411 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3412 hr = IBasicVideo_put_SourceWidth(video, 700);
3413 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3414 hr = IBasicVideo_put_SourceWidth(video, 500);
3415 ok(hr == S_OK, "Got hr %#x.\n", hr);
3416 check_source_position(video, 0, 0, 500, 400);
3417 hr = IBasicVideo_IsUsingDefaultSource(video);
3418 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3420 hr = IBasicVideo_put_SourceHeight(video, -300);
3421 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3422 hr = IBasicVideo_put_SourceHeight(video, 0);
3423 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3424 hr = IBasicVideo_put_SourceHeight(video, 600);
3425 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3426 hr = IBasicVideo_put_SourceHeight(video, 300);
3427 ok(hr == S_OK, "Got hr %#x.\n", hr);
3428 check_source_position(video, 0, 0, 500, 300);
3429 hr = IBasicVideo_IsUsingDefaultSource(video);
3430 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3432 hr = IBasicVideo_put_SourceLeft(video, -10);
3433 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3434 hr = IBasicVideo_put_SourceLeft(video, 10);
3435 ok(hr == S_OK, "Got hr %#x.\n", hr);
3436 check_source_position(video, 10, 0, 500, 300);
3437 hr = IBasicVideo_IsUsingDefaultSource(video);
3438 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3440 hr = IBasicVideo_put_SourceTop(video, -10);
3441 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3442 hr = IBasicVideo_put_SourceTop(video, 20);
3443 ok(hr == S_OK, "Got hr %#x.\n", hr);
3444 check_source_position(video, 10, 20, 500, 300);
3445 hr = IBasicVideo_IsUsingDefaultSource(video);
3446 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3448 hr = IBasicVideo_SetSourcePosition(video, 4, 5, 60, 40);
3449 ok(hr == S_OK, "Got hr %#x.\n", hr);
3450 check_source_position(video, 4, 5, 60, 40);
3451 hr = IBasicVideo_IsUsingDefaultSource(video);
3452 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3454 hr = IBasicVideo_SetSourcePosition(video, 0, 0, 600, 400);
3455 ok(hr == S_OK, "Got hr %#x.\n", hr);
3456 check_source_position(video, 0, 0, 600, 400);
3457 hr = IBasicVideo_IsUsingDefaultSource(video);
3458 ok(hr == S_OK, "Got hr %#x.\n", hr);
3460 hr = IBasicVideo_SetSourcePosition(video, 4, 5, 60, 40);
3461 ok(hr == S_OK, "Got hr %#x.\n", hr);
3462 hr = IBasicVideo_SetDefaultSourcePosition(video);
3463 ok(hr == S_OK, "Got hr %#x.\n", hr);
3464 check_source_position(video, 0, 0, 600, 400);
3465 hr = IBasicVideo_IsUsingDefaultSource(video);
3466 ok(hr == S_OK, "Got hr %#x.\n", hr);
3469 static void check_destination_position_(int line, IBasicVideo *video,
3470 LONG expect_left, LONG expect_top, LONG expect_width, LONG expect_height)
3472 LONG left, top, width, height, l;
3473 HRESULT hr;
3475 left = top = width = height = 0xdeadbeef;
3476 hr = IBasicVideo_GetDestinationPosition(video, &left, &top, &width, &height);
3477 ok_(__FILE__,line)(hr == S_OK, "Failed to get position, hr %#x.\n", hr);
3478 ok_(__FILE__,line)(left == expect_left, "Got left %d.\n", left);
3479 ok_(__FILE__,line)(top == expect_top, "Got top %d.\n", top);
3480 ok_(__FILE__,line)(width == expect_width, "Got width %d.\n", width);
3481 ok_(__FILE__,line)(height == expect_height, "Got height %d.\n", height);
3483 l = 0xdeadbeef;
3484 hr = IBasicVideo_get_DestinationLeft(video, &l);
3485 ok_(__FILE__,line)(hr == S_OK, "Failed to get left, hr %#x.\n", hr);
3486 ok_(__FILE__,line)(l == left, "Got left %d.\n", l);
3488 l = 0xdeadbeef;
3489 hr = IBasicVideo_get_DestinationTop(video, &l);
3490 ok_(__FILE__,line)(hr == S_OK, "Failed to get top, hr %#x.\n", hr);
3491 ok_(__FILE__,line)(l == top, "Got top %d.\n", l);
3493 l = 0xdeadbeef;
3494 hr = IBasicVideo_get_DestinationWidth(video, &l);
3495 ok_(__FILE__,line)(hr == S_OK, "Failed to get width, hr %#x.\n", hr);
3496 ok_(__FILE__,line)(l == width, "Got width %d.\n", l);
3498 l = 0xdeadbeef;
3499 hr = IBasicVideo_get_DestinationHeight(video, &l);
3500 ok_(__FILE__,line)(hr == S_OK, "Failed to get height, hr %#x.\n", hr);
3501 ok_(__FILE__,line)(l == height, "Got height %d.\n", l);
3503 #define check_destination_position(a,b,c,d,e) check_destination_position_(__LINE__,a,b,c,d,e)
3505 static void test_basic_video_destination(IBasicVideo *video)
3507 IVideoWindow *window;
3508 HRESULT hr;
3509 RECT rect;
3511 IBasicVideo_QueryInterface(video, &IID_IVideoWindow, (void **)&window);
3513 check_destination_position(video, 0, 0, 600, 400);
3514 hr = IBasicVideo_IsUsingDefaultDestination(video);
3515 ok(hr == S_OK, "Got hr %#x.\n", hr);
3517 hr = IBasicVideo_put_DestinationLeft(video, -10);
3518 ok(hr == S_OK, "Got hr %#x.\n", hr);
3519 check_destination_position(video, -10, 0, 600, 400);
3520 hr = IBasicVideo_IsUsingDefaultDestination(video);
3521 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3523 hr = IBasicVideo_put_DestinationLeft(video, 10);
3524 ok(hr == S_OK, "Got hr %#x.\n", hr);
3525 check_destination_position(video, 10, 0, 600, 400);
3526 hr = IBasicVideo_IsUsingDefaultDestination(video);
3527 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3529 hr = IBasicVideo_put_DestinationTop(video, -20);
3530 ok(hr == S_OK, "Got hr %#x.\n", hr);
3531 check_destination_position(video, 10, -20, 600, 400);
3532 hr = IBasicVideo_IsUsingDefaultDestination(video);
3533 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3535 hr = IBasicVideo_put_DestinationTop(video, 20);
3536 ok(hr == S_OK, "Got hr %#x.\n", hr);
3537 check_destination_position(video, 10, 20, 600, 400);
3538 hr = IBasicVideo_IsUsingDefaultDestination(video);
3539 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3541 hr = IBasicVideo_put_DestinationWidth(video, -700);
3542 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3543 hr = IBasicVideo_put_DestinationWidth(video, 0);
3544 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3545 hr = IBasicVideo_put_DestinationWidth(video, 700);
3546 ok(hr == S_OK, "Got hr %#x.\n", hr);
3547 check_destination_position(video, 10, 20, 700, 400);
3548 hr = IBasicVideo_IsUsingDefaultDestination(video);
3549 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3551 hr = IBasicVideo_put_DestinationWidth(video, 500);
3552 ok(hr == S_OK, "Got hr %#x.\n", hr);
3553 check_destination_position(video, 10, 20, 500, 400);
3554 hr = IBasicVideo_IsUsingDefaultDestination(video);
3555 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3557 hr = IBasicVideo_put_DestinationHeight(video, -500);
3558 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3559 hr = IBasicVideo_put_DestinationHeight(video, 0);
3560 ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
3561 hr = IBasicVideo_put_DestinationHeight(video, 500);
3562 ok(hr == S_OK, "Got hr %#x.\n", hr);
3563 check_destination_position(video, 10, 20, 500, 500);
3564 hr = IBasicVideo_IsUsingDefaultDestination(video);
3565 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3567 hr = IBasicVideo_put_DestinationHeight(video, 300);
3568 ok(hr == S_OK, "Got hr %#x.\n", hr);
3569 check_destination_position(video, 10, 20, 500, 300);
3570 hr = IBasicVideo_IsUsingDefaultDestination(video);
3571 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3573 hr = IBasicVideo_SetDestinationPosition(video, 4, 5, 60, 40);
3574 ok(hr == S_OK, "Got hr %#x.\n", hr);
3575 check_destination_position(video, 4, 5, 60, 40);
3576 hr = IBasicVideo_IsUsingDefaultDestination(video);
3577 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3579 hr = IBasicVideo_SetDestinationPosition(video, 0, 0, 600, 400);
3580 ok(hr == S_OK, "Got hr %#x.\n", hr);
3581 check_destination_position(video, 0, 0, 600, 400);
3582 hr = IBasicVideo_IsUsingDefaultDestination(video);
3583 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3585 hr = IBasicVideo_SetDestinationPosition(video, 4, 5, 60, 40);
3586 ok(hr == S_OK, "Got hr %#x.\n", hr);
3587 hr = IBasicVideo_SetDefaultDestinationPosition(video);
3588 ok(hr == S_OK, "Got hr %#x.\n", hr);
3589 check_destination_position(video, 0, 0, 600, 400);
3590 hr = IBasicVideo_IsUsingDefaultDestination(video);
3591 ok(hr == S_OK, "Got hr %#x.\n", hr);
3593 SetRect(&rect, 100, 200, 500, 500);
3594 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
3595 hr = IVideoWindow_SetWindowPosition(window, rect.left, rect.top,
3596 rect.right - rect.left, rect.bottom - rect.top);
3597 ok(hr == S_OK, "Got hr %#x.\n", hr);
3598 check_destination_position(video, 0, 0, 400, 300);
3599 hr = IBasicVideo_IsUsingDefaultDestination(video);
3600 ok(hr == S_OK, "Got hr %#x.\n", hr);
3602 hr = IBasicVideo_SetDestinationPosition(video, 0, 0, 400, 300);
3603 ok(hr == S_OK, "Got hr %#x.\n", hr);
3604 check_destination_position(video, 0, 0, 400, 300);
3605 hr = IBasicVideo_IsUsingDefaultDestination(video);
3606 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3608 SetRect(&rect, 100, 200, 600, 600);
3609 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
3610 hr = IVideoWindow_SetWindowPosition(window, rect.left, rect.top,
3611 rect.right - rect.left, rect.bottom - rect.top);
3612 ok(hr == S_OK, "Got hr %#x.\n", hr);
3613 check_destination_position(video, 0, 0, 400, 300);
3614 hr = IBasicVideo_IsUsingDefaultDestination(video);
3615 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
3617 IVideoWindow_Release(window);
3620 static void test_basic_video(void)
3622 ALLOCATOR_PROPERTIES req_props = {1, 600 * 400 * 4, 1, 0}, ret_props;
3623 VIDEOINFOHEADER vih =
3625 .AvgTimePerFrame = 200000,
3626 .rcSource = {4, 6, 16, 12},
3627 .rcTarget = {40, 60, 120, 160},
3628 .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
3629 .bmiHeader.biBitCount = 32,
3630 .bmiHeader.biWidth = 600,
3631 .bmiHeader.biHeight = 400,
3632 .bmiHeader.biPlanes = 1,
3633 .bmiHeader.biCompression = BI_RGB,
3635 AM_MEDIA_TYPE req_mt =
3637 .majortype = MEDIATYPE_Video,
3638 .subtype = MEDIASUBTYPE_RGB32,
3639 .formattype = FORMAT_VideoInfo,
3640 .cbFormat = sizeof(vih),
3641 .pbFormat = (BYTE *)&vih,
3643 IBaseFilter *filter = create_vmr9(VMR9Mode_Windowed);
3644 IFilterGraph2 *graph = create_graph();
3645 LONG left, top, width, height, l;
3646 struct testfilter source;
3647 IMemAllocator *allocator;
3648 IMemInputPin *input;
3649 ITypeInfo *typeinfo;
3650 IBasicVideo *video;
3651 TYPEATTR *typeattr;
3652 REFTIME reftime;
3653 HRESULT hr;
3654 UINT count;
3655 ULONG ref;
3656 IPin *pin;
3657 RECT rect;
3659 IBaseFilter_QueryInterface(filter, &IID_IBasicVideo, (void **)&video);
3660 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
3661 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input);
3663 hr = IBasicVideo_GetTypeInfoCount(video, &count);
3664 ok(hr == S_OK, "Got hr %#x.\n", hr);
3665 ok(count == 1, "Got count %u.\n", count);
3667 hr = IBasicVideo_GetTypeInfo(video, 0, 0, &typeinfo);
3668 ok(hr == S_OK, "Got hr %#x.\n", hr);
3669 hr = ITypeInfo_GetTypeAttr(typeinfo, &typeattr);
3670 ok(hr == S_OK, "Got hr %#x.\n", hr);
3671 ok(typeattr->typekind == TKIND_DISPATCH, "Got kind %u.\n", typeattr->typekind);
3672 ok(IsEqualGUID(&typeattr->guid, &IID_IBasicVideo), "Got IID %s.\n", wine_dbgstr_guid(&typeattr->guid));
3673 ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
3674 ITypeInfo_Release(typeinfo);
3676 hr = IBasicVideo_get_AvgTimePerFrame(video, NULL);
3677 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3678 hr = IBasicVideo_get_AvgTimePerFrame(video, &reftime);
3679 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
3681 hr = IBasicVideo_get_BitRate(video, NULL);
3682 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3683 hr = IBasicVideo_get_BitRate(video, &l);
3684 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
3686 hr = IBasicVideo_get_BitErrorRate(video, NULL);
3687 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3688 hr = IBasicVideo_get_BitErrorRate(video, &l);
3689 ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
3691 hr = IBasicVideo_get_VideoWidth(video, NULL);
3692 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3693 hr = IBasicVideo_get_VideoHeight(video, NULL);
3694 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3696 hr = IBasicVideo_get_SourceLeft(video, NULL);
3697 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3698 hr = IBasicVideo_get_SourceWidth(video, NULL);
3699 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3700 hr = IBasicVideo_get_SourceTop(video, NULL);
3701 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3702 hr = IBasicVideo_get_SourceHeight(video, NULL);
3703 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3705 hr = IBasicVideo_get_DestinationLeft(video, NULL);
3706 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3707 hr = IBasicVideo_get_DestinationWidth(video, NULL);
3708 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3709 hr = IBasicVideo_get_DestinationTop(video, NULL);
3710 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3711 hr = IBasicVideo_get_DestinationHeight(video, NULL);
3712 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3714 hr = IBasicVideo_GetSourcePosition(video, NULL, &top, &width, &height);
3715 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3716 hr = IBasicVideo_GetSourcePosition(video, &left, NULL, &width, &height);
3717 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3718 hr = IBasicVideo_GetSourcePosition(video, &left, &top, NULL, &height);
3719 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3720 hr = IBasicVideo_GetSourcePosition(video, &left, &top, &width, NULL);
3721 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3723 hr = IBasicVideo_GetDestinationPosition(video, NULL, &top, &width, &height);
3724 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3725 hr = IBasicVideo_GetDestinationPosition(video, &left, NULL, &width, &height);
3726 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3727 hr = IBasicVideo_GetDestinationPosition(video, &left, &top, NULL, &height);
3728 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3729 hr = IBasicVideo_GetDestinationPosition(video, &left, &top, &width, NULL);
3730 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3732 hr = IBasicVideo_GetVideoSize(video, &width, NULL);
3733 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3734 hr = IBasicVideo_GetVideoSize(video, NULL, &height);
3735 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3737 hr = IBasicVideo_GetVideoPaletteEntries(video, 0, 1, NULL, &l);
3738 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3739 hr = IBasicVideo_GetVideoPaletteEntries(video, 0, 1, &l, NULL);
3740 todo_wine ok(hr == VFW_E_NOT_CONNECTED, "Got hr %#x.\n", hr);
3742 testfilter_init(&source);
3743 IFilterGraph2_AddFilter(graph, &source.filter.IBaseFilter_iface, L"vmr9");
3744 IFilterGraph2_AddFilter(graph, filter, L"source");
3745 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
3746 if (hr == E_FAIL)
3748 skip("Got E_FAIL when connecting.\n");
3749 goto out;
3751 ok(hr == S_OK, "Got hr %#x.\n", hr);
3753 hr = IMemInputPin_GetAllocator(input, &allocator);
3754 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
3755 if (hr == S_OK)
3757 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
3758 ok(hr == S_OK, "Got hr %#x.\n", hr);
3759 ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
3760 hr = IMemAllocator_Commit(allocator);
3761 ok(hr == S_OK, "Got hr %#x.\n", hr);
3762 IMemAllocator_Release(allocator);
3765 reftime = 0.0;
3766 hr = IBasicVideo_get_AvgTimePerFrame(video, &reftime);
3767 ok(hr == S_OK, "Got hr %#x.\n", hr);
3768 ok(compare_double(reftime, 0.02, 1 << 28), "Got frame rate %.16e.\n", reftime);
3770 l = 0xdeadbeef;
3771 hr = IBasicVideo_get_BitRate(video, &l);
3772 ok(hr == S_OK, "Got hr %#x.\n", hr);
3773 ok(!l, "Got bit rate %d.\n", l);
3775 l = 0xdeadbeef;
3776 hr = IBasicVideo_get_BitErrorRate(video, &l);
3777 ok(hr == S_OK, "Got hr %#x.\n", hr);
3778 ok(!l, "Got bit rate %d.\n", l);
3780 hr = IBasicVideo_GetVideoPaletteEntries(video, 0, 1, &l, NULL);
3781 todo_wine ok(hr == VFW_E_NO_PALETTE_AVAILABLE, "Got hr %#x.\n", hr);
3783 width = height = 0xdeadbeef;
3784 hr = IBasicVideo_GetVideoSize(video, &width, &height);
3785 ok(hr == S_OK, "Got hr %#x.\n", hr);
3786 ok(width == 600, "Got width %d.\n", width);
3787 ok(height == 400, "Got height %d.\n", height);
3789 test_basic_video_source(video);
3790 test_basic_video_destination(video);
3792 hr = IFilterGraph2_Disconnect(graph, &source.source.pin.IPin_iface);
3793 ok(hr == S_OK, "Got hr %#x.\n", hr);
3794 hr = IFilterGraph2_Disconnect(graph, pin);
3795 ok(hr == S_OK, "Got hr %#x.\n", hr);
3797 vih.bmiHeader.biWidth = 16;
3798 vih.bmiHeader.biHeight = 16;
3799 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &req_mt);
3800 ok(hr == S_OK, "Got hr %#x.\n", hr);
3802 hr = IMemInputPin_GetAllocator(input, &allocator);
3803 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
3804 if (hr == S_OK)
3806 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
3807 ok(hr == S_OK, "Got hr %#x.\n", hr);
3808 ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
3809 hr = IMemAllocator_Commit(allocator);
3810 ok(hr == S_OK, "Got hr %#x.\n", hr);
3811 IMemAllocator_Release(allocator);
3814 check_source_position(video, 0, 0, 16, 16);
3816 SetRect(&rect, 0, 0, 0, 0);
3817 AdjustWindowRectEx(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, FALSE, 0);
3818 check_destination_position(video, 0, 0, max(16, GetSystemMetrics(SM_CXMIN) - (rect.right - rect.left)),
3819 max(16, GetSystemMetrics(SM_CYMIN) - (rect.bottom - rect.top)));
3821 out:
3822 ref = IFilterGraph2_Release(graph);
3823 ok(!ref, "Got outstanding refcount %d.\n", ref);
3824 IBasicVideo_Release(video);
3825 IMemInputPin_Release(input);
3826 IPin_Release(pin);
3827 ref = IBaseFilter_Release(filter);
3828 ok(!ref, "Got outstanding refcount %d.\n", ref);
3829 ref = IBaseFilter_Release(&source.filter.IBaseFilter_iface);
3830 ok(!ref, "Got outstanding refcount %d.\n", ref);
3833 static void test_windowless_size(void)
3835 ALLOCATOR_PROPERTIES req_props = {1, 32 * 16 * 4, 1, 0}, ret_props;
3836 VIDEOINFOHEADER vih =
3838 .bmiHeader.biSize = sizeof(BITMAPINFOHEADER),
3839 .bmiHeader.biWidth = 32,
3840 .bmiHeader.biHeight = 16,
3841 .bmiHeader.biBitCount = 32,
3842 .bmiHeader.biPlanes = 1,
3844 AM_MEDIA_TYPE mt =
3846 .majortype = MEDIATYPE_Video,
3847 .subtype = MEDIASUBTYPE_RGB32,
3848 .formattype = FORMAT_VideoInfo,
3849 .cbFormat = sizeof(vih),
3850 .pbFormat = (BYTE *)&vih,
3852 IBaseFilter *filter = create_vmr9(VMR9Mode_Windowless);
3853 LONG width, height, aspect_width, aspect_height;
3854 IVMRWindowlessControl9 *windowless_control;
3855 IFilterGraph2 *graph = create_graph();
3856 VMR9AspectRatioMode aspect_mode;
3857 struct testfilter source;
3858 IMemAllocator *allocator;
3859 RECT src, dst, expect;
3860 IMemInputPin *input;
3861 HWND window;
3862 HRESULT hr;
3863 ULONG ref;
3864 IPin *pin;
3866 IBaseFilter_QueryInterface(filter, &IID_IVMRWindowlessControl9, (void **)&windowless_control);
3867 IBaseFilter_FindPin(filter, L"VMR Input0", &pin);
3868 IPin_QueryInterface(pin, &IID_IMemInputPin, (void **)&input);
3869 testfilter_init(&source);
3870 IFilterGraph2_AddFilter(graph, &source.filter.IBaseFilter_iface, L"source");
3871 IFilterGraph2_AddFilter(graph, filter, L"vmr9");
3872 window = CreateWindowA("static", "quartz_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0);
3873 ok(!!window, "Failed to create a window.\n");
3875 hr = IVMRWindowlessControl9_SetVideoClippingWindow(windowless_control, window);
3876 ok(hr == S_OK, "Got hr %#x.\n", hr);
3878 hr = IFilterGraph2_ConnectDirect(graph, &source.source.pin.IPin_iface, pin, &mt);
3879 ok(hr == S_OK, "Got hr %#x.\n", hr);
3880 hr = IMemInputPin_GetAllocator(input, &allocator);
3881 todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
3882 if (hr == S_OK)
3884 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
3885 IMemAllocator_Release(allocator);
3886 if (hr == E_FAIL)
3888 skip("Got E_FAIL when setting allocator properties.\n");
3889 goto out;
3891 ok(hr == S_OK, "Got hr %#x.\n", hr);
3892 ok(!memcmp(&ret_props, &req_props, sizeof(req_props)), "Properties did not match.\n");
3895 hr = IVMRWindowlessControl9_GetNativeVideoSize(windowless_control, NULL, &height, &aspect_width, &aspect_height);
3896 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3897 hr = IVMRWindowlessControl9_GetNativeVideoSize(windowless_control, &width, NULL, &aspect_width, &aspect_height);
3898 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
3900 aspect_mode = 0xdeadbeef;
3901 hr = IVMRWindowlessControl9_GetAspectRatioMode(windowless_control, &aspect_mode);
3902 ok(hr == S_OK, "Got hr %#x.\n", hr);
3903 ok(aspect_mode == VMR9ARMode_None, "Got mode %u.\n", aspect_mode);
3905 width = height = 0xdeadbeef;
3906 hr = IVMRWindowlessControl9_GetNativeVideoSize(windowless_control, &width, &height, NULL, NULL);
3907 ok(hr == S_OK, "Got hr %#x.\n", hr);
3908 ok(width == 32, "Got width %d.\n", width);
3909 ok(height == 16, "Got height %d.\n", height);
3911 aspect_width = aspect_height = 0xdeadbeef;
3912 hr = IVMRWindowlessControl9_GetNativeVideoSize(windowless_control, &width, &height, &aspect_width, &aspect_height);
3913 ok(hr == S_OK, "Got hr %#x.\n", hr);
3914 ok(aspect_width == 32, "Got width %d.\n", aspect_width);
3915 ok(aspect_height == 16, "Got height %d.\n", aspect_height);
3917 memset(&src, 0xcc, sizeof(src));
3918 hr = IVMRWindowlessControl9_GetVideoPosition(windowless_control, &src, NULL);
3919 ok(hr == S_OK, "Got hr %#x.\n", hr);
3920 SetRect(&expect, 0, 0, 32, 16);
3921 ok(EqualRect(&src, &expect), "Got source rect %s.\n", wine_dbgstr_rect(&src));
3923 memset(&dst, 0xcc, sizeof(dst));
3924 hr = IVMRWindowlessControl9_GetVideoPosition(windowless_control, NULL, &dst);
3925 ok(hr == S_OK, "Got hr %#x.\n", hr);
3926 SetRect(&expect, 0, 0, 0, 0);
3927 ok(EqualRect(&dst, &expect), "Got dest rect %s.\n", wine_dbgstr_rect(&dst));
3929 SetRect(&src, 4, 6, 16, 12);
3930 hr = IVMRWindowlessControl9_SetVideoPosition(windowless_control, &src, NULL);
3931 ok(hr == S_OK, "Got hr %#x.\n", hr);
3933 memset(&src, 0xcc, sizeof(src));
3934 memset(&dst, 0xcc, sizeof(dst));
3935 hr = IVMRWindowlessControl9_GetVideoPosition(windowless_control, &src, &dst);
3936 ok(hr == S_OK, "Got hr %#x.\n", hr);
3937 SetRect(&expect, 4, 6, 16, 12);
3938 ok(EqualRect(&src, &expect), "Got source rect %s.\n", wine_dbgstr_rect(&src));
3939 SetRect(&expect, 0, 0, 0, 0);
3940 ok(EqualRect(&dst, &expect), "Got dest rect %s.\n", wine_dbgstr_rect(&dst));
3942 SetRect(&dst, 40, 60, 120, 160);
3943 hr = IVMRWindowlessControl9_SetVideoPosition(windowless_control, NULL, &dst);
3944 ok(hr == S_OK, "Got hr %#x.\n", hr);
3946 memset(&src, 0xcc, sizeof(src));
3947 memset(&dst, 0xcc, sizeof(dst));
3948 hr = IVMRWindowlessControl9_GetVideoPosition(windowless_control, &src, &dst);
3949 ok(hr == S_OK, "Got hr %#x.\n", hr);
3950 SetRect(&expect, 4, 6, 16, 12);
3951 ok(EqualRect(&src, &expect), "Got source rect %s.\n", wine_dbgstr_rect(&src));
3952 SetRect(&expect, 40, 60, 120, 160);
3953 ok(EqualRect(&dst, &expect), "Got dest rect %s.\n", wine_dbgstr_rect(&dst));
3955 GetWindowRect(window, &src);
3956 SetRect(&expect, 0, 0, 640, 480);
3957 ok(EqualRect(&src, &expect), "Got window rect %s.\n", wine_dbgstr_rect(&src));
3959 hr = IVMRWindowlessControl9_SetAspectRatioMode(windowless_control, VMR9ARMode_LetterBox);
3960 ok(hr == S_OK, "Got hr %#x.\n", hr);
3962 aspect_mode = 0xdeadbeef;
3963 hr = IVMRWindowlessControl9_GetAspectRatioMode(windowless_control, &aspect_mode);
3964 ok(hr == S_OK, "Got hr %#x.\n", hr);
3965 ok(aspect_mode == VMR9ARMode_LetterBox, "Got mode %u.\n", aspect_mode);
3967 memset(&src, 0xcc, sizeof(src));
3968 memset(&dst, 0xcc, sizeof(dst));
3969 hr = IVMRWindowlessControl9_GetVideoPosition(windowless_control, &src, &dst);
3970 ok(hr == S_OK, "Got hr %#x.\n", hr);
3971 SetRect(&expect, 4, 6, 16, 12);
3972 ok(EqualRect(&src, &expect), "Got source rect %s.\n", wine_dbgstr_rect(&src));
3973 SetRect(&expect, 40, 60, 120, 160);
3974 ok(EqualRect(&dst, &expect), "Got dest rect %s.\n", wine_dbgstr_rect(&dst));
3976 SetRect(&src, 0, 0, 32, 16);
3977 SetRect(&dst, 0, 0, 640, 480);
3978 hr = IVMRWindowlessControl9_SetVideoPosition(windowless_control, &src, &dst);
3979 ok(hr == S_OK, "Got hr %#x.\n", hr);
3981 memset(&src, 0xcc, sizeof(src));
3982 memset(&dst, 0xcc, sizeof(dst));
3983 hr = IVMRWindowlessControl9_GetVideoPosition(windowless_control, &src, &dst);
3984 ok(hr == S_OK, "Got hr %#x.\n", hr);
3985 SetRect(&expect, 0, 0, 32, 16);
3986 ok(EqualRect(&src, &expect), "Got source rect %s.\n", wine_dbgstr_rect(&src));
3987 SetRect(&expect, 0, 0, 640, 480);
3988 ok(EqualRect(&dst, &expect), "Got dest rect %s.\n", wine_dbgstr_rect(&dst));
3990 out:
3991 ref = IFilterGraph2_Release(graph);
3992 ok(!ref, "Got outstanding refcount %d.\n", ref);
3993 IMemInputPin_Release(input);
3994 IPin_Release(pin);
3995 IVMRWindowlessControl9_Release(windowless_control);
3996 ref = IBaseFilter_Release(filter);
3997 ok(!ref, "Got outstanding refcount %d.\n", ref);
3998 DestroyWindow(window);
4001 static void test_mixing_prefs(void)
4003 IBaseFilter *filter = create_vmr9(VMR9Mode_Windowed);
4004 IVMRMixerControl9 *mixer_control;
4005 DWORD flags;
4006 HRESULT hr;
4007 ULONG ref;
4009 set_mixing_mode(filter, 1);
4011 hr = IBaseFilter_QueryInterface(filter, &IID_IVMRMixerControl9, (void **)&mixer_control);
4012 ok(hr == S_OK, "Got hr %#x.\n", hr);
4014 hr = IVMRMixerControl9_GetMixingPrefs(mixer_control, &flags);
4015 ok(hr == S_OK, "Got hr %#x.\n", hr);
4016 ok(flags == (MixerPref9_NoDecimation | MixerPref9_ARAdjustXorY | MixerPref9_BiLinearFiltering
4017 | MixerPref9_RenderTargetRGB), "Got flags %#x.\n", flags);
4019 hr = IVMRMixerControl9_SetMixingPrefs(mixer_control, MixerPref9_NoDecimation
4020 | MixerPref9_ARAdjustXorY | MixerPref9_PointFiltering | MixerPref9_RenderTargetRGB);
4021 ok(hr == S_OK, "Got hr %#x.\n", hr);
4023 hr = IVMRMixerControl9_GetMixingPrefs(mixer_control, &flags);
4024 ok(hr == S_OK, "Got hr %#x.\n", hr);
4025 ok(flags == (MixerPref9_NoDecimation | MixerPref9_ARAdjustXorY | MixerPref9_PointFiltering
4026 | MixerPref9_RenderTargetRGB), "Got flags %#x.\n", flags);
4028 IVMRMixerControl9_Release(mixer_control);
4029 ref = IBaseFilter_Release(filter);
4030 ok(!ref, "Got outstanding refcount %d.\n", ref);
4033 START_TEST(vmr9)
4035 IBaseFilter *filter;
4036 HRESULT hr;
4038 CoInitialize(NULL);
4040 if (FAILED(hr = CoCreateInstance(&CLSID_VideoMixingRenderer9, NULL,
4041 CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (void **)&filter)))
4043 skip("Failed to create VMR9, hr %#x.\n", hr);
4044 return;
4046 IBaseFilter_Release(filter);
4048 test_filter_config();
4049 test_interfaces();
4050 test_aggregation();
4051 test_enum_pins();
4052 test_find_pin();
4053 test_pin_info();
4054 test_media_types();
4055 test_enum_media_types();
4056 test_unconnected_filter_state();
4057 test_connect_pin();
4058 test_overlay();
4059 test_video_window();
4060 test_allocate_surface_helper();
4061 test_renderless_formats();
4062 test_mixing_mode();
4063 test_clipping_window();
4064 test_surface_allocator_notify_refcount();
4065 test_basic_video();
4066 test_windowless_size();
4067 test_mixing_prefs();
4069 CoUninitialize();