setupapi: Use SetupGetIntField() in SetupGetSourceFileLocation().
[wine.git] / dlls / evr / tests / evr.c
blob4674221b86d02f49d48504c8a688b2ca4660f2e1
1 /*
2 * Enhanced Video Renderer filter unit tests
4 * Copyright 2018 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 #define COBJMACROS
23 #include "dshow.h"
24 #include "wine/test.h"
25 #include "d3d9.h"
26 #include "evr.h"
27 #include "mferror.h"
28 #include "mfapi.h"
29 #include "initguid.h"
30 #include "evr9.h"
32 static const WCHAR sink_id[] = L"EVR Input0";
34 static void load_resource(const WCHAR *filename, const BYTE **data, DWORD *length)
36 HRSRC resource = FindResourceW(NULL, filename, (const WCHAR *)RT_RCDATA);
37 ok(resource != 0, "FindResourceW failed, error %lu\n", GetLastError());
38 *data = LockResource(LoadResource(GetModuleHandleW(NULL), resource));
39 *length = SizeofResource(GetModuleHandleW(NULL), resource);
42 static DWORD compare_rgb(const BYTE *data, DWORD *length, const SIZE *size, const RECT *rect, const BYTE *expect, UINT bits)
44 DWORD x, y, step = bits / 8, data_size, diff = 0, width = size->cx, height = size->cy;
46 /* skip BMP header from the dump */
47 data_size = *(DWORD *)(expect + 2 + 2 * sizeof(DWORD));
48 *length = *length + data_size;
49 expect = expect + data_size;
51 for (y = 0; y < height; y++, data += width * step, expect += width * step)
53 if (y < rect->top || y >= rect->bottom) continue;
54 for (x = 0; x < width; x++)
56 if (x < rect->left || x >= rect->right) continue;
57 diff += abs((int)expect[step * x + 0] - (int)data[step * x + 0]);
58 diff += abs((int)expect[step * x + 1] - (int)data[step * x + 1]);
59 if (step >= 3) diff += abs((int)expect[step * x + 2] - (int)data[step * x + 2]);
63 data_size = (rect->right - rect->left) * (rect->bottom - rect->top) * min(step, 3);
64 return diff * 100 / 256 / data_size;
67 static DWORD compare_rgb32(const BYTE *data, DWORD *length, const SIZE *size, const RECT *rect, const BYTE *expect)
69 return compare_rgb(data, length, size, rect, expect, 32);
72 static void dump_rgb(const BYTE *data, DWORD length, const SIZE *size, HANDLE output, UINT bits)
74 DWORD width = size->cx, height = size->cy;
75 static const char magic[2] = "BM";
76 struct
78 DWORD length;
79 DWORD reserved;
80 DWORD offset;
81 BITMAPINFOHEADER biHeader;
82 } header =
84 .length = length + sizeof(header) + 2, .offset = sizeof(header) + 2,
85 .biHeader =
87 .biSize = sizeof(BITMAPINFOHEADER), .biWidth = width, .biHeight = height, .biPlanes = 1,
88 .biBitCount = bits, .biCompression = BI_RGB, .biSizeImage = width * height * (bits / 8),
91 DWORD written;
92 BOOL ret;
94 ret = WriteFile(output, magic, sizeof(magic), &written, NULL);
95 ok(ret, "WriteFile failed, error %lu\n", GetLastError());
96 ok(written == sizeof(magic), "written %lu bytes\n", written);
97 ret = WriteFile(output, &header, sizeof(header), &written, NULL);
98 ok(ret, "WriteFile failed, error %lu\n", GetLastError());
99 ok(written == sizeof(header), "written %lu bytes\n", written);
100 ret = WriteFile(output, data, length, &written, NULL);
101 ok(ret, "WriteFile failed, error %lu\n", GetLastError());
102 ok(written == length, "written %lu bytes\n", written);
105 static void dump_rgb32(const BYTE *data, DWORD length, const SIZE *size, HANDLE output)
107 return dump_rgb(data, length, size, output, 32);
110 #define check_rgb32_data(a, b, c, d) check_rgb32_data_(__LINE__, a, b, c, d)
111 static DWORD check_rgb32_data_(int line, const WCHAR *filename, const BYTE *data, DWORD length, const RECT *rect)
113 SIZE size = {rect->right, rect->bottom};
114 WCHAR output_path[MAX_PATH];
115 const BYTE *expect_data;
116 HRSRC resource;
117 HANDLE output;
119 GetTempPathW(ARRAY_SIZE(output_path), output_path);
120 lstrcatW(output_path, filename);
121 output = CreateFileW(output_path, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
122 ok(output != INVALID_HANDLE_VALUE, "CreateFileW failed, error %lu\n", GetLastError());
123 dump_rgb32(data, length, &size, output);
124 trace("created %s\n", debugstr_w(output_path));
125 CloseHandle(output);
127 resource = FindResourceW(NULL, filename, (const WCHAR *)RT_RCDATA);
128 ok(resource != 0, "FindResourceW failed, error %lu\n", GetLastError());
129 expect_data = LockResource(LoadResource(GetModuleHandleW(NULL), resource));
131 return compare_rgb32(data, &length, &size, rect, expect_data);
134 static void set_rect(MFVideoNormalizedRect *rect, float left, float top, float right, float bottom)
136 rect->left = left;
137 rect->top = top;
138 rect->right = right;
139 rect->bottom = bottom;
142 static HWND create_window(void)
144 RECT r = {0, 0, 640, 480};
146 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
148 return CreateWindowA("static", "evr_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
149 0, 0, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
152 static IDirect3DDevice9 *create_device(HWND focus_window)
154 D3DPRESENT_PARAMETERS present_parameters = {0};
155 IDirect3DDevice9 *device = NULL;
156 IDirect3D9 *d3d9;
158 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
159 ok(!!d3d9, "Failed to create a D3D object.\n");
161 present_parameters.BackBufferWidth = 640;
162 present_parameters.BackBufferHeight = 480;
163 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
164 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
165 present_parameters.hDeviceWindow = focus_window;
166 present_parameters.Windowed = TRUE;
167 present_parameters.EnableAutoDepthStencil = TRUE;
168 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
170 IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
171 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
173 IDirect3D9_Release(d3d9);
175 return device;
178 static IBaseFilter *create_evr(void)
180 IBaseFilter *filter = NULL;
181 HRESULT hr = CoCreateInstance(&CLSID_EnhancedVideoRenderer, NULL, CLSCTX_INPROC_SERVER,
182 &IID_IBaseFilter, (void **)&filter);
183 ok(hr == S_OK, "Got hr %#lx.\n", hr);
184 return filter;
187 static IFilterGraph2 *create_graph(void)
189 IFilterGraph2 *ret;
190 HRESULT hr;
192 hr = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterGraph2, (void **)&ret);
193 ok(hr == S_OK, "Failed to create FilterGraph: %#lx\n", hr);
194 return ret;
197 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
198 static void _expect_ref(IUnknown *obj, ULONG ref, int line)
200 ULONG rc;
201 IUnknown_AddRef(obj);
202 rc = IUnknown_Release(obj);
203 ok_(__FILE__,line)(rc == ref, "Unexpected refcount %ld, expected %ld.\n", rc, ref);
206 static ULONG get_refcount(void *iface)
208 IUnknown *unknown = iface;
209 IUnknown_AddRef(unknown);
210 return IUnknown_Release(unknown);
213 static const GUID test_iid = {0x33333333};
214 static LONG outer_ref = 1;
216 static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
218 if (IsEqualGUID(iid, &IID_IUnknown)
219 || IsEqualGUID(iid, &IID_IBaseFilter)
220 || IsEqualGUID(iid, &test_iid))
222 *out = (IUnknown *)0xdeadbeef;
223 return S_OK;
225 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
226 return E_NOINTERFACE;
229 static ULONG WINAPI outer_AddRef(IUnknown *iface)
231 return InterlockedIncrement(&outer_ref);
234 static ULONG WINAPI outer_Release(IUnknown *iface)
236 return InterlockedDecrement(&outer_ref);
239 static const IUnknownVtbl outer_vtbl =
241 outer_QueryInterface,
242 outer_AddRef,
243 outer_Release,
246 static IUnknown test_outer = {&outer_vtbl};
248 static void test_aggregation(void)
250 IBaseFilter *filter, *filter2;
251 IMFVideoPresenter *presenter;
252 IUnknown *unk, *unk2;
253 IMFTransform *mixer;
254 HRESULT hr;
255 ULONG ref;
257 filter = (IBaseFilter *)0xdeadbeef;
258 hr = CoCreateInstance(&CLSID_EnhancedVideoRenderer, &test_outer, CLSCTX_INPROC_SERVER,
259 &IID_IBaseFilter, (void **)&filter);
260 ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr);
261 ok(!filter, "Got interface %p.\n", filter);
263 hr = CoCreateInstance(&CLSID_EnhancedVideoRenderer, &test_outer, CLSCTX_INPROC_SERVER,
264 &IID_IUnknown, (void **)&unk);
265 ok(hr == S_OK, "Got hr %#lx.\n", hr);
266 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
267 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
268 ref = get_refcount(unk);
269 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
271 ref = IUnknown_AddRef(unk);
272 ok(ref == 2, "Got unexpected refcount %ld.\n", ref);
273 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
275 ref = IUnknown_Release(unk);
276 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
277 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
279 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
280 ok(hr == S_OK, "Got hr %#lx.\n", hr);
281 ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
282 IUnknown_Release(unk2);
284 hr = IUnknown_QueryInterface(unk, &IID_IBaseFilter, (void **)&filter);
285 ok(hr == S_OK, "Got hr %#lx.\n", hr);
287 hr = IBaseFilter_QueryInterface(filter, &IID_IUnknown, (void **)&unk2);
288 ok(hr == S_OK, "Got hr %#lx.\n", hr);
289 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
291 hr = IBaseFilter_QueryInterface(filter, &IID_IBaseFilter, (void **)&filter2);
292 ok(hr == S_OK, "Got hr %#lx.\n", hr);
293 ok(filter2 == (IBaseFilter *)0xdeadbeef, "Got unexpected IBaseFilter %p.\n", filter2);
295 hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
296 ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr);
297 ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
299 hr = IBaseFilter_QueryInterface(filter, &test_iid, (void **)&unk2);
300 ok(hr == S_OK, "Got hr %#lx.\n", hr);
301 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
303 IBaseFilter_Release(filter);
304 ref = IUnknown_Release(unk);
305 ok(!ref, "Got unexpected refcount %ld.\n", ref);
306 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
308 /* Default presenter. */
309 presenter = (void *)0xdeadbeef;
310 hr = CoCreateInstance(&CLSID_MFVideoPresenter9, &test_outer, CLSCTX_INPROC_SERVER, &IID_IMFVideoPresenter,
311 (void **)&presenter);
312 ok(hr == E_NOINTERFACE, "Unexpected hr %#lx.\n", hr);
313 ok(!presenter, "Got interface %p.\n", presenter);
315 hr = CoCreateInstance(&CLSID_MFVideoPresenter9, &test_outer, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
316 ok(hr == S_OK || broken(hr == E_FAIL) /* WinXP */, "Unexpected hr %#lx.\n", hr);
317 if (SUCCEEDED(hr))
319 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
320 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
321 ref = get_refcount(unk);
322 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
324 IUnknown_Release(unk);
327 /* Default mixer. */
328 presenter = (void *)0xdeadbeef;
329 hr = CoCreateInstance(&CLSID_MFVideoMixer9, &test_outer, CLSCTX_INPROC_SERVER, &IID_IMFTransform,
330 (void **)&mixer);
331 ok(hr == E_NOINTERFACE, "Unexpected hr %#lx.\n", hr);
332 ok(!mixer, "Got interface %p.\n", mixer);
334 hr = CoCreateInstance(&CLSID_MFVideoMixer9, &test_outer, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk);
335 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
336 ok(outer_ref == 1, "Got unexpected refcount %ld.\n", outer_ref);
337 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
338 ref = get_refcount(unk);
339 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
341 IUnknown_Release(unk);
344 #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
345 static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
347 IUnknown *iface = iface_ptr;
348 HRESULT hr, expected_hr;
349 IUnknown *unk;
351 expected_hr = supported ? S_OK : E_NOINTERFACE;
353 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
354 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
355 if (SUCCEEDED(hr))
356 IUnknown_Release(unk);
359 #define check_service_interface(a, b, c, d) check_service_interface_(__LINE__, a, b, c, d)
360 static void check_service_interface_(unsigned int line, void *iface_ptr, REFGUID service, REFIID iid, BOOL supported)
362 IUnknown *iface = iface_ptr;
363 HRESULT hr, expected_hr;
364 IUnknown *unk;
366 expected_hr = supported ? S_OK : E_NOINTERFACE;
368 hr = MFGetService(iface, service, iid, (void **)&unk);
369 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
370 if (SUCCEEDED(hr))
371 IUnknown_Release(unk);
374 static void test_interfaces(void)
376 IBaseFilter *filter = create_evr(), *filter2;
377 IUnknown *unk;
378 HRESULT hr;
379 ULONG ref;
381 check_interface(filter, &IID_IAMFilterMiscFlags, TRUE);
382 check_interface(filter, &IID_IBaseFilter, TRUE);
383 check_interface(filter, &IID_IEVRFilterConfig, TRUE);
384 check_interface(filter, &IID_IMFGetService, TRUE);
385 check_interface(filter, &IID_IMFVideoRenderer, TRUE);
386 check_interface(filter, &IID_IMediaFilter, TRUE);
387 check_interface(filter, &IID_IMediaPosition, TRUE);
388 check_interface(filter, &IID_IMediaSeeking, TRUE);
389 check_interface(filter, &IID_IMediaEventSink, TRUE);
390 check_interface(filter, &IID_IPersist, TRUE);
391 check_interface(filter, &IID_IUnknown, TRUE);
393 check_interface(filter, &IID_IBasicAudio, FALSE);
394 check_interface(filter, &IID_IBasicVideo, FALSE);
395 check_interface(filter, &IID_IDirectXVideoMemoryConfiguration, FALSE);
396 check_interface(filter, &IID_IMemInputPin, FALSE);
397 check_interface(filter, &IID_IPersistPropertyBag, FALSE);
398 check_interface(filter, &IID_IPin, FALSE);
399 check_interface(filter, &IID_IReferenceClock, FALSE);
400 check_interface(filter, &IID_IVideoWindow, FALSE);
402 /* The scope of IMediaEventSink */
403 hr = IBaseFilter_QueryInterface(filter, &IID_IMediaEventSink, (void **)&unk);
404 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
405 hr = IUnknown_QueryInterface(unk, &IID_IBaseFilter, (void **)&filter2);
406 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
407 ok(filter == filter2, "Unexpected pointer.\n");
408 IBaseFilter_Release(filter2);
409 IUnknown_Release(unk);
411 ref = IBaseFilter_Release(filter);
412 ok(!ref, "Got unexpected refcount %ld.\n", ref);
415 static void test_enum_pins(void)
417 IBaseFilter *filter = create_evr();
418 IEnumPins *enum1, *enum2;
419 ULONG count, ref;
420 IPin *pins[2];
421 HRESULT hr;
423 ref = get_refcount(filter);
424 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
426 hr = IBaseFilter_EnumPins(filter, NULL);
427 ok(hr == E_POINTER, "Got hr %#lx.\n", hr);
429 hr = IBaseFilter_EnumPins(filter, &enum1);
430 ok(hr == S_OK, "Got hr %#lx.\n", hr);
431 ref = get_refcount(filter);
432 ok(ref == 2, "Got unexpected refcount %ld.\n", ref);
433 ref = get_refcount(enum1);
434 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
436 hr = IEnumPins_Next(enum1, 1, NULL, NULL);
437 ok(hr == E_POINTER, "Got hr %#lx.\n", hr);
439 hr = IEnumPins_Next(enum1, 1, pins, NULL);
440 ok(hr == S_OK, "Got hr %#lx.\n", hr);
441 ref = get_refcount(filter);
442 ok(ref == 3, "Got unexpected refcount %ld.\n", ref);
443 ref = get_refcount(pins[0]);
444 ok(ref == 3, "Got unexpected refcount %ld.\n", ref);
445 ref = get_refcount(enum1);
446 ok(ref == 1, "Got unexpected refcount %ld.\n", ref);
447 IPin_Release(pins[0]);
448 ref = get_refcount(filter);
449 ok(ref == 2, "Got unexpected refcount %ld.\n", ref);
451 hr = IEnumPins_Next(enum1, 1, pins, NULL);
452 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
454 hr = IEnumPins_Reset(enum1);
455 ok(hr == S_OK, "Got hr %#lx.\n", hr);
457 hr = IEnumPins_Next(enum1, 1, pins, &count);
458 ok(hr == S_OK, "Got hr %#lx.\n", hr);
459 ok(count == 1, "Got count %lu.\n", count);
460 IPin_Release(pins[0]);
462 hr = IEnumPins_Next(enum1, 1, pins, &count);
463 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
464 ok(!count, "Got count %lu.\n", count);
466 hr = IEnumPins_Reset(enum1);
467 ok(hr == S_OK, "Got hr %#lx.\n", hr);
469 hr = IEnumPins_Next(enum1, 2, pins, NULL);
470 ok(hr == E_INVALIDARG, "Got hr %#lx.\n", hr);
472 hr = IEnumPins_Next(enum1, 2, pins, &count);
473 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
474 ok(count == 1, "Got count %lu.\n", count);
475 IPin_Release(pins[0]);
477 hr = IEnumPins_Reset(enum1);
478 ok(hr == S_OK, "Got hr %#lx.\n", hr);
480 hr = IEnumPins_Clone(enum1, &enum2);
481 ok(hr == S_OK, "Got hr %#lx.\n", hr);
483 hr = IEnumPins_Skip(enum1, 2);
484 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
486 hr = IEnumPins_Skip(enum1, 1);
487 ok(hr == S_OK, "Got hr %#lx.\n", hr);
489 hr = IEnumPins_Skip(enum1, 1);
490 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
492 hr = IEnumPins_Next(enum1, 1, pins, NULL);
493 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
495 hr = IEnumPins_Next(enum2, 1, pins, NULL);
496 ok(hr == S_OK, "Got hr %#lx.\n", hr);
497 IPin_Release(pins[0]);
499 IEnumPins_Release(enum2);
500 IEnumPins_Release(enum1);
501 ref = IBaseFilter_Release(filter);
502 ok(!ref, "Got outstanding refcount %ld.\n", ref);
505 static void test_find_pin(void)
507 IBaseFilter *filter = create_evr();
508 IEnumPins *enum_pins;
509 IPin *pin, *pin2;
510 HRESULT hr;
511 ULONG ref;
513 hr = IBaseFilter_EnumPins(filter, &enum_pins);
514 ok(hr == S_OK, "Got hr %#lx.\n", hr);
516 hr = IBaseFilter_FindPin(filter, sink_id, &pin);
517 ok(hr == S_OK, "Got hr %#lx.\n", hr);
518 hr = IEnumPins_Next(enum_pins, 1, &pin2, NULL);
519 ok(hr == S_OK, "Got hr %#lx.\n", hr);
520 ok(pin2 == pin, "Expected pin %p, got %p.\n", pin, pin2);
521 IPin_Release(pin2);
522 IPin_Release(pin);
524 IEnumPins_Release(enum_pins);
525 ref = IBaseFilter_Release(filter);
526 ok(!ref, "Got outstanding refcount %ld.\n", ref);
529 static void test_pin_info(void)
531 IBaseFilter *filter = create_evr();
532 PIN_DIRECTION dir;
533 PIN_INFO info;
534 HRESULT hr;
535 WCHAR *id;
536 ULONG ref;
537 IPin *pin;
539 hr = IBaseFilter_FindPin(filter, sink_id, &pin);
540 ok(hr == S_OK, "Got hr %#lx.\n", hr);
541 ref = get_refcount(filter);
542 ok(ref == 2, "Got unexpected refcount %ld.\n", ref);
543 ref = get_refcount(pin);
544 ok(ref == 2, "Got unexpected refcount %ld.\n", ref);
546 hr = IPin_QueryPinInfo(pin, &info);
547 ok(hr == S_OK, "Got hr %#lx.\n", hr);
548 ok(info.pFilter == filter, "Expected filter %p, got %p.\n", filter, info.pFilter);
549 ok(info.dir == PINDIR_INPUT, "Got direction %d.\n", info.dir);
550 ok(!lstrcmpW(info.achName, sink_id), "Got name %s.\n", wine_dbgstr_w(info.achName));
551 ref = get_refcount(filter);
552 ok(ref == 3, "Got unexpected refcount %ld.\n", ref);
553 ref = get_refcount(pin);
554 ok(ref == 3, "Got unexpected refcount %ld.\n", ref);
555 IBaseFilter_Release(info.pFilter);
557 hr = IPin_QueryDirection(pin, &dir);
558 ok(hr == S_OK, "Got hr %#lx.\n", hr);
559 ok(dir == PINDIR_INPUT, "Got direction %d.\n", dir);
561 hr = IPin_QueryId(pin, &id);
562 ok(hr == S_OK, "Got hr %#lx.\n", hr);
563 ok(!lstrcmpW(id, sink_id), "Got id %s.\n", wine_dbgstr_w(id));
564 CoTaskMemFree(id);
566 hr = IPin_QueryInternalConnections(pin, NULL, NULL);
567 ok(hr == E_NOTIMPL, "Got hr %#lx.\n", hr);
569 IPin_Release(pin);
570 ref = IBaseFilter_Release(filter);
571 ok(!ref, "Got outstanding refcount %ld.\n", ref);
574 static unsigned int check_event_code(IMediaEvent *eventsrc, DWORD timeout, LONG expected_code, LONG_PTR expected1, LONG_PTR expected2)
576 LONG_PTR param1, param2;
577 unsigned int ret = 0;
578 HRESULT hr;
579 LONG code;
581 while ((hr = IMediaEvent_GetEvent(eventsrc, &code, &param1, &param2, timeout)) == S_OK)
583 if (code == expected_code)
585 ok(param1 == expected1, "Got param1 %#Ix.\n", param1);
586 ok(param2 == expected2, "Got param2 %#Ix.\n", param2);
587 ret++;
589 IMediaEvent_FreeEventParams(eventsrc, code, param1, param2);
590 timeout = 0;
592 ok(hr == E_ABORT, "Got hr %#lx.\n", hr);
594 return ret;
597 static unsigned int check_ec_complete(IMediaEvent *eventsrc, DWORD timeout)
599 return check_event_code(eventsrc, timeout, EC_COMPLETE, S_OK, 0);
602 static void test_unconnected_eos(void)
604 IBaseFilter *filter = create_evr();
605 IFilterGraph2 *graph = create_graph();
606 IMediaControl *control;
607 IMediaEvent *eventsrc;
608 unsigned int ret;
609 HRESULT hr;
610 ULONG ref;
612 hr = IFilterGraph2_AddFilter(graph, filter, L"renderer");
613 ok(hr == S_OK, "Got hr %#lx.\n", hr);
615 hr = IFilterGraph2_QueryInterface(graph, &IID_IMediaControl, (void **)&control);
616 ok(hr == S_OK, "Got hr %#lx.\n", hr);
618 hr = IFilterGraph2_QueryInterface(graph, &IID_IMediaEvent, (void **)&eventsrc);
619 ok(hr == S_OK, "Got hr %#lx.\n", hr);
621 ret = check_ec_complete(eventsrc, 0);
622 ok(!ret, "Got %u EC_COMPLETE events.\n", ret);
624 hr = IMediaControl_Pause(control);
625 ok(hr == S_OK, "Got hr %#lx.\n", hr);
627 ret = check_ec_complete(eventsrc, 0);
628 ok(!ret, "Got %u EC_COMPLETE events.\n", ret);
630 hr = IMediaControl_Run(control);
631 ok(hr == S_OK, "Got hr %#lx.\n", hr);
633 ret = check_ec_complete(eventsrc, 0);
634 ok(ret == 1, "Got %u EC_COMPLETE events.\n", ret);
636 hr = IMediaControl_Pause(control);
637 ok(hr == S_OK, "Got hr %#lx.\n", hr);
639 ret = check_ec_complete(eventsrc, 0);
640 ok(!ret, "Got %u EC_COMPLETE events.\n", ret);
642 hr = IMediaControl_Run(control);
643 ok(hr == S_OK, "Got hr %#lx.\n", hr);
645 ret = check_ec_complete(eventsrc, 0);
646 ok(ret == 1, "Got %u EC_COMPLETE events.\n", ret);
648 hr = IMediaControl_Stop(control);
649 ok(hr == S_OK, "Got hr %#lx.\n", hr);
651 ret = check_ec_complete(eventsrc, 0);
652 ok(!ret, "Got %u EC_COMPLETE events.\n", ret);
654 hr = IMediaControl_Run(control);
655 ok(hr == S_OK, "Got hr %#lx.\n", hr);
657 ret = check_ec_complete(eventsrc, 0);
658 ok(ret == 1, "Got %u EC_COMPLETE events.\n", ret);
660 IMediaControl_Release(control);
661 IMediaEvent_Release(eventsrc);
662 ref = IFilterGraph2_Release(graph);
663 ok(!ref, "Got outstanding refcount %ld.\n", ref);
664 ref = IBaseFilter_Release(filter);
665 ok(!ref, "Got outstanding refcount %ld.\n", ref);
668 static void test_misc_flags(void)
670 IBaseFilter *filter = create_evr();
671 IAMFilterMiscFlags *misc_flags;
672 ULONG ref, flags;
673 HRESULT hr;
675 hr = IBaseFilter_QueryInterface(filter, &IID_IAMFilterMiscFlags, (void **)&misc_flags);
676 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
678 flags = IAMFilterMiscFlags_GetMiscFlags(misc_flags);
679 ok(flags == AM_FILTER_MISC_FLAGS_IS_RENDERER, "Unexpected flags %#lx.\n", flags);
680 IAMFilterMiscFlags_Release(misc_flags);
682 ref = IBaseFilter_Release(filter);
683 ok(!ref, "Got outstanding refcount %ld.\n", ref);
686 static void test_display_control(void)
688 IBaseFilter *filter = create_evr();
689 IMFVideoDisplayControl *display_control;
690 HRESULT hr;
691 ULONG ref;
693 hr = MFGetService((IUnknown *)filter, &MR_VIDEO_RENDER_SERVICE,
694 &IID_IMFVideoDisplayControl, (void **)&display_control);
695 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
697 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, 0);
698 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
700 IMFVideoDisplayControl_Release(display_control);
702 ref = IBaseFilter_Release(filter);
703 ok(!ref, "Got outstanding refcount %ld.\n", ref);
706 static void test_service_lookup(void)
708 IBaseFilter *filter = create_evr();
709 IMFTopologyServiceLookup *service_lookup;
710 IUnknown *unk;
711 DWORD count;
712 HRESULT hr;
713 ULONG ref;
715 hr = IBaseFilter_QueryInterface(filter, &IID_IMFTopologyServiceLookup, (void **)&service_lookup);
716 if (FAILED(hr))
718 win_skip("IMFTopologyServiceLookup is not exposed.\n");
719 IBaseFilter_Release(filter);
720 return;
722 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
724 hr = IMFTopologyServiceLookup_QueryInterface(service_lookup, &IID_IBaseFilter, (void **)&unk);
725 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
726 ok(unk == (IUnknown *)filter, "Unexpected pointer.\n");
727 IUnknown_Release(unk);
729 count = 1;
730 hr = IMFTopologyServiceLookup_LookupService(service_lookup, MF_SERVICE_LOOKUP_GLOBAL, 0,
731 &MR_VIDEO_RENDER_SERVICE, &IID_IMediaEventSink, (void **)&unk, &count);
732 ok(hr == MF_E_NOTACCEPTING, "Unexpected hr %#lx.\n", hr);
734 IMFTopologyServiceLookup_Release(service_lookup);
736 ref = IBaseFilter_Release(filter);
737 ok(!ref, "Got outstanding refcount %ld.\n", ref);
740 static void test_query_accept(void)
742 IBaseFilter *filter = create_evr();
743 AM_MEDIA_TYPE req_mt = {{0}};
744 VIDEOINFOHEADER vih =
746 {0}, {0}, 0, 0, 0,
747 {sizeof(BITMAPINFOHEADER), 32, 24, 1, 0, 0xdeadbeef}
749 unsigned int i;
750 HRESULT hr;
751 ULONG ref;
752 IPin *pin;
754 static const GUID *subtype_tests[] =
756 &MEDIASUBTYPE_RGB32,
757 &MEDIASUBTYPE_YUY2,
760 static const GUID *unsupported_subtype_tests[] =
762 &MEDIASUBTYPE_RGB8,
765 IBaseFilter_FindPin(filter, L"EVR Input0", &pin);
767 req_mt.majortype = MEDIATYPE_Video;
768 req_mt.formattype = FORMAT_VideoInfo;
769 req_mt.cbFormat = sizeof(VIDEOINFOHEADER);
770 req_mt.pbFormat = (BYTE *)&vih;
772 for (i = 0; i < ARRAY_SIZE(subtype_tests); ++i)
774 memcpy(&req_mt.subtype, subtype_tests[i], sizeof(GUID));
775 hr = IPin_QueryAccept(pin, &req_mt);
776 ok(hr == S_OK, "Got hr %#lx.\n", hr);
779 for (i = 0; i < ARRAY_SIZE(unsupported_subtype_tests); ++i)
781 memcpy(&req_mt.subtype, unsupported_subtype_tests[i], sizeof(GUID));
782 hr = IPin_QueryAccept(pin, &req_mt);
783 ok(hr == S_FALSE, "Got hr %#lx.\n", hr);
786 IPin_Release(pin);
788 ref = IBaseFilter_Release(filter);
789 ok(!ref, "Got outstanding refcount %ld.\n", ref);
792 static IMFMediaType * create_video_type(const GUID *subtype)
794 IMFMediaType *video_type;
795 HRESULT hr;
797 hr = MFCreateMediaType(&video_type);
798 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
800 hr = IMFMediaType_SetGUID(video_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
801 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
803 hr = IMFMediaType_SetGUID(video_type, &MF_MT_SUBTYPE, subtype);
804 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
806 return video_type;
809 static void test_default_mixer(void)
811 DWORD input_min, input_max, output_min, output_max;
812 IMFAttributes *attributes, *attributes2;
813 IMFVideoMixerControl2 *mixer_control2;
814 MFT_OUTPUT_STREAM_INFO output_info;
815 MFT_INPUT_STREAM_INFO input_info;
816 DWORD input_count, output_count;
817 IMFVideoProcessor *processor;
818 IMFVideoDeviceID *deviceid;
819 MFVideoNormalizedRect rect;
820 DWORD input_id, output_id;
821 IMFTransform *transform;
822 DXVA2_ValueRange range;
823 DXVA2_Fixed32 dxva_value;
824 UINT32 count, value;
825 COLORREF color;
826 unsigned int i;
827 DWORD ids[16];
828 IUnknown *unk;
829 DWORD flags;
830 GUID *guids;
831 HRESULT hr;
832 IID iid;
834 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&transform);
835 ok(hr == S_OK, "Failed to create default mixer, hr %#lx.\n", hr);
837 check_interface(transform, &IID_IMFQualityAdvise, TRUE);
838 check_interface(transform, &IID_IMFClockStateSink, TRUE);
839 check_interface(transform, &IID_IMFTopologyServiceLookupClient, TRUE);
840 check_interface(transform, &IID_IMFGetService, TRUE);
841 check_interface(transform, &IID_IMFAttributes, TRUE);
842 check_interface(transform, &IID_IMFVideoMixerBitmap, TRUE);
843 check_interface(transform, &IID_IMFVideoPositionMapper, TRUE);
844 check_interface(transform, &IID_IMFVideoProcessor, TRUE);
845 check_interface(transform, &IID_IMFVideoMixerControl, TRUE);
846 check_interface(transform, &IID_IMFVideoDeviceID, TRUE);
847 check_service_interface(transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFVideoMixerBitmap, TRUE);
848 check_service_interface(transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFVideoProcessor, TRUE);
849 check_service_interface(transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFVideoMixerControl, TRUE);
850 check_service_interface(transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFVideoPositionMapper, TRUE);
851 check_service_interface(transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFTransform, FALSE);
853 hr = MFGetService((IUnknown *)transform, &MR_VIDEO_RENDER_SERVICE, &IID_IUnknown, (void **)&unk);
854 ok(hr == MF_E_UNSUPPORTED_SERVICE, "Unexpected hr %#lx.\n", hr);
856 if (SUCCEEDED(MFGetService((IUnknown *)transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFVideoMixerControl2, (void **)&mixer_control2)))
858 hr = IMFVideoMixerControl2_GetMixingPrefs(mixer_control2, NULL);
859 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
861 hr = IMFVideoMixerControl2_GetMixingPrefs(mixer_control2, &flags);
862 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
863 ok(!flags, "Unexpected flags %#lx.\n", flags);
865 IMFVideoMixerControl2_Release(mixer_control2);
868 hr = MFGetService((IUnknown *)transform, &MR_VIDEO_MIXER_SERVICE, &IID_IMFVideoProcessor, (void **)&processor);
869 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
871 hr = IMFVideoProcessor_GetBackgroundColor(processor, NULL);
872 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
874 color = 1;
875 hr = IMFVideoProcessor_GetBackgroundColor(processor, &color);
876 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
877 ok(!color, "Unexpected color %#lx.\n", color);
879 hr = IMFVideoProcessor_SetBackgroundColor(processor, 0x00121212);
880 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
882 hr = IMFVideoProcessor_GetBackgroundColor(processor, &color);
883 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
884 ok(color == 0x121212, "Unexpected color %#lx.\n", color);
886 hr = IMFVideoProcessor_GetFilteringRange(processor, DXVA2_DetailFilterChromaLevel, &range);
887 todo_wine
888 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
890 hr = IMFVideoProcessor_GetFilteringValue(processor, DXVA2_DetailFilterChromaLevel, &dxva_value);
891 todo_wine
892 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
894 hr = IMFVideoProcessor_GetAvailableVideoProcessorModes(processor, &count, &guids);
895 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
897 IMFVideoProcessor_Release(processor);
899 hr = IMFTransform_SetOutputBounds(transform, 100, 10);
900 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
902 hr = IMFTransform_QueryInterface(transform, &IID_IMFVideoDeviceID, (void **)&deviceid);
903 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
905 hr = IMFTransform_GetAttributes(transform, NULL);
906 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
908 hr = IMFTransform_GetAttributes(transform, &attributes);
909 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
911 hr = IMFTransform_GetAttributes(transform, &attributes2);
912 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
913 ok(attributes == attributes2, "Unexpected attributes instance.\n");
914 IMFAttributes_Release(attributes2);
916 hr = IMFTransform_QueryInterface(transform, &IID_IMFAttributes, (void **)&attributes2);
917 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
918 ok(attributes != attributes2, "Unexpected attributes instance.\n");
920 hr = IMFAttributes_QueryInterface(attributes2, &IID_IMFTransform, (void **)&unk);
921 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
922 IUnknown_Release(unk);
924 hr = IMFAttributes_GetCount(attributes2, &count);
925 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
926 ok(count == 1, "Unexpected attribute count %u.\n", count);
928 value = 0;
929 hr = IMFAttributes_GetUINT32(attributes2, &MF_SA_D3D_AWARE, &value);
930 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
931 ok(value == 1, "Unexpected value %d.\n", value);
933 IMFAttributes_Release(attributes2);
935 hr = IMFAttributes_GetCount(attributes, &count);
936 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
937 ok(count == 1, "Unexpected attribute count %u.\n", count);
939 memset(&rect, 0, sizeof(rect));
940 hr = IMFAttributes_GetBlob(attributes, &VIDEO_ZOOM_RECT, (UINT8 *)&rect, sizeof(rect), NULL);
941 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
942 ok(rect.left == 0.0f && rect.top == 0.0f && rect.right == 1.0f && rect.bottom == 1.0f,
943 "Unexpected zoom rect (%f, %f) - (%f, %f).\n", rect.left, rect.top, rect.right, rect.bottom);
945 IMFAttributes_Release(attributes);
947 hr = IMFVideoDeviceID_GetDeviceID(deviceid, NULL);
948 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
950 hr = IMFVideoDeviceID_GetDeviceID(deviceid, &iid);
951 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
952 ok(IsEqualIID(&iid, &IID_IDirect3DDevice9), "Unexpected id %s.\n", wine_dbgstr_guid(&iid));
954 IMFVideoDeviceID_Release(deviceid);
956 /* Stream configuration. */
957 input_count = output_count = 0;
958 hr = IMFTransform_GetStreamCount(transform, &input_count, &output_count);
959 ok(hr == S_OK, "Failed to get stream count, hr %#lx.\n", hr);
960 ok(input_count == 1 && output_count == 1, "Unexpected stream count %lu/%lu.\n", input_count, output_count);
962 hr = IMFTransform_GetStreamLimits(transform, &input_min, &input_max, &output_min, &output_max);
963 ok(hr == S_OK, "Failed to get stream limits, hr %#lx.\n", hr);
964 ok(input_min == 1 && input_max == 16 && output_min == 1 && output_max == 1, "Unexpected stream limits %lu/%lu, %lu/%lu.\n",
965 input_min, input_max, output_min, output_max);
967 hr = IMFTransform_GetInputStreamInfo(transform, 1, &input_info);
968 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
970 hr = IMFTransform_GetOutputStreamInfo(transform, 1, &output_info);
971 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
973 memset(&input_info, 0xcc, sizeof(input_info));
974 hr = IMFTransform_GetInputStreamInfo(transform, 0, &input_info);
975 ok(hr == S_OK, "Failed to get input info, hr %#lx.\n", hr);
977 memset(&output_info, 0xcc, sizeof(output_info));
978 hr = IMFTransform_GetOutputStreamInfo(transform, 0, &output_info);
979 ok(hr == S_OK, "Failed to get input info, hr %#lx.\n", hr);
980 ok(!(output_info.dwFlags & (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES | MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES)),
981 "Unexpected output flags %#lx.\n", output_info.dwFlags);
983 hr = IMFTransform_GetStreamIDs(transform, 1, &input_id, 1, &output_id);
984 ok(hr == S_OK, "Failed to get input info, hr %#lx.\n", hr);
985 ok(input_id == 0 && output_id == 0, "Unexpected stream ids.\n");
987 hr = IMFTransform_GetInputStreamAttributes(transform, 1, &attributes);
988 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
990 hr = IMFTransform_GetOutputStreamAttributes(transform, 1, &attributes);
991 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
993 hr = IMFTransform_GetOutputStreamAttributes(transform, 0, &attributes);
994 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
996 hr = IMFTransform_AddInputStreams(transform, 16, NULL);
997 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
999 hr = IMFTransform_AddInputStreams(transform, 16, ids);
1000 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1002 memset(ids, 0, sizeof(ids));
1003 hr = IMFTransform_AddInputStreams(transform, 15, ids);
1004 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1006 for (i = 0; i < ARRAY_SIZE(ids); ++i)
1007 ids[i] = i + 1;
1009 hr = IMFTransform_AddInputStreams(transform, 15, ids);
1010 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1012 input_count = output_count = 0;
1013 hr = IMFTransform_GetStreamCount(transform, &input_count, &output_count);
1014 ok(hr == S_OK, "Failed to get stream count, hr %#lx.\n", hr);
1015 ok(input_count == 16 && output_count == 1, "Unexpected stream count %lu/%lu.\n", input_count, output_count);
1017 memset(&input_info, 0, sizeof(input_info));
1018 hr = IMFTransform_GetInputStreamInfo(transform, 1, &input_info);
1019 ok(hr == S_OK, "Failed to get input info, hr %#lx.\n", hr);
1020 ok((input_info.dwFlags & (MFT_INPUT_STREAM_REMOVABLE | MFT_INPUT_STREAM_OPTIONAL)) ==
1021 (MFT_INPUT_STREAM_REMOVABLE | MFT_INPUT_STREAM_OPTIONAL), "Unexpected flags %#lx.\n", input_info.dwFlags);
1023 attributes = NULL;
1024 hr = IMFTransform_GetInputStreamAttributes(transform, 0, &attributes);
1025 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1026 hr = IMFAttributes_GetCount(attributes, &count);
1027 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1028 ok(count == 1, "Unexpected count %u.\n", count);
1029 hr = IMFAttributes_GetUINT32(attributes, &MF_SA_REQUIRED_SAMPLE_COUNT, &count);
1030 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1031 ok(count == 1, "Unexpected count %u.\n", count);
1032 ok(!!attributes, "Unexpected attributes.\n");
1034 attributes2 = NULL;
1035 hr = IMFTransform_GetInputStreamAttributes(transform, 0, &attributes2);
1036 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1037 ok(attributes == attributes2, "Unexpected instance.\n");
1039 IMFAttributes_Release(attributes2);
1040 IMFAttributes_Release(attributes);
1042 attributes = NULL;
1043 hr = IMFTransform_GetInputStreamAttributes(transform, 1, &attributes);
1044 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1045 ok(!!attributes, "Unexpected attributes.\n");
1046 IMFAttributes_Release(attributes);
1048 hr = IMFTransform_DeleteInputStream(transform, 0);
1049 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
1051 hr = IMFTransform_DeleteInputStream(transform, 1);
1052 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1054 input_count = output_count = 0;
1055 hr = IMFTransform_GetStreamCount(transform, &input_count, &output_count);
1056 ok(hr == S_OK, "Failed to get stream count, hr %#lx.\n", hr);
1057 ok(input_count == 15 && output_count == 1, "Unexpected stream count %lu/%lu.\n", input_count, output_count);
1059 IMFTransform_Release(transform);
1061 hr = MFCreateVideoMixer(NULL, &IID_IMFTransform, &IID_IMFTransform, (void **)&transform);
1062 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1064 hr = CoCreateInstance(&CLSID_MFVideoMixer9, NULL, CLSCTX_INPROC_SERVER, &IID_IMFTransform, (void **)&transform);
1065 ok(hr == S_OK, "Failed to create default mixer, hr %#lx.\n", hr);
1066 IMFTransform_Release(transform);
1069 static void test_surface_sample(void)
1071 IDirect3DSurface9 *backbuffer = NULL, *surface;
1072 DWORD flags, buffer_count, length;
1073 IMFDesiredSample *desired_sample;
1074 IMFMediaBuffer *buffer, *buffer2;
1075 LONGLONG duration, time1, time2;
1076 IDirect3DSwapChain9 *swapchain;
1077 IDirect3DDevice9 *device;
1078 IMFSample *sample;
1079 IUnknown *unk;
1080 UINT32 count;
1081 HWND window;
1082 HRESULT hr;
1083 BYTE *data;
1085 window = create_window();
1086 if (!(device = create_device(window)))
1088 skip("Failed to create a D3D device, skipping tests.\n");
1089 goto done;
1092 hr = IDirect3DDevice9_GetSwapChain(device, 0, &swapchain);
1093 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1095 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
1096 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1097 ok(backbuffer != NULL, "The back buffer is NULL\n");
1099 IDirect3DSwapChain9_Release(swapchain);
1101 hr = MFCreateVideoSampleFromSurface(NULL, &sample);
1102 ok(hr == S_OK, "Failed to create surface sample, hr %#lx.\n", hr);
1103 IMFSample_Release(sample);
1105 hr = MFCreateVideoSampleFromSurface((IUnknown *)backbuffer, &sample);
1106 ok(hr == S_OK, "Failed to create surface sample, hr %#lx.\n", hr);
1108 hr = IMFSample_QueryInterface(sample, &IID_IMFTrackedSample, (void **)&unk);
1109 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1110 IUnknown_Release(unk);
1112 hr = IMFSample_QueryInterface(sample, &IID_IMFDesiredSample, (void **)&desired_sample);
1113 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1115 hr = IMFSample_GetCount(sample, &count);
1116 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1117 ok(!count, "Unexpected attribute count %u.\n", count);
1119 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, NULL, NULL);
1120 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1122 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, NULL, &time2);
1123 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1125 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, &time1, NULL);
1126 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1128 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, &time1, &time2);
1129 ok(hr == MF_E_NOT_AVAILABLE, "Unexpected hr %#lx.\n", hr);
1131 IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired_sample, 123, 456);
1133 time1 = time2 = 0;
1134 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, &time1, &time2);
1135 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1136 ok(time1 == 123 && time2 == 456, "Unexpected time values.\n");
1138 IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired_sample, 0, 0);
1140 time1 = time2 = 1;
1141 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, &time1, &time2);
1142 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1143 ok(time1 == 0 && time2 == 0, "Unexpected time values.\n");
1145 IMFDesiredSample_Clear(desired_sample);
1147 hr = IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample, &time1, &time2);
1148 ok(hr == MF_E_NOT_AVAILABLE, "Unexpected hr %#lx.\n", hr);
1150 hr = IMFSample_GetCount(sample, &count);
1151 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1152 ok(!count, "Unexpected attribute count %u.\n", count);
1154 /* Attributes are cleared. */
1155 hr = IMFSample_SetUnknown(sample, &MFSampleExtension_Token, NULL);
1156 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1158 hr = IMFSample_GetCount(sample, &count);
1159 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1160 ok(count == 1, "Unexpected attribute count %u.\n", count);
1162 hr = IMFSample_SetSampleTime(sample, 0);
1163 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1165 hr = IMFSample_GetSampleTime(sample, &time1);
1166 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1168 hr = IMFSample_SetSampleDuration(sample, 0);
1169 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1171 hr = IMFSample_GetSampleDuration(sample, &duration);
1172 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1174 hr = IMFSample_SetSampleFlags(sample, 0x1);
1175 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1177 IMFDesiredSample_Clear(desired_sample);
1179 hr = IMFSample_GetCount(sample, &count);
1180 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1181 ok(!count, "Unexpected attribute count %u.\n", count);
1183 hr = IMFSample_GetSampleTime(sample, &time1);
1184 ok(hr == MF_E_NO_SAMPLE_TIMESTAMP, "Unexpected hr %#lx.\n", hr);
1186 hr = IMFSample_GetSampleDuration(sample, &duration);
1187 ok(hr == MF_E_NO_SAMPLE_DURATION, "Unexpected hr %#lx.\n", hr);
1189 hr = IMFSample_GetSampleFlags(sample, &flags);
1190 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1191 ok(!flags, "Unexpected flags %#lx.\n", flags);
1193 IMFDesiredSample_Release(desired_sample);
1195 hr = IMFSample_GetCount(sample, &count);
1196 ok(hr == S_OK, "Failed to get attribute count, hr %#lx.\n", hr);
1197 ok(!count, "Unexpected attribute count.\n");
1199 buffer_count = 0;
1200 hr = IMFSample_GetBufferCount(sample, &buffer_count);
1201 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
1202 ok(buffer_count == 1, "Unexpected attribute count.\n");
1204 hr = IMFSample_GetTotalLength(sample, &length);
1205 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
1206 ok(!length, "Unexpected length %lu.\n", length);
1208 hr = IMFSample_GetSampleDuration(sample, &duration);
1209 ok(hr == MF_E_NO_SAMPLE_DURATION, "Unexpected hr %#lx.\n", hr);
1211 hr = IMFSample_GetSampleTime(sample, &duration);
1212 ok(hr == MF_E_NO_SAMPLE_TIMESTAMP, "Unexpected hr %#lx.\n", hr);
1214 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
1215 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1217 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
1218 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1220 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
1221 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
1222 ok(!length, "Unexpected length %lu.\n", length);
1224 hr = IMFMediaBuffer_SetCurrentLength(buffer, 16);
1225 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
1227 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
1228 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
1229 ok(length == 16, "Unexpected length %lu.\n", length);
1231 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
1232 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1234 hr = IMFMediaBuffer_Unlock(buffer);
1235 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1237 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&unk);
1238 ok(hr == E_NOINTERFACE, "Unexpected hr %#lx.\n", hr);
1240 hr = IMFSample_AddBuffer(sample, buffer);
1241 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1243 hr = IMFSample_GetBufferCount(sample, &buffer_count);
1244 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
1245 ok(buffer_count == 2, "Unexpected buffer count.\n");
1247 hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer2);
1248 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1250 hr = IMFSample_CopyToBuffer(sample, buffer);
1251 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1253 hr = IMFSample_RemoveAllBuffers(sample);
1254 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1256 hr = IMFSample_GetBufferCount(sample, &buffer_count);
1257 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
1258 ok(!buffer_count, "Unexpected buffer count.\n");
1260 hr = MFGetService((IUnknown *)buffer, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, (void **)&surface);
1261 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1262 ok(surface == backbuffer, "Unexpected instance.\n");
1263 IDirect3DSurface9_Release(surface);
1265 hr = MFGetService((IUnknown *)buffer, &MR_BUFFER_SERVICE, &IID_IUnknown, (void **)&surface);
1266 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1267 ok(surface == backbuffer, "Unexpected instance.\n");
1268 IDirect3DSurface9_Release(surface);
1270 IMFMediaBuffer_Release(buffer);
1272 hr = IMFSample_GetSampleFlags(sample, &flags);
1273 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1275 hr = IMFSample_SetSampleFlags(sample, 0x123);
1276 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1278 flags = 0;
1279 hr = IMFSample_GetSampleFlags(sample, &flags);
1280 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1281 ok(flags == 0x123, "Unexpected flags %#lx.\n", flags);
1283 IMFSample_Release(sample);
1284 if (backbuffer)
1285 IDirect3DSurface9_Release(backbuffer);
1286 ok(!IDirect3DDevice9_Release(device), "Unexpected refcount.\n");
1288 done:
1289 DestroyWindow(window);
1292 static void test_default_mixer_type_negotiation(void)
1294 IMFMediaType *media_type, *media_type2;
1295 IDirect3DDeviceManager9 *manager;
1296 DXVA2_VideoProcessorCaps caps;
1297 IMFVideoProcessor *processor;
1298 GUID subtype, guid, *guids;
1299 IDirect3DDevice9 *device;
1300 IMFMediaType *video_type;
1301 IMFTransform *transform;
1302 MFVideoArea aperture;
1303 UINT count, token;
1304 IUnknown *unk;
1305 DWORD index;
1306 HWND window;
1307 HRESULT hr;
1309 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&transform);
1310 ok(hr == S_OK, "Failed to create default mixer, hr %#lx.\n", hr);
1312 hr = IMFTransform_QueryInterface(transform, &IID_IMFVideoProcessor, (void **)&processor);
1313 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1315 hr = IMFTransform_GetInputAvailableType(transform, 0, 0, &media_type);
1316 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1318 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type);
1319 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1321 hr = IMFTransform_GetOutputAvailableType(transform, 0, 0, &media_type);
1322 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1324 hr = MFCreateMediaType(&media_type);
1325 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
1327 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
1328 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1330 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
1331 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1333 hr = IMFTransform_SetInputType(transform, 0, media_type, 0);
1334 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
1336 hr = IMFTransform_SetInputType(transform, 0, media_type, MFT_SET_TYPE_TEST_ONLY);
1337 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
1339 hr = IMFVideoProcessor_GetAvailableVideoProcessorModes(processor, &count, &guids);
1340 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1342 /* Now try with device manager. */
1344 window = create_window();
1345 if (!(device = create_device(window)))
1347 skip("Failed to create a D3D device, skipping tests.\n");
1348 goto done;
1351 hr = IMFTransform_SetInputType(transform, 0, NULL, 0);
1352 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1353 hr = IMFTransform_SetInputType(transform, 0, NULL, MFT_SET_TYPE_TEST_ONLY);
1354 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1356 hr = DXVA2CreateDirect3DDeviceManager9(&token, &manager);
1357 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1359 hr = IMFTransform_ProcessMessage(transform, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)manager);
1360 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1362 /* Now manager is not initialized. */
1363 hr = IMFTransform_SetInputType(transform, 0, media_type, 0);
1364 ok(hr == DXVA2_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
1366 hr = IMFTransform_SetInputType(transform, 0, media_type, MFT_SET_TYPE_TEST_ONLY);
1367 ok(hr == DXVA2_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
1369 hr = IDirect3DDeviceManager9_ResetDevice(manager, device, token);
1370 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1372 /* And now type description is incomplete. */
1373 hr = IMFTransform_SetInputType(transform, 0, media_type, 0);
1374 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
1375 IMFMediaType_Release(media_type);
1377 video_type = create_video_type(&MFVideoFormat_RGB32);
1379 /* Partially initialized type. */
1380 hr = IMFTransform_SetInputType(transform, 0, video_type, 0);
1381 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
1383 /* Only required data - frame size and uncompressed marker. */
1384 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)640 << 32 | 480);
1385 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1386 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
1387 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1388 memset(&aperture, 0, sizeof(aperture));
1389 aperture.Area.cx = 100; aperture.Area.cy = 200;
1390 hr = IMFMediaType_SetBlob(video_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&aperture, sizeof(aperture));
1391 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1392 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_FIXED_SIZE_SAMPLES, 2);
1393 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1395 hr = IMFTransform_SetInputType(transform, 0, video_type, MFT_SET_TYPE_TEST_ONLY);
1396 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1398 hr = IMFTransform_GetOutputAvailableType(transform, 0, 0, &media_type);
1399 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1401 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type);
1402 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1404 hr = IMFTransform_SetInputType(transform, 0, video_type, 0);
1405 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1407 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type);
1408 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1409 ok(media_type == video_type, "Unexpected media type instance.\n");
1411 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type2);
1412 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1413 ok(media_type == media_type2, "Unexpected media type instance.\n");
1414 IMFMediaType_Release(media_type);
1415 IMFMediaType_Release(media_type2);
1417 /* Modified after type was set. */
1418 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_PIXEL_ASPECT_RATIO, (UINT64)56 << 32 | 55);
1419 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1421 /* Check attributes on available output types. */
1422 index = 0;
1423 while (SUCCEEDED(IMFTransform_GetOutputAvailableType(transform, 0, index++, &media_type)))
1425 UINT64 frame_size, ratio;
1426 MFVideoArea aperture;
1427 GUID subtype, major;
1428 UINT32 value;
1430 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &major);
1431 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1432 ok(IsEqualGUID(&major, &MFMediaType_Video), "Unexpected major type.\n");
1433 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &subtype);
1434 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1435 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &frame_size);
1436 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1437 ok(frame_size == ((UINT64)100 << 32 | 200), "Unexpected frame size %s.\n", wine_dbgstr_longlong(frame_size));
1438 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value);
1439 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1440 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value);
1441 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1442 ok(value == MFVideoInterlace_Progressive, "Unexpected interlace mode.\n");
1443 /* Ratio from input type */
1444 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &ratio);
1445 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1446 ok(ratio == ((UINT64)1 << 32 | 1), "Unexpected PAR %s.\n", wine_dbgstr_longlong(ratio));
1447 hr = IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)&aperture, sizeof(aperture), NULL);
1448 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1449 ok(aperture.Area.cx == 100 && aperture.Area.cy == 200, "Unexpected aperture area.\n");
1450 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (UINT8 *)&aperture, sizeof(aperture), NULL);
1451 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1452 ok(aperture.Area.cx == 100 && aperture.Area.cy == 200, "Unexpected aperture area.\n");
1453 hr = IMFMediaType_GetUINT32(video_type, &MF_MT_FIXED_SIZE_SAMPLES, &value);
1454 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1455 ok(value == 2, "Unexpected value %u.\n", value);
1457 IMFMediaType_Release(media_type);
1459 ok(index > 1, "Unexpected number of available types.\n");
1461 hr = IMFMediaType_DeleteItem(video_type, &MF_MT_FIXED_SIZE_SAMPLES);
1462 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1464 hr = IMFTransform_SetInputType(transform, 0, video_type, 0);
1465 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1467 index = 0;
1468 while (SUCCEEDED(IMFTransform_GetOutputAvailableType(transform, 0, index++, &media_type)))
1470 UINT32 value;
1471 UINT64 ratio;
1473 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &ratio);
1474 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1475 ok(ratio == ((UINT64)56 << 32 | 55), "Unexpected PAR %s.\n", wine_dbgstr_longlong(ratio));
1477 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value);
1478 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1479 ok(value == 1, "Unexpected value %u.\n", value);
1481 IMFMediaType_Release(media_type);
1483 ok(index > 1, "Unexpected number of available types.\n");
1485 /* Cloned type is returned. */
1486 hr = IMFTransform_GetOutputAvailableType(transform, 0, 0, &media_type);
1487 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1488 hr = IMFTransform_GetOutputAvailableType(transform, 0, 0, &media_type2);
1489 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1490 ok(media_type != media_type2, "Unexpected media type instance.\n");
1491 IMFMediaType_Release(media_type);
1492 IMFMediaType_Release(media_type2);
1494 /* Minimal valid attribute set for output type. */
1495 hr = IMFTransform_GetOutputAvailableType(transform, 0, 0, &media_type);
1496 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1498 hr = MFCreateMediaType(&media_type2);
1499 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1501 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &subtype);
1502 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1504 hr = IMFMediaType_SetGUID(media_type2, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
1505 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1506 hr = IMFMediaType_SetGUID(media_type2, &MF_MT_SUBTYPE, &subtype);
1507 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1509 hr = IMFTransform_SetOutputType(transform, 1, NULL, MFT_SET_TYPE_TEST_ONLY);
1510 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
1512 hr = IMFTransform_SetOutputType(transform, 0, NULL, MFT_SET_TYPE_TEST_ONLY);
1513 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1515 hr = IMFTransform_SetOutputType(transform, 0, media_type2, MFT_SET_TYPE_TEST_ONLY);
1516 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
1518 hr = IMFMediaType_SetUINT32(media_type2, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
1519 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1521 hr = IMFTransform_SetOutputType(transform, 0, media_type2, MFT_SET_TYPE_TEST_ONLY);
1522 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1524 /* Candidate type have frame size set, mismatching size is accepted. */
1525 hr = IMFMediaType_SetUINT64(media_type2, &MF_MT_FRAME_SIZE, (UINT64)64 << 32 | 64);
1526 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1528 hr = IMFTransform_SetOutputType(transform, 0, media_type2, MFT_SET_TYPE_TEST_ONLY);
1529 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1531 IMFMediaType_Release(media_type2);
1532 IMFMediaType_Release(media_type);
1534 hr = IMFVideoProcessor_GetVideoProcessorMode(processor, &guid);
1535 todo_wine
1536 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1538 hr = IMFVideoProcessor_GetVideoProcessorCaps(processor, (GUID *)&DXVA2_VideoProcSoftwareDevice, &caps);
1539 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1541 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type);
1542 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1543 ok(media_type == video_type, "Unexpected pointer.\n");
1544 hr = IMFMediaType_QueryInterface(media_type, &IID_IMFVideoMediaType, (void **)&unk);
1545 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1546 IUnknown_Release(unk);
1547 IMFMediaType_Release(media_type);
1549 hr = IMFVideoProcessor_GetAvailableVideoProcessorModes(processor, &count, &guids);
1550 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1552 hr = IMFTransform_GetOutputAvailableType(transform, 0, 0, &media_type);
1553 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1555 hr = IMFTransform_SetOutputType(transform, 1, media_type, 0);
1556 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
1558 hr = IMFTransform_SetOutputType(transform, 0, media_type, 0);
1559 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1561 hr = IMFVideoProcessor_GetVideoProcessorMode(processor, &guid);
1562 todo_wine
1563 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
1565 hr = IMFVideoProcessor_GetAvailableVideoProcessorModes(processor, &count, &guids);
1566 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1567 ok(count > 0 && !!guids, "Unexpected modes data.\n");
1568 CoTaskMemFree(guids);
1570 hr = IMFVideoProcessor_GetVideoProcessorCaps(processor, (GUID *)&DXVA2_VideoProcSoftwareDevice, &caps);
1571 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1573 hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type2);
1574 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1575 ok(media_type == media_type2, "Unexpected media type instance.\n");
1577 IMFMediaType_Release(media_type);
1579 /* Clear input types */
1580 hr = IMFTransform_SetInputType(transform, 0, NULL, MFT_SET_TYPE_TEST_ONLY);
1581 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1583 hr = IMFTransform_SetInputType(transform, 0, NULL, 0);
1584 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1585 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type);
1586 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1587 hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type);
1588 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1590 /* Restore types */
1591 hr = IMFTransform_SetOutputType(transform, 0, media_type2, 0);
1592 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
1593 hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type);
1594 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
1596 hr = IMFTransform_SetInputType(transform, 0, video_type, 0);
1597 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1598 hr = IMFTransform_GetInputCurrentType(transform, 0, &media_type);
1599 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1600 ok(media_type == video_type, "Unexpected media type instance.\n");
1601 IMFMediaType_Release(media_type);
1603 hr = IMFTransform_SetOutputType(transform, 0, media_type2, 0);
1604 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1605 hr = IMFTransform_GetOutputCurrentType(transform, 0, &media_type);
1606 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1607 ok(media_type2 == media_type, "Unexpected media type instance.\n");
1609 IMFMediaType_Release(media_type2);
1610 IMFMediaType_Release(media_type);
1612 /* Resetting type twice */
1613 hr = IMFTransform_SetInputType(transform, 0, NULL, 0);
1614 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1615 hr = IMFTransform_SetInputType(transform, 0, NULL, 0);
1616 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1618 IMFVideoProcessor_Release(processor);
1620 IMFMediaType_Release(video_type);
1622 IDirect3DDeviceManager9_Release(manager);
1624 IDirect3DDevice9_Release(device);
1626 done:
1627 IMFTransform_Release(transform);
1628 DestroyWindow(window);
1631 static void test_default_presenter(void)
1633 IMFVideoDisplayControl *display_control;
1634 IMFVideoPresenter *presenter;
1635 IMFRateSupport *rate_support;
1636 IDirect3DDeviceManager9 *dm;
1637 IMFVideoDeviceID *deviceid;
1638 IUnknown *unk, *unk2;
1639 HWND hwnd, hwnd2;
1640 DWORD flags;
1641 float rate;
1642 HRESULT hr;
1643 GUID iid;
1645 hr = MFCreateVideoPresenter(NULL, &IID_IMFVideoPresenter, &IID_IMFVideoPresenter, (void **)&presenter);
1646 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1648 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
1649 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
1651 check_interface(presenter, &IID_IQualProp, TRUE);
1652 check_interface(presenter, &IID_IMFVideoPositionMapper, TRUE);
1653 check_interface(presenter, &IID_IMFTopologyServiceLookupClient, TRUE);
1654 check_interface(presenter, &IID_IMFVideoDisplayControl, TRUE);
1655 check_interface(presenter, &IID_IMFRateSupport, TRUE);
1656 check_interface(presenter, &IID_IMFGetService, TRUE);
1657 check_interface(presenter, &IID_IMFClockStateSink, TRUE);
1658 check_interface(presenter, &IID_IMFVideoPresenter, TRUE);
1659 check_interface(presenter, &IID_IMFVideoDeviceID, TRUE);
1660 check_interface(presenter, &IID_IMFQualityAdvise, TRUE);
1661 check_interface(presenter, &IID_IDirect3DDeviceManager9, TRUE);
1662 check_interface(presenter, &IID_IMFQualityAdviseLimits, TRUE);
1663 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFVideoPositionMapper, TRUE);
1664 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFVideoDisplayControl, TRUE);
1665 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFVideoPresenter, TRUE);
1666 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFClockStateSink, TRUE);
1667 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFTopologyServiceLookupClient, TRUE);
1668 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IQualProp, TRUE);
1669 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFRateSupport, TRUE);
1670 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFGetService, TRUE);
1671 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFVideoDeviceID, TRUE);
1672 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFQualityAdvise, TRUE);
1673 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFQualityAdviseLimits, TRUE);
1674 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFTransform, FALSE);
1675 check_service_interface(presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IDirect3DDeviceManager9, TRUE);
1676 check_service_interface(presenter, &MR_VIDEO_ACCELERATION_SERVICE, &IID_IDirect3DDeviceManager9, TRUE);
1678 /* Query arbitrary supported interface back from device manager wrapper. */
1679 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IDirect3DDeviceManager9, (void **)&dm);
1680 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1681 hr = IDirect3DDeviceManager9_QueryInterface(dm, &IID_IQualProp, (void **)&unk);
1682 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1683 IUnknown_Release(unk);
1684 hr = IDirect3DDeviceManager9_QueryInterface(dm, &IID_IUnknown, (void **)&unk);
1685 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1686 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IUnknown, (void **)&unk2);
1687 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1688 ok(unk == unk2, "Unexpected interface.\n");
1689 IUnknown_Release(unk2);
1690 IUnknown_Release(unk);
1691 IDirect3DDeviceManager9_Release(dm);
1693 hr = MFGetService((IUnknown *)presenter, &MR_VIDEO_MIXER_SERVICE, &IID_IUnknown, (void **)&unk);
1694 ok(hr == MF_E_UNSUPPORTED_SERVICE, "Unexpected hr %#lx.\n", hr);
1696 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDeviceID, (void **)&deviceid);
1697 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1699 hr = IMFVideoDeviceID_GetDeviceID(deviceid, NULL);
1700 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1702 hr = IMFVideoDeviceID_GetDeviceID(deviceid, &iid);
1703 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1704 ok(IsEqualIID(&iid, &IID_IDirect3DDevice9), "Unexpected id %s.\n", wine_dbgstr_guid(&iid));
1706 IMFVideoDeviceID_Release(deviceid);
1708 hr = MFGetService((IUnknown *)presenter, &MR_VIDEO_RENDER_SERVICE, &IID_IMFVideoDisplayControl, (void **)&display_control);
1709 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1711 hr = IMFVideoDisplayControl_GetRenderingPrefs(display_control, NULL);
1712 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1714 flags = 123;
1715 hr = IMFVideoDisplayControl_GetRenderingPrefs(display_control, &flags);
1716 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1717 ok(!flags, "Unexpected rendering flags %#lx.\n", flags);
1719 IMFVideoDisplayControl_Release(display_control);
1721 hr = MFGetService((IUnknown *)presenter, &MR_VIDEO_ACCELERATION_SERVICE, &IID_IDirect3DDeviceManager9, (void **)&dm);
1722 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1723 IDirect3DDeviceManager9_Release(dm);
1725 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
1726 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1728 /* Video window */
1729 hwnd = create_window();
1730 ok(!!hwnd, "Failed to create a test window.\n");
1732 hr = IMFVideoDisplayControl_GetVideoWindow(display_control, NULL);
1733 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1735 hwnd2 = hwnd;
1736 hr = IMFVideoDisplayControl_GetVideoWindow(display_control, &hwnd2);
1737 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1738 ok(hwnd2 == NULL, "Unexpected window %p.\n", hwnd2);
1740 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, NULL);
1741 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1743 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, (HWND)0x1);
1744 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1746 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, hwnd);
1747 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1749 hwnd2 = NULL;
1750 hr = IMFVideoDisplayControl_GetVideoWindow(display_control, &hwnd2);
1751 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1752 ok(hwnd2 == hwnd, "Unexpected window %p.\n", hwnd2);
1753 IMFVideoDisplayControl_Release(display_control);
1755 /* Rate support. */
1756 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFRateSupport, (void **)&rate_support);
1757 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1759 rate = 1.0f;
1760 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_FORWARD, FALSE, &rate);
1761 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1762 ok(rate == 0.0f, "Unexpected rate %f.\n", rate);
1764 rate = 1.0f;
1765 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_FORWARD, TRUE, &rate);
1766 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1767 ok(rate == 0.0f, "Unexpected rate %f.\n", rate);
1769 rate = 1.0f;
1770 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_REVERSE, FALSE, &rate);
1771 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1772 ok(rate == 0.0f, "Unexpected rate %f.\n", rate);
1774 rate = 1.0f;
1775 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_REVERSE, TRUE, &rate);
1776 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1777 ok(rate == 0.0f, "Unexpected rate %f.\n", rate);
1779 IMFRateSupport_Release(rate_support);
1781 ok(!IMFVideoPresenter_Release(presenter), "Unexpected refcount.\n");
1783 DestroyWindow(hwnd);
1786 static void test_MFCreateVideoMixerAndPresenter(void)
1788 IUnknown *mixer, *presenter;
1789 HRESULT hr;
1791 hr = MFCreateVideoMixerAndPresenter(NULL, NULL, &IID_IUnknown, (void **)&mixer, &IID_IUnknown, (void **)&presenter);
1792 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1794 IUnknown_Release(mixer);
1795 IUnknown_Release(presenter);
1798 static HRESULT WINAPI test_notify_callback_QueryInterface(IMFVideoSampleAllocatorNotify *iface,
1799 REFIID riid, void **obj)
1801 if (IsEqualIID(riid, &IID_IMFVideoSampleAllocatorNotify) ||
1802 IsEqualIID(riid, &IID_IUnknown))
1804 *obj = iface;
1805 IMFVideoSampleAllocatorNotify_AddRef(iface);
1806 return S_OK;
1809 *obj = NULL;
1810 return E_NOINTERFACE;
1813 static ULONG WINAPI test_notify_callback_AddRef(IMFVideoSampleAllocatorNotify *iface)
1815 return 2;
1818 static ULONG WINAPI test_notify_callback_Release(IMFVideoSampleAllocatorNotify *iface)
1820 return 1;
1823 static HRESULT WINAPI test_notify_callback_NotifyRelease(IMFVideoSampleAllocatorNotify *iface)
1825 return E_NOTIMPL;
1828 static const IMFVideoSampleAllocatorNotifyVtbl test_notify_callback_vtbl =
1830 test_notify_callback_QueryInterface,
1831 test_notify_callback_AddRef,
1832 test_notify_callback_Release,
1833 test_notify_callback_NotifyRelease,
1836 static void test_MFCreateVideoSampleAllocator(void)
1838 IMFVideoSampleAllocatorNotify test_notify = { &test_notify_callback_vtbl };
1839 IMFVideoSampleAllocatorCallback *allocator_cb;
1840 IMFMediaType *media_type, *video_type;
1841 IMFVideoSampleAllocator *allocator;
1842 IDirect3DDeviceManager9 *manager;
1843 IMFSample *sample, *sample2;
1844 IDirect3DSurface9 *surface;
1845 IDirect3DDevice9 *device;
1846 IMFMediaBuffer *buffer;
1847 LONG refcount, count;
1848 unsigned int token;
1849 IMFGetService *gs;
1850 IUnknown *unk;
1851 HWND window;
1852 HRESULT hr;
1853 BYTE *data;
1855 hr = MFCreateVideoSampleAllocator(&IID_IUnknown, (void **)&unk);
1856 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1857 IUnknown_Release(unk);
1859 hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator, (void **)&allocator);
1860 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1862 hr = IMFVideoSampleAllocator_QueryInterface(allocator, &IID_IMFVideoSampleAllocatorCallback, (void **)&allocator_cb);
1863 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1865 hr = IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb, NULL);
1866 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1868 hr = IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb, &test_notify);
1869 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1871 hr = IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb, NULL);
1872 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1874 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, NULL);
1875 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1877 count = 10;
1878 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
1879 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1880 ok(!count, "Unexpected count %ld.\n", count);
1882 hr = IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator);
1883 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1885 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
1886 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
1888 hr = IMFVideoSampleAllocator_SetDirectXManager(allocator, NULL);
1889 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1891 hr = MFCreateMediaType(&media_type);
1892 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1894 /* It expects IMFVideoMediaType aka video major type. Exact return code is E_NOINTERFACE,
1895 likely coming from querying for IMFVideoMediaType. Does not seem valuable to match it. */
1896 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, media_type);
1897 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
1899 video_type = create_video_type(&MFVideoFormat_RGB32);
1901 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, video_type);
1902 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
1904 /* Frame size is required. */
1905 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 320 << 32 | 240);
1906 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1907 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 0, video_type);
1908 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1910 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
1911 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1912 ok(count == 1, "Unexpected count %ld.\n", count);
1914 sample = NULL;
1915 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
1916 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1917 refcount = get_refcount(sample);
1919 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample2);
1920 ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#lx.\n", hr);
1922 /* Reinitialize with active sample. */
1923 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 4, video_type);
1924 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1925 ok(refcount == get_refcount(sample), "Unexpected refcount %lu.\n", get_refcount(sample));
1927 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
1928 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1929 ok(count == 4, "Unexpected count %ld.\n", count);
1931 check_interface(sample, &IID_IMFDesiredSample, TRUE);
1932 check_interface(sample, &IID_IMFTrackedSample, TRUE);
1934 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
1935 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1937 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
1939 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFGetService, (void **)&gs);
1940 ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* Win7 */, "Unexpected hr %#lx.\n", hr);
1942 /* Device manager wasn't set, sample gets regular memory buffers. */
1943 if (SUCCEEDED(hr))
1945 hr = IMFGetService_GetService(gs, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, (void **)&surface);
1946 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
1947 IMFGetService_Release(gs);
1950 IMFMediaBuffer_Release(buffer);
1952 IMFSample_Release(sample);
1954 IMFVideoSampleAllocatorCallback_Release(allocator_cb);
1956 IMFVideoSampleAllocator_Release(allocator);
1958 hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocatorCallback, (void **)&unk);
1959 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1960 IUnknown_Release(unk);
1962 /* Using device manager */
1963 window = create_window();
1964 if (!(device = create_device(window)))
1966 skip("Failed to create a D3D device, skipping tests.\n");
1967 IMFMediaType_Release(video_type);
1968 IMFMediaType_Release(media_type);
1969 DestroyWindow(window);
1970 return;
1973 hr = DXVA2CreateDirect3DDeviceManager9(&token, &manager);
1974 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1975 hr = IDirect3DDeviceManager9_ResetDevice(manager, device, token);
1976 ok(hr == S_OK, "Failed to set a device, hr %#lx.\n", hr);
1978 hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator, (void **)&allocator);
1979 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1981 hr = IMFVideoSampleAllocator_SetDirectXManager(allocator, (IUnknown *)manager);
1982 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1984 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 320 << 32 | 240);
1985 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1986 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 0, video_type);
1987 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1989 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
1990 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1992 check_interface(sample, &IID_IMFTrackedSample, TRUE);
1993 check_interface(sample, &IID_IMFDesiredSample, TRUE);
1995 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
1996 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1998 check_service_interface(buffer, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, TRUE);
1999 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
2000 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
2002 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
2003 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2005 hr = IMFMediaBuffer_Unlock(buffer);
2006 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2008 IMFMediaBuffer_Release(buffer);
2009 IMFSample_Release(sample);
2010 IMFVideoSampleAllocator_Release(allocator);
2011 IMFMediaType_Release(video_type);
2012 IMFMediaType_Release(media_type);
2013 IDirect3DDeviceManager9_Release(manager);
2014 IDirect3DDevice9_Release(device);
2015 DestroyWindow(window);
2018 struct test_host
2020 IMFTopologyServiceLookup IMFTopologyServiceLookup_iface;
2021 IMediaEventSink IMediaEventSink_iface;
2022 IMFTransform *mixer;
2023 IMFVideoPresenter *presenter;
2026 static struct test_host *impl_from_test_host(IMFTopologyServiceLookup *iface)
2028 return CONTAINING_RECORD(iface, struct test_host, IMFTopologyServiceLookup_iface);
2031 static struct test_host *impl_from_test_host_events(IMediaEventSink *iface)
2033 return CONTAINING_RECORD(iface, struct test_host, IMediaEventSink_iface);
2036 static HRESULT WINAPI test_host_QueryInterface(IMFTopologyServiceLookup *iface, REFIID riid, void **obj)
2038 if (IsEqualIID(riid, &IID_IMFTopologyServiceLookup) ||
2039 IsEqualIID(riid, &IID_IUnknown))
2041 *obj = iface;
2042 IMFTopologyServiceLookup_AddRef(iface);
2043 return S_OK;
2046 *obj = NULL;
2047 return E_NOINTERFACE;
2050 static ULONG WINAPI test_host_AddRef(IMFTopologyServiceLookup *iface)
2052 return 2;
2055 static ULONG WINAPI test_host_Release(IMFTopologyServiceLookup *iface)
2057 return 1;
2060 static HRESULT WINAPI test_host_LookupService(IMFTopologyServiceLookup *iface,
2061 MF_SERVICE_LOOKUP_TYPE lookup_type, DWORD index, REFGUID service,
2062 REFIID riid, void **objects, DWORD *num_objects)
2064 struct test_host *host = impl_from_test_host(iface);
2066 ok(*num_objects == 1, "Unexpected number of requested objects %lu\n", *num_objects);
2068 memset(objects, 0, *num_objects * sizeof(*objects));
2070 if (IsEqualGUID(service, &MR_VIDEO_RENDER_SERVICE))
2072 if (IsEqualIID(riid, &IID_IMFClock)) return E_FAIL;
2073 if (IsEqualIID(riid, &IID_IMediaEventSink))
2075 *objects = &host->IMediaEventSink_iface;
2076 IMediaEventSink_AddRef(&host->IMediaEventSink_iface);
2077 return S_OK;
2080 ok(0, "Unexpected interface %s.\n", wine_dbgstr_guid(riid));
2081 return E_UNEXPECTED;
2084 if (IsEqualGUID(service, &MR_VIDEO_MIXER_SERVICE))
2086 if (IsEqualIID(riid, &IID_IMFTransform))
2088 *objects = host->mixer;
2089 IMFTransform_AddRef(host->mixer);
2090 return S_OK;
2092 ok(0, "Unexpected interface %s.\n", wine_dbgstr_guid(riid));
2093 return E_UNEXPECTED;
2096 return E_NOTIMPL;
2099 static const IMFTopologyServiceLookupVtbl test_host_vtbl =
2101 test_host_QueryInterface,
2102 test_host_AddRef,
2103 test_host_Release,
2104 test_host_LookupService,
2107 static HRESULT WINAPI test_host_events_QueryInterface(IMediaEventSink *iface, REFIID riid, void **obj)
2109 struct test_host *host = impl_from_test_host_events(iface);
2110 return IMFTopologyServiceLookup_QueryInterface(&host->IMFTopologyServiceLookup_iface, riid, obj);
2113 static ULONG WINAPI test_host_events_AddRef(IMediaEventSink *iface)
2115 struct test_host *host = impl_from_test_host_events(iface);
2116 return IMFTopologyServiceLookup_AddRef(&host->IMFTopologyServiceLookup_iface);
2119 static ULONG WINAPI test_host_events_Release(IMediaEventSink *iface)
2121 struct test_host *host = impl_from_test_host_events(iface);
2122 return IMFTopologyServiceLookup_Release(&host->IMFTopologyServiceLookup_iface);
2125 static HRESULT WINAPI test_host_events_Notify(IMediaEventSink *iface, LONG code, LONG_PTR param1, LONG_PTR param2)
2127 return S_OK;
2130 static const IMediaEventSinkVtbl test_host_events_vtbl =
2132 test_host_events_QueryInterface,
2133 test_host_events_AddRef,
2134 test_host_events_Release,
2135 test_host_events_Notify,
2138 static void init_test_host(struct test_host *host, IMFTransform *mixer, IMFVideoPresenter *presenter)
2140 host->IMFTopologyServiceLookup_iface.lpVtbl = &test_host_vtbl;
2141 host->IMediaEventSink_iface.lpVtbl = &test_host_events_vtbl;
2142 /* No need to keep references. */
2143 host->mixer = mixer;
2144 host->presenter = presenter;
2147 static void test_presenter_video_position(void)
2149 IMFTopologyServiceLookupClient *lookup_client;
2150 IMFVideoDisplayControl *display_control;
2151 IMFAttributes *mixer_attributes;
2152 MFVideoNormalizedRect src_rect;
2153 IMFVideoPresenter *presenter;
2154 struct test_host host;
2155 IMFTransform *mixer;
2156 RECT dst_rect;
2157 UINT32 count;
2158 HRESULT hr;
2159 HWND hwnd;
2161 hwnd = create_window();
2162 ok(!!hwnd, "Failed to create a test window.\n");
2164 /* Setting position without the mixer. */
2165 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
2166 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2167 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
2168 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2170 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
2171 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
2172 SetRect(&dst_rect, 0, 0, 10, 10);
2173 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst_rect);
2174 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2175 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, hwnd);
2176 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2178 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
2179 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
2180 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst_rect);
2181 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2183 IMFVideoDisplayControl_Release(display_control);
2184 IMFVideoPresenter_Release(presenter);
2186 /* With the mixer. */
2187 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
2188 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
2190 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
2191 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2193 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
2194 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2196 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
2197 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2199 init_test_host(&host, mixer, presenter);
2201 /* Clear default mixer attributes, then attach presenter. */
2202 hr = IMFTransform_GetAttributes(mixer, &mixer_attributes);
2203 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2205 hr = IMFAttributes_DeleteAllItems(mixer_attributes);
2206 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2208 hr = IMFTopologyServiceLookupClient_InitServicePointers(lookup_client, &host.IMFTopologyServiceLookup_iface);
2209 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2211 hr = IMFAttributes_GetCount(mixer_attributes, &count);
2212 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2213 ok(count == 1, "Unexpected count %u.\n", count);
2215 memset(&src_rect, 0, sizeof(src_rect));
2216 hr = IMFAttributes_GetBlob(mixer_attributes, &VIDEO_ZOOM_RECT, (UINT8 *)&src_rect, sizeof(src_rect), NULL);
2217 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2218 ok(src_rect.left == 0.0f && src_rect.top == 0.0f && src_rect.right == 1.0f &&
2219 src_rect.bottom == 1.0f, "Unexpected source rectangle.\n");
2221 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, NULL, &dst_rect);
2222 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2224 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, &src_rect, NULL);
2225 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2227 SetRect(&dst_rect, 1, 2, 3, 4);
2228 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, &src_rect, &dst_rect);
2229 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2230 ok(src_rect.left == 0.0f && src_rect.top == 0.0f && src_rect.right == 1.0f &&
2231 src_rect.bottom == 1.0f, "Unexpected source rectangle.\n");
2232 ok(dst_rect.left == 0 && dst_rect.right == 0 && dst_rect.top == 0 && dst_rect.bottom == 0,
2233 "Unexpected destination rectangle %s.\n", wine_dbgstr_rect(&dst_rect));
2235 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, NULL);
2236 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2238 /* Setting position requires a window. */
2239 SetRect(&dst_rect, 0, 0, 10, 10);
2240 memset(&src_rect, 0, sizeof(src_rect));
2241 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, &src_rect, &dst_rect);
2242 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2244 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, hwnd);
2245 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2247 SetRect(&dst_rect, 0, 0, 10, 10);
2248 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst_rect);
2249 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2251 SetRect(&dst_rect, 1, 2, 3, 4);
2252 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, &src_rect, &dst_rect);
2253 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2254 ok(dst_rect.left == 0 && dst_rect.right == 10 && dst_rect.top == 0 && dst_rect.bottom == 10,
2255 "Unexpected destination rectangle %s.\n", wine_dbgstr_rect(&dst_rect));
2257 set_rect(&src_rect, 0.0f, 0.0f, 2.0f, 1.0f);
2258 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, &src_rect, NULL);
2259 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2261 set_rect(&src_rect, -0.1f, 0.0f, 0.9f, 1.0f);
2262 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, &src_rect, NULL);
2263 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2265 /* Flipped source rectangle. */
2266 set_rect(&src_rect, 0.5f, 0.0f, 0.4f, 1.0f);
2267 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, &src_rect, NULL);
2268 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2270 set_rect(&src_rect, 0.0f, 0.5f, 0.4f, 0.1f);
2271 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, &src_rect, NULL);
2272 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2274 set_rect(&src_rect, 0.1f, 0.2f, 0.8f, 0.9f);
2275 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, &src_rect, NULL);
2276 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2278 /* Presenter updates mixer attribute. */
2279 memset(&src_rect, 0, sizeof(src_rect));
2280 hr = IMFAttributes_GetBlob(mixer_attributes, &VIDEO_ZOOM_RECT, (UINT8 *)&src_rect, sizeof(src_rect), NULL);
2281 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2282 ok(src_rect.left == 0.1f && src_rect.top == 0.2f && src_rect.right == 0.8f &&
2283 src_rect.bottom == 0.9f, "Unexpected source rectangle.\n");
2285 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, &src_rect, &dst_rect);
2286 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2287 ok(src_rect.left == 0.1f && src_rect.top == 0.2f && src_rect.right == 0.8f &&
2288 src_rect.bottom == 0.9f, "Unexpected source rectangle.\n");
2290 SetRect(&dst_rect, 1, 2, 999, 1000);
2291 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst_rect);
2292 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2294 SetRect(&dst_rect, 0, 1, 3, 4);
2295 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, &src_rect, &dst_rect);
2296 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2297 ok(dst_rect.left == 1 && dst_rect.right == 999 && dst_rect.top == 2 && dst_rect.bottom == 1000,
2298 "Unexpected destination rectangle %s.\n", wine_dbgstr_rect(&dst_rect));
2300 /* Flipped destination rectangle. */
2301 SetRect(&dst_rect, 100, 1, 50, 1000);
2302 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst_rect);
2303 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2305 SetRect(&dst_rect, 1, 100, 100, 50);
2306 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst_rect);
2307 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2309 IMFVideoDisplayControl_Release(display_control);
2311 IMFTopologyServiceLookupClient_Release(lookup_client);
2312 IMFVideoPresenter_Release(presenter);
2313 IMFAttributes_Release(mixer_attributes);
2314 IMFTransform_Release(mixer);
2316 DestroyWindow(hwnd);
2319 static void test_presenter_native_video_size(void)
2321 IMFTopologyServiceLookupClient *lookup_client;
2322 IMFVideoDisplayControl *display_control;
2323 IMFVideoPresenter *presenter;
2324 struct test_host host;
2325 IMFTransform *mixer;
2326 SIZE size, ratio;
2327 HRESULT hr;
2328 IMFMediaType *video_type;
2329 IDirect3DDeviceManager9 *dm;
2331 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
2332 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
2334 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
2335 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2337 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
2338 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2339 IMFTopologyServiceLookupClient_Release(lookup_client);
2341 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
2342 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2344 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, NULL, NULL);
2345 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2347 memset(&size, 0xcc, sizeof(size));
2348 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, &size, NULL);
2349 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2350 ok(size.cx == 0 && size.cy == 0, "Unexpected size.\n");
2352 memset(&ratio, 0xcc, sizeof(ratio));
2353 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, NULL, &ratio);
2354 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2355 ok(ratio.cx == 0 && ratio.cy == 0, "Unexpected ratio.\n");
2357 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
2358 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2360 /* Configure mixer primary stream. */
2361 hr = MFGetService((IUnknown *)presenter, &MR_VIDEO_ACCELERATION_SERVICE, &IID_IDirect3DDeviceManager9, (void **)&dm);
2362 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2364 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)dm);
2365 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2367 IDirect3DDeviceManager9_Release(dm);
2369 video_type = create_video_type(&MFVideoFormat_RGB32);
2371 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)640 << 32 | 480);
2372 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2373 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
2374 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2376 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
2377 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2379 /* Native video size is cached on initialization. */
2380 init_test_host(&host, mixer, presenter);
2382 hr = IMFTopologyServiceLookupClient_InitServicePointers(lookup_client, &host.IMFTopologyServiceLookup_iface);
2383 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2385 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, &size, &ratio);
2386 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2387 ok(size.cx == 640 && size.cy == 480, "Unexpected size %lu x %lu.\n", size.cx, size.cy);
2388 ok((ratio.cx == 4 && ratio.cy == 3) || broken(!memcmp(&ratio, &size, sizeof(ratio))) /* < Win10 */,
2389 "Unexpected ratio %lu x %lu.\n", ratio.cx, ratio.cy);
2391 /* Update input type. */
2392 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)320 << 32 | 240);
2393 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2395 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
2396 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2398 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, &size, &ratio);
2399 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2400 ok(size.cx == 640 && size.cy == 480, "Unexpected size %lu x %lu.\n", size.cx, size.cy);
2401 ok((ratio.cx == 4 && ratio.cy == 3) || broken(!memcmp(&ratio, &size, sizeof(ratio))) /* < Win10 */,
2402 "Unexpected ratio %lu x %lu.\n", ratio.cx, ratio.cy);
2404 /* Negotiating types updates native video size. */
2405 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
2406 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2408 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, &size, &ratio);
2409 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2410 ok(size.cx == 320 && size.cy == 240, "Unexpected size %lu x %lu.\n", size.cx, size.cy);
2411 ok((ratio.cx == 4 && ratio.cy == 3) || broken(!memcmp(&ratio, &size, sizeof(ratio))) /* < Win10 */,
2412 "Unexpected ratio %lu x %lu.\n", ratio.cx, ratio.cy);
2414 IMFTopologyServiceLookupClient_Release(lookup_client);
2415 IMFMediaType_Release(video_type);
2416 IMFVideoDisplayControl_Release(display_control);
2417 IMFVideoPresenter_Release(presenter);
2418 IMFTransform_Release(mixer);
2421 static void test_presenter_ar_mode(void)
2423 IMFVideoDisplayControl *display_control;
2424 HRESULT hr;
2425 DWORD mode;
2427 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoDisplayControl, (void **)&display_control);
2428 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2430 hr = IMFVideoDisplayControl_GetAspectRatioMode(display_control, NULL);
2431 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2433 mode = 0;
2434 hr = IMFVideoDisplayControl_GetAspectRatioMode(display_control, &mode);
2435 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2436 ok(mode == (MFVideoARMode_PreservePicture | MFVideoARMode_PreservePixel), "Unexpected mode %#lx.\n", mode);
2438 hr = IMFVideoDisplayControl_SetAspectRatioMode(display_control, 0x100);
2439 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2441 hr = IMFVideoDisplayControl_SetAspectRatioMode(display_control, MFVideoARMode_Mask);
2442 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2444 mode = 0;
2445 hr = IMFVideoDisplayControl_GetAspectRatioMode(display_control, &mode);
2446 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2447 ok(mode == MFVideoARMode_Mask, "Unexpected mode %#lx.\n", mode);
2449 IMFVideoDisplayControl_Release(display_control);
2452 static void test_presenter_video_window(void)
2454 D3DDEVICE_CREATION_PARAMETERS device_params = { 0 };
2455 IMFVideoDisplayControl *display_control;
2456 IDirect3DDeviceManager9 *dm;
2457 IDirect3DDevice9 *d3d_device;
2458 HANDLE hdevice;
2459 HRESULT hr;
2460 IDirect3DSwapChain9 *swapchain;
2461 D3DPRESENT_PARAMETERS present_params = { 0 };
2462 HWND window;
2464 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoDisplayControl, (void **)&display_control);
2465 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2467 hr = MFGetService((IUnknown *)display_control, &MR_VIDEO_ACCELERATION_SERVICE,
2468 &IID_IDirect3DDeviceManager9, (void **)&dm);
2470 hr = IDirect3DDeviceManager9_OpenDeviceHandle(dm, &hdevice);
2471 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2473 hr = IDirect3DDeviceManager9_LockDevice(dm, hdevice, &d3d_device, FALSE);
2474 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2476 hr = IDirect3DDevice9_GetCreationParameters(d3d_device, &device_params);
2477 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2478 ok(device_params.hFocusWindow == GetDesktopWindow(), "Unexpected window %p.\n", device_params.hFocusWindow);
2480 hr = IDirect3DDevice9_GetSwapChain(d3d_device, 0, &swapchain);
2481 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2483 hr = IDirect3DSwapChain9_GetPresentParameters(swapchain, &present_params);
2484 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2486 ok(present_params.hDeviceWindow == GetDesktopWindow(), "Unexpected device window.\n");
2487 ok(present_params.Windowed, "Unexpected windowed mode.\n");
2488 ok(present_params.SwapEffect == D3DSWAPEFFECT_COPY, "Unexpected swap effect.\n");
2489 ok(present_params.Flags & D3DPRESENTFLAG_VIDEO, "Unexpected flags %#lx.\n", present_params.Flags);
2490 ok(present_params.PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE, "Unexpected present interval.\n");
2492 IDirect3DSwapChain9_Release(swapchain);
2493 IDirect3DDevice9_Release(d3d_device);
2495 hr = IDirect3DDeviceManager9_UnlockDevice(dm, hdevice, FALSE);
2496 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2498 /* Setting window. */
2499 hr = IMFVideoDisplayControl_GetVideoWindow(display_control, &window);
2500 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2501 ok(!window, "Unexpected window %p.\n", window);
2503 window = create_window();
2505 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, window);
2506 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2508 /* Device is not recreated or reset on window change. */
2509 hr = IDirect3DDeviceManager9_LockDevice(dm, hdevice, &d3d_device, FALSE);
2510 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2512 hr = IDirect3DDevice9_GetSwapChain(d3d_device, 0, &swapchain);
2513 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2515 hr = IDirect3DSwapChain9_GetPresentParameters(swapchain, &present_params);
2516 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2518 ok(present_params.hDeviceWindow == GetDesktopWindow(), "Unexpected device window.\n");
2519 ok(present_params.Windowed, "Unexpected windowed mode.\n");
2520 ok(present_params.SwapEffect == D3DSWAPEFFECT_COPY, "Unexpected swap effect.\n");
2521 ok(present_params.Flags & D3DPRESENTFLAG_VIDEO, "Unexpected flags %#lx.\n", present_params.Flags);
2522 ok(present_params.PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE, "Unexpected present interval.\n");
2524 IDirect3DSwapChain9_Release(swapchain);
2525 IDirect3DDevice9_Release(d3d_device);
2527 hr = IDirect3DDeviceManager9_UnlockDevice(dm, hdevice, FALSE);
2528 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2530 hr = IDirect3DDeviceManager9_CloseDeviceHandle(dm, hdevice);
2531 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2533 IDirect3DDeviceManager9_Release(dm);
2534 ok(!IMFVideoDisplayControl_Release(display_control), "Unexpected refcount.\n");
2536 DestroyWindow(window);
2539 static void test_presenter_quality_control(void)
2541 IMFQualityAdviseLimits *qa_limits;
2542 IMFVideoPresenter *presenter;
2543 MF_QUALITY_DROP_MODE mode;
2544 IMFQualityAdvise *advise;
2545 MF_QUALITY_LEVEL level;
2546 IQualProp *qual_prop;
2547 int frame_count;
2548 HRESULT hr;
2550 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
2551 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2553 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFQualityAdviseLimits, (void **)&qa_limits);
2554 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2556 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFQualityAdvise, (void **)&advise);
2557 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2559 hr = IMFQualityAdviseLimits_GetMaximumDropMode(qa_limits, NULL);
2560 todo_wine
2561 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2563 hr = IMFQualityAdviseLimits_GetMaximumDropMode(qa_limits, &mode);
2564 todo_wine
2565 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2566 if (SUCCEEDED(hr))
2567 ok(mode == MF_DROP_MODE_NONE, "Unexpected mode %d.\n", mode);
2569 hr = IMFQualityAdviseLimits_GetMinimumQualityLevel(qa_limits, NULL);
2570 todo_wine
2571 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2573 hr = IMFQualityAdviseLimits_GetMinimumQualityLevel(qa_limits, &level);
2574 todo_wine
2575 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2576 if (SUCCEEDED(hr))
2577 ok(level == MF_QUALITY_NORMAL, "Unexpected level %d.\n", level);
2579 IMFQualityAdviseLimits_Release(qa_limits);
2581 todo_wine {
2582 mode = 1;
2583 hr = IMFQualityAdvise_GetDropMode(advise, &mode);
2584 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2585 ok(mode == MF_DROP_MODE_NONE, "Unexpected mode %d.\n", mode);
2587 level = 1;
2588 hr = IMFQualityAdvise_GetQualityLevel(advise, &level);
2589 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2590 ok(level == MF_QUALITY_NORMAL, "Unexpected mode %d.\n", level);
2592 hr = IMFQualityAdvise_SetDropMode(advise, MF_DROP_MODE_1);
2593 ok(hr == MF_E_NO_MORE_DROP_MODES, "Unexpected hr %#lx.\n", hr);
2595 hr = IMFQualityAdvise_SetQualityLevel(advise, MF_QUALITY_NORMAL_MINUS_1);
2596 ok(hr == MF_E_NO_MORE_QUALITY_LEVELS, "Unexpected hr %#lx.\n", hr);
2599 IMFQualityAdvise_Release(advise);
2601 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IQualProp, (void **)&qual_prop);
2602 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2604 hr = IQualProp_get_FramesDrawn(qual_prop, NULL);
2605 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
2607 hr = IQualProp_get_FramesDrawn(qual_prop, &frame_count);
2608 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
2610 IQualProp_Release(qual_prop);
2612 IMFVideoPresenter_Release(presenter);
2615 static void get_output_aperture(IMFTransform *mixer, SIZE *frame_size, MFVideoArea *aperture)
2617 IMFMediaType *media_type;
2618 UINT64 size;
2619 HRESULT hr;
2621 memset(frame_size, 0xcc, sizeof(*frame_size));
2622 memset(aperture, 0xcc, sizeof(*aperture));
2624 hr = IMFTransform_GetOutputCurrentType(mixer, 0, &media_type);
2625 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2627 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &size);
2628 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2630 frame_size->cx = size >> 32;
2631 frame_size->cy = size;
2633 hr = IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (UINT8 *)aperture, sizeof(*aperture), NULL);
2634 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2636 IMFMediaType_Release(media_type);
2639 static void test_presenter_media_type(void)
2641 IMFTopologyServiceLookupClient *lookup_client;
2642 IMFVideoPresenter *presenter;
2643 struct test_host host;
2644 IMFMediaType *input_type;
2645 IDirect3DDeviceManager9 *manager;
2646 HRESULT hr;
2647 IMFTransform *mixer;
2648 IDirect3DDevice9 *device;
2649 unsigned int token;
2650 SIZE frame_size;
2651 HWND window;
2652 MFVideoArea aperture;
2653 IMFVideoDisplayControl *display_control;
2654 RECT dst;
2656 window = create_window();
2657 if (!(device = create_device(window)))
2659 skip("Failed to create a D3D device, skipping tests.\n");
2660 goto done;
2663 hr = DXVA2CreateDirect3DDeviceManager9(&token, &manager);
2664 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2666 hr = IDirect3DDeviceManager9_ResetDevice(manager, device, token);
2667 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2669 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
2670 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2672 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
2673 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2675 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
2676 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
2678 input_type = create_video_type(&MFVideoFormat_RGB32);
2680 hr = IMFMediaType_SetUINT64(input_type, &MF_MT_FRAME_SIZE, (UINT64)100 << 32 | 50);
2681 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2682 hr = IMFMediaType_SetUINT32(input_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
2683 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2685 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)manager);
2686 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2688 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
2689 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2691 init_test_host(&host, mixer, presenter);
2693 hr = IMFTopologyServiceLookupClient_InitServicePointers(lookup_client, &host.IMFTopologyServiceLookup_iface);
2694 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2695 IMFTopologyServiceLookupClient_Release(lookup_client);
2697 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, window);
2698 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2700 /* Set destination rectangle before mixer types are configured. */
2701 SetRect(&dst, 0, 0, 101, 51);
2702 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst);
2703 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2705 hr = IMFTransform_SetInputType(mixer, 0, input_type, 0);
2706 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2707 IMFMediaType_Release(input_type);
2709 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
2710 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2712 get_output_aperture(mixer, &frame_size, &aperture);
2713 ok(frame_size.cx == 101 && frame_size.cy == 51, "Unexpected frame size %lu x %lu.\n", frame_size.cx, frame_size.cy);
2714 ok(aperture.Area.cx == 101 && aperture.Area.cy == 51, "Unexpected size %lu x %lu.\n", aperture.Area.cx, aperture.Area.cy);
2715 ok(!aperture.OffsetX.value && !aperture.OffsetX.fract && !aperture.OffsetY.value && !aperture.OffsetY.fract,
2716 "Unexpected offset %u x %u.\n", aperture.OffsetX.value, aperture.OffsetY.value);
2718 SetRect(&dst, 1, 2, 200, 300);
2719 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &dst);
2720 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2722 get_output_aperture(mixer, &frame_size, &aperture);
2723 ok(frame_size.cx == 199 && frame_size.cy == 298, "Unexpected frame size %lu x %lu.\n", frame_size.cx, frame_size.cy);
2724 ok(aperture.Area.cx == 199 && aperture.Area.cy == 298, "Unexpected size %lu x %lu.\n", aperture.Area.cx, aperture.Area.cy);
2725 ok(!aperture.OffsetX.value && !aperture.OffsetX.fract && !aperture.OffsetY.value && !aperture.OffsetY.fract,
2726 "Unexpected offset %u x %u.\n", aperture.OffsetX.value, aperture.OffsetY.value);
2728 hr = IMFVideoDisplayControl_SetAspectRatioMode(display_control, MFVideoARMode_None);
2729 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2731 get_output_aperture(mixer, &frame_size, &aperture);
2732 ok(frame_size.cx == 199 && frame_size.cy == 298, "Unexpected frame size %lu x %lu.\n", frame_size.cx, frame_size.cy);
2733 ok(aperture.Area.cx == 199 && aperture.Area.cy == 298, "Unexpected size %lu x %lu.\n", aperture.Area.cx, aperture.Area.cy);
2734 ok(!aperture.OffsetX.value && !aperture.OffsetX.fract && !aperture.OffsetY.value && !aperture.OffsetY.fract,
2735 "Unexpected offset %u x %u.\n", aperture.OffsetX.value, aperture.OffsetY.value);
2737 IMFVideoDisplayControl_Release(display_control);
2738 IMFVideoPresenter_Release(presenter);
2739 IMFTransform_Release(mixer);
2740 IDirect3DDeviceManager9_Release(manager);
2741 IDirect3DDevice9_Release(device);
2743 done:
2744 DestroyWindow(window);
2747 static void test_presenter_shutdown(void)
2749 IMFTopologyServiceLookupClient *lookup_client;
2750 IMFVideoDisplayControl *display_control;
2751 IMFVideoMediaType *media_type;
2752 IMFVideoPresenter *presenter;
2753 IMFVideoDeviceID *deviceid;
2754 HWND window, window2;
2755 IQualProp *qual_prop;
2756 int frame_count;
2757 HRESULT hr;
2758 DWORD mode;
2759 RECT rect;
2760 SIZE size;
2761 IID iid;
2763 window = create_window();
2764 ok(!!window, "Failed to create test window.\n");
2766 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
2767 ok(hr == S_OK, "Failed to create default presenter, hr %#lx.\n", hr);
2769 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
2770 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2772 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDeviceID, (void **)&deviceid);
2773 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2775 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
2776 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2778 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IQualProp, (void **)&qual_prop);
2779 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2781 hr = IMFTopologyServiceLookupClient_ReleaseServicePointers(lookup_client);
2782 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2784 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
2785 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2787 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_BEGINSTREAMING, 0);
2788 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2790 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_ENDSTREAMING, 0);
2791 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2793 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_PROCESSINPUTNOTIFY, 0);
2794 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2796 hr = IMFVideoPresenter_GetCurrentMediaType(presenter, &media_type);
2797 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2799 hr = IMFVideoDeviceID_GetDeviceID(deviceid, &iid);
2800 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2802 hr = IMFVideoDisplayControl_GetNativeVideoSize(display_control, &size, &size);
2803 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2805 hr = IMFVideoDisplayControl_GetIdealVideoSize(display_control, &size, &size);
2806 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2808 SetRect(&rect, 0, 0, 10, 10);
2809 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &rect);
2810 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2812 hr = IMFVideoDisplayControl_GetVideoPosition(display_control, NULL, &rect);
2813 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2815 hr = IMFVideoDisplayControl_SetAspectRatioMode(display_control, MFVideoARMode_None);
2816 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2818 hr = IMFVideoDisplayControl_GetAspectRatioMode(display_control, &mode);
2819 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2821 hr = IMFVideoDisplayControl_SetVideoWindow(display_control, window);
2822 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2824 hr = IMFVideoDisplayControl_SetVideoPosition(display_control, NULL, &rect);
2825 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2827 hr = IMFVideoDisplayControl_GetVideoWindow(display_control, &window2);
2828 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2830 hr = IMFVideoDisplayControl_RepaintVideo(display_control);
2831 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
2833 hr = IQualProp_get_FramesDrawn(qual_prop, NULL);
2834 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
2836 hr = IQualProp_get_FramesDrawn(qual_prop, &frame_count);
2837 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
2839 hr = IMFTopologyServiceLookupClient_ReleaseServicePointers(lookup_client);
2840 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2842 IQualProp_Release(qual_prop);
2843 IMFVideoDeviceID_Release(deviceid);
2844 IMFVideoDisplayControl_Release(display_control);
2845 IMFTopologyServiceLookupClient_Release(lookup_client);
2847 IMFVideoPresenter_Release(presenter);
2849 DestroyWindow(window);
2852 static void test_mixer_output_rectangle(void)
2854 IMFVideoMixerControl *mixer_control;
2855 MFVideoNormalizedRect rect;
2856 IMFTransform *mixer;
2857 HRESULT hr;
2859 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
2860 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
2862 hr = IMFTransform_QueryInterface(mixer, &IID_IMFVideoMixerControl, (void **)&mixer_control);
2863 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2865 hr = IMFVideoMixerControl_GetStreamOutputRect(mixer_control, 0, NULL);
2866 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2868 set_rect(&rect, 0.0f, 0.0f, 0.0f, 0.0f);
2869 hr = IMFVideoMixerControl_GetStreamOutputRect(mixer_control, 0, &rect);
2870 ok(hr == S_OK, "Failed to get output rect, hr %#lx.\n", hr);
2871 ok(rect.left == 0.0f && rect.top == 0.0f && rect.right == 1.0f && rect.bottom == 1.0f,
2872 "Unexpected rectangle.\n");
2874 hr = IMFVideoMixerControl_GetStreamOutputRect(mixer_control, 1, &rect);
2875 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
2877 hr = IMFVideoMixerControl_GetStreamOutputRect(mixer_control, 1, NULL);
2878 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2880 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 1, &rect);
2881 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
2883 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 1, NULL);
2884 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2886 /* Wrong bounds. */
2887 set_rect(&rect, 0.0f, 0.0f, 1.1f, 1.0f);
2888 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 0, &rect);
2889 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2891 set_rect(&rect, -0.1f, 0.0f, 0.5f, 1.0f);
2892 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 0, &rect);
2893 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2895 /* Flipped. */
2896 set_rect(&rect, 1.0f, 0.0f, 0.0f, 1.0f);
2897 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 0, &rect);
2898 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2900 set_rect(&rect, 0.0f, 1.0f, 1.0f, 0.5f);
2901 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 0, &rect);
2902 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2904 hr = IMFVideoMixerControl_SetStreamOutputRect(mixer_control, 0, NULL);
2905 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2907 IMFVideoMixerControl_Release(mixer_control);
2908 IMFTransform_Release(mixer);
2911 static void test_mixer_zorder(void)
2913 IMFVideoMixerControl *mixer_control;
2914 IMFTransform *mixer;
2915 DWORD ids[2];
2916 DWORD value;
2917 HRESULT hr;
2919 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
2920 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
2922 hr = IMFTransform_QueryInterface(mixer, &IID_IMFVideoMixerControl, (void **)&mixer_control);
2923 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2925 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 0, NULL);
2926 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2928 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 1, NULL);
2929 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2931 value = 1;
2932 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 0, &value);
2933 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2934 ok(!value, "Unexpected value %lu.\n", value);
2936 value = 1;
2937 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 1, &value);
2938 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
2940 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 0, 1);
2941 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2943 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 1, 1);
2944 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2946 /* Exceeds maximum stream number. */
2947 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 0, 20);
2948 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2950 value = 1;
2951 hr = IMFTransform_AddInputStreams(mixer, 1, &value);
2952 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2954 value = 0;
2955 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 1, &value);
2956 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2957 ok(value == 1, "Unexpected zorder %lu.\n", value);
2959 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 1, 0);
2960 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
2962 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 1, 2);
2963 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2965 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 0, 0);
2966 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2968 value = 2;
2969 hr = IMFTransform_AddInputStreams(mixer, 1, &value);
2970 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2972 value = 0;
2973 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 2, &value);
2974 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2975 ok(value == 2, "Unexpected zorder %lu.\n", value);
2977 hr = IMFVideoMixerControl_SetStreamZOrder(mixer_control, 2, 1);
2978 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2980 value = 3;
2981 hr = IMFTransform_AddInputStreams(mixer, 1, &value);
2982 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2984 value = 0;
2985 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 3, &value);
2986 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2987 ok(value == 3, "Unexpected zorder %lu.\n", value);
2989 hr = IMFTransform_DeleteInputStream(mixer, 1);
2990 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2991 hr = IMFTransform_DeleteInputStream(mixer, 2);
2992 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2993 hr = IMFTransform_DeleteInputStream(mixer, 3);
2994 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2996 ids[0] = 2;
2997 ids[1] = 1;
2998 hr = IMFTransform_AddInputStreams(mixer, 2, ids);
2999 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3001 value = 0;
3002 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 1, &value);
3003 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3004 ok(value == 2, "Unexpected zorder %lu.\n", value);
3006 value = 0;
3007 hr = IMFVideoMixerControl_GetStreamZOrder(mixer_control, 2, &value);
3008 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3009 ok(value == 1, "Unexpected zorder %lu.\n", value);
3011 IMFVideoMixerControl_Release(mixer_control);
3012 IMFTransform_Release(mixer);
3015 static IDirect3DSurface9 * create_surface(IDirect3DDeviceManager9 *manager, UINT fourcc,
3016 unsigned int width, unsigned int height)
3018 IDirectXVideoAccelerationService *service;
3019 IDirect3DSurface9 *surface = NULL;
3020 IDirect3DDevice9 *device;
3021 HANDLE handle;
3022 HRESULT hr;
3024 hr = IDirect3DDeviceManager9_OpenDeviceHandle(manager, &handle);
3025 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3027 hr = IDirect3DDeviceManager9_LockDevice(manager, handle, &device, TRUE);
3028 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3030 hr = IDirect3DDeviceManager9_GetVideoService(manager, handle, &IID_IDirectXVideoProcessorService,
3031 (void **)&service);
3032 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3034 hr = IDirectXVideoAccelerationService_CreateSurface(service, width, height, 0, fourcc,
3035 D3DPOOL_DEFAULT, 0, DXVA2_VideoProcessorRenderTarget, &surface, NULL);
3036 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3038 IDirectXVideoAccelerationService_Release(service);
3040 hr = IDirect3DDevice9_ColorFill(device, surface, NULL, D3DCOLOR_ARGB(0x10, 0xff, 0x00, 0x00));
3041 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3043 IDirect3DDevice9_Release(device);
3045 hr = IDirect3DDeviceManager9_UnlockDevice(manager, handle, FALSE);
3046 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3048 hr = IDirect3DDeviceManager9_CloseDeviceHandle(manager, handle);
3049 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3051 return surface;
3054 /* Format is assumed as 32bpp */
3055 static DWORD get_surface_color(IDirect3DSurface9 *surface, unsigned int x, unsigned int y)
3057 D3DLOCKED_RECT locked_rect = { 0 };
3058 D3DSURFACE_DESC desc;
3059 DWORD *row, color;
3060 HRESULT hr;
3062 hr = IDirect3DSurface9_GetDesc(surface, &desc);
3063 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3064 ok(x < desc.Width && y < desc.Height, "Invalid coordinate.\n");
3065 if (x >= desc.Width || y >= desc.Height) return 0;
3067 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
3068 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3070 row = (DWORD *)((char *)locked_rect.pBits + y * locked_rect.Pitch);
3071 color = row[x];
3073 hr = IDirect3DSurface9_UnlockRect(surface);
3074 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3076 return color;
3079 static void test_mixer_samples(void)
3081 IDirect3DDeviceManager9 *manager;
3082 MFT_OUTPUT_DATA_BUFFER buffers[2];
3083 IMFVideoProcessor *processor;
3084 IDirect3DSurface9 *surface;
3085 IMFDesiredSample *desired;
3086 IDirect3DDevice9 *device;
3087 IMFMediaType *video_type;
3088 DWORD flags, color, status;
3089 IMFTransform *mixer;
3090 IMFSample *sample, *sample2;
3091 HWND window;
3092 UINT token;
3093 HRESULT hr;
3094 LONGLONG pts, duration;
3095 UINT32 count;
3097 window = create_window();
3098 if (!(device = create_device(window)))
3100 skip("Failed to create a D3D device, skipping tests.\n");
3101 goto done;
3104 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
3105 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
3107 hr = IMFTransform_QueryInterface(mixer, &IID_IMFVideoProcessor, (void **)&processor);
3108 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3110 hr = IMFTransform_GetInputStatus(mixer, 0, NULL);
3111 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3113 hr = IMFTransform_GetInputStatus(mixer, 1, NULL);
3114 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3116 hr = IMFTransform_GetInputStatus(mixer, 0, &status);
3117 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
3119 hr = IMFTransform_GetInputStatus(mixer, 1, &status);
3120 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
3122 hr = IMFTransform_GetOutputStatus(mixer, NULL);
3123 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3125 hr = IMFTransform_GetOutputStatus(mixer, &status);
3126 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
3128 /* Configure device and media types. */
3129 hr = DXVA2CreateDirect3DDeviceManager9(&token, &manager);
3130 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3132 hr = IDirect3DDeviceManager9_ResetDevice(manager, device, token);
3133 ok(hr == S_OK, "Failed to set a device, hr %#lx.\n", hr);
3135 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)manager);
3136 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3138 video_type = create_video_type(&MFVideoFormat_RGB32);
3140 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)640 << 32 | 480);
3141 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3142 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3143 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3145 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
3146 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3148 hr = IMFTransform_GetInputStatus(mixer, 0, &status);
3149 ok(hr == MF_E_TRANSFORM_TYPE_NOT_SET, "Unexpected hr %#lx.\n", hr);
3151 hr = IMFTransform_SetOutputType(mixer, 0, video_type, 0);
3152 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3154 status = 0;
3155 hr = IMFTransform_GetInputStatus(mixer, 0, &status);
3156 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3157 ok(status == MFT_INPUT_STATUS_ACCEPT_DATA, "Unexpected status %#lx.\n", status);
3159 hr = IMFTransform_GetInputStatus(mixer, 1, &status);
3160 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
3162 status = ~0u;
3163 hr = IMFTransform_GetOutputStatus(mixer, &status);
3164 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3165 ok(!status, "Unexpected status %#lx.\n", status);
3167 IMFMediaType_Release(video_type);
3169 memset(buffers, 0, sizeof(buffers));
3170 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3171 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3173 /* It needs a sample with a backing surface. */
3174 hr = MFCreateSample(&sample);
3175 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3177 buffers[0].pSample = sample;
3178 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3179 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3181 IMFSample_Release(sample);
3183 surface = create_surface(manager, D3DFMT_A8R8G8B8, 64, 64);
3185 hr = MFCreateVideoSampleFromSurface((IUnknown *)surface, &sample);
3186 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3188 hr = IMFSample_QueryInterface(sample, &IID_IMFDesiredSample, (void **)&desired);
3189 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3191 buffers[0].pSample = sample;
3192 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3193 ok(hr == MF_E_TRANSFORM_NEED_MORE_INPUT, "Unexpected hr %#lx.\n", hr);
3195 color = get_surface_color(surface, 0, 0);
3196 ok(color == D3DCOLOR_ARGB(0x10, 0xff, 0x00, 0x00), "Unexpected color %#lx.\n", color);
3198 /* Streaming is not started yet. Output is colored black, but only if desired timestamps were set. */
3199 IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired, 100, 0);
3201 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3202 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3204 color = get_surface_color(surface, 0, 0);
3205 ok(!color, "Unexpected color %#lx.\n", color);
3207 hr = IMFVideoProcessor_SetBackgroundColor(processor, RGB(0, 0, 255));
3208 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3210 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3211 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3213 color = get_surface_color(surface, 0, 0);
3214 ok(!color, "Unexpected color %#lx.\n", color);
3216 hr = IMFTransform_ProcessOutput(mixer, 0, 2, buffers, &status);
3217 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3219 buffers[1].pSample = sample;
3220 hr = IMFTransform_ProcessOutput(mixer, 0, 2, buffers, &status);
3221 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3223 buffers[0].dwStreamID = 1;
3224 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3225 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
3227 IMFDesiredSample_Clear(desired);
3228 IMFDesiredSample_Release(desired);
3230 hr = IMFTransform_ProcessInput(mixer, 0, NULL, 0);
3231 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3233 hr = IMFTransform_ProcessInput(mixer, 5, NULL, 0);
3234 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3236 status = 0;
3237 hr = IMFTransform_GetInputStatus(mixer, 0, &status);
3238 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3239 ok(status == MFT_INPUT_STATUS_ACCEPT_DATA, "Unexpected status %#lx.\n", status);
3241 status = ~0u;
3242 hr = IMFTransform_GetOutputStatus(mixer, &status);
3243 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3244 ok(!status, "Unexpected status %#lx.\n", status);
3246 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3247 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3249 status = ~0u;
3250 hr = IMFTransform_GetInputStatus(mixer, 0, &status);
3251 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3252 ok(!status, "Unexpected status %#lx.\n", status);
3254 hr = IMFTransform_GetOutputStatus(mixer, &status);
3255 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3256 ok(status == MFT_OUTPUT_STATUS_SAMPLE_READY, "Unexpected status %#lx.\n", status);
3258 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3259 ok(hr == MF_E_NOTACCEPTING, "Unexpected hr %#lx.\n", hr);
3261 hr = IMFTransform_ProcessInput(mixer, 5, sample, 0);
3262 ok(hr == MF_E_INVALIDSTREAMNUMBER, "Unexpected hr %#lx.\n", hr);
3264 /* ProcessOutput() sets sample time and duration. */
3265 hr = MFCreateVideoSampleFromSurface((IUnknown *)surface, &sample2);
3266 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3268 hr = IMFSample_SetUINT32(sample2, &IID_IMFSample, 1);
3269 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3271 hr = IMFSample_SetSampleFlags(sample2, 0x123);
3272 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3274 hr = IMFSample_GetSampleTime(sample2, &pts);
3275 ok(hr == MF_E_NO_SAMPLE_TIMESTAMP, "Unexpected hr %#lx.\n", hr);
3277 hr = IMFSample_GetSampleDuration(sample2, &duration);
3278 ok(hr == MF_E_NO_SAMPLE_DURATION, "Unexpected hr %#lx.\n", hr);
3280 hr = IMFSample_SetSampleTime(sample, 0);
3281 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3283 hr = IMFSample_SetSampleDuration(sample, 0);
3284 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3286 memset(buffers, 0, sizeof(buffers));
3287 buffers[0].pSample = sample2;
3288 hr = IMFTransform_ProcessOutput(mixer, 0, 1, buffers, &status);
3289 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3291 hr = IMFSample_GetSampleTime(sample2, &pts);
3292 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3293 ok(!pts, "Unexpected sample time.\n");
3295 hr = IMFSample_GetSampleDuration(sample2, &duration);
3296 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3297 ok(!duration, "Unexpected duration\n");
3299 /* Flags are not copied. */
3300 hr = IMFSample_GetSampleFlags(sample2, &flags);
3301 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3302 ok(flags == 0x123, "Unexpected flags %#lx.\n", flags);
3304 /* Attributes are not removed. */
3305 hr = IMFSample_GetCount(sample2, &count);
3306 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3307 ok(count == 1, "Unexpected attribute count %u.\n", count);
3309 hr = IMFSample_GetCount(sample, &count);
3310 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3311 ok(!count, "Unexpected attribute count %u.\n", count);
3313 IMFSample_Release(sample2);
3315 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_COMMAND_DRAIN, 0);
3316 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3318 IMFSample_Release(sample);
3320 IDirect3DSurface9_Release(surface);
3322 IMFVideoProcessor_Release(processor);
3323 IMFTransform_Release(mixer);
3325 IDirect3DDeviceManager9_Release(manager);
3326 ok(!IDirect3DDevice9_Release(device), "Unexpected refcount.\n");
3328 done:
3329 DestroyWindow(window);
3332 static void create_d3d_sample(IDirect3DDeviceManager9 *manager, const GUID *subtype, IMFSample **sample)
3334 static const BITMAPINFOHEADER expect_header =
3336 .biSize = sizeof(BITMAPINFOHEADER),
3337 .biWidth = 96, .biHeight = 96,
3338 .biPlanes = 1, .biBitCount = 32,
3339 .biCompression = BI_RGB,
3340 .biSizeImage = 96 * 96 * 4,
3342 DWORD data_size, frame_data_len;
3343 D3DLOCKED_RECT d3d_rect = {0};
3344 IDirect3DSurface9 *surface;
3345 const BYTE *frame_data;
3346 LONG stride;
3347 HRESULT hr;
3349 if (IsEqualGUID(subtype, &MFVideoFormat_NV12))
3351 load_resource(L"nv12frame.bmp", &frame_data, &frame_data_len);
3352 /* skip BMP header and RGB data from the dump */
3353 data_size = *(DWORD *)(frame_data + 2);
3354 frame_data_len = frame_data_len - data_size;
3355 frame_data = frame_data + data_size;
3356 ok(frame_data_len == 13824, "got length %lu\n", frame_data_len);
3358 else
3360 load_resource(L"rgb32frame.bmp", &frame_data, &frame_data_len);
3361 /* skip BMP header from the dump */
3362 data_size = *(DWORD *)(frame_data + 2 + 2 * sizeof(DWORD));
3363 frame_data_len -= data_size;
3364 frame_data += data_size;
3365 ok(frame_data_len == 36864, "got length %lu\n", frame_data_len);
3368 surface = create_surface(manager, subtype->Data1, expect_header.biWidth, expect_header.biHeight);
3369 ok(!!surface, "Failed to create input surface.\n");
3370 hr = IDirect3DSurface9_LockRect(surface, &d3d_rect, NULL, 0);
3371 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3372 if (IsEqualGUID(subtype, &MFVideoFormat_RGB32))
3373 memcpy(d3d_rect.pBits, frame_data, frame_data_len);
3374 else if (IsEqualGUID(subtype, &MFVideoFormat_NV12))
3376 hr = MFGetStrideForBitmapInfoHeader(subtype->Data1, expect_header.biWidth, &stride);
3377 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3378 hr = MFCopyImage(d3d_rect.pBits, d3d_rect.Pitch, frame_data, stride, expect_header.biWidth, expect_header.biHeight);
3379 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3380 frame_data += stride * expect_header.biHeight;
3381 d3d_rect.pBits = (BYTE *)d3d_rect.pBits + d3d_rect.Pitch * expect_header.biHeight;
3382 hr = MFCopyImage(d3d_rect.pBits, d3d_rect.Pitch, frame_data, stride, expect_header.biWidth, expect_header.biHeight / 2);
3383 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3385 hr = IDirect3DSurface9_UnlockRect(surface);
3386 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3387 hr = MFCreateVideoSampleFromSurface((IUnknown *)surface, sample);
3388 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3389 IDirect3DSurface9_Release(surface);
3392 #define check_presenter_output(a, b, c, d) check_presenter_output_(__LINE__, a, b, c, d, FALSE)
3393 static DWORD check_presenter_output_(int line, IMFVideoPresenter *presenter, const BITMAPINFOHEADER *expect_header,
3394 const WCHAR *resource, const RECT *rect, BOOL todo)
3396 BITMAPINFOHEADER header = {.biSize = sizeof(BITMAPINFOHEADER)};
3397 IMFVideoDisplayControl *display_control;
3398 DWORD diff, data_size;
3399 LONGLONG timestamp;
3400 BYTE *data;
3401 HRESULT hr;
3403 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFVideoDisplayControl, (void **)&display_control);
3404 ok_(__FILE__, line)(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3405 hr = IMFVideoDisplayControl_GetCurrentImage(display_control, &header, &data, &data_size, &timestamp);
3406 if (hr == MF_E_INVALIDREQUEST)
3408 Sleep(500);
3409 hr = IMFVideoDisplayControl_GetCurrentImage(display_control, &header, &data, &data_size, &timestamp);
3411 ok_(__FILE__, line)(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3412 IMFVideoDisplayControl_Release(display_control);
3414 ok_(__FILE__, line)(header.biSize == expect_header->biSize, "Unexpected biSize %#lx\n", header.biSize);
3415 todo_wine_if(todo)
3416 ok_(__FILE__, line)(header.biWidth == expect_header->biWidth, "Unexpected biWidth %#lx\n", header.biWidth);
3417 todo_wine_if(todo)
3418 ok_(__FILE__, line)(header.biHeight == expect_header->biHeight, "Unexpected biHeight %#lx\n", header.biHeight);
3419 ok_(__FILE__, line)(header.biPlanes == expect_header->biPlanes, "Unexpected biPlanes %#x\n", header.biPlanes);
3420 ok_(__FILE__, line)(header.biBitCount == expect_header->biBitCount, "Unexpected biBitCount %#x\n", header.biBitCount);
3421 ok_(__FILE__, line)(header.biCompression == expect_header->biCompression, "Unexpected biCompression %#lx\n", header.biCompression);
3422 todo_wine_if(todo)
3423 ok_(__FILE__, line)(header.biSizeImage == expect_header->biSizeImage, "Unexpected biSizeImage %#lx\n", header.biSizeImage);
3424 ok_(__FILE__, line)(header.biXPelsPerMeter == expect_header->biXPelsPerMeter, "Unexpected biXPelsPerMeter %#lx\n", header.biXPelsPerMeter);
3425 ok_(__FILE__, line)(header.biYPelsPerMeter == expect_header->biYPelsPerMeter, "Unexpected biYPelsPerMeter %#lx\n", header.biYPelsPerMeter);
3426 ok_(__FILE__, line)(header.biClrUsed == expect_header->biClrUsed, "Unexpected biClrUsed %#lx\n", header.biClrUsed);
3427 ok_(__FILE__, line)(header.biClrImportant == expect_header->biClrImportant, "Unexpected biClrImportant %#lx\n", header.biClrImportant);
3429 diff = check_rgb32_data(resource, data, header.biSizeImage, rect);
3430 CoTaskMemFree(data);
3432 return diff;
3435 static void test_presenter_orientation(const GUID *subtype)
3437 IMFTopologyServiceLookupClient *lookup_client;
3438 static const BITMAPINFOHEADER expect_header =
3440 .biSize = sizeof(BITMAPINFOHEADER),
3441 .biWidth = 96, .biHeight = 96,
3442 .biPlanes = 1, .biBitCount = 32,
3443 .biCompression = BI_RGB,
3444 .biSizeImage = 96 * 96 * 4,
3446 IDirect3DDeviceManager9 *manager;
3447 IMFVideoPresenter *presenter;
3448 IMFMediaType *video_type;
3449 struct test_host host;
3450 IMFTransform *mixer;
3451 IMFSample *sample;
3452 HWND window;
3453 HRESULT hr;
3454 DWORD diff;
3455 RECT rect;
3457 window = create_window();
3459 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
3460 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
3461 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
3462 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3464 init_test_host(&host, mixer, presenter);
3465 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
3466 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3467 hr = IMFTopologyServiceLookupClient_InitServicePointers(lookup_client, &host.IMFTopologyServiceLookup_iface);
3468 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3469 IMFTopologyServiceLookupClient_Release(lookup_client);
3471 /* Configure device and media types. */
3473 hr = MFGetService((IUnknown *)presenter, &MR_VIDEO_ACCELERATION_SERVICE, &IID_IDirect3DDeviceManager9, (void **)&manager);
3474 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3475 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)manager);
3476 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3477 IDirect3DDeviceManager9_Release(manager);
3479 video_type = create_video_type(subtype);
3480 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3481 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3482 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3483 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3485 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
3486 if (broken(IsEqualGUID(subtype, &MFVideoFormat_NV12) && hr == E_FAIL))
3488 win_skip("Skipping unsupported NV12 format\n");
3489 IMFMediaType_Release(video_type);
3490 goto skip_tests;
3492 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3493 hr = IMFTransform_SetOutputType(mixer, 0, video_type, 0);
3494 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3495 IMFMediaType_Release(video_type);
3497 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
3498 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3499 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_BEGINSTREAMING, 0);
3500 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3502 create_d3d_sample(manager, subtype, &sample);
3503 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3504 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3505 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_PROCESSINPUTNOTIFY, 0);
3506 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3507 IMFSample_Release(sample);
3509 SetRect(&rect, 0, 0, expect_header.biWidth, expect_header.biHeight);
3510 diff = check_presenter_output(presenter, &expect_header, L"rgb32frame-flip.bmp", &rect);
3511 ok(diff <= 5, "Unexpected %lu%% diff\n", diff);
3513 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_ENDSTREAMING, 0);
3514 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3516 skip_tests:
3517 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
3518 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3519 hr = IMFTopologyServiceLookupClient_ReleaseServicePointers(lookup_client);
3520 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3521 IMFTopologyServiceLookupClient_Release(lookup_client);
3523 IMFTransform_Release(mixer);
3524 IMFVideoPresenter_Release(presenter);
3526 DestroyWindow(window);
3529 static void test_mixer_video_aperture(void)
3531 IMFTopologyServiceLookupClient *lookup_client;
3532 static const BITMAPINFOHEADER expect_header_crop =
3534 .biSize = sizeof(BITMAPINFOHEADER),
3535 .biWidth = 34, .biHeight = 56,
3536 .biPlanes = 1, .biBitCount = 32,
3537 .biCompression = BI_RGB,
3538 .biSizeImage = 34 * 56 * 4,
3540 static const BITMAPINFOHEADER expect_header =
3542 .biSize = sizeof(BITMAPINFOHEADER),
3543 .biWidth = 96, .biHeight = 96,
3544 .biPlanes = 1, .biBitCount = 32,
3545 .biCompression = BI_RGB,
3546 .biSizeImage = 96 * 96 * 4,
3548 const MFVideoArea aperture = {.Area = {.cx = 34, .cy = 56}};
3549 IDirect3DDeviceManager9 *manager;
3550 IMFVideoPresenter *presenter;
3551 IMFMediaType *video_type;
3552 struct test_host host;
3553 IMFTransform *mixer;
3554 IMFSample *sample;
3555 HWND window;
3556 HRESULT hr;
3557 DWORD diff;
3558 RECT rect;
3560 window = create_window();
3562 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
3563 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
3564 hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter);
3565 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3567 init_test_host(&host, mixer, presenter);
3568 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
3569 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3570 hr = IMFTopologyServiceLookupClient_InitServicePointers(lookup_client, &host.IMFTopologyServiceLookup_iface);
3571 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3572 IMFTopologyServiceLookupClient_Release(lookup_client);
3574 /* Configure device and media types. */
3576 hr = MFGetService((IUnknown *)presenter, &MR_VIDEO_ACCELERATION_SERVICE, &IID_IDirect3DDeviceManager9, (void **)&manager);
3577 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3578 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)manager);
3579 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3580 IDirect3DDeviceManager9_Release(manager);
3583 /* MF_MT_MINIMUM_DISPLAY_APERTURE / MF_MT_PAN_SCAN_APERTURE have no effect */
3585 video_type = create_video_type(&MFVideoFormat_RGB32);
3586 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3587 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3588 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3589 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3590 hr = IMFMediaType_SetBlob(video_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture));
3591 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3592 hr = IMFMediaType_SetBlob(video_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture));
3593 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3594 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
3595 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3596 IMFMediaType_Release(video_type);
3598 video_type = create_video_type(&MFVideoFormat_RGB32);
3599 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3600 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3601 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3602 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3603 hr = IMFTransform_SetOutputType(mixer, 0, video_type, 0);
3604 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3605 IMFMediaType_Release(video_type);
3607 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
3608 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3609 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_BEGINSTREAMING, 0);
3610 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3612 create_d3d_sample(manager, &MFVideoFormat_RGB32, &sample);
3613 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3614 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3615 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_PROCESSINPUTNOTIFY, 0);
3616 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3617 IMFSample_Release(sample);
3619 SetRect(&rect, 0, 0, expect_header.biWidth, expect_header.biHeight);
3620 diff = check_presenter_output(presenter, &expect_header, L"rgb32frame-flip.bmp", &rect);
3621 ok(diff <= 5, "Unexpected %lu%% diff\n", diff);
3623 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_ENDSTREAMING, 0);
3624 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3627 /* MF_MT_PAN_SCAN_APERTURE has an effect only when enabled */
3629 video_type = create_video_type(&MFVideoFormat_RGB32);
3630 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3631 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3632 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3633 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3634 hr = IMFTransform_SetOutputType(mixer, 0, video_type, 0);
3635 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3636 IMFMediaType_Release(video_type);
3638 video_type = create_video_type(&MFVideoFormat_RGB32);
3639 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3640 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3641 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3642 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3643 hr = IMFMediaType_SetBlob(video_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture));
3644 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3645 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_PAN_SCAN_ENABLED, TRUE);
3646 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3647 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
3648 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3649 IMFMediaType_Release(video_type);
3651 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
3652 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3653 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_BEGINSTREAMING, 0);
3654 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3656 create_d3d_sample(manager, &MFVideoFormat_RGB32, &sample);
3657 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3658 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3659 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_PROCESSINPUTNOTIFY, 0);
3660 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3661 IMFSample_Release(sample);
3663 SetRect(&rect, 0, 0, expect_header_crop.biWidth, expect_header_crop.biHeight);
3664 diff = check_presenter_output_(__LINE__, presenter, &expect_header_crop, L"rgb32frame-crop.bmp", &rect, TRUE);
3665 todo_wine ok(diff <= 5, "Unexpected %lu%% diff\n", diff);
3667 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_ENDSTREAMING, 0);
3668 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3671 /* MF_MT_GEOMETRIC_APERTURE has an effect */
3673 video_type = create_video_type(&MFVideoFormat_RGB32);
3674 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3675 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3676 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3677 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3678 hr = IMFMediaType_SetBlob(video_type, &MF_MT_GEOMETRIC_APERTURE, (BYTE *)&aperture, sizeof(aperture));
3679 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3680 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
3681 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3682 IMFMediaType_Release(video_type);
3684 video_type = create_video_type(&MFVideoFormat_RGB32);
3685 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)expect_header.biWidth << 32 | expect_header.biHeight);
3686 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3687 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3688 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3689 hr = IMFTransform_SetOutputType(mixer, 0, video_type, 0);
3690 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3691 IMFMediaType_Release(video_type);
3693 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_INVALIDATEMEDIATYPE, 0);
3694 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3695 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_BEGINSTREAMING, 0);
3696 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3698 create_d3d_sample(manager, &MFVideoFormat_RGB32, &sample);
3699 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3700 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3701 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_PROCESSINPUTNOTIFY, 0);
3702 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3703 IMFSample_Release(sample);
3705 SetRect(&rect, 0, 0, expect_header_crop.biWidth, expect_header_crop.biHeight);
3706 diff = check_presenter_output(presenter, &expect_header_crop, L"rgb32frame-crop.bmp", &rect);
3707 ok(diff <= 5, "Unexpected %lu%% diff\n", diff);
3709 hr = IMFVideoPresenter_ProcessMessage(presenter, MFVP_MESSAGE_ENDSTREAMING, 0);
3710 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3713 hr = IMFVideoPresenter_QueryInterface(presenter, &IID_IMFTopologyServiceLookupClient, (void **)&lookup_client);
3714 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3715 hr = IMFTopologyServiceLookupClient_ReleaseServicePointers(lookup_client);
3716 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3717 IMFTopologyServiceLookupClient_Release(lookup_client);
3719 IMFTransform_Release(mixer);
3720 IMFVideoPresenter_Release(presenter);
3722 DestroyWindow(window);
3725 static void test_MFIsFormatYUV(void)
3727 static const DWORD formats[] =
3729 D3DFMT_UYVY,
3730 D3DFMT_YUY2,
3731 MAKEFOURCC('A','Y','U','V'),
3732 MAKEFOURCC('I','M','C','1'),
3733 MAKEFOURCC('I','M','C','2'),
3734 MAKEFOURCC('Y','V','1','2'),
3735 MAKEFOURCC('N','V','1','1'),
3736 MAKEFOURCC('N','V','1','2'),
3737 MAKEFOURCC('Y','2','1','0'),
3738 MAKEFOURCC('Y','2','1','6'),
3740 static const DWORD unsupported_formats[] =
3742 D3DFMT_A8R8G8B8,
3743 MAKEFOURCC('I','Y','U','V'),
3744 MAKEFOURCC('I','4','2','0'),
3745 MAKEFOURCC('Y','V','Y','U'),
3746 MAKEFOURCC('Y','V','U','9'),
3747 MAKEFOURCC('Y','4','1','0'),
3748 MAKEFOURCC('Y','4','1','6'),
3750 unsigned int i;
3751 BOOL ret;
3753 for (i = 0; i < ARRAY_SIZE(formats); ++i)
3755 ret = MFIsFormatYUV(formats[i]);
3756 ok(ret, "Unexpected ret %d, format %s.\n", ret, debugstr_an((char *)&formats[i], 4));
3759 for (i = 0; i < ARRAY_SIZE(unsupported_formats); ++i)
3761 ret = MFIsFormatYUV(unsupported_formats[i]);
3762 ok(!ret, "Unexpected ret %d, format %s.\n", ret, debugstr_an((char *)&unsupported_formats[i], 4));
3766 static void test_mixer_render(void)
3768 IMFMediaType *video_type, *output_type;
3769 IMFVideoMixerControl *mixer_control;
3770 IDirect3DDeviceManager9 *manager;
3771 IMFVideoProcessor *processor;
3772 IDirect3DSurface9 *surface;
3773 IDirect3DDevice9 *device;
3774 IMFTransform *mixer;
3775 IMFSample *sample;
3776 DWORD status;
3777 HWND window;
3778 UINT token;
3779 HRESULT hr;
3781 window = create_window();
3782 if (!(device = create_device(window)))
3784 skip("Failed to create a D3D device, skipping tests.\n");
3785 goto done;
3788 hr = MFCreateVideoMixer(NULL, &IID_IDirect3DDevice9, &IID_IMFTransform, (void **)&mixer);
3789 ok(hr == S_OK, "Failed to create a mixer, hr %#lx.\n", hr);
3791 hr = IMFTransform_QueryInterface(mixer, &IID_IMFVideoProcessor, (void **)&processor);
3792 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3793 IMFVideoProcessor_Release(processor);
3795 hr = IMFTransform_QueryInterface(mixer, &IID_IMFVideoMixerControl, (void **)&mixer_control);
3796 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3797 IMFVideoMixerControl_Release(mixer_control);
3799 /* Configure device and media types. */
3800 hr = DXVA2CreateDirect3DDeviceManager9(&token, &manager);
3801 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3803 hr = IDirect3DDeviceManager9_ResetDevice(manager, device, token);
3804 ok(hr == S_OK, "Failed to set a device, hr %#lx.\n", hr);
3806 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_SET_D3D_MANAGER, (ULONG_PTR)manager);
3807 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3809 video_type = create_video_type(&MFVideoFormat_RGB32);
3811 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64)64 << 32 | 64);
3812 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3813 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
3814 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3816 hr = IMFTransform_SetInputType(mixer, 0, video_type, 0);
3817 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3819 hr = IMFTransform_GetOutputAvailableType(mixer, 0, 0, &output_type);
3820 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3822 hr = IMFTransform_SetOutputType(mixer, 0, output_type, 0);
3823 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3825 IMFMediaType_Release(output_type);
3826 IMFMediaType_Release(video_type);
3828 surface = create_surface(manager, D3DFMT_A8R8G8B8, 64, 64);
3829 ok(!!surface, "Failed to create input surface.\n");
3831 hr = MFCreateVideoSampleFromSurface((IUnknown *)surface, &sample);
3832 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3834 EXPECT_REF(sample, 1);
3835 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3836 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3837 EXPECT_REF(sample, 2);
3839 hr = IMFTransform_GetOutputStatus(mixer, &status);
3840 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3841 ok(status == MFT_OUTPUT_STATUS_SAMPLE_READY, "Unexpected status %#lx.\n", status);
3843 /* FLUSH/END_STREAMING releases input */
3844 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_NOTIFY_END_STREAMING, 0);
3845 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3846 EXPECT_REF(sample, 1);
3848 hr = IMFTransform_GetOutputStatus(mixer, &status);
3849 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3850 ok(!status, "Unexpected status %#lx.\n", status);
3852 hr = IMFTransform_ProcessInput(mixer, 0, sample, 0);
3853 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3854 EXPECT_REF(sample, 2);
3856 hr = IMFTransform_GetOutputStatus(mixer, &status);
3857 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3858 ok(status == MFT_OUTPUT_STATUS_SAMPLE_READY, "Unexpected status %#lx.\n", status);
3860 hr = IMFTransform_ProcessMessage(mixer, MFT_MESSAGE_COMMAND_FLUSH, 0);
3861 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3862 EXPECT_REF(sample, 1);
3864 hr = IMFTransform_GetOutputStatus(mixer, &status);
3865 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3866 ok(!status, "Unexpected status %#lx.\n", status);
3868 IMFSample_Release(sample);
3869 IDirect3DSurface9_Release(surface);
3870 IMFTransform_Release(mixer);
3872 IDirect3DDeviceManager9_Release(manager);
3873 ok(!IDirect3DDevice9_Release(device), "Unexpected refcount.\n");
3875 done:
3876 DestroyWindow(window);
3879 START_TEST(evr)
3881 IMFVideoPresenter *presenter;
3882 IDirect3D9 *d3d9;
3883 HRESULT hr;
3885 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
3886 if (!d3d9)
3888 skip("Failed to initialize D3D9. Skipping EVR tests.\n");
3889 return;
3891 IDirect3D9_Release(d3d9);
3893 CoInitialize(NULL);
3895 if (FAILED(hr = MFCreateVideoPresenter(NULL, &IID_IDirect3DDevice9, &IID_IMFVideoPresenter, (void **)&presenter)))
3897 win_skip("Failed to create default presenter, hr %#lx. Skipping tests.\n", hr);
3898 CoUninitialize();
3899 return;
3901 IMFVideoPresenter_Release(presenter);
3903 test_aggregation();
3904 test_interfaces();
3905 test_enum_pins();
3906 test_find_pin();
3907 test_pin_info();
3908 test_unconnected_eos();
3909 test_misc_flags();
3910 test_display_control();
3911 test_service_lookup();
3912 test_query_accept();
3914 test_default_mixer();
3915 test_default_mixer_type_negotiation();
3916 test_surface_sample();
3917 test_default_presenter();
3918 test_MFCreateVideoMixerAndPresenter();
3919 test_MFCreateVideoSampleAllocator();
3920 test_presenter_video_position();
3921 test_presenter_native_video_size();
3922 test_presenter_ar_mode();
3923 test_presenter_video_window();
3924 test_presenter_quality_control();
3925 test_presenter_media_type();
3926 test_presenter_orientation(&MFVideoFormat_NV12);
3927 test_presenter_orientation(&MFVideoFormat_RGB32);
3928 test_mixer_video_aperture();
3929 test_presenter_shutdown();
3930 test_mixer_output_rectangle();
3931 test_mixer_zorder();
3932 test_mixer_samples();
3933 test_mixer_render();
3934 test_MFIsFormatYUV();
3936 CoUninitialize();