2 * Unit test suite for mfplat.
4 * Copyright 2015 Michael Müller
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
35 #include "mfreadwrite.h"
36 #include "propvarutil.h"
40 #include "wine/test.h"
42 #define D3D11_INIT_GUID
46 #include "d3d9types.h"
52 #define EXTERN_GUID DEFINE_GUID
55 DEFINE_GUID(DUMMY_CLSID
, 0x12345678,0x1234,0x1234,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19);
56 DEFINE_GUID(DUMMY_GUID1
, 0x12345678,0x1234,0x1234,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21);
57 DEFINE_GUID(DUMMY_GUID2
, 0x12345678,0x1234,0x1234,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22);
58 DEFINE_GUID(DUMMY_GUID3
, 0x12345678,0x1234,0x1234,0x23,0x23,0x23,0x23,0x23,0x23,0x23,0x23);
60 extern const CLSID CLSID_FileSchemePlugin
;
62 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC1
, MAKEFOURCC('I','M','C','1'));
63 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC2
, MAKEFOURCC('I','M','C','2'));
64 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC3
, MAKEFOURCC('I','M','C','3'));
65 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC4
, MAKEFOURCC('I','M','C','4'));
67 static BOOL is_win8_plus
;
69 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
70 static void _expect_ref(IUnknown
*obj
, ULONG ref
, int line
)
74 rc
= IUnknown_Release(obj
);
75 ok_(__FILE__
,line
)(rc
== ref
, "Unexpected refcount %ld, expected %ld.\n", rc
, ref
);
78 static ULONG
get_refcount(void *iface
)
80 IUnknown
*unknown
= iface
;
81 IUnknown_AddRef(unknown
);
82 return IUnknown_Release(unknown
);
85 #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
86 static void check_interface_(unsigned int line
, void *iface_ptr
, REFIID iid
, BOOL supported
)
88 IUnknown
*iface
= iface_ptr
;
89 HRESULT hr
, expected_hr
;
92 expected_hr
= supported
? S_OK
: E_NOINTERFACE
;
94 hr
= IUnknown_QueryInterface(iface
, iid
, (void **)&unk
);
95 ok_(__FILE__
, line
)(hr
== expected_hr
, "Got hr %#lx, expected %#lx.\n", hr
, expected_hr
);
97 IUnknown_Release(unk
);
100 #define check_service_interface(a, b, c, d) check_service_interface_(__LINE__, a, b, c, d)
101 static void check_service_interface_(unsigned int line
, void *iface_ptr
, REFGUID service
, REFIID iid
, BOOL supported
)
103 IUnknown
*iface
= iface_ptr
;
104 HRESULT hr
, expected_hr
;
108 expected_hr
= supported
? S_OK
: E_NOINTERFACE
;
110 if (SUCCEEDED(hr
= IUnknown_QueryInterface(iface
, &IID_IMFGetService
, (void **)&gs
)))
112 hr
= IMFGetService_GetService(gs
, service
, iid
, (void **)&unk
);
113 IMFGetService_Release(gs
);
115 ok_(__FILE__
, line
)(hr
== expected_hr
, "Got hr %#lx, expected %#lx.\n", hr
, expected_hr
);
117 IUnknown_Release(unk
);
120 struct d3d11_resource_readback
122 ID3D11Resource
*resource
;
123 D3D11_MAPPED_SUBRESOURCE map_desc
;
124 ID3D11DeviceContext
*immediate_context
;
125 unsigned int width
, height
, depth
, sub_resource_idx
;
128 static void init_d3d11_resource_readback(ID3D11Resource
*resource
, ID3D11Resource
*readback_resource
,
129 unsigned int width
, unsigned int height
, unsigned int depth
, unsigned int sub_resource_idx
,
130 ID3D11Device
*device
, struct d3d11_resource_readback
*rb
)
134 rb
->resource
= readback_resource
;
138 rb
->sub_resource_idx
= sub_resource_idx
;
140 ID3D11Device_GetImmediateContext(device
, &rb
->immediate_context
);
142 ID3D11DeviceContext_CopyResource(rb
->immediate_context
, rb
->resource
, resource
);
143 if (FAILED(hr
= ID3D11DeviceContext_Map(rb
->immediate_context
,
144 rb
->resource
, sub_resource_idx
, D3D11_MAP_READ
, 0, &rb
->map_desc
)))
146 trace("Failed to map resource, hr %#lx.\n", hr
);
147 ID3D11Resource_Release(rb
->resource
);
149 ID3D11DeviceContext_Release(rb
->immediate_context
);
150 rb
->immediate_context
= NULL
;
154 static void get_d3d11_texture2d_readback(ID3D11Texture2D
*texture
, unsigned int sub_resource_idx
,
155 struct d3d11_resource_readback
*rb
)
157 D3D11_TEXTURE2D_DESC texture_desc
;
158 ID3D11Resource
*rb_texture
;
159 unsigned int miplevel
;
160 ID3D11Device
*device
;
163 memset(rb
, 0, sizeof(*rb
));
165 ID3D11Texture2D_GetDevice(texture
, &device
);
167 ID3D11Texture2D_GetDesc(texture
, &texture_desc
);
168 texture_desc
.Usage
= D3D11_USAGE_STAGING
;
169 texture_desc
.BindFlags
= 0;
170 texture_desc
.CPUAccessFlags
= D3D11_CPU_ACCESS_READ
;
171 texture_desc
.MiscFlags
= 0;
172 if (FAILED(hr
= ID3D11Device_CreateTexture2D(device
, &texture_desc
, NULL
, (ID3D11Texture2D
**)&rb_texture
)))
174 trace("Failed to create texture, hr %#lx.\n", hr
);
175 ID3D11Device_Release(device
);
179 miplevel
= sub_resource_idx
% texture_desc
.MipLevels
;
180 init_d3d11_resource_readback((ID3D11Resource
*)texture
, rb_texture
,
181 max(1, texture_desc
.Width
>> miplevel
),
182 max(1, texture_desc
.Height
>> miplevel
),
183 1, sub_resource_idx
, device
, rb
);
185 ID3D11Device_Release(device
);
188 static void release_d3d11_resource_readback(struct d3d11_resource_readback
*rb
)
190 ID3D11DeviceContext_Unmap(rb
->immediate_context
, rb
->resource
, rb
->sub_resource_idx
);
191 ID3D11Resource_Release(rb
->resource
);
192 ID3D11DeviceContext_Release(rb
->immediate_context
);
195 static void *get_d3d11_readback_data(struct d3d11_resource_readback
*rb
,
196 unsigned int x
, unsigned int y
, unsigned int z
, unsigned byte_width
)
198 return (BYTE
*)rb
->map_desc
.pData
+ z
* rb
->map_desc
.DepthPitch
+ y
* rb
->map_desc
.RowPitch
+ x
* byte_width
;
201 static DWORD
get_d3d11_readback_u32(struct d3d11_resource_readback
*rb
, unsigned int x
, unsigned int y
, unsigned int z
)
203 return *(DWORD
*)get_d3d11_readback_data(rb
, x
, y
, z
, sizeof(DWORD
));
206 static DWORD
get_d3d11_readback_color(struct d3d11_resource_readback
*rb
, unsigned int x
, unsigned int y
, unsigned int z
)
208 return get_d3d11_readback_u32(rb
, x
, y
, z
);
211 static DWORD
get_d3d11_texture_color(ID3D11Texture2D
*texture
, unsigned int x
, unsigned int y
)
213 struct d3d11_resource_readback rb
;
216 get_d3d11_texture2d_readback(texture
, 0, &rb
);
217 color
= get_d3d11_readback_color(&rb
, x
, y
, 0);
218 release_d3d11_resource_readback(&rb
);
223 static HRESULT (WINAPI
*pD3D11CreateDevice
)(IDXGIAdapter
*adapter
, D3D_DRIVER_TYPE driver_type
, HMODULE swrast
, UINT flags
,
224 const D3D_FEATURE_LEVEL
*feature_levels
, UINT levels
, UINT sdk_version
, ID3D11Device
**device_out
,
225 D3D_FEATURE_LEVEL
*obtained_feature_level
, ID3D11DeviceContext
**immediate_context
);
226 static HRESULT (WINAPI
*pD3D12CreateDevice
)(IUnknown
*adapter
, D3D_FEATURE_LEVEL minimum_feature_level
,
227 REFIID iid
, void **device
);
229 static HRESULT (WINAPI
*pCoGetApartmentType
)(APTTYPE
*type
, APTTYPEQUALIFIER
*qualifier
);
231 static HRESULT (WINAPI
*pMFCopyImage
)(BYTE
*dest
, LONG deststride
, const BYTE
*src
, LONG srcstride
,
232 DWORD width
, DWORD lines
);
233 static HRESULT (WINAPI
*pMFCreateDXGIDeviceManager
)(UINT
*token
, IMFDXGIDeviceManager
**manager
);
234 static HRESULT (WINAPI
*pMFCreateSourceResolver
)(IMFSourceResolver
**resolver
);
235 static HRESULT (WINAPI
*pMFCreateMFByteStreamOnStream
)(IStream
*stream
, IMFByteStream
**bytestream
);
236 static HRESULT (WINAPI
*pMFPutWaitingWorkItem
)(HANDLE event
, LONG priority
, IMFAsyncResult
*result
, MFWORKITEM_KEY
*key
);
237 static HRESULT (WINAPI
*pMFAllocateSerialWorkQueue
)(DWORD queue
, DWORD
*serial_queue
);
238 static HRESULT (WINAPI
*pMFAddPeriodicCallback
)(MFPERIODICCALLBACK callback
, IUnknown
*context
, DWORD
*key
);
239 static HRESULT (WINAPI
*pMFRemovePeriodicCallback
)(DWORD key
);
240 static HRESULT (WINAPI
*pMFRegisterLocalByteStreamHandler
)(const WCHAR
*extension
, const WCHAR
*mime
,
241 IMFActivate
*activate
);
242 static HRESULT (WINAPI
*pMFRegisterLocalSchemeHandler
)(const WCHAR
*scheme
, IMFActivate
*activate
);
243 static HRESULT (WINAPI
*pMFCreateTransformActivate
)(IMFActivate
**activate
);
244 static HRESULT (WINAPI
*pMFTRegisterLocal
)(IClassFactory
*factory
, REFGUID category
, LPCWSTR name
,
245 UINT32 flags
, UINT32 cinput
, const MFT_REGISTER_TYPE_INFO
*input_types
, UINT32 coutput
,
246 const MFT_REGISTER_TYPE_INFO
* output_types
);
247 static HRESULT (WINAPI
*pMFTRegisterLocalByCLSID
)(REFCLSID clsid
, REFGUID category
, LPCWSTR name
, UINT32 flags
,
248 UINT32 input_count
, const MFT_REGISTER_TYPE_INFO
*input_types
, UINT32 output_count
,
249 const MFT_REGISTER_TYPE_INFO
*output_types
);
250 static HRESULT (WINAPI
*pMFTUnregisterLocal
)(IClassFactory
*factory
);
251 static HRESULT (WINAPI
*pMFTUnregisterLocalByCLSID
)(CLSID clsid
);
252 static HRESULT (WINAPI
*pMFAllocateWorkQueueEx
)(MFASYNC_WORKQUEUE_TYPE queue_type
, DWORD
*queue
);
253 static HRESULT (WINAPI
*pMFTEnumEx
)(GUID category
, UINT32 flags
, const MFT_REGISTER_TYPE_INFO
*input_type
,
254 const MFT_REGISTER_TYPE_INFO
*output_type
, IMFActivate
***activate
, UINT32
*count
);
255 static HRESULT (WINAPI
*pMFGetPlaneSize
)(DWORD format
, DWORD width
, DWORD height
, DWORD
*size
);
256 static HRESULT (WINAPI
*pMFGetStrideForBitmapInfoHeader
)(DWORD format
, DWORD width
, LONG
*stride
);
257 static HRESULT (WINAPI
*pMFCreate2DMediaBuffer
)(DWORD width
, DWORD height
, DWORD fourcc
, BOOL bottom_up
,
258 IMFMediaBuffer
**buffer
);
259 static HRESULT (WINAPI
*pMFCreateMediaBufferFromMediaType
)(IMFMediaType
*media_type
, LONGLONG duration
, DWORD min_length
,
260 DWORD min_alignment
, IMFMediaBuffer
**buffer
);
261 static HRESULT (WINAPI
*pMFCreateDXSurfaceBuffer
)(REFIID riid
, IUnknown
*surface
, BOOL bottom_up
, IMFMediaBuffer
**buffer
);
262 static HRESULT (WINAPI
*pMFCreateTrackedSample
)(IMFTrackedSample
**sample
);
263 static DWORD (WINAPI
*pMFMapDXGIFormatToDX9Format
)(DXGI_FORMAT dxgi_format
);
264 static DXGI_FORMAT (WINAPI
*pMFMapDX9FormatToDXGIFormat
)(DWORD format
);
265 static HRESULT (WINAPI
*pMFCreateVideoSampleAllocatorEx
)(REFIID riid
, void **allocator
);
266 static HRESULT (WINAPI
*pMFCreateDXGISurfaceBuffer
)(REFIID riid
, IUnknown
*surface
, UINT subresource
, BOOL bottomup
,
267 IMFMediaBuffer
**buffer
);
268 static HRESULT (WINAPI
*pMFCreateVideoMediaTypeFromSubtype
)(const GUID
*subtype
, IMFVideoMediaType
**media_type
);
269 static HRESULT (WINAPI
*pMFLockSharedWorkQueue
)(const WCHAR
*name
, LONG base_priority
, DWORD
*taskid
, DWORD
*queue
);
270 static HRESULT (WINAPI
*pMFLockDXGIDeviceManager
)(UINT
*token
, IMFDXGIDeviceManager
**manager
);
271 static HRESULT (WINAPI
*pMFUnlockDXGIDeviceManager
)(void);
272 static HRESULT (WINAPI
*pMFInitVideoFormat_RGB
)(MFVIDEOFORMAT
*format
, DWORD width
, DWORD height
, DWORD d3dformat
);
274 static HWND
create_window(void)
276 RECT r
= {0, 0, 640, 480};
278 AdjustWindowRect(&r
, WS_OVERLAPPEDWINDOW
| WS_VISIBLE
, FALSE
);
280 return CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
281 0, 0, r
.right
- r
.left
, r
.bottom
- r
.top
, NULL
, NULL
, NULL
, NULL
);
284 static IDirect3DDevice9
*create_d3d9_device(IDirect3D9
*d3d9
, HWND focus_window
)
286 D3DPRESENT_PARAMETERS present_parameters
= {0};
287 IDirect3DDevice9
*device
= NULL
;
289 present_parameters
.BackBufferWidth
= 640;
290 present_parameters
.BackBufferHeight
= 480;
291 present_parameters
.BackBufferFormat
= D3DFMT_A8R8G8B8
;
292 present_parameters
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
293 present_parameters
.hDeviceWindow
= focus_window
;
294 present_parameters
.Windowed
= TRUE
;
295 present_parameters
.EnableAutoDepthStencil
= TRUE
;
296 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D24S8
;
297 present_parameters
.Flags
= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
;
299 IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, focus_window
,
300 D3DCREATE_HARDWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
305 static const WCHAR fileschemeW
[] = L
"file://";
307 static WCHAR
*load_resource(const WCHAR
*name
)
309 static WCHAR pathW
[MAX_PATH
];
315 GetTempPathW(ARRAY_SIZE(pathW
), pathW
);
316 lstrcatW(pathW
, name
);
318 file
= CreateFileW(pathW
, GENERIC_READ
|GENERIC_WRITE
, 0,
319 NULL
, CREATE_ALWAYS
, 0, 0);
320 ok(file
!= INVALID_HANDLE_VALUE
, "file creation failed, at %s, error %ld\n",
321 wine_dbgstr_w(pathW
), GetLastError());
323 res
= FindResourceW(NULL
, name
, (LPCWSTR
)RT_RCDATA
);
324 ok(res
!= 0, "couldn't find resource\n");
325 ptr
= LockResource(LoadResource(GetModuleHandleA(NULL
), res
));
326 WriteFile(file
, ptr
, SizeofResource(GetModuleHandleA(NULL
), res
),
328 ok(written
== SizeofResource(GetModuleHandleA(NULL
), res
),
329 "couldn't write resource\n" );
337 IMFAsyncCallback IMFAsyncCallback_iface
;
341 IMFMediaEvent
*media_event
;
344 static struct test_callback
*impl_from_IMFAsyncCallback(IMFAsyncCallback
*iface
)
346 return CONTAINING_RECORD(iface
, struct test_callback
, IMFAsyncCallback_iface
);
349 static HRESULT WINAPI
testcallback_QueryInterface(IMFAsyncCallback
*iface
, REFIID riid
, void **obj
)
351 if (IsEqualIID(riid
, &IID_IMFAsyncCallback
) ||
352 IsEqualIID(riid
, &IID_IUnknown
))
355 IMFAsyncCallback_AddRef(iface
);
360 return E_NOINTERFACE
;
363 static ULONG WINAPI
testcallback_AddRef(IMFAsyncCallback
*iface
)
365 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
366 return InterlockedIncrement(&callback
->refcount
);
369 static ULONG WINAPI
testcallback_Release(IMFAsyncCallback
*iface
)
371 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
372 ULONG refcount
= InterlockedDecrement(&callback
->refcount
);
380 static HRESULT WINAPI
testcallback_GetParameters(IMFAsyncCallback
*iface
, DWORD
*flags
, DWORD
*queue
)
382 ok(flags
!= NULL
&& queue
!= NULL
, "Unexpected arguments.\n");
386 static BOOL
check_clsid(CLSID
*clsids
, UINT32 count
)
389 for (i
= 0; i
< count
; i
++)
391 if (IsEqualGUID(&clsids
[i
], &DUMMY_CLSID
))
397 static void test_register(void)
399 MFT_REGISTER_TYPE_INFO
*in_types
, *out_types
;
400 WCHAR name
[] = L
"Wine test";
401 MFT_REGISTER_TYPE_INFO input
[] =
403 { DUMMY_CLSID
, DUMMY_GUID1
}
405 MFT_REGISTER_TYPE_INFO output
[] =
407 { DUMMY_CLSID
, DUMMY_GUID2
}
409 UINT32 count
, in_count
, out_count
;
410 IMFAttributes
*attributes
;
415 ret
= MFTRegister(DUMMY_CLSID
, MFT_CATEGORY_OTHER
, name
, 0, 1, input
, 1, output
, NULL
);
416 if (ret
== E_ACCESSDENIED
)
418 win_skip("Not enough permissions to register a transform.\n");
421 ok(ret
== S_OK
, "Failed to register dummy transform, hr %#lx.\n", ret
);
425 /* NULL name crashes on windows */
426 ret
= MFTRegister(DUMMY_CLSID
, MFT_CATEGORY_OTHER
, NULL
, 0, 1, input
, 1, output
, NULL
);
427 ok(ret
== E_INVALIDARG
, "Unexpected hr %#lx.\n", ret
);
430 ret
= MFTRegister(DUMMY_CLSID
, MFT_CATEGORY_OTHER
, name
, 0, 0, NULL
, 0, NULL
, NULL
);
431 ok(ret
== S_OK
, "Failed to register dummy filter: %lx\n", ret
);
433 ret
= MFTRegister(DUMMY_CLSID
, MFT_CATEGORY_OTHER
, name
, 0, 1, NULL
, 0, NULL
, NULL
);
434 ok(ret
== S_OK
, "Failed to register dummy filter: %lx\n", ret
);
436 ret
= MFTRegister(DUMMY_CLSID
, MFT_CATEGORY_OTHER
, name
, 0, 0, NULL
, 1, NULL
, NULL
);
437 ok(ret
== S_OK
, "Failed to register dummy filter: %lx\n", ret
);
441 /* NULL clsids/count crashes on windows (vista) */
443 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, NULL
, NULL
, NULL
, NULL
, &count
);
444 ok(ret
== E_POINTER
, "Failed to enumerate filters: %lx\n", ret
);
445 ok(count
== 0, "Expected count == 0\n");
448 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, NULL
, NULL
, NULL
, &clsids
, NULL
);
449 ok(ret
== E_POINTER
, "Failed to enumerate filters: %lx\n", ret
);
451 hr
= MFTGetInfo(DUMMY_CLSID
, &mft_name
, NULL
, NULL
, NULL
, NULL
, NULL
);
452 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
453 ok(!lstrcmpW(mft_name
, L
"Wine test"), "Unexpected name %s.\n", wine_dbgstr_w(mft_name
));
454 CoTaskMemFree(mft_name
);
456 hr
= MFTGetInfo(DUMMY_CLSID
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
457 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
459 in_count
= out_count
= 1;
460 hr
= MFTGetInfo(DUMMY_CLSID
, NULL
, NULL
, &in_count
, NULL
, &out_count
, NULL
);
461 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
462 ok(!in_count
, "Unexpected count %u.\n", in_count
);
463 ok(!out_count
, "Unexpected count %u.\n", out_count
);
465 hr
= MFTGetInfo(DUMMY_CLSID
, NULL
, NULL
, NULL
, NULL
, NULL
, &attributes
);
466 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
467 ok(!!attributes
, "Unexpected attributes.\n");
468 IMFAttributes_Release(attributes
);
470 hr
= MFTGetInfo(DUMMY_CLSID
, &mft_name
, &in_types
, &in_count
, &out_types
, &out_count
, &attributes
);
471 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
472 ok(!lstrcmpW(mft_name
, L
"Wine test"), "Unexpected name %s.\n", wine_dbgstr_w(mft_name
));
473 ok(!!in_types
, "Unexpected pointer.\n");
474 ok(!!out_types
, "Unexpected pointer.\n");
475 ok(in_count
== 1, "Unexpected count %u.\n", in_count
);
476 ok(out_count
== 1, "Unexpected count %u.\n", out_count
);
477 ok(IsEqualGUID(&in_types
->guidMajorType
, &DUMMY_CLSID
), "Unexpected type guid %s.\n",
478 wine_dbgstr_guid(&in_types
->guidMajorType
));
479 ok(IsEqualGUID(&in_types
->guidSubtype
, &DUMMY_GUID1
), "Unexpected type guid %s.\n",
480 wine_dbgstr_guid(&in_types
->guidSubtype
));
481 ok(IsEqualGUID(&out_types
->guidMajorType
, &DUMMY_CLSID
), "Unexpected type guid %s.\n",
482 wine_dbgstr_guid(&out_types
->guidMajorType
));
483 ok(IsEqualGUID(&out_types
->guidSubtype
, &DUMMY_GUID2
), "Unexpected type guid %s.\n",
484 wine_dbgstr_guid(&out_types
->guidSubtype
));
485 ok(!!attributes
, "Unexpected attributes.\n");
487 hr
= IMFAttributes_GetCount(attributes
, &count
);
488 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
489 ok(!count
, "Unexpected count %u.\n", count
);
490 CoTaskMemFree(mft_name
);
491 CoTaskMemFree(in_types
);
492 CoTaskMemFree(out_types
);
493 IMFAttributes_Release(attributes
);
497 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, NULL
, NULL
, NULL
, &clsids
, &count
);
498 ok(ret
== S_OK
, "Failed to enumerate filters: %lx\n", ret
);
499 ok(count
> 0, "Expected count > 0\n");
500 ok(clsids
!= NULL
, "Expected clsids != NULL\n");
501 ok(check_clsid(clsids
, count
), "Filter was not part of enumeration\n");
502 CoTaskMemFree(clsids
);
506 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, input
, NULL
, NULL
, &clsids
, &count
);
507 ok(ret
== S_OK
, "Failed to enumerate filters: %lx\n", ret
);
508 ok(count
> 0, "Expected count > 0\n");
509 ok(clsids
!= NULL
, "Expected clsids != NULL\n");
510 ok(check_clsid(clsids
, count
), "Filter was not part of enumeration\n");
511 CoTaskMemFree(clsids
);
515 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, NULL
, output
, NULL
, &clsids
, &count
);
516 ok(ret
== S_OK
, "Failed to enumerate filters: %lx\n", ret
);
517 ok(count
> 0, "Expected count > 0\n");
518 ok(clsids
!= NULL
, "Expected clsids != NULL\n");
519 ok(check_clsid(clsids
, count
), "Filter was not part of enumeration\n");
520 CoTaskMemFree(clsids
);
524 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, input
, output
, NULL
, &clsids
, &count
);
525 ok(ret
== S_OK
, "Failed to enumerate filters: %lx\n", ret
);
526 ok(count
> 0, "Expected count > 0\n");
527 ok(clsids
!= NULL
, "Expected clsids != NULL\n");
528 ok(check_clsid(clsids
, count
), "Filter was not part of enumeration\n");
529 CoTaskMemFree(clsids
);
531 /* exchange input and output */
534 ret
= MFTEnum(MFT_CATEGORY_OTHER
, 0, output
, input
, NULL
, &clsids
, &count
);
535 ok(ret
== S_OK
, "Failed to enumerate filters: %lx\n", ret
);
536 ok(!count
, "got %d\n", count
);
537 ok(clsids
== NULL
, "Expected clsids == NULL\n");
539 ret
= MFTUnregister(DUMMY_CLSID
);
542 broken(ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)), "Unexpected hr %#lx.\n", ret
);
544 ret
= MFTUnregister(DUMMY_CLSID
);
545 ok(ret
== S_OK
|| broken(ret
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)), "Unexpected hr %#lx.\n", ret
);
548 static HRESULT WINAPI
test_create_from_url_callback_Invoke(IMFAsyncCallback
*iface
, IMFAsyncResult
*result
)
550 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
551 IMFSourceResolver
*resolver
;
552 IUnknown
*object
, *object2
;
553 MF_OBJECT_TYPE obj_type
;
556 ok(!!result
, "Unexpected result object.\n");
558 resolver
= (IMFSourceResolver
*)IMFAsyncResult_GetStateNoAddRef(result
);
561 hr
= IMFSourceResolver_EndCreateObjectFromURL(resolver
, result
, &obj_type
, &object
);
562 ok(hr
== S_OK
, "Failed to create an object, hr %#lx.\n", hr
);
564 hr
= IMFAsyncResult_GetObject(result
, &object2
);
565 ok(hr
== S_OK
, "Failed to get result object, hr %#lx.\n", hr
);
566 ok(object2
== object
, "Unexpected object.\n");
569 IUnknown_Release(object
);
570 IUnknown_Release(object2
);
572 SetEvent(callback
->event
);
577 static const IMFAsyncCallbackVtbl test_create_from_url_callback_vtbl
=
579 testcallback_QueryInterface
,
581 testcallback_Release
,
582 testcallback_GetParameters
,
583 test_create_from_url_callback_Invoke
,
586 static HRESULT WINAPI
test_create_from_file_handler_callback_Invoke(IMFAsyncCallback
*iface
, IMFAsyncResult
*result
)
588 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
589 IMFSchemeHandler
*handler
;
590 IUnknown
*object
, *object2
;
591 MF_OBJECT_TYPE obj_type
;
594 ok(!!result
, "Unexpected result object.\n");
596 handler
= (IMFSchemeHandler
*)IMFAsyncResult_GetStateNoAddRef(result
);
598 hr
= IMFSchemeHandler_EndCreateObject(handler
, result
, &obj_type
, &object
);
599 ok(hr
== S_OK
, "Failed to create an object, hr %#lx.\n", hr
);
603 hr
= IMFAsyncResult_GetObject(result
, &object2
);
604 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
606 IUnknown_Release(object
);
609 SetEvent(callback
->event
);
614 static const IMFAsyncCallbackVtbl test_create_from_file_handler_callback_vtbl
=
616 testcallback_QueryInterface
,
618 testcallback_Release
,
619 testcallback_GetParameters
,
620 test_create_from_file_handler_callback_Invoke
,
623 static HRESULT WINAPI
source_events_callback_Invoke(IMFAsyncCallback
*iface
, IMFAsyncResult
*result
)
625 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
626 IMFMediaEventGenerator
*generator
;
629 ok(!!result
, "Unexpected result object.\n");
631 generator
= (IMFMediaEventGenerator
*)IMFAsyncResult_GetStateNoAddRef(result
);
633 hr
= IMFMediaEventGenerator_EndGetEvent(generator
, result
, &callback
->media_event
);
634 ok(hr
== S_OK
, "Failed to create an object, hr %#lx.\n", hr
);
636 SetEvent(callback
->event
);
641 static const IMFAsyncCallbackVtbl events_callback_vtbl
=
643 testcallback_QueryInterface
,
645 testcallback_Release
,
646 testcallback_GetParameters
,
647 source_events_callback_Invoke
,
650 static const IMFAsyncCallbackVtbl testcallbackvtbl
;
652 static struct test_callback
* create_test_callback(const IMFAsyncCallbackVtbl
*vtbl
)
654 struct test_callback
*callback
= calloc(1, sizeof(*callback
));
656 callback
->IMFAsyncCallback_iface
.lpVtbl
= vtbl
? vtbl
: &testcallbackvtbl
;
657 callback
->refcount
= 1;
662 static BOOL
get_event(IMFMediaEventGenerator
*generator
, MediaEventType expected_event_type
, PROPVARIANT
*value
)
664 struct test_callback
*callback
;
665 MediaEventType event_type
;
669 callback
= create_test_callback(&events_callback_vtbl
);
670 callback
->event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
674 hr
= IMFMediaEventGenerator_BeginGetEvent(generator
, &callback
->IMFAsyncCallback_iface
,
675 (IUnknown
*)generator
);
676 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
678 if (WaitForSingleObject(callback
->event
, 1000) == WAIT_TIMEOUT
)
686 hr
= IMFMediaEvent_GetType(callback
->media_event
, &event_type
);
687 ok(hr
== S_OK
, "Failed to event type, hr %#lx.\n", hr
);
689 if ((ret
= (event_type
== expected_event_type
)))
693 hr
= IMFMediaEvent_GetValue(callback
->media_event
, value
);
694 ok(hr
== S_OK
, "Failed to get value of event, hr %#lx.\n", hr
);
701 CloseHandle(callback
->event
);
702 if (callback
->media_event
)
703 IMFMediaEvent_Release(callback
->media_event
);
704 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
709 static void test_source_resolver(void)
711 struct test_callback
*callback
, *callback2
;
712 IMFSourceResolver
*resolver
, *resolver2
;
713 IMFPresentationDescriptor
*descriptor
;
714 IMFSchemeHandler
*scheme_handler
;
715 IMFMediaStream
*video_stream
;
716 IMFAttributes
*attributes
;
717 IMFMediaSource
*mediasource
;
718 IMFMediaTypeHandler
*handler
;
719 IMFMediaType
*media_type
;
720 BOOL selected
, do_uninit
;
721 MF_OBJECT_TYPE obj_type
;
722 IMFStreamDescriptor
*sd
;
723 IUnknown
*cancel_cookie
;
724 IMFByteStream
*stream
;
725 IMFGetService
*get_service
;
726 IMFRateSupport
*rate_support
;
727 WCHAR pathW
[MAX_PATH
];
736 if (!pMFCreateSourceResolver
)
738 win_skip("MFCreateSourceResolver() not found\n");
742 callback
= create_test_callback(&test_create_from_url_callback_vtbl
);
743 callback2
= create_test_callback(&test_create_from_file_handler_callback_vtbl
);
745 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
746 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
748 hr
= pMFCreateSourceResolver(NULL
);
749 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
751 hr
= pMFCreateSourceResolver(&resolver
);
752 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
754 hr
= pMFCreateSourceResolver(&resolver2
);
755 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
756 ok(resolver
!= resolver2
, "Expected new instance\n");
758 IMFSourceResolver_Release(resolver2
);
760 filename
= load_resource(L
"test.mp4");
762 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, filename
, &stream
);
763 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
765 hr
= IMFSourceResolver_CreateObjectFromByteStream(
766 resolver
, NULL
, NULL
, MF_RESOLUTION_MEDIASOURCE
, NULL
,
767 &obj_type
, (IUnknown
**)&mediasource
);
768 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
770 hr
= IMFSourceResolver_CreateObjectFromByteStream(resolver
, stream
, NULL
, MF_RESOLUTION_MEDIASOURCE
, NULL
,
771 NULL
, (IUnknown
**)&mediasource
);
772 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
774 hr
= IMFSourceResolver_CreateObjectFromByteStream(resolver
, stream
, NULL
, MF_RESOLUTION_MEDIASOURCE
, NULL
,
776 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
778 IMFByteStream_Release(stream
);
780 /* Create from URL. */
781 callback
->event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
783 hr
= IMFSourceResolver_CreateObjectFromURL(resolver
, L
"nonexisting.mp4", MF_RESOLUTION_BYTESTREAM
, NULL
, &obj_type
,
784 (IUnknown
**)&stream
);
785 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Unexpected hr %#lx.\n", hr
);
787 hr
= IMFSourceResolver_CreateObjectFromURL(resolver
, filename
, MF_RESOLUTION_BYTESTREAM
, NULL
, &obj_type
,
788 (IUnknown
**)&stream
);
789 ok(hr
== S_OK
, "Failed to resolve url, hr %#lx.\n", hr
);
790 IMFByteStream_Release(stream
);
792 hr
= IMFSourceResolver_BeginCreateObjectFromURL(resolver
, filename
, MF_RESOLUTION_BYTESTREAM
, NULL
,
793 &cancel_cookie
, &callback
->IMFAsyncCallback_iface
, (IUnknown
*)resolver
);
794 ok(hr
== S_OK
, "Create request failed, hr %#lx.\n", hr
);
795 ok(cancel_cookie
!= NULL
, "Unexpected cancel object.\n");
796 IUnknown_Release(cancel_cookie
);
799 WaitForSingleObject(callback
->event
, INFINITE
);
801 /* With explicit scheme. */
802 lstrcpyW(pathW
, fileschemeW
);
803 lstrcatW(pathW
, filename
);
805 hr
= IMFSourceResolver_CreateObjectFromURL(resolver
, pathW
, MF_RESOLUTION_BYTESTREAM
, NULL
, &obj_type
,
806 (IUnknown
**)&stream
);
807 ok(hr
== S_OK
, "Failed to resolve url, hr %#lx.\n", hr
);
808 IMFByteStream_Release(stream
);
810 /* We have to create a new bytestream here, because all following
811 * calls to CreateObjectFromByteStream will fail. */
812 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, filename
, &stream
);
813 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
815 hr
= IMFByteStream_QueryInterface(stream
, &IID_IMFAttributes
, (void **)&attributes
);
816 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
817 hr
= IMFAttributes_SetString(attributes
, &MF_BYTESTREAM_CONTENT_TYPE
, L
"video/mp4");
818 ok(hr
== S_OK
, "Failed to set string value, hr %#lx.\n", hr
);
819 IMFAttributes_Release(attributes
);
821 /* Start of gstreamer dependent tests */
823 hr
= IMFSourceResolver_CreateObjectFromByteStream(resolver
, stream
, NULL
, MF_RESOLUTION_MEDIASOURCE
, NULL
,
824 &obj_type
, (IUnknown
**)&mediasource
);
825 if (strcmp(winetest_platform
, "wine"))
826 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
829 IMFByteStream_Release(stream
);
830 IMFSourceResolver_Release(resolver
);
833 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
835 DeleteFileW(filename
);
838 ok(mediasource
!= NULL
, "got %p\n", mediasource
);
839 ok(obj_type
== MF_OBJECT_MEDIASOURCE
, "got %d\n", obj_type
);
841 check_interface(mediasource
, &IID_IMFGetService
, TRUE
);
842 check_service_interface(mediasource
, &MF_RATE_CONTROL_SERVICE
, &IID_IMFRateSupport
, TRUE
);
844 hr
= IMFMediaSource_QueryInterface(mediasource
, &IID_IMFGetService
, (void**)&get_service
);
845 ok(hr
== S_OK
, "Failed to get service interface, hr %#lx.\n", hr
);
847 hr
= IMFGetService_GetService(get_service
, &MF_RATE_CONTROL_SERVICE
, &IID_IMFRateSupport
, (void**)&rate_support
);
848 ok(hr
== S_OK
, "Failed to get rate support interface, hr %#lx.\n", hr
);
850 hr
= IMFRateSupport_GetFastestRate(rate_support
, MFRATE_FORWARD
, FALSE
, &rate
);
851 ok(hr
== S_OK
, "Failed to query fastest rate, hr %#lx.\n", hr
);
852 ok(rate
== 1e6f
, "Unexpected fastest rate %f.\n", rate
);
853 hr
= IMFRateSupport_GetFastestRate(rate_support
, MFRATE_FORWARD
, TRUE
, &rate
);
854 ok(hr
== S_OK
, "Failed to query fastest rate, hr %#lx.\n", hr
);
855 ok(rate
== 1e6f
, "Unexpected fastest rate %f.\n", rate
);
856 hr
= IMFRateSupport_GetFastestRate(rate_support
, MFRATE_REVERSE
, FALSE
, &rate
);
857 ok(hr
== S_OK
, "Failed to query fastest rate, hr %#lx.\n", hr
);
858 ok(rate
== -1e6f
, "Unexpected fastest rate %f.\n", rate
);
859 hr
= IMFRateSupport_GetFastestRate(rate_support
, MFRATE_REVERSE
, TRUE
, &rate
);
860 ok(hr
== S_OK
, "Failed to query fastest rate, hr %#lx.\n", hr
);
861 ok(rate
== -1e6f
, "Unexpected fastest rate %f.\n", rate
);
863 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_FORWARD
, FALSE
, &rate
);
864 ok(hr
== S_OK
, "Failed to query slowest rate, hr %#lx.\n", hr
);
865 ok(rate
== 0.0f
, "Unexpected slowest rate %f.\n", rate
);
866 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_FORWARD
, TRUE
, &rate
);
867 ok(hr
== S_OK
, "Failed to query slowest rate, hr %#lx.\n", hr
);
868 ok(rate
== 0.0f
, "Unexpected slowest rate %f.\n", rate
);
869 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_REVERSE
, FALSE
, &rate
);
870 ok(hr
== S_OK
, "Failed to query slowest rate, hr %#lx.\n", hr
);
871 ok(rate
== 0.0f
, "Unexpected slowest rate %f.\n", rate
);
872 hr
= IMFRateSupport_GetSlowestRate(rate_support
, MFRATE_REVERSE
, TRUE
, &rate
);
873 ok(hr
== S_OK
, "Failed to query slowest rate, hr %#lx.\n", hr
);
874 ok(rate
== 0.0f
, "Unexpected slowest rate %f.\n", rate
);
876 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, 0.0f
, NULL
);
877 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
878 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, 0.0f
, &rate
);
879 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
880 ok(rate
== 0.0f
, "Unexpected rate %f.\n", rate
);
882 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, 1.0f
, &rate
);
883 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
884 ok(rate
== 1.0f
, "Unexpected rate %f.\n", rate
);
885 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, -1.0f
, &rate
);
886 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
887 ok(rate
== -1.0f
, "Unexpected rate %f.\n", rate
);
888 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, 1e6f
+ 1.0f
, &rate
);
889 ok(hr
== MF_E_UNSUPPORTED_RATE
, "Unexpected hr %#lx.\n", hr
);
890 ok(rate
== 1e6f
+ 1.0f
|| broken(rate
== 1e6f
) /* Win7 */, "Unexpected %f.\n", rate
);
891 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, -1e6f
, &rate
);
892 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
893 ok(rate
== -1e6f
, "Unexpected rate %f.\n", rate
);
895 hr
= IMFRateSupport_IsRateSupported(rate_support
, FALSE
, -1e6f
- 1.0f
, &rate
);
896 ok(hr
== MF_E_UNSUPPORTED_RATE
, "Unexpected hr %#lx.\n", hr
);
897 ok(rate
== -1e6f
- 1.0f
|| broken(rate
== -1e6f
) /* Win7 */, "Unexpected rate %f.\n", rate
);
899 check_service_interface(mediasource
, &MF_RATE_CONTROL_SERVICE
, &IID_IMFRateControl
, TRUE
);
900 hr
= IMFMediaSource_CreatePresentationDescriptor(mediasource
, &descriptor
);
901 ok(hr
== S_OK
, "Failed to get presentation descriptor, hr %#lx.\n", hr
);
902 ok(descriptor
!= NULL
, "got %p\n", descriptor
);
904 hr
= IMFPresentationDescriptor_GetStreamDescriptorByIndex(descriptor
, 0, &selected
, &sd
);
905 ok(hr
== S_OK
, "Failed to get stream descriptor, hr %#lx.\n", hr
);
907 hr
= IMFStreamDescriptor_GetMediaTypeHandler(sd
, &handler
);
908 ok(hr
== S_OK
, "Failed to get type handler, hr %#lx.\n", hr
);
909 IMFStreamDescriptor_Release(sd
);
911 hr
= IMFMediaTypeHandler_GetMajorType(handler
, &guid
);
912 ok(hr
== S_OK
, "Failed to get stream major type, hr %#lx.\n", hr
);
914 /* Check major/minor type for the test media. */
915 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected major type %s.\n", debugstr_guid(&guid
));
917 hr
= IMFMediaTypeHandler_GetCurrentMediaType(handler
, &media_type
);
918 ok(hr
== S_OK
, "Failed to get current media type, hr %#lx.\n", hr
);
919 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
920 ok(hr
== S_OK
, "Failed to get media sub type, hr %#lx.\n", hr
);
922 ok(IsEqualGUID(&guid
, &MFVideoFormat_M4S2
), "Unexpected sub type %s.\n", debugstr_guid(&guid
));
924 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_ROTATION
, &rotation
);
925 ok(hr
== S_OK
|| broken(hr
== MF_E_ATTRIBUTENOTFOUND
) /* Win7 */, "Failed to get rotation, hr %#lx.\n", hr
);
927 ok(rotation
== MFVideoRotationFormat_0
, "Got wrong rotation %u.\n", rotation
);
929 IMFMediaType_Release(media_type
);
931 hr
= IMFPresentationDescriptor_SelectStream(descriptor
, 0);
932 ok(hr
== S_OK
, "Failed to select video stream, hr %#lx.\n", hr
);
935 hr
= IMFMediaSource_Start(mediasource
, descriptor
, &GUID_NULL
, &var
);
936 ok(hr
== S_OK
, "Failed to start media source, hr %#lx.\n", hr
);
939 if (get_event((IMFMediaEventGenerator
*)mediasource
, MENewStream
, &var
))
941 ok(var
.vt
== VT_UNKNOWN
, "Unexpected value type.\n");
942 video_stream
= (IMFMediaStream
*)var
.punkVal
;
945 hr
= IMFMediaSource_Pause(mediasource
);
946 ok(hr
== S_OK
, "Failed to pause media source, hr %#lx.\n", hr
);
947 if (get_event((IMFMediaEventGenerator
*)mediasource
, MESourcePaused
, &var
))
948 ok(var
.vt
== VT_EMPTY
, "Unexpected value type.\n");
951 hr
= IMFMediaSource_Start(mediasource
, descriptor
, &GUID_NULL
, &var
);
952 ok(hr
== S_OK
, "Failed to start media source, hr %#lx.\n", hr
);
954 if (get_event((IMFMediaEventGenerator
*)mediasource
, MESourceStarted
, &var
))
955 ok(var
.vt
== VT_EMPTY
, "Unexpected value type.\n");
957 hr
= IMFMediaSource_Pause(mediasource
);
958 ok(hr
== S_OK
, "Failed to pause media source, hr %#lx.\n", hr
);
959 if (get_event((IMFMediaEventGenerator
*)mediasource
, MESourcePaused
, &var
))
960 ok(var
.vt
== VT_EMPTY
, "Unexpected value type.\n");
963 var
.uhVal
.QuadPart
= 0;
964 hr
= IMFMediaSource_Start(mediasource
, descriptor
, &GUID_NULL
, &var
);
965 ok(hr
== S_OK
, "Failed to start media source, hr %#lx.\n", hr
);
967 if (get_event((IMFMediaEventGenerator
*)mediasource
, MESourceSeeked
, &var
))
968 ok(var
.vt
== VT_I8
, "Unexpected value type.\n");
970 hr
= IMFMediaSource_Stop(mediasource
);
971 ok(hr
== S_OK
, "Failed to pause media source, hr %#lx.\n", hr
);
972 if (get_event((IMFMediaEventGenerator
*)mediasource
, MESourceStopped
, &var
))
973 ok(var
.vt
== VT_EMPTY
, "Unexpected value type.\n");
976 var
.uhVal
.QuadPart
= 0;
977 hr
= IMFMediaSource_Start(mediasource
, descriptor
, &GUID_NULL
, &var
);
978 ok(hr
== S_OK
, "Failed to start media source, hr %#lx.\n", hr
);
980 if (get_event((IMFMediaEventGenerator
*)mediasource
, MESourceStarted
, &var
))
981 ok(var
.vt
== VT_I8
, "Unexpected value type.\n");
985 for (i
= 0; i
< sample_count
; ++i
)
987 hr
= IMFMediaStream_RequestSample(video_stream
, NULL
);
988 ok(hr
== S_OK
, "Failed to request sample %u, hr %#lx.\n", i
+ 1, hr
);
993 for (i
= 0; i
< sample_count
; ++i
)
995 static const LONGLONG MILLI_TO_100_NANO
= 10000;
996 LONGLONG duration
, time
;
1001 ret
= get_event((IMFMediaEventGenerator
*)video_stream
, MEMediaSample
, &var
);
1002 ok(ret
, "Sample %u not received.\n", i
+ 1);
1006 ok(var
.vt
== VT_UNKNOWN
, "Unexpected value type %u from MEMediaSample event.\n", var
.vt
);
1007 sample
= (IMFSample
*)var
.punkVal
;
1009 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
1010 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
1011 ok(buffer_count
== 1, "Unexpected buffer count %lu.\n", buffer_count
);
1013 hr
= IMFSample_GetSampleDuration(sample
, &duration
);
1014 ok(hr
== S_OK
, "Failed to get sample duration, hr %#lx.\n", hr
);
1015 ok(duration
== 40 * MILLI_TO_100_NANO
, "Unexpected duration %s.\n", wine_dbgstr_longlong(duration
));
1017 hr
= IMFSample_GetSampleTime(sample
, &time
);
1018 ok(hr
== S_OK
, "Failed to get sample time, hr %#lx.\n", hr
);
1019 ok(time
== i
* 40 * MILLI_TO_100_NANO
, "Unexpected time %s.\n", wine_dbgstr_longlong(time
));
1021 IMFSample_Release(sample
);
1024 if (i
== sample_count
)
1026 IMFMediaEvent
*event
;
1028 /* MEEndOfStream isn't queued until after a one request beyond the last frame is submitted */
1030 hr
= IMFMediaEventGenerator_GetEvent((IMFMediaEventGenerator
*)video_stream
, MF_EVENT_FLAG_NO_WAIT
, &event
);
1031 ok (hr
== MF_E_NO_EVENTS_AVAILABLE
, "Unexpected hr %#lx.\n", hr
);
1033 hr
= IMFMediaStream_RequestSample(video_stream
, NULL
);
1034 ok (hr
== S_OK
|| hr
== MF_E_END_OF_STREAM
, "Unexpected hr %#lx.\n", hr
);
1035 get_event((IMFMediaEventGenerator
*)video_stream
, MEEndOfStream
, NULL
);
1039 hr
= IMFMediaStream_RequestSample(video_stream
, NULL
);
1040 ok(hr
== MF_E_END_OF_STREAM
, "Unexpected hr %#lx.\n", hr
);
1042 get_event((IMFMediaEventGenerator
*)mediasource
, MEEndOfPresentation
, NULL
);
1044 IMFMediaStream_Release(video_stream
);
1045 IMFMediaTypeHandler_Release(handler
);
1046 IMFPresentationDescriptor_Release(descriptor
);
1048 hr
= IMFMediaSource_Shutdown(mediasource
);
1049 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1051 hr
= IMFMediaSource_CreatePresentationDescriptor(mediasource
, NULL
);
1052 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
1054 IMFRateSupport_Release(rate_support
);
1055 IMFGetService_Release(get_service
);
1056 IMFMediaSource_Release(mediasource
);
1057 IMFByteStream_Release(stream
);
1059 /* Create directly through scheme handler. */
1060 hr
= CoInitialize(NULL
);
1061 ok(SUCCEEDED(hr
), "Failed to initialize, hr %#lx.\n", hr
);
1062 do_uninit
= hr
== S_OK
;
1064 hr
= CoCreateInstance(&CLSID_FileSchemePlugin
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMFSchemeHandler
,
1065 (void **)&scheme_handler
);
1066 ok(hr
== S_OK
, "Failed to create handler object, hr %#lx.\n", hr
);
1068 callback2
->event
= callback
->event
;
1069 cancel_cookie
= NULL
;
1070 hr
= IMFSchemeHandler_BeginCreateObject(scheme_handler
, pathW
, MF_RESOLUTION_MEDIASOURCE
, NULL
, &cancel_cookie
,
1071 &callback2
->IMFAsyncCallback_iface
, (IUnknown
*)scheme_handler
);
1072 ok(hr
== S_OK
, "Create request failed, hr %#lx.\n", hr
);
1073 ok(!!cancel_cookie
, "Unexpected cancel object.\n");
1074 IUnknown_Release(cancel_cookie
);
1076 WaitForSingleObject(callback2
->event
, INFINITE
);
1078 IMFSchemeHandler_Release(scheme_handler
);
1083 CloseHandle(callback
->event
);
1085 IMFSourceResolver_Release(resolver
);
1088 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
1090 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
1091 IMFAsyncCallback_Release(&callback2
->IMFAsyncCallback_iface
);
1093 DeleteFileW(filename
);
1096 static void init_functions(void)
1098 HMODULE mod
= GetModuleHandleA("mfplat.dll");
1100 #define X(f) p##f = (void*)GetProcAddress(mod, #f)
1101 X(MFAddPeriodicCallback
);
1102 X(MFAllocateSerialWorkQueue
);
1103 X(MFAllocateWorkQueueEx
);
1105 X(MFCreate2DMediaBuffer
);
1106 X(MFCreateDXGIDeviceManager
);
1107 X(MFCreateDXGISurfaceBuffer
);
1108 X(MFCreateDXSurfaceBuffer
);
1109 X(MFCreateSourceResolver
);
1110 X(MFCreateMediaBufferFromMediaType
);
1111 X(MFCreateMFByteStreamOnStream
);
1112 X(MFCreateTrackedSample
);
1113 X(MFCreateTransformActivate
);
1114 X(MFCreateVideoMediaTypeFromSubtype
);
1115 X(MFCreateVideoSampleAllocatorEx
);
1117 X(MFGetStrideForBitmapInfoHeader
);
1118 X(MFInitVideoFormat_RGB
);
1119 X(MFLockDXGIDeviceManager
);
1120 X(MFLockSharedWorkQueue
);
1121 X(MFMapDX9FormatToDXGIFormat
);
1122 X(MFMapDXGIFormatToDX9Format
);
1123 X(MFPutWaitingWorkItem
);
1124 X(MFRegisterLocalByteStreamHandler
);
1125 X(MFRegisterLocalSchemeHandler
);
1126 X(MFRemovePeriodicCallback
);
1128 X(MFTRegisterLocal
);
1129 X(MFTRegisterLocalByCLSID
);
1130 X(MFTUnregisterLocal
);
1131 X(MFTUnregisterLocalByCLSID
);
1132 X(MFUnlockDXGIDeviceManager
);
1134 if ((mod
= LoadLibraryA("d3d11.dll")))
1136 X(D3D11CreateDevice
);
1139 if ((mod
= LoadLibraryA("d3d12.dll")))
1141 X(D3D12CreateDevice
);
1144 mod
= GetModuleHandleA("ole32.dll");
1146 X(CoGetApartmentType
);
1149 is_win8_plus
= pMFPutWaitingWorkItem
!= NULL
;
1152 static void test_media_type(void)
1154 IMFMediaType
*mediatype
, *mediatype2
;
1155 IMFVideoMediaType
*video_type
;
1156 IUnknown
*unk
, *unk2
;
1165 /* Crash on Windows Vista/7 */
1166 hr
= MFCreateMediaType(NULL
);
1167 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1170 hr
= MFCreateMediaType(&mediatype
);
1171 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1173 hr
= IMFMediaType_GetMajorType(mediatype
, &guid
);
1174 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
1177 hr
= IMFMediaType_IsCompressedFormat(mediatype
, &compressed
);
1178 ok(hr
== S_OK
, "Failed to get media type property, hr %#lx.\n", hr
);
1179 ok(compressed
, "Unexpected value %d.\n", compressed
);
1181 hr
= IMFMediaType_SetUINT32(mediatype
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, 0);
1182 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1185 hr
= IMFMediaType_IsCompressedFormat(mediatype
, &compressed
);
1186 ok(hr
== S_OK
, "Failed to get media type property, hr %#lx.\n", hr
);
1187 ok(compressed
, "Unexpected value %d.\n", compressed
);
1189 hr
= IMFMediaType_SetUINT32(mediatype
, &MF_MT_COMPRESSED
, 0);
1190 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1193 hr
= IMFMediaType_IsCompressedFormat(mediatype
, &compressed
);
1194 ok(hr
== S_OK
, "Failed to get media type property, hr %#lx.\n", hr
);
1195 ok(compressed
, "Unexpected value %d.\n", compressed
);
1197 hr
= IMFMediaType_SetUINT32(mediatype
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, 1);
1198 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1200 hr
= IMFMediaType_SetUINT32(mediatype
, &MF_MT_COMPRESSED
, 1);
1201 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1204 hr
= IMFMediaType_IsCompressedFormat(mediatype
, &compressed
);
1205 ok(hr
== S_OK
, "Failed to get media type property, hr %#lx.\n", hr
);
1206 ok(!compressed
, "Unexpected value %d.\n", compressed
);
1208 hr
= IMFMediaType_DeleteItem(mediatype
, &MF_MT_COMPRESSED
);
1209 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1211 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
1212 ok(hr
== S_OK
, "Failed to set GUID value, hr %#lx.\n", hr
);
1214 hr
= IMFMediaType_GetMajorType(mediatype
, &guid
);
1215 ok(hr
== S_OK
, "Failed to get major type, hr %#lx.\n", hr
);
1216 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected major type.\n");
1219 hr
= MFCreateMediaType(&mediatype2
);
1220 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
1223 hr
= IMFMediaType_IsEqual(mediatype
, mediatype2
, &flags
);
1224 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1225 ok(flags
== 0, "Unexpected flags %#lx.\n", flags
);
1227 /* Different major types. */
1228 hr
= IMFMediaType_SetGUID(mediatype2
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
1229 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
1232 hr
= IMFMediaType_IsEqual(mediatype
, mediatype2
, &flags
);
1233 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
1234 ok(flags
== (MF_MEDIATYPE_EQUAL_FORMAT_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA
),
1235 "Unexpected flags %#lx.\n", flags
);
1237 /* Same major types, different subtypes. */
1238 hr
= IMFMediaType_SetGUID(mediatype2
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
1239 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
1242 hr
= IMFMediaType_IsEqual(mediatype
, mediatype2
, &flags
);
1243 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1244 ok(flags
== (MF_MEDIATYPE_EQUAL_MAJOR_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_DATA
1245 | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA
), "Unexpected flags %#lx.\n", flags
);
1247 /* Different user data. */
1248 hr
= IMFMediaType_SetBlob(mediatype
, &MF_MT_USER_DATA
, (const UINT8
*)&flags
, sizeof(flags
));
1249 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
1252 hr
= IMFMediaType_IsEqual(mediatype
, mediatype2
, &flags
);
1253 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
1254 ok(flags
== (MF_MEDIATYPE_EQUAL_MAJOR_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_DATA
),
1255 "Unexpected flags %#lx.\n", flags
);
1257 hr
= IMFMediaType_DeleteItem(mediatype
, &MF_MT_USER_DATA
);
1258 ok(hr
== S_OK
, "Failed to delete item, hr %#lx.\n", hr
);
1260 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
1261 ok(hr
== S_OK
, "Failed to set subtype, hr %#lx.\n", hr
);
1264 hr
= IMFMediaType_IsEqual(mediatype
, mediatype2
, &flags
);
1265 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
1266 ok(flags
== (MF_MEDIATYPE_EQUAL_MAJOR_TYPES
| MF_MEDIATYPE_EQUAL_FORMAT_DATA
| MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA
),
1267 "Unexpected flags %#lx.\n", flags
);
1269 IMFMediaType_Release(mediatype2
);
1270 IMFMediaType_Release(mediatype
);
1272 /* IMFVideoMediaType */
1273 hr
= MFCreateMediaType(&mediatype
);
1274 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1276 check_interface(mediatype
, &IID_IMFVideoMediaType
, FALSE
);
1278 hr
= IMFMediaType_QueryInterface(mediatype
, &IID_IUnknown
, (void **)&unk
);
1279 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1280 ok(unk
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1281 IUnknown_Release(unk
);
1283 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
1284 ok(hr
== S_OK
, "Failed to set GUID value, hr %#lx.\n", hr
);
1286 hr
= IMFMediaType_QueryInterface(mediatype
, &IID_IMFVideoMediaType
, (void **)&unk
);
1287 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1289 hr
= IUnknown_QueryInterface(unk
, &IID_IUnknown
, (void **)&unk2
);
1290 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1291 ok(unk2
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1292 IUnknown_Release(unk2
);
1294 hr
= IUnknown_QueryInterface(unk
, &IID_IMFAttributes
, (void **)&unk2
);
1295 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1296 ok(unk2
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1297 IUnknown_Release(unk2
);
1299 hr
= IUnknown_QueryInterface(unk
, &IID_IMFMediaType
, (void **)&unk2
);
1300 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1301 ok(unk2
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1302 IUnknown_Release(unk2
);
1304 IUnknown_Release(unk
);
1305 IMFMediaType_Release(mediatype
);
1307 if (pMFCreateVideoMediaTypeFromSubtype
)
1309 hr
= pMFCreateVideoMediaTypeFromSubtype(&MFVideoFormat_RGB555
, &video_type
);
1310 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1312 check_interface(video_type
, &IID_IMFMediaType
, TRUE
);
1313 check_interface(video_type
, &IID_IMFVideoMediaType
, TRUE
);
1315 /* Major and subtype are set on creation. */
1316 hr
= IMFVideoMediaType_GetCount(video_type
, &count
);
1317 ok(count
== 2, "Unexpected attribute count %#lx.\n", hr
);
1319 hr
= IMFVideoMediaType_DeleteAllItems(video_type
);
1320 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1322 hr
= IMFVideoMediaType_GetCount(video_type
, &count
);
1323 ok(!count
, "Unexpected attribute count %#lx.\n", hr
);
1325 check_interface(video_type
, &IID_IMFVideoMediaType
, FALSE
);
1327 IMFVideoMediaType_Release(video_type
);
1330 win_skip("MFCreateVideoMediaTypeFromSubtype() is not available.\n");
1332 /* IMFAudioMediaType */
1333 hr
= MFCreateMediaType(&mediatype
);
1334 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1336 check_interface(mediatype
, &IID_IMFAudioMediaType
, FALSE
);
1338 hr
= IMFMediaType_QueryInterface(mediatype
, &IID_IUnknown
, (void **)&unk
);
1339 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1340 ok(unk
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1341 IUnknown_Release(unk
);
1343 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
1344 ok(hr
== S_OK
, "Failed to set GUID value, hr %#lx.\n", hr
);
1346 hr
= IMFMediaType_QueryInterface(mediatype
, &IID_IMFAudioMediaType
, (void **)&unk
);
1347 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1349 hr
= IUnknown_QueryInterface(unk
, &IID_IUnknown
, (void **)&unk2
);
1350 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1351 ok(unk2
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1352 IUnknown_Release(unk2
);
1354 hr
= IUnknown_QueryInterface(unk
, &IID_IMFAttributes
, (void **)&unk2
);
1355 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1356 ok(unk2
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1357 IUnknown_Release(unk2
);
1359 hr
= IUnknown_QueryInterface(unk
, &IID_IMFMediaType
, (void **)&unk2
);
1360 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1361 ok(unk2
== (IUnknown
*)mediatype
, "Unexpected pointer.\n");
1362 IUnknown_Release(unk2
);
1364 IUnknown_Release(unk
);
1366 IMFMediaType_Release(mediatype
);
1369 static void test_MFCreateMediaEvent(void)
1372 IMFMediaEvent
*mediaevent
;
1374 MediaEventType type
;
1379 PropVariantInit(&value
);
1380 value
.vt
= VT_UNKNOWN
;
1382 hr
= MFCreateMediaEvent(MEError
, &GUID_NULL
, E_FAIL
, &value
, &mediaevent
);
1383 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1385 PropVariantClear(&value
);
1387 hr
= IMFMediaEvent_GetType(mediaevent
, &type
);
1388 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1389 ok(type
== MEError
, "got %#lx\n", type
);
1391 hr
= IMFMediaEvent_GetExtendedType(mediaevent
, &extended_type
);
1392 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1393 ok(IsEqualGUID(&extended_type
, &GUID_NULL
), "got %s\n",
1394 wine_dbgstr_guid(&extended_type
));
1396 hr
= IMFMediaEvent_GetStatus(mediaevent
, &status
);
1397 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1398 ok(status
== E_FAIL
, "Unexpected hr %#lx.\n", status
);
1400 PropVariantInit(&value
);
1401 hr
= IMFMediaEvent_GetValue(mediaevent
, &value
);
1402 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1403 ok(value
.vt
== VT_UNKNOWN
, "got %#x\n", value
.vt
);
1404 PropVariantClear(&value
);
1406 IMFMediaEvent_Release(mediaevent
);
1408 hr
= MFCreateMediaEvent(MEUnknown
, &DUMMY_GUID1
, S_OK
, NULL
, &mediaevent
);
1409 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1411 hr
= IMFMediaEvent_GetType(mediaevent
, &type
);
1412 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1413 ok(type
== MEUnknown
, "got %#lx\n", type
);
1415 hr
= IMFMediaEvent_GetExtendedType(mediaevent
, &extended_type
);
1416 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1417 ok(IsEqualGUID(&extended_type
, &DUMMY_GUID1
), "got %s\n",
1418 wine_dbgstr_guid(&extended_type
));
1420 hr
= IMFMediaEvent_GetStatus(mediaevent
, &status
);
1421 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1422 ok(status
== S_OK
, "Unexpected hr %#lx.\n", status
);
1424 PropVariantInit(&value
);
1425 hr
= IMFMediaEvent_GetValue(mediaevent
, &value
);
1426 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1427 ok(value
.vt
== VT_EMPTY
, "got %#x\n", value
.vt
);
1428 PropVariantClear(&value
);
1430 IMFMediaEvent_Release(mediaevent
);
1433 #define CHECK_ATTR_COUNT(obj, expected) check_attr_count(obj, expected, __LINE__)
1434 static void check_attr_count(IMFAttributes
* obj
, UINT32 expected
, int line
)
1436 UINT32 count
= expected
+ 1;
1437 HRESULT hr
= IMFAttributes_GetCount(obj
, &count
);
1438 ok_(__FILE__
, line
)(hr
== S_OK
, "Failed to get attributes count, hr %#lx.\n", hr
);
1439 ok_(__FILE__
, line
)(count
== expected
, "Unexpected count %u, expected %u.\n", count
, expected
);
1442 #define CHECK_ATTR_TYPE(obj, key, expected) check_attr_type(obj, key, expected, __LINE__)
1443 static void check_attr_type(IMFAttributes
*obj
, const GUID
*key
, MF_ATTRIBUTE_TYPE expected
, int line
)
1445 MF_ATTRIBUTE_TYPE type
;
1448 hr
= IMFAttributes_GetItemType(obj
, key
, &type
);
1449 ok_(__FILE__
, line
)(hr
== S_OK
, "Failed to get item type, hr %#lx.\n", hr
);
1450 ok_(__FILE__
, line
)(type
== expected
, "Unexpected item type %d, expected %d.\n", type
, expected
);
1453 static void test_attributes(void)
1455 static const WCHAR stringW
[] = L
"Wine";
1456 static const UINT8 blob
[] = {0,1,2,3,4,5};
1457 IMFAttributes
*attributes
, *attributes1
;
1458 UINT8 blob_value
[256], *blob_buf
= NULL
;
1459 MF_ATTRIBUTES_MATCH_TYPE match_type
;
1460 UINT32 value
, string_length
, size
;
1461 PROPVARIANT propvar
, ret_propvar
;
1462 MF_ATTRIBUTE_TYPE type
;
1463 double double_value
;
1464 IUnknown
*unk_value
;
1472 hr
= MFCreateAttributes( &attributes
, 3 );
1473 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1475 hr
= IMFAttributes_GetItemType(attributes
, &GUID_NULL
, &type
);
1476 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
1478 CHECK_ATTR_COUNT(attributes
, 0);
1479 hr
= IMFAttributes_SetUINT32(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, 123);
1480 ok(hr
== S_OK
, "Failed to set UINT32 value, hr %#lx.\n", hr
);
1481 CHECK_ATTR_COUNT(attributes
, 1);
1482 CHECK_ATTR_TYPE(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, MF_ATTRIBUTE_UINT32
);
1485 hr
= IMFAttributes_GetUINT32(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, &value
);
1486 ok(hr
== S_OK
, "Failed to get UINT32 value, hr %#lx.\n", hr
);
1487 ok(value
== 123, "Unexpected value %u, expected: 123.\n", value
);
1489 value64
= 0xdeadbeef;
1490 hr
= IMFAttributes_GetUINT64(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, &value64
);
1491 ok(hr
== MF_E_INVALIDTYPE
, "Unexpected hr %#lx.\n", hr
);
1492 ok(value64
== 0xdeadbeef, "Unexpected value.\n");
1494 hr
= IMFAttributes_SetUINT64(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, 65536);
1495 ok(hr
== S_OK
, "Failed to set UINT64 value, hr %#lx.\n", hr
);
1496 CHECK_ATTR_COUNT(attributes
, 1);
1497 CHECK_ATTR_TYPE(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, MF_ATTRIBUTE_UINT64
);
1499 hr
= IMFAttributes_GetUINT64(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, &value64
);
1500 ok(hr
== S_OK
, "Failed to get UINT64 value, hr %#lx.\n", hr
);
1501 ok(value64
== 65536, "Unexpected value.\n");
1504 hr
= IMFAttributes_GetUINT32(attributes
, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS
, &value
);
1505 ok(hr
== MF_E_INVALIDTYPE
, "Unexpected hr %#lx.\n", hr
);
1506 ok(value
== 0xdeadbeef, "Unexpected value.\n");
1508 IMFAttributes_Release(attributes
);
1510 hr
= MFCreateAttributes(&attributes
, 0);
1511 ok(hr
== S_OK
, "Failed to create attributes object, hr %#lx.\n", hr
);
1513 PropVariantInit(&propvar
);
1514 propvar
.vt
= MF_ATTRIBUTE_UINT32
;
1515 U(propvar
).ulVal
= 123;
1516 hr
= IMFAttributes_SetItem(attributes
, &DUMMY_GUID1
, &propvar
);
1517 ok(hr
== S_OK
, "Failed to set item, hr %#lx.\n", hr
);
1518 PropVariantInit(&ret_propvar
);
1519 ret_propvar
.vt
= MF_ATTRIBUTE_UINT32
;
1520 U(ret_propvar
).ulVal
= 0xdeadbeef;
1521 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID1
, &ret_propvar
);
1522 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1523 ok(!PropVariantCompareEx(&propvar
, &ret_propvar
, 0, 0), "Unexpected item value.\n");
1524 PropVariantClear(&ret_propvar
);
1525 CHECK_ATTR_COUNT(attributes
, 1);
1527 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID1
, NULL
);
1528 ok(hr
== S_OK
, "Item check failed, hr %#lx.\n", hr
);
1530 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID2
, NULL
);
1531 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
1533 PropVariantInit(&ret_propvar
);
1534 ret_propvar
.vt
= MF_ATTRIBUTE_STRING
;
1535 U(ret_propvar
).pwszVal
= NULL
;
1536 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID1
, &ret_propvar
);
1537 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1538 ok(!PropVariantCompareEx(&propvar
, &ret_propvar
, 0, 0), "Unexpected item value.\n");
1539 PropVariantClear(&ret_propvar
);
1541 PropVariantClear(&propvar
);
1543 PropVariantInit(&propvar
);
1544 propvar
.vt
= MF_ATTRIBUTE_UINT64
;
1545 U(propvar
).uhVal
.QuadPart
= 65536;
1546 hr
= IMFAttributes_SetItem(attributes
, &DUMMY_GUID1
, &propvar
);
1547 ok(hr
== S_OK
, "Failed to set item, hr %#lx.\n", hr
);
1548 PropVariantInit(&ret_propvar
);
1549 ret_propvar
.vt
= MF_ATTRIBUTE_UINT32
;
1550 U(ret_propvar
).ulVal
= 0xdeadbeef;
1551 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID1
, &ret_propvar
);
1552 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1553 ok(!PropVariantCompareEx(&propvar
, &ret_propvar
, 0, 0), "Unexpected item value.\n");
1554 PropVariantClear(&ret_propvar
);
1555 PropVariantClear(&propvar
);
1556 CHECK_ATTR_COUNT(attributes
, 1);
1558 PropVariantInit(&propvar
);
1560 U(propvar
).lVal
= 123;
1561 hr
= IMFAttributes_SetItem(attributes
, &DUMMY_GUID2
, &propvar
);
1562 ok(hr
== MF_E_INVALIDTYPE
, "Failed to set item, hr %#lx.\n", hr
);
1563 PropVariantInit(&ret_propvar
);
1564 ret_propvar
.vt
= MF_ATTRIBUTE_UINT32
;
1565 U(ret_propvar
).lVal
= 0xdeadbeef;
1566 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID2
, &ret_propvar
);
1567 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1568 PropVariantClear(&propvar
);
1569 ok(!PropVariantCompareEx(&propvar
, &ret_propvar
, 0, 0), "Unexpected item value.\n");
1570 PropVariantClear(&ret_propvar
);
1572 PropVariantInit(&propvar
);
1573 propvar
.vt
= MF_ATTRIBUTE_UINT32
;
1574 U(propvar
).ulVal
= 123;
1575 hr
= IMFAttributes_SetItem(attributes
, &DUMMY_GUID3
, &propvar
);
1576 ok(hr
== S_OK
, "Failed to set item, hr %#lx.\n", hr
);
1578 hr
= IMFAttributes_DeleteItem(attributes
, &DUMMY_GUID2
);
1579 ok(hr
== S_OK
, "Failed to delete item, hr %#lx.\n", hr
);
1580 CHECK_ATTR_COUNT(attributes
, 2);
1582 hr
= IMFAttributes_DeleteItem(attributes
, &DUMMY_GUID2
);
1583 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1584 CHECK_ATTR_COUNT(attributes
, 2);
1586 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID3
, &ret_propvar
);
1587 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1588 ok(!PropVariantCompareEx(&propvar
, &ret_propvar
, 0, 0), "Unexpected item value.\n");
1589 PropVariantClear(&ret_propvar
);
1590 PropVariantClear(&propvar
);
1592 propvar
.vt
= MF_ATTRIBUTE_UINT64
;
1593 U(propvar
).uhVal
.QuadPart
= 65536;
1595 hr
= IMFAttributes_GetItem(attributes
, &DUMMY_GUID1
, &ret_propvar
);
1596 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1597 ok(!PropVariantCompareEx(&propvar
, &ret_propvar
, 0, 0), "Unexpected item value.\n");
1598 PropVariantClear(&ret_propvar
);
1599 PropVariantClear(&propvar
);
1601 /* Item ordering is not consistent across Windows version. */
1602 hr
= IMFAttributes_GetItemByIndex(attributes
, 0, &key
, &ret_propvar
);
1603 ok(hr
== S_OK
, "Failed to get item, hr %#lx.\n", hr
);
1604 PropVariantClear(&ret_propvar
);
1606 hr
= IMFAttributes_GetItemByIndex(attributes
, 100, &key
, &ret_propvar
);
1607 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1608 PropVariantClear(&ret_propvar
);
1610 hr
= IMFAttributes_SetDouble(attributes
, &GUID_NULL
, 22.0);
1611 ok(hr
== S_OK
, "Failed to set double value, hr %#lx.\n", hr
);
1612 CHECK_ATTR_COUNT(attributes
, 3);
1613 CHECK_ATTR_TYPE(attributes
, &GUID_NULL
, MF_ATTRIBUTE_DOUBLE
);
1615 double_value
= 0xdeadbeef;
1616 hr
= IMFAttributes_GetDouble(attributes
, &GUID_NULL
, &double_value
);
1617 ok(hr
== S_OK
, "Failed to get double value, hr %#lx.\n", hr
);
1618 ok(double_value
== 22.0, "Unexpected value: %f, expected: 22.0.\n", double_value
);
1620 propvar
.vt
= MF_ATTRIBUTE_UINT64
;
1621 U(propvar
).uhVal
.QuadPart
= 22;
1622 hr
= IMFAttributes_CompareItem(attributes
, &GUID_NULL
, &propvar
, &result
);
1623 ok(hr
== S_OK
, "Failed to compare items, hr %#lx.\n", hr
);
1624 ok(!result
, "Unexpected result.\n");
1626 propvar
.vt
= MF_ATTRIBUTE_DOUBLE
;
1627 U(propvar
).dblVal
= 22.0;
1628 hr
= IMFAttributes_CompareItem(attributes
, &GUID_NULL
, &propvar
, &result
);
1629 ok(hr
== S_OK
, "Failed to compare items, hr %#lx.\n", hr
);
1630 ok(result
, "Unexpected result.\n");
1632 hr
= IMFAttributes_SetString(attributes
, &DUMMY_GUID1
, stringW
);
1633 ok(hr
== S_OK
, "Failed to set string attribute, hr %#lx.\n", hr
);
1634 CHECK_ATTR_COUNT(attributes
, 3);
1635 CHECK_ATTR_TYPE(attributes
, &DUMMY_GUID1
, MF_ATTRIBUTE_STRING
);
1637 hr
= IMFAttributes_GetStringLength(attributes
, &DUMMY_GUID1
, &string_length
);
1638 ok(hr
== S_OK
, "Failed to get string length, hr %#lx.\n", hr
);
1639 ok(string_length
== lstrlenW(stringW
), "Unexpected length %u.\n", string_length
);
1641 string_length
= 0xdeadbeef;
1642 hr
= IMFAttributes_GetAllocatedString(attributes
, &DUMMY_GUID1
, &string
, &string_length
);
1643 ok(hr
== S_OK
, "Failed to get allocated string, hr %#lx.\n", hr
);
1644 ok(!lstrcmpW(string
, stringW
), "Unexpected string %s.\n", wine_dbgstr_w(string
));
1645 ok(string_length
== lstrlenW(stringW
), "Unexpected length %u.\n", string_length
);
1646 CoTaskMemFree(string
);
1648 string_length
= 0xdeadbeef;
1649 hr
= IMFAttributes_GetString(attributes
, &DUMMY_GUID1
, bufferW
, ARRAY_SIZE(bufferW
), &string_length
);
1650 ok(hr
== S_OK
, "Failed to get string value, hr %#lx.\n", hr
);
1651 ok(!lstrcmpW(bufferW
, stringW
), "Unexpected string %s.\n", wine_dbgstr_w(bufferW
));
1652 ok(string_length
== lstrlenW(stringW
), "Unexpected length %u.\n", string_length
);
1653 memset(bufferW
, 0, sizeof(bufferW
));
1655 hr
= IMFAttributes_GetString(attributes
, &DUMMY_GUID1
, bufferW
, ARRAY_SIZE(bufferW
), NULL
);
1656 ok(hr
== S_OK
, "Failed to get string value, hr %#lx.\n", hr
);
1657 ok(!lstrcmpW(bufferW
, stringW
), "Unexpected string %s.\n", wine_dbgstr_w(bufferW
));
1658 memset(bufferW
, 0, sizeof(bufferW
));
1661 hr
= IMFAttributes_GetString(attributes
, &DUMMY_GUID1
, bufferW
, 1, &string_length
);
1662 ok(hr
== STRSAFE_E_INSUFFICIENT_BUFFER
, "Unexpected hr %#lx.\n", hr
);
1663 ok(!bufferW
[0], "Unexpected string %s.\n", wine_dbgstr_w(bufferW
));
1664 ok(string_length
, "Unexpected length.\n");
1666 string_length
= 0xdeadbeef;
1667 hr
= IMFAttributes_GetStringLength(attributes
, &GUID_NULL
, &string_length
);
1668 ok(hr
== MF_E_INVALIDTYPE
, "Unexpected hr %#lx.\n", hr
);
1669 ok(string_length
== 0xdeadbeef, "Unexpected length %u.\n", string_length
);
1672 hr
= IMFAttributes_SetUnknown(attributes
, &DUMMY_GUID2
, (IUnknown
*)attributes
);
1673 ok(hr
== S_OK
, "Failed to set value, hr %#lx.\n", hr
);
1674 CHECK_ATTR_COUNT(attributes
, 4);
1675 CHECK_ATTR_TYPE(attributes
, &DUMMY_GUID2
, MF_ATTRIBUTE_IUNKNOWN
);
1677 hr
= IMFAttributes_GetUnknown(attributes
, &DUMMY_GUID2
, &IID_IUnknown
, (void **)&unk_value
);
1678 ok(hr
== S_OK
, "Failed to get value, hr %#lx.\n", hr
);
1679 IUnknown_Release(unk_value
);
1681 hr
= IMFAttributes_GetUnknown(attributes
, &DUMMY_GUID2
, &IID_IMFAttributes
, (void **)&unk_value
);
1682 ok(hr
== S_OK
, "Failed to get value, hr %#lx.\n", hr
);
1683 IUnknown_Release(unk_value
);
1685 hr
= IMFAttributes_GetUnknown(attributes
, &DUMMY_GUID2
, &IID_IStream
, (void **)&unk_value
);
1686 ok(hr
== E_NOINTERFACE
, "Unexpected hr %#lx.\n", hr
);
1688 hr
= IMFAttributes_SetUnknown(attributes
, &DUMMY_CLSID
, NULL
);
1689 ok(hr
== S_OK
, "Failed to set value, hr %#lx.\n", hr
);
1690 CHECK_ATTR_COUNT(attributes
, 5);
1693 hr
= IMFAttributes_GetUnknown(attributes
, &DUMMY_CLSID
, &IID_IUnknown
, (void **)&unk_value
);
1694 ok(hr
== MF_E_INVALIDTYPE
, "Unexpected hr %#lx.\n", hr
);
1696 /* CopyAllItems() */
1697 hr
= MFCreateAttributes(&attributes1
, 0);
1698 ok(hr
== S_OK
, "Failed to create attributes object, hr %#lx.\n", hr
);
1699 hr
= IMFAttributes_CopyAllItems(attributes
, attributes1
);
1700 ok(hr
== S_OK
, "Failed to copy items, hr %#lx.\n", hr
);
1701 CHECK_ATTR_COUNT(attributes
, 5);
1702 CHECK_ATTR_COUNT(attributes1
, 5);
1704 hr
= IMFAttributes_DeleteAllItems(attributes1
);
1705 ok(hr
== S_OK
, "Failed to delete items, hr %#lx.\n", hr
);
1706 CHECK_ATTR_COUNT(attributes1
, 0);
1708 propvar
.vt
= MF_ATTRIBUTE_UINT64
;
1709 U(propvar
).uhVal
.QuadPart
= 22;
1710 hr
= IMFAttributes_CompareItem(attributes
, &GUID_NULL
, &propvar
, &result
);
1711 ok(hr
== S_OK
, "Failed to compare items, hr %#lx.\n", hr
);
1712 ok(!result
, "Unexpected result.\n");
1714 hr
= IMFAttributes_CopyAllItems(attributes1
, attributes
);
1715 ok(hr
== S_OK
, "Failed to copy items, hr %#lx.\n", hr
);
1716 CHECK_ATTR_COUNT(attributes
, 0);
1719 hr
= IMFAttributes_SetBlob(attributes
, &DUMMY_GUID1
, blob
, sizeof(blob
));
1720 ok(hr
== S_OK
, "Failed to set blob attribute, hr %#lx.\n", hr
);
1721 CHECK_ATTR_COUNT(attributes
, 1);
1722 CHECK_ATTR_TYPE(attributes
, &DUMMY_GUID1
, MF_ATTRIBUTE_BLOB
);
1723 hr
= IMFAttributes_GetBlobSize(attributes
, &DUMMY_GUID1
, &size
);
1724 ok(hr
== S_OK
, "Failed to get blob size, hr %#lx.\n", hr
);
1725 ok(size
== sizeof(blob
), "Unexpected blob size %u.\n", size
);
1727 hr
= IMFAttributes_GetBlobSize(attributes
, &DUMMY_GUID2
, &size
);
1728 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
1731 hr
= IMFAttributes_GetBlob(attributes
, &DUMMY_GUID1
, blob_value
, sizeof(blob_value
), &size
);
1732 ok(hr
== S_OK
, "Failed to get blob, hr %#lx.\n", hr
);
1733 ok(size
== sizeof(blob
), "Unexpected blob size %u.\n", size
);
1734 ok(!memcmp(blob_value
, blob
, size
), "Unexpected blob.\n");
1736 hr
= IMFAttributes_GetBlob(attributes
, &DUMMY_GUID2
, blob_value
, sizeof(blob_value
), &size
);
1737 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
1739 memset(blob_value
, 0, sizeof(blob_value
));
1741 hr
= IMFAttributes_GetAllocatedBlob(attributes
, &DUMMY_GUID1
, &blob_buf
, &size
);
1742 ok(hr
== S_OK
, "Failed to get allocated blob, hr %#lx.\n", hr
);
1743 ok(size
== sizeof(blob
), "Unexpected blob size %u.\n", size
);
1744 ok(!memcmp(blob_buf
, blob
, size
), "Unexpected blob.\n");
1745 CoTaskMemFree(blob_buf
);
1747 hr
= IMFAttributes_GetAllocatedBlob(attributes
, &DUMMY_GUID2
, &blob_buf
, &size
);
1748 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
1750 hr
= IMFAttributes_GetBlob(attributes
, &DUMMY_GUID1
, blob_value
, sizeof(blob
) - 1, NULL
);
1751 ok(hr
== E_NOT_SUFFICIENT_BUFFER
, "Unexpected hr %#lx.\n", hr
);
1753 IMFAttributes_Release(attributes
);
1754 IMFAttributes_Release(attributes1
);
1757 hr
= MFCreateAttributes(&attributes
, 0);
1758 ok(hr
== S_OK
, "Failed to create attributes object, hr %#lx.\n", hr
);
1759 hr
= MFCreateAttributes(&attributes1
, 0);
1760 ok(hr
== S_OK
, "Failed to create attributes object, hr %#lx.\n", hr
);
1762 hr
= IMFAttributes_Compare(attributes
, attributes
, MF_ATTRIBUTES_MATCH_SMALLER
+ 1, &result
);
1763 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
1765 for (match_type
= MF_ATTRIBUTES_MATCH_OUR_ITEMS
; match_type
<= MF_ATTRIBUTES_MATCH_SMALLER
; ++match_type
)
1768 hr
= IMFAttributes_Compare(attributes
, attributes
, match_type
, &result
);
1769 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1770 ok(result
, "Unexpected result %d.\n", result
);
1773 hr
= IMFAttributes_Compare(attributes
, attributes1
, match_type
, &result
);
1774 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1775 ok(result
, "Unexpected result %d.\n", result
);
1778 hr
= IMFAttributes_SetUINT32(attributes
, &DUMMY_GUID1
, 1);
1779 ok(hr
== S_OK
, "Failed to set value, hr %#lx.\n", hr
);
1782 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_OUR_ITEMS
, &result
);
1783 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1784 ok(!result
, "Unexpected result %d.\n", result
);
1787 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1788 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1789 ok(!result
, "Unexpected result %d.\n", result
);
1792 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1793 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1794 ok(result
, "Unexpected result %d.\n", result
);
1797 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1798 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1799 ok(result
, "Unexpected result %d.\n", result
);
1801 hr
= IMFAttributes_SetUINT32(attributes1
, &DUMMY_GUID1
, 2);
1802 ok(hr
== S_OK
, "Failed to set value, hr %#lx.\n", hr
);
1805 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1806 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1807 ok(!result
, "Unexpected result %d.\n", result
);
1810 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_OUR_ITEMS
, &result
);
1811 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1812 ok(!result
, "Unexpected result %d.\n", result
);
1815 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_THEIR_ITEMS
, &result
);
1816 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1817 ok(!result
, "Unexpected result %d.\n", result
);
1820 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1821 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1822 ok(!result
, "Unexpected result %d.\n", result
);
1825 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1826 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1827 ok(!result
, "Unexpected result %d.\n", result
);
1830 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1831 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1832 ok(!result
, "Unexpected result %d.\n", result
);
1835 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_OUR_ITEMS
, &result
);
1836 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1837 ok(!result
, "Unexpected result %d.\n", result
);
1840 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_THEIR_ITEMS
, &result
);
1841 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1842 ok(!result
, "Unexpected result %d.\n", result
);
1845 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1846 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1847 ok(!result
, "Unexpected result %d.\n", result
);
1850 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1851 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1852 ok(!result
, "Unexpected result %d.\n", result
);
1854 hr
= IMFAttributes_SetUINT32(attributes1
, &DUMMY_GUID1
, 1);
1855 ok(hr
== S_OK
, "Failed to set value, hr %#lx.\n", hr
);
1858 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1859 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1860 ok(result
, "Unexpected result %d.\n", result
);
1863 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_THEIR_ITEMS
, &result
);
1864 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1865 ok(result
, "Unexpected result %d.\n", result
);
1868 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1869 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1870 ok(result
, "Unexpected result %d.\n", result
);
1873 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1874 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1875 ok(result
, "Unexpected result %d.\n", result
);
1878 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1879 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1880 ok(result
, "Unexpected result %d.\n", result
);
1883 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_THEIR_ITEMS
, &result
);
1884 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1885 ok(result
, "Unexpected result %d.\n", result
);
1888 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1889 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1890 ok(result
, "Unexpected result %d.\n", result
);
1893 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1894 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1895 ok(result
, "Unexpected result %d.\n", result
);
1897 hr
= IMFAttributes_SetUINT32(attributes1
, &DUMMY_GUID2
, 2);
1898 ok(hr
== S_OK
, "Failed to set value, hr %#lx.\n", hr
);
1901 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1902 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1903 ok(!result
, "Unexpected result %d.\n", result
);
1906 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_THEIR_ITEMS
, &result
);
1907 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1908 ok(!result
, "Unexpected result %d.\n", result
);
1911 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_OUR_ITEMS
, &result
);
1912 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1913 ok(result
, "Unexpected result %d.\n", result
);
1916 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1917 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1918 ok(result
, "Unexpected result %d.\n", result
);
1921 hr
= IMFAttributes_Compare(attributes
, attributes1
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1922 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1923 ok(result
, "Unexpected result %d.\n", result
);
1926 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_ALL_ITEMS
, &result
);
1927 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1928 ok(!result
, "Unexpected result %d.\n", result
);
1931 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_THEIR_ITEMS
, &result
);
1932 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1933 ok(result
, "Unexpected result %d.\n", result
);
1936 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_OUR_ITEMS
, &result
);
1937 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1938 ok(!result
, "Unexpected result %d.\n", result
);
1941 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_INTERSECTION
, &result
);
1942 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1943 ok(result
, "Unexpected result %d.\n", result
);
1946 hr
= IMFAttributes_Compare(attributes1
, attributes
, MF_ATTRIBUTES_MATCH_SMALLER
, &result
);
1947 ok(hr
== S_OK
, "Failed to compare, hr %#lx.\n", hr
);
1948 ok(result
, "Unexpected result %d.\n", result
);
1950 IMFAttributes_Release(attributes
);
1951 IMFAttributes_Release(attributes1
);
1954 static void test_MFCreateMFByteStreamOnStream(void)
1956 IMFByteStream
*bytestream
;
1957 IMFByteStream
*bytestream2
;
1959 IMFAttributes
*attributes
= NULL
;
1960 DWORD caps
, written
;
1966 if(!pMFCreateMFByteStreamOnStream
)
1968 win_skip("MFCreateMFByteStreamOnStream() not found\n");
1972 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
1973 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1976 hr
= IStream_Write(stream
, &caps
, sizeof(caps
), &written
);
1977 ok(hr
== S_OK
, "Failed to write, hr %#lx.\n", hr
);
1979 hr
= pMFCreateMFByteStreamOnStream(stream
, &bytestream
);
1980 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1982 hr
= IMFByteStream_QueryInterface(bytestream
, &IID_IUnknown
,
1984 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1985 ok((void *)unknown
== (void *)bytestream
, "got %p\n", unknown
);
1986 ref
= IUnknown_Release(unknown
);
1987 ok(ref
== 1, "got %lu\n", ref
);
1989 hr
= IUnknown_QueryInterface(unknown
, &IID_IMFByteStream
,
1990 (void **)&bytestream2
);
1991 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
1992 ok(bytestream2
== bytestream
, "got %p\n", bytestream2
);
1993 ref
= IMFByteStream_Release(bytestream2
);
1994 ok(ref
== 1, "got %lu\n", ref
);
1996 hr
= IMFByteStream_QueryInterface(bytestream
, &IID_IMFAttributes
,
1997 (void **)&attributes
);
2000 broken(hr
== E_NOINTERFACE
), "Unexpected hr %#lx.\n", hr
);
2004 win_skip("Cannot retrieve IMFAttributes interface from IMFByteStream\n");
2005 IStream_Release(stream
);
2006 IMFByteStream_Release(bytestream
);
2010 ok(attributes
!= NULL
, "got NULL\n");
2011 hr
= IMFAttributes_GetCount(attributes
, &count
);
2012 ok(hr
== S_OK
, "Failed to get attributes count, hr %#lx.\n", hr
);
2013 ok(count
== 0, "Unexpected attributes count %u.\n", count
);
2015 hr
= IMFAttributes_QueryInterface(attributes
, &IID_IUnknown
,
2017 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2018 ok((void *)unknown
== (void *)bytestream
, "got %p\n", unknown
);
2019 ref
= IUnknown_Release(unknown
);
2020 ok(ref
== 2, "got %lu\n", ref
);
2022 hr
= IMFAttributes_QueryInterface(attributes
, &IID_IMFByteStream
,
2023 (void **)&bytestream2
);
2024 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2025 ok(bytestream2
== bytestream
, "got %p\n", bytestream2
);
2026 ref
= IMFByteStream_Release(bytestream2
);
2027 ok(ref
== 2, "got %lu\n", ref
);
2029 check_interface(bytestream
, &IID_IMFByteStreamBuffering
, FALSE
);
2030 check_interface(bytestream
, &IID_IMFByteStreamCacheControl
, FALSE
);
2031 check_interface(bytestream
, &IID_IMFMediaEventGenerator
, FALSE
);
2032 check_interface(bytestream
, &IID_IMFGetService
, FALSE
);
2034 hr
= IMFByteStream_GetCapabilities(bytestream
, &caps
);
2035 ok(hr
== S_OK
, "Failed to get stream capabilities, hr %#lx.\n", hr
);
2036 ok(caps
== (MFBYTESTREAM_IS_READABLE
| MFBYTESTREAM_IS_SEEKABLE
), "Unexpected caps %#lx.\n", caps
);
2038 hr
= IMFByteStream_Close(bytestream
);
2039 ok(hr
== S_OK
, "Failed to close, hr %#lx.\n", hr
);
2041 hr
= IMFByteStream_Close(bytestream
);
2042 ok(hr
== S_OK
, "Failed to close, hr %#lx.\n", hr
);
2044 hr
= IMFByteStream_GetCapabilities(bytestream
, &caps
);
2045 ok(hr
== S_OK
, "Failed to get stream capabilities, hr %#lx.\n", hr
);
2046 ok(caps
== (MFBYTESTREAM_IS_READABLE
| MFBYTESTREAM_IS_SEEKABLE
), "Unexpected caps %#lx.\n", caps
);
2049 hr
= IMFByteStream_Read(bytestream
, (BYTE
*)&caps
, sizeof(caps
), &size
);
2050 ok(hr
== S_OK
, "Failed to read from stream, hr %#lx.\n", hr
);
2051 ok(caps
== 0xffff0000, "Unexpected content.\n");
2053 IMFAttributes_Release(attributes
);
2054 IMFByteStream_Release(bytestream
);
2055 IStream_Release(stream
);
2058 static void test_file_stream(void)
2060 static const WCHAR newfilename
[] = L
"new.mp4";
2061 IMFByteStream
*bytestream
, *bytestream2
;
2062 QWORD bytestream_length
, position
;
2063 IMFAttributes
*attributes
= NULL
;
2064 MF_ATTRIBUTE_TYPE item_type
;
2065 WCHAR pathW
[MAX_PATH
];
2073 filename
= load_resource(L
"test.mp4");
2075 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
2076 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2078 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
,
2079 MF_FILEFLAGS_NONE
, filename
, &bytestream
);
2080 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2082 check_interface(bytestream
, &IID_IMFByteStreamBuffering
, FALSE
);
2083 check_interface(bytestream
, &IID_IMFByteStreamCacheControl
, FALSE
);
2084 check_interface(bytestream
, &IID_IMFMediaEventGenerator
, FALSE
);
2085 check_interface(bytestream
, &IID_IMFGetService
, TRUE
);
2087 hr
= IMFByteStream_GetCapabilities(bytestream
, &caps
);
2088 ok(hr
== S_OK
, "Failed to get stream capabilities, hr %#lx.\n", hr
);
2091 ok(caps
== (MFBYTESTREAM_IS_READABLE
| MFBYTESTREAM_IS_SEEKABLE
| MFBYTESTREAM_DOES_NOT_USE_NETWORK
),
2092 "Unexpected caps %#lx.\n", caps
);
2095 ok(caps
== (MFBYTESTREAM_IS_READABLE
| MFBYTESTREAM_IS_SEEKABLE
), "Unexpected caps %#lx.\n", caps
);
2097 hr
= IMFByteStream_QueryInterface(bytestream
, &IID_IMFAttributes
,
2098 (void **)&attributes
);
2099 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2100 ok(attributes
!= NULL
, "got NULL\n");
2102 hr
= IMFAttributes_GetCount(attributes
, &count
);
2103 ok(hr
== S_OK
, "Failed to get attributes count, hr %#lx.\n", hr
);
2104 ok(count
== 2, "Unexpected attributes count %u.\n", count
);
2106 /* Original file name. */
2107 hr
= IMFAttributes_GetAllocatedString(attributes
, &MF_BYTESTREAM_ORIGIN_NAME
, &str
, &count
);
2108 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
2109 ok(!lstrcmpW(str
, filename
), "Unexpected name %s.\n", wine_dbgstr_w(str
));
2112 /* Modification time. */
2113 hr
= IMFAttributes_GetItemType(attributes
, &MF_BYTESTREAM_LAST_MODIFIED_TIME
, &item_type
);
2114 ok(hr
== S_OK
, "Failed to get item type, hr %#lx.\n", hr
);
2115 ok(item_type
== MF_ATTRIBUTE_BLOB
, "Unexpected item type.\n");
2117 IMFAttributes_Release(attributes
);
2120 hr
= IMFByteStream_GetLength(bytestream
, NULL
);
2121 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2123 bytestream_length
= 0;
2124 hr
= IMFByteStream_GetLength(bytestream
, &bytestream_length
);
2125 ok(hr
== S_OK
, "Failed to get bytestream length, hr %#lx.\n", hr
);
2126 ok(bytestream_length
> 0, "Unexpected bytestream length %s.\n", wine_dbgstr_longlong(bytestream_length
));
2128 hr
= IMFByteStream_SetCurrentPosition(bytestream
, bytestream_length
);
2129 ok(hr
== S_OK
, "Failed to set bytestream position, hr %#lx.\n", hr
);
2131 hr
= IMFByteStream_IsEndOfStream(bytestream
, &eos
);
2132 ok(hr
== S_OK
, "Failed query end of stream, hr %#lx.\n", hr
);
2133 ok(eos
== TRUE
, "Unexpected IsEndOfStream result, %u.\n", eos
);
2135 hr
= IMFByteStream_SetCurrentPosition(bytestream
, 2 * bytestream_length
);
2136 ok(hr
== S_OK
, "Failed to set bytestream position, hr %#lx.\n", hr
);
2138 hr
= IMFByteStream_GetCurrentPosition(bytestream
, NULL
);
2139 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2141 hr
= IMFByteStream_GetCurrentPosition(bytestream
, &position
);
2142 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2143 ok(position
== 2 * bytestream_length
, "Unexpected position.\n");
2145 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
,
2146 MF_FILEFLAGS_NONE
, filename
, &bytestream2
);
2147 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2148 IMFByteStream_Release(bytestream2
);
2150 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, filename
, &bytestream2
);
2151 ok(hr
== HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION
), "Unexpected hr %#lx.\n", hr
);
2153 hr
= MFCreateFile(MF_ACCESSMODE_READWRITE
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, filename
, &bytestream2
);
2154 ok(hr
== HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION
), "Unexpected hr %#lx.\n", hr
);
2156 IMFByteStream_Release(bytestream
);
2158 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
,
2159 MF_FILEFLAGS_NONE
, newfilename
, &bytestream
);
2160 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Unexpected hr %#lx.\n", hr
);
2162 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_EXIST
,
2163 MF_FILEFLAGS_NONE
, filename
, &bytestream
);
2164 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_EXISTS
), "Unexpected hr %#lx.\n", hr
);
2166 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_EXIST
,
2167 MF_FILEFLAGS_NONE
, newfilename
, &bytestream
);
2168 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2170 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, newfilename
, &bytestream2
);
2171 ok(hr
== HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION
), "Unexpected hr %#lx.\n", hr
);
2173 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, newfilename
, &bytestream2
);
2174 ok(hr
== HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION
), "Unexpected hr %#lx.\n", hr
);
2176 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_ALLOW_WRITE_SHARING
,
2177 newfilename
, &bytestream2
);
2178 ok(hr
== HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION
), "Unexpected hr %#lx.\n", hr
);
2180 IMFByteStream_Release(bytestream
);
2182 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_NOT_EXIST
,
2183 MF_FILEFLAGS_ALLOW_WRITE_SHARING
, newfilename
, &bytestream
);
2184 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2186 /* Opening the file again fails even though MF_FILEFLAGS_ALLOW_WRITE_SHARING is set. */
2187 hr
= MFCreateFile(MF_ACCESSMODE_WRITE
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_ALLOW_WRITE_SHARING
,
2188 newfilename
, &bytestream2
);
2189 ok(hr
== HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION
), "Unexpected hr %#lx.\n", hr
);
2191 IMFByteStream_Release(bytestream
);
2193 /* Explicit file: scheme */
2194 lstrcpyW(pathW
, fileschemeW
);
2195 lstrcatW(pathW
, filename
);
2196 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, pathW
, &bytestream
);
2197 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
2199 hr
= MFCreateFile(MF_ACCESSMODE_READ
, MF_OPENMODE_FAIL_IF_NOT_EXIST
, MF_FILEFLAGS_NONE
, filename
, &bytestream
);
2200 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2201 ok(DeleteFileW(filename
), "failed to delete file\n");
2202 IMFByteStream_Release(bytestream
);
2205 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
2207 DeleteFileW(newfilename
);
2210 static void test_system_memory_buffer(void)
2212 IMFMediaBuffer
*buffer
;
2217 hr
= MFCreateMemoryBuffer(1024, NULL
);
2218 ok(hr
== E_INVALIDARG
|| hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2220 hr
= MFCreateMemoryBuffer(0, &buffer
);
2221 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2224 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
2225 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2226 ok(length
== 0, "got %lu\n", length
);
2228 IMFMediaBuffer_Release(buffer
);
2231 hr
= MFCreateMemoryBuffer(1024, &buffer
);
2232 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2234 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
2236 hr
= IMFMediaBuffer_GetMaxLength(buffer
, NULL
);
2237 ok(hr
== E_INVALIDARG
|| hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2239 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
2240 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2241 ok(length
== 1024, "got %lu\n", length
);
2243 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 1025);
2244 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2246 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 10);
2247 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2249 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, NULL
);
2250 ok(hr
== E_INVALIDARG
|| hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2252 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
2253 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2254 ok(length
== 10, "got %lu\n", length
);
2258 hr
= IMFMediaBuffer_Lock(buffer
, NULL
, &length
, &max
);
2259 ok(hr
== E_INVALIDARG
|| hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2260 ok(length
== 0, "got %lu\n", length
);
2261 ok(max
== 0, "got %lu\n", length
);
2263 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max
, &length
);
2264 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2265 ok(length
== 10, "got %lu\n", length
);
2266 ok(max
== 1024, "got %lu\n", max
);
2268 /* Attempt to lock the buffer twice */
2269 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, &max
, &length
);
2270 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2271 ok(data
== data2
, "Unexpected hr %#lx.\n", hr
);
2273 hr
= IMFMediaBuffer_Unlock(buffer
);
2274 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2276 hr
= IMFMediaBuffer_Unlock(buffer
);
2277 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2279 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
2280 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2282 hr
= IMFMediaBuffer_Unlock(buffer
);
2283 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2286 hr
= IMFMediaBuffer_Unlock(buffer
);
2287 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2289 IMFMediaBuffer_Release(buffer
);
2292 static void test_system_memory_aligned_buffer(void)
2294 static const DWORD alignments
[] =
2296 MF_16_BYTE_ALIGNMENT
,
2297 MF_32_BYTE_ALIGNMENT
,
2298 MF_64_BYTE_ALIGNMENT
,
2299 MF_128_BYTE_ALIGNMENT
,
2300 MF_256_BYTE_ALIGNMENT
,
2301 MF_512_BYTE_ALIGNMENT
,
2303 IMFMediaBuffer
*buffer
;
2309 hr
= MFCreateAlignedMemoryBuffer(16, MF_8_BYTE_ALIGNMENT
, NULL
);
2310 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
2312 hr
= MFCreateAlignedMemoryBuffer(201, MF_8_BYTE_ALIGNMENT
, &buffer
);
2313 ok(hr
== S_OK
, "Failed to create memory buffer, hr %#lx.\n", hr
);
2315 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
2316 ok(hr
== S_OK
, "Failed to get current length, hr %#lx.\n", hr
);
2317 ok(length
== 0, "Unexpected current length %lu.\n", length
);
2319 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 1);
2320 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
2321 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
2322 ok(hr
== S_OK
, "Failed to get current length, hr %#lx.\n", hr
);
2323 ok(length
== 1, "Unexpected current length %lu.\n", length
);
2325 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
2326 ok(hr
== S_OK
, "Failed to get max length, hr %#lx.\n", hr
);
2327 ok(length
== 201, "Unexpected max length %lu.\n", length
);
2329 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 202);
2330 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2331 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
2332 ok(hr
== S_OK
, "Failed to get max length, hr %#lx.\n", hr
);
2333 ok(length
== 201, "Unexpected max length %lu.\n", length
);
2334 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 10);
2335 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
2337 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max
, &length
);
2338 ok(hr
== S_OK
, "Failed to lock, hr %#lx.\n", hr
);
2339 ok(max
== 201 && length
== 10, "Unexpected length.\n");
2340 hr
= IMFMediaBuffer_Unlock(buffer
);
2341 ok(hr
== S_OK
, "Failed to unlock, hr %#lx.\n", hr
);
2343 IMFMediaBuffer_Release(buffer
);
2345 for (i
= 0; i
< ARRAY_SIZE(alignments
); ++i
)
2347 hr
= MFCreateAlignedMemoryBuffer(200, alignments
[i
], &buffer
);
2348 ok(hr
== S_OK
, "Failed to create memory buffer, hr %#lx.\n", hr
);
2350 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max
, &length
);
2351 ok(hr
== S_OK
, "Failed to lock, hr %#lx.\n", hr
);
2352 ok(max
== 200 && !length
, "Unexpected length.\n");
2353 ok(!((uintptr_t)data
& alignments
[i
]), "Data at %p is misaligned.\n", data
);
2354 hr
= IMFMediaBuffer_Unlock(buffer
);
2355 ok(hr
== S_OK
, "Failed to unlock, hr %#lx.\n", hr
);
2357 IMFMediaBuffer_Release(buffer
);
2360 hr
= MFCreateAlignedMemoryBuffer(200, 0, &buffer
);
2361 ok(hr
== S_OK
, "Failed to create memory buffer, hr %#lx.\n", hr
);
2362 IMFMediaBuffer_Release(buffer
);
2365 static void test_sample(void)
2367 static const DWORD test_pattern
= 0x22222222;
2368 IMFMediaBuffer
*buffer
, *buffer2
, *buffer3
;
2369 DWORD count
, flags
, length
;
2370 IMFAttributes
*attributes
;
2376 hr
= MFCreateSample( &sample
);
2377 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2379 hr
= IMFSample_QueryInterface(sample
, &IID_IMFAttributes
, (void **)&attributes
);
2380 ok(hr
== S_OK
, "Failed to get attributes interface, hr %#lx.\n", hr
);
2382 CHECK_ATTR_COUNT(attributes
, 0);
2384 hr
= IMFSample_GetBufferCount(sample
, NULL
);
2385 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2387 hr
= IMFSample_GetBufferCount(sample
, &count
);
2388 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2389 ok(count
== 0, "got %ld\n", count
);
2391 hr
= IMFSample_GetSampleFlags(sample
, &flags
);
2392 ok(hr
== S_OK
, "Failed to get sample flags, hr %#lx.\n", hr
);
2393 ok(!flags
, "Unexpected flags %#lx.\n", flags
);
2395 hr
= IMFSample_SetSampleFlags(sample
, 0x123);
2396 ok(hr
== S_OK
, "Failed to set sample flags, hr %#lx.\n", hr
);
2397 hr
= IMFSample_GetSampleFlags(sample
, &flags
);
2398 ok(hr
== S_OK
, "Failed to get sample flags, hr %#lx.\n", hr
);
2399 ok(flags
== 0x123, "Unexpected flags %#lx.\n", flags
);
2401 hr
= IMFSample_GetSampleTime(sample
, &time
);
2402 ok(hr
== MF_E_NO_SAMPLE_TIMESTAMP
, "Unexpected hr %#lx.\n", hr
);
2404 hr
= IMFSample_GetSampleDuration(sample
, &time
);
2405 ok(hr
== MF_E_NO_SAMPLE_DURATION
, "Unexpected hr %#lx.\n", hr
);
2407 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
2408 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2410 hr
= IMFSample_RemoveBufferByIndex(sample
, 0);
2411 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2413 hr
= IMFSample_RemoveAllBuffers(sample
);
2414 ok(hr
== S_OK
, "Failed to remove all, hr %#lx.\n", hr
);
2416 hr
= IMFSample_GetTotalLength(sample
, &length
);
2417 ok(hr
== S_OK
, "Failed to get total length, hr %#lx.\n", hr
);
2418 ok(!length
, "Unexpected total length %lu.\n", length
);
2420 hr
= MFCreateMemoryBuffer(16, &buffer
);
2421 ok(hr
== S_OK
, "Failed to create buffer, hr %#lx.\n", hr
);
2423 hr
= IMFSample_AddBuffer(sample
, buffer
);
2424 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2426 hr
= IMFSample_AddBuffer(sample
, buffer
);
2427 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2429 hr
= IMFSample_GetBufferCount(sample
, &count
);
2430 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
2431 ok(count
== 2, "Unexpected buffer count %lu.\n", count
);
2433 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer2
);
2434 ok(hr
== S_OK
, "Failed to get buffer, hr %#lx.\n", hr
);
2435 ok(buffer2
== buffer
, "Unexpected object.\n");
2436 IMFMediaBuffer_Release(buffer2
);
2438 hr
= IMFSample_GetTotalLength(sample
, &length
);
2439 ok(hr
== S_OK
, "Failed to get total length, hr %#lx.\n", hr
);
2440 ok(!length
, "Unexpected total length %lu.\n", length
);
2442 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 2);
2443 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
2445 hr
= IMFSample_GetTotalLength(sample
, &length
);
2446 ok(hr
== S_OK
, "Failed to get total length, hr %#lx.\n", hr
);
2447 ok(length
== 4, "Unexpected total length %lu.\n", length
);
2449 hr
= IMFSample_RemoveBufferByIndex(sample
, 1);
2450 ok(hr
== S_OK
, "Failed to remove buffer, hr %#lx.\n", hr
);
2452 hr
= IMFSample_GetTotalLength(sample
, &length
);
2453 ok(hr
== S_OK
, "Failed to get total length, hr %#lx.\n", hr
);
2454 ok(length
== 2, "Unexpected total length %lu.\n", length
);
2456 IMFMediaBuffer_Release(buffer
);
2459 hr
= IMFSample_SetSampleDuration(sample
, 10);
2460 ok(hr
== S_OK
, "Failed to set duration, hr %#lx.\n", hr
);
2461 CHECK_ATTR_COUNT(attributes
, 0);
2462 hr
= IMFSample_GetSampleDuration(sample
, &time
);
2463 ok(hr
== S_OK
, "Failed to get sample duration, hr %#lx.\n", hr
);
2464 ok(time
== 10, "Unexpected duration.\n");
2467 hr
= IMFSample_SetSampleTime(sample
, 1);
2468 ok(hr
== S_OK
, "Failed to set timestamp, hr %#lx.\n", hr
);
2469 CHECK_ATTR_COUNT(attributes
, 0);
2470 hr
= IMFSample_GetSampleTime(sample
, &time
);
2471 ok(hr
== S_OK
, "Failed to get sample time, hr %#lx.\n", hr
);
2472 ok(time
== 1, "Unexpected timestamp.\n");
2474 IMFAttributes_Release(attributes
);
2475 IMFSample_Release(sample
);
2477 /* CopyToBuffer() */
2478 hr
= MFCreateSample(&sample
);
2479 ok(hr
== S_OK
, "Failed to create a sample, hr %#lx.\n", hr
);
2481 hr
= MFCreateMemoryBuffer(16, &buffer2
);
2482 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
2484 /* Sample with no buffers. */
2485 hr
= IMFMediaBuffer_SetCurrentLength(buffer2
, 1);
2486 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
2487 hr
= IMFSample_CopyToBuffer(sample
, buffer2
);
2488 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2489 hr
= IMFMediaBuffer_GetCurrentLength(buffer2
, &length
);
2490 ok(hr
== S_OK
, "Failed to get current length, hr %#lx.\n", hr
);
2491 ok(!length
, "Unexpected length %lu.\n", length
);
2493 /* Single buffer, larger destination. */
2494 hr
= MFCreateMemoryBuffer(8, &buffer
);
2495 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
2497 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
2498 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
2499 *(DWORD
*)data
= 0x11111111;
2500 hr
= IMFMediaBuffer_Unlock(buffer
);
2501 ok(hr
== S_OK
, "Failed to unlock, hr %#lx.\n", hr
);
2502 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 4);
2503 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
2505 hr
= IMFSample_AddBuffer(sample
, buffer
);
2506 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2508 /* Existing content is overwritten. */
2509 hr
= IMFMediaBuffer_SetCurrentLength(buffer2
, 8);
2510 ok(hr
== S_OK
, "Failed to set length, hr %#lx.\n", hr
);
2512 hr
= IMFSample_CopyToBuffer(sample
, buffer2
);
2513 ok(hr
== S_OK
, "Failed to copy to buffer, hr %#lx.\n", hr
);
2515 hr
= IMFMediaBuffer_GetCurrentLength(buffer2
, &length
);
2516 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
2517 ok(length
== 4, "Unexpected buffer length %lu.\n", length
);
2519 /* Multiple buffers, matching total size. */
2520 hr
= IMFSample_AddBuffer(sample
, buffer
);
2521 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2523 hr
= IMFSample_GetBufferCount(sample
, &count
);
2524 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
2525 ok(count
== 2, "Unexpected buffer count %lu.\n", count
);
2527 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 8);
2528 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
2530 hr
= IMFSample_CopyToBuffer(sample
, buffer2
);
2531 ok(hr
== S_OK
, "Failed to copy to buffer, hr %#lx.\n", hr
);
2533 hr
= IMFMediaBuffer_GetCurrentLength(buffer2
, &length
);
2534 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
2535 ok(length
== 16, "Unexpected buffer length %lu.\n", length
);
2537 hr
= IMFSample_AddBuffer(sample
, buffer
);
2538 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2540 hr
= IMFMediaBuffer_SetCurrentLength(buffer2
, 1);
2541 ok(hr
== S_OK
, "Failed to set buffer length, hr %#lx.\n", hr
);
2543 hr
= IMFMediaBuffer_Lock(buffer2
, &data
, NULL
, NULL
);
2544 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
2545 *(DWORD
*)data
= test_pattern
;
2546 hr
= IMFMediaBuffer_Unlock(buffer2
);
2547 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
2549 hr
= IMFSample_CopyToBuffer(sample
, buffer2
);
2550 ok(hr
== MF_E_BUFFERTOOSMALL
, "Unexpected hr %#lx.\n", hr
);
2552 hr
= IMFMediaBuffer_Lock(buffer2
, &data
, NULL
, NULL
);
2553 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
2554 ok(!memcmp(data
, &test_pattern
, sizeof(test_pattern
)), "Unexpected contents, %#lx\n", *(DWORD
*)data
);
2555 hr
= IMFMediaBuffer_Unlock(buffer2
);
2556 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
2558 hr
= IMFMediaBuffer_GetCurrentLength(buffer2
, &length
);
2559 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
2560 ok(!length
, "Unexpected buffer length %lu.\n", length
);
2562 IMFMediaBuffer_Release(buffer2
);
2563 IMFSample_Release(sample
);
2565 /* ConvertToContiguousBuffer() */
2566 hr
= MFCreateSample(&sample
);
2567 ok(hr
== S_OK
, "Failed to create a sample, hr %#lx.\n", hr
);
2569 hr
= IMFSample_ConvertToContiguousBuffer(sample
, &buffer
);
2570 ok(hr
== E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
2572 hr
= MFCreateMemoryBuffer(16, &buffer
);
2573 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
2575 hr
= IMFSample_AddBuffer(sample
, buffer
);
2576 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2578 hr
= IMFSample_ConvertToContiguousBuffer(sample
, &buffer2
);
2579 ok(hr
== S_OK
, "Failed to convert, hr %#lx.\n", hr
);
2580 ok(buffer2
== buffer
, "Unexpected buffer instance.\n");
2581 IMFMediaBuffer_Release(buffer2
);
2583 hr
= IMFSample_ConvertToContiguousBuffer(sample
, NULL
);
2584 ok(hr
== S_OK
, "Failed to convert, hr %#lx.\n", hr
);
2586 hr
= IMFSample_ConvertToContiguousBuffer(sample
, &buffer2
);
2587 ok(hr
== S_OK
, "Failed to convert, hr %#lx.\n", hr
);
2588 ok(buffer2
== buffer
, "Unexpected buffer instance.\n");
2589 IMFMediaBuffer_Release(buffer2
);
2591 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 3);
2592 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2594 hr
= MFCreateMemoryBuffer(16, &buffer2
);
2595 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
2597 hr
= IMFMediaBuffer_SetCurrentLength(buffer2
, 4);
2598 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2600 hr
= IMFSample_AddBuffer(sample
, buffer2
);
2601 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2602 IMFMediaBuffer_Release(buffer2
);
2604 hr
= IMFSample_GetBufferCount(sample
, &count
);
2605 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
2606 ok(count
== 2, "Unexpected buffer count %lu.\n", count
);
2608 hr
= IMFSample_ConvertToContiguousBuffer(sample
, &buffer3
);
2609 ok(hr
== S_OK
, "Failed to convert, hr %#lx.\n", hr
);
2611 hr
= IMFMediaBuffer_GetMaxLength(buffer3
, &length
);
2612 ok(hr
== S_OK
, "Failed to get maximum length, hr %#lx.\n", hr
);
2613 ok(length
== 7, "Unexpected length %lu.\n", length
);
2615 hr
= IMFMediaBuffer_GetCurrentLength(buffer3
, &length
);
2616 ok(hr
== S_OK
, "Failed to get maximum length, hr %#lx.\n", hr
);
2617 ok(length
== 7, "Unexpected length %lu.\n", length
);
2619 IMFMediaBuffer_Release(buffer3
);
2621 hr
= IMFSample_GetBufferCount(sample
, &count
);
2622 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
2623 ok(count
== 1, "Unexpected buffer count %lu.\n", count
);
2625 hr
= IMFSample_AddBuffer(sample
, buffer
);
2626 ok(hr
== S_OK
, "Failed to add buffer, hr %#lx.\n", hr
);
2628 hr
= IMFSample_GetBufferCount(sample
, &count
);
2629 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
2630 ok(count
== 2, "Unexpected buffer count %lu.\n", count
);
2632 hr
= IMFSample_ConvertToContiguousBuffer(sample
, NULL
);
2633 ok(hr
== S_OK
, "Failed to convert, hr %#lx.\n", hr
);
2635 hr
= IMFSample_GetBufferCount(sample
, &count
);
2636 ok(hr
== S_OK
, "Failed to get buffer count, hr %#lx.\n", hr
);
2637 ok(count
== 1, "Unexpected buffer count %lu.\n", count
);
2639 IMFMediaBuffer_Release(buffer
);
2641 IMFSample_Release(sample
);
2644 static HRESULT WINAPI
testcallback_Invoke(IMFAsyncCallback
*iface
, IMFAsyncResult
*result
)
2646 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
2647 IMFMediaEventQueue
*queue
;
2648 IUnknown
*state
, *obj
;
2651 ok(result
!= NULL
, "Unexpected result object.\n");
2653 state
= IMFAsyncResult_GetStateNoAddRef(result
);
2654 if (state
&& SUCCEEDED(IUnknown_QueryInterface(state
, &IID_IMFMediaEventQueue
, (void **)&queue
)))
2656 IMFMediaEvent
*event
= NULL
, *event2
;
2660 hr
= IMFMediaEventQueue_GetEvent(queue
, MF_EVENT_FLAG_NO_WAIT
, &event
);
2661 ok(hr
== MF_E_MULTIPLE_SUBSCRIBERS
, "Failed to get event, hr %#lx.\n", hr
);
2663 hr
= IMFMediaEventQueue_GetEvent(queue
, 0, &event
);
2664 ok(hr
== MF_E_MULTIPLE_SUBSCRIBERS
, "Failed to get event, hr %#lx.\n", hr
);
2666 hr
= IMFMediaEventQueue_EndGetEvent(queue
, result
, &event
);
2667 ok(hr
== S_OK
, "Failed to finalize GetEvent, hr %#lx.\n", hr
);
2669 hr
= IMFMediaEventQueue_EndGetEvent(queue
, result
, &event2
);
2670 ok(hr
== E_FAIL
, "Unexpected result, hr %#lx.\n", hr
);
2673 IMFMediaEvent_Release(event
);
2676 hr
= IMFAsyncResult_GetObject(result
, &obj
);
2677 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2679 IMFMediaEventQueue_Release(queue
);
2681 SetEvent(callback
->event
);
2687 static const IMFAsyncCallbackVtbl testcallbackvtbl
=
2689 testcallback_QueryInterface
,
2690 testcallback_AddRef
,
2691 testcallback_Release
,
2692 testcallback_GetParameters
,
2693 testcallback_Invoke
,
2696 static void test_MFCreateAsyncResult(void)
2698 IMFAsyncResult
*result
, *result2
;
2699 struct test_callback
*callback
;
2700 IUnknown
*state
, *object
;
2701 MFASYNCRESULT
*data
;
2708 callback
= create_test_callback(NULL
);
2710 hr
= MFCreateAsyncResult(NULL
, NULL
, NULL
, NULL
);
2711 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
2713 hr
= MFCreateAsyncResult(NULL
, NULL
, NULL
, &result
);
2714 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
2716 data
= (MFASYNCRESULT
*)result
;
2717 ok(data
->pCallback
== NULL
, "Unexpected callback value.\n");
2718 ok(data
->hrStatusResult
== S_OK
, "Unexpected status %#lx.\n", data
->hrStatusResult
);
2719 ok(data
->dwBytesTransferred
== 0, "Unexpected byte length %lu.\n", data
->dwBytesTransferred
);
2720 ok(data
->hEvent
== NULL
, "Unexpected event.\n");
2722 hr
= IMFAsyncResult_GetState(result
, NULL
);
2723 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2725 state
= (void *)0xdeadbeef;
2726 hr
= IMFAsyncResult_GetState(result
, &state
);
2727 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2728 ok(state
== (void *)0xdeadbeef, "Unexpected state.\n");
2730 hr
= IMFAsyncResult_GetStatus(result
);
2731 ok(hr
== S_OK
, "Unexpected status %#lx.\n", hr
);
2733 data
->hrStatusResult
= 123;
2734 hr
= IMFAsyncResult_GetStatus(result
);
2735 ok(hr
== 123, "Unexpected status %#lx.\n", hr
);
2737 hr
= IMFAsyncResult_SetStatus(result
, E_FAIL
);
2738 ok(hr
== S_OK
, "Failed to set status, hr %#lx.\n", hr
);
2739 ok(data
->hrStatusResult
== E_FAIL
, "Unexpected status %#lx.\n", hr
);
2741 hr
= IMFAsyncResult_GetObject(result
, NULL
);
2742 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2744 object
= (void *)0xdeadbeef;
2745 hr
= IMFAsyncResult_GetObject(result
, &object
);
2746 ok(hr
== E_POINTER
, "Failed to get object, hr %#lx.\n", hr
);
2747 ok(object
== (void *)0xdeadbeef, "Unexpected object.\n");
2749 state
= IMFAsyncResult_GetStateNoAddRef(result
);
2750 ok(state
== NULL
, "Unexpected state.\n");
2753 hr
= MFCreateAsyncResult((IUnknown
*)result
, &callback
->IMFAsyncCallback_iface
, NULL
, &result2
);
2754 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
2756 data
= (MFASYNCRESULT
*)result2
;
2757 ok(data
->pCallback
== &callback
->IMFAsyncCallback_iface
, "Unexpected callback value.\n");
2758 ok(data
->hrStatusResult
== S_OK
, "Unexpected status %#lx.\n", data
->hrStatusResult
);
2759 ok(data
->dwBytesTransferred
== 0, "Unexpected byte length %lu.\n", data
->dwBytesTransferred
);
2760 ok(data
->hEvent
== NULL
, "Unexpected event.\n");
2763 hr
= IMFAsyncResult_GetObject(result2
, &object
);
2764 ok(hr
== S_OK
, "Failed to get object, hr %#lx.\n", hr
);
2765 ok(object
== (IUnknown
*)result
, "Unexpected object.\n");
2766 IUnknown_Release(object
);
2768 IMFAsyncResult_Release(result2
);
2771 hr
= MFCreateAsyncResult(NULL
, &callback
->IMFAsyncCallback_iface
, (IUnknown
*)result
, &result2
);
2772 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
2774 data
= (MFASYNCRESULT
*)result2
;
2775 ok(data
->pCallback
== &callback
->IMFAsyncCallback_iface
, "Unexpected callback value.\n");
2776 ok(data
->hrStatusResult
== S_OK
, "Unexpected status %#lx.\n", data
->hrStatusResult
);
2777 ok(data
->dwBytesTransferred
== 0, "Unexpected byte length %lu.\n", data
->dwBytesTransferred
);
2778 ok(data
->hEvent
== NULL
, "Unexpected event.\n");
2781 hr
= IMFAsyncResult_GetState(result2
, &state
);
2782 ok(hr
== S_OK
, "Failed to get state object, hr %#lx.\n", hr
);
2783 ok(state
== (IUnknown
*)result
, "Unexpected state.\n");
2784 IUnknown_Release(state
);
2786 state
= IMFAsyncResult_GetStateNoAddRef(result2
);
2787 ok(state
== (IUnknown
*)result
, "Unexpected state.\n");
2789 refcount
= IMFAsyncResult_Release(result2
);
2790 ok(!refcount
, "Unexpected refcount %lu.\n", refcount
);
2791 refcount
= IMFAsyncResult_Release(result
);
2792 ok(!refcount
, "Unexpected refcount %lu.\n", refcount
);
2794 /* Event handle is closed on release. */
2795 hr
= MFCreateAsyncResult(NULL
, NULL
, NULL
, &result
);
2796 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
2798 data
= (MFASYNCRESULT
*)result
;
2799 data
->hEvent
= event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2800 ok(data
->hEvent
!= NULL
, "Failed to create event.\n");
2801 ret
= GetHandleInformation(event
, &flags
);
2802 ok(ret
, "Failed to get handle info.\n");
2804 refcount
= IMFAsyncResult_Release(result
);
2805 ok(!refcount
, "Unexpected refcount %lu.\n", refcount
);
2806 ret
= GetHandleInformation(event
, &flags
);
2807 ok(!ret
, "Expected handle to be closed.\n");
2809 hr
= MFCreateAsyncResult(NULL
, &callback
->IMFAsyncCallback_iface
, NULL
, &result
);
2810 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
2812 data
= (MFASYNCRESULT
*)result
;
2813 data
->hEvent
= event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2814 ok(data
->hEvent
!= NULL
, "Failed to create event.\n");
2815 ret
= GetHandleInformation(event
, &flags
);
2816 ok(ret
, "Failed to get handle info.\n");
2818 refcount
= IMFAsyncResult_Release(result
);
2819 ok(!refcount
, "Unexpected refcount %lu.\n", refcount
);
2820 ret
= GetHandleInformation(event
, &flags
);
2821 ok(!ret
, "Expected handle to be closed.\n");
2823 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
2826 static void test_startup(void)
2831 hr
= MFStartup(MAKELONG(MF_API_VERSION
, 0xdead), MFSTARTUP_FULL
);
2832 ok(hr
== MF_E_BAD_STARTUP_VERSION
, "Unexpected hr %#lx.\n", hr
);
2834 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
2835 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
2837 hr
= MFAllocateWorkQueue(&queue
);
2838 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
2839 hr
= MFUnlockWorkQueue(queue
);
2840 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
2843 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
2845 hr
= MFAllocateWorkQueue(&queue
);
2846 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2848 /* Already shut down, has no effect. */
2850 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
2852 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
2853 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
2855 hr
= MFAllocateWorkQueue(&queue
);
2856 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
2857 hr
= MFUnlockWorkQueue(queue
);
2858 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
2861 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
2863 /* Platform lock. */
2864 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
2865 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
2867 hr
= MFAllocateWorkQueue(&queue
);
2868 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
2869 hr
= MFUnlockWorkQueue(queue
);
2870 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
2872 /* Unlocking implies shutdown. */
2873 hr
= MFUnlockPlatform();
2874 ok(hr
== S_OK
, "Failed to unlock, %#lx.\n", hr
);
2876 hr
= MFAllocateWorkQueue(&queue
);
2877 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
2879 hr
= MFLockPlatform();
2880 ok(hr
== S_OK
, "Failed to lock, %#lx.\n", hr
);
2882 hr
= MFAllocateWorkQueue(&queue
);
2883 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
2884 hr
= MFUnlockWorkQueue(queue
);
2885 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
2888 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
2891 static void test_allocate_queue(void)
2893 DWORD queue
, queue2
;
2896 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
2897 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
2899 hr
= MFAllocateWorkQueue(&queue
);
2900 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
2901 ok(queue
& MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK
, "Unexpected queue id.\n");
2903 hr
= MFUnlockWorkQueue(queue
);
2904 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
2906 hr
= MFUnlockWorkQueue(queue
);
2907 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
2909 hr
= MFAllocateWorkQueue(&queue2
);
2910 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
2911 ok(queue2
& MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK
, "Unexpected queue id.\n");
2913 hr
= MFUnlockWorkQueue(queue2
);
2914 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
2916 /* Unlock in system queue range. */
2917 hr
= MFUnlockWorkQueue(MFASYNC_CALLBACK_QUEUE_STANDARD
);
2918 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2920 hr
= MFUnlockWorkQueue(MFASYNC_CALLBACK_QUEUE_UNDEFINED
);
2921 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2923 hr
= MFUnlockWorkQueue(0x20);
2924 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2927 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
2930 static void test_MFCopyImage(void)
2932 BYTE dest
[16], src
[16];
2937 win_skip("MFCopyImage() is not available.\n");
2941 memset(dest
, 0xaa, sizeof(dest
));
2942 memset(src
, 0x11, sizeof(src
));
2944 hr
= pMFCopyImage(dest
, 8, src
, 8, 4, 1);
2945 ok(hr
== S_OK
, "Failed to copy image %#lx.\n", hr
);
2946 ok(!memcmp(dest
, src
, 4) && dest
[4] == 0xaa, "Unexpected buffer contents.\n");
2948 memset(dest
, 0xaa, sizeof(dest
));
2949 memset(src
, 0x11, sizeof(src
));
2951 hr
= pMFCopyImage(dest
, 8, src
, 8, 16, 1);
2952 ok(hr
== S_OK
, "Failed to copy image %#lx.\n", hr
);
2953 ok(!memcmp(dest
, src
, 16), "Unexpected buffer contents.\n");
2955 memset(dest
, 0xaa, sizeof(dest
));
2956 memset(src
, 0x11, sizeof(src
));
2958 hr
= pMFCopyImage(dest
, 8, src
, 8, 8, 2);
2959 ok(hr
== S_OK
, "Failed to copy image %#lx.\n", hr
);
2960 ok(!memcmp(dest
, src
, 16), "Unexpected buffer contents.\n");
2963 static void test_MFCreateCollection(void)
2965 IMFCollection
*collection
;
2970 hr
= MFCreateCollection(NULL
);
2971 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2973 hr
= MFCreateCollection(&collection
);
2974 ok(hr
== S_OK
, "Failed to create collection, hr %#lx.\n", hr
);
2976 hr
= IMFCollection_GetElementCount(collection
, NULL
);
2977 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2980 hr
= IMFCollection_GetElementCount(collection
, &count
);
2981 ok(hr
== S_OK
, "Failed to get element count, hr %#lx.\n", hr
);
2982 ok(count
== 0, "Unexpected count %lu.\n", count
);
2984 hr
= IMFCollection_GetElement(collection
, 0, NULL
);
2985 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2987 element
= (void *)0xdeadbeef;
2988 hr
= IMFCollection_GetElement(collection
, 0, &element
);
2989 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
2990 ok(element
== (void *)0xdeadbeef, "Unexpected pointer.\n");
2992 hr
= IMFCollection_RemoveElement(collection
, 0, NULL
);
2993 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
2995 element
= (void *)0xdeadbeef;
2996 hr
= IMFCollection_RemoveElement(collection
, 0, &element
);
2997 ok(hr
== E_INVALIDARG
, "Failed to remove element, hr %#lx.\n", hr
);
2998 ok(element
== (void *)0xdeadbeef, "Unexpected pointer.\n");
3000 hr
= IMFCollection_RemoveAllElements(collection
);
3001 ok(hr
== S_OK
, "Failed to clear, hr %#lx.\n", hr
);
3003 hr
= IMFCollection_AddElement(collection
, (IUnknown
*)collection
);
3004 ok(hr
== S_OK
, "Failed to add element, hr %#lx.\n", hr
);
3007 hr
= IMFCollection_GetElementCount(collection
, &count
);
3008 ok(hr
== S_OK
, "Failed to get element count, hr %#lx.\n", hr
);
3009 ok(count
== 1, "Unexpected count %lu.\n", count
);
3011 hr
= IMFCollection_AddElement(collection
, NULL
);
3012 ok(hr
== S_OK
, "Failed to add element, hr %#lx.\n", hr
);
3015 hr
= IMFCollection_GetElementCount(collection
, &count
);
3016 ok(hr
== S_OK
, "Failed to get element count, hr %#lx.\n", hr
);
3017 ok(count
== 2, "Unexpected count %lu.\n", count
);
3019 hr
= IMFCollection_InsertElementAt(collection
, 10, (IUnknown
*)collection
);
3020 ok(hr
== S_OK
, "Failed to insert element, hr %#lx.\n", hr
);
3023 hr
= IMFCollection_GetElementCount(collection
, &count
);
3024 ok(hr
== S_OK
, "Failed to get element count, hr %#lx.\n", hr
);
3025 ok(count
== 11, "Unexpected count %lu.\n", count
);
3027 hr
= IMFCollection_GetElement(collection
, 0, &element
);
3028 ok(hr
== S_OK
, "Failed to get element, hr %#lx.\n", hr
);
3029 ok(element
== (IUnknown
*)collection
, "Unexpected element.\n");
3030 IUnknown_Release(element
);
3032 hr
= IMFCollection_GetElement(collection
, 1, &element
);
3033 ok(hr
== E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
3034 ok(!element
, "Unexpected element.\n");
3036 hr
= IMFCollection_GetElement(collection
, 2, &element
);
3037 ok(hr
== E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
3038 ok(!element
, "Unexpected element.\n");
3040 hr
= IMFCollection_GetElement(collection
, 10, &element
);
3041 ok(hr
== S_OK
, "Failed to get element, hr %#lx.\n", hr
);
3042 ok(element
== (IUnknown
*)collection
, "Unexpected element.\n");
3043 IUnknown_Release(element
);
3045 hr
= IMFCollection_InsertElementAt(collection
, 0, NULL
);
3046 ok(hr
== S_OK
, "Failed to insert element, hr %#lx.\n", hr
);
3048 hr
= IMFCollection_GetElement(collection
, 0, &element
);
3049 ok(hr
== E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
3051 hr
= IMFCollection_RemoveAllElements(collection
);
3052 ok(hr
== S_OK
, "Failed to clear, hr %#lx.\n", hr
);
3055 hr
= IMFCollection_GetElementCount(collection
, &count
);
3056 ok(hr
== S_OK
, "Failed to get element count, hr %#lx.\n", hr
);
3057 ok(count
== 0, "Unexpected count %lu.\n", count
);
3059 hr
= IMFCollection_InsertElementAt(collection
, 0, NULL
);
3060 ok(hr
== S_OK
, "Failed to insert element, hr %#lx.\n", hr
);
3062 IMFCollection_Release(collection
);
3065 static void test_MFHeapAlloc(void)
3069 res
= MFHeapAlloc(16, 0, NULL
, 0, eAllocationTypeIgnore
);
3070 ok(res
!= NULL
, "MFHeapAlloc failed.\n");
3075 static void test_scheduled_items(void)
3077 struct test_callback
*callback
;
3078 IMFAsyncResult
*result
;
3079 MFWORKITEM_KEY key
, key2
;
3082 callback
= create_test_callback(NULL
);
3084 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
3085 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
3087 hr
= MFScheduleWorkItem(&callback
->IMFAsyncCallback_iface
, NULL
, -5000, &key
);
3088 ok(hr
== S_OK
, "Failed to schedule item, hr %#lx.\n", hr
);
3090 hr
= MFCancelWorkItem(key
);
3091 ok(hr
== S_OK
, "Failed to cancel item, hr %#lx.\n", hr
);
3093 hr
= MFCancelWorkItem(key
);
3094 ok(hr
== MF_E_NOT_FOUND
|| broken(hr
== S_OK
) /* < win10 */, "Unexpected hr %#lx.\n", hr
);
3096 if (!pMFPutWaitingWorkItem
)
3098 win_skip("Waiting items are not supported.\n");
3102 hr
= MFCreateAsyncResult(NULL
, &callback
->IMFAsyncCallback_iface
, NULL
, &result
);
3103 ok(hr
== S_OK
, "Failed to create result, hr %#lx.\n", hr
);
3105 hr
= pMFPutWaitingWorkItem(NULL
, 0, result
, &key
);
3106 ok(hr
== S_OK
, "Failed to add waiting item, hr %#lx.\n", hr
);
3108 hr
= pMFPutWaitingWorkItem(NULL
, 0, result
, &key2
);
3109 ok(hr
== S_OK
, "Failed to add waiting item, hr %#lx.\n", hr
);
3111 hr
= MFCancelWorkItem(key
);
3112 ok(hr
== S_OK
, "Failed to cancel item, hr %#lx.\n", hr
);
3114 hr
= MFCancelWorkItem(key2
);
3115 ok(hr
== S_OK
, "Failed to cancel item, hr %#lx.\n", hr
);
3117 IMFAsyncResult_Release(result
);
3119 hr
= MFScheduleWorkItem(&callback
->IMFAsyncCallback_iface
, NULL
, -5000, &key
);
3120 ok(hr
== S_OK
, "Failed to schedule item, hr %#lx.\n", hr
);
3122 hr
= MFCancelWorkItem(key
);
3123 ok(hr
== S_OK
, "Failed to cancel item, hr %#lx.\n", hr
);
3126 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3128 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
3131 static void test_serial_queue(void)
3133 static const DWORD queue_ids
[] =
3135 MFASYNC_CALLBACK_QUEUE_STANDARD
,
3136 MFASYNC_CALLBACK_QUEUE_RT
,
3137 MFASYNC_CALLBACK_QUEUE_IO
,
3138 MFASYNC_CALLBACK_QUEUE_TIMER
,
3139 MFASYNC_CALLBACK_QUEUE_MULTITHREADED
,
3140 MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION
,
3142 DWORD queue
, serial_queue
;
3146 if (!pMFAllocateSerialWorkQueue
)
3148 win_skip("Serial queues are not supported.\n");
3152 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
3153 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
3155 for (i
= 0; i
< ARRAY_SIZE(queue_ids
); ++i
)
3157 BOOL broken_types
= queue_ids
[i
] == MFASYNC_CALLBACK_QUEUE_TIMER
||
3158 queue_ids
[i
] == MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION
;
3160 hr
= pMFAllocateSerialWorkQueue(queue_ids
[i
], &serial_queue
);
3161 ok(hr
== S_OK
|| broken(broken_types
&& hr
== E_INVALIDARG
) /* Win8 */,
3162 "%u: failed to allocate a queue, hr %#lx.\n", i
, hr
);
3166 hr
= MFUnlockWorkQueue(serial_queue
);
3167 ok(hr
== S_OK
, "%u: failed to unlock the queue, hr %#lx.\n", i
, hr
);
3171 /* Chain them together. */
3172 hr
= pMFAllocateSerialWorkQueue(MFASYNC_CALLBACK_QUEUE_STANDARD
, &serial_queue
);
3173 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
3175 hr
= pMFAllocateSerialWorkQueue(serial_queue
, &queue
);
3176 ok(hr
== S_OK
, "Failed to allocate a queue, hr %#lx.\n", hr
);
3178 hr
= MFUnlockWorkQueue(serial_queue
);
3179 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
3181 hr
= MFUnlockWorkQueue(queue
);
3182 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
3185 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3188 static LONG periodic_counter
;
3189 static void CALLBACK
periodic_callback(IUnknown
*context
)
3191 InterlockedIncrement(&periodic_counter
);
3194 static void test_periodic_callback(void)
3199 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
3200 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
3203 hr
= MFGetTimerPeriodicity(&period
);
3204 ok(hr
== S_OK
, "Failed to get timer perdiod, hr %#lx.\n", hr
);
3205 ok(period
== 10, "Unexpected period %lu.\n", period
);
3207 if (!pMFAddPeriodicCallback
)
3209 win_skip("Periodic callbacks are not supported.\n");
3211 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3215 ok(periodic_counter
== 0, "Unexpected counter value %lu.\n", periodic_counter
);
3217 hr
= pMFAddPeriodicCallback(periodic_callback
, NULL
, &key
);
3218 ok(hr
== S_OK
, "Failed to add periodic callback, hr %#lx.\n", hr
);
3219 ok(key
!= 0, "Unexpected key %#lx.\n", key
);
3223 hr
= pMFRemovePeriodicCallback(key
);
3224 ok(hr
== S_OK
, "Failed to remove callback, hr %#lx.\n", hr
);
3226 ok(periodic_counter
> 0, "Unexpected counter value %lu.\n", periodic_counter
);
3229 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3232 static void test_event_queue(void)
3234 struct test_callback
*callback
, *callback2
;
3235 IMFMediaEvent
*event
, *event2
;
3236 IMFMediaEventQueue
*queue
;
3237 IMFAsyncResult
*result
;
3241 callback
= create_test_callback(NULL
);
3242 callback2
= create_test_callback(NULL
);
3244 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
3245 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
3247 hr
= MFCreateEventQueue(&queue
);
3248 ok(hr
== S_OK
, "Failed to create event queue, hr %#lx.\n", hr
);
3250 hr
= IMFMediaEventQueue_GetEvent(queue
, MF_EVENT_FLAG_NO_WAIT
, &event
);
3251 ok(hr
== MF_E_NO_EVENTS_AVAILABLE
, "Unexpected hr %#lx.\n", hr
);
3253 hr
= MFCreateMediaEvent(MEError
, &GUID_NULL
, E_FAIL
, NULL
, &event
);
3254 ok(hr
== S_OK
, "Failed to create event object, hr %#lx.\n", hr
);
3258 hr
= IMFMediaEventQueue_QueueEvent(queue
, event
);
3259 ok(hr
== S_OK
, "Failed to queue event, hr %#lx.\n", hr
);
3261 hr
= IMFMediaEventQueue_GetEvent(queue
, MF_EVENT_FLAG_NO_WAIT
, &event2
);
3262 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3263 ok(event2
== event
, "Unexpected event object.\n");
3264 IMFMediaEvent_Release(event2
);
3266 hr
= IMFMediaEventQueue_QueueEvent(queue
, event
);
3267 ok(hr
== S_OK
, "Failed to queue event, hr %#lx.\n", hr
);
3269 hr
= IMFMediaEventQueue_GetEvent(queue
, 0, &event2
);
3270 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3271 IMFMediaEvent_Release(event2
);
3275 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, NULL
, NULL
);
3276 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3278 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback
->IMFAsyncCallback_iface
, (IUnknown
*)queue
);
3279 ok(hr
== S_OK
, "Failed to Begin*, hr %#lx.\n", hr
);
3281 /* Same callback, same state. */
3282 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback
->IMFAsyncCallback_iface
, (IUnknown
*)queue
);
3283 ok(hr
== MF_S_MULTIPLE_BEGIN
, "Unexpected hr %#lx.\n", hr
);
3285 /* Same callback, different state. */
3286 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback
->IMFAsyncCallback_iface
, (IUnknown
*)&callback
->IMFAsyncCallback_iface
);
3287 ok(hr
== MF_E_MULTIPLE_BEGIN
, "Unexpected hr %#lx.\n", hr
);
3289 /* Different callback, same state. */
3290 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback2
->IMFAsyncCallback_iface
, (IUnknown
*)queue
);
3291 ok(hr
== MF_E_MULTIPLE_SUBSCRIBERS
, "Unexpected hr %#lx.\n", hr
);
3293 /* Different callback, different state. */
3294 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback2
->IMFAsyncCallback_iface
, (IUnknown
*)&callback
->IMFAsyncCallback_iface
);
3295 ok(hr
== MF_E_MULTIPLE_SUBSCRIBERS
, "Unexpected hr %#lx.\n", hr
);
3297 callback
->event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
3299 hr
= IMFMediaEventQueue_QueueEvent(queue
, event
);
3300 ok(hr
== S_OK
, "Failed to queue event, hr %#lx.\n", hr
);
3302 ret
= WaitForSingleObject(callback
->event
, 500);
3303 ok(ret
== WAIT_OBJECT_0
, "Unexpected return value %#lx.\n", ret
);
3305 CloseHandle(callback
->event
);
3307 IMFMediaEvent_Release(event
);
3309 hr
= MFCreateAsyncResult(NULL
, &callback
->IMFAsyncCallback_iface
, NULL
, &result
);
3310 ok(hr
== S_OK
, "Failed to create result, hr %#lx.\n", hr
);
3312 hr
= IMFMediaEventQueue_EndGetEvent(queue
, result
, &event
);
3313 ok(hr
== E_FAIL
, "Unexpected hr %#lx.\n", hr
);
3315 /* Shutdown behavior. */
3316 hr
= IMFMediaEventQueue_Shutdown(queue
);
3317 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3319 hr
= IMFMediaEventQueue_GetEvent(queue
, MF_EVENT_FLAG_NO_WAIT
, &event
);
3320 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
3322 hr
= MFCreateMediaEvent(MEError
, &GUID_NULL
, E_FAIL
, NULL
, &event
);
3323 ok(hr
== S_OK
, "Failed to create event object, hr %#lx.\n", hr
);
3324 hr
= IMFMediaEventQueue_QueueEvent(queue
, event
);
3325 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
3326 IMFMediaEvent_Release(event
);
3328 hr
= IMFMediaEventQueue_QueueEventParamUnk(queue
, MEError
, &GUID_NULL
, E_FAIL
, NULL
);
3329 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
3331 hr
= IMFMediaEventQueue_QueueEventParamVar(queue
, MEError
, &GUID_NULL
, E_FAIL
, NULL
);
3332 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
3334 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback
->IMFAsyncCallback_iface
, NULL
);
3335 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
3337 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, NULL
, NULL
);
3338 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3340 hr
= IMFMediaEventQueue_EndGetEvent(queue
, result
, &event
);
3341 ok(hr
== MF_E_SHUTDOWN
, "Unexpected hr %#lx.\n", hr
);
3342 IMFAsyncResult_Release(result
);
3344 /* Already shut down. */
3345 hr
= IMFMediaEventQueue_Shutdown(queue
);
3346 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3348 IMFMediaEventQueue_Release(queue
);
3349 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
3351 /* Release while subscribed. */
3352 callback
= create_test_callback(NULL
);
3354 hr
= MFCreateEventQueue(&queue
);
3355 ok(hr
== S_OK
, "Failed to create event queue, hr %#lx.\n", hr
);
3357 hr
= IMFMediaEventQueue_BeginGetEvent(queue
, &callback
->IMFAsyncCallback_iface
, NULL
);
3358 ok(hr
== S_OK
, "Failed to Begin*, hr %#lx.\n", hr
);
3359 EXPECT_REF(&callback
->IMFAsyncCallback_iface
, 2);
3361 IMFMediaEventQueue_Release(queue
);
3362 ret
= get_refcount(&callback
->IMFAsyncCallback_iface
);
3363 ok(ret
== 1 || broken(ret
== 2) /* Vista */,
3364 "Unexpected refcount %ld, expected 1.\n", ret
);
3365 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
3368 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3371 static void test_presentation_descriptor(void)
3373 IMFStreamDescriptor
*stream_desc
[2], *stream_desc2
;
3374 IMFPresentationDescriptor
*pd
, *pd2
;
3375 IMFMediaType
*media_type
;
3382 hr
= MFCreateMediaType(&media_type
);
3383 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
3385 for (i
= 0; i
< ARRAY_SIZE(stream_desc
); ++i
)
3387 hr
= MFCreateStreamDescriptor(0, 1, &media_type
, &stream_desc
[i
]);
3388 ok(hr
== S_OK
, "Failed to create descriptor, hr %#lx.\n", hr
);
3391 hr
= MFCreatePresentationDescriptor(ARRAY_SIZE(stream_desc
), stream_desc
, &pd
);
3392 ok(hr
== S_OK
, "Failed to create presentation descriptor, hr %#lx.\n", hr
);
3394 hr
= IMFPresentationDescriptor_GetStreamDescriptorCount(pd
, &count
);
3395 ok(count
== ARRAY_SIZE(stream_desc
), "Unexpected count %lu.\n", count
);
3397 for (i
= 0; i
< count
; ++i
)
3399 hr
= IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd
, i
, &selected
, &stream_desc2
);
3400 ok(hr
== S_OK
, "Failed to get stream descriptor, hr %#lx.\n", hr
);
3401 ok(!selected
, "Unexpected selected state.\n");
3402 ok(stream_desc
[i
] == stream_desc2
, "Unexpected object.\n");
3403 IMFStreamDescriptor_Release(stream_desc2
);
3406 hr
= IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd
, 10, &selected
, &stream_desc2
);
3407 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3409 hr
= IMFPresentationDescriptor_SelectStream(pd
, 10);
3410 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3412 hr
= IMFPresentationDescriptor_SelectStream(pd
, 0);
3413 ok(hr
== S_OK
, "Failed to select a stream, hr %#lx.\n", hr
);
3415 hr
= IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd
, 0, &selected
, &stream_desc2
);
3416 ok(hr
== S_OK
, "Failed to get stream descriptor, hr %#lx.\n", hr
);
3417 ok(!!selected
, "Unexpected selected state.\n");
3418 IMFStreamDescriptor_Release(stream_desc2
);
3420 hr
= IMFPresentationDescriptor_SetUINT64(pd
, &MF_PD_TOTAL_FILE_SIZE
, 1);
3421 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
3423 hr
= IMFPresentationDescriptor_Clone(pd
, &pd2
);
3424 ok(hr
== S_OK
, "Failed to clone, hr %#lx.\n", hr
);
3426 hr
= IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd2
, 0, &selected
, &stream_desc2
);
3427 ok(hr
== S_OK
, "Failed to get stream descriptor, hr %#lx.\n", hr
);
3428 ok(!!selected
, "Unexpected selected state.\n");
3429 ok(stream_desc2
== stream_desc
[0], "Unexpected stream descriptor.\n");
3430 IMFStreamDescriptor_Release(stream_desc2
);
3433 hr
= IMFPresentationDescriptor_GetUINT64(pd2
, &MF_PD_TOTAL_FILE_SIZE
, &value
);
3434 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
3435 ok(value
== 1, "Unexpected attribute value.\n");
3437 IMFPresentationDescriptor_Release(pd2
);
3438 IMFPresentationDescriptor_Release(pd
);
3440 for (i
= 0; i
< ARRAY_SIZE(stream_desc
); ++i
)
3442 IMFStreamDescriptor_Release(stream_desc
[i
]);
3445 /* Partially initialized array. */
3446 hr
= MFCreateStreamDescriptor(0, 1, &media_type
, &stream_desc
[1]);
3447 ok(hr
== S_OK
, "Failed to create descriptor, hr %#lx.\n", hr
);
3448 stream_desc
[0] = NULL
;
3450 hr
= MFCreatePresentationDescriptor(ARRAY_SIZE(stream_desc
), stream_desc
, &pd
);
3451 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3453 IMFStreamDescriptor_Release(stream_desc
[1]);
3454 IMFMediaType_Release(media_type
);
3465 static void test_system_time_source(void)
3467 static const struct clock_state_test
3469 enum clock_action action
;
3470 MFCLOCK_STATE state
;
3473 clock_state_change
[] =
3475 { CLOCK_STOP
, MFCLOCK_STATE_INVALID
},
3476 { CLOCK_RESTART
, MFCLOCK_STATE_INVALID
, TRUE
},
3477 { CLOCK_PAUSE
, MFCLOCK_STATE_PAUSED
},
3478 { CLOCK_PAUSE
, MFCLOCK_STATE_PAUSED
, TRUE
},
3479 { CLOCK_STOP
, MFCLOCK_STATE_STOPPED
},
3480 { CLOCK_STOP
, MFCLOCK_STATE_STOPPED
},
3481 { CLOCK_RESTART
, MFCLOCK_STATE_STOPPED
, TRUE
},
3482 { CLOCK_START
, MFCLOCK_STATE_RUNNING
},
3483 { CLOCK_START
, MFCLOCK_STATE_RUNNING
},
3484 { CLOCK_RESTART
, MFCLOCK_STATE_RUNNING
, TRUE
},
3485 { CLOCK_PAUSE
, MFCLOCK_STATE_PAUSED
},
3486 { CLOCK_START
, MFCLOCK_STATE_RUNNING
},
3487 { CLOCK_PAUSE
, MFCLOCK_STATE_PAUSED
},
3488 { CLOCK_RESTART
, MFCLOCK_STATE_RUNNING
},
3489 { CLOCK_RESTART
, MFCLOCK_STATE_RUNNING
, TRUE
},
3490 { CLOCK_STOP
, MFCLOCK_STATE_STOPPED
},
3491 { CLOCK_PAUSE
, MFCLOCK_STATE_STOPPED
, TRUE
},
3493 IMFPresentationTimeSource
*time_source
, *time_source2
;
3494 IMFClockStateSink
*statesink
;
3495 IMFClock
*clock
, *clock2
;
3496 MFCLOCK_PROPERTIES props
;
3497 MFCLOCK_STATE state
;
3504 hr
= MFCreateSystemTimeSource(&time_source
);
3505 ok(hr
== S_OK
, "Failed to create time source, hr %#lx.\n", hr
);
3507 hr
= IMFPresentationTimeSource_GetClockCharacteristics(time_source
, &value
);
3508 ok(hr
== S_OK
, "Failed to get flags, hr %#lx.\n", hr
);
3509 ok(value
== (MFCLOCK_CHARACTERISTICS_FLAG_FREQUENCY_10MHZ
| MFCLOCK_CHARACTERISTICS_FLAG_IS_SYSTEM_CLOCK
),
3510 "Unexpected flags %#lx.\n", value
);
3513 hr
= IMFPresentationTimeSource_GetContinuityKey(time_source
, &value
);
3514 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3515 ok(value
== 0, "Unexpected value %lu.\n", value
);
3517 hr
= IMFPresentationTimeSource_GetState(time_source
, 0, &state
);
3518 ok(hr
== S_OK
, "Failed to get state, hr %#lx.\n", hr
);
3519 ok(state
== MFCLOCK_STATE_INVALID
, "Unexpected state %d.\n", state
);
3521 hr
= IMFPresentationTimeSource_QueryInterface(time_source
, &IID_IMFClockStateSink
, (void **)&statesink
);
3522 ok(hr
== S_OK
, "Failed to get state sink, hr %#lx.\n", hr
);
3524 /* State changes. */
3525 for (i
= 0; i
< ARRAY_SIZE(clock_state_change
); ++i
)
3527 switch (clock_state_change
[i
].action
)
3530 hr
= IMFClockStateSink_OnClockStop(statesink
, 0);
3533 hr
= IMFClockStateSink_OnClockRestart(statesink
, 0);
3536 hr
= IMFClockStateSink_OnClockPause(statesink
, 0);
3539 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 0);
3544 ok(hr
== (clock_state_change
[i
].is_invalid
? MF_E_INVALIDREQUEST
: S_OK
), "%u: unexpected hr %#lx.\n", i
, hr
);
3545 hr
= IMFPresentationTimeSource_GetState(time_source
, 0, &state
);
3546 ok(hr
== S_OK
, "%u: failed to get state, hr %#lx.\n", i
, hr
);
3547 ok(state
== clock_state_change
[i
].state
, "%u: unexpected state %d.\n", i
, state
);
3550 IMFClockStateSink_Release(statesink
);
3553 hr
= IMFPresentationTimeSource_GetProperties(time_source
, NULL
);
3554 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
3556 hr
= IMFPresentationTimeSource_GetProperties(time_source
, &props
);
3557 ok(hr
== S_OK
, "Failed to get clock properties, hr %#lx.\n", hr
);
3559 ok(props
.qwCorrelationRate
== 0, "Unexpected correlation rate %s.\n",
3560 wine_dbgstr_longlong(props
.qwCorrelationRate
));
3561 ok(IsEqualGUID(&props
.guidClockId
, &GUID_NULL
), "Unexpected clock id %s.\n", wine_dbgstr_guid(&props
.guidClockId
));
3562 ok(props
.dwClockFlags
== 0, "Unexpected flags %#lx.\n", props
.dwClockFlags
);
3563 ok(props
.qwClockFrequency
== MFCLOCK_FREQUENCY_HNS
, "Unexpected frequency %s.\n",
3564 wine_dbgstr_longlong(props
.qwClockFrequency
));
3565 ok(props
.dwClockTolerance
== MFCLOCK_TOLERANCE_UNKNOWN
, "Unexpected tolerance %lu.\n", props
.dwClockTolerance
);
3566 ok(props
.dwClockJitter
== 1, "Unexpected jitter %lu.\n", props
.dwClockJitter
);
3568 /* Underlying clock. */
3569 hr
= MFCreateSystemTimeSource(&time_source2
);
3570 ok(hr
== S_OK
, "Failed to create time source, hr %#lx.\n", hr
);
3571 EXPECT_REF(time_source2
, 1);
3572 hr
= IMFPresentationTimeSource_GetUnderlyingClock(time_source2
, &clock2
);
3573 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3574 EXPECT_REF(time_source2
, 1);
3575 EXPECT_REF(clock2
, 2);
3577 EXPECT_REF(time_source
, 1);
3578 hr
= IMFPresentationTimeSource_GetUnderlyingClock(time_source
, &clock
);
3579 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3580 EXPECT_REF(time_source
, 1);
3581 EXPECT_REF(clock
, 2);
3583 ok(clock
!= clock2
, "Unexpected clock instance.\n");
3585 IMFPresentationTimeSource_Release(time_source2
);
3586 IMFClock_Release(clock2
);
3588 hr
= IMFClock_GetClockCharacteristics(clock
, &value
);
3589 ok(hr
== S_OK
, "Failed to get clock flags, hr %#lx.\n", hr
);
3590 ok(value
== (MFCLOCK_CHARACTERISTICS_FLAG_FREQUENCY_10MHZ
| MFCLOCK_CHARACTERISTICS_FLAG_ALWAYS_RUNNING
|
3591 MFCLOCK_CHARACTERISTICS_FLAG_IS_SYSTEM_CLOCK
), "Unexpected flags %#lx.\n", value
);
3593 hr
= IMFClock_GetContinuityKey(clock
, &value
);
3594 ok(hr
== S_OK
, "Failed to get clock key, hr %#lx.\n", hr
);
3595 ok(value
== 0, "Unexpected key value %lu.\n", value
);
3597 hr
= IMFClock_GetState(clock
, 0, &state
);
3598 ok(hr
== S_OK
, "Failed to get clock state, hr %#lx.\n", hr
);
3599 ok(state
== MFCLOCK_STATE_RUNNING
, "Unexpected state %d.\n", state
);
3601 hr
= IMFClock_GetProperties(clock
, &props
);
3602 ok(hr
== S_OK
, "Failed to get clock properties, hr %#lx.\n", hr
);
3604 ok(props
.qwCorrelationRate
== 0, "Unexpected correlation rate %s.\n",
3605 wine_dbgstr_longlong(props
.qwCorrelationRate
));
3606 ok(IsEqualGUID(&props
.guidClockId
, &GUID_NULL
), "Unexpected clock id %s.\n", wine_dbgstr_guid(&props
.guidClockId
));
3607 ok(props
.dwClockFlags
== 0, "Unexpected flags %#lx.\n", props
.dwClockFlags
);
3608 ok(props
.qwClockFrequency
== MFCLOCK_FREQUENCY_HNS
, "Unexpected frequency %s.\n",
3609 wine_dbgstr_longlong(props
.qwClockFrequency
));
3610 ok(props
.dwClockTolerance
== MFCLOCK_TOLERANCE_UNKNOWN
, "Unexpected tolerance %lu.\n", props
.dwClockTolerance
);
3611 ok(props
.dwClockJitter
== 1, "Unexpected jitter %lu.\n", props
.dwClockJitter
);
3613 hr
= IMFClock_GetCorrelatedTime(clock
, 0, &time
, &systime
);
3614 ok(hr
== S_OK
, "Failed to get clock time, hr %#lx.\n", hr
);
3615 ok(time
== systime
, "Unexpected time %s, %s.\n", wine_dbgstr_longlong(time
), wine_dbgstr_longlong(systime
));
3617 IMFClock_Release(clock
);
3619 /* Test returned time regarding specified rate and offset. */
3620 hr
= IMFPresentationTimeSource_QueryInterface(time_source
, &IID_IMFClockStateSink
, (void **)&statesink
);
3621 ok(hr
== S_OK
, "Failed to get sink interface, hr %#lx.\n", hr
);
3623 hr
= IMFPresentationTimeSource_GetState(time_source
, 0, &state
);
3624 ok(hr
== S_OK
, "Failed to get state %#lx.\n", hr
);
3625 ok(state
== MFCLOCK_STATE_STOPPED
, "Unexpected state %d.\n", state
);
3627 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3628 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3629 ok(time
== 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
), wine_dbgstr_longlong(systime
));
3631 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 0);
3632 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3634 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3635 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3636 ok(time
== systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
), wine_dbgstr_longlong(systime
));
3638 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 1);
3639 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3641 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3642 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3643 ok(time
== systime
+ 1, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3644 wine_dbgstr_longlong(systime
));
3646 hr
= IMFClockStateSink_OnClockPause(statesink
, 2);
3647 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3649 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3650 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3651 ok(time
== 3, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
), wine_dbgstr_longlong(systime
));
3653 hr
= IMFClockStateSink_OnClockRestart(statesink
, 5);
3654 ok(hr
== S_OK
, "Failed to restart source, hr %#lx.\n", hr
);
3656 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3657 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3658 ok(time
== systime
- 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3659 wine_dbgstr_longlong(systime
));
3661 hr
= IMFClockStateSink_OnClockPause(statesink
, 0);
3662 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3664 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3665 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3666 ok(time
== -2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3667 wine_dbgstr_longlong(systime
));
3669 hr
= IMFClockStateSink_OnClockStop(statesink
, 123);
3670 ok(hr
== S_OK
, "Failed to stop source, hr %#lx.\n", hr
);
3672 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3673 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3674 ok(time
== 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
), wine_dbgstr_longlong(systime
));
3676 /* Increased rate. */
3677 hr
= IMFClockStateSink_OnClockSetRate(statesink
, 0, 2.0f
);
3678 ok(hr
== S_OK
, "Failed to set rate, hr %#lx.\n", hr
);
3680 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 0);
3681 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3683 hr
= IMFClockStateSink_OnClockSetRate(statesink
, 5, 2.0f
);
3684 ok(hr
== S_OK
, "Failed to set rate, hr %#lx.\n", hr
);
3686 hr
= IMFClockStateSink_OnClockPause(statesink
, 6);
3687 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3689 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3690 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3691 ok(time
== 12 && !!systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3692 wine_dbgstr_longlong(systime
));
3694 hr
= IMFClockStateSink_OnClockRestart(statesink
, 7);
3695 ok(hr
== S_OK
, "Failed to restart source, hr %#lx.\n", hr
);
3697 hr
= IMFClockStateSink_OnClockPause(statesink
, 8);
3698 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3700 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3701 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3702 ok(time
== 14 && !!systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3703 wine_dbgstr_longlong(systime
));
3705 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 0);
3706 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3708 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3709 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3710 ok(time
== 2 * systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3711 wine_dbgstr_longlong(2 * systime
));
3713 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 10);
3714 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3716 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3717 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3718 ok(time
== 2 * systime
+ 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3719 wine_dbgstr_longlong(2 * systime
));
3721 hr
= IMFClockStateSink_OnClockPause(statesink
, 2);
3722 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3724 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3725 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3726 ok(time
== 10 + 2 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3727 wine_dbgstr_longlong(systime
));
3729 hr
= IMFClockStateSink_OnClockRestart(statesink
, 5);
3730 ok(hr
== S_OK
, "Failed to restart source, hr %#lx.\n", hr
);
3732 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3733 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3734 ok(time
== 2 * systime
+ 14 - 5 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3735 wine_dbgstr_longlong(systime
));
3737 hr
= IMFClockStateSink_OnClockPause(statesink
, 0);
3738 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3740 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3741 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3742 ok(time
== 4, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3743 wine_dbgstr_longlong(systime
));
3745 hr
= IMFClockStateSink_OnClockStop(statesink
, 123);
3746 ok(hr
== S_OK
, "Failed to stop source, hr %#lx.\n", hr
);
3748 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3749 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3750 ok(time
== 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
), wine_dbgstr_longlong(systime
));
3752 hr
= IMFClockStateSink_OnClockStart(statesink
, 10, 0);
3753 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3755 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3756 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3757 ok(time
== 2 * systime
- 2 * 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3758 wine_dbgstr_longlong(2 * systime
));
3760 hr
= IMFClockStateSink_OnClockStop(statesink
, 123);
3761 ok(hr
== S_OK
, "Failed to stop source, hr %#lx.\n", hr
);
3763 hr
= IMFClockStateSink_OnClockStart(statesink
, 10, 20);
3764 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3766 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3767 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3768 ok(time
== 2 * systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3769 wine_dbgstr_longlong(2 * systime
));
3771 hr
= IMFClockStateSink_OnClockPause(statesink
, 2);
3772 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3774 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3775 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3776 ok(time
== 2 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3777 wine_dbgstr_longlong(systime
));
3779 hr
= IMFClockStateSink_OnClockRestart(statesink
, 5);
3780 ok(hr
== S_OK
, "Failed to restart source, hr %#lx.\n", hr
);
3782 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3783 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3784 ok(time
== 2 * systime
+ 4 - 5 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3785 wine_dbgstr_longlong(systime
));
3787 hr
= IMFClockStateSink_OnClockPause(statesink
, 0);
3788 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3790 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3791 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3792 ok(time
== -6, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3793 wine_dbgstr_longlong(systime
));
3795 IMFClockStateSink_Release(statesink
);
3796 IMFPresentationTimeSource_Release(time_source
);
3798 /* PRESENTATION_CURRENT_POSITION */
3799 hr
= MFCreateSystemTimeSource(&time_source
);
3800 ok(hr
== S_OK
, "Failed to create time source, hr %#lx.\n", hr
);
3802 hr
= IMFPresentationTimeSource_QueryInterface(time_source
, &IID_IMFClockStateSink
, (void **)&statesink
);
3803 ok(hr
== S_OK
, "Failed to get sink interface, hr %#lx.\n", hr
);
3805 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3806 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3807 ok(!time
&& systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3808 wine_dbgstr_longlong(systime
));
3810 /* INVALID -> RUNNING */
3811 hr
= IMFClockStateSink_OnClockStart(statesink
, 10, PRESENTATION_CURRENT_POSITION
);
3812 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3814 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3815 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3816 ok(time
== systime
- 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3817 wine_dbgstr_longlong(systime
));
3819 /* RUNNING -> RUNNING */
3820 hr
= IMFClockStateSink_OnClockStart(statesink
, 20, PRESENTATION_CURRENT_POSITION
);
3821 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3823 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3824 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3825 ok(time
== systime
- 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3826 wine_dbgstr_longlong(systime
));
3828 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, PRESENTATION_CURRENT_POSITION
);
3829 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3831 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3832 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3833 ok(time
== systime
- 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3834 wine_dbgstr_longlong(systime
));
3836 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 0);
3837 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3839 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3840 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3841 ok(time
== systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3842 wine_dbgstr_longlong(systime
));
3844 hr
= IMFClockStateSink_OnClockStart(statesink
, 30, PRESENTATION_CURRENT_POSITION
);
3845 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3847 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3848 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3849 ok(time
== systime
, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3850 wine_dbgstr_longlong(systime
));
3852 /* STOPPED -> RUNNING */
3853 hr
= IMFClockStateSink_OnClockStop(statesink
, 567);
3854 ok(hr
== S_OK
, "Failed to stop source, hr %#lx.\n", hr
);
3856 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3857 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3858 ok(!time
&& systime
!= 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3859 wine_dbgstr_longlong(systime
));
3861 hr
= IMFClockStateSink_OnClockStart(statesink
, 30, PRESENTATION_CURRENT_POSITION
);
3862 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3864 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3865 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3866 ok(time
== systime
- 30, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3867 wine_dbgstr_longlong(systime
));
3869 /* PAUSED -> RUNNING */
3870 hr
= IMFClockStateSink_OnClockPause(statesink
, 8);
3871 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3873 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3874 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3875 ok(time
== (-30 + 8) && systime
!= 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3876 wine_dbgstr_longlong(systime
));
3878 hr
= IMFClockStateSink_OnClockStart(statesink
, 40, PRESENTATION_CURRENT_POSITION
);
3879 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3881 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3882 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3883 ok(time
== systime
+ (-30 + 8 - 40), "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3884 wine_dbgstr_longlong(systime
));
3886 hr
= IMFClockStateSink_OnClockPause(statesink
, 7);
3887 ok(hr
== S_OK
, "Failed to pause source, hr %#lx.\n", hr
);
3889 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3890 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3891 ok(time
== (-30 + 8 - 40 + 7) && systime
!= 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3892 wine_dbgstr_longlong(systime
));
3894 hr
= IMFClockStateSink_OnClockStart(statesink
, 50, 7);
3895 ok(hr
== S_OK
, "Failed to start source, hr %#lx.\n", hr
);
3897 hr
= IMFPresentationTimeSource_GetCorrelatedTime(time_source
, 0, &time
, &systime
);
3898 ok(hr
== S_OK
, "Failed to get time %#lx.\n", hr
);
3899 ok(time
== systime
+ (-50 + 7), "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time
),
3900 wine_dbgstr_longlong(systime
));
3902 IMFClockStateSink_Release(statesink
);
3903 IMFPresentationTimeSource_Release(time_source
);
3906 static void test_MFInvokeCallback(void)
3908 struct test_callback
*callback
;
3909 IMFAsyncResult
*result
;
3910 MFASYNCRESULT
*data
;
3915 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
3916 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
3918 callback
= create_test_callback(NULL
);
3920 hr
= MFCreateAsyncResult(NULL
, &callback
->IMFAsyncCallback_iface
, NULL
, &result
);
3921 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
3923 data
= (MFASYNCRESULT
*)result
;
3924 data
->hEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
3925 ok(data
->hEvent
!= NULL
, "Failed to create event.\n");
3927 hr
= MFInvokeCallback(result
);
3928 ok(hr
== S_OK
, "Failed to invoke, hr %#lx.\n", hr
);
3930 ret
= WaitForSingleObject(data
->hEvent
, 100);
3931 ok(ret
== WAIT_TIMEOUT
, "Expected timeout, ret %#lx.\n", ret
);
3933 refcount
= IMFAsyncResult_Release(result
);
3934 ok(!refcount
, "Unexpected refcount %lu.\n", refcount
);
3936 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
3939 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3942 static void test_stream_descriptor(void)
3944 IMFMediaType
*media_types
[2], *media_type
, *media_type2
, *media_type3
;
3945 IMFMediaTypeHandler
*type_handler
;
3946 IMFStreamDescriptor
*stream_desc
;
3952 hr
= MFCreateStreamDescriptor(123, 0, NULL
, &stream_desc
);
3953 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3955 for (i
= 0; i
< ARRAY_SIZE(media_types
); ++i
)
3957 hr
= MFCreateMediaType(&media_types
[i
]);
3958 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
3961 hr
= MFCreateStreamDescriptor(123, 0, media_types
, &stream_desc
);
3962 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
3964 hr
= MFCreateStreamDescriptor(123, ARRAY_SIZE(media_types
), media_types
, &stream_desc
);
3965 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
3967 hr
= IMFStreamDescriptor_GetStreamIdentifier(stream_desc
, &id
);
3968 ok(hr
== S_OK
, "Failed to get descriptor id, hr %#lx.\n", hr
);
3969 ok(id
== 123, "Unexpected id %#lx.\n", id
);
3971 hr
= IMFStreamDescriptor_GetMediaTypeHandler(stream_desc
, &type_handler
);
3972 ok(hr
== S_OK
, "Failed to get type handler, hr %#lx.\n", hr
);
3974 hr
= IMFMediaTypeHandler_GetMediaTypeCount(type_handler
, &count
);
3975 ok(hr
== S_OK
, "Failed to get type count, hr %#lx.\n", hr
);
3976 ok(count
== ARRAY_SIZE(media_types
), "Unexpected type count.\n");
3978 hr
= IMFMediaTypeHandler_GetCurrentMediaType(type_handler
, &media_type
);
3979 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
3981 hr
= IMFMediaTypeHandler_GetMajorType(type_handler
, &major_type
);
3982 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
3984 for (i
= 0; i
< ARRAY_SIZE(media_types
); ++i
)
3986 hr
= IMFMediaTypeHandler_GetMediaTypeByIndex(type_handler
, i
, &media_type
);
3987 ok(hr
== S_OK
, "Failed to get media type, hr %#lx.\n", hr
);
3988 ok(media_type
== media_types
[i
], "Unexpected object.\n");
3991 IMFMediaType_Release(media_type
);
3994 hr
= IMFMediaTypeHandler_GetMediaTypeByIndex(type_handler
, 2, &media_type
);
3995 ok(hr
== MF_E_NO_MORE_TYPES
, "Unexpected hr %#lx.\n", hr
);
3997 /* IsMediaTypeSupported() */
3999 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, NULL
, NULL
);
4000 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
4002 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, NULL
, &media_type2
);
4003 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
4005 hr
= MFCreateMediaType(&media_type
);
4006 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
4008 hr
= MFCreateMediaType(&media_type3
);
4009 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
4011 media_type2
= (void *)0xdeadbeef;
4012 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type
, &media_type2
);
4013 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4014 ok(!media_type2
, "Unexpected pointer.\n");
4016 hr
= IMFMediaTypeHandler_SetCurrentMediaType(type_handler
, NULL
);
4017 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
4019 hr
= IMFMediaTypeHandler_SetCurrentMediaType(type_handler
, media_type
);
4020 ok(hr
== S_OK
, "Failed to set current type, hr %#lx.\n", hr
);
4022 media_type2
= (void *)0xdeadbeef;
4023 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type
, &media_type2
);
4024 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4025 ok(!media_type2
, "Unexpected pointer.\n");
4027 hr
= IMFMediaTypeHandler_GetMajorType(type_handler
, &major_type
);
4028 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
4030 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4031 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
4033 hr
= IMFMediaTypeHandler_GetMajorType(type_handler
, &major_type
);
4034 ok(hr
== S_OK
, "Failed to get major type, hr %#lx.\n", hr
);
4035 ok(IsEqualGUID(&major_type
, &MFMediaType_Audio
), "Unexpected major type.\n");
4037 /* Mismatching major types. */
4038 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
4039 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
4041 media_type2
= (void *)0xdeadbeef;
4042 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4043 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4044 ok(!media_type2
, "Unexpected pointer.\n");
4046 /* Subtype missing. */
4047 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4048 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4050 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
4051 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4053 media_type2
= (void *)0xdeadbeef;
4054 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4055 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4056 ok(!media_type2
, "Unexpected pointer.\n");
4058 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
4059 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4061 media_type2
= (void *)0xdeadbeef;
4062 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4063 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4064 ok(!media_type2
, "Unexpected pointer.\n");
4066 /* Mismatching subtype. */
4067 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_SUBTYPE
, &MFAudioFormat_MP3
);
4068 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4070 media_type2
= (void *)0xdeadbeef;
4071 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4072 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4073 ok(!media_type2
, "Unexpected pointer.\n");
4075 hr
= IMFMediaTypeHandler_GetMediaTypeCount(type_handler
, &count
);
4076 ok(hr
== S_OK
, "Failed to get type count, hr %#lx.\n", hr
);
4077 ok(count
== ARRAY_SIZE(media_types
), "Unexpected type count.\n");
4079 IMFMediaTypeHandler_Release(type_handler
);
4080 IMFStreamDescriptor_Release(stream_desc
);
4082 /* IsMediaTypeSupported() for unset current type. */
4083 hr
= MFCreateStreamDescriptor(123, ARRAY_SIZE(media_types
), media_types
, &stream_desc
);
4084 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4086 hr
= IMFStreamDescriptor_GetMediaTypeHandler(stream_desc
, &type_handler
);
4087 ok(hr
== S_OK
, "Failed to get type handler, hr %#lx.\n", hr
);
4089 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, NULL
);
4090 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4092 /* Initialize one from initial type set. */
4093 hr
= IMFMediaType_CopyAllItems(media_type3
, (IMFAttributes
*)media_types
[0]);
4094 ok(hr
== S_OK
, "Failed to copy attributes, hr %#lx.\n", hr
);
4096 media_type2
= (void *)0xdeadbeef;
4097 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4098 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4099 ok(!media_type2
, "Unexpected pointer.\n");
4101 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
4102 ok(hr
== S_OK
, "Failed to copy attributes, hr %#lx.\n", hr
);
4104 media_type2
= (void *)0xdeadbeef;
4105 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4106 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
4107 ok(!media_type2
, "Unexpected pointer.\n");
4109 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_SUBTYPE
, &MFAudioFormat_MP3
);
4110 ok(hr
== S_OK
, "Failed to copy attributes, hr %#lx.\n", hr
);
4112 media_type2
= (void *)0xdeadbeef;
4113 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4114 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4115 ok(!media_type2
, "Unexpected pointer.\n");
4117 /* Now set current type that's not compatible. */
4118 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
4119 ok(hr
== S_OK
, "Failed to copy attributes, hr %#lx.\n", hr
);
4121 hr
= IMFMediaType_SetGUID(media_type3
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB8
);
4122 ok(hr
== S_OK
, "Failed to copy attributes, hr %#lx.\n", hr
);
4124 hr
= IMFMediaTypeHandler_SetCurrentMediaType(type_handler
, media_type3
);
4125 ok(hr
== S_OK
, "Failed to set current type, hr %#lx.\n", hr
);
4127 media_type2
= (void *)0xdeadbeef;
4128 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type3
, &media_type2
);
4129 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4130 ok(!media_type2
, "Unexpected pointer.\n");
4132 hr
= IMFMediaType_CopyAllItems(media_types
[0], (IMFAttributes
*)media_type
);
4133 ok(hr
== S_OK
, "Failed to copy attributes, hr %#lx.\n", hr
);
4135 media_type2
= (void *)0xdeadbeef;
4136 hr
= IMFMediaTypeHandler_IsMediaTypeSupported(type_handler
, media_type
, &media_type2
);
4137 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4138 ok(!media_type2
, "Unexpected pointer.\n");
4140 IMFMediaType_Release(media_type
);
4141 IMFMediaType_Release(media_type3
);
4143 IMFMediaTypeHandler_Release(type_handler
);
4145 IMFStreamDescriptor_Release(stream_desc
);
4147 /* Major type is returned for first entry. */
4148 hr
= MFCreateMediaType(&media_types
[0]);
4149 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4150 hr
= MFCreateMediaType(&media_types
[1]);
4151 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4153 hr
= IMFMediaType_SetGUID(media_types
[0], &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4154 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4155 hr
= IMFMediaType_SetGUID(media_types
[1], &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
4156 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4158 hr
= MFCreateStreamDescriptor(0, 2, media_types
, &stream_desc
);
4159 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4161 hr
= IMFStreamDescriptor_GetMediaTypeHandler(stream_desc
, &type_handler
);
4162 ok(hr
== S_OK
, "Failed to get type handler, hr %#lx.\n", hr
);
4164 hr
= IMFMediaTypeHandler_GetMajorType(type_handler
, &major_type
);
4165 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4166 ok(IsEqualGUID(&major_type
, &MFMediaType_Audio
), "Unexpected major type %s.\n", wine_dbgstr_guid(&major_type
));
4168 hr
= IMFMediaType_SetGUID(media_types
[0], &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
4169 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4170 hr
= IMFMediaType_SetGUID(media_types
[1], &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4171 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4173 hr
= IMFMediaTypeHandler_GetMajorType(type_handler
, &major_type
);
4174 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4175 ok(IsEqualGUID(&major_type
, &MFMediaType_Video
), "Unexpected major type %s.\n", wine_dbgstr_guid(&major_type
));
4177 IMFMediaType_Release(media_types
[0]);
4178 IMFMediaType_Release(media_types
[1]);
4180 IMFMediaTypeHandler_Release(type_handler
);
4181 IMFStreamDescriptor_Release(stream_desc
);
4184 static const struct image_size_test
4186 const GUID
*subtype
;
4190 UINT32 plane_size
; /* Matches image size when 0. */
4192 image_size_tests
[] =
4194 { &MFVideoFormat_RGB8
, 3, 5, 20 },
4195 { &MFVideoFormat_RGB8
, 1, 1, 4 },
4196 { &MFVideoFormat_RGB555
, 3, 5, 40 },
4197 { &MFVideoFormat_RGB555
, 1, 1, 4 },
4198 { &MFVideoFormat_RGB565
, 3, 5, 40 },
4199 { &MFVideoFormat_RGB565
, 1, 1, 4 },
4200 { &MFVideoFormat_RGB24
, 3, 5, 60 },
4201 { &MFVideoFormat_RGB24
, 1, 1, 4 },
4202 { &MFVideoFormat_RGB32
, 3, 5, 60 },
4203 { &MFVideoFormat_RGB32
, 1, 1, 4 },
4204 { &MFVideoFormat_ARGB32
, 3, 5, 60 },
4205 { &MFVideoFormat_ARGB32
, 1, 1, 4 },
4206 { &MFVideoFormat_A2R10G10B10
, 3, 5, 60 },
4207 { &MFVideoFormat_A2R10G10B10
, 1, 1, 4 },
4208 { &MFVideoFormat_A16B16G16R16F
, 3, 5, 120 },
4209 { &MFVideoFormat_A16B16G16R16F
, 1, 1, 8 },
4212 { &MFVideoFormat_NV12
, 1, 3, 9, 4 },
4213 { &MFVideoFormat_NV12
, 1, 2, 6, 3 },
4214 { &MFVideoFormat_NV12
, 2, 2, 6, 6 },
4215 { &MFVideoFormat_NV12
, 3, 2, 12, 9 },
4216 { &MFVideoFormat_NV12
, 4, 2, 12 },
4217 { &MFVideoFormat_NV12
, 320, 240, 115200 },
4218 { &MFVideoFormat_AYUV
, 1, 1, 4 },
4219 { &MFVideoFormat_AYUV
, 2, 1, 8 },
4220 { &MFVideoFormat_AYUV
, 1, 2, 8 },
4221 { &MFVideoFormat_AYUV
, 4, 3, 48 },
4222 { &MFVideoFormat_AYUV
, 320, 240, 307200 },
4223 { &MFVideoFormat_IMC1
, 1, 1, 4 },
4224 { &MFVideoFormat_IMC1
, 2, 1, 4 },
4225 { &MFVideoFormat_IMC1
, 1, 2, 8 },
4226 { &MFVideoFormat_IMC1
, 4, 3, 24 },
4227 { &MFVideoFormat_IMC1
, 320, 240, 153600 },
4228 { &MFVideoFormat_IMC3
, 1, 1, 4 },
4229 { &MFVideoFormat_IMC3
, 2, 1, 4 },
4230 { &MFVideoFormat_IMC3
, 1, 2, 8 },
4231 { &MFVideoFormat_IMC3
, 4, 3, 24 },
4232 { &MFVideoFormat_IMC3
, 320, 240, 153600 },
4233 { &MFVideoFormat_IMC2
, 1, 3, 9, 4 },
4234 { &MFVideoFormat_IMC2
, 1, 2, 6, 3 },
4235 { &MFVideoFormat_IMC2
, 2, 2, 6, 6 },
4236 { &MFVideoFormat_IMC2
, 3, 2, 12, 9 },
4237 { &MFVideoFormat_IMC2
, 4, 2, 12 },
4238 { &MFVideoFormat_IMC2
, 320, 240, 115200 },
4239 { &MFVideoFormat_IMC4
, 1, 3, 9, 4 },
4240 { &MFVideoFormat_IMC4
, 1, 2, 6, 3 },
4241 { &MFVideoFormat_IMC4
, 2, 2, 6, 6 },
4242 { &MFVideoFormat_IMC4
, 3, 2, 12, 9 },
4243 { &MFVideoFormat_IMC4
, 4, 2, 12 },
4244 { &MFVideoFormat_IMC4
, 320, 240, 115200 },
4245 { &MFVideoFormat_YV12
, 1, 1, 3, 1 },
4246 { &MFVideoFormat_YV12
, 2, 1, 3 },
4247 { &MFVideoFormat_YV12
, 1, 2, 6, 3 },
4248 { &MFVideoFormat_YV12
, 4, 3, 18 },
4249 { &MFVideoFormat_YV12
, 320, 240, 115200 },
4251 { &MFVideoFormat_I420
, 1, 1, 3, 1 },
4252 { &MFVideoFormat_I420
, 2, 1, 3 },
4253 { &MFVideoFormat_I420
, 1, 2, 6, 3 },
4254 { &MFVideoFormat_I420
, 4, 3, 18 },
4255 { &MFVideoFormat_I420
, 320, 240, 115200 },
4257 { &MFVideoFormat_IYUV
, 1, 1, 3, 1 },
4258 { &MFVideoFormat_IYUV
, 2, 1, 3 },
4259 { &MFVideoFormat_IYUV
, 1, 2, 6, 3 },
4260 { &MFVideoFormat_IYUV
, 4, 3, 18 },
4261 { &MFVideoFormat_IYUV
, 320, 240, 115200 },
4263 { &MFVideoFormat_YUY2
, 2, 1, 4 },
4264 { &MFVideoFormat_YUY2
, 4, 3, 24 },
4265 { &MFVideoFormat_YUY2
, 128, 128, 32768 },
4266 { &MFVideoFormat_YUY2
, 320, 240, 153600 },
4268 { &MFVideoFormat_UYVY
, 2, 1, 4 },
4269 { &MFVideoFormat_UYVY
, 4, 3, 24 },
4270 { &MFVideoFormat_UYVY
, 128, 128, 32768 },
4271 { &MFVideoFormat_UYVY
, 320, 240, 153600 },
4274 static void test_MFCalculateImageSize(void)
4282 hr
= MFCalculateImageSize(&IID_IUnknown
, 1, 1, &size
);
4283 ok(hr
== E_INVALIDARG
|| broken(hr
== S_OK
) /* Vista */, "Unexpected hr %#lx.\n", hr
);
4284 ok(size
== 0, "Unexpected size %u.\n", size
);
4286 for (i
= 0; i
< ARRAY_SIZE(image_size_tests
); ++i
)
4288 const struct image_size_test
*ptr
= &image_size_tests
[i
];
4290 /* Those are supported since Win10. */
4291 BOOL is_broken
= IsEqualGUID(ptr
->subtype
, &MFVideoFormat_A16B16G16R16F
) ||
4292 IsEqualGUID(ptr
->subtype
, &MFVideoFormat_A2R10G10B10
);
4294 hr
= MFCalculateImageSize(ptr
->subtype
, ptr
->width
, ptr
->height
, &size
);
4295 ok(hr
== S_OK
|| (is_broken
&& hr
== E_INVALIDARG
), "%u: failed to calculate image size, hr %#lx.\n", i
, hr
);
4296 ok(size
== ptr
->size
, "%u: unexpected image size %u, expected %u. Size %u x %u, format %s.\n", i
, size
, ptr
->size
,
4297 ptr
->width
, ptr
->height
, wine_dbgstr_an((char *)&ptr
->subtype
->Data1
, 4));
4299 if (pMFGetPlaneSize
)
4301 unsigned int expected
= ptr
->plane_size
? ptr
->plane_size
: ptr
->size
;
4303 hr
= pMFGetPlaneSize(ptr
->subtype
->Data1
, ptr
->width
, ptr
->height
, &plane_size
);
4304 ok(hr
== S_OK
, "%u: failed to get plane size, hr %#lx.\n", i
, hr
);
4305 ok(plane_size
== expected
, "%u: unexpected plane size %lu, expected %u.\n", i
, plane_size
, expected
);
4310 static void test_MFGetPlaneSize(void)
4316 if (!pMFGetPlaneSize
)
4318 win_skip("MFGetPlaneSize() is not available.\n");
4323 hr
= pMFGetPlaneSize(0xdeadbeef, 64, 64, &size
);
4324 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
4325 ok(size
== 0, "Unexpected size %lu.\n", size
);
4327 for (i
= 0; i
< ARRAY_SIZE(image_size_tests
); ++i
)
4329 const struct image_size_test
*ptr
= &image_size_tests
[i
];
4330 unsigned int plane_size
= ptr
->plane_size
? ptr
->plane_size
: ptr
->size
;
4332 hr
= pMFGetPlaneSize(ptr
->subtype
->Data1
, ptr
->width
, ptr
->height
, &size
);
4333 ok(hr
== S_OK
, "%u: failed to get plane size, hr %#lx.\n", i
, hr
);
4334 ok(size
== plane_size
, "%u: unexpected plane size %lu, expected %u.\n", i
, size
, plane_size
);
4338 static void test_MFCompareFullToPartialMediaType(void)
4340 IMFMediaType
*full_type
, *partial_type
;
4344 hr
= MFCreateMediaType(&full_type
);
4345 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
4347 hr
= MFCreateMediaType(&partial_type
);
4348 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
4350 ret
= MFCompareFullToPartialMediaType(full_type
, partial_type
);
4351 ok(!ret
, "Unexpected result %d.\n", ret
);
4353 hr
= IMFMediaType_SetGUID(full_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4354 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
4356 hr
= IMFMediaType_SetGUID(partial_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4357 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
4359 ret
= MFCompareFullToPartialMediaType(full_type
, partial_type
);
4360 ok(ret
, "Unexpected result %d.\n", ret
);
4362 hr
= IMFMediaType_SetGUID(full_type
, &MF_MT_SUBTYPE
, &MFMediaType_Audio
);
4363 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
4365 ret
= MFCompareFullToPartialMediaType(full_type
, partial_type
);
4366 ok(ret
, "Unexpected result %d.\n", ret
);
4368 hr
= IMFMediaType_SetGUID(partial_type
, &MF_MT_SUBTYPE
, &MFMediaType_Video
);
4369 ok(hr
== S_OK
, "Failed to set major type, hr %#lx.\n", hr
);
4371 ret
= MFCompareFullToPartialMediaType(full_type
, partial_type
);
4372 ok(!ret
, "Unexpected result %d.\n", ret
);
4374 IMFMediaType_Release(full_type
);
4375 IMFMediaType_Release(partial_type
);
4378 static void test_attributes_serialization(void)
4380 static const UINT8 blob
[] = {1,2,3};
4381 IMFAttributes
*attributes
, *dest
;
4382 UINT32 size
, count
, value32
;
4391 hr
= MFCreateAttributes(&attributes
, 0);
4392 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
4394 hr
= MFCreateAttributes(&dest
, 0);
4395 ok(hr
== S_OK
, "Failed to create object, hr %#lx.\n", hr
);
4397 hr
= MFGetAttributesAsBlobSize(attributes
, &size
);
4398 ok(hr
== S_OK
, "Failed to get blob size, hr %#lx.\n", hr
);
4399 ok(size
== 8, "Got size %u.\n", size
);
4401 buffer
= malloc(size
);
4403 hr
= MFGetAttributesAsBlob(attributes
, buffer
, size
);
4404 ok(hr
== S_OK
, "Failed to serialize, hr %#lx.\n", hr
);
4406 hr
= MFGetAttributesAsBlob(attributes
, buffer
, size
- 1);
4407 ok(hr
== MF_E_BUFFERTOOSMALL
, "Unexpected hr %#lx.\n", hr
);
4409 hr
= MFInitAttributesFromBlob(dest
, buffer
, size
- 1);
4410 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4412 hr
= IMFAttributes_SetUINT32(dest
, &MF_MT_MAJOR_TYPE
, 1);
4413 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4415 hr
= MFInitAttributesFromBlob(dest
, buffer
, size
);
4416 ok(hr
== S_OK
, "Failed to deserialize, hr %#lx.\n", hr
);
4418 /* Previous items are cleared. */
4419 hr
= IMFAttributes_GetCount(dest
, &count
);
4420 ok(hr
== S_OK
, "Failed to get attribute count, hr %#lx.\n", hr
);
4421 ok(count
== 0, "Unexpected count %u.\n", count
);
4425 /* Set some attributes of various types. */
4426 IMFAttributes_SetUINT32(attributes
, &MF_MT_MAJOR_TYPE
, 456);
4427 IMFAttributes_SetUINT64(attributes
, &MF_MT_SUBTYPE
, 123);
4428 IMFAttributes_SetDouble(attributes
, &IID_IUnknown
, 0.5);
4429 IMFAttributes_SetUnknown(attributes
, &IID_IMFAttributes
, (IUnknown
*)attributes
);
4430 IMFAttributes_SetGUID(attributes
, &GUID_NULL
, &IID_IUnknown
);
4431 IMFAttributes_SetString(attributes
, &DUMMY_CLSID
, L
"Text");
4432 IMFAttributes_SetBlob(attributes
, &DUMMY_GUID1
, blob
, sizeof(blob
));
4434 hr
= MFGetAttributesAsBlobSize(attributes
, &size
);
4435 ok(hr
== S_OK
, "Failed to get blob size, hr %#lx.\n", hr
);
4436 ok(size
> 8, "Got unexpected size %u.\n", size
);
4438 buffer
= malloc(size
);
4439 hr
= MFGetAttributesAsBlob(attributes
, buffer
, size
);
4440 ok(hr
== S_OK
, "Failed to serialize, hr %#lx.\n", hr
);
4441 hr
= MFInitAttributesFromBlob(dest
, buffer
, size
);
4442 ok(hr
== S_OK
, "Failed to deserialize, hr %#lx.\n", hr
);
4445 hr
= IMFAttributes_GetUINT32(dest
, &MF_MT_MAJOR_TYPE
, &value32
);
4446 ok(hr
== S_OK
, "Failed to get get uint32 value, hr %#lx.\n", hr
);
4447 ok(value32
== 456, "Unexpected value %u.\n", value32
);
4448 hr
= IMFAttributes_GetUINT64(dest
, &MF_MT_SUBTYPE
, &value64
);
4449 ok(hr
== S_OK
, "Failed to get get uint64 value, hr %#lx.\n", hr
);
4450 ok(value64
== 123, "Unexpected value.\n");
4451 hr
= IMFAttributes_GetDouble(dest
, &IID_IUnknown
, &value_dbl
);
4452 ok(hr
== S_OK
, "Failed to get get double value, hr %#lx.\n", hr
);
4453 ok(value_dbl
== 0.5, "Unexpected value.\n");
4454 hr
= IMFAttributes_GetUnknown(dest
, &IID_IMFAttributes
, &IID_IUnknown
, (void **)&obj
);
4455 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
4456 hr
= IMFAttributes_GetGUID(dest
, &GUID_NULL
, &guid
);
4457 ok(hr
== S_OK
, "Failed to get guid value, hr %#lx.\n", hr
);
4458 ok(IsEqualGUID(&guid
, &IID_IUnknown
), "Unexpected guid.\n");
4459 hr
= IMFAttributes_GetAllocatedString(dest
, &DUMMY_CLSID
, &str
, &size
);
4460 ok(hr
== S_OK
, "Failed to get string value, hr %#lx.\n", hr
);
4461 ok(!lstrcmpW(str
, L
"Text"), "Unexpected string.\n");
4463 hr
= IMFAttributes_GetAllocatedBlob(dest
, &DUMMY_GUID1
, &buffer
, &size
);
4464 ok(hr
== S_OK
, "Failed to get blob value, hr %#lx.\n", hr
);
4465 ok(!memcmp(buffer
, blob
, sizeof(blob
)), "Unexpected blob.\n");
4466 CoTaskMemFree(buffer
);
4468 IMFAttributes_Release(attributes
);
4469 IMFAttributes_Release(dest
);
4472 static void test_wrapped_media_type(void)
4474 IMFMediaType
*mediatype
, *mediatype2
;
4479 hr
= MFCreateMediaType(&mediatype
);
4480 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
4482 hr
= MFUnwrapMediaType(mediatype
, &mediatype2
);
4483 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
4485 hr
= IMFMediaType_SetUINT32(mediatype
, &GUID_NULL
, 1);
4486 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4487 hr
= IMFMediaType_SetUINT32(mediatype
, &DUMMY_GUID1
, 2);
4488 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4490 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
4491 ok(hr
== S_OK
, "Failed to set GUID value, hr %#lx.\n", hr
);
4493 hr
= MFWrapMediaType(mediatype
, &MFMediaType_Audio
, &IID_IUnknown
, &mediatype2
);
4494 ok(hr
== S_OK
, "Failed to create wrapped media type, hr %#lx.\n", hr
);
4496 hr
= IMFMediaType_GetGUID(mediatype2
, &MF_MT_MAJOR_TYPE
, &guid
);
4497 ok(hr
== S_OK
, "Failed to get major type, hr %#lx.\n", hr
);
4498 ok(IsEqualGUID(&guid
, &MFMediaType_Audio
), "Unexpected major type.\n");
4500 hr
= IMFMediaType_GetGUID(mediatype2
, &MF_MT_SUBTYPE
, &guid
);
4501 ok(hr
== S_OK
, "Failed to get subtype, hr %#lx.\n", hr
);
4502 ok(IsEqualGUID(&guid
, &IID_IUnknown
), "Unexpected major type.\n");
4504 hr
= IMFMediaType_GetCount(mediatype2
, &count
);
4505 ok(hr
== S_OK
, "Failed to get item count, hr %#lx.\n", hr
);
4506 ok(count
== 3, "Unexpected count %u.\n", count
);
4508 hr
= IMFMediaType_GetItemType(mediatype2
, &MF_MT_WRAPPED_TYPE
, &type
);
4509 ok(hr
== S_OK
, "Failed to get item type, hr %#lx.\n", hr
);
4510 ok(type
== MF_ATTRIBUTE_BLOB
, "Unexpected item type.\n");
4512 IMFMediaType_Release(mediatype
);
4514 hr
= MFUnwrapMediaType(mediatype2
, &mediatype
);
4515 ok(hr
== S_OK
, "Failed to unwrap, hr %#lx.\n", hr
);
4517 hr
= IMFMediaType_GetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &guid
);
4518 ok(hr
== S_OK
, "Failed to get major type, hr %#lx.\n", hr
);
4519 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected major type.\n");
4521 hr
= IMFMediaType_GetGUID(mediatype
, &MF_MT_SUBTYPE
, &guid
);
4522 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
4524 IMFMediaType_Release(mediatype
);
4525 IMFMediaType_Release(mediatype2
);
4528 static void test_MFCreateWaveFormatExFromMFMediaType(void)
4530 static const struct wave_fmt_test
4532 const GUID
*subtype
;
4537 { &MFAudioFormat_PCM
, WAVE_FORMAT_PCM
, },
4538 { &MFAudioFormat_Float
, WAVE_FORMAT_IEEE_FLOAT
, },
4540 WAVEFORMATEXTENSIBLE
*format_ext
;
4541 IMFMediaType
*mediatype
;
4542 WAVEFORMATEX
*format
;
4546 hr
= MFCreateMediaType(&mediatype
);
4547 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
4549 hr
= MFCreateWaveFormatExFromMFMediaType(mediatype
, &format
, &size
, MFWaveFormatExConvertFlag_Normal
);
4550 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
4552 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
4553 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4555 hr
= MFCreateWaveFormatExFromMFMediaType(mediatype
, &format
, &size
, MFWaveFormatExConvertFlag_Normal
);
4556 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
4558 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_SUBTYPE
, &MFMediaType_Video
);
4559 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4561 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
4562 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4564 for (i
= 0; i
< ARRAY_SIZE(wave_fmt_tests
); ++i
)
4566 hr
= IMFMediaType_SetGUID(mediatype
, &MF_MT_SUBTYPE
, wave_fmt_tests
[i
].subtype
);
4567 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
4569 hr
= MFCreateWaveFormatExFromMFMediaType(mediatype
, &format
, &size
, MFWaveFormatExConvertFlag_Normal
);
4570 ok(hr
== S_OK
, "Failed to create format, hr %#lx.\n", hr
);
4571 ok(format
!= NULL
, "Expected format structure.\n");
4572 ok(size
== sizeof(*format
), "Unexpected size %u.\n", size
);
4573 ok(format
->wFormatTag
== wave_fmt_tests
[i
].format_tag
, "Expected tag %u, got %u.\n", wave_fmt_tests
[i
].format_tag
, format
->wFormatTag
);
4574 ok(format
->nChannels
== 0, "Unexpected number of channels, %u.\n", format
->nChannels
);
4575 ok(format
->nSamplesPerSec
== 0, "Unexpected sample rate, %lu.\n", format
->nSamplesPerSec
);
4576 ok(format
->nAvgBytesPerSec
== 0, "Unexpected average data rate rate, %lu.\n", format
->nAvgBytesPerSec
);
4577 ok(format
->nBlockAlign
== 0, "Unexpected alignment, %u.\n", format
->nBlockAlign
);
4578 ok(format
->wBitsPerSample
== 0, "Unexpected sample size, %u.\n", format
->wBitsPerSample
);
4579 ok(format
->cbSize
== 0, "Unexpected size field, %u.\n", format
->cbSize
);
4580 CoTaskMemFree(format
);
4582 hr
= MFCreateWaveFormatExFromMFMediaType(mediatype
, (WAVEFORMATEX
**)&format_ext
, &size
,
4583 MFWaveFormatExConvertFlag_ForceExtensible
);
4584 ok(hr
== S_OK
, "Failed to create format, hr %#lx.\n", hr
);
4585 ok(format_ext
!= NULL
, "Expected format structure.\n");
4586 ok(size
== sizeof(*format_ext
), "Unexpected size %u.\n", size
);
4587 ok(format_ext
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
, "Unexpected tag.\n");
4588 ok(format_ext
->Format
.nChannels
== 0, "Unexpected number of channels, %u.\n", format_ext
->Format
.nChannels
);
4589 ok(format_ext
->Format
.nSamplesPerSec
== 0, "Unexpected sample rate, %lu.\n", format_ext
->Format
.nSamplesPerSec
);
4590 ok(format_ext
->Format
.nAvgBytesPerSec
== 0, "Unexpected average data rate rate, %lu.\n",
4591 format_ext
->Format
.nAvgBytesPerSec
);
4592 ok(format_ext
->Format
.nBlockAlign
== 0, "Unexpected alignment, %u.\n", format_ext
->Format
.nBlockAlign
);
4593 ok(format_ext
->Format
.wBitsPerSample
== 0, "Unexpected sample size, %u.\n", format_ext
->Format
.wBitsPerSample
);
4594 ok(format_ext
->Format
.cbSize
== sizeof(*format_ext
) - sizeof(format_ext
->Format
), "Unexpected size field, %u.\n",
4595 format_ext
->Format
.cbSize
);
4596 CoTaskMemFree(format_ext
);
4598 hr
= MFCreateWaveFormatExFromMFMediaType(mediatype
, &format
, &size
, MFWaveFormatExConvertFlag_ForceExtensible
+ 1);
4599 ok(hr
== S_OK
, "Failed to create format, hr %#lx.\n", hr
);
4600 ok(size
== sizeof(*format
), "Unexpected size %u.\n", size
);
4601 CoTaskMemFree(format
);
4604 IMFMediaType_Release(mediatype
);
4607 static HRESULT WINAPI
test_create_file_callback_Invoke(IMFAsyncCallback
*iface
, IMFAsyncResult
*result
)
4609 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
4610 IMFByteStream
*stream
;
4614 ok(!!result
, "Unexpected result object.\n");
4616 ok((IUnknown
*)iface
== IMFAsyncResult_GetStateNoAddRef(result
), "Unexpected result state.\n");
4618 hr
= IMFAsyncResult_GetObject(result
, &object
);
4619 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
4621 hr
= MFEndCreateFile(result
, &stream
);
4622 ok(hr
== S_OK
, "Failed to get file stream, hr %#lx.\n", hr
);
4623 IMFByteStream_Release(stream
);
4625 SetEvent(callback
->event
);
4630 static const IMFAsyncCallbackVtbl test_create_file_callback_vtbl
=
4632 testcallback_QueryInterface
,
4633 testcallback_AddRef
,
4634 testcallback_Release
,
4635 testcallback_GetParameters
,
4636 test_create_file_callback_Invoke
,
4639 static void test_async_create_file(void)
4641 WCHAR pathW
[MAX_PATH
], fileW
[MAX_PATH
];
4642 struct test_callback
*callback
;
4643 IUnknown
*cancel_cookie
;
4647 callback
= create_test_callback(&test_create_file_callback_vtbl
);
4649 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
4650 ok(hr
== S_OK
, "Fail to start up, hr %#lx.\n", hr
);
4652 callback
->event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
4654 GetTempPathW(ARRAY_SIZE(pathW
), pathW
);
4655 GetTempFileNameW(pathW
, NULL
, 0, fileW
);
4657 hr
= MFBeginCreateFile(MF_ACCESSMODE_READWRITE
, MF_OPENMODE_DELETE_IF_EXIST
, MF_FILEFLAGS_NONE
, fileW
,
4658 &callback
->IMFAsyncCallback_iface
, (IUnknown
*)&callback
->IMFAsyncCallback_iface
, &cancel_cookie
);
4659 ok(hr
== S_OK
, "Async create request failed, hr %#lx.\n", hr
);
4660 ok(cancel_cookie
!= NULL
, "Unexpected cancellation object.\n");
4662 WaitForSingleObject(callback
->event
, INFINITE
);
4664 IUnknown_Release(cancel_cookie
);
4666 CloseHandle(callback
->event
);
4669 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
4671 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
4673 ret
= DeleteFileW(fileW
);
4674 ok(ret
, "Failed to delete test file.\n");
4677 struct activate_object
4679 IMFActivate IMFActivate_iface
;
4683 static HRESULT WINAPI
activate_object_QueryInterface(IMFActivate
*iface
, REFIID riid
, void **obj
)
4685 if (IsEqualIID(riid
, &IID_IMFActivate
) ||
4686 IsEqualIID(riid
, &IID_IMFAttributes
) ||
4687 IsEqualIID(riid
, &IID_IUnknown
))
4690 IMFActivate_AddRef(iface
);
4695 return E_NOINTERFACE
;
4698 static ULONG WINAPI
activate_object_AddRef(IMFActivate
*iface
)
4703 static ULONG WINAPI
activate_object_Release(IMFActivate
*iface
)
4708 static HRESULT WINAPI
activate_object_GetItem(IMFActivate
*iface
, REFGUID key
, PROPVARIANT
*value
)
4713 static HRESULT WINAPI
activate_object_GetItemType(IMFActivate
*iface
, REFGUID key
, MF_ATTRIBUTE_TYPE
*type
)
4718 static HRESULT WINAPI
activate_object_CompareItem(IMFActivate
*iface
, REFGUID key
, REFPROPVARIANT value
, BOOL
*result
)
4723 static HRESULT WINAPI
activate_object_Compare(IMFActivate
*iface
, IMFAttributes
*theirs
, MF_ATTRIBUTES_MATCH_TYPE type
,
4729 static HRESULT WINAPI
activate_object_GetUINT32(IMFActivate
*iface
, REFGUID key
, UINT32
*value
)
4734 static HRESULT WINAPI
activate_object_GetUINT64(IMFActivate
*iface
, REFGUID key
, UINT64
*value
)
4739 static HRESULT WINAPI
activate_object_GetDouble(IMFActivate
*iface
, REFGUID key
, double *value
)
4744 static HRESULT WINAPI
activate_object_GetGUID(IMFActivate
*iface
, REFGUID key
, GUID
*value
)
4749 static HRESULT WINAPI
activate_object_GetStringLength(IMFActivate
*iface
, REFGUID key
, UINT32
*length
)
4754 static HRESULT WINAPI
activate_object_GetString(IMFActivate
*iface
, REFGUID key
, WCHAR
*value
,
4755 UINT32 size
, UINT32
*length
)
4760 static HRESULT WINAPI
activate_object_GetAllocatedString(IMFActivate
*iface
, REFGUID key
,
4761 WCHAR
**value
, UINT32
*length
)
4766 static HRESULT WINAPI
activate_object_GetBlobSize(IMFActivate
*iface
, REFGUID key
, UINT32
*size
)
4771 static HRESULT WINAPI
activate_object_GetBlob(IMFActivate
*iface
, REFGUID key
, UINT8
*buf
,
4772 UINT32 bufsize
, UINT32
*blobsize
)
4777 static HRESULT WINAPI
activate_object_GetAllocatedBlob(IMFActivate
*iface
, REFGUID key
, UINT8
**buf
, UINT32
*size
)
4782 static HRESULT WINAPI
activate_object_GetUnknown(IMFActivate
*iface
, REFGUID key
, REFIID riid
, void **ppv
)
4787 static HRESULT WINAPI
activate_object_SetItem(IMFActivate
*iface
, REFGUID key
, REFPROPVARIANT value
)
4792 static HRESULT WINAPI
activate_object_DeleteItem(IMFActivate
*iface
, REFGUID key
)
4797 static HRESULT WINAPI
activate_object_DeleteAllItems(IMFActivate
*iface
)
4802 static HRESULT WINAPI
activate_object_SetUINT32(IMFActivate
*iface
, REFGUID key
, UINT32 value
)
4807 static HRESULT WINAPI
activate_object_SetUINT64(IMFActivate
*iface
, REFGUID key
, UINT64 value
)
4812 static HRESULT WINAPI
activate_object_SetDouble(IMFActivate
*iface
, REFGUID key
, double value
)
4817 static HRESULT WINAPI
activate_object_SetGUID(IMFActivate
*iface
, REFGUID key
, REFGUID value
)
4822 static HRESULT WINAPI
activate_object_SetString(IMFActivate
*iface
, REFGUID key
, const WCHAR
*value
)
4827 static HRESULT WINAPI
activate_object_SetBlob(IMFActivate
*iface
, REFGUID key
, const UINT8
*buf
, UINT32 size
)
4832 static HRESULT WINAPI
activate_object_SetUnknown(IMFActivate
*iface
, REFGUID key
, IUnknown
*unknown
)
4837 static HRESULT WINAPI
activate_object_LockStore(IMFActivate
*iface
)
4842 static HRESULT WINAPI
activate_object_UnlockStore(IMFActivate
*iface
)
4847 static HRESULT WINAPI
activate_object_GetCount(IMFActivate
*iface
, UINT32
*count
)
4852 static HRESULT WINAPI
activate_object_GetItemByIndex(IMFActivate
*iface
, UINT32 index
, GUID
*key
, PROPVARIANT
*value
)
4857 static HRESULT WINAPI
activate_object_CopyAllItems(IMFActivate
*iface
, IMFAttributes
*dest
)
4862 static HRESULT WINAPI
activate_object_ActivateObject(IMFActivate
*iface
, REFIID riid
, void **obj
)
4867 static HRESULT WINAPI
activate_object_ShutdownObject(IMFActivate
*iface
)
4872 static HRESULT WINAPI
activate_object_DetachObject(IMFActivate
*iface
)
4877 static const IMFActivateVtbl activate_object_vtbl
=
4879 activate_object_QueryInterface
,
4880 activate_object_AddRef
,
4881 activate_object_Release
,
4882 activate_object_GetItem
,
4883 activate_object_GetItemType
,
4884 activate_object_CompareItem
,
4885 activate_object_Compare
,
4886 activate_object_GetUINT32
,
4887 activate_object_GetUINT64
,
4888 activate_object_GetDouble
,
4889 activate_object_GetGUID
,
4890 activate_object_GetStringLength
,
4891 activate_object_GetString
,
4892 activate_object_GetAllocatedString
,
4893 activate_object_GetBlobSize
,
4894 activate_object_GetBlob
,
4895 activate_object_GetAllocatedBlob
,
4896 activate_object_GetUnknown
,
4897 activate_object_SetItem
,
4898 activate_object_DeleteItem
,
4899 activate_object_DeleteAllItems
,
4900 activate_object_SetUINT32
,
4901 activate_object_SetUINT64
,
4902 activate_object_SetDouble
,
4903 activate_object_SetGUID
,
4904 activate_object_SetString
,
4905 activate_object_SetBlob
,
4906 activate_object_SetUnknown
,
4907 activate_object_LockStore
,
4908 activate_object_UnlockStore
,
4909 activate_object_GetCount
,
4910 activate_object_GetItemByIndex
,
4911 activate_object_CopyAllItems
,
4912 activate_object_ActivateObject
,
4913 activate_object_ShutdownObject
,
4914 activate_object_DetachObject
,
4917 static void test_local_handlers(void)
4919 IMFActivate local_activate
= { &activate_object_vtbl
};
4920 static const WCHAR localW
[] = L
"local";
4923 if (!pMFRegisterLocalSchemeHandler
)
4925 win_skip("Local handlers are not supported.\n");
4929 hr
= pMFRegisterLocalSchemeHandler(NULL
, NULL
);
4930 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4932 hr
= pMFRegisterLocalSchemeHandler(localW
, NULL
);
4933 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4935 hr
= pMFRegisterLocalSchemeHandler(NULL
, &local_activate
);
4936 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4938 hr
= pMFRegisterLocalSchemeHandler(localW
, &local_activate
);
4939 ok(hr
== S_OK
, "Failed to register scheme handler, hr %#lx.\n", hr
);
4941 hr
= pMFRegisterLocalSchemeHandler(localW
, &local_activate
);
4942 ok(hr
== S_OK
, "Failed to register scheme handler, hr %#lx.\n", hr
);
4944 hr
= pMFRegisterLocalByteStreamHandler(NULL
, NULL
, NULL
);
4945 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4947 hr
= pMFRegisterLocalByteStreamHandler(NULL
, NULL
, &local_activate
);
4948 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4950 hr
= pMFRegisterLocalByteStreamHandler(NULL
, localW
, &local_activate
);
4951 ok(hr
== S_OK
, "Failed to register stream handler, hr %#lx.\n", hr
);
4953 hr
= pMFRegisterLocalByteStreamHandler(localW
, NULL
, &local_activate
);
4954 ok(hr
== S_OK
, "Failed to register stream handler, hr %#lx.\n", hr
);
4956 hr
= pMFRegisterLocalByteStreamHandler(localW
, localW
, &local_activate
);
4957 ok(hr
== S_OK
, "Failed to register stream handler, hr %#lx.\n", hr
);
4960 static void test_create_property_store(void)
4962 static const PROPERTYKEY test_pkey
= {{0x12345678}, 9};
4963 IPropertyStore
*store
, *store2
;
4964 PROPVARIANT value
= {0};
4970 hr
= CreatePropertyStore(NULL
);
4971 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4973 hr
= CreatePropertyStore(&store
);
4974 ok(hr
== S_OK
, "Failed to create property store, hr %#lx.\n", hr
);
4976 hr
= CreatePropertyStore(&store2
);
4977 ok(hr
== S_OK
, "Failed to create property store, hr %#lx.\n", hr
);
4978 ok(store2
!= store
, "Expected different store objects.\n");
4979 IPropertyStore_Release(store2
);
4981 check_interface(store
, &IID_IPropertyStoreCache
, FALSE
);
4982 check_interface(store
, &IID_IPersistSerializedPropStorage
, FALSE
);
4984 hr
= IPropertyStore_GetCount(store
, NULL
);
4985 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4988 hr
= IPropertyStore_GetCount(store
, &count
);
4989 ok(hr
== S_OK
, "Failed to get count, hr %#lx.\n", hr
);
4990 ok(!count
, "Unexpected count %lu.\n", count
);
4992 hr
= IPropertyStore_Commit(store
);
4993 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
4995 hr
= IPropertyStore_GetAt(store
, 0, &key
);
4996 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
4998 hr
= IPropertyStore_GetValue(store
, NULL
, &value
);
4999 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
5001 hr
= IPropertyStore_GetValue(store
, &test_pkey
, NULL
);
5002 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
5004 hr
= IPropertyStore_GetValue(store
, &test_pkey
, &value
);
5005 ok(hr
== S_FALSE
, "Unexpected hr %#lx.\n", hr
);
5007 memset(&value
, 0, sizeof(PROPVARIANT
));
5009 value
.lVal
= 0xdeadbeef;
5010 hr
= IPropertyStore_SetValue(store
, &test_pkey
, &value
);
5011 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5015 /* crashes on Windows */
5016 hr
= IPropertyStore_SetValue(store
, NULL
, &value
);
5017 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5020 hr
= IPropertyStore_GetCount(store
, &count
);
5021 ok(hr
== S_OK
, "Failed to get count, hr %#lx.\n", hr
);
5022 ok(count
== 1, "Unexpected count %lu.\n", count
);
5024 hr
= IPropertyStore_Commit(store
);
5025 ok(hr
== E_NOTIMPL
, "Unexpected hr %#lx.\n", hr
);
5027 hr
= IPropertyStore_GetAt(store
, 0, &key
);
5028 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5029 ok(!memcmp(&key
, &test_pkey
, sizeof(PROPERTYKEY
)), "Keys didn't match.\n");
5031 hr
= IPropertyStore_GetAt(store
, 1, &key
);
5032 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
5034 memset(&value
, 0xcc, sizeof(PROPVARIANT
));
5035 hr
= IPropertyStore_GetValue(store
, &test_pkey
, &value
);
5036 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5037 ok(value
.vt
== VT_I4
, "Unexpected type %u.\n", value
.vt
);
5038 ok(value
.lVal
== 0xdeadbeef, "Unexpected value %#lx.\n", value
.lVal
);
5040 memset(&value
, 0, sizeof(PROPVARIANT
));
5041 hr
= IPropertyStore_SetValue(store
, &test_pkey
, &value
);
5042 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5044 hr
= IPropertyStore_GetCount(store
, &count
);
5045 ok(hr
== S_OK
, "Failed to get count, hr %#lx.\n", hr
);
5046 ok(count
== 1, "Unexpected count %lu.\n", count
);
5048 memset(&value
, 0xcc, sizeof(PROPVARIANT
));
5049 hr
= IPropertyStore_GetValue(store
, &test_pkey
, &value
);
5050 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5051 ok(value
.vt
== VT_EMPTY
, "Unexpected type %u.\n", value
.vt
);
5052 ok(!value
.lVal
, "Unexpected value %#lx.\n", value
.lVal
);
5054 refcount
= IPropertyStore_Release(store
);
5055 ok(!refcount
, "Unexpected refcount %lu.\n", refcount
);
5058 struct test_thread_param
5060 IMFDXGIDeviceManager
*manager
;
5065 static DWORD WINAPI
test_device_manager_thread(void *arg
)
5067 struct test_thread_param
*param
= arg
;
5068 ID3D11Device
*device
;
5073 hr
= IMFDXGIDeviceManager_LockDevice(param
->manager
, param
->handle
, &IID_ID3D11Device
,
5074 (void **)&device
, FALSE
);
5076 ID3D11Device_Release(device
);
5079 hr
= IMFDXGIDeviceManager_UnlockDevice(param
->manager
, param
->handle
, FALSE
);
5084 static void test_dxgi_device_manager(void)
5086 IMFDXGIDeviceManager
*manager
, *manager2
;
5087 ID3D11Device
*device
, *d3d11_dev
, *d3d11_dev2
;
5088 struct test_thread_param param
;
5089 HANDLE handle1
, handle
, thread
;
5094 if (!pMFCreateDXGIDeviceManager
)
5096 win_skip("MFCreateDXGIDeviceManager not found.\n");
5100 hr
= pMFCreateDXGIDeviceManager(NULL
, &manager
);
5101 ok(hr
== E_POINTER
, "MFCreateDXGIDeviceManager should failed: %#lx.\n", hr
);
5104 hr
= pMFCreateDXGIDeviceManager(&token
, NULL
);
5105 ok(hr
== E_POINTER
, "MFCreateDXGIDeviceManager should failed: %#lx.\n", hr
);
5106 ok(!token
, "got wrong token: %u.\n", token
);
5108 hr
= pMFCreateDXGIDeviceManager(&token
, &manager
);
5109 ok(hr
== S_OK
, "MFCreateDXGIDeviceManager failed: %#lx.\n", hr
);
5110 EXPECT_REF(manager
, 1);
5111 ok(!!token
, "got wrong token: %u.\n", token
);
5115 hr
= pMFCreateDXGIDeviceManager(&token2
, &manager2
);
5116 ok(hr
== S_OK
, "MFCreateDXGIDeviceManager failed: %#lx.\n", hr
);
5117 EXPECT_REF(manager2
, 1);
5118 ok(token2
&& token2
!= token
, "got wrong token: %u, %u.\n", token2
, token
);
5119 ok(manager
!= manager2
, "got wrong pointer: %p.\n", manager2
);
5120 EXPECT_REF(manager
, 1);
5122 hr
= IMFDXGIDeviceManager_GetVideoService(manager
, NULL
, &IID_ID3D11Device
, (void **)&unk
);
5123 ok(hr
== MF_E_DXGI_DEVICE_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
5125 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle
);
5126 ok(hr
== MF_E_DXGI_DEVICE_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
5128 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, 0);
5129 ok(hr
== E_HANDLE
, "Unexpected hr %#lx.\n", hr
);
5131 hr
= pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, D3D11_CREATE_DEVICE_VIDEO_SUPPORT
,
5132 NULL
, 0, D3D11_SDK_VERSION
, &d3d11_dev
, NULL
, NULL
);
5133 ok(hr
== S_OK
, "D3D11CreateDevice failed: %#lx.\n", hr
);
5134 EXPECT_REF(d3d11_dev
, 1);
5136 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)d3d11_dev
, token
- 1);
5137 ok(hr
== E_INVALIDARG
, "IMFDXGIDeviceManager_ResetDevice should failed: %#lx.\n", hr
);
5138 EXPECT_REF(d3d11_dev
, 1);
5140 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, NULL
, token
);
5141 ok(hr
== E_INVALIDARG
, "IMFDXGIDeviceManager_ResetDevice should failed: %#lx.\n", hr
);
5143 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)d3d11_dev
, token
);
5144 ok(hr
== S_OK
, "IMFDXGIDeviceManager_ResetDevice failed: %#lx.\n", hr
);
5145 EXPECT_REF(manager
, 1);
5146 EXPECT_REF(d3d11_dev
, 2);
5148 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)manager2
, token
);
5149 ok(hr
== E_INVALIDARG
, "IMFDXGIDeviceManager_ResetDevice should failed: %#lx.\n", hr
);
5150 EXPECT_REF(manager2
, 1);
5151 EXPECT_REF(d3d11_dev
, 2);
5153 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)d3d11_dev
, token
);
5154 ok(hr
== S_OK
, "IMFDXGIDeviceManager_ResetDevice failed: %#lx.\n", hr
);
5155 EXPECT_REF(manager
, 1);
5156 EXPECT_REF(d3d11_dev
, 2);
5158 /* GetVideoService() on device change. */
5160 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle
);
5161 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5162 ok(!!handle
, "Unexpected handle value %p.\n", handle
);
5164 hr
= pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0,
5165 NULL
, 0, D3D11_SDK_VERSION
, &d3d11_dev2
, NULL
, NULL
);
5166 ok(hr
== S_OK
, "D3D11CreateDevice failed: %#lx.\n", hr
);
5167 EXPECT_REF(d3d11_dev2
, 1);
5168 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)d3d11_dev2
, token
);
5169 ok(hr
== S_OK
, "IMFDXGIDeviceManager_ResetDevice failed: %#lx.\n", hr
);
5170 EXPECT_REF(manager
, 1);
5171 EXPECT_REF(d3d11_dev2
, 2);
5172 EXPECT_REF(d3d11_dev
, 1);
5174 hr
= IMFDXGIDeviceManager_GetVideoService(manager
, handle
, &IID_ID3D11Device
, (void **)&unk
);
5175 ok(hr
== MF_E_DXGI_NEW_VIDEO_DEVICE
, "Unexpected hr %#lx.\n", hr
);
5177 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle
);
5178 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5181 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle
);
5182 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5183 ok(!!handle
, "Unexpected handle value %p.\n", handle
);
5185 hr
= IMFDXGIDeviceManager_GetVideoService(manager
, NULL
, &IID_ID3D11Device
, (void **)&unk
);
5186 ok(hr
== E_HANDLE
, "Unexpected hr %#lx.\n", hr
);
5188 hr
= IMFDXGIDeviceManager_GetVideoService(manager
, handle
, &IID_ID3D11Device
, (void **)&unk
);
5189 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5190 IUnknown_Release(unk
);
5192 hr
= IMFDXGIDeviceManager_GetVideoService(manager
, handle
, &IID_IUnknown
, (void **)&unk
);
5193 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5194 IUnknown_Release(unk
);
5196 hr
= IMFDXGIDeviceManager_GetVideoService(manager
, handle
, &IID_IDXGIDevice
, (void **)&unk
);
5197 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5198 IUnknown_Release(unk
);
5201 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle1
);
5202 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5203 ok(handle
!= handle1
, "Unexpected handle.\n");
5205 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle
);
5206 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5208 /* Already closed. */
5209 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle
);
5210 ok(hr
== E_HANDLE
, "Unexpected hr %#lx.\n", hr
);
5213 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle
);
5214 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5216 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle1
);
5217 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5219 hr
= IMFDXGIDeviceManager_TestDevice(manager
, handle1
);
5220 ok(hr
== E_HANDLE
, "Unexpected hr %#lx.\n", hr
);
5222 hr
= IMFDXGIDeviceManager_LockDevice(manager
, handle
, &IID_ID3D11Device
, (void **)&device
, FALSE
);
5223 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5224 ok(device
== d3d11_dev2
, "Unexpected device pointer.\n");
5225 ID3D11Device_Release(device
);
5227 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle
, FALSE
);
5228 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5230 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle
, FALSE
);
5231 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
5233 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, UlongToHandle(100), FALSE
);
5234 ok(hr
== E_FAIL
, "Unexpected hr %#lx.\n", hr
);
5236 /* Locked with one handle, unlock with another. */
5237 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle1
);
5238 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5240 hr
= IMFDXGIDeviceManager_LockDevice(manager
, handle
, &IID_ID3D11Device
, (void **)&device
, FALSE
);
5241 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5243 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle1
, FALSE
);
5244 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
5246 ID3D11Device_Release(device
);
5248 /* Closing unlocks the device. */
5249 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle
);
5250 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5252 hr
= IMFDXGIDeviceManager_LockDevice(manager
, handle1
, &IID_ID3D11Device
, (void **)&device
, FALSE
);
5253 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5254 ID3D11Device_Release(device
);
5256 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle1
);
5257 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5259 /* Open two handles. */
5260 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle
);
5261 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5263 hr
= IMFDXGIDeviceManager_OpenDeviceHandle(manager
, &handle1
);
5264 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5266 hr
= IMFDXGIDeviceManager_LockDevice(manager
, handle
, &IID_ID3D11Device
, (void **)&device
, FALSE
);
5267 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5268 ID3D11Device_Release(device
);
5270 hr
= IMFDXGIDeviceManager_LockDevice(manager
, handle1
, &IID_ID3D11Device
, (void **)&device
, FALSE
);
5271 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5272 ID3D11Device_Release(device
);
5274 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle
, FALSE
);
5275 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5277 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle
, FALSE
);
5278 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
5280 param
.manager
= manager
;
5281 param
.handle
= handle
;
5283 thread
= CreateThread(NULL
, 0, test_device_manager_thread
, ¶m
, 0, NULL
);
5284 ok(!WaitForSingleObject(thread
, 1000), "Wait for a test thread failed.\n");
5285 GetExitCodeThread(thread
, (DWORD
*)&hr
);
5286 ok(hr
== MF_E_DXGI_VIDEO_DEVICE_LOCKED
, "Unexpected hr %#lx.\n", hr
);
5287 CloseHandle(thread
);
5289 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle1
, FALSE
);
5290 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5292 hr
= IMFDXGIDeviceManager_UnlockDevice(manager
, handle1
, FALSE
);
5293 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
5295 /* Lock on main thread, unlock on another. */
5296 hr
= IMFDXGIDeviceManager_LockDevice(manager
, handle
, &IID_ID3D11Device
, (void **)&device
, FALSE
);
5297 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5298 ID3D11Device_Release(device
);
5300 param
.manager
= manager
;
5301 param
.handle
= handle
;
5303 thread
= CreateThread(NULL
, 0, test_device_manager_thread
, ¶m
, 0, NULL
);
5304 ok(!WaitForSingleObject(thread
, 1000), "Wait for a test thread failed.\n");
5305 GetExitCodeThread(thread
, (DWORD
*)&hr
);
5306 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5307 CloseHandle(thread
);
5309 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle1
);
5310 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5312 hr
= IMFDXGIDeviceManager_CloseDeviceHandle(manager
, handle
);
5313 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5315 IMFDXGIDeviceManager_Release(manager
);
5316 EXPECT_REF(d3d11_dev2
, 1);
5317 ID3D11Device_Release(d3d11_dev
);
5318 ID3D11Device_Release(d3d11_dev2
);
5319 IMFDXGIDeviceManager_Release(manager2
);
5322 static void test_MFCreateTransformActivate(void)
5324 IMFActivate
*activate
;
5328 if (!pMFCreateTransformActivate
)
5330 win_skip("MFCreateTransformActivate() is not available.\n");
5334 hr
= pMFCreateTransformActivate(&activate
);
5335 ok(hr
== S_OK
, "Failed to create activator, hr %#lx.\n", hr
);
5337 hr
= IMFActivate_GetCount(activate
, &count
);
5338 ok(hr
== S_OK
, "Failed to get count, hr %#lx.\n", hr
);
5339 ok(!count
, "Unexpected attribute count %u.\n", count
);
5341 IMFActivate_Release(activate
);
5344 static HRESULT WINAPI
test_mft_factory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **obj
)
5346 if (IsEqualIID(riid
, &IID_IClassFactory
) ||
5347 IsEqualIID(riid
, &IID_IUnknown
))
5350 IClassFactory_AddRef(iface
);
5355 return E_NOINTERFACE
;
5358 static ULONG WINAPI
test_mft_factory_AddRef(IClassFactory
*iface
)
5363 static ULONG WINAPI
test_mft_factory_Release(IClassFactory
*iface
)
5368 static HRESULT WINAPI
test_mft_factory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **obj
)
5370 ok(0, "Unexpected call.\n");
5374 static HRESULT WINAPI
test_mft_factory_LockServer(IClassFactory
*iface
, BOOL fLock
)
5379 static const IClassFactoryVtbl test_mft_factory_vtbl
=
5381 test_mft_factory_QueryInterface
,
5382 test_mft_factory_AddRef
,
5383 test_mft_factory_Release
,
5384 test_mft_factory_CreateInstance
,
5385 test_mft_factory_LockServer
,
5388 static void test_MFTRegisterLocal(void)
5390 IClassFactory test_factory
= { &test_mft_factory_vtbl
};
5391 MFT_REGISTER_TYPE_INFO input_types
[1], *in_types
, *out_types
;
5392 IMFAttributes
*attributes
;
5393 IMFActivate
**activate
;
5394 UINT32 count
, count2
;
5398 if (!pMFTRegisterLocal
)
5400 win_skip("MFTRegisterLocal() is not available.\n");
5404 input_types
[0].guidMajorType
= MFMediaType_Audio
;
5405 input_types
[0].guidSubtype
= MFAudioFormat_PCM
;
5406 hr
= pMFTRegisterLocal(&test_factory
, &MFT_CATEGORY_OTHER
, L
"Local MFT name", 0, 1, input_types
, 0, NULL
);
5407 ok(hr
== S_OK
, "Failed to register MFT, hr %#lx.\n", hr
);
5409 hr
= pMFTRegisterLocal(&test_factory
, &MFT_CATEGORY_OTHER
, L
"Local MFT name", 0, 1, input_types
, 0, NULL
);
5410 ok(hr
== S_OK
, "Failed to register MFT, hr %#lx.\n", hr
);
5412 hr
= pMFTEnumEx(MFT_CATEGORY_OTHER
, MFT_ENUM_FLAG_LOCALMFT
, NULL
, NULL
, &activate
, &count
);
5413 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5414 ok(count
> 0, "Unexpected count %u.\n", count
);
5415 CoTaskMemFree(activate
);
5417 hr
= pMFTUnregisterLocal(&test_factory
);
5418 ok(hr
== S_OK
, "Failed to unregister MFT, hr %#lx.\n", hr
);
5420 hr
= pMFTEnumEx(MFT_CATEGORY_OTHER
, MFT_ENUM_FLAG_LOCALMFT
, NULL
, NULL
, &activate
, &count2
);
5421 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5422 ok(count2
< count
, "Unexpected count %u.\n", count2
);
5423 CoTaskMemFree(activate
);
5425 hr
= pMFTUnregisterLocal(&test_factory
);
5426 ok(hr
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
), "Unexpected hr %#lx.\n", hr
);
5428 hr
= pMFTUnregisterLocal(NULL
);
5429 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5431 hr
= pMFTRegisterLocalByCLSID(&MFT_CATEGORY_OTHER
, &MFT_CATEGORY_OTHER
, L
"Local MFT name 2", 0, 1, input_types
,
5433 ok(hr
== S_OK
, "Failed to register MFT, hr %#lx.\n", hr
);
5435 hr
= MFTGetInfo(MFT_CATEGORY_OTHER
, &name
, &in_types
, &count
, &out_types
, &count2
, &attributes
);
5436 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Unexpected hr %#lx.\n", hr
);
5438 hr
= pMFTUnregisterLocal(NULL
);
5439 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5441 hr
= pMFTUnregisterLocalByCLSID(MFT_CATEGORY_OTHER
);
5442 ok(hr
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
), "Unexpected hr %#lx.\n", hr
);
5444 hr
= pMFTRegisterLocalByCLSID(&MFT_CATEGORY_OTHER
, &MFT_CATEGORY_OTHER
, L
"Local MFT name 2", 0, 1, input_types
,
5446 ok(hr
== S_OK
, "Failed to register MFT, hr %#lx.\n", hr
);
5448 hr
= pMFTUnregisterLocalByCLSID(MFT_CATEGORY_OTHER
);
5449 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5452 static void test_queue_com(void)
5454 static int system_queues
[] =
5456 MFASYNC_CALLBACK_QUEUE_STANDARD
,
5457 MFASYNC_CALLBACK_QUEUE_RT
,
5458 MFASYNC_CALLBACK_QUEUE_IO
,
5459 MFASYNC_CALLBACK_QUEUE_TIMER
,
5460 MFASYNC_CALLBACK_QUEUE_MULTITHREADED
,
5461 MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION
,
5464 static int user_queues
[] =
5466 MF_STANDARD_WORKQUEUE
,
5467 MF_WINDOW_WORKQUEUE
,
5468 MF_MULTITHREADED_WORKQUEUE
,
5471 char path_name
[MAX_PATH
];
5472 PROCESS_INFORMATION info
;
5473 STARTUPINFOA startup
;
5477 if (!pCoGetApartmentType
)
5479 win_skip("CoGetApartmentType() is not available.\n");
5483 winetest_get_mainargs(&argv
);
5485 for (i
= 0; i
< ARRAY_SIZE(system_queues
); ++i
)
5487 memset(&startup
, 0, sizeof(startup
));
5488 startup
.cb
= sizeof(startup
);
5489 sprintf(path_name
, "%s mfplat s%d", argv
[0], system_queues
[i
]);
5490 ok(CreateProcessA( NULL
, path_name
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
),
5491 "CreateProcess failed.\n" );
5492 wait_child_process(info
.hProcess
);
5493 CloseHandle(info
.hProcess
);
5494 CloseHandle(info
.hThread
);
5497 for (i
= 0; i
< ARRAY_SIZE(user_queues
); ++i
)
5499 memset(&startup
, 0, sizeof(startup
));
5500 startup
.cb
= sizeof(startup
);
5501 sprintf(path_name
, "%s mfplat u%d", argv
[0], user_queues
[i
]);
5502 ok(CreateProcessA( NULL
, path_name
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
),
5503 "CreateProcess failed.\n" );
5504 wait_child_process(info
.hProcess
);
5505 CloseHandle(info
.hProcess
);
5506 CloseHandle(info
.hThread
);
5510 static HRESULT WINAPI
test_queue_com_state_callback_Invoke(IMFAsyncCallback
*iface
, IMFAsyncResult
*result
)
5512 struct test_callback
*callback
= impl_from_IMFAsyncCallback(iface
);
5513 APTTYPEQUALIFIER qualifier
;
5517 hr
= pCoGetApartmentType(&com_type
, &qualifier
);
5518 ok(SUCCEEDED(hr
), "Failed to get apartment type, hr %#lx.\n", hr
);
5522 if (callback
->param
== MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION
)
5523 ok(com_type
== APTTYPE_MAINSTA
&& qualifier
== APTTYPEQUALIFIER_NONE
,
5524 "%#lx: unexpected type %u, qualifier %u.\n", callback
->param
, com_type
, qualifier
);
5526 ok(com_type
== APTTYPE_MTA
&& qualifier
== APTTYPEQUALIFIER_NONE
,
5527 "%#lx: unexpected type %u, qualifier %u.\n", callback
->param
, com_type
, qualifier
);
5531 SetEvent(callback
->event
);
5535 static const IMFAsyncCallbackVtbl test_queue_com_state_callback_vtbl
=
5537 testcallback_QueryInterface
,
5538 testcallback_AddRef
,
5539 testcallback_Release
,
5540 testcallback_GetParameters
,
5541 test_queue_com_state_callback_Invoke
,
5544 static void test_queue_com_state(const char *name
)
5546 struct test_callback
*callback
;
5547 DWORD queue
, queue_type
;
5550 callback
= create_test_callback(&test_queue_com_state_callback_vtbl
);
5551 callback
->event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
5553 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
5554 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
5558 callback
->param
= name
[1] - '0';
5559 hr
= MFPutWorkItem(callback
->param
, &callback
->IMFAsyncCallback_iface
, NULL
);
5560 ok(SUCCEEDED(hr
), "Failed to queue work item, hr %#lx.\n", hr
);
5561 WaitForSingleObject(callback
->event
, INFINITE
);
5563 else if (name
[0] == 'u')
5565 queue_type
= name
[1] - '0';
5567 hr
= pMFAllocateWorkQueueEx(queue_type
, &queue
);
5568 ok(hr
== S_OK
|| broken(queue_type
== MF_MULTITHREADED_WORKQUEUE
&& hr
== E_INVALIDARG
) /* Win7 */,
5569 "Failed to allocate a queue of type %lu, hr %#lx.\n", queue_type
, hr
);
5573 callback
->param
= queue
;
5574 hr
= MFPutWorkItem(queue
, &callback
->IMFAsyncCallback_iface
, NULL
);
5575 ok(SUCCEEDED(hr
), "Failed to queue work item, hr %#lx.\n", hr
);
5576 WaitForSingleObject(callback
->event
, INFINITE
);
5578 hr
= MFUnlockWorkQueue(queue
);
5579 ok(hr
== S_OK
, "Failed to unlock the queue, hr %#lx.\n", hr
);
5583 CloseHandle(callback
->event
);
5586 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
5588 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
5591 static void test_MFGetStrideForBitmapInfoHeader(void)
5593 static const struct stride_test
5595 const GUID
*subtype
;
5601 { &MFVideoFormat_RGB8
, 3, -4 },
5602 { &MFVideoFormat_RGB8
, 1, -4 },
5603 { &MFVideoFormat_RGB555
, 3, -8 },
5604 { &MFVideoFormat_RGB555
, 1, -4 },
5605 { &MFVideoFormat_RGB565
, 3, -8 },
5606 { &MFVideoFormat_RGB565
, 1, -4 },
5607 { &MFVideoFormat_RGB24
, 3, -12 },
5608 { &MFVideoFormat_RGB24
, 1, -4 },
5609 { &MFVideoFormat_RGB32
, 3, -12 },
5610 { &MFVideoFormat_RGB32
, 1, -4 },
5611 { &MFVideoFormat_ARGB32
, 3, -12 },
5612 { &MFVideoFormat_ARGB32
, 1, -4 },
5613 { &MFVideoFormat_A2R10G10B10
, 3, -12 },
5614 { &MFVideoFormat_A2R10G10B10
, 1, -4 },
5615 { &MFVideoFormat_A16B16G16R16F
, 3, -24 },
5616 { &MFVideoFormat_A16B16G16R16F
, 1, -8 },
5619 { &MFVideoFormat_NV12
, 1, 1 },
5620 { &MFVideoFormat_NV12
, 2, 2 },
5621 { &MFVideoFormat_NV12
, 3, 3 },
5622 { &MFVideoFormat_AYUV
, 1, 4 },
5623 { &MFVideoFormat_AYUV
, 4, 16 },
5624 { &MFVideoFormat_AYUV
, 5, 20 },
5625 { &MFVideoFormat_IMC1
, 1, 4 },
5626 { &MFVideoFormat_IMC1
, 2, 4 },
5627 { &MFVideoFormat_IMC1
, 3, 8 },
5628 { &MFVideoFormat_IMC3
, 1, 4 },
5629 { &MFVideoFormat_IMC3
, 2, 4 },
5630 { &MFVideoFormat_IMC3
, 3, 8 },
5631 { &MFVideoFormat_IMC2
, 1, 1 },
5632 { &MFVideoFormat_IMC2
, 2, 2 },
5633 { &MFVideoFormat_IMC2
, 3, 3 },
5634 { &MFVideoFormat_IMC4
, 1, 1 },
5635 { &MFVideoFormat_IMC4
, 2, 2 },
5636 { &MFVideoFormat_IMC4
, 3, 3 },
5637 { &MFVideoFormat_YV12
, 1, 1 },
5638 { &MFVideoFormat_YV12
, 2, 2 },
5639 { &MFVideoFormat_YV12
, 3, 3 },
5640 { &MFVideoFormat_YV12
, 320, 320 },
5641 { &MFVideoFormat_I420
, 1, 1 },
5642 { &MFVideoFormat_I420
, 2, 2 },
5643 { &MFVideoFormat_I420
, 3, 3 },
5644 { &MFVideoFormat_I420
, 320, 320 },
5645 { &MFVideoFormat_IYUV
, 1, 1 },
5646 { &MFVideoFormat_IYUV
, 2, 2 },
5647 { &MFVideoFormat_IYUV
, 3, 3 },
5648 { &MFVideoFormat_IYUV
, 320, 320 },
5654 if (!pMFGetStrideForBitmapInfoHeader
)
5656 win_skip("MFGetStrideForBitmapInfoHeader() is not available.\n");
5660 hr
= pMFGetStrideForBitmapInfoHeader(MAKEFOURCC('H','2','6','4'), 1, &stride
);
5661 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
5663 for (i
= 0; i
< ARRAY_SIZE(stride_tests
); ++i
)
5665 hr
= pMFGetStrideForBitmapInfoHeader(stride_tests
[i
].subtype
->Data1
, stride_tests
[i
].width
, &stride
);
5666 ok(hr
== S_OK
, "%u: failed to get stride, hr %#lx.\n", i
, hr
);
5667 ok(stride
== stride_tests
[i
].stride
, "%u: format %s, unexpected stride %ld, expected %ld.\n", i
,
5668 wine_dbgstr_an((char *)&stride_tests
[i
].subtype
->Data1
, 4), stride
, stride_tests
[i
].stride
);
5672 static void test_MFCreate2DMediaBuffer(void)
5674 static const struct _2d_buffer_test
5677 unsigned int height
;
5678 unsigned int fourcc
;
5679 unsigned int contiguous_length
;
5681 unsigned int plane_multiplier
;
5682 unsigned int max_length
;
5683 } _2d_buffer_tests
[] =
5685 { 2, 2, MAKEFOURCC('N','V','1','2'), 6, 64, 0, 192 },
5686 { 4, 2, MAKEFOURCC('N','V','1','2'), 12, 64 },
5687 { 2, 4, MAKEFOURCC('N','V','1','2'), 12, 64 },
5688 { 1, 3, MAKEFOURCC('N','V','1','2'), 4, 64 },
5689 { 4, 16, MAKEFOURCC('N','V','1','2'), 96, 64, 0, 1536 },
5691 { 2, 2, MAKEFOURCC('I','M','C','2'), 6, 128, 0, 384 },
5692 { 4, 2, MAKEFOURCC('I','M','C','2'), 12, 128 },
5693 { 2, 4, MAKEFOURCC('I','M','C','2'), 12, 128 },
5694 { 2, 2, MAKEFOURCC('I','M','C','4'), 6, 128 },
5695 { 4, 2, MAKEFOURCC('I','M','C','4'), 12, 128 },
5696 { 2, 4, MAKEFOURCC('I','M','C','4'), 12, 128 },
5698 { 4, 2, MAKEFOURCC('I','M','C','1'), 32, 128, 2 },
5699 { 4, 4, MAKEFOURCC('I','M','C','1'), 64, 128, 2 },
5700 { 4, 16, MAKEFOURCC('I','M','C','1'), 256, 128, 2, 4096 },
5701 { 4, 20, MAKEFOURCC('I','M','C','1'), 320, 128, 2 },
5703 { 4, 2, MAKEFOURCC('I','M','C','3'), 32, 128, 2 },
5704 { 4, 4, MAKEFOURCC('I','M','C','3'), 64, 128, 2 },
5705 { 4, 16, MAKEFOURCC('I','M','C','3'), 256, 128, 2, 4096 },
5706 { 4, 20, MAKEFOURCC('I','M','C','3'), 320, 128, 2 },
5708 { 4, 2, MAKEFOURCC('Y','V','1','2'), 12, 128 },
5709 { 4, 4, MAKEFOURCC('Y','V','1','2'), 24, 128 },
5710 { 4, 16, MAKEFOURCC('Y','V','1','2'), 96, 128, 0, 3072 },
5712 { 4, 2, MAKEFOURCC('A','Y','U','V'), 32, 64 },
5713 { 4, 4, MAKEFOURCC('A','Y','U','V'), 64, 64 },
5714 { 4, 16, MAKEFOURCC('A','Y','U','V'), 256, 64, 0, 1024 },
5716 { 4, 2, MAKEFOURCC('Y','U','Y','2'), 16, 64 },
5717 { 4, 4, MAKEFOURCC('Y','U','Y','2'), 32, 64 },
5718 { 4, 16, MAKEFOURCC('Y','U','Y','2'), 128, 64, 0, 1024 },
5720 { 4, 2, MAKEFOURCC('U','Y','V','Y'), 16, 64 },
5721 { 4, 4, MAKEFOURCC('U','Y','V','Y'), 32, 64 },
5722 { 4, 16, MAKEFOURCC('U','Y','V','Y'), 128, 64, 0, 1024 },
5724 { 2, 4, D3DFMT_A8R8G8B8
, 32, 64 },
5725 { 1, 4, D3DFMT_A8R8G8B8
, 16, 64 },
5726 { 4, 1, D3DFMT_A8R8G8B8
, 16, 64 },
5728 DWORD max_length
, length
, length2
;
5729 BYTE
*buffer_start
, *data
, *data2
;
5730 LONG pitch
, pitch2
, stride
;
5731 IMF2DBuffer2
*_2dbuffer2
;
5732 IMF2DBuffer
*_2dbuffer
;
5733 IMFMediaBuffer
*buffer
;
5738 if (!pMFCreate2DMediaBuffer
)
5740 win_skip("MFCreate2DMediaBuffer() is not available.\n");
5744 hr
= pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('H','2','6','4'), FALSE
, &buffer
);
5745 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
5747 hr
= pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('N','V','1','2'), FALSE
, NULL
);
5748 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
5750 /* YUV formats can't be bottom-up. */
5751 hr
= pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('N','V','1','2'), TRUE
, &buffer
);
5752 ok(hr
== MF_E_INVALIDMEDIATYPE
, "Unexpected hr %#lx.\n", hr
);
5754 hr
= pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('N','V','1','2'), FALSE
, &buffer
);
5755 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
5757 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
5758 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
5760 /* Full backing buffer size, with 64 bytes per row alignment. */
5761 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &max_length
);
5762 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
5763 ok(max_length
> 0, "Unexpected length %lu.\n", max_length
);
5765 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
5766 ok(hr
== S_OK
, "Failed to get current length, hr %#lx.\n", hr
);
5767 ok(!length
, "Unexpected length.\n");
5769 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 10);
5770 ok(hr
== S_OK
, "Failed to set current length, hr %#lx.\n", hr
);
5772 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
5773 ok(hr
== S_OK
, "Failed to get current length, hr %#lx.\n", hr
);
5774 ok(length
== 10, "Unexpected length.\n");
5776 /* Linear lock/unlock. */
5778 hr
= IMFMediaBuffer_Lock(buffer
, NULL
, &max_length
, &length
);
5779 ok(FAILED(hr
), "Unexpected hr %#lx.\n", hr
);
5781 /* Linear locking call returns plane size.*/
5782 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &length
);
5783 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5784 ok(max_length
== length
, "Unexpected length.\n");
5787 pMFGetPlaneSize(MAKEFOURCC('N','V','1','2'), 2, 3, &length
);
5788 ok(max_length
== length
&& length
== 9, "Unexpected length %lu.\n", length
);
5790 /* Already locked */
5791 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
5792 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5793 ok(data2
== data
, "Unexpected pointer.\n");
5795 hr
= IMFMediaBuffer_Unlock(buffer
);
5796 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5798 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2dbuffer
);
5799 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
5801 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, NULL
);
5802 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5804 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, &length
);
5805 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
5806 ok(length
== 9, "Unexpected length %lu.\n", length
);
5808 hr
= IMF2DBuffer_IsContiguousFormat(_2dbuffer
, NULL
);
5809 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5812 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
5813 ok(hr
== MF_E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
5815 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, &pitch
);
5816 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
5818 hr
= IMFMediaBuffer_Unlock(buffer
);
5819 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5821 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, &pitch
);
5822 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
5824 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, NULL
, NULL
);
5825 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5827 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, NULL
);
5828 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5830 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, NULL
, &pitch
);
5831 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5833 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
5834 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5835 ok(!!data
, "Expected data pointer.\n");
5836 ok(pitch
== 64, "Unexpected pitch %ld.\n", pitch
);
5838 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data2
, &pitch
);
5839 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5840 ok(data
== data2
, "Expected data pointer.\n");
5842 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, NULL
, &pitch
);
5843 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5845 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, NULL
);
5846 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5848 /* Active 2D lock */
5849 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
5850 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
5852 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5853 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5855 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
5856 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
5858 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5859 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5861 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5862 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
5864 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer2
, (void **)&_2dbuffer2
);
5865 ok(hr
== S_OK
|| broken(hr
== E_NOINTERFACE
), "Failed to get interface, hr %#lx.\n", hr
);
5869 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
5870 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5872 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data2
, &pitch
, &buffer_start
, &length
);
5873 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5875 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5876 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5878 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5879 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5881 /* Flags are ignored. */
5882 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data2
, &pitch
, &buffer_start
, &length
);
5883 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5885 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data2
, &pitch
, &buffer_start
, &length
);
5886 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5888 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5889 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5891 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5892 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5894 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data2
, &pitch
, NULL
, &length
);
5895 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5897 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data2
, &pitch
, &buffer_start
, NULL
);
5898 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
5900 IMF2DBuffer2_Release(_2dbuffer2
);
5903 win_skip("IMF2DBuffer2 is not supported.\n");
5905 IMF2DBuffer_Release(_2dbuffer
);
5907 IMFMediaBuffer_Release(buffer
);
5909 for (i
= 0; i
< ARRAY_SIZE(_2d_buffer_tests
); ++i
)
5911 const struct _2d_buffer_test
*ptr
= &_2d_buffer_tests
[i
];
5913 hr
= pMFCreate2DMediaBuffer(ptr
->width
, ptr
->height
, ptr
->fourcc
, FALSE
, &buffer
);
5914 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
5916 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
5917 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
5918 if (ptr
->max_length
)
5919 ok(length
== ptr
->max_length
, "%u: unexpected maximum length %lu for %u x %u, format %s.\n",
5920 i
, length
, ptr
->width
, ptr
->height
, wine_dbgstr_an((char *)&ptr
->fourcc
, 4));
5922 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2dbuffer
);
5923 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
5925 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, &length
);
5926 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
5927 ok(length
== ptr
->contiguous_length
, "%d: unexpected contiguous length %lu for %u x %u, format %s.\n",
5928 i
, length
, ptr
->width
, ptr
->height
, wine_dbgstr_an((char *)&ptr
->fourcc
, 4));
5930 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &length2
, NULL
);
5931 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5932 ok(length2
== ptr
->contiguous_length
, "%d: unexpected linear buffer length %lu for %u x %u, format %s.\n",
5933 i
, length2
, ptr
->width
, ptr
->height
, wine_dbgstr_an((char *)&ptr
->fourcc
, 4));
5935 memset(data
, 0xff, length2
);
5937 hr
= IMFMediaBuffer_Unlock(buffer
);
5938 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5940 hr
= pMFGetPlaneSize(ptr
->fourcc
, ptr
->width
, ptr
->height
, &length2
);
5941 ok(hr
== S_OK
, "Failed to get plane size, hr %#lx.\n", hr
);
5942 if (ptr
->plane_multiplier
)
5943 length2
*= ptr
->plane_multiplier
;
5944 ok(length2
== length
, "%d: contiguous length %lu does not match plane size %lu, %u x %u, format %s.\n", i
, length
,
5945 length2
, ptr
->width
, ptr
->height
, wine_dbgstr_an((char *)&ptr
->fourcc
, 4));
5947 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
5948 ok(hr
== S_OK
, "Failed to lock buffer, hr %#lx.\n", hr
);
5950 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data2
, &pitch2
);
5951 ok(hr
== S_OK
, "Failed to get scanline, hr %#lx.\n", hr
);
5952 ok(data2
== data
, "Unexpected data pointer.\n");
5953 ok(pitch
== pitch2
, "Unexpected pitch.\n");
5956 for(j
= 0; j
< ptr
->height
; j
++)
5957 for (k
= 0; k
< ptr
->width
; k
++)
5958 ok(data
[j
* pitch
+ k
] == 0xff, "Unexpected byte %02x at test %d row %d column %d.\n", data
[j
* pitch
+ k
], i
, j
, k
);
5960 hr
= pMFGetStrideForBitmapInfoHeader(ptr
->fourcc
, ptr
->width
, &stride
);
5961 ok(hr
== S_OK
, "Failed to get stride, hr %#lx.\n", hr
);
5963 /* secondary planes */
5964 switch (ptr
->fourcc
)
5966 case MAKEFOURCC('I','M','C','1'):
5967 case MAKEFOURCC('I','M','C','3'):
5968 for (j
= ptr
->height
; j
< length2
/ stride
; j
++)
5969 for (k
= 0; k
< ptr
->width
/ 2; k
++)
5970 ok(data
[j
* pitch
+ k
] == 0xff, "Unexpected byte %02x at test %d row %d column %d.\n", data
[j
* pitch
+ k
], i
, j
, k
);
5973 case MAKEFOURCC('I','M','C','2'):
5974 case MAKEFOURCC('I','M','C','4'):
5975 for (j
= ptr
->height
; j
< length2
/ stride
; j
++)
5976 for (k
= 0; k
< ptr
->width
/ 2; k
++)
5977 ok(data
[j
* pitch
+ k
] == 0xff, "Unexpected byte %02x at test %d row %d column %d.\n", data
[j
* pitch
+ k
], i
, j
, k
);
5978 for (j
= ptr
->height
; j
< length2
/ stride
; j
++)
5979 for (k
= pitch
/ 2; k
< pitch
/ 2 + ptr
->width
/ 2; k
++)
5980 ok(data
[j
* pitch
+ k
] == 0xff, "Unexpected byte %02x at test %d row %d column %d.\n", data
[j
* pitch
+ k
], i
, j
, k
);
5983 case MAKEFOURCC('N','V','1','2'):
5984 for (j
= ptr
->height
; j
< length2
/ stride
; j
++)
5985 for (k
= 0; k
< ptr
->width
; k
++)
5986 ok(data
[j
* pitch
+ k
] == 0xff, "Unexpected byte %02x at test %d row %d column %d.\n", data
[j
* pitch
+ k
], i
, j
, k
);
5993 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
5994 ok(hr
== S_OK
, "Failed to unlock buffer, hr %#lx.\n", hr
);
5996 ok(pitch
== ptr
->pitch
, "%d: unexpected pitch %ld, expected %d, %u x %u, format %s.\n", i
, pitch
, ptr
->pitch
,
5997 ptr
->width
, ptr
->height
, wine_dbgstr_an((char *)&ptr
->fourcc
, 4));
6000 hr
= IMF2DBuffer_IsContiguousFormat(_2dbuffer
, &ret
);
6001 ok(hr
== S_OK
, "Failed to get format flag, hr %#lx.\n", hr
);
6002 ok(!ret
, "%d: unexpected format flag %d.\n", i
, ret
);
6004 IMF2DBuffer_Release(_2dbuffer
);
6006 IMFMediaBuffer_Release(buffer
);
6010 static void test_MFCreateMediaBufferFromMediaType(void)
6012 static struct audio_buffer_test
6014 unsigned int duration
;
6015 unsigned int min_length
;
6016 unsigned int min_alignment
;
6017 unsigned int block_alignment
;
6018 unsigned int bytes_per_second
;
6019 unsigned int buffer_length
;
6022 { 0, 0, 0, 4, 0, 20 },
6023 { 0, 16, 0, 4, 0, 20 },
6024 { 0, 0, 32, 4, 0, 36 },
6025 { 0, 64, 32, 4, 0, 64 },
6026 { 1, 0, 0, 4, 16, 36 },
6027 { 2, 0, 0, 4, 16, 52 },
6029 IMFMediaBuffer
*buffer
;
6032 IMFMediaType
*media_type
;
6035 if (!pMFCreateMediaBufferFromMediaType
)
6037 win_skip("MFCreateMediaBufferFromMediaType() is not available.\n");
6041 hr
= pMFCreateMediaBufferFromMediaType(NULL
, 0, 0, 0, &buffer
);
6042 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
6044 hr
= MFCreateMediaType(&media_type
);
6045 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
6047 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
6048 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
6050 for (i
= 0; i
< ARRAY_SIZE(audio_tests
); ++i
)
6052 const struct audio_buffer_test
*ptr
= &audio_tests
[i
];
6054 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, ptr
->block_alignment
);
6055 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
6057 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND
, ptr
->bytes_per_second
);
6058 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
6060 hr
= pMFCreateMediaBufferFromMediaType(media_type
, ptr
->duration
* 10000000, ptr
->min_length
,
6061 ptr
->min_alignment
, &buffer
);
6062 ok(hr
== S_OK
|| broken(FAILED(hr
)) /* Win8 */, "Unexpected hr %#lx.\n", hr
);
6066 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
6068 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &length
);
6069 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6070 ok(ptr
->buffer_length
== length
, "%d: unexpected buffer length %lu, expected %u.\n", i
, length
, ptr
->buffer_length
);
6072 IMFMediaBuffer_Release(buffer
);
6075 IMFMediaType_Release(media_type
);
6078 static void validate_media_type(IMFMediaType
*mediatype
, const WAVEFORMATEX
*format
)
6084 hr
= IMFMediaType_GetMajorType(mediatype
, &guid
);
6085 ok(hr
== S_OK
, "Failed to get major type, hr %#lx.\n", hr
);
6086 ok(IsEqualGUID(&guid
, &MFMediaType_Audio
), "Unexpected major type %s.\n", wine_dbgstr_guid(&guid
));
6088 hr
= IMFMediaType_GetGUID(mediatype
, &MF_MT_SUBTYPE
, &guid
);
6089 ok(hr
== S_OK
, "Failed to get subtype, hr %#lx.\n", hr
);
6091 if (format
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
6093 const WAVEFORMATEXTENSIBLE
*fex
= (const WAVEFORMATEXTENSIBLE
*)format
;
6094 ok(IsEqualGUID(&guid
, &fex
->SubFormat
), "Unexpected subtype %s.\n", wine_dbgstr_guid(&guid
));
6096 if (fex
->dwChannelMask
)
6098 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_CHANNEL_MASK
, &value
);
6099 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6100 ok(value
== fex
->dwChannelMask
, "Unexpected CHANNEL_MASK %#x.\n", value
);
6103 if (format
->wBitsPerSample
&& fex
->Samples
.wValidBitsPerSample
)
6105 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE
, &value
);
6106 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6107 ok(value
== fex
->Samples
.wValidBitsPerSample
, "Unexpected VALID_BITS_PER_SAMPLE %#x.\n", value
);
6112 memcpy(&subtype
, &MFAudioFormat_Base
, sizeof(subtype
));
6113 subtype
.Data1
= format
->wFormatTag
;
6114 ok(IsEqualGUID(&guid
, &subtype
), "Unexpected subtype %s.\n", wine_dbgstr_guid(&guid
));
6116 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_PREFER_WAVEFORMATEX
, &value
);
6117 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6118 ok(value
, "Unexpected value.\n");
6121 if (format
->nChannels
)
6123 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_NUM_CHANNELS
, &value
);
6124 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6125 ok(value
== format
->nChannels
, "Unexpected NUM_CHANNELS %u.\n", value
);
6128 if (format
->nSamplesPerSec
)
6130 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, &value
);
6131 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6132 ok(value
== format
->nSamplesPerSec
, "Unexpected SAMPLES_PER_SECOND %u.\n", value
);
6135 if (format
->nAvgBytesPerSec
)
6137 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND
, &value
);
6138 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6139 ok(value
== format
->nAvgBytesPerSec
, "Unexpected AVG_BYTES_PER_SECOND %u.\n", value
);
6142 if (format
->nBlockAlign
)
6144 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, &value
);
6145 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6146 ok(value
== format
->nBlockAlign
, "Unexpected BLOCK_ALIGNMENT %u.\n", value
);
6149 if (format
->wBitsPerSample
)
6151 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, &value
);
6152 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6153 ok(value
== format
->wBitsPerSample
, "Unexpected BITS_PER_SAMPLE %u.\n", value
);
6156 /* Only set for uncompressed formats. */
6157 hr
= IMFMediaType_GetUINT32(mediatype
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value
);
6158 if (IsEqualGUID(&guid
, &MFAudioFormat_Float
) ||
6159 IsEqualGUID(&guid
, &MFAudioFormat_PCM
))
6161 ok(hr
== S_OK
, "Failed to get attribute, hr %#lx.\n", hr
);
6162 ok(value
, "Unexpected ALL_SAMPLES_INDEPENDENT value.\n");
6165 ok(FAILED(hr
), "Unexpected ALL_SAMPLES_INDEPENDENT.\n");
6168 static void test_MFInitMediaTypeFromWaveFormatEx(void)
6170 static const WAVEFORMATEX waveformatex_tests
[] =
6172 { WAVE_FORMAT_PCM
, 2, 44100, 0, 2, 8 },
6173 { WAVE_FORMAT_PCM
, 2, 44100, 1, 2, 8 },
6174 { WAVE_FORMAT_PCM
, 0, 44100, 0, 0, 0 },
6175 { WAVE_FORMAT_PCM
, 0, 0, 0, 0, 0 },
6176 { WAVE_FORMAT_IEEE_FLOAT
, 2, 44100, 1, 2, 8 },
6177 { 1234, 0, 0, 0, 0, 0 },
6178 { WAVE_FORMAT_ALAW
},
6179 { WAVE_FORMAT_CREATIVE_ADPCM
},
6180 { WAVE_FORMAT_MPEGLAYER3
},
6181 { WAVE_FORMAT_MPEG_ADTS_AAC
},
6182 { WAVE_FORMAT_ALAC
},
6183 { WAVE_FORMAT_AMR_NB
},
6184 { WAVE_FORMAT_AMR_WB
},
6185 { WAVE_FORMAT_AMR_WP
},
6186 { WAVE_FORMAT_DOLBY_AC3_SPDIF
},
6187 { WAVE_FORMAT_DRM
},
6188 { WAVE_FORMAT_DTS
},
6189 { WAVE_FORMAT_FLAC
},
6190 { WAVE_FORMAT_MPEG
},
6191 { WAVE_FORMAT_WMAVOICE9
},
6192 { WAVE_FORMAT_OPUS
},
6193 { WAVE_FORMAT_WMAUDIO2
},
6194 { WAVE_FORMAT_WMAUDIO3
},
6195 { WAVE_FORMAT_WMAUDIO_LOSSLESS
},
6196 { WAVE_FORMAT_WMASPDIF
},
6199 UINT8 buff
[MPEGLAYER3_WFX_EXTRA_BYTES
];
6200 WAVEFORMATEXTENSIBLE waveformatext
;
6201 MPEGLAYER3WAVEFORMAT mp3format
;
6202 IMFMediaType
*mediatype
;
6203 unsigned int i
, size
;
6206 hr
= MFCreateMediaType(&mediatype
);
6207 ok(hr
== S_OK
, "Failed to create mediatype, hr %#lx.\n", hr
);
6209 for (i
= 0; i
< ARRAY_SIZE(waveformatex_tests
); ++i
)
6211 hr
= MFInitMediaTypeFromWaveFormatEx(mediatype
, &waveformatex_tests
[i
], sizeof(waveformatex_tests
[i
]));
6212 ok(hr
== S_OK
, "%d: format %#x, failed to initialize media type, hr %#lx.\n", i
, waveformatex_tests
[i
].wFormatTag
, hr
);
6214 validate_media_type(mediatype
, &waveformatex_tests
[i
]);
6216 waveformatext
.Format
= waveformatex_tests
[i
];
6217 waveformatext
.Format
.wFormatTag
= WAVE_FORMAT_EXTENSIBLE
;
6218 waveformatext
.Format
.cbSize
= sizeof(waveformatext
) - sizeof(waveformatext
.Format
);
6219 waveformatext
.Samples
.wSamplesPerBlock
= 123;
6220 waveformatext
.dwChannelMask
= 0x8;
6221 memcpy(&waveformatext
.SubFormat
, &MFAudioFormat_Base
, sizeof(waveformatext
.SubFormat
));
6222 waveformatext
.SubFormat
.Data1
= waveformatex_tests
[i
].wFormatTag
;
6224 hr
= MFInitMediaTypeFromWaveFormatEx(mediatype
, &waveformatext
.Format
, sizeof(waveformatext
));
6225 ok(hr
== S_OK
, "Failed to initialize media type, hr %#lx.\n", hr
);
6227 hr
= IMFMediaType_GetItem(mediatype
, &MF_MT_USER_DATA
, NULL
);
6228 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
6230 validate_media_type(mediatype
, &waveformatext
.Format
);
6233 /* MPEGLAYER3WAVEFORMAT */
6234 mp3format
.wfx
.wFormatTag
= WAVE_FORMAT_MPEGLAYER3
;
6235 mp3format
.wfx
.nChannels
= 2;
6236 mp3format
.wfx
.nSamplesPerSec
= 44100;
6237 mp3format
.wfx
.nAvgBytesPerSec
= 16000;
6238 mp3format
.wfx
.nBlockAlign
= 1;
6239 mp3format
.wfx
.wBitsPerSample
= 0;
6240 mp3format
.wfx
.cbSize
= MPEGLAYER3_WFX_EXTRA_BYTES
;
6241 mp3format
.wID
= MPEGLAYER3_ID_MPEG
;
6242 mp3format
.fdwFlags
= 0;
6243 mp3format
.nBlockSize
= 417;
6244 mp3format
.nFramesPerBlock
= 0;
6245 mp3format
.nCodecDelay
= 0;
6247 hr
= MFInitMediaTypeFromWaveFormatEx(mediatype
, (WAVEFORMATEX
*)&mp3format
, sizeof(mp3format
));
6248 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6250 validate_media_type(mediatype
, &mp3format
.wfx
);
6251 hr
= IMFMediaType_GetBlob(mediatype
, &MF_MT_USER_DATA
, buff
, sizeof(buff
), &size
);
6252 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6253 ok(size
== mp3format
.wfx
.cbSize
, "Unexpected size %u.\n", size
);
6254 ok(!memcmp(buff
, (WAVEFORMATEX
*)&mp3format
+ 1, size
), "Unexpected user data.\n");
6256 IMFMediaType_Release(mediatype
);
6259 static void test_MFCreateMFVideoFormatFromMFMediaType(void)
6261 MFVIDEOFORMAT
*video_format
;
6262 IMFMediaType
*media_type
;
6266 hr
= MFCreateMediaType(&media_type
);
6267 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
6269 hr
= MFCreateMFVideoFormatFromMFMediaType(media_type
, &video_format
, &size
);
6270 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6271 ok(!!video_format
, "Unexpected format.\n");
6272 ok(video_format
->dwSize
== size
&& size
== sizeof(*video_format
), "Unexpected size %u.\n", size
);
6273 CoTaskMemFree(video_format
);
6275 IMFMediaType_Release(media_type
);
6278 static void test_MFCreateDXSurfaceBuffer(void)
6280 IDirect3DSurface9
*backbuffer
= NULL
, *surface
;
6281 IDirect3DSwapChain9
*swapchain
;
6282 DWORD length
, max_length
;
6283 IDirect3DDevice9
*device
;
6284 IMF2DBuffer2
*_2dbuffer2
;
6285 IMFMediaBuffer
*buffer
;
6286 IMF2DBuffer
*_2dbuffer
;
6295 if (!pMFCreateDXSurfaceBuffer
)
6297 win_skip("MFCreateDXSurfaceBuffer is not available.\n");
6301 window
= create_window();
6302 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
6303 ok(!!d3d
, "Failed to create a D3D object.\n");
6304 if (!(device
= create_d3d9_device(d3d
, window
)))
6306 skip("Failed to create a D3D device, skipping tests.\n");
6310 hr
= IDirect3DDevice9_GetSwapChain(device
, 0, &swapchain
);
6311 ok(SUCCEEDED(hr
), "Failed to get the implicit swapchain (%08lx)\n", hr
);
6313 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
6314 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08lx)\n", hr
);
6315 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
6317 IDirect3DSwapChain9_Release(swapchain
);
6319 hr
= pMFCreateDXSurfaceBuffer(&IID_IUnknown
, (IUnknown
*)backbuffer
, FALSE
, &buffer
);
6320 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
6322 hr
= pMFCreateDXSurfaceBuffer(&IID_IDirect3DSurface9
, (IUnknown
*)backbuffer
, FALSE
, &buffer
);
6323 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
6325 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
6326 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
6327 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
6329 /* Surface is accessible. */
6330 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFGetService
, (void **)&gs
);
6331 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6332 hr
= IMFGetService_GetService(gs
, &MR_BUFFER_SERVICE
, &IID_IDirect3DSurface9
, (void **)&surface
);
6333 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6334 ok(surface
== backbuffer
, "Unexpected surface pointer.\n");
6335 IDirect3DSurface9_Release(surface
);
6336 IMFGetService_Release(gs
);
6339 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &max_length
);
6340 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6341 ok(!!max_length
, "Unexpected length %lu.\n", max_length
);
6343 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
6344 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6345 ok(!length
, "Unexpected length %lu.\n", length
);
6347 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 2 * max_length
);
6348 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6350 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
6351 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6352 ok(length
== 2 * max_length
, "Unexpected length %lu.\n", length
);
6354 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, &length
);
6355 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6356 ok(length
== max_length
, "Unexpected length.\n");
6359 hr
= IMFMediaBuffer_Unlock(buffer
);
6360 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6362 hr
= IMFMediaBuffer_Unlock(buffer
);
6363 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
6366 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
6367 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6369 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
6370 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6371 ok(data
== data2
, "Unexpected pointer.\n");
6373 hr
= IMFMediaBuffer_Unlock(buffer
);
6374 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6376 hr
= IMFMediaBuffer_Unlock(buffer
);
6377 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6379 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2dbuffer
);
6380 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6383 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, &pitch
);
6384 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
6386 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
6387 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6389 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, &pitch
);
6390 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6392 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
6393 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
6395 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
6396 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6398 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
6399 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6401 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
6402 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6404 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
6405 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
6407 hr
= IMF2DBuffer_IsContiguousFormat(_2dbuffer
, &value
);
6408 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6409 ok(!value
, "Unexpected return value %d.\n", value
);
6411 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, NULL
);
6412 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
6413 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, &length
);
6414 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6415 ok(length
== max_length
, "Unexpected length %lu.\n", length
);
6417 IMF2DBuffer_Release(_2dbuffer
);
6419 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer2
, (void **)&_2dbuffer2
);
6420 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6422 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
6423 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6424 ok(data
== data2
, "Unexpected scanline pointer.\n");
6425 memset(data
, 0xab, 4);
6426 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
6428 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
6429 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6430 ok(data
[0] == 0xab, "Unexpected leading byte.\n");
6431 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
6433 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
6434 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6435 ok(data
[0] == 0xab, "Unexpected leading byte.\n");
6436 hr
= IMFMediaBuffer_Unlock(buffer
);
6437 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6439 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
6440 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6441 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
6443 IMF2DBuffer2_Release(_2dbuffer2
);
6445 IMFMediaBuffer_Release(buffer
);
6449 IDirect3DSurface9_Release(backbuffer
);
6450 IDirect3D9_Release(d3d
);
6451 DestroyWindow(window
);
6454 static void test_MFCreateTrackedSample(void)
6456 IMFTrackedSample
*tracked_sample
;
6461 if (!pMFCreateTrackedSample
)
6463 win_skip("MFCreateTrackedSample() is not available.\n");
6467 hr
= pMFCreateTrackedSample(&tracked_sample
);
6468 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6470 /* It's actually a sample. */
6471 hr
= IMFTrackedSample_QueryInterface(tracked_sample
, &IID_IMFSample
, (void **)&sample
);
6472 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6474 hr
= IMFTrackedSample_QueryInterface(tracked_sample
, &IID_IUnknown
, (void **)&unk
);
6475 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6476 ok(unk
== (IUnknown
*)sample
, "Unexpected pointer.\n");
6477 IUnknown_Release(unk
);
6479 IMFSample_Release(sample
);
6481 check_interface(tracked_sample
, &IID_IMFDesiredSample
, FALSE
);
6483 IMFTrackedSample_Release(tracked_sample
);
6486 static void test_MFFrameRateToAverageTimePerFrame(void)
6488 static const struct frame_rate_test
6490 unsigned int numerator
;
6491 unsigned int denominator
;
6493 } frame_rate_tests
[] =
6495 { 60000, 1001, 166833 },
6496 { 30000, 1001, 333667 },
6497 { 24000, 1001, 417188 },
6512 hr
= MFFrameRateToAverageTimePerFrame(0, 0, &avgtime
);
6513 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6514 ok(!avgtime
, "Unexpected frame time.\n");
6517 hr
= MFFrameRateToAverageTimePerFrame(0, 1001, &avgtime
);
6518 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6519 ok(!avgtime
, "Unexpected frame time.\n");
6521 for (i
= 0; i
< ARRAY_SIZE(frame_rate_tests
); ++i
)
6524 hr
= MFFrameRateToAverageTimePerFrame(frame_rate_tests
[i
].numerator
,
6525 frame_rate_tests
[i
].denominator
, &avgtime
);
6526 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6527 ok(avgtime
== frame_rate_tests
[i
].avgtime
, "%u: unexpected frame time %s, expected %s.\n",
6528 i
, wine_dbgstr_longlong(avgtime
), wine_dbgstr_longlong(frame_rate_tests
[i
].avgtime
));
6532 static void test_MFAverageTimePerFrameToFrameRate(void)
6534 static const struct frame_rate_test
6536 unsigned int numerator
;
6537 unsigned int denominator
;
6539 } frame_rate_tests
[] =
6541 { 60000, 1001, 166833 },
6542 { 30000, 1001, 333667 },
6543 { 24000, 1001, 417188 },
6550 { 1000000, 25641, 256410 },
6551 { 10000000, 83333, 83333 },
6552 { 1, 10, 100000000 },
6553 { 1, 10, 100000001 },
6554 { 1, 10, 200000000 },
6560 unsigned int i
, numerator
, denominator
;
6563 numerator
= denominator
= 1;
6564 hr
= MFAverageTimePerFrameToFrameRate(0, &numerator
, &denominator
);
6565 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6566 ok(!numerator
&& !denominator
, "Unexpected output %u/%u.\n", numerator
, denominator
);
6568 for (i
= 0; i
< ARRAY_SIZE(frame_rate_tests
); ++i
)
6570 numerator
= denominator
= 12345;
6571 hr
= MFAverageTimePerFrameToFrameRate(frame_rate_tests
[i
].avgtime
, &numerator
, &denominator
);
6572 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6573 ok(numerator
== frame_rate_tests
[i
].numerator
&& denominator
== frame_rate_tests
[i
].denominator
,
6574 "%u: unexpected %u/%u, expected %u/%u.\n", i
, numerator
, denominator
, frame_rate_tests
[i
].numerator
,
6575 frame_rate_tests
[i
].denominator
);
6579 static void test_MFMapDXGIFormatToDX9Format(void)
6581 static const struct format_pair
6583 DXGI_FORMAT dxgi_format
;
6588 { DXGI_FORMAT_R32G32B32A32_FLOAT
, D3DFMT_A32B32G32R32F
},
6589 { DXGI_FORMAT_R16G16B16A16_FLOAT
, D3DFMT_A16B16G16R16F
},
6590 { DXGI_FORMAT_R16G16B16A16_UNORM
, D3DFMT_A16B16G16R16
},
6591 { DXGI_FORMAT_R16G16B16A16_SNORM
, D3DFMT_Q16W16V16U16
},
6592 { DXGI_FORMAT_R32G32_FLOAT
, D3DFMT_G32R32F
},
6593 { DXGI_FORMAT_R10G10B10A2_UNORM
, D3DFMT_A2B10G10R10
},
6594 { DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
, D3DFMT_A8R8G8B8
},
6595 { DXGI_FORMAT_R8G8B8A8_SNORM
, D3DFMT_Q8W8V8U8
},
6596 { DXGI_FORMAT_R16G16_FLOAT
, D3DFMT_G16R16F
},
6597 { DXGI_FORMAT_R16G16_UNORM
, D3DFMT_G16R16
},
6598 { DXGI_FORMAT_R16G16_SNORM
, D3DFMT_V16U16
},
6599 { DXGI_FORMAT_D32_FLOAT
, D3DFMT_D32F_LOCKABLE
},
6600 { DXGI_FORMAT_R32_FLOAT
, D3DFMT_R32F
},
6601 { DXGI_FORMAT_D24_UNORM_S8_UINT
, D3DFMT_D24S8
},
6602 { DXGI_FORMAT_R8G8_SNORM
, D3DFMT_V8U8
},
6603 { DXGI_FORMAT_R16_FLOAT
, D3DFMT_R16F
},
6604 { DXGI_FORMAT_R16_UNORM
, D3DFMT_L16
},
6605 { DXGI_FORMAT_R8_UNORM
, D3DFMT_L8
},
6606 { DXGI_FORMAT_A8_UNORM
, D3DFMT_A8
},
6607 { DXGI_FORMAT_BC1_UNORM
, D3DFMT_DXT1
},
6608 { DXGI_FORMAT_BC1_UNORM_SRGB
, D3DFMT_DXT1
},
6609 { DXGI_FORMAT_BC2_UNORM
, D3DFMT_DXT2
},
6610 { DXGI_FORMAT_BC2_UNORM_SRGB
, D3DFMT_DXT2
},
6611 { DXGI_FORMAT_BC3_UNORM
, D3DFMT_DXT4
},
6612 { DXGI_FORMAT_BC3_UNORM_SRGB
, D3DFMT_DXT4
},
6613 { DXGI_FORMAT_B8G8R8A8_UNORM
, D3DFMT_A8R8G8B8
},
6614 { DXGI_FORMAT_B8G8R8X8_UNORM
, D3DFMT_X8R8G8B8
},
6615 { DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
, D3DFMT_A8R8G8B8
},
6616 { DXGI_FORMAT_B8G8R8X8_UNORM_SRGB
, D3DFMT_X8R8G8B8
},
6617 { DXGI_FORMAT_AYUV
, MAKEFOURCC('A','Y','U','V') },
6618 { DXGI_FORMAT_Y410
, MAKEFOURCC('Y','4','1','0') },
6619 { DXGI_FORMAT_Y416
, MAKEFOURCC('Y','4','1','6') },
6620 { DXGI_FORMAT_NV12
, MAKEFOURCC('N','V','1','2') },
6621 { DXGI_FORMAT_P010
, MAKEFOURCC('P','0','1','0') },
6622 { DXGI_FORMAT_P016
, MAKEFOURCC('P','0','1','6') },
6623 { DXGI_FORMAT_420_OPAQUE
, MAKEFOURCC('4','2','0','O') },
6624 { DXGI_FORMAT_YUY2
, D3DFMT_YUY2
},
6625 { DXGI_FORMAT_Y210
, MAKEFOURCC('Y','2','1','0') },
6626 { DXGI_FORMAT_Y216
, MAKEFOURCC('Y','2','1','6') },
6627 { DXGI_FORMAT_NV11
, MAKEFOURCC('N','V','1','1') },
6628 { DXGI_FORMAT_AI44
, MAKEFOURCC('A','I','4','4') },
6629 { DXGI_FORMAT_IA44
, MAKEFOURCC('I','A','4','4') },
6630 { DXGI_FORMAT_P8
, D3DFMT_P8
},
6631 { DXGI_FORMAT_A8P8
, D3DFMT_A8P8
},
6636 if (!pMFMapDXGIFormatToDX9Format
)
6638 win_skip("MFMapDXGIFormatToDX9Format is not available.\n");
6642 for (i
= 0; i
< ARRAY_SIZE(formats_map
); ++i
)
6644 format
= pMFMapDXGIFormatToDX9Format(formats_map
[i
].dxgi_format
);
6645 ok(format
== formats_map
[i
].d3d9_format
, "Unexpected d3d9 format %#lx, dxgi format %#x.\n", format
, formats_map
[i
].dxgi_format
);
6649 static void test_MFMapDX9FormatToDXGIFormat(void)
6651 static const struct format_pair
6653 DXGI_FORMAT dxgi_format
;
6658 { DXGI_FORMAT_R32G32B32A32_FLOAT
, D3DFMT_A32B32G32R32F
},
6659 { DXGI_FORMAT_R16G16B16A16_FLOAT
, D3DFMT_A16B16G16R16F
},
6660 { DXGI_FORMAT_R16G16B16A16_UNORM
, D3DFMT_A16B16G16R16
},
6661 { DXGI_FORMAT_R16G16B16A16_SNORM
, D3DFMT_Q16W16V16U16
},
6662 { DXGI_FORMAT_R32G32_FLOAT
, D3DFMT_G32R32F
},
6663 { DXGI_FORMAT_R10G10B10A2_UNORM
, D3DFMT_A2B10G10R10
},
6664 { DXGI_FORMAT_R8G8B8A8_SNORM
, D3DFMT_Q8W8V8U8
},
6665 { DXGI_FORMAT_R16G16_FLOAT
, D3DFMT_G16R16F
},
6666 { DXGI_FORMAT_R16G16_UNORM
, D3DFMT_G16R16
},
6667 { DXGI_FORMAT_R16G16_SNORM
, D3DFMT_V16U16
},
6668 { DXGI_FORMAT_D32_FLOAT
, D3DFMT_D32F_LOCKABLE
},
6669 { DXGI_FORMAT_R32_FLOAT
, D3DFMT_R32F
},
6670 { DXGI_FORMAT_D24_UNORM_S8_UINT
, D3DFMT_D24S8
},
6671 { DXGI_FORMAT_R8G8_SNORM
, D3DFMT_V8U8
},
6672 { DXGI_FORMAT_R16_FLOAT
, D3DFMT_R16F
},
6673 { DXGI_FORMAT_R16_UNORM
, D3DFMT_L16
},
6674 { DXGI_FORMAT_R8_UNORM
, D3DFMT_L8
},
6675 { DXGI_FORMAT_A8_UNORM
, D3DFMT_A8
},
6676 { DXGI_FORMAT_BC1_UNORM
, D3DFMT_DXT1
},
6677 { DXGI_FORMAT_BC2_UNORM
, D3DFMT_DXT2
},
6678 { DXGI_FORMAT_BC3_UNORM
, D3DFMT_DXT4
},
6679 { DXGI_FORMAT_B8G8R8A8_UNORM
, D3DFMT_A8R8G8B8
},
6680 { DXGI_FORMAT_B8G8R8X8_UNORM
, D3DFMT_X8R8G8B8
},
6681 { DXGI_FORMAT_AYUV
, MAKEFOURCC('A','Y','U','V') },
6682 { DXGI_FORMAT_Y410
, MAKEFOURCC('Y','4','1','0') },
6683 { DXGI_FORMAT_Y416
, MAKEFOURCC('Y','4','1','6') },
6684 { DXGI_FORMAT_NV12
, MAKEFOURCC('N','V','1','2') },
6685 { DXGI_FORMAT_P010
, MAKEFOURCC('P','0','1','0') },
6686 { DXGI_FORMAT_P016
, MAKEFOURCC('P','0','1','6') },
6687 { DXGI_FORMAT_420_OPAQUE
, MAKEFOURCC('4','2','0','O') },
6688 { DXGI_FORMAT_YUY2
, D3DFMT_YUY2
},
6689 { DXGI_FORMAT_Y210
, MAKEFOURCC('Y','2','1','0') },
6690 { DXGI_FORMAT_Y216
, MAKEFOURCC('Y','2','1','6') },
6691 { DXGI_FORMAT_NV11
, MAKEFOURCC('N','V','1','1') },
6692 { DXGI_FORMAT_AI44
, MAKEFOURCC('A','I','4','4') },
6693 { DXGI_FORMAT_IA44
, MAKEFOURCC('I','A','4','4') },
6694 { DXGI_FORMAT_P8
, D3DFMT_P8
},
6695 { DXGI_FORMAT_A8P8
, D3DFMT_A8P8
},
6700 if (!pMFMapDX9FormatToDXGIFormat
)
6702 win_skip("MFMapDX9FormatToDXGIFormat() is not available.\n");
6706 for (i
= 0; i
< ARRAY_SIZE(formats_map
); ++i
)
6708 format
= pMFMapDX9FormatToDXGIFormat(formats_map
[i
].d3d9_format
);
6709 ok(format
== formats_map
[i
].dxgi_format
, "Unexpected DXGI format %#x, d3d9 format %#lx.\n",
6710 format
, formats_map
[i
].d3d9_format
);
6714 static HRESULT WINAPI
test_notify_callback_QueryInterface(IMFVideoSampleAllocatorNotify
*iface
,
6715 REFIID riid
, void **obj
)
6717 if (IsEqualIID(riid
, &IID_IMFVideoSampleAllocatorNotify
) ||
6718 IsEqualIID(riid
, &IID_IUnknown
))
6721 IMFVideoSampleAllocatorNotify_AddRef(iface
);
6726 return E_NOINTERFACE
;
6729 static ULONG WINAPI
test_notify_callback_AddRef(IMFVideoSampleAllocatorNotify
*iface
)
6734 static ULONG WINAPI
test_notify_callback_Release(IMFVideoSampleAllocatorNotify
*iface
)
6739 static HRESULT WINAPI
test_notify_callback_NotifyRelease(IMFVideoSampleAllocatorNotify
*iface
)
6744 static const IMFVideoSampleAllocatorNotifyVtbl test_notify_callback_vtbl
=
6746 test_notify_callback_QueryInterface
,
6747 test_notify_callback_AddRef
,
6748 test_notify_callback_Release
,
6749 test_notify_callback_NotifyRelease
,
6752 static IMFMediaType
* create_video_type(const GUID
*subtype
)
6754 IMFMediaType
*video_type
;
6757 hr
= MFCreateMediaType(&video_type
);
6758 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6760 hr
= IMFMediaType_SetGUID(video_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
6761 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6763 hr
= IMFMediaType_SetGUID(video_type
, &MF_MT_SUBTYPE
, subtype
);
6764 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6769 static ID3D11Device
*create_d3d11_device(void)
6771 static const D3D_FEATURE_LEVEL default_feature_level
[] =
6773 D3D_FEATURE_LEVEL_11_0
,
6774 D3D_FEATURE_LEVEL_10_1
,
6775 D3D_FEATURE_LEVEL_10_0
,
6777 const D3D_FEATURE_LEVEL
*feature_level
;
6778 unsigned int feature_level_count
;
6779 ID3D11Device
*device
;
6781 feature_level
= default_feature_level
;
6782 feature_level_count
= ARRAY_SIZE(default_feature_level
);
6784 if (SUCCEEDED(pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0,
6785 feature_level
, feature_level_count
, D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
6787 if (SUCCEEDED(pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_WARP
, NULL
, 0,
6788 feature_level
, feature_level_count
, D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
6790 if (SUCCEEDED(pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_REFERENCE
, NULL
, 0,
6791 feature_level
, feature_level_count
, D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
6797 static void update_d3d11_texture(ID3D11Texture2D
*texture
, unsigned int sub_resource_idx
,
6798 const BYTE
*data
, unsigned int src_pitch
)
6800 ID3D11DeviceContext
*immediate_context
;
6801 ID3D11Device
*device
;
6803 ID3D11Texture2D_GetDevice(texture
, &device
);
6804 ID3D11Device_GetImmediateContext(device
, &immediate_context
);
6806 ID3D11DeviceContext_UpdateSubresource(immediate_context
, (ID3D11Resource
*)texture
,
6807 sub_resource_idx
, NULL
, data
, src_pitch
, 0);
6809 ID3D11DeviceContext_Release(immediate_context
);
6810 ID3D11Device_Release(device
);
6813 static ID3D12Device
*create_d3d12_device(void)
6815 ID3D12Device
*device
;
6818 if (!pD3D12CreateDevice
) return NULL
;
6820 hr
= pD3D12CreateDevice(NULL
, D3D_FEATURE_LEVEL_11_0
, &IID_ID3D12Device
, (void **)&device
);
6827 static void test_d3d11_surface_buffer(void)
6829 DWORD max_length
, cur_length
, length
, color
;
6830 IMFDXGIBuffer
*dxgi_buffer
;
6831 D3D11_TEXTURE2D_DESC desc
;
6832 ID3D11Texture2D
*texture
;
6833 IMF2DBuffer
*_2d_buffer
;
6834 IMFMediaBuffer
*buffer
;
6835 ID3D11Device
*device
;
6836 BYTE buff
[64 * 64 * 4];
6843 if (!pMFCreateDXGISurfaceBuffer
)
6845 win_skip("MFCreateDXGISurfaceBuffer() is not available.\n");
6850 if (!(device
= create_d3d11_device()))
6852 skip("Failed to create a D3D11 device, skipping tests.\n");
6856 memset(&desc
, 0, sizeof(desc
));
6860 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
6861 desc
.SampleDesc
.Count
= 1;
6862 desc
.SampleDesc
.Quality
= 0;
6864 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
6865 ok(hr
== S_OK
, "Failed to create a texture, hr %#lx.\n", hr
);
6867 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 0, FALSE
, &buffer
);
6868 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
6870 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
6871 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
6872 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
6873 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
6876 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &max_length
);
6877 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6878 ok(!!max_length
, "Unexpected length %lu.\n", max_length
);
6880 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &cur_length
);
6881 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6882 ok(!cur_length
, "Unexpected length %lu.\n", cur_length
);
6884 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 2 * max_length
);
6885 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6887 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &cur_length
);
6888 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
6889 ok(cur_length
== 2 * max_length
, "Unexpected length %lu.\n", cur_length
);
6891 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
6892 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6894 hr
= IMF2DBuffer_GetContiguousLength(_2d_buffer
, NULL
);
6895 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
6896 hr
= IMF2DBuffer_GetContiguousLength(_2d_buffer
, &length
);
6897 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6898 ok(length
== max_length
, "Unexpected length %lu.\n", length
);
6899 IMF2DBuffer_Release(_2d_buffer
);
6901 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
6902 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
6904 EXPECT_REF(texture
, 2);
6905 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&obj
);
6906 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
6907 EXPECT_REF(texture
, 3);
6908 ok(obj
== (IUnknown
*)texture
, "Unexpected resource pointer.\n");
6909 IUnknown_Release(obj
);
6911 hr
= IMFDXGIBuffer_GetSubresourceIndex(dxgi_buffer
, NULL
);
6912 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
6914 hr
= IMFDXGIBuffer_GetSubresourceIndex(dxgi_buffer
, &index
);
6915 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6916 ok(index
== 0, "Unexpected subresource index.\n");
6918 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, NULL
);
6919 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6921 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, (void *)device
);
6922 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6924 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, (void *)device
);
6925 ok(hr
== HRESULT_FROM_WIN32(ERROR_OBJECT_ALREADY_EXISTS
), "Unexpected hr %#lx.\n", hr
);
6927 hr
= ID3D11Texture2D_GetPrivateData(texture
, &IID_IMFDXGIBuffer
, &size
, &data
);
6928 ok(hr
== DXGI_ERROR_NOT_FOUND
, "Unexpected hr %#lx.\n", hr
);
6930 hr
= IMFDXGIBuffer_GetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, &IID_ID3D11Device
, (void **)&obj
);
6931 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6932 ok(obj
== (IUnknown
*)device
, "Unexpected pointer.\n");
6933 IUnknown_Release(obj
);
6935 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, NULL
);
6936 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6938 hr
= IMFDXGIBuffer_GetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, &IID_IUnknown
, (void **)&obj
);
6939 ok(hr
== MF_E_NOT_FOUND
, "Unexpected hr %#lx.\n", hr
);
6941 IMFDXGIBuffer_Release(dxgi_buffer
);
6943 /* Texture updates. */
6944 color
= get_d3d11_texture_color(texture
, 0, 0);
6945 ok(!color
, "Unexpected texture color %#lx.\n", color
);
6947 max_length
= cur_length
= 0;
6949 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &cur_length
);
6950 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6951 ok(max_length
&& max_length
== cur_length
, "Unexpected length %lu.\n", max_length
);
6952 if (data
) *(DWORD
*)data
= ~0u;
6954 color
= get_d3d11_texture_color(texture
, 0, 0);
6955 ok(!color
, "Unexpected texture color %#lx.\n", color
);
6957 hr
= IMFMediaBuffer_Unlock(buffer
);
6958 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6960 color
= get_d3d11_texture_color(texture
, 0, 0);
6961 ok(color
== ~0u, "Unexpected texture color %#lx.\n", color
);
6963 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &cur_length
);
6964 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6965 ok(*(DWORD
*)data
== ~0u, "Unexpected buffer %#lx.\n", *(DWORD
*)data
);
6967 hr
= IMFMediaBuffer_Unlock(buffer
);
6968 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6970 /* Lock2D()/Unlock2D() */
6971 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
6972 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6974 hr
= IMF2DBuffer_GetScanline0AndPitch(_2d_buffer
, &data2
, &pitch2
);
6975 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
6977 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
6978 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6979 ok(!!data
&& pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
6981 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
6982 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6983 ok(!!data
&& pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
6985 hr
= IMF2DBuffer_GetScanline0AndPitch(_2d_buffer
, &data2
, &pitch2
);
6986 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6987 ok(data2
== data
&& pitch2
== pitch
, "Unexpected data/pitch.\n");
6989 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &cur_length
);
6990 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
6992 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
6993 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6995 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
6996 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
6998 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
6999 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
7001 IMF2DBuffer_Release(_2d_buffer
);
7002 IMFMediaBuffer_Release(buffer
);
7005 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 0, TRUE
, &buffer
);
7006 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
7008 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
7009 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7011 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
7012 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7013 ok(!!data
&& pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
7015 hr
= IMF2DBuffer_GetScanline0AndPitch(_2d_buffer
, &data2
, &pitch2
);
7016 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7017 ok(data2
== data
&& pitch2
== pitch
, "Unexpected data/pitch.\n");
7019 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
7020 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7022 IMF2DBuffer_Release(_2d_buffer
);
7023 IMFMediaBuffer_Release(buffer
);
7025 ID3D11Texture2D_Release(texture
);
7027 /* Subresource index 1. */
7028 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
7029 ok(hr
== S_OK
, "Failed to create a texture, hr %#lx.\n", hr
);
7031 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 1, FALSE
, &buffer
);
7032 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
7034 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
7035 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7037 /* Pitch reflects top level. */
7038 memset(buff
, 0, sizeof(buff
));
7039 *(DWORD
*)buff
= 0xff00ff00;
7040 update_d3d11_texture(texture
, 1, buff
, 64 * 4);
7042 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
7043 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7044 ok(pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
7045 ok(*(DWORD
*)data
== 0xff00ff00, "Unexpected color %#lx.\n", *(DWORD
*)data
);
7047 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
7048 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7050 IMF2DBuffer_Release(_2d_buffer
);
7051 IMFMediaBuffer_Release(buffer
);
7053 ID3D11Texture2D_Release(texture
);
7055 ID3D11Device_Release(device
);
7058 static void test_d3d12_surface_buffer(void)
7060 IMFDXGIBuffer
*dxgi_buffer
;
7061 D3D12_HEAP_PROPERTIES heap_props
;
7062 D3D12_RESOURCE_DESC desc
;
7063 ID3D12Resource
*resource
;
7064 IMFMediaBuffer
*buffer
;
7065 unsigned int refcount
;
7066 ID3D12Device
*device
;
7071 if (!(device
= create_d3d12_device()))
7073 skip("Failed to create a D3D12 device, skipping tests.\n");
7077 memset(&heap_props
, 0, sizeof(heap_props
));
7078 heap_props
.Type
= D3D12_HEAP_TYPE_DEFAULT
;
7080 memset(&desc
, 0, sizeof(desc
));
7081 desc
.Dimension
= D3D12_RESOURCE_DIMENSION_TEXTURE2D
;
7085 desc
.DepthOrArraySize
= 1;
7087 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
7088 desc
.SampleDesc
.Count
= 1;
7089 desc
.SampleDesc
.Quality
= 0;
7090 desc
.Layout
= D3D12_TEXTURE_LAYOUT_UNKNOWN
;
7091 desc
.Flags
= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET
;
7093 hr
= ID3D12Device_CreateCommittedResource(device
, &heap_props
, D3D12_HEAP_FLAG_NONE
,
7094 &desc
, D3D12_RESOURCE_STATE_RENDER_TARGET
, NULL
, &IID_ID3D12Resource
, (void **)&resource
);
7095 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7097 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D12Resource
, (IUnknown
*)resource
, 0, FALSE
, &buffer
);
7098 if (hr
== E_INVALIDARG
)
7101 win_skip("D3D12 resource buffers are not supported.\n");
7104 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
7108 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
7109 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
7110 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
7111 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
7113 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
7114 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
7116 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D12Resource
, (void **)&obj
);
7117 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
7118 ok(obj
== (IUnknown
*)resource
, "Unexpected resource pointer.\n");
7119 IUnknown_Release(obj
);
7121 IMFDXGIBuffer_Release(dxgi_buffer
);
7122 IMFMediaBuffer_Release(buffer
);
7126 ID3D12Resource_Release(resource
);
7127 refcount
= ID3D12Device_Release(device
);
7128 ok(!refcount
, "Unexpected device refcount %u.\n", refcount
);
7131 static void test_sample_allocator_sysmem(void)
7133 IMFVideoSampleAllocatorNotify test_notify
= { &test_notify_callback_vtbl
};
7134 IMFMediaType
*media_type
, *video_type
, *video_type2
;
7135 IMFVideoSampleAllocatorCallback
*allocator_cb
;
7136 IMFVideoSampleAllocatorEx
*allocatorex
;
7137 IMFVideoSampleAllocator
*allocator
;
7138 IMFSample
*sample
, *sample2
;
7139 IMFAttributes
*attributes
;
7140 IMFMediaBuffer
*buffer
;
7141 LONG refcount
, count
;
7146 if (!pMFCreateVideoSampleAllocatorEx
)
7149 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IUnknown
, (void **)&unk
);
7150 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7152 check_interface(unk
, &IID_IMFVideoSampleAllocator
, TRUE
);
7153 check_interface(unk
, &IID_IMFVideoSampleAllocatorEx
, TRUE
);
7154 check_interface(unk
, &IID_IMFVideoSampleAllocatorCallback
, TRUE
);
7156 IUnknown_Release(unk
);
7158 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
7159 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7161 hr
= IMFVideoSampleAllocator_QueryInterface(allocator
, &IID_IMFVideoSampleAllocatorCallback
, (void **)&allocator_cb
);
7162 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7164 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, NULL
);
7165 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7167 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, &test_notify
);
7168 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7170 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, NULL
);
7171 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7173 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, NULL
);
7174 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
7177 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
7178 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7179 ok(!count
, "Unexpected count %ld.\n", count
);
7181 hr
= IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator
);
7182 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7184 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
7185 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
7187 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, NULL
);
7188 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7190 hr
= MFCreateMediaType(&media_type
);
7191 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7193 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, media_type
);
7194 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7196 video_type
= create_video_type(&MFVideoFormat_RGB32
);
7197 video_type2
= create_video_type(&MFVideoFormat_RGB32
);
7199 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, video_type
);
7200 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7202 /* Frame size is required. */
7203 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 240);
7204 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7206 hr
= IMFMediaType_SetUINT64(video_type2
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 240);
7207 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7209 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 0, video_type
);
7210 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7212 EXPECT_REF(video_type
, 1);
7213 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
7214 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7215 EXPECT_REF(video_type
, 2);
7217 hr
= IMFMediaType_SetUINT64(video_type2
, &IID_IUnknown
, (UINT64
) 320 << 32 | 240);
7218 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7220 /* Setting identical type does not replace it. */
7221 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type2
);
7222 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7223 EXPECT_REF(video_type
, 2);
7224 EXPECT_REF(video_type2
, 1);
7226 hr
= IMFMediaType_SetUINT64(video_type2
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
7227 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7229 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type2
);
7230 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7231 EXPECT_REF(video_type2
, 2);
7232 EXPECT_REF(video_type
, 1);
7234 /* Modify referenced type. */
7235 hr
= IMFMediaType_SetUINT64(video_type2
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 64);
7236 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7238 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
7239 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7240 EXPECT_REF(video_type
, 2);
7241 EXPECT_REF(video_type2
, 1);
7244 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
7245 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7246 ok(count
== 1, "Unexpected count %ld.\n", count
);
7249 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
7250 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7251 refcount
= get_refcount(sample
);
7253 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
7254 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7255 ok(!count
, "Unexpected count %ld.\n", count
);
7257 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample2
);
7258 ok(hr
== MF_E_SAMPLEALLOCATOR_EMPTY
, "Unexpected hr %#lx.\n", hr
);
7260 /* Reinitialize with active sample. */
7261 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, video_type
);
7262 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7263 ok(refcount
== get_refcount(sample
), "Unexpected refcount %lu.\n", get_refcount(sample
));
7264 EXPECT_REF(video_type
, 2);
7266 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
7267 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7269 ok(!count
, "Unexpected count %ld.\n", count
);
7271 check_interface(sample
, &IID_IMFTrackedSample
, TRUE
);
7272 check_interface(sample
, &IID_IMFDesiredSample
, FALSE
);
7274 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
7275 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7277 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
7278 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
7279 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
7280 check_interface(buffer
, &IID_IMFDXGIBuffer
, FALSE
);
7282 IMFMediaBuffer_Release(buffer
);
7284 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
7285 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7286 ok(buffer_count
== 1, "Unexpected buffer count %lu.\n", buffer_count
);
7288 IMFSample_Release(sample
);
7290 hr
= IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator
);
7291 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7293 EXPECT_REF(video_type
, 2);
7295 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
7296 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7297 ok(!count
, "Unexpected count %ld.\n", count
);
7299 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
7300 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
7302 IMFVideoSampleAllocatorCallback_Release(allocator_cb
);
7303 IMFVideoSampleAllocator_Release(allocator
);
7305 /* IMFVideoSampleAllocatorEx */
7306 hr
= MFCreateAttributes(&attributes
, 0);
7307 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7309 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx
, (void **)&allocatorex
);
7310 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7312 hr
= IMFVideoSampleAllocatorEx_QueryInterface(allocatorex
, &IID_IMFVideoSampleAllocatorCallback
, (void **)&allocator_cb
);
7313 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7315 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 1, 0, NULL
, video_type
);
7316 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7318 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_BUFFERS_PER_SAMPLE
, 2);
7319 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7321 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
7322 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
7324 EXPECT_REF(attributes
, 1);
7325 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, attributes
, video_type
);
7326 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7327 EXPECT_REF(attributes
, 2);
7330 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
7331 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7332 ok(count
== 1, "Unexpected count %ld.\n", count
);
7334 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
7335 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7337 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
7338 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7339 ok(buffer_count
== 2, "Unexpected buffer count %lu.\n", buffer_count
);
7341 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample2
);
7342 ok(hr
== MF_E_SAMPLEALLOCATOR_EMPTY
, "Unexpected hr %#lx.\n", hr
);
7344 /* Reinitialize with already allocated samples. */
7345 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, NULL
, video_type
);
7346 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7347 EXPECT_REF(attributes
, 1);
7349 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample2
);
7350 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7351 IMFSample_Release(sample2
);
7353 IMFSample_Release(sample
);
7355 IMFVideoSampleAllocatorCallback_Release(allocator_cb
);
7356 IMFVideoSampleAllocatorEx_Release(allocatorex
);
7357 IMFAttributes_Release(attributes
);
7360 static void test_sample_allocator_d3d9(void)
7362 IDirect3DDeviceManager9
*d3d9_manager
;
7363 IMFVideoSampleAllocator
*allocator
;
7364 IDirect3DDevice9
*d3d9_device
;
7365 IMFMediaType
*video_type
;
7366 IMFMediaBuffer
*buffer
;
7373 if (!pMFCreateVideoSampleAllocatorEx
)
7376 window
= create_window();
7377 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
7378 ok(!!d3d9
, "Failed to create a D3D9 object.\n");
7379 if (!(d3d9_device
= create_d3d9_device(d3d9
, window
)))
7381 skip("Failed to create a D3D9 device, skipping tests.\n");
7385 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &d3d9_manager
);
7386 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7388 hr
= IDirect3DDeviceManager9_ResetDevice(d3d9_manager
, d3d9_device
, token
);
7389 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7391 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
7392 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7394 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)d3d9_manager
);
7395 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7397 video_type
= create_video_type(&MFVideoFormat_RGB32
);
7399 /* Frame size is required. */
7400 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
7401 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7403 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
7404 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7406 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
7407 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7409 check_interface(sample
, &IID_IMFTrackedSample
, TRUE
);
7410 check_interface(sample
, &IID_IMFDesiredSample
, FALSE
);
7412 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
7413 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7415 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
7416 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
7417 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
7418 check_interface(buffer
, &IID_IMFDXGIBuffer
, FALSE
);
7420 IMFSample_Release(sample
);
7421 IMFMediaBuffer_Release(buffer
);
7423 IMFVideoSampleAllocator_Release(allocator
);
7424 IMFMediaType_Release(video_type
);
7427 IDirect3D9_Release(d3d9
);
7428 DestroyWindow(window
);
7431 static void test_sample_allocator_d3d11(void)
7433 IMFMediaType
*video_type
;
7434 IMFVideoSampleAllocatorEx
*allocatorex
;
7435 IMFVideoSampleAllocator
*allocator
;
7436 unsigned int i
, token
;
7437 IMFDXGIDeviceManager
*manager
;
7439 IMFDXGIBuffer
*dxgi_buffer
;
7440 IMFAttributes
*attributes
;
7441 D3D11_TEXTURE2D_DESC desc
;
7442 ID3D11Texture2D
*texture
;
7443 IMFMediaBuffer
*buffer
;
7444 ID3D11Device
*device
;
7447 static const unsigned int usage
[] =
7449 D3D11_USAGE_DEFAULT
,
7450 D3D11_USAGE_IMMUTABLE
,
7451 D3D11_USAGE_DYNAMIC
,
7452 D3D11_USAGE_STAGING
,
7453 D3D11_USAGE_STAGING
+ 1,
7455 static const unsigned int sharing
[] =
7457 D3D11_RESOURCE_MISC_SHARED
| D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
7458 D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
7459 D3D11_RESOURCE_MISC_SHARED
,
7462 if (!pMFCreateVideoSampleAllocatorEx
)
7465 if (!(device
= create_d3d11_device()))
7467 skip("Failed to create a D3D11 device, skipping tests.\n");
7471 hr
= pMFCreateDXGIDeviceManager(&token
, &manager
);
7472 ok(hr
== S_OK
, "Failed to create device manager, hr %#lx.\n", hr
);
7474 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)device
, token
);
7475 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
7477 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
7478 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7480 EXPECT_REF(manager
, 1);
7481 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)manager
);
7482 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7483 EXPECT_REF(manager
, 2);
7485 video_type
= create_video_type(&MFVideoFormat_RGB32
);
7486 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
7487 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7489 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
7490 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7492 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
7493 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7495 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
7496 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7498 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
7499 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
7500 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
7501 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
7503 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
7504 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
7506 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&texture
);
7507 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
7509 ID3D11Texture2D_GetDesc(texture
, &desc
);
7510 ok(desc
.Width
== 64, "Unexpected width %u.\n", desc
.Width
);
7511 ok(desc
.Height
== 64, "Unexpected height %u.\n", desc
.Height
);
7512 ok(desc
.MipLevels
== 1, "Unexpected miplevels %u.\n", desc
.MipLevels
);
7513 ok(desc
.ArraySize
== 1, "Unexpected array size %u.\n", desc
.ArraySize
);
7514 ok(desc
.Format
== DXGI_FORMAT_B8G8R8X8_UNORM
, "Unexpected format %u.\n", desc
.Format
);
7515 ok(desc
.SampleDesc
.Count
== 1, "Unexpected sample count %u.\n", desc
.SampleDesc
.Count
);
7516 ok(!desc
.SampleDesc
.Quality
, "Unexpected sample quality %u.\n", desc
.SampleDesc
.Quality
);
7517 ok(desc
.Usage
== D3D11_USAGE_DEFAULT
, "Unexpected usage %u.\n", desc
.Usage
);
7518 ok(desc
.BindFlags
== (D3D11_BIND_SHADER_RESOURCE
| D3D11_BIND_RENDER_TARGET
), "Unexpected bind flags %#x.\n",
7520 ok(!desc
.CPUAccessFlags
, "Unexpected CPU access flags %#x.\n", desc
.CPUAccessFlags
);
7521 ok(!desc
.MiscFlags
, "Unexpected misc flags %#x.\n", desc
.MiscFlags
);
7523 ID3D11Texture2D_Release(texture
);
7524 IMFDXGIBuffer_Release(dxgi_buffer
);
7526 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
7527 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7529 hr
= IMFMediaBuffer_Unlock(buffer
);
7530 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7532 IMFSample_Release(sample
);
7534 IMFVideoSampleAllocator_Release(allocator
);
7536 /* MF_SA_D3D11_USAGE */
7537 hr
= MFCreateAttributes(&attributes
, 1);
7538 ok(hr
== S_OK
, "Failed to create attributes, hr %#lx.\n", hr
);
7540 for (i
= 0; i
< ARRAY_SIZE(usage
); ++i
)
7542 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx
, (void **)&allocatorex
);
7543 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7545 hr
= IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex
, (IUnknown
*)manager
);
7546 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7548 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_USAGE
, usage
[i
]);
7549 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
7551 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, attributes
, video_type
);
7552 if (usage
[i
] == D3D11_USAGE_IMMUTABLE
|| usage
[i
] > D3D11_USAGE_STAGING
)
7554 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7555 IMFVideoSampleAllocatorEx_Release(allocatorex
);
7558 ok(hr
== S_OK
, "%u: Unexpected hr %#lx.\n", usage
[i
], hr
);
7560 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_USAGE
, D3D11_USAGE_DEFAULT
);
7561 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
7563 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
7564 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7566 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
7567 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7569 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
7570 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
7572 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&texture
);
7573 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
7575 ID3D11Texture2D_GetDesc(texture
, &desc
);
7576 ok(desc
.Usage
== usage
[i
], "Unexpected usage %u.\n", desc
.Usage
);
7577 if (usage
[i
] == D3D11_USAGE_DEFAULT
)
7579 ok(desc
.BindFlags
== (D3D11_BIND_SHADER_RESOURCE
| D3D11_BIND_RENDER_TARGET
), "Unexpected bind flags %#x.\n",
7581 ok(!desc
.CPUAccessFlags
, "Unexpected CPU access flags %#x.\n", desc
.CPUAccessFlags
);
7583 else if (usage
[i
] == D3D11_USAGE_DYNAMIC
)
7585 ok(desc
.BindFlags
== D3D11_BIND_SHADER_RESOURCE
, "Unexpected bind flags %#x.\n", desc
.BindFlags
);
7586 ok(desc
.CPUAccessFlags
== D3D11_CPU_ACCESS_WRITE
, "Unexpected CPU access flags %#x.\n", desc
.CPUAccessFlags
);
7588 else if (usage
[i
] == D3D11_USAGE_STAGING
)
7590 ok(!desc
.BindFlags
, "Unexpected bind flags %#x.\n", desc
.BindFlags
);
7591 ok(desc
.CPUAccessFlags
== (D3D11_CPU_ACCESS_WRITE
| D3D11_CPU_ACCESS_READ
), "Unexpected CPU access flags %#x.\n",
7592 desc
.CPUAccessFlags
);
7594 ok(!desc
.MiscFlags
, "Unexpected misc flags %#x.\n", desc
.MiscFlags
);
7596 ID3D11Texture2D_Release(texture
);
7597 IMFDXGIBuffer_Release(dxgi_buffer
);
7598 IMFMediaBuffer_Release(buffer
);
7600 IMFSample_Release(sample
);
7602 IMFVideoSampleAllocatorEx_Release(allocatorex
);
7605 /* MF_SA_D3D11_SHARED, MF_SA_D3D11_SHARED_WITHOUT_MUTEX */
7606 for (i
= 0; i
< ARRAY_SIZE(sharing
); ++i
)
7608 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx
, (void **)&allocatorex
);
7609 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7611 hr
= IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex
, (IUnknown
*)manager
);
7612 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7614 hr
= IMFAttributes_DeleteAllItems(attributes
);
7615 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7617 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_USAGE
, D3D11_USAGE_DEFAULT
);
7618 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
7620 if (sharing
[i
] & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
)
7622 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_SHARED
, TRUE
);
7623 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
7626 if (sharing
[i
] & D3D11_RESOURCE_MISC_SHARED
)
7628 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX
, TRUE
);
7629 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
7632 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, attributes
, video_type
);
7633 if (sharing
[i
] == (D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
| D3D11_RESOURCE_MISC_SHARED
))
7636 ok(hr
== E_INVALIDARG
, "%u: Unexpected hr %#lx.\n", i
, hr
);
7637 IMFVideoSampleAllocatorEx_Release(allocatorex
);
7640 ok(hr
== S_OK
, "%u: Unexpected hr %#lx.\n", i
, hr
);
7642 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
7643 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7645 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
7646 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7648 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
7649 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
7651 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&texture
);
7652 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
7654 ID3D11Texture2D_GetDesc(texture
, &desc
);
7655 ok(desc
.MiscFlags
== sharing
[i
], "%u: unexpected misc flags %#x.\n", i
, desc
.MiscFlags
);
7657 ID3D11Texture2D_Release(texture
);
7658 IMFDXGIBuffer_Release(dxgi_buffer
);
7659 IMFMediaBuffer_Release(buffer
);
7661 IMFSample_Release(sample
);
7663 IMFVideoSampleAllocatorEx_Release(allocatorex
);
7666 IMFAttributes_Release(attributes
);
7668 IMFDXGIDeviceManager_Release(manager
);
7669 ID3D11Device_Release(device
);
7672 static void test_sample_allocator_d3d12(void)
7674 IMFVideoSampleAllocator
*allocator
;
7675 D3D12_HEAP_PROPERTIES heap_props
;
7676 IMFDXGIDeviceManager
*manager
;
7677 D3D12_HEAP_FLAGS heap_flags
;
7678 IMFDXGIBuffer
*dxgi_buffer
;
7679 IMFMediaType
*video_type
;
7680 ID3D12Resource
*resource
;
7681 D3D12_RESOURCE_DESC desc
;
7682 IMFMediaBuffer
*buffer
;
7683 ID3D12Device
*device
;
7688 if (!(device
= create_d3d12_device()))
7690 skip("Failed to create a D3D12 device, skipping tests.\n");
7694 hr
= pMFCreateDXGIDeviceManager(&token
, &manager
);
7695 ok(hr
== S_OK
, "Failed to create device manager, hr %#lx.\n", hr
);
7697 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)device
, token
);
7700 win_skip("Device manager does not support D3D12 devices.\n");
7703 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
7705 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
7706 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7708 EXPECT_REF(manager
, 1);
7709 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)manager
);
7710 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7711 EXPECT_REF(manager
, 2);
7713 video_type
= create_video_type(&MFVideoFormat_RGB32
);
7714 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
7715 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7716 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_D3D_RESOURCE_VERSION
, MF_D3D12_RESOURCE
);
7717 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7719 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
7721 ok(hr
== S_OK
|| broken(hr
== MF_E_UNEXPECTED
) /* Some Win10 versions fail. */, "Unexpected hr %#lx.\n", hr
);
7722 if (FAILED(hr
)) goto done
;
7724 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
7725 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7727 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
7728 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7730 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
7731 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
7732 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
7733 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
7735 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
7736 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
7738 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D12Resource
, (void **)&resource
);
7739 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
7741 resource
->lpVtbl
->GetDesc(resource
, &desc
);
7742 ok(desc
.Width
== 64, "Unexpected width.\n");
7743 ok(desc
.Height
== 64, "Unexpected height.\n");
7744 ok(desc
.DepthOrArraySize
== 1, "Unexpected array size %u.\n", desc
.DepthOrArraySize
);
7745 ok(desc
.MipLevels
== 1, "Unexpected miplevels %u.\n", desc
.MipLevels
);
7746 ok(desc
.Format
== DXGI_FORMAT_B8G8R8X8_UNORM
, "Unexpected format %u.\n", desc
.Format
);
7747 ok(desc
.SampleDesc
.Count
== 1, "Unexpected sample count %u.\n", desc
.SampleDesc
.Count
);
7748 ok(!desc
.SampleDesc
.Quality
, "Unexpected sample quality %u.\n", desc
.SampleDesc
.Quality
);
7749 ok(!desc
.Layout
, "Unexpected layout %u.\n", desc
.Layout
);
7750 ok(!desc
.Flags
, "Unexpected flags %#x.\n", desc
.Flags
);
7752 hr
= ID3D12Resource_GetHeapProperties(resource
, &heap_props
, &heap_flags
);
7753 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7754 ok(heap_props
.Type
== D3D12_HEAP_TYPE_DEFAULT
, "Unexpected heap type %u.\n", heap_props
.Type
);
7755 ok(heap_props
.CPUPageProperty
== D3D12_CPU_PAGE_PROPERTY_UNKNOWN
, "Unexpected page property %u.\n",
7756 heap_props
.CPUPageProperty
);
7757 ok(!heap_props
.MemoryPoolPreference
, "Unexpected pool preference %u.\n", heap_props
.MemoryPoolPreference
);
7758 ok(heap_flags
== D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES
, "Unexpected heap flags %#x.\n", heap_flags
);
7760 ID3D12Resource_Release(resource
);
7761 IMFDXGIBuffer_Release(dxgi_buffer
);
7762 IMFSample_Release(sample
);
7764 IMFVideoSampleAllocator_Release(allocator
);
7767 IMFDXGIDeviceManager_Release(manager
);
7768 ID3D12Device_Release(device
);
7771 static void test_MFLockSharedWorkQueue(void)
7773 DWORD taskid
, queue
, queue2
;
7776 if (!pMFLockSharedWorkQueue
)
7778 win_skip("MFLockSharedWorkQueue() is not available.\n");
7782 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
7783 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
7785 hr
= pMFLockSharedWorkQueue(NULL
, 0, &taskid
, &queue
);
7786 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
7788 hr
= pMFLockSharedWorkQueue(NULL
, 0, NULL
, &queue
);
7789 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
7792 hr
= pMFLockSharedWorkQueue(L
"", 0, &taskid
, &queue
);
7793 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7796 hr
= pMFLockSharedWorkQueue(L
"", 0, NULL
, &queue
);
7797 ok(queue
& MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK
, "Unexpected queue id.\n");
7800 hr
= pMFLockSharedWorkQueue(L
"", 0, NULL
, &queue2
);
7801 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7802 ok(queue
== queue2
, "Unexpected queue %#lx.\n", queue2
);
7804 hr
= MFUnlockWorkQueue(queue2
);
7805 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7807 hr
= MFUnlockWorkQueue(queue
);
7808 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7811 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
7814 static void test_MFllMulDiv(void)
7816 /* (a * b + d) / c */
7817 static const struct muldivtest
7827 { 0, 0, 0, 0, _I64_MAX
},
7828 { 1000000, 1000000, 2, 0, 500000000000 },
7829 { _I64_MAX
, 3, _I64_MAX
, 0, 3 },
7830 { _I64_MAX
, 3, _I64_MAX
, 1, 3 },
7831 { -10000, 3, 100, 0, -300 },
7833 { 2, 1, 1, -3, -1 },
7834 /* a * b product does not fit in uint64_t */
7835 { _I64_MAX
, 4, 8, 0, _I64_MAX
/ 2 },
7836 /* Large a * b product, large denominator */
7837 { _I64_MAX
, 4, 0x100000000, 0, 0x1ffffffff },
7841 for (i
= 0; i
< ARRAY_SIZE(muldivtests
); ++i
)
7845 result
= MFllMulDiv(muldivtests
[i
].a
, muldivtests
[i
].b
, muldivtests
[i
].c
, muldivtests
[i
].d
);
7846 ok(result
== muldivtests
[i
].result
, "%u: unexpected result %s, expected %s.\n", i
,
7847 wine_dbgstr_longlong(result
), wine_dbgstr_longlong(muldivtests
[i
].result
));
7851 static void test_shared_dxgi_device_manager(void)
7853 IMFDXGIDeviceManager
*manager
;
7857 if (!pMFLockDXGIDeviceManager
)
7859 win_skip("Shared DXGI device manager is not supported.\n");
7863 hr
= pMFUnlockDXGIDeviceManager();
7864 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7867 hr
= pMFLockDXGIDeviceManager(NULL
, &manager
);
7868 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7869 ok(!!manager
, "Unexpected instance.\n");
7871 hr
= pMFLockDXGIDeviceManager(&token
, &manager
);
7872 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7874 EXPECT_REF(manager
, 3);
7876 hr
= pMFUnlockDXGIDeviceManager();
7877 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7879 EXPECT_REF(manager
, 2);
7881 hr
= pMFUnlockDXGIDeviceManager();
7882 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7885 static void check_video_format(const MFVIDEOFORMAT
*format
, unsigned int width
, unsigned int height
,
7888 unsigned int transfer_function
;
7891 if (!d3dformat
) d3dformat
= D3DFMT_X8R8G8B8
;
7895 case D3DFMT_X8R8G8B8
:
7897 case D3DFMT_A8R8G8B8
:
7899 case D3DFMT_X1R5G5B5
:
7900 case D3DFMT_A2B10G10R10
:
7902 transfer_function
= MFVideoTransFunc_sRGB
;
7905 transfer_function
= MFVideoTransFunc_10
;
7908 memcpy(&guid
, &MFVideoFormat_Base
, sizeof(guid
));
7909 guid
.Data1
= d3dformat
;
7911 ok(format
->dwSize
== sizeof(*format
), "Unexpected format size.\n");
7912 ok(format
->videoInfo
.dwWidth
== width
, "Unexpected width %lu.\n", format
->videoInfo
.dwWidth
);
7913 ok(format
->videoInfo
.dwHeight
== height
, "Unexpected height %lu.\n", format
->videoInfo
.dwHeight
);
7914 ok(format
->videoInfo
.PixelAspectRatio
.Numerator
== 1 &&
7915 format
->videoInfo
.PixelAspectRatio
.Denominator
== 1, "Unexpected PAR.\n");
7916 ok(format
->videoInfo
.SourceChromaSubsampling
== MFVideoChromaSubsampling_Unknown
, "Unexpected chroma subsampling.\n");
7917 ok(format
->videoInfo
.InterlaceMode
== MFVideoInterlace_Progressive
, "Unexpected interlace mode %u.\n",
7918 format
->videoInfo
.InterlaceMode
);
7919 ok(format
->videoInfo
.TransferFunction
== transfer_function
, "Unexpected transfer function %u.\n",
7920 format
->videoInfo
.TransferFunction
);
7921 ok(format
->videoInfo
.ColorPrimaries
== MFVideoPrimaries_BT709
, "Unexpected color primaries %u.\n",
7922 format
->videoInfo
.ColorPrimaries
);
7923 ok(format
->videoInfo
.TransferMatrix
== MFVideoTransferMatrix_Unknown
, "Unexpected transfer matrix.\n");
7924 ok(format
->videoInfo
.SourceLighting
== MFVideoLighting_office
, "Unexpected source lighting %u.\n",
7925 format
->videoInfo
.SourceLighting
);
7926 ok(format
->videoInfo
.FramesPerSecond
.Numerator
== 60 &&
7927 format
->videoInfo
.FramesPerSecond
.Denominator
== 1, "Unexpected frame rate %lu/%lu.\n",
7928 format
->videoInfo
.FramesPerSecond
.Numerator
, format
->videoInfo
.FramesPerSecond
.Denominator
);
7929 ok(format
->videoInfo
.NominalRange
== MFNominalRange_Normal
, "Unexpected nominal range %u.\n",
7930 format
->videoInfo
.NominalRange
);
7931 ok(format
->videoInfo
.GeometricAperture
.Area
.cx
== width
&& format
->videoInfo
.GeometricAperture
.Area
.cy
== height
,
7932 "Unexpected geometric aperture.\n");
7933 ok(!memcmp(&format
->videoInfo
.GeometricAperture
, &format
->videoInfo
.MinimumDisplayAperture
, sizeof(MFVideoArea
)),
7934 "Unexpected minimum display aperture.\n");
7935 ok(format
->videoInfo
.PanScanAperture
.Area
.cx
== 0 && format
->videoInfo
.PanScanAperture
.Area
.cy
== 0,
7936 "Unexpected geometric aperture.\n");
7937 ok(format
->videoInfo
.VideoFlags
== 0, "Unexpected video flags.\n");
7938 ok(IsEqualGUID(&format
->guidFormat
, &guid
), "Unexpected format guid %s.\n", wine_dbgstr_guid(&format
->guidFormat
));
7939 ok(format
->compressedInfo
.AvgBitrate
== 0, "Unexpected bitrate.\n");
7940 ok(format
->compressedInfo
.AvgBitErrorRate
== 0, "Unexpected error bitrate.\n");
7941 ok(format
->compressedInfo
.MaxKeyFrameSpacing
== 0, "Unexpected MaxKeyFrameSpacing.\n");
7942 ok(format
->surfaceInfo
.Format
== d3dformat
, "Unexpected format %lu.\n", format
->surfaceInfo
.Format
);
7943 ok(format
->surfaceInfo
.PaletteEntries
== 0, "Unexpected palette size %lu.\n", format
->surfaceInfo
.PaletteEntries
);
7946 static void test_MFInitVideoFormat_RGB(void)
7948 static const DWORD formats
[] =
7950 0, /* same D3DFMT_X8R8G8B8 */
7963 D3DFMT_A16B16G16R16F
,
7965 MFVIDEOFORMAT format
;
7969 if (!pMFInitVideoFormat_RGB
)
7971 win_skip("MFInitVideoFormat_RGB is not available.\n");
7975 hr
= pMFInitVideoFormat_RGB(NULL
, 64, 32, 0);
7976 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7978 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
7980 memset(&format
, 0, sizeof(format
));
7981 hr
= pMFInitVideoFormat_RGB(&format
, 64, 32, formats
[i
]);
7982 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7984 check_video_format(&format
, 64, 32, formats
[i
]);
7995 argc
= winetest_get_mainargs(&argv
);
7998 test_queue_com_state(argv
[2]);
8002 if (!pMFCreateVideoSampleAllocatorEx
)
8003 win_skip("MFCreateVideoSampleAllocatorEx() is not available. Some tests will be skipped.\n");
8005 if (!pD3D12CreateDevice
)
8006 skip("Missing d3d12 support, some tests will be skipped.\n");
8013 test_MFCreateMediaEvent();
8017 test_MFCreateMFByteStreamOnStream();
8018 test_system_memory_buffer();
8019 test_system_memory_aligned_buffer();
8020 test_source_resolver();
8021 test_MFCreateAsyncResult();
8022 test_allocate_queue();
8023 test_MFLockSharedWorkQueue();
8025 test_MFCreateCollection();
8027 test_scheduled_items();
8028 test_serial_queue();
8029 test_periodic_callback();
8031 test_presentation_descriptor();
8032 test_system_time_source();
8033 test_MFInvokeCallback();
8034 test_stream_descriptor();
8035 test_MFCalculateImageSize();
8036 test_MFGetPlaneSize();
8037 test_MFCompareFullToPartialMediaType();
8038 test_attributes_serialization();
8039 test_wrapped_media_type();
8040 test_MFCreateWaveFormatExFromMFMediaType();
8041 test_async_create_file();
8042 test_local_handlers();
8043 test_create_property_store();
8044 test_dxgi_device_manager();
8045 test_MFCreateTransformActivate();
8046 test_MFTRegisterLocal();
8048 test_MFGetStrideForBitmapInfoHeader();
8049 test_MFCreate2DMediaBuffer();
8050 test_MFCreateMediaBufferFromMediaType();
8051 test_MFInitMediaTypeFromWaveFormatEx();
8052 test_MFCreateMFVideoFormatFromMFMediaType();
8053 test_MFCreateDXSurfaceBuffer();
8054 test_MFCreateTrackedSample();
8055 test_MFFrameRateToAverageTimePerFrame();
8056 test_MFAverageTimePerFrameToFrameRate();
8057 test_MFMapDXGIFormatToDX9Format();
8058 test_d3d11_surface_buffer();
8059 test_d3d12_surface_buffer();
8060 test_sample_allocator_sysmem();
8061 test_sample_allocator_d3d9();
8062 test_sample_allocator_d3d11();
8063 test_sample_allocator_d3d12();
8064 test_MFMapDX9FormatToDXGIFormat();
8066 test_shared_dxgi_device_manager();
8067 test_MFInitVideoFormat_RGB();