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
24 #include "wine/test.h"
32 static const WCHAR sink_id
[] = L
"EVR Input0";
34 static void set_rect(MFVideoNormalizedRect
*rect
, float left
, float top
, float right
, float bottom
)
39 rect
->bottom
= bottom
;
42 static HWND
create_window(void)
44 RECT r
= {0, 0, 640, 480};
46 AdjustWindowRect(&r
, WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, FALSE
);
48 return CreateWindowA("static", "evr_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
49 0, 0, r
.right
- r
.left
, r
.bottom
- r
.top
, NULL
, NULL
, NULL
, NULL
);
52 static IDirect3DDevice9
*create_device(HWND focus_window
)
54 D3DPRESENT_PARAMETERS present_parameters
= {0};
55 IDirect3DDevice9
*device
= NULL
;
58 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
59 ok(!!d3d9
, "Failed to create a D3D object.\n");
61 present_parameters
.BackBufferWidth
= 640;
62 present_parameters
.BackBufferHeight
= 480;
63 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
64 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
65 present_parameters
.hDeviceWindow
= focus_window
;
66 present_parameters
.Windowed
= TRUE
;
67 present_parameters
.EnableAutoDepthStencil
= TRUE
;
68 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
70 IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
71 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
73 IDirect3D9_Release(d3d9
);
78 static IBaseFilter
*create_evr(void)
80 IBaseFilter
*filter
= NULL
;
81 HRESULT hr
= CoCreateInstance(&CLSID_EnhancedVideoRenderer
, NULL
, CLSCTX_INPROC_SERVER
,
82 &IID_IBaseFilter
, (void **)&filter
);
83 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
87 static IFilterGraph2
*create_graph(void)
92 hr
= CoCreateInstance(&CLSID_FilterGraph
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IFilterGraph2
, (void **)&ret
);
93 ok(hr
== S_OK
, "Failed to create FilterGraph: %#lx\n", hr
);
97 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
98 static void _expect_ref(IUnknown
*obj
, ULONG ref
, int line
)
101 IUnknown_AddRef(obj
);
102 rc
= IUnknown_Release(obj
);
103 ok_(__FILE__
,line
)(rc
== ref
, "Unexpected refcount %ld, expected %ld.\n", rc
, ref
);
106 static ULONG
get_refcount(void *iface
)
108 IUnknown
*unknown
= iface
;
109 IUnknown_AddRef(unknown
);
110 return IUnknown_Release(unknown
);
113 static const GUID test_iid
= {0x33333333};
114 static LONG outer_ref
= 1;
116 static HRESULT WINAPI
outer_QueryInterface(IUnknown
*iface
, REFIID iid
, void **out
)
118 if (IsEqualGUID(iid
, &IID_IUnknown
)
119 || IsEqualGUID(iid
, &IID_IBaseFilter
)
120 || IsEqualGUID(iid
, &test_iid
))
122 *out
= (IUnknown
*)0xdeadbeef;
125 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid
));
126 return E_NOINTERFACE
;
129 static ULONG WINAPI
outer_AddRef(IUnknown
*iface
)
131 return InterlockedIncrement(&outer_ref
);
134 static ULONG WINAPI
outer_Release(IUnknown
*iface
)
136 return InterlockedDecrement(&outer_ref
);
139 static const IUnknownVtbl outer_vtbl
=
141 outer_QueryInterface
,
146 static IUnknown test_outer
= {&outer_vtbl
};
148 static void test_aggregation(void)
150 IBaseFilter
*filter
, *filter2
;
151 IMFVideoPresenter
*presenter
;
152 IUnknown
*unk
, *unk2
;
157 filter
= (IBaseFilter
*)0xdeadbeef;
158 hr
= CoCreateInstance(&CLSID_EnhancedVideoRenderer
, &test_outer
, CLSCTX_INPROC_SERVER
,
159 &IID_IBaseFilter
, (void **)&filter
);
160 ok(hr
== E_NOINTERFACE
, "Got hr %#lx.\n", hr
);
161 ok(!filter
, "Got interface %p.\n", filter
);
163 hr
= CoCreateInstance(&CLSID_EnhancedVideoRenderer
, &test_outer
, CLSCTX_INPROC_SERVER
,
164 &IID_IUnknown
, (void **)&unk
);
165 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
166 ok(outer_ref
== 1, "Got unexpected refcount %ld.\n", outer_ref
);
167 ok(unk
!= &test_outer
, "Returned IUnknown should not be outer IUnknown.\n");
168 ref
= get_refcount(unk
);
169 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
171 ref
= IUnknown_AddRef(unk
);
172 ok(ref
== 2, "Got unexpected refcount %ld.\n", ref
);
173 ok(outer_ref
== 1, "Got unexpected refcount %ld.\n", outer_ref
);
175 ref
= IUnknown_Release(unk
);
176 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
177 ok(outer_ref
== 1, "Got unexpected refcount %ld.\n", outer_ref
);
179 hr
= IUnknown_QueryInterface(unk
, &IID_IUnknown
, (void **)&unk2
);
180 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
181 ok(unk2
== unk
, "Got unexpected IUnknown %p.\n", unk2
);
182 IUnknown_Release(unk2
);
184 hr
= IUnknown_QueryInterface(unk
, &IID_IBaseFilter
, (void **)&filter
);
185 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
187 hr
= IBaseFilter_QueryInterface(filter
, &IID_IUnknown
, (void **)&unk2
);
188 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
189 ok(unk2
== (IUnknown
*)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2
);
191 hr
= IBaseFilter_QueryInterface(filter
, &IID_IBaseFilter
, (void **)&filter2
);
192 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
193 ok(filter2
== (IBaseFilter
*)0xdeadbeef, "Got unexpected IBaseFilter %p.\n", filter2
);
195 hr
= IUnknown_QueryInterface(unk
, &test_iid
, (void **)&unk2
);
196 ok(hr
== E_NOINTERFACE
, "Got hr %#lx.\n", hr
);
197 ok(!unk2
, "Got unexpected IUnknown %p.\n", unk2
);
199 hr
= IBaseFilter_QueryInterface(filter
, &test_iid
, (void **)&unk2
);
200 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
201 ok(unk2
== (IUnknown
*)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2
);
203 IBaseFilter_Release(filter
);
204 ref
= IUnknown_Release(unk
);
205 ok(!ref
, "Got unexpected refcount %ld.\n", ref
);
206 ok(outer_ref
== 1, "Got unexpected refcount %ld.\n", outer_ref
);
208 /* Default presenter. */
209 presenter
= (void *)0xdeadbeef;
210 hr
= CoCreateInstance(&CLSID_MFVideoPresenter9
, &test_outer
, CLSCTX_INPROC_SERVER
, &IID_IMFVideoPresenter
,
211 (void **)&presenter
);
212 ok(hr
== E_NOINTERFACE
, "Unexpected hr %#lx.\n", hr
);
213 ok(!presenter
, "Got interface %p.\n", presenter
);
215 hr
= CoCreateInstance(&CLSID_MFVideoPresenter9
, &test_outer
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&unk
);
216 ok(hr
== S_OK
|| broken(hr
== E_FAIL
) /* WinXP */, "Unexpected hr %#lx.\n", hr
);
219 ok(outer_ref
== 1, "Got unexpected refcount %ld.\n", outer_ref
);
220 ok(unk
!= &test_outer
, "Returned IUnknown should not be outer IUnknown.\n");
221 ref
= get_refcount(unk
);
222 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
224 IUnknown_Release(unk
);
228 presenter
= (void *)0xdeadbeef;
229 hr
= CoCreateInstance(&CLSID_MFVideoMixer9
, &test_outer
, CLSCTX_INPROC_SERVER
, &IID_IMFTransform
,
231 ok(hr
== E_NOINTERFACE
, "Unexpected hr %#lx.\n", hr
);
232 ok(!mixer
, "Got interface %p.\n", mixer
);
234 hr
= CoCreateInstance(&CLSID_MFVideoMixer9
, &test_outer
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void **)&unk
);
235 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
236 ok(outer_ref
== 1, "Got unexpected refcount %ld.\n", outer_ref
);
237 ok(unk
!= &test_outer
, "Returned IUnknown should not be outer IUnknown.\n");
238 ref
= get_refcount(unk
);
239 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
241 IUnknown_Release(unk
);
244 #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
245 static void check_interface_(unsigned int line
, void *iface_ptr
, REFIID iid
, BOOL supported
)
247 IUnknown
*iface
= iface_ptr
;
248 HRESULT hr
, expected_hr
;
251 expected_hr
= supported
? S_OK
: E_NOINTERFACE
;
253 hr
= IUnknown_QueryInterface(iface
, iid
, (void **)&unk
);
254 ok_(__FILE__
, line
)(hr
== expected_hr
, "Got hr %#lx, expected %#lx.\n", hr
, expected_hr
);
256 IUnknown_Release(unk
);
259 #define check_service_interface(a, b, c, d) check_service_interface_(__LINE__, a, b, c, d)
260 static void check_service_interface_(unsigned int line
, void *iface_ptr
, REFGUID service
, REFIID iid
, BOOL supported
)
262 IUnknown
*iface
= iface_ptr
;
263 HRESULT hr
, expected_hr
;
266 expected_hr
= supported
? S_OK
: E_NOINTERFACE
;
268 hr
= MFGetService(iface
, service
, iid
, (void **)&unk
);
269 ok_(__FILE__
, line
)(hr
== expected_hr
, "Got hr %#lx, expected %#lx.\n", hr
, expected_hr
);
271 IUnknown_Release(unk
);
274 static void test_interfaces(void)
276 IBaseFilter
*filter
= create_evr(), *filter2
;
281 check_interface(filter
, &IID_IAMFilterMiscFlags
, TRUE
);
282 check_interface(filter
, &IID_IBaseFilter
, TRUE
);
283 check_interface(filter
, &IID_IEVRFilterConfig
, TRUE
);
284 check_interface(filter
, &IID_IMFGetService
, TRUE
);
285 check_interface(filter
, &IID_IMFVideoRenderer
, TRUE
);
286 check_interface(filter
, &IID_IMediaFilter
, TRUE
);
287 check_interface(filter
, &IID_IMediaPosition
, TRUE
);
288 check_interface(filter
, &IID_IMediaSeeking
, TRUE
);
289 check_interface(filter
, &IID_IMediaEventSink
, TRUE
);
290 check_interface(filter
, &IID_IPersist
, TRUE
);
291 check_interface(filter
, &IID_IUnknown
, TRUE
);
293 check_interface(filter
, &IID_IBasicAudio
, FALSE
);
294 check_interface(filter
, &IID_IBasicVideo
, FALSE
);
295 check_interface(filter
, &IID_IDirectXVideoMemoryConfiguration
, FALSE
);
296 check_interface(filter
, &IID_IMemInputPin
, FALSE
);
297 check_interface(filter
, &IID_IPersistPropertyBag
, FALSE
);
298 check_interface(filter
, &IID_IPin
, FALSE
);
299 check_interface(filter
, &IID_IReferenceClock
, FALSE
);
300 check_interface(filter
, &IID_IVideoWindow
, FALSE
);
302 /* The scope of IMediaEventSink */
303 hr
= IBaseFilter_QueryInterface(filter
, &IID_IMediaEventSink
, (void **)&unk
);
304 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
305 hr
= IUnknown_QueryInterface(unk
, &IID_IBaseFilter
, (void **)&filter2
);
306 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
307 ok(filter
== filter2
, "Unexpected pointer.\n");
308 IBaseFilter_Release(filter2
);
309 IUnknown_Release(unk
);
311 ref
= IBaseFilter_Release(filter
);
312 ok(!ref
, "Got unexpected refcount %ld.\n", ref
);
315 static void test_enum_pins(void)
317 IBaseFilter
*filter
= create_evr();
318 IEnumPins
*enum1
, *enum2
;
323 ref
= get_refcount(filter
);
324 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
326 hr
= IBaseFilter_EnumPins(filter
, NULL
);
327 ok(hr
== E_POINTER
, "Got hr %#lx.\n", hr
);
329 hr
= IBaseFilter_EnumPins(filter
, &enum1
);
330 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
331 ref
= get_refcount(filter
);
332 ok(ref
== 2, "Got unexpected refcount %ld.\n", ref
);
333 ref
= get_refcount(enum1
);
334 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
336 hr
= IEnumPins_Next(enum1
, 1, NULL
, NULL
);
337 ok(hr
== E_POINTER
, "Got hr %#lx.\n", hr
);
339 hr
= IEnumPins_Next(enum1
, 1, pins
, NULL
);
340 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
341 ref
= get_refcount(filter
);
342 ok(ref
== 3, "Got unexpected refcount %ld.\n", ref
);
343 ref
= get_refcount(pins
[0]);
344 ok(ref
== 3, "Got unexpected refcount %ld.\n", ref
);
345 ref
= get_refcount(enum1
);
346 ok(ref
== 1, "Got unexpected refcount %ld.\n", ref
);
347 IPin_Release(pins
[0]);
348 ref
= get_refcount(filter
);
349 ok(ref
== 2, "Got unexpected refcount %ld.\n", ref
);
351 hr
= IEnumPins_Next(enum1
, 1, pins
, NULL
);
352 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
354 hr
= IEnumPins_Reset(enum1
);
355 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
357 hr
= IEnumPins_Next(enum1
, 1, pins
, &count
);
358 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
359 ok(count
== 1, "Got count %lu.\n", count
);
360 IPin_Release(pins
[0]);
362 hr
= IEnumPins_Next(enum1
, 1, pins
, &count
);
363 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
364 ok(!count
, "Got count %lu.\n", count
);
366 hr
= IEnumPins_Reset(enum1
);
367 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
369 hr
= IEnumPins_Next(enum1
, 2, pins
, NULL
);
370 ok(hr
== E_INVALIDARG
, "Got hr %#lx.\n", hr
);
372 hr
= IEnumPins_Next(enum1
, 2, pins
, &count
);
373 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
374 ok(count
== 1, "Got count %lu.\n", count
);
375 IPin_Release(pins
[0]);
377 hr
= IEnumPins_Reset(enum1
);
378 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
380 hr
= IEnumPins_Clone(enum1
, &enum2
);
381 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
383 hr
= IEnumPins_Skip(enum1
, 2);
384 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
386 hr
= IEnumPins_Skip(enum1
, 1);
387 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
389 hr
= IEnumPins_Skip(enum1
, 1);
390 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
392 hr
= IEnumPins_Next(enum1
, 1, pins
, NULL
);
393 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
395 hr
= IEnumPins_Next(enum2
, 1, pins
, NULL
);
396 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
397 IPin_Release(pins
[0]);
399 IEnumPins_Release(enum2
);
400 IEnumPins_Release(enum1
);
401 ref
= IBaseFilter_Release(filter
);
402 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
405 static void test_find_pin(void)
407 IBaseFilter
*filter
= create_evr();
408 IEnumPins
*enum_pins
;
413 hr
= IBaseFilter_EnumPins(filter
, &enum_pins
);
414 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
416 hr
= IBaseFilter_FindPin(filter
, sink_id
, &pin
);
417 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
418 hr
= IEnumPins_Next(enum_pins
, 1, &pin2
, NULL
);
419 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
420 ok(pin2
== pin
, "Expected pin %p, got %p.\n", pin
, pin2
);
424 IEnumPins_Release(enum_pins
);
425 ref
= IBaseFilter_Release(filter
);
426 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
429 static void test_pin_info(void)
431 IBaseFilter
*filter
= create_evr();
439 hr
= IBaseFilter_FindPin(filter
, sink_id
, &pin
);
440 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
441 ref
= get_refcount(filter
);
442 ok(ref
== 2, "Got unexpected refcount %ld.\n", ref
);
443 ref
= get_refcount(pin
);
444 ok(ref
== 2, "Got unexpected refcount %ld.\n", ref
);
446 hr
= IPin_QueryPinInfo(pin
, &info
);
447 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
448 ok(info
.pFilter
== filter
, "Expected filter %p, got %p.\n", filter
, info
.pFilter
);
449 ok(info
.dir
== PINDIR_INPUT
, "Got direction %d.\n", info
.dir
);
450 ok(!lstrcmpW(info
.achName
, sink_id
), "Got name %s.\n", wine_dbgstr_w(info
.achName
));
451 ref
= get_refcount(filter
);
452 ok(ref
== 3, "Got unexpected refcount %ld.\n", ref
);
453 ref
= get_refcount(pin
);
454 ok(ref
== 3, "Got unexpected refcount %ld.\n", ref
);
455 IBaseFilter_Release(info
.pFilter
);
457 hr
= IPin_QueryDirection(pin
, &dir
);
458 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
459 ok(dir
== PINDIR_INPUT
, "Got direction %d.\n", dir
);
461 hr
= IPin_QueryId(pin
, &id
);
462 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
463 ok(!lstrcmpW(id
, sink_id
), "Got id %s.\n", wine_dbgstr_w(id
));
466 hr
= IPin_QueryInternalConnections(pin
, NULL
, NULL
);
467 ok(hr
== E_NOTIMPL
, "Got hr %#lx.\n", hr
);
470 ref
= IBaseFilter_Release(filter
);
471 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
474 static unsigned int check_event_code(IMediaEvent
*eventsrc
, DWORD timeout
, LONG expected_code
, LONG_PTR expected1
, LONG_PTR expected2
)
476 LONG_PTR param1
, param2
;
477 unsigned int ret
= 0;
481 while ((hr
= IMediaEvent_GetEvent(eventsrc
, &code
, ¶m1
, ¶m2
, timeout
)) == S_OK
)
483 if (code
== expected_code
)
485 ok(param1
== expected1
, "Got param1 %#Ix.\n", param1
);
486 ok(param2
== expected2
, "Got param2 %#Ix.\n", param2
);
489 IMediaEvent_FreeEventParams(eventsrc
, code
, param1
, param2
);
492 ok(hr
== E_ABORT
, "Got hr %#lx.\n", hr
);
497 static unsigned int check_ec_complete(IMediaEvent
*eventsrc
, DWORD timeout
)
499 return check_event_code(eventsrc
, timeout
, EC_COMPLETE
, S_OK
, 0);
502 static void test_unconnected_eos(void)
504 IBaseFilter
*filter
= create_evr();
505 IFilterGraph2
*graph
= create_graph();
506 IMediaControl
*control
;
507 IMediaEvent
*eventsrc
;
512 hr
= IFilterGraph2_AddFilter(graph
, filter
, L
"renderer");
513 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
515 hr
= IFilterGraph2_QueryInterface(graph
, &IID_IMediaControl
, (void **)&control
);
516 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
518 hr
= IFilterGraph2_QueryInterface(graph
, &IID_IMediaEvent
, (void **)&eventsrc
);
519 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
521 ret
= check_ec_complete(eventsrc
, 0);
522 ok(!ret
, "Got %u EC_COMPLETE events.\n", ret
);
524 hr
= IMediaControl_Pause(control
);
525 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
527 ret
= check_ec_complete(eventsrc
, 0);
528 ok(!ret
, "Got %u EC_COMPLETE events.\n", ret
);
530 hr
= IMediaControl_Run(control
);
531 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
533 ret
= check_ec_complete(eventsrc
, 0);
534 ok(ret
== 1, "Got %u EC_COMPLETE events.\n", ret
);
536 hr
= IMediaControl_Pause(control
);
537 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
539 ret
= check_ec_complete(eventsrc
, 0);
540 ok(!ret
, "Got %u EC_COMPLETE events.\n", ret
);
542 hr
= IMediaControl_Run(control
);
543 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
545 ret
= check_ec_complete(eventsrc
, 0);
546 ok(ret
== 1, "Got %u EC_COMPLETE events.\n", ret
);
548 hr
= IMediaControl_Stop(control
);
549 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
551 ret
= check_ec_complete(eventsrc
, 0);
552 ok(!ret
, "Got %u EC_COMPLETE events.\n", ret
);
554 hr
= IMediaControl_Run(control
);
555 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
557 ret
= check_ec_complete(eventsrc
, 0);
558 ok(ret
== 1, "Got %u EC_COMPLETE events.\n", ret
);
560 IMediaControl_Release(control
);
561 IMediaEvent_Release(eventsrc
);
562 ref
= IFilterGraph2_Release(graph
);
563 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
564 ref
= IBaseFilter_Release(filter
);
565 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
568 static void test_misc_flags(void)
570 IBaseFilter
*filter
= create_evr();
571 IAMFilterMiscFlags
*misc_flags
;
575 hr
= IBaseFilter_QueryInterface(filter
, &IID_IAMFilterMiscFlags
, (void **)&misc_flags
);
576 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
578 flags
= IAMFilterMiscFlags_GetMiscFlags(misc_flags
);
579 ok(flags
== AM_FILTER_MISC_FLAGS_IS_RENDERER
, "Unexpected flags %#lx.\n", flags
);
580 IAMFilterMiscFlags_Release(misc_flags
);
582 ref
= IBaseFilter_Release(filter
);
583 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
586 static void test_display_control(void)
588 IBaseFilter
*filter
= create_evr();
589 IMFVideoDisplayControl
*display_control
;
593 hr
= MFGetService((IUnknown
*)filter
, &MR_VIDEO_RENDER_SERVICE
,
594 &IID_IMFVideoDisplayControl
, (void **)&display_control
);
595 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
597 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, 0);
598 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
600 IMFVideoDisplayControl_Release(display_control
);
602 ref
= IBaseFilter_Release(filter
);
603 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
606 static void test_service_lookup(void)
608 IBaseFilter
*filter
= create_evr();
609 IMFTopologyServiceLookup
*service_lookup
;
615 hr
= IBaseFilter_QueryInterface(filter
, &IID_IMFTopologyServiceLookup
, (void **)&service_lookup
);
618 win_skip("IMFTopologyServiceLookup is not exposed.\n");
619 IBaseFilter_Release(filter
);
622 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
624 hr
= IMFTopologyServiceLookup_QueryInterface(service_lookup
, &IID_IBaseFilter
, (void **)&unk
);
625 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
626 ok(unk
== (IUnknown
*)filter
, "Unexpected pointer.\n");
627 IUnknown_Release(unk
);
630 hr
= IMFTopologyServiceLookup_LookupService(service_lookup
, MF_SERVICE_LOOKUP_GLOBAL
, 0,
631 &MR_VIDEO_RENDER_SERVICE
, &IID_IMediaEventSink
, (void **)&unk
, &count
);
632 ok(hr
== MF_E_NOTACCEPTING
, "Unexpected hr %#lx.\n", hr
);
634 IMFTopologyServiceLookup_Release(service_lookup
);
636 ref
= IBaseFilter_Release(filter
);
637 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
640 static void test_query_accept(void)
642 IBaseFilter
*filter
= create_evr();
643 AM_MEDIA_TYPE req_mt
= {{0}};
644 VIDEOINFOHEADER vih
=
647 {sizeof(BITMAPINFOHEADER
), 32, 24, 1, 0, 0xdeadbeef}
654 static const GUID
*subtype_tests
[] =
660 static const GUID
*unsupported_subtype_tests
[] =
665 IBaseFilter_FindPin(filter
, L
"EVR Input0", &pin
);
667 req_mt
.majortype
= MEDIATYPE_Video
;
668 req_mt
.formattype
= FORMAT_VideoInfo
;
669 req_mt
.cbFormat
= sizeof(VIDEOINFOHEADER
);
670 req_mt
.pbFormat
= (BYTE
*)&vih
;
672 for (i
= 0; i
< ARRAY_SIZE(subtype_tests
); ++i
)
674 memcpy(&req_mt
.subtype
, subtype_tests
[i
], sizeof(GUID
));
675 hr
= IPin_QueryAccept(pin
, &req_mt
);
676 ok(hr
== S_OK
, "Got hr %#lx.\n", hr
);
679 for (i
= 0; i
< ARRAY_SIZE(unsupported_subtype_tests
); ++i
)
681 memcpy(&req_mt
.subtype
, unsupported_subtype_tests
[i
], sizeof(GUID
));
682 hr
= IPin_QueryAccept(pin
, &req_mt
);
683 ok(hr
== S_FALSE
, "Got hr %#lx.\n", hr
);
688 ref
= IBaseFilter_Release(filter
);
689 ok(!ref
, "Got outstanding refcount %ld.\n", ref
);
692 static IMFMediaType
* create_video_type(const GUID
*subtype
)
694 IMFMediaType
*video_type
;
697 hr
= MFCreateMediaType(&video_type
);
698 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
700 hr
= IMFMediaType_SetGUID(video_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
701 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
703 hr
= IMFMediaType_SetGUID(video_type
, &MF_MT_SUBTYPE
, subtype
);
704 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
709 static void test_default_mixer(void)
711 DWORD input_min
, input_max
, output_min
, output_max
;
712 IMFAttributes
*attributes
, *attributes2
;
713 IMFVideoMixerControl2
*mixer_control2
;
714 MFT_OUTPUT_STREAM_INFO output_info
;
715 MFT_INPUT_STREAM_INFO input_info
;
716 DWORD input_count
, output_count
;
717 IMFVideoProcessor
*processor
;
718 IMFVideoDeviceID
*deviceid
;
719 MFVideoNormalizedRect rect
;
720 DWORD input_id
, output_id
;
721 IMFTransform
*transform
;
722 DXVA2_ValueRange range
;
723 DXVA2_Fixed32 dxva_value
;
734 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&transform
);
735 ok(hr
== S_OK
, "Failed to create default mixer, hr %#lx.\n", hr
);
737 check_interface(transform
, &IID_IMFQualityAdvise
, TRUE
);
738 check_interface(transform
, &IID_IMFClockStateSink
, TRUE
);
739 check_interface(transform
, &IID_IMFTopologyServiceLookupClient
, TRUE
);
740 check_interface(transform
, &IID_IMFGetService
, TRUE
);
741 check_interface(transform
, &IID_IMFAttributes
, TRUE
);
742 check_interface(transform
, &IID_IMFVideoMixerBitmap
, TRUE
);
743 check_interface(transform
, &IID_IMFVideoPositionMapper
, TRUE
);
744 check_interface(transform
, &IID_IMFVideoProcessor
, TRUE
);
745 check_interface(transform
, &IID_IMFVideoMixerControl
, TRUE
);
746 check_interface(transform
, &IID_IMFVideoDeviceID
, TRUE
);
747 check_service_interface(transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFVideoMixerBitmap
, TRUE
);
748 check_service_interface(transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFVideoProcessor
, TRUE
);
749 check_service_interface(transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFVideoMixerControl
, TRUE
);
750 check_service_interface(transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFVideoPositionMapper
, TRUE
);
751 check_service_interface(transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFTransform
, FALSE
);
753 hr
= MFGetService((IUnknown
*)transform
, &MR_VIDEO_RENDER_SERVICE
, &IID_IUnknown
, (void **)&unk
);
754 ok(hr
== MF_E_UNSUPPORTED_SERVICE
, "Unexpected hr %#lx.\n", hr
);
756 if (SUCCEEDED(MFGetService((IUnknown
*)transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFVideoMixerControl2
, (void **)&mixer_control2
)))
758 hr
= IMFVideoMixerControl2_GetMixingPrefs(mixer_control2
, NULL
);
759 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
761 hr
= IMFVideoMixerControl2_GetMixingPrefs(mixer_control2
, &flags
);
762 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
763 ok(!flags
, "Unexpected flags %#lx.\n", flags
);
765 IMFVideoMixerControl2_Release(mixer_control2
);
768 hr
= MFGetService((IUnknown
*)transform
, &MR_VIDEO_MIXER_SERVICE
, &IID_IMFVideoProcessor
, (void **)&processor
);
769 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
771 hr
= IMFVideoProcessor_GetBackgroundColor(processor
, NULL
);
772 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
775 hr
= IMFVideoProcessor_GetBackgroundColor(processor
, &color
);
776 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
777 ok(!color
, "Unexpected color %#lx.\n", color
);
779 hr
= IMFVideoProcessor_SetBackgroundColor(processor
, 0x00121212);
780 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
782 hr
= IMFVideoProcessor_GetBackgroundColor(processor
, &color
);
783 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
784 ok(color
== 0x121212, "Unexpected color %#lx.\n", color
);
786 hr
= IMFVideoProcessor_GetFilteringRange(processor
, DXVA2_DetailFilterChromaLevel
, &range
);
788 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
790 hr
= IMFVideoProcessor_GetFilteringValue(processor
, DXVA2_DetailFilterChromaLevel
, &dxva_value
);
792 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
794 hr
= IMFVideoProcessor_GetAvailableVideoProcessorModes(processor
, &count
, &guids
);
795 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
797 IMFVideoProcessor_Release(processor
);
799 hr
= IMFTransform_SetOutputBounds(transform
, 100, 10);
800 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
802 hr
= IMFTransform_QueryInterface(transform
, &IID_IMFVideoDeviceID
, (void **)&deviceid
);
803 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
805 hr
= IMFTransform_GetAttributes(transform
, NULL
);
806 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
808 hr
= IMFTransform_GetAttributes(transform
, &attributes
);
809 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
811 hr
= IMFTransform_GetAttributes(transform
, &attributes2
);
812 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
813 ok(attributes
== attributes2
, "Unexpected attributes instance.\n");
814 IMFAttributes_Release(attributes2
);
816 hr
= IMFTransform_QueryInterface(transform
, &IID_IMFAttributes
, (void **)&attributes2
);
817 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
818 ok(attributes
!= attributes2
, "Unexpected attributes instance.\n");
820 hr
= IMFAttributes_QueryInterface(attributes2
, &IID_IMFTransform
, (void **)&unk
);
821 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
822 IUnknown_Release(unk
);
824 hr
= IMFAttributes_GetCount(attributes2
, &count
);
825 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
826 ok(count
== 1, "Unexpected attribute count %u.\n", count
);
829 hr
= IMFAttributes_GetUINT32(attributes2
, &MF_SA_D3D_AWARE
, &value
);
830 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
831 ok(value
== 1, "Unexpected value %d.\n", value
);
833 IMFAttributes_Release(attributes2
);
835 hr
= IMFAttributes_GetCount(attributes
, &count
);
836 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
837 ok(count
== 1, "Unexpected attribute count %u.\n", count
);
839 memset(&rect
, 0, sizeof(rect
));
840 hr
= IMFAttributes_GetBlob(attributes
, &VIDEO_ZOOM_RECT
, (UINT8
*)&rect
, sizeof(rect
), NULL
);
841 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
842 ok(rect
.left
== 0.0f
&& rect
.top
== 0.0f
&& rect
.right
== 1.0f
&& rect
.bottom
== 1.0f
,
843 "Unexpected zoom rect (%f, %f) - (%f, %f).\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
845 IMFAttributes_Release(attributes
);
847 hr
= IMFVideoDeviceID_GetDeviceID(deviceid
, NULL
);
848 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
850 hr
= IMFVideoDeviceID_GetDeviceID(deviceid
, &iid
);
851 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
852 ok(IsEqualIID(&iid
, &IID_IDirect3DDevice9
), "Unexpected id %s.\n", wine_dbgstr_guid(&iid
));
854 IMFVideoDeviceID_Release(deviceid
);
856 /* Stream configuration. */
857 input_count
= output_count
= 0;
858 hr
= IMFTransform_GetStreamCount(transform
, &input_count
, &output_count
);
859 ok(hr
== S_OK
, "Failed to get stream count, hr %#lx.\n", hr
);
860 ok(input_count
== 1 && output_count
== 1, "Unexpected stream count %lu/%lu.\n", input_count
, output_count
);
862 hr
= IMFTransform_GetStreamLimits(transform
, &input_min
, &input_max
, &output_min
, &output_max
);
863 ok(hr
== S_OK
, "Failed to get stream limits, hr %#lx.\n", hr
);
864 ok(input_min
== 1 && input_max
== 16 && output_min
== 1 && output_max
== 1, "Unexpected stream limits %lu/%lu, %lu/%lu.\n",
865 input_min
, input_max
, output_min
, output_max
);
867 hr
= IMFTransform_GetInputStreamInfo(transform
, 1, &input_info
);
868 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
870 hr
= IMFTransform_GetOutputStreamInfo(transform
, 1, &output_info
);
871 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
873 memset(&input_info
, 0xcc, sizeof(input_info
));
874 hr
= IMFTransform_GetInputStreamInfo(transform
, 0, &input_info
);
875 ok(hr
== S_OK
, "Failed to get input info, hr %#lx.\n", hr
);
877 memset(&output_info
, 0xcc, sizeof(output_info
));
878 hr
= IMFTransform_GetOutputStreamInfo(transform
, 0, &output_info
);
879 ok(hr
== S_OK
, "Failed to get input info, hr %#lx.\n", hr
);
880 ok(!(output_info
.dwFlags
& (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES
| MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES
)),
881 "Unexpected output flags %#lx.\n", output_info
.dwFlags
);
883 hr
= IMFTransform_GetStreamIDs(transform
, 1, &input_id
, 1, &output_id
);
884 ok(hr
== S_OK
, "Failed to get input info, hr %#lx.\n", hr
);
885 ok(input_id
== 0 && output_id
== 0, "Unexpected stream ids.\n");
887 hr
= IMFTransform_GetInputStreamAttributes(transform
, 1, &attributes
);
888 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
890 hr
= IMFTransform_GetOutputStreamAttributes(transform
, 1, &attributes
);
891 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
893 hr
= IMFTransform_GetOutputStreamAttributes(transform
, 0, &attributes
);
894 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
896 hr
= IMFTransform_AddInputStreams(transform
, 16, NULL
);
897 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
899 hr
= IMFTransform_AddInputStreams(transform
, 16, ids
);
900 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
902 memset(ids
, 0, sizeof(ids
));
903 hr
= IMFTransform_AddInputStreams(transform
, 15, ids
);
904 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
906 for (i
= 0; i
< ARRAY_SIZE(ids
); ++i
)
909 hr
= IMFTransform_AddInputStreams(transform
, 15, ids
);
910 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
912 input_count
= output_count
= 0;
913 hr
= IMFTransform_GetStreamCount(transform
, &input_count
, &output_count
);
914 ok(hr
== S_OK
, "Failed to get stream count, hr %#lx.\n", hr
);
915 ok(input_count
== 16 && output_count
== 1, "Unexpected stream count %lu/%lu.\n", input_count
, output_count
);
917 memset(&input_info
, 0, sizeof(input_info
));
918 hr
= IMFTransform_GetInputStreamInfo(transform
, 1, &input_info
);
919 ok(hr
== S_OK
, "Failed to get input info, hr %#lx.\n", hr
);
920 ok((input_info
.dwFlags
& (MFT_INPUT_STREAM_REMOVABLE
| MFT_INPUT_STREAM_OPTIONAL
)) ==
921 (MFT_INPUT_STREAM_REMOVABLE
| MFT_INPUT_STREAM_OPTIONAL
), "Unexpected flags %#lx.\n", input_info
.dwFlags
);
924 hr
= IMFTransform_GetInputStreamAttributes(transform
, 0, &attributes
);
925 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
926 hr
= IMFAttributes_GetCount(attributes
, &count
);
927 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
928 ok(count
== 1, "Unexpected count %u.\n", count
);
929 hr
= IMFAttributes_GetUINT32(attributes
, &MF_SA_REQUIRED_SAMPLE_COUNT
, &count
);
930 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
931 ok(count
== 1, "Unexpected count %u.\n", count
);
932 ok(!!attributes
, "Unexpected attributes.\n");
935 hr
= IMFTransform_GetInputStreamAttributes(transform
, 0, &attributes2
);
936 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
937 ok(attributes
== attributes2
, "Unexpected instance.\n");
939 IMFAttributes_Release(attributes2
);
940 IMFAttributes_Release(attributes
);
943 hr
= IMFTransform_GetInputStreamAttributes(transform
, 1, &attributes
);
944 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
945 ok(!!attributes
, "Unexpected attributes.\n");
946 IMFAttributes_Release(attributes
);
948 hr
= IMFTransform_DeleteInputStream(transform
, 0);
949 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
951 hr
= IMFTransform_DeleteInputStream(transform
, 1);
952 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
954 input_count
= output_count
= 0;
955 hr
= IMFTransform_GetStreamCount(transform
, &input_count
, &output_count
);
956 ok(hr
== S_OK
, "Failed to get stream count, hr %#lx.\n", hr
);
957 ok(input_count
== 15 && output_count
== 1, "Unexpected stream count %lu/%lu.\n", input_count
, output_count
);
959 IMFTransform_Release(transform
);
961 hr
= MFCreateVideoMixer(NULL
, &IID_IMFTransform
, &IID_IMFTransform
, (void **)&transform
);
962 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
964 hr
= CoCreateInstance(&CLSID_MFVideoMixer9
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMFTransform
, (void **)&transform
);
965 ok(hr
== S_OK
, "Failed to create default mixer, hr %#lx.\n", hr
);
966 IMFTransform_Release(transform
);
969 static void test_surface_sample(void)
971 IDirect3DSurface9
*backbuffer
= NULL
, *surface
;
972 DWORD flags
, buffer_count
, length
;
973 IMFDesiredSample
*desired_sample
;
974 IMFMediaBuffer
*buffer
, *buffer2
;
975 LONGLONG duration
, time1
, time2
;
976 IDirect3DSwapChain9
*swapchain
;
977 IDirect3DDevice9
*device
;
985 window
= create_window();
986 if (!(device
= create_device(window
)))
988 skip("Failed to create a D3D device, skipping tests.\n");
992 hr
= IDirect3DDevice9_GetSwapChain(device
, 0, &swapchain
);
993 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
995 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
996 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
997 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
999 IDirect3DSwapChain9_Release(swapchain
);
1001 hr
= MFCreateVideoSampleFromSurface(NULL
, &sample
);
1002 ok(hr
== S_OK
, "Failed to create surface sample, hr %#lx.\n", hr
);
1003 IMFSample_Release(sample
);
1005 hr
= MFCreateVideoSampleFromSurface((IUnknown
*)backbuffer
, &sample
);
1006 ok(hr
== S_OK
, "Failed to create surface sample, hr %#lx.\n", hr
);
1008 hr
= IMFSample_QueryInterface(sample
, &IID_IMFTrackedSample
, (void **)&unk
);
1009 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1010 IUnknown_Release(unk
);
1012 hr
= IMFSample_QueryInterface(sample
, &IID_IMFDesiredSample
, (void **)&desired_sample
);
1013 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1015 hr
= IMFSample_GetCount(sample
, &count
);
1016 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1017 ok(!count
, "Unexpected attribute count %u.\n", count
);
1019 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, NULL
, NULL
);
1020 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
1022 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, NULL
, &time2
);
1023 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
1025 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, &time1
, NULL
);
1026 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
1028 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, &time1
, &time2
);
1029 ok(hr
== MF_E_NOT_AVAILABLE
, "Unexpected hr %#lx.\n", hr
);
1031 IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired_sample
, 123, 456);
1034 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, &time1
, &time2
);
1035 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1036 ok(time1
== 123 && time2
== 456, "Unexpected time values.\n");
1038 IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired_sample
, 0, 0);
1041 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, &time1
, &time2
);
1042 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1043 ok(time1
== 0 && time2
== 0, "Unexpected time values.\n");
1045 IMFDesiredSample_Clear(desired_sample
);
1047 hr
= IMFDesiredSample_GetDesiredSampleTimeAndDuration(desired_sample
, &time1
, &time2
);
1048 ok(hr
== MF_E_NOT_AVAILABLE
, "Unexpected hr %#lx.\n", hr
);
1050 hr
= IMFSample_GetCount(sample
, &count
);
1051 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1052 ok(!count
, "Unexpected attribute count %u.\n", count
);
1054 /* Attributes are cleared. */
1055 hr
= IMFSample_SetUnknown(sample
, &MFSampleExtension_Token
, NULL
);
1056 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1058 hr
= IMFSample_GetCount(sample
, &count
);
1059 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1060 ok(count
== 1, "Unexpected attribute count %u.\n", count
);
1062 hr
= IMFSample_SetSampleTime(sample
, 0);
1063 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1065 hr
= IMFSample_GetSampleTime(sample
, &time1
);
1066 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1068 hr
= IMFSample_SetSampleDuration(sample
, 0);
1069 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1071 hr
= IMFSample_GetSampleDuration(sample
, &duration
);
1072 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1074 hr
= IMFSample_SetSampleFlags(sample
, 0x1);
1075 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1077 IMFDesiredSample_Clear(desired_sample
);
1079 hr
= IMFSample_GetCount(sample
, &count
);
1080 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1081 ok(!count
, "Unexpected attribute count %u.\n", count
);
1083 hr
= IMFSample_GetSampleTime(sample
, &time1
);
1084 ok(hr
== MF_E_NO_SAMPLE_TIMESTAMP
, "Unexpected hr %#lx.\n", hr
);
1086 hr
= IMFSample_GetSampleDuration(sample
, &duration
);
1087 ok(hr
== MF_E_NO_SAMPLE_DURATION
, "Unexpected hr %#lx.\n", hr
);
1089 hr
= IMFSample_GetSampleFlags(sample
, &flags
);
1090 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1091 ok(!flags
, "Unexpected flags %#lx.\n", flags
);
1093 IMFDesiredSample_Release(desired_sample
);
1095 hr
= IMFSample_GetCount(sample
, &count
);
1096 ok(hr
== S_OK
, "Failed to get attribute count, hr %#lx.\n", hr
);
1097 ok(!count
, "Unexpected attribute count.\n");
1100 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
1101 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
1102 ok(buffer_count
== 1, "Unexpected attribute count.\n");
1104 hr
= IMFSample_GetTotalLength(sample
, &length
);
1105 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
1106 ok(!length
, "Unexpected length %lu.\n", length
);
1108 hr
= IMFSample_GetSampleDuration(sample
, &duration
);
1109 ok(hr
== MF_E_NO_SAMPLE_DURATION
, "Unexpected hr %#lx.\n", hr
);
1111 hr
= IMFSample_GetSampleTime(sample
, &duration
);
1112 ok(hr
== MF_E_NO_SAMPLE_TIMESTAMP
, "Unexpected hr %#lx.\n", hr
);
1114 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
1115 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1117 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
1118 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1120 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
1121 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
1122 ok(!length
, "Unexpected length %lu.\n", length
);
1124 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 16);
1125 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
1127 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
1128 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
1129 ok(length
== 16, "Unexpected length %lu.\n", length
);
1131 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
1132 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1134 hr
= IMFMediaBuffer_Unlock(buffer
);
1135 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1137 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&unk
);
1138 ok(hr
== E_NOINTERFACE
, "Unexpected hr %#lx.\n", hr
);
1140 hr
= IMFSample_AddBuffer(sample
, buffer
);
1141 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1143 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
1144 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
1145 ok(buffer_count
== 2, "Unexpected buffer count.\n");
1147 hr
= IMFSample_ConvertToContiguousBuffer(sample
, &buffer2
);
1148 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1150 hr
= IMFSample_CopyToBuffer(sample
, buffer
);
1151 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1153 hr
= IMFSample_RemoveAllBuffers(sample
);
1154 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1156 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
1157 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
1158 ok(!buffer_count
, "Unexpected buffer count.\n");
1160 hr
= MFGetService((IUnknown
*)buffer
, &MR_BUFFER_SERVICE
, &IID_IDirect3DSurface9
, (void **)&surface
);
1161 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1162 ok(surface
== backbuffer
, "Unexpected instance.\n");
1163 IDirect3DSurface9_Release(surface
);
1165 hr
= MFGetService((IUnknown
*)buffer
, &MR_BUFFER_SERVICE
, &IID_IUnknown
, (void **)&surface
);
1166 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1167 ok(surface
== backbuffer
, "Unexpected instance.\n");
1168 IDirect3DSurface9_Release(surface
);
1170 IMFMediaBuffer_Release(buffer
);
1172 hr
= IMFSample_GetSampleFlags(sample
, &flags
);
1173 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1175 hr
= IMFSample_SetSampleFlags(sample
, 0x123);
1176 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1179 hr
= IMFSample_GetSampleFlags(sample
, &flags
);
1180 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1181 ok(flags
== 0x123, "Unexpected flags %#lx.\n", flags
);
1183 IMFSample_Release(sample
);
1185 IDirect3DSurface9_Release(backbuffer
);
1186 ok(!IDirect3DDevice9_Release(device
), "Unexpected refcount.\n");
1189 DestroyWindow(window
);
1192 static void test_default_mixer_type_negotiation(void)
1194 IMFMediaType
*media_type
, *media_type2
;
1195 IDirect3DDeviceManager9
*manager
;
1196 DXVA2_VideoProcessorCaps caps
;
1197 IMFVideoProcessor
*processor
;
1198 GUID subtype
, guid
, *guids
;
1199 IDirect3DDevice9
*device
;
1200 IMFMediaType
*video_type
;
1201 IMFTransform
*transform
;
1202 MFVideoArea aperture
;
1209 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&transform
);
1210 ok(hr
== S_OK
, "Failed to create default mixer, hr %#lx.\n", hr
);
1212 hr
= IMFTransform_QueryInterface(transform
, &IID_IMFVideoProcessor
, (void **)&processor
);
1213 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1215 hr
= IMFTransform_GetInputAvailableType(transform
, 0, 0, &media_type
);
1216 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1218 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type
);
1219 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1221 hr
= IMFTransform_GetOutputAvailableType(transform
, 0, 0, &media_type
);
1222 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1224 hr
= MFCreateMediaType(&media_type
);
1225 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
1227 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
1228 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1230 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
1231 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1233 hr
= IMFTransform_SetInputType(transform
, 0, media_type
, 0);
1234 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
1236 hr
= IMFTransform_SetInputType(transform
, 0, media_type
, MFT_SET_TYPE_TEST_ONLY
);
1237 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
1239 hr
= IMFVideoProcessor_GetAvailableVideoProcessorModes(processor
, &count
, &guids
);
1240 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1242 /* Now try with device manager. */
1244 window
= create_window();
1245 if (!(device
= create_device(window
)))
1247 skip("Failed to create a D3D device, skipping tests.\n");
1251 hr
= IMFTransform_SetInputType(transform
, 0, NULL
, 0);
1252 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1253 hr
= IMFTransform_SetInputType(transform
, 0, NULL
, MFT_SET_TYPE_TEST_ONLY
);
1254 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1256 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &manager
);
1257 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1259 hr
= IMFTransform_ProcessMessage(transform
, MFT_MESSAGE_SET_D3D_MANAGER
, (ULONG_PTR
)manager
);
1260 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1262 /* Now manager is not initialized. */
1263 hr
= IMFTransform_SetInputType(transform
, 0, media_type
, 0);
1264 ok(hr
== DXVA2_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
1266 hr
= IMFTransform_SetInputType(transform
, 0, media_type
, MFT_SET_TYPE_TEST_ONLY
);
1267 ok(hr
== DXVA2_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
1269 hr
= IDirect3DDeviceManager9_ResetDevice(manager
, device
, token
);
1270 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1272 /* And now type description is incomplete. */
1273 hr
= IMFTransform_SetInputType(transform
, 0, media_type
, 0);
1274 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
1275 IMFMediaType_Release(media_type
);
1277 video_type
= create_video_type(&MFVideoFormat_RGB32
);
1279 /* Partially initialized type. */
1280 hr
= IMFTransform_SetInputType(transform
, 0, video_type
, 0);
1281 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
1283 /* Only required data - frame size and uncompressed marker. */
1284 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
)640 << 32 | 480);
1285 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1286 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
1287 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1288 memset(&aperture
, 0, sizeof(aperture
));
1289 aperture
.Area
.cx
= 100; aperture
.Area
.cy
= 200;
1290 hr
= IMFMediaType_SetBlob(video_type
, &MF_MT_GEOMETRIC_APERTURE
, (UINT8
*)&aperture
, sizeof(aperture
));
1291 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1292 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_FIXED_SIZE_SAMPLES
, 2);
1293 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1295 hr
= IMFTransform_SetInputType(transform
, 0, video_type
, MFT_SET_TYPE_TEST_ONLY
);
1296 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1298 hr
= IMFTransform_GetOutputAvailableType(transform
, 0, 0, &media_type
);
1299 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1301 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type
);
1302 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1304 hr
= IMFTransform_SetInputType(transform
, 0, video_type
, 0);
1305 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1307 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type
);
1308 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1309 ok(media_type
== video_type
, "Unexpected media type instance.\n");
1311 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type2
);
1312 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1313 ok(media_type
== media_type2
, "Unexpected media type instance.\n");
1314 IMFMediaType_Release(media_type
);
1315 IMFMediaType_Release(media_type2
);
1317 /* Modified after type was set. */
1318 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_PIXEL_ASPECT_RATIO
, (UINT64
)56 << 32 | 55);
1319 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1321 /* Check attributes on available output types. */
1323 while (SUCCEEDED(IMFTransform_GetOutputAvailableType(transform
, 0, index
++, &media_type
)))
1325 UINT64 frame_size
, ratio
;
1326 MFVideoArea aperture
;
1327 GUID subtype
, major
;
1330 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &major
);
1331 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1332 ok(IsEqualGUID(&major
, &MFMediaType_Video
), "Unexpected major type.\n");
1333 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &subtype
);
1334 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1335 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &frame_size
);
1336 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1337 ok(frame_size
== ((UINT64
)100 << 32 | 200), "Unexpected frame size %s.\n", wine_dbgstr_longlong(frame_size
));
1338 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value
);
1339 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1340 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value
);
1341 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1342 ok(value
== MFVideoInterlace_Progressive
, "Unexpected interlace mode.\n");
1343 /* Ratio from input type */
1344 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &ratio
);
1345 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1346 ok(ratio
== ((UINT64
)1 << 32 | 1), "Unexpected PAR %s.\n", wine_dbgstr_longlong(ratio
));
1347 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_GEOMETRIC_APERTURE
, (UINT8
*)&aperture
, sizeof(aperture
), NULL
);
1348 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1349 ok(aperture
.Area
.cx
== 100 && aperture
.Area
.cy
== 200, "Unexpected aperture area.\n");
1350 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (UINT8
*)&aperture
, sizeof(aperture
), NULL
);
1351 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1352 ok(aperture
.Area
.cx
== 100 && aperture
.Area
.cy
== 200, "Unexpected aperture area.\n");
1353 hr
= IMFMediaType_GetUINT32(video_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value
);
1354 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1355 ok(value
== 2, "Unexpected value %u.\n", value
);
1357 IMFMediaType_Release(media_type
);
1359 ok(index
> 1, "Unexpected number of available types.\n");
1361 hr
= IMFMediaType_DeleteItem(video_type
, &MF_MT_FIXED_SIZE_SAMPLES
);
1362 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1364 hr
= IMFTransform_SetInputType(transform
, 0, video_type
, 0);
1365 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1368 while (SUCCEEDED(IMFTransform_GetOutputAvailableType(transform
, 0, index
++, &media_type
)))
1373 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &ratio
);
1374 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1375 ok(ratio
== ((UINT64
)56 << 32 | 55), "Unexpected PAR %s.\n", wine_dbgstr_longlong(ratio
));
1377 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value
);
1378 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1379 ok(value
== 1, "Unexpected value %u.\n", value
);
1381 IMFMediaType_Release(media_type
);
1383 ok(index
> 1, "Unexpected number of available types.\n");
1385 /* Cloned type is returned. */
1386 hr
= IMFTransform_GetOutputAvailableType(transform
, 0, 0, &media_type
);
1387 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1388 hr
= IMFTransform_GetOutputAvailableType(transform
, 0, 0, &media_type2
);
1389 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1390 ok(media_type
!= media_type2
, "Unexpected media type instance.\n");
1391 IMFMediaType_Release(media_type
);
1392 IMFMediaType_Release(media_type2
);
1394 /* Minimal valid attribute set for output type. */
1395 hr
= IMFTransform_GetOutputAvailableType(transform
, 0, 0, &media_type
);
1396 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1398 hr
= MFCreateMediaType(&media_type2
);
1399 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1401 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &subtype
);
1402 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1404 hr
= IMFMediaType_SetGUID(media_type2
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
1405 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1406 hr
= IMFMediaType_SetGUID(media_type2
, &MF_MT_SUBTYPE
, &subtype
);
1407 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1409 hr
= IMFTransform_SetOutputType(transform
, 1, NULL
, MFT_SET_TYPE_TEST_ONLY
);
1410 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
1412 hr
= IMFTransform_SetOutputType(transform
, 0, NULL
, MFT_SET_TYPE_TEST_ONLY
);
1413 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1415 hr
= IMFTransform_SetOutputType(transform
, 0, media_type2
, MFT_SET_TYPE_TEST_ONLY
);
1416 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
1418 hr
= IMFMediaType_SetUINT32(media_type2
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
1419 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1421 hr
= IMFTransform_SetOutputType(transform
, 0, media_type2
, MFT_SET_TYPE_TEST_ONLY
);
1422 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1424 /* Candidate type have frame size set, mismatching size is accepted. */
1425 hr
= IMFMediaType_SetUINT64(media_type2
, &MF_MT_FRAME_SIZE
, (UINT64
)64 << 32 | 64);
1426 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1428 hr
= IMFTransform_SetOutputType(transform
, 0, media_type2
, MFT_SET_TYPE_TEST_ONLY
);
1429 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1431 IMFMediaType_Release(media_type2
);
1432 IMFMediaType_Release(media_type
);
1434 hr
= IMFVideoProcessor_GetVideoProcessorMode(processor
, &guid
);
1436 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1438 hr
= IMFVideoProcessor_GetVideoProcessorCaps(processor
, (GUID
*)&DXVA2_VideoProcSoftwareDevice
, &caps
);
1439 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1441 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type
);
1442 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1443 ok(media_type
== video_type
, "Unexpected pointer.\n");
1444 hr
= IMFMediaType_QueryInterface(media_type
, &IID_IMFVideoMediaType
, (void **)&unk
);
1445 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1446 IUnknown_Release(unk
);
1447 IMFMediaType_Release(media_type
);
1449 hr
= IMFVideoProcessor_GetAvailableVideoProcessorModes(processor
, &count
, &guids
);
1450 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1452 hr
= IMFTransform_GetOutputAvailableType(transform
, 0, 0, &media_type
);
1453 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1455 hr
= IMFTransform_SetOutputType(transform
, 1, media_type
, 0);
1456 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
1458 hr
= IMFTransform_SetOutputType(transform
, 0, media_type
, 0);
1459 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1461 hr
= IMFVideoProcessor_GetVideoProcessorMode(processor
, &guid
);
1463 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
1465 hr
= IMFVideoProcessor_GetAvailableVideoProcessorModes(processor
, &count
, &guids
);
1466 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1467 ok(count
> 0 && !!guids
, "Unexpected modes data.\n");
1468 CoTaskMemFree(guids
);
1470 hr
= IMFVideoProcessor_GetVideoProcessorCaps(processor
, (GUID
*)&DXVA2_VideoProcSoftwareDevice
, &caps
);
1471 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1473 hr
= IMFTransform_GetOutputCurrentType(transform
, 0, &media_type2
);
1474 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1475 ok(media_type
== media_type2
, "Unexpected media type instance.\n");
1477 IMFMediaType_Release(media_type
);
1479 /* Clear input types */
1480 hr
= IMFTransform_SetInputType(transform
, 0, NULL
, MFT_SET_TYPE_TEST_ONLY
);
1481 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1483 hr
= IMFTransform_SetInputType(transform
, 0, NULL
, 0);
1484 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1485 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type
);
1486 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1487 hr
= IMFTransform_GetOutputCurrentType(transform
, 0, &media_type
);
1488 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1491 hr
= IMFTransform_SetOutputType(transform
, 0, media_type2
, 0);
1492 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
1493 hr
= IMFTransform_GetOutputCurrentType(transform
, 0, &media_type
);
1494 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
1496 hr
= IMFTransform_SetInputType(transform
, 0, video_type
, 0);
1497 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1498 hr
= IMFTransform_GetInputCurrentType(transform
, 0, &media_type
);
1499 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1500 ok(media_type
== video_type
, "Unexpected media type instance.\n");
1501 IMFMediaType_Release(media_type
);
1503 hr
= IMFTransform_SetOutputType(transform
, 0, media_type2
, 0);
1504 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1505 hr
= IMFTransform_GetOutputCurrentType(transform
, 0, &media_type
);
1506 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1507 ok(media_type2
== media_type
, "Unexpected media type instance.\n");
1509 IMFMediaType_Release(media_type2
);
1510 IMFMediaType_Release(media_type
);
1512 /* Resetting type twice */
1513 hr
= IMFTransform_SetInputType(transform
, 0, NULL
, 0);
1514 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1515 hr
= IMFTransform_SetInputType(transform
, 0, NULL
, 0);
1516 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1518 IMFVideoProcessor_Release(processor
);
1520 IMFMediaType_Release(video_type
);
1522 IDirect3DDeviceManager9_Release(manager
);
1524 IDirect3DDevice9_Release(device
);
1527 IMFTransform_Release(transform
);
1528 DestroyWindow(window
);
1531 static void test_default_presenter(void)
1533 IMFVideoDisplayControl
*display_control
;
1534 IMFVideoPresenter
*presenter
;
1535 IMFRateSupport
*rate_support
;
1536 IDirect3DDeviceManager9
*dm
;
1537 IMFVideoDeviceID
*deviceid
;
1538 IUnknown
*unk
, *unk2
;
1545 hr
= MFCreateVideoPresenter(NULL
, &IID_IMFVideoPresenter
, &IID_IMFVideoPresenter
, (void **)&presenter
);
1546 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1548 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
1549 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
1551 check_interface(presenter
, &IID_IQualProp
, TRUE
);
1552 check_interface(presenter
, &IID_IMFVideoPositionMapper
, TRUE
);
1553 check_interface(presenter
, &IID_IMFTopologyServiceLookupClient
, TRUE
);
1554 check_interface(presenter
, &IID_IMFVideoDisplayControl
, TRUE
);
1555 check_interface(presenter
, &IID_IMFRateSupport
, TRUE
);
1556 check_interface(presenter
, &IID_IMFGetService
, TRUE
);
1557 check_interface(presenter
, &IID_IMFClockStateSink
, TRUE
);
1558 check_interface(presenter
, &IID_IMFVideoPresenter
, TRUE
);
1559 check_interface(presenter
, &IID_IMFVideoDeviceID
, TRUE
);
1560 check_interface(presenter
, &IID_IMFQualityAdvise
, TRUE
);
1561 check_interface(presenter
, &IID_IDirect3DDeviceManager9
, TRUE
);
1562 check_interface(presenter
, &IID_IMFQualityAdviseLimits
, TRUE
);
1563 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFVideoPositionMapper
, TRUE
);
1564 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFVideoDisplayControl
, TRUE
);
1565 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFVideoPresenter
, TRUE
);
1566 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFClockStateSink
, TRUE
);
1567 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFTopologyServiceLookupClient
, TRUE
);
1568 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IQualProp
, TRUE
);
1569 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFRateSupport
, TRUE
);
1570 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFGetService
, TRUE
);
1571 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFVideoDeviceID
, TRUE
);
1572 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFQualityAdvise
, TRUE
);
1573 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFQualityAdviseLimits
, TRUE
);
1574 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFTransform
, FALSE
);
1575 check_service_interface(presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IDirect3DDeviceManager9
, TRUE
);
1576 check_service_interface(presenter
, &MR_VIDEO_ACCELERATION_SERVICE
, &IID_IDirect3DDeviceManager9
, TRUE
);
1578 /* Query arbitrary supported interface back from device manager wrapper. */
1579 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IDirect3DDeviceManager9
, (void **)&dm
);
1580 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1581 hr
= IDirect3DDeviceManager9_QueryInterface(dm
, &IID_IQualProp
, (void **)&unk
);
1582 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1583 IUnknown_Release(unk
);
1584 hr
= IDirect3DDeviceManager9_QueryInterface(dm
, &IID_IUnknown
, (void **)&unk
);
1585 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1586 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IUnknown
, (void **)&unk2
);
1587 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1588 ok(unk
== unk2
, "Unexpected interface.\n");
1589 IUnknown_Release(unk2
);
1590 IUnknown_Release(unk
);
1591 IDirect3DDeviceManager9_Release(dm
);
1593 hr
= MFGetService((IUnknown
*)presenter
, &MR_VIDEO_MIXER_SERVICE
, &IID_IUnknown
, (void **)&unk
);
1594 ok(hr
== MF_E_UNSUPPORTED_SERVICE
, "Unexpected hr %#lx.\n", hr
);
1596 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDeviceID
, (void **)&deviceid
);
1597 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1599 hr
= IMFVideoDeviceID_GetDeviceID(deviceid
, NULL
);
1600 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
1602 hr
= IMFVideoDeviceID_GetDeviceID(deviceid
, &iid
);
1603 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1604 ok(IsEqualIID(&iid
, &IID_IDirect3DDevice9
), "Unexpected id %s.\n", wine_dbgstr_guid(&iid
));
1606 IMFVideoDeviceID_Release(deviceid
);
1608 hr
= MFGetService((IUnknown
*)presenter
, &MR_VIDEO_RENDER_SERVICE
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
1609 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1611 hr
= IMFVideoDisplayControl_GetRenderingPrefs(display_control
, NULL
);
1612 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
1615 hr
= IMFVideoDisplayControl_GetRenderingPrefs(display_control
, &flags
);
1616 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1617 ok(!flags
, "Unexpected rendering flags %#lx.\n", flags
);
1619 IMFVideoDisplayControl_Release(display_control
);
1621 hr
= MFGetService((IUnknown
*)presenter
, &MR_VIDEO_ACCELERATION_SERVICE
, &IID_IDirect3DDeviceManager9
, (void **)&dm
);
1622 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1623 IDirect3DDeviceManager9_Release(dm
);
1625 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
1626 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1629 hwnd
= create_window();
1630 ok(!!hwnd
, "Failed to create a test window.\n");
1632 hr
= IMFVideoDisplayControl_GetVideoWindow(display_control
, NULL
);
1633 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
1636 hr
= IMFVideoDisplayControl_GetVideoWindow(display_control
, &hwnd2
);
1637 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1638 ok(hwnd2
== NULL
, "Unexpected window %p.\n", hwnd2
);
1640 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, NULL
);
1641 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1643 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, (HWND
)0x1);
1644 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1646 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, hwnd
);
1647 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1650 hr
= IMFVideoDisplayControl_GetVideoWindow(display_control
, &hwnd2
);
1651 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1652 ok(hwnd2
== hwnd
, "Unexpected window %p.\n", hwnd2
);
1653 IMFVideoDisplayControl_Release(display_control
);
1656 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFRateSupport
, (void **)&rate_support
);
1657 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1660 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_FORWARD
, FALSE
, &rate
);
1661 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1662 ok(rate
== 0.0f
, "Unexpected rate %f.\n", rate
);
1665 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_FORWARD
, TRUE
, &rate
);
1666 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1667 ok(rate
== 0.0f
, "Unexpected rate %f.\n", rate
);
1670 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_REVERSE
, FALSE
, &rate
);
1671 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1672 ok(rate
== 0.0f
, "Unexpected rate %f.\n", rate
);
1675 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_REVERSE
, TRUE
, &rate
);
1676 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1677 ok(rate
== 0.0f
, "Unexpected rate %f.\n", rate
);
1679 IMFRateSupport_Release(rate_support
);
1681 ok(!IMFVideoPresenter_Release(presenter
), "Unexpected refcount.\n");
1683 DestroyWindow(hwnd
);
1686 static void test_MFCreateVideoMixerAndPresenter(void)
1688 IUnknown
*mixer
, *presenter
;
1691 hr
= MFCreateVideoMixerAndPresenter(NULL
, NULL
, &IID_IUnknown
, (void **)&mixer
, &IID_IUnknown
, (void **)&presenter
);
1692 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1694 IUnknown_Release(mixer
);
1695 IUnknown_Release(presenter
);
1698 static HRESULT WINAPI
test_notify_callback_QueryInterface(IMFVideoSampleAllocatorNotify
*iface
,
1699 REFIID riid
, void **obj
)
1701 if (IsEqualIID(riid
, &IID_IMFVideoSampleAllocatorNotify
) ||
1702 IsEqualIID(riid
, &IID_IUnknown
))
1705 IMFVideoSampleAllocatorNotify_AddRef(iface
);
1710 return E_NOINTERFACE
;
1713 static ULONG WINAPI
test_notify_callback_AddRef(IMFVideoSampleAllocatorNotify
*iface
)
1718 static ULONG WINAPI
test_notify_callback_Release(IMFVideoSampleAllocatorNotify
*iface
)
1723 static HRESULT WINAPI
test_notify_callback_NotifyRelease(IMFVideoSampleAllocatorNotify
*iface
)
1728 static const IMFVideoSampleAllocatorNotifyVtbl test_notify_callback_vtbl
=
1730 test_notify_callback_QueryInterface
,
1731 test_notify_callback_AddRef
,
1732 test_notify_callback_Release
,
1733 test_notify_callback_NotifyRelease
,
1736 static void test_MFCreateVideoSampleAllocator(void)
1738 IMFVideoSampleAllocatorNotify test_notify
= { &test_notify_callback_vtbl
};
1739 IMFVideoSampleAllocatorCallback
*allocator_cb
;
1740 IMFMediaType
*media_type
, *video_type
;
1741 IMFVideoSampleAllocator
*allocator
;
1742 IDirect3DDeviceManager9
*manager
;
1743 IMFSample
*sample
, *sample2
;
1744 IDirect3DSurface9
*surface
;
1745 IDirect3DDevice9
*device
;
1746 IMFMediaBuffer
*buffer
;
1747 LONG refcount
, count
;
1755 hr
= MFCreateVideoSampleAllocator(&IID_IUnknown
, (void **)&unk
);
1756 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1757 IUnknown_Release(unk
);
1759 hr
= MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
1760 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1762 hr
= IMFVideoSampleAllocator_QueryInterface(allocator
, &IID_IMFVideoSampleAllocatorCallback
, (void **)&allocator_cb
);
1763 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1765 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, NULL
);
1766 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1768 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, &test_notify
);
1769 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1771 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, NULL
);
1772 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1774 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, NULL
);
1775 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1778 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
1779 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1780 ok(!count
, "Unexpected count %ld.\n", count
);
1782 hr
= IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator
);
1783 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1785 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
1786 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
1788 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, NULL
);
1789 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1791 hr
= MFCreateMediaType(&media_type
);
1792 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1794 /* It expects IMFVideoMediaType aka video major type. Exact return code is E_NOINTERFACE,
1795 likely coming from querying for IMFVideoMediaType. Does not seem valuable to match it. */
1796 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, media_type
);
1797 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
1799 video_type
= create_video_type(&MFVideoFormat_RGB32
);
1801 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, video_type
);
1802 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
1804 /* Frame size is required. */
1805 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 240);
1806 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1807 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 0, video_type
);
1808 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1810 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
1811 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1812 ok(count
== 1, "Unexpected count %ld.\n", count
);
1815 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
1816 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1817 refcount
= get_refcount(sample
);
1819 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample2
);
1820 ok(hr
== MF_E_SAMPLEALLOCATOR_EMPTY
, "Unexpected hr %#lx.\n", hr
);
1822 /* Reinitialize with active sample. */
1823 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 4, video_type
);
1824 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1825 ok(refcount
== get_refcount(sample
), "Unexpected refcount %lu.\n", get_refcount(sample
));
1827 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
1828 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1829 ok(count
== 4, "Unexpected count %ld.\n", count
);
1831 check_interface(sample
, &IID_IMFDesiredSample
, TRUE
);
1832 check_interface(sample
, &IID_IMFTrackedSample
, TRUE
);
1834 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
1835 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1837 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
1839 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFGetService
, (void **)&gs
);
1840 ok(hr
== S_OK
|| broken(hr
== E_NOINTERFACE
) /* Win7 */, "Unexpected hr %#lx.\n", hr
);
1842 /* Device manager wasn't set, sample gets regular memory buffers. */
1845 hr
= IMFGetService_GetService(gs
, &MR_BUFFER_SERVICE
, &IID_IDirect3DSurface9
, (void **)&surface
);
1846 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
1847 IMFGetService_Release(gs
);
1850 IMFMediaBuffer_Release(buffer
);
1852 IMFSample_Release(sample
);
1854 IMFVideoSampleAllocatorCallback_Release(allocator_cb
);
1856 IMFVideoSampleAllocator_Release(allocator
);
1858 hr
= MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocatorCallback
, (void **)&unk
);
1859 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1860 IUnknown_Release(unk
);
1862 /* Using device manager */
1863 window
= create_window();
1864 if (!(device
= create_device(window
)))
1866 skip("Failed to create a D3D device, skipping tests.\n");
1867 IMFMediaType_Release(video_type
);
1868 IMFMediaType_Release(media_type
);
1869 DestroyWindow(window
);
1873 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &manager
);
1874 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1875 hr
= IDirect3DDeviceManager9_ResetDevice(manager
, device
, token
);
1876 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
1878 hr
= MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
1879 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1881 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)manager
);
1882 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1884 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 240);
1885 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1886 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 0, video_type
);
1887 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1889 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
1890 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1892 check_interface(sample
, &IID_IMFTrackedSample
, TRUE
);
1893 check_interface(sample
, &IID_IMFDesiredSample
, TRUE
);
1895 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
1896 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1898 check_service_interface(buffer
, &MR_BUFFER_SERVICE
, &IID_IDirect3DSurface9
, TRUE
);
1899 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
1900 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
1902 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
1903 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1905 hr
= IMFMediaBuffer_Unlock(buffer
);
1906 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1908 IMFMediaBuffer_Release(buffer
);
1909 IMFSample_Release(sample
);
1910 IMFVideoSampleAllocator_Release(allocator
);
1911 IMFMediaType_Release(video_type
);
1912 IMFMediaType_Release(media_type
);
1913 IDirect3DDeviceManager9_Release(manager
);
1914 IDirect3DDevice9_Release(device
);
1915 DestroyWindow(window
);
1920 IMFTopologyServiceLookup IMFTopologyServiceLookup_iface
;
1921 IMediaEventSink IMediaEventSink_iface
;
1922 IMFTransform
*mixer
;
1923 IMFVideoPresenter
*presenter
;
1926 static struct test_host
*impl_from_test_host(IMFTopologyServiceLookup
*iface
)
1928 return CONTAINING_RECORD(iface
, struct test_host
, IMFTopologyServiceLookup_iface
);
1931 static struct test_host
*impl_from_test_host_events(IMediaEventSink
*iface
)
1933 return CONTAINING_RECORD(iface
, struct test_host
, IMediaEventSink_iface
);
1936 static HRESULT WINAPI
test_host_QueryInterface(IMFTopologyServiceLookup
*iface
, REFIID riid
, void **obj
)
1938 if (IsEqualIID(riid
, &IID_IMFTopologyServiceLookup
) ||
1939 IsEqualIID(riid
, &IID_IUnknown
))
1942 IMFTopologyServiceLookup_AddRef(iface
);
1947 return E_NOINTERFACE
;
1950 static ULONG WINAPI
test_host_AddRef(IMFTopologyServiceLookup
*iface
)
1955 static ULONG WINAPI
test_host_Release(IMFTopologyServiceLookup
*iface
)
1960 static HRESULT WINAPI
test_host_LookupService(IMFTopologyServiceLookup
*iface
,
1961 MF_SERVICE_LOOKUP_TYPE lookup_type
, DWORD index
, REFGUID service
,
1962 REFIID riid
, void **objects
, DWORD
*num_objects
)
1964 struct test_host
*host
= impl_from_test_host(iface
);
1966 ok(*num_objects
== 1, "Unexpected number of requested objects %lu\n", *num_objects
);
1968 memset(objects
, 0, *num_objects
* sizeof(*objects
));
1970 if (IsEqualGUID(service
, &MR_VIDEO_RENDER_SERVICE
))
1972 if (IsEqualIID(riid
, &IID_IMFClock
)) return E_FAIL
;
1973 if (IsEqualIID(riid
, &IID_IMediaEventSink
))
1975 *objects
= &host
->IMediaEventSink_iface
;
1976 IMediaEventSink_AddRef(&host
->IMediaEventSink_iface
);
1980 ok(0, "Unexpected interface %s.\n", wine_dbgstr_guid(riid
));
1981 return E_UNEXPECTED
;
1984 if (IsEqualGUID(service
, &MR_VIDEO_MIXER_SERVICE
))
1986 if (IsEqualIID(riid
, &IID_IMFTransform
))
1988 *objects
= host
->mixer
;
1989 IMFTransform_AddRef(host
->mixer
);
1992 ok(0, "Unexpected interface %s.\n", wine_dbgstr_guid(riid
));
1993 return E_UNEXPECTED
;
1999 static const IMFTopologyServiceLookupVtbl test_host_vtbl
=
2001 test_host_QueryInterface
,
2004 test_host_LookupService
,
2007 static HRESULT WINAPI
test_host_events_QueryInterface(IMediaEventSink
*iface
, REFIID riid
, void **obj
)
2009 struct test_host
*host
= impl_from_test_host_events(iface
);
2010 return IMFTopologyServiceLookup_QueryInterface(&host
->IMFTopologyServiceLookup_iface
, riid
, obj
);
2013 static ULONG WINAPI
test_host_events_AddRef(IMediaEventSink
*iface
)
2015 struct test_host
*host
= impl_from_test_host_events(iface
);
2016 return IMFTopologyServiceLookup_AddRef(&host
->IMFTopologyServiceLookup_iface
);
2019 static ULONG WINAPI
test_host_events_Release(IMediaEventSink
*iface
)
2021 struct test_host
*host
= impl_from_test_host_events(iface
);
2022 return IMFTopologyServiceLookup_Release(&host
->IMFTopologyServiceLookup_iface
);
2025 static HRESULT WINAPI
test_host_events_Notify(IMediaEventSink
*iface
, LONG code
, LONG_PTR param1
, LONG_PTR param2
)
2030 static const IMediaEventSinkVtbl test_host_events_vtbl
=
2032 test_host_events_QueryInterface
,
2033 test_host_events_AddRef
,
2034 test_host_events_Release
,
2035 test_host_events_Notify
,
2038 static void init_test_host(struct test_host
*host
, IMFTransform
*mixer
, IMFVideoPresenter
*presenter
)
2040 host
->IMFTopologyServiceLookup_iface
.lpVtbl
= &test_host_vtbl
;
2041 host
->IMediaEventSink_iface
.lpVtbl
= &test_host_events_vtbl
;
2042 /* No need to keep references. */
2043 host
->mixer
= mixer
;
2044 host
->presenter
= presenter
;
2047 static void test_presenter_video_position(void)
2049 IMFTopologyServiceLookupClient
*lookup_client
;
2050 IMFVideoDisplayControl
*display_control
;
2051 IMFAttributes
*mixer_attributes
;
2052 MFVideoNormalizedRect src_rect
;
2053 IMFVideoPresenter
*presenter
;
2054 struct test_host host
;
2055 IMFTransform
*mixer
;
2061 hwnd
= create_window();
2062 ok(!!hwnd
, "Failed to create a test window.\n");
2064 /* Setting position without the mixer. */
2065 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
2066 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2067 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2068 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2070 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_INVALIDATEMEDIATYPE
, 0);
2071 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
2072 SetRect(&dst_rect
, 0, 0, 10, 10);
2073 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst_rect
);
2074 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2075 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, hwnd
);
2076 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2078 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_INVALIDATEMEDIATYPE
, 0);
2079 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
2080 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst_rect
);
2081 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2083 IMFVideoDisplayControl_Release(display_control
);
2084 IMFVideoPresenter_Release(presenter
);
2086 /* With the mixer. */
2087 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
2088 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
2090 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
2091 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2093 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2094 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2096 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFTopologyServiceLookupClient
, (void **)&lookup_client
);
2097 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2099 init_test_host(&host
, mixer
, presenter
);
2101 /* Clear default mixer attributes, then attach presenter. */
2102 hr
= IMFTransform_GetAttributes(mixer
, &mixer_attributes
);
2103 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2105 hr
= IMFAttributes_DeleteAllItems(mixer_attributes
);
2106 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2108 hr
= IMFTopologyServiceLookupClient_InitServicePointers(lookup_client
, &host
.IMFTopologyServiceLookup_iface
);
2109 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2111 hr
= IMFAttributes_GetCount(mixer_attributes
, &count
);
2112 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2113 ok(count
== 1, "Unexpected count %u.\n", count
);
2115 memset(&src_rect
, 0, sizeof(src_rect
));
2116 hr
= IMFAttributes_GetBlob(mixer_attributes
, &VIDEO_ZOOM_RECT
, (UINT8
*)&src_rect
, sizeof(src_rect
), NULL
);
2117 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2118 ok(src_rect
.left
== 0.0f
&& src_rect
.top
== 0.0f
&& src_rect
.right
== 1.0f
&&
2119 src_rect
.bottom
== 1.0f
, "Unexpected source rectangle.\n");
2121 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, NULL
, &dst_rect
);
2122 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2124 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, &src_rect
, NULL
);
2125 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2127 SetRect(&dst_rect
, 1, 2, 3, 4);
2128 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, &src_rect
, &dst_rect
);
2129 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2130 ok(src_rect
.left
== 0.0f
&& src_rect
.top
== 0.0f
&& src_rect
.right
== 1.0f
&&
2131 src_rect
.bottom
== 1.0f
, "Unexpected source rectangle.\n");
2132 ok(dst_rect
.left
== 0 && dst_rect
.right
== 0 && dst_rect
.top
== 0 && dst_rect
.bottom
== 0,
2133 "Unexpected destination rectangle %s.\n", wine_dbgstr_rect(&dst_rect
));
2135 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, NULL
);
2136 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2138 /* Setting position requires a window. */
2139 SetRect(&dst_rect
, 0, 0, 10, 10);
2140 memset(&src_rect
, 0, sizeof(src_rect
));
2141 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, &src_rect
, &dst_rect
);
2142 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2144 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, hwnd
);
2145 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2147 SetRect(&dst_rect
, 0, 0, 10, 10);
2148 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst_rect
);
2149 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2151 SetRect(&dst_rect
, 1, 2, 3, 4);
2152 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, &src_rect
, &dst_rect
);
2153 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2154 ok(dst_rect
.left
== 0 && dst_rect
.right
== 10 && dst_rect
.top
== 0 && dst_rect
.bottom
== 10,
2155 "Unexpected destination rectangle %s.\n", wine_dbgstr_rect(&dst_rect
));
2157 set_rect(&src_rect
, 0.0f
, 0.0f
, 2.0f
, 1.0f
);
2158 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, &src_rect
, NULL
);
2159 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2161 set_rect(&src_rect
, -0.1f
, 0.0f
, 0.9f
, 1.0f
);
2162 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, &src_rect
, NULL
);
2163 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2165 /* Flipped source rectangle. */
2166 set_rect(&src_rect
, 0.5f
, 0.0f
, 0.4f
, 1.0f
);
2167 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, &src_rect
, NULL
);
2168 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2170 set_rect(&src_rect
, 0.0f
, 0.5f
, 0.4f
, 0.1f
);
2171 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, &src_rect
, NULL
);
2172 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2174 set_rect(&src_rect
, 0.1f
, 0.2f
, 0.8f
, 0.9f
);
2175 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, &src_rect
, NULL
);
2176 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2178 /* Presenter updates mixer attribute. */
2179 memset(&src_rect
, 0, sizeof(src_rect
));
2180 hr
= IMFAttributes_GetBlob(mixer_attributes
, &VIDEO_ZOOM_RECT
, (UINT8
*)&src_rect
, sizeof(src_rect
), NULL
);
2181 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2182 ok(src_rect
.left
== 0.1f
&& src_rect
.top
== 0.2f
&& src_rect
.right
== 0.8f
&&
2183 src_rect
.bottom
== 0.9f
, "Unexpected source rectangle.\n");
2185 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, &src_rect
, &dst_rect
);
2186 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2187 ok(src_rect
.left
== 0.1f
&& src_rect
.top
== 0.2f
&& src_rect
.right
== 0.8f
&&
2188 src_rect
.bottom
== 0.9f
, "Unexpected source rectangle.\n");
2190 SetRect(&dst_rect
, 1, 2, 999, 1000);
2191 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst_rect
);
2192 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2194 SetRect(&dst_rect
, 0, 1, 3, 4);
2195 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, &src_rect
, &dst_rect
);
2196 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2197 ok(dst_rect
.left
== 1 && dst_rect
.right
== 999 && dst_rect
.top
== 2 && dst_rect
.bottom
== 1000,
2198 "Unexpected destination rectangle %s.\n", wine_dbgstr_rect(&dst_rect
));
2200 /* Flipped destination rectangle. */
2201 SetRect(&dst_rect
, 100, 1, 50, 1000);
2202 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst_rect
);
2203 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2205 SetRect(&dst_rect
, 1, 100, 100, 50);
2206 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst_rect
);
2207 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2209 IMFVideoDisplayControl_Release(display_control
);
2211 IMFTopologyServiceLookupClient_Release(lookup_client
);
2212 IMFVideoPresenter_Release(presenter
);
2213 IMFAttributes_Release(mixer_attributes
);
2214 IMFTransform_Release(mixer
);
2216 DestroyWindow(hwnd
);
2219 static void test_presenter_native_video_size(void)
2221 IMFTopologyServiceLookupClient
*lookup_client
;
2222 IMFVideoDisplayControl
*display_control
;
2223 IMFVideoPresenter
*presenter
;
2224 struct test_host host
;
2225 IMFTransform
*mixer
;
2228 IMFMediaType
*video_type
;
2229 IDirect3DDeviceManager9
*dm
;
2231 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
2232 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
2234 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
2235 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2237 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFTopologyServiceLookupClient
, (void **)&lookup_client
);
2238 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2239 IMFTopologyServiceLookupClient_Release(lookup_client
);
2241 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2242 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2244 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, NULL
, NULL
);
2245 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2247 memset(&size
, 0xcc, sizeof(size
));
2248 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, &size
, NULL
);
2249 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2250 ok(size
.cx
== 0 && size
.cy
== 0, "Unexpected size.\n");
2252 memset(&ratio
, 0xcc, sizeof(ratio
));
2253 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, NULL
, &ratio
);
2254 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2255 ok(ratio
.cx
== 0 && ratio
.cy
== 0, "Unexpected ratio.\n");
2257 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFTopologyServiceLookupClient
, (void **)&lookup_client
);
2258 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2260 /* Configure mixer primary stream. */
2261 hr
= MFGetService((IUnknown
*)presenter
, &MR_VIDEO_ACCELERATION_SERVICE
, &IID_IDirect3DDeviceManager9
, (void **)&dm
);
2262 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2264 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_SET_D3D_MANAGER
, (ULONG_PTR
)dm
);
2265 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2267 IDirect3DDeviceManager9_Release(dm
);
2269 video_type
= create_video_type(&MFVideoFormat_RGB32
);
2271 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
)640 << 32 | 480);
2272 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2273 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
2274 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2276 hr
= IMFTransform_SetInputType(mixer
, 0, video_type
, 0);
2277 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2279 /* Native video size is cached on initialization. */
2280 init_test_host(&host
, mixer
, presenter
);
2282 hr
= IMFTopologyServiceLookupClient_InitServicePointers(lookup_client
, &host
.IMFTopologyServiceLookup_iface
);
2283 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2285 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, &size
, &ratio
);
2286 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2287 ok(size
.cx
== 640 && size
.cy
== 480, "Unexpected size %lu x %lu.\n", size
.cx
, size
.cy
);
2288 ok((ratio
.cx
== 4 && ratio
.cy
== 3) || broken(!memcmp(&ratio
, &size
, sizeof(ratio
))) /* < Win10 */,
2289 "Unexpected ratio %lu x %lu.\n", ratio
.cx
, ratio
.cy
);
2291 /* Update input type. */
2292 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
)320 << 32 | 240);
2293 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2295 hr
= IMFTransform_SetInputType(mixer
, 0, video_type
, 0);
2296 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2298 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, &size
, &ratio
);
2299 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2300 ok(size
.cx
== 640 && size
.cy
== 480, "Unexpected size %lu x %lu.\n", size
.cx
, size
.cy
);
2301 ok((ratio
.cx
== 4 && ratio
.cy
== 3) || broken(!memcmp(&ratio
, &size
, sizeof(ratio
))) /* < Win10 */,
2302 "Unexpected ratio %lu x %lu.\n", ratio
.cx
, ratio
.cy
);
2304 /* Negotiating types updates native video size. */
2305 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_INVALIDATEMEDIATYPE
, 0);
2306 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2308 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, &size
, &ratio
);
2309 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2310 ok(size
.cx
== 320 && size
.cy
== 240, "Unexpected size %lu x %lu.\n", size
.cx
, size
.cy
);
2311 ok((ratio
.cx
== 4 && ratio
.cy
== 3) || broken(!memcmp(&ratio
, &size
, sizeof(ratio
))) /* < Win10 */,
2312 "Unexpected ratio %lu x %lu.\n", ratio
.cx
, ratio
.cy
);
2314 IMFTopologyServiceLookupClient_Release(lookup_client
);
2315 IMFMediaType_Release(video_type
);
2316 IMFVideoDisplayControl_Release(display_control
);
2317 IMFVideoPresenter_Release(presenter
);
2318 IMFTransform_Release(mixer
);
2321 static void test_presenter_ar_mode(void)
2323 IMFVideoDisplayControl
*display_control
;
2327 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2328 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2330 hr
= IMFVideoDisplayControl_GetAspectRatioMode(display_control
, NULL
);
2331 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2334 hr
= IMFVideoDisplayControl_GetAspectRatioMode(display_control
, &mode
);
2335 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2336 ok(mode
== (MFVideoARMode_PreservePicture
| MFVideoARMode_PreservePixel
), "Unexpected mode %#lx.\n", mode
);
2338 hr
= IMFVideoDisplayControl_SetAspectRatioMode(display_control
, 0x100);
2339 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2341 hr
= IMFVideoDisplayControl_SetAspectRatioMode(display_control
, MFVideoARMode_Mask
);
2342 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2345 hr
= IMFVideoDisplayControl_GetAspectRatioMode(display_control
, &mode
);
2346 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2347 ok(mode
== MFVideoARMode_Mask
, "Unexpected mode %#lx.\n", mode
);
2349 IMFVideoDisplayControl_Release(display_control
);
2352 static void test_presenter_video_window(void)
2354 D3DDEVICE_CREATION_PARAMETERS device_params
= { 0 };
2355 IMFVideoDisplayControl
*display_control
;
2356 IDirect3DDeviceManager9
*dm
;
2357 IDirect3DDevice9
*d3d_device
;
2360 IDirect3DSwapChain9
*swapchain
;
2361 D3DPRESENT_PARAMETERS present_params
= { 0 };
2364 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2365 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2367 hr
= MFGetService((IUnknown
*)display_control
, &MR_VIDEO_ACCELERATION_SERVICE
,
2368 &IID_IDirect3DDeviceManager9
, (void **)&dm
);
2370 hr
= IDirect3DDeviceManager9_OpenDeviceHandle(dm
, &hdevice
);
2371 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2373 hr
= IDirect3DDeviceManager9_LockDevice(dm
, hdevice
, &d3d_device
, FALSE
);
2374 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2376 hr
= IDirect3DDevice9_GetCreationParameters(d3d_device
, &device_params
);
2377 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2378 ok(device_params
.hFocusWindow
== GetDesktopWindow(), "Unexpected window %p.\n", device_params
.hFocusWindow
);
2380 hr
= IDirect3DDevice9_GetSwapChain(d3d_device
, 0, &swapchain
);
2381 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2383 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain
, &present_params
);
2384 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2386 ok(present_params
.hDeviceWindow
== GetDesktopWindow(), "Unexpected device window.\n");
2387 ok(present_params
.Windowed
, "Unexpected windowed mode.\n");
2388 ok(present_params
.SwapEffect
== D3DSWAPEFFECT_COPY
, "Unexpected swap effect.\n");
2389 ok(present_params
.Flags
& D3DPRESENTFLAG_VIDEO
, "Unexpected flags %#lx.\n", present_params
.Flags
);
2390 ok(present_params
.PresentationInterval
== D3DPRESENT_INTERVAL_IMMEDIATE
, "Unexpected present interval.\n");
2392 IDirect3DSwapChain9_Release(swapchain
);
2393 IDirect3DDevice9_Release(d3d_device
);
2395 hr
= IDirect3DDeviceManager9_UnlockDevice(dm
, hdevice
, FALSE
);
2396 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2398 /* Setting window. */
2399 hr
= IMFVideoDisplayControl_GetVideoWindow(display_control
, &window
);
2400 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2401 ok(!window
, "Unexpected window %p.\n", window
);
2403 window
= create_window();
2405 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, window
);
2406 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2408 /* Device is not recreated or reset on window change. */
2409 hr
= IDirect3DDeviceManager9_LockDevice(dm
, hdevice
, &d3d_device
, FALSE
);
2410 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2412 hr
= IDirect3DDevice9_GetSwapChain(d3d_device
, 0, &swapchain
);
2413 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2415 hr
= IDirect3DSwapChain9_GetPresentParameters(swapchain
, &present_params
);
2416 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2418 ok(present_params
.hDeviceWindow
== GetDesktopWindow(), "Unexpected device window.\n");
2419 ok(present_params
.Windowed
, "Unexpected windowed mode.\n");
2420 ok(present_params
.SwapEffect
== D3DSWAPEFFECT_COPY
, "Unexpected swap effect.\n");
2421 ok(present_params
.Flags
& D3DPRESENTFLAG_VIDEO
, "Unexpected flags %#lx.\n", present_params
.Flags
);
2422 ok(present_params
.PresentationInterval
== D3DPRESENT_INTERVAL_IMMEDIATE
, "Unexpected present interval.\n");
2424 IDirect3DSwapChain9_Release(swapchain
);
2425 IDirect3DDevice9_Release(d3d_device
);
2427 hr
= IDirect3DDeviceManager9_UnlockDevice(dm
, hdevice
, FALSE
);
2428 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2430 hr
= IDirect3DDeviceManager9_CloseDeviceHandle(dm
, hdevice
);
2431 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2433 IDirect3DDeviceManager9_Release(dm
);
2434 ok(!IMFVideoDisplayControl_Release(display_control
), "Unexpected refcount.\n");
2436 DestroyWindow(window
);
2439 static void test_presenter_quality_control(void)
2441 IMFQualityAdviseLimits
*qa_limits
;
2442 IMFVideoPresenter
*presenter
;
2443 MF_QUALITY_DROP_MODE mode
;
2444 IMFQualityAdvise
*advise
;
2445 MF_QUALITY_LEVEL level
;
2446 IQualProp
*qual_prop
;
2450 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
2451 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2453 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFQualityAdviseLimits
, (void **)&qa_limits
);
2454 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2456 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFQualityAdvise
, (void **)&advise
);
2457 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2459 hr
= IMFQualityAdviseLimits_GetMaximumDropMode(qa_limits
, NULL
);
2461 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2463 hr
= IMFQualityAdviseLimits_GetMaximumDropMode(qa_limits
, &mode
);
2465 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2467 ok(mode
== MF_DROP_MODE_NONE
, "Unexpected mode %d.\n", mode
);
2469 hr
= IMFQualityAdviseLimits_GetMinimumQualityLevel(qa_limits
, NULL
);
2471 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2473 hr
= IMFQualityAdviseLimits_GetMinimumQualityLevel(qa_limits
, &level
);
2475 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2477 ok(level
== MF_QUALITY_NORMAL
, "Unexpected level %d.\n", level
);
2479 IMFQualityAdviseLimits_Release(qa_limits
);
2483 hr
= IMFQualityAdvise_GetDropMode(advise
, &mode
);
2484 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2485 ok(mode
== MF_DROP_MODE_NONE
, "Unexpected mode %d.\n", mode
);
2488 hr
= IMFQualityAdvise_GetQualityLevel(advise
, &level
);
2489 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2490 ok(level
== MF_QUALITY_NORMAL
, "Unexpected mode %d.\n", level
);
2492 hr
= IMFQualityAdvise_SetDropMode(advise
, MF_DROP_MODE_1
);
2493 ok(hr
== MF_E_NO_MORE_DROP_MODES
, "Unexpected hr %#lx.\n", hr
);
2495 hr
= IMFQualityAdvise_SetQualityLevel(advise
, MF_QUALITY_NORMAL_MINUS_1
);
2496 ok(hr
== MF_E_NO_MORE_QUALITY_LEVELS
, "Unexpected hr %#lx.\n", hr
);
2499 IMFQualityAdvise_Release(advise
);
2501 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IQualProp
, (void **)&qual_prop
);
2502 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2504 hr
= IQualProp_get_FramesDrawn(qual_prop
, NULL
);
2505 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
2507 hr
= IQualProp_get_FramesDrawn(qual_prop
, &frame_count
);
2508 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
2510 IQualProp_Release(qual_prop
);
2512 IMFVideoPresenter_Release(presenter
);
2515 static void get_output_aperture(IMFTransform
*mixer
, SIZE
*frame_size
, MFVideoArea
*aperture
)
2517 IMFMediaType
*media_type
;
2521 memset(frame_size
, 0xcc, sizeof(*frame_size
));
2522 memset(aperture
, 0xcc, sizeof(*aperture
));
2524 hr
= IMFTransform_GetOutputCurrentType(mixer
, 0, &media_type
);
2525 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2527 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &size
);
2528 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2530 frame_size
->cx
= size
>> 32;
2531 frame_size
->cy
= size
;
2533 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_GEOMETRIC_APERTURE
, (UINT8
*)aperture
, sizeof(*aperture
), NULL
);
2534 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2536 IMFMediaType_Release(media_type
);
2539 static void test_presenter_media_type(void)
2541 IMFTopologyServiceLookupClient
*lookup_client
;
2542 IMFVideoPresenter
*presenter
;
2543 struct test_host host
;
2544 IMFMediaType
*input_type
;
2545 IDirect3DDeviceManager9
*manager
;
2547 IMFTransform
*mixer
;
2548 IDirect3DDevice9
*device
;
2552 MFVideoArea aperture
;
2553 IMFVideoDisplayControl
*display_control
;
2556 window
= create_window();
2557 if (!(device
= create_device(window
)))
2559 skip("Failed to create a D3D device, skipping tests.\n");
2563 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &manager
);
2564 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2566 hr
= IDirect3DDeviceManager9_ResetDevice(manager
, device
, token
);
2567 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2569 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
2570 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2572 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2573 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2575 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
2576 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
2578 input_type
= create_video_type(&MFVideoFormat_RGB32
);
2580 hr
= IMFMediaType_SetUINT64(input_type
, &MF_MT_FRAME_SIZE
, (UINT64
)100 << 32 | 50);
2581 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2582 hr
= IMFMediaType_SetUINT32(input_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
2583 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2585 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_SET_D3D_MANAGER
, (ULONG_PTR
)manager
);
2586 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2588 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFTopologyServiceLookupClient
, (void **)&lookup_client
);
2589 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2591 init_test_host(&host
, mixer
, presenter
);
2593 hr
= IMFTopologyServiceLookupClient_InitServicePointers(lookup_client
, &host
.IMFTopologyServiceLookup_iface
);
2594 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2595 IMFTopologyServiceLookupClient_Release(lookup_client
);
2597 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, window
);
2598 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2600 /* Set destination rectangle before mixer types are configured. */
2601 SetRect(&dst
, 0, 0, 101, 51);
2602 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst
);
2603 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2605 hr
= IMFTransform_SetInputType(mixer
, 0, input_type
, 0);
2606 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2607 IMFMediaType_Release(input_type
);
2609 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_INVALIDATEMEDIATYPE
, 0);
2610 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2612 get_output_aperture(mixer
, &frame_size
, &aperture
);
2613 ok(frame_size
.cx
== 101 && frame_size
.cy
== 51, "Unexpected frame size %lu x %lu.\n", frame_size
.cx
, frame_size
.cy
);
2614 ok(aperture
.Area
.cx
== 101 && aperture
.Area
.cy
== 51, "Unexpected size %lu x %lu.\n", aperture
.Area
.cx
, aperture
.Area
.cy
);
2615 ok(!aperture
.OffsetX
.value
&& !aperture
.OffsetX
.fract
&& !aperture
.OffsetY
.value
&& !aperture
.OffsetY
.fract
,
2616 "Unexpected offset %u x %u.\n", aperture
.OffsetX
.value
, aperture
.OffsetY
.value
);
2618 SetRect(&dst
, 1, 2, 200, 300);
2619 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &dst
);
2620 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2622 get_output_aperture(mixer
, &frame_size
, &aperture
);
2623 ok(frame_size
.cx
== 199 && frame_size
.cy
== 298, "Unexpected frame size %lu x %lu.\n", frame_size
.cx
, frame_size
.cy
);
2624 ok(aperture
.Area
.cx
== 199 && aperture
.Area
.cy
== 298, "Unexpected size %lu x %lu.\n", aperture
.Area
.cx
, aperture
.Area
.cy
);
2625 ok(!aperture
.OffsetX
.value
&& !aperture
.OffsetX
.fract
&& !aperture
.OffsetY
.value
&& !aperture
.OffsetY
.fract
,
2626 "Unexpected offset %u x %u.\n", aperture
.OffsetX
.value
, aperture
.OffsetY
.value
);
2628 hr
= IMFVideoDisplayControl_SetAspectRatioMode(display_control
, MFVideoARMode_None
);
2629 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2631 get_output_aperture(mixer
, &frame_size
, &aperture
);
2632 ok(frame_size
.cx
== 199 && frame_size
.cy
== 298, "Unexpected frame size %lu x %lu.\n", frame_size
.cx
, frame_size
.cy
);
2633 ok(aperture
.Area
.cx
== 199 && aperture
.Area
.cy
== 298, "Unexpected size %lu x %lu.\n", aperture
.Area
.cx
, aperture
.Area
.cy
);
2634 ok(!aperture
.OffsetX
.value
&& !aperture
.OffsetX
.fract
&& !aperture
.OffsetY
.value
&& !aperture
.OffsetY
.fract
,
2635 "Unexpected offset %u x %u.\n", aperture
.OffsetX
.value
, aperture
.OffsetY
.value
);
2637 IMFVideoDisplayControl_Release(display_control
);
2638 IMFVideoPresenter_Release(presenter
);
2639 IMFTransform_Release(mixer
);
2640 IDirect3DDeviceManager9_Release(manager
);
2641 IDirect3DDevice9_Release(device
);
2644 DestroyWindow(window
);
2647 static void test_presenter_shutdown(void)
2649 IMFTopologyServiceLookupClient
*lookup_client
;
2650 IMFVideoDisplayControl
*display_control
;
2651 IMFVideoMediaType
*media_type
;
2652 IMFVideoPresenter
*presenter
;
2653 IMFVideoDeviceID
*deviceid
;
2654 HWND window
, window2
;
2655 IQualProp
*qual_prop
;
2663 window
= create_window();
2664 ok(!!window
, "Failed to create test window.\n");
2666 hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
);
2667 ok(hr
== S_OK
, "Failed to create default presenter, hr %#lx.\n", hr
);
2669 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFTopologyServiceLookupClient
, (void **)&lookup_client
);
2670 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2672 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDeviceID
, (void **)&deviceid
);
2673 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2675 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IMFVideoDisplayControl
, (void **)&display_control
);
2676 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2678 hr
= IMFVideoPresenter_QueryInterface(presenter
, &IID_IQualProp
, (void **)&qual_prop
);
2679 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2681 hr
= IMFTopologyServiceLookupClient_ReleaseServicePointers(lookup_client
);
2682 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2684 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_INVALIDATEMEDIATYPE
, 0);
2685 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2687 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_BEGINSTREAMING
, 0);
2688 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2690 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_ENDSTREAMING
, 0);
2691 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2693 hr
= IMFVideoPresenter_ProcessMessage(presenter
, MFVP_MESSAGE_PROCESSINPUTNOTIFY
, 0);
2694 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2696 hr
= IMFVideoPresenter_GetCurrentMediaType(presenter
, &media_type
);
2697 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2699 hr
= IMFVideoDeviceID_GetDeviceID(deviceid
, &iid
);
2700 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2702 hr
= IMFVideoDisplayControl_GetNativeVideoSize(display_control
, &size
, &size
);
2703 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2705 hr
= IMFVideoDisplayControl_GetIdealVideoSize(display_control
, &size
, &size
);
2706 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2708 SetRect(&rect
, 0, 0, 10, 10);
2709 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &rect
);
2710 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2712 hr
= IMFVideoDisplayControl_GetVideoPosition(display_control
, NULL
, &rect
);
2713 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2715 hr
= IMFVideoDisplayControl_SetAspectRatioMode(display_control
, MFVideoARMode_None
);
2716 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2718 hr
= IMFVideoDisplayControl_GetAspectRatioMode(display_control
, &mode
);
2719 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2721 hr
= IMFVideoDisplayControl_SetVideoWindow(display_control
, window
);
2722 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2724 hr
= IMFVideoDisplayControl_SetVideoPosition(display_control
, NULL
, &rect
);
2725 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2727 hr
= IMFVideoDisplayControl_GetVideoWindow(display_control
, &window2
);
2728 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2730 hr
= IMFVideoDisplayControl_RepaintVideo(display_control
);
2731 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2733 hr
= IQualProp_get_FramesDrawn(qual_prop
, NULL
);
2734 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
2736 hr
= IQualProp_get_FramesDrawn(qual_prop
, &frame_count
);
2737 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
2739 hr
= IMFTopologyServiceLookupClient_ReleaseServicePointers(lookup_client
);
2740 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2742 IQualProp_Release(qual_prop
);
2743 IMFVideoDeviceID_Release(deviceid
);
2744 IMFVideoDisplayControl_Release(display_control
);
2745 IMFTopologyServiceLookupClient_Release(lookup_client
);
2747 IMFVideoPresenter_Release(presenter
);
2749 DestroyWindow(window
);
2752 static void test_mixer_output_rectangle(void)
2754 IMFVideoMixerControl
*mixer_control
;
2755 MFVideoNormalizedRect rect
;
2756 IMFTransform
*mixer
;
2759 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
2760 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
2762 hr
= IMFTransform_QueryInterface(mixer
, &IID_IMFVideoMixerControl
, (void **)&mixer_control
);
2763 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2765 hr
= IMFVideoMixerControl_GetStreamOutputRect(mixer_control
, 0, NULL
);
2766 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2768 set_rect(&rect
, 0.0f
, 0.0f
, 0.0f
, 0.0f
);
2769 hr
= IMFVideoMixerControl_GetStreamOutputRect(mixer_control
, 0, &rect
);
2770 ok(hr
== S_OK
, "Failed to get output rect, hr %#lx.\n", hr
);
2771 ok(rect
.left
== 0.0f
&& rect
.top
== 0.0f
&& rect
.right
== 1.0f
&& rect
.bottom
== 1.0f
,
2772 "Unexpected rectangle.\n");
2774 hr
= IMFVideoMixerControl_GetStreamOutputRect(mixer_control
, 1, &rect
);
2775 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
2777 hr
= IMFVideoMixerControl_GetStreamOutputRect(mixer_control
, 1, NULL
);
2778 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2780 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 1, &rect
);
2781 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
2783 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 1, NULL
);
2784 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2787 set_rect(&rect
, 0.0f
, 0.0f
, 1.1f
, 1.0f
);
2788 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 0, &rect
);
2789 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2791 set_rect(&rect
, -0.1f
, 0.0f
, 0.5f
, 1.0f
);
2792 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 0, &rect
);
2793 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2796 set_rect(&rect
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
2797 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 0, &rect
);
2798 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2800 set_rect(&rect
, 0.0f
, 1.0f
, 1.0f
, 0.5f
);
2801 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 0, &rect
);
2802 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2804 hr
= IMFVideoMixerControl_SetStreamOutputRect(mixer_control
, 0, NULL
);
2805 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2807 IMFVideoMixerControl_Release(mixer_control
);
2808 IMFTransform_Release(mixer
);
2811 static void test_mixer_zorder(void)
2813 IMFVideoMixerControl
*mixer_control
;
2814 IMFTransform
*mixer
;
2819 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
2820 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
2822 hr
= IMFTransform_QueryInterface(mixer
, &IID_IMFVideoMixerControl
, (void **)&mixer_control
);
2823 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2825 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 0, NULL
);
2826 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2828 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 1, NULL
);
2829 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2832 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 0, &value
);
2833 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2834 ok(!value
, "Unexpected value %lu.\n", value
);
2837 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 1, &value
);
2838 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
2840 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 0, 1);
2841 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2843 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 1, 1);
2844 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2846 /* Exceeds maximum stream number. */
2847 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 0, 20);
2848 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2851 hr
= IMFTransform_AddInputStreams(mixer
, 1, &value
);
2852 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2855 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 1, &value
);
2856 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2857 ok(value
== 1, "Unexpected zorder %lu.\n", value
);
2859 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 1, 0);
2860 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
2862 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 1, 2);
2863 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2865 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 0, 0);
2866 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2869 hr
= IMFTransform_AddInputStreams(mixer
, 1, &value
);
2870 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2873 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 2, &value
);
2874 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2875 ok(value
== 2, "Unexpected zorder %lu.\n", value
);
2877 hr
= IMFVideoMixerControl_SetStreamZOrder(mixer_control
, 2, 1);
2878 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2881 hr
= IMFTransform_AddInputStreams(mixer
, 1, &value
);
2882 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2885 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 3, &value
);
2886 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2887 ok(value
== 3, "Unexpected zorder %lu.\n", value
);
2889 hr
= IMFTransform_DeleteInputStream(mixer
, 1);
2890 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2891 hr
= IMFTransform_DeleteInputStream(mixer
, 2);
2892 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2893 hr
= IMFTransform_DeleteInputStream(mixer
, 3);
2894 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2898 hr
= IMFTransform_AddInputStreams(mixer
, 2, ids
);
2899 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2902 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 1, &value
);
2903 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2904 ok(value
== 2, "Unexpected zorder %lu.\n", value
);
2907 hr
= IMFVideoMixerControl_GetStreamZOrder(mixer_control
, 2, &value
);
2908 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2909 ok(value
== 1, "Unexpected zorder %lu.\n", value
);
2911 IMFVideoMixerControl_Release(mixer_control
);
2912 IMFTransform_Release(mixer
);
2915 static IDirect3DSurface9
* create_surface(IDirect3DDeviceManager9
*manager
, unsigned int width
,
2916 unsigned int height
)
2918 IDirectXVideoAccelerationService
*service
;
2919 IDirect3DSurface9
*surface
= NULL
;
2920 IDirect3DDevice9
*device
;
2924 hr
= IDirect3DDeviceManager9_OpenDeviceHandle(manager
, &handle
);
2925 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2927 hr
= IDirect3DDeviceManager9_LockDevice(manager
, handle
, &device
, TRUE
);
2928 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2930 hr
= IDirect3DDeviceManager9_GetVideoService(manager
, handle
, &IID_IDirectXVideoProcessorService
,
2932 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2934 hr
= IDirectXVideoAccelerationService_CreateSurface(service
, width
, height
, 0, D3DFMT_A8R8G8B8
,
2935 D3DPOOL_DEFAULT
, 0, DXVA2_VideoProcessorRenderTarget
, &surface
, NULL
);
2936 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2938 IDirectXVideoAccelerationService_Release(service
);
2940 hr
= IDirect3DDevice9_ColorFill(device
, surface
, NULL
, D3DCOLOR_ARGB(0x10, 0xff, 0x00, 0x00));
2941 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2943 IDirect3DDevice9_Release(device
);
2945 hr
= IDirect3DDeviceManager9_UnlockDevice(manager
, handle
, FALSE
);
2946 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2948 hr
= IDirect3DDeviceManager9_CloseDeviceHandle(manager
, handle
);
2949 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2954 /* Format is assumed as 32bpp */
2955 static DWORD
get_surface_color(IDirect3DSurface9
*surface
, unsigned int x
, unsigned int y
)
2957 D3DLOCKED_RECT locked_rect
= { 0 };
2958 D3DSURFACE_DESC desc
;
2962 hr
= IDirect3DSurface9_GetDesc(surface
, &desc
);
2963 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2964 ok(x
< desc
.Width
&& y
< desc
.Height
, "Invalid coordinate.\n");
2965 if (x
>= desc
.Width
|| y
>= desc
.Height
) return 0;
2967 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, 0);
2968 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2970 row
= (DWORD
*)((char *)locked_rect
.pBits
+ y
* locked_rect
.Pitch
);
2973 hr
= IDirect3DSurface9_UnlockRect(surface
);
2974 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2979 static void test_mixer_samples(void)
2981 IDirect3DDeviceManager9
*manager
;
2982 MFT_OUTPUT_DATA_BUFFER buffers
[2];
2983 IMFVideoProcessor
*processor
;
2984 IDirect3DSurface9
*surface
;
2985 IMFDesiredSample
*desired
;
2986 IDirect3DDevice9
*device
;
2987 IMFMediaType
*video_type
;
2988 DWORD flags
, color
, status
;
2989 IMFTransform
*mixer
;
2990 IMFSample
*sample
, *sample2
;
2994 LONGLONG pts
, duration
;
2997 window
= create_window();
2998 if (!(device
= create_device(window
)))
3000 skip("Failed to create a D3D device, skipping tests.\n");
3004 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
3005 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
3007 hr
= IMFTransform_QueryInterface(mixer
, &IID_IMFVideoProcessor
, (void **)&processor
);
3008 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3010 hr
= IMFTransform_GetInputStatus(mixer
, 0, NULL
);
3011 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
3013 hr
= IMFTransform_GetInputStatus(mixer
, 1, NULL
);
3014 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
3016 hr
= IMFTransform_GetInputStatus(mixer
, 0, &status
);
3017 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
3019 hr
= IMFTransform_GetInputStatus(mixer
, 1, &status
);
3020 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
3022 hr
= IMFTransform_GetOutputStatus(mixer
, NULL
);
3023 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
3025 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3026 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
3028 /* Configure device and media types. */
3029 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &manager
);
3030 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3032 hr
= IDirect3DDeviceManager9_ResetDevice(manager
, device
, token
);
3033 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
3035 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_SET_D3D_MANAGER
, (ULONG_PTR
)manager
);
3036 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3038 video_type
= create_video_type(&MFVideoFormat_RGB32
);
3040 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
)640 << 32 | 480);
3041 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3042 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
3043 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3045 hr
= IMFTransform_SetInputType(mixer
, 0, video_type
, 0);
3046 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3048 hr
= IMFTransform_GetInputStatus(mixer
, 0, &status
);
3049 ok(hr
== MF_E_TRANSFORM_TYPE_NOT_SET
, "Unexpected hr %#lx.\n", hr
);
3051 hr
= IMFTransform_SetOutputType(mixer
, 0, video_type
, 0);
3052 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3055 hr
= IMFTransform_GetInputStatus(mixer
, 0, &status
);
3056 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3057 ok(status
== MFT_INPUT_STATUS_ACCEPT_DATA
, "Unexpected status %#lx.\n", status
);
3059 hr
= IMFTransform_GetInputStatus(mixer
, 1, &status
);
3060 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
3063 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3064 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3065 ok(!status
, "Unexpected status %#lx.\n", status
);
3067 IMFMediaType_Release(video_type
);
3069 memset(buffers
, 0, sizeof(buffers
));
3070 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3071 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3073 /* It needs a sample with a backing surface. */
3074 hr
= MFCreateSample(&sample
);
3075 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3077 buffers
[0].pSample
= sample
;
3078 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3079 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3081 IMFSample_Release(sample
);
3083 surface
= create_surface(manager
, 64, 64);
3085 hr
= MFCreateVideoSampleFromSurface((IUnknown
*)surface
, &sample
);
3086 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3088 hr
= IMFSample_QueryInterface(sample
, &IID_IMFDesiredSample
, (void **)&desired
);
3089 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3091 buffers
[0].pSample
= sample
;
3092 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3093 ok(hr
== MF_E_TRANSFORM_NEED_MORE_INPUT
, "Unexpected hr %#lx.\n", hr
);
3095 color
= get_surface_color(surface
, 0, 0);
3096 ok(color
== D3DCOLOR_ARGB(0x10, 0xff, 0x00, 0x00), "Unexpected color %#lx.\n", color
);
3098 /* Streaming is not started yet. Output is colored black, but only if desired timestamps were set. */
3099 IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired
, 100, 0);
3101 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3102 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3104 color
= get_surface_color(surface
, 0, 0);
3105 ok(!color
, "Unexpected color %#lx.\n", color
);
3107 hr
= IMFVideoProcessor_SetBackgroundColor(processor
, RGB(0, 0, 255));
3108 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3110 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3111 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3113 color
= get_surface_color(surface
, 0, 0);
3114 ok(!color
, "Unexpected color %#lx.\n", color
);
3116 hr
= IMFTransform_ProcessOutput(mixer
, 0, 2, buffers
, &status
);
3117 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3119 buffers
[1].pSample
= sample
;
3120 hr
= IMFTransform_ProcessOutput(mixer
, 0, 2, buffers
, &status
);
3121 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3123 buffers
[0].dwStreamID
= 1;
3124 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3125 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
3127 IMFDesiredSample_Clear(desired
);
3128 IMFDesiredSample_Release(desired
);
3130 hr
= IMFTransform_ProcessInput(mixer
, 0, NULL
, 0);
3131 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
3133 hr
= IMFTransform_ProcessInput(mixer
, 5, NULL
, 0);
3134 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
3137 hr
= IMFTransform_GetInputStatus(mixer
, 0, &status
);
3138 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3139 ok(status
== MFT_INPUT_STATUS_ACCEPT_DATA
, "Unexpected status %#lx.\n", status
);
3142 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3143 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3144 ok(!status
, "Unexpected status %#lx.\n", status
);
3146 hr
= IMFTransform_ProcessInput(mixer
, 0, sample
, 0);
3147 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3150 hr
= IMFTransform_GetInputStatus(mixer
, 0, &status
);
3151 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3152 ok(!status
, "Unexpected status %#lx.\n", status
);
3154 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3155 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3156 ok(status
== MFT_OUTPUT_STATUS_SAMPLE_READY
, "Unexpected status %#lx.\n", status
);
3158 hr
= IMFTransform_ProcessInput(mixer
, 0, sample
, 0);
3159 ok(hr
== MF_E_NOTACCEPTING
, "Unexpected hr %#lx.\n", hr
);
3161 hr
= IMFTransform_ProcessInput(mixer
, 5, sample
, 0);
3162 ok(hr
== MF_E_INVALIDSTREAMNUMBER
, "Unexpected hr %#lx.\n", hr
);
3164 /* ProcessOutput() sets sample time and duration. */
3165 hr
= MFCreateVideoSampleFromSurface((IUnknown
*)surface
, &sample2
);
3166 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3168 hr
= IMFSample_SetUINT32(sample2
, &IID_IMFSample
, 1);
3169 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3171 hr
= IMFSample_SetSampleFlags(sample2
, 0x123);
3172 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3174 hr
= IMFSample_GetSampleTime(sample2
, &pts
);
3175 ok(hr
== MF_E_NO_SAMPLE_TIMESTAMP
, "Unexpected hr %#lx.\n", hr
);
3177 hr
= IMFSample_GetSampleDuration(sample2
, &duration
);
3178 ok(hr
== MF_E_NO_SAMPLE_DURATION
, "Unexpected hr %#lx.\n", hr
);
3180 hr
= IMFSample_SetSampleTime(sample
, 0);
3181 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3183 hr
= IMFSample_SetSampleDuration(sample
, 0);
3184 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3186 memset(buffers
, 0, sizeof(buffers
));
3187 buffers
[0].pSample
= sample2
;
3188 hr
= IMFTransform_ProcessOutput(mixer
, 0, 1, buffers
, &status
);
3189 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3191 hr
= IMFSample_GetSampleTime(sample2
, &pts
);
3192 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3193 ok(!pts
, "Unexpected sample time.\n");
3195 hr
= IMFSample_GetSampleDuration(sample2
, &duration
);
3196 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3197 ok(!duration
, "Unexpected duration\n");
3199 /* Flags are not copied. */
3200 hr
= IMFSample_GetSampleFlags(sample2
, &flags
);
3201 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3202 ok(flags
== 0x123, "Unexpected flags %#lx.\n", flags
);
3204 /* Attributes are not removed. */
3205 hr
= IMFSample_GetCount(sample2
, &count
);
3206 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3207 ok(count
== 1, "Unexpected attribute count %u.\n", count
);
3209 hr
= IMFSample_GetCount(sample
, &count
);
3210 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3211 ok(!count
, "Unexpected attribute count %u.\n", count
);
3213 IMFSample_Release(sample2
);
3215 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_COMMAND_DRAIN
, 0);
3216 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3218 IMFSample_Release(sample
);
3220 IDirect3DSurface9_Release(surface
);
3222 IMFVideoProcessor_Release(processor
);
3223 IMFTransform_Release(mixer
);
3225 IDirect3DDeviceManager9_Release(manager
);
3226 ok(!IDirect3DDevice9_Release(device
), "Unexpected refcount.\n");
3229 DestroyWindow(window
);
3232 static void test_MFIsFormatYUV(void)
3234 static const DWORD formats
[] =
3238 MAKEFOURCC('A','Y','U','V'),
3239 MAKEFOURCC('I','M','C','1'),
3240 MAKEFOURCC('I','M','C','2'),
3241 MAKEFOURCC('Y','V','1','2'),
3242 MAKEFOURCC('N','V','1','1'),
3243 MAKEFOURCC('N','V','1','2'),
3244 MAKEFOURCC('Y','2','1','0'),
3245 MAKEFOURCC('Y','2','1','6'),
3247 static const DWORD unsupported_formats
[] =
3250 MAKEFOURCC('I','Y','U','V'),
3251 MAKEFOURCC('I','4','2','0'),
3252 MAKEFOURCC('Y','V','Y','U'),
3253 MAKEFOURCC('Y','V','U','9'),
3254 MAKEFOURCC('Y','4','1','0'),
3255 MAKEFOURCC('Y','4','1','6'),
3260 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
3262 ret
= MFIsFormatYUV(formats
[i
]);
3263 ok(ret
, "Unexpected ret %d, format %s.\n", ret
, debugstr_an((char *)&formats
[i
], 4));
3266 for (i
= 0; i
< ARRAY_SIZE(unsupported_formats
); ++i
)
3268 ret
= MFIsFormatYUV(unsupported_formats
[i
]);
3269 ok(!ret
, "Unexpected ret %d, format %s.\n", ret
, debugstr_an((char *)&unsupported_formats
[i
], 4));
3273 static void test_mixer_render(void)
3275 IMFMediaType
*video_type
, *output_type
;
3276 IMFVideoMixerControl
*mixer_control
;
3277 IDirect3DDeviceManager9
*manager
;
3278 IMFVideoProcessor
*processor
;
3279 IDirect3DSurface9
*surface
;
3280 IDirect3DDevice9
*device
;
3281 IMFTransform
*mixer
;
3288 window
= create_window();
3289 if (!(device
= create_device(window
)))
3291 skip("Failed to create a D3D device, skipping tests.\n");
3295 hr
= MFCreateVideoMixer(NULL
, &IID_IDirect3DDevice9
, &IID_IMFTransform
, (void **)&mixer
);
3296 ok(hr
== S_OK
, "Failed to create a mixer, hr %#lx.\n", hr
);
3298 hr
= IMFTransform_QueryInterface(mixer
, &IID_IMFVideoProcessor
, (void **)&processor
);
3299 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3300 IMFVideoProcessor_Release(processor
);
3302 hr
= IMFTransform_QueryInterface(mixer
, &IID_IMFVideoMixerControl
, (void **)&mixer_control
);
3303 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3304 IMFVideoMixerControl_Release(mixer_control
);
3306 /* Configure device and media types. */
3307 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &manager
);
3308 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3310 hr
= IDirect3DDeviceManager9_ResetDevice(manager
, device
, token
);
3311 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
3313 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_SET_D3D_MANAGER
, (ULONG_PTR
)manager
);
3314 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3316 video_type
= create_video_type(&MFVideoFormat_RGB32
);
3318 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
)64 << 32 | 64);
3319 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3320 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, TRUE
);
3321 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3323 hr
= IMFTransform_SetInputType(mixer
, 0, video_type
, 0);
3324 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3326 hr
= IMFTransform_GetOutputAvailableType(mixer
, 0, 0, &output_type
);
3327 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3329 hr
= IMFTransform_SetOutputType(mixer
, 0, output_type
, 0);
3330 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3332 IMFMediaType_Release(output_type
);
3333 IMFMediaType_Release(video_type
);
3335 surface
= create_surface(manager
, 64, 64);
3336 ok(!!surface
, "Failed to create input surface.\n");
3338 hr
= MFCreateVideoSampleFromSurface((IUnknown
*)surface
, &sample
);
3339 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3341 EXPECT_REF(sample
, 1);
3342 hr
= IMFTransform_ProcessInput(mixer
, 0, sample
, 0);
3343 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3344 EXPECT_REF(sample
, 2);
3346 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3347 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3348 ok(status
== MFT_OUTPUT_STATUS_SAMPLE_READY
, "Unexpected status %#lx.\n", status
);
3350 /* FLUSH/END_STREAMING releases input */
3351 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_NOTIFY_END_STREAMING
, 0);
3352 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3353 EXPECT_REF(sample
, 1);
3355 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3356 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3357 ok(!status
, "Unexpected status %#lx.\n", status
);
3359 hr
= IMFTransform_ProcessInput(mixer
, 0, sample
, 0);
3360 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3361 EXPECT_REF(sample
, 2);
3363 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3364 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3365 ok(status
== MFT_OUTPUT_STATUS_SAMPLE_READY
, "Unexpected status %#lx.\n", status
);
3367 hr
= IMFTransform_ProcessMessage(mixer
, MFT_MESSAGE_COMMAND_FLUSH
, 0);
3368 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3369 EXPECT_REF(sample
, 1);
3371 hr
= IMFTransform_GetOutputStatus(mixer
, &status
);
3372 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3373 ok(!status
, "Unexpected status %#lx.\n", status
);
3375 IMFSample_Release(sample
);
3376 IDirect3DSurface9_Release(surface
);
3377 IMFTransform_Release(mixer
);
3379 IDirect3DDeviceManager9_Release(manager
);
3380 ok(!IDirect3DDevice9_Release(device
), "Unexpected refcount.\n");
3383 DestroyWindow(window
);
3388 IMFVideoPresenter
*presenter
;
3393 if (FAILED(hr
= MFCreateVideoPresenter(NULL
, &IID_IDirect3DDevice9
, &IID_IMFVideoPresenter
, (void **)&presenter
)))
3395 win_skip("Failed to create default presenter, hr %#lx. Skipping tests.\n", hr
);
3399 IMFVideoPresenter_Release(presenter
);
3406 test_unconnected_eos();
3408 test_display_control();
3409 test_service_lookup();
3410 test_query_accept();
3412 test_default_mixer();
3413 test_default_mixer_type_negotiation();
3414 test_surface_sample();
3415 test_default_presenter();
3416 test_MFCreateVideoMixerAndPresenter();
3417 test_MFCreateVideoSampleAllocator();
3418 test_presenter_video_position();
3419 test_presenter_native_video_size();
3420 test_presenter_ar_mode();
3421 test_presenter_video_window();
3422 test_presenter_quality_control();
3423 test_presenter_media_type();
3424 test_presenter_shutdown();
3425 test_mixer_output_rectangle();
3426 test_mixer_zorder();
3427 test_mixer_samples();
3428 test_mixer_render();
3429 test_MFIsFormatYUV();