mfplat/tests: Add tests for MFInitMediaTypeFromMFVideoFormat.
[wine.git] / dlls / mfplat / tests / mfplat.c
blob035d9e44dfa5a2eb9132a9785ecb40cd30644a27
1 /*
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
21 #include <stdarg.h>
22 #include <string.h>
23 #include <limits.h>
25 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "ole2.h"
32 #include "ks.h"
33 #include "ksmedia.h"
34 #include "amvideo.h"
35 #include "mfapi.h"
36 #include "mfidl.h"
37 #include "mferror.h"
38 #include "mfreadwrite.h"
39 #include "propvarutil.h"
40 #include "strsafe.h"
41 #include "uuids.h"
42 #include "evr.h"
43 #include "mfmediaengine.h"
45 #include "wine/test.h"
47 #define D3D11_INIT_GUID
48 #include "initguid.h"
49 #include "d3d11_4.h"
50 #include "d3d9.h"
51 #include "d3d9types.h"
52 #include "ks.h"
53 #include "ksmedia.h"
54 #include "dxva2api.h"
55 #include "d3d12.h"
56 #undef EXTERN_GUID
57 #define EXTERN_GUID DEFINE_GUID
58 #include "mfd3d12.h"
59 #include "wmcodecdsp.h"
60 #include "dvdmedia.h"
62 DEFINE_GUID(DUMMY_CLSID, 0x12345678,0x1234,0x1234,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19);
63 DEFINE_GUID(DUMMY_GUID1, 0x12345678,0x1234,0x1234,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21);
64 DEFINE_GUID(DUMMY_GUID2, 0x12345678,0x1234,0x1234,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22);
65 DEFINE_GUID(DUMMY_GUID3, 0x12345678,0x1234,0x1234,0x23,0x23,0x23,0x23,0x23,0x23,0x23,0x23);
67 extern const CLSID CLSID_FileSchemePlugin;
69 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_Base,0);
71 DEFINE_MEDIATYPE_GUID(MFVideoFormat_RGB1, D3DFMT_A1);
72 DEFINE_MEDIATYPE_GUID(MFVideoFormat_RGB4, MAKEFOURCC('4','P','x','x'));
73 DEFINE_MEDIATYPE_GUID(MFVideoFormat_ARGB1555, D3DFMT_A1R5G5B5);
74 DEFINE_MEDIATYPE_GUID(MFVideoFormat_ARGB4444, D3DFMT_A4R4G4B4);
75 /* SDK MFVideoFormat_A2R10G10B10 uses D3DFMT_A2B10G10R10, let's name it the other way */
76 DEFINE_MEDIATYPE_GUID(MFVideoFormat_A2B10G10R10, D3DFMT_A2R10G10B10);
78 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_h264,MAKEFOURCC('h','2','6','4'));
79 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_MP3,WAVE_FORMAT_MPEGLAYER3);
81 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC1, MAKEFOURCC('I','M','C','1'));
82 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC2, MAKEFOURCC('I','M','C','2'));
83 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC3, MAKEFOURCC('I','M','C','3'));
84 DEFINE_MEDIATYPE_GUID(MFVideoFormat_IMC4, MAKEFOURCC('I','M','C','4'));
86 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_AVC1,MAKEFOURCC('A','V','C','1'));
87 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_MP42,MAKEFOURCC('M','P','4','2'));
88 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_mp42,MAKEFOURCC('m','p','4','2'));
89 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_MPG4,MAKEFOURCC('M','P','G','4'));
90 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_mpg4,MAKEFOURCC('m','p','g','4'));
91 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_P422,MAKEFOURCC('P','4','2','2'));
92 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_wmva,MAKEFOURCC('w','m','v','a'));
93 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_WMVB,MAKEFOURCC('W','M','V','B'));
94 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_wmvb,MAKEFOURCC('w','m','v','b'));
95 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_wmvp,MAKEFOURCC('w','m','v','p'));
96 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_wmvr,MAKEFOURCC('w','m','v','r'));
97 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_wvp2,MAKEFOURCC('w','v','p','2'));
98 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_X264,MAKEFOURCC('X','2','6','4'));
99 DEFINE_MEDIATYPE_GUID(MEDIASUBTYPE_x264,MAKEFOURCC('x','2','6','4'));
101 static BOOL is_win8_plus;
103 #define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__)
104 static void _expect_ref(IUnknown *obj, ULONG ref, int line)
106 ULONG rc;
107 IUnknown_AddRef(obj);
108 rc = IUnknown_Release(obj);
109 ok_(__FILE__,line)(rc == ref, "Unexpected refcount %ld, expected %ld.\n", rc, ref);
112 static ULONG get_refcount(void *iface)
114 IUnknown *unknown = iface;
115 IUnknown_AddRef(unknown);
116 return IUnknown_Release(unknown);
119 #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
120 static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
122 IUnknown *iface = iface_ptr;
123 HRESULT hr, expected_hr;
124 IUnknown *unk;
126 expected_hr = supported ? S_OK : E_NOINTERFACE;
128 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
129 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
130 if (SUCCEEDED(hr))
131 IUnknown_Release(unk);
134 #define check_service_interface(a, b, c, d) check_service_interface_(__LINE__, a, b, c, d)
135 static void check_service_interface_(unsigned int line, void *iface_ptr, REFGUID service, REFIID iid, BOOL supported)
137 IUnknown *iface = iface_ptr;
138 HRESULT hr, expected_hr;
139 IMFGetService *gs;
140 IUnknown *unk;
142 expected_hr = supported ? S_OK : E_NOINTERFACE;
144 if (SUCCEEDED(hr = IUnknown_QueryInterface(iface, &IID_IMFGetService, (void **)&gs)))
146 hr = IMFGetService_GetService(gs, service, iid, (void **)&unk);
147 IMFGetService_Release(gs);
149 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
150 if (SUCCEEDED(hr))
151 IUnknown_Release(unk);
154 struct d3d9_surface_readback
156 IDirect3DSurface9 *surface, *readback_surface;
157 D3DLOCKED_RECT map_desc;
158 D3DSURFACE_DESC surf_desc;
161 static void get_d3d9_surface_readback(IDirect3DSurface9 *surface, struct d3d9_surface_readback *rb)
163 IDirect3DDevice9 *device;
164 HRESULT hr;
166 rb->surface = surface;
168 hr = IDirect3DSurface9_GetDevice(surface, &device);
169 ok(hr == D3D_OK, "Failed to get device, hr %#lx.\n", hr);
171 hr = IDirect3DSurface9_GetDesc(surface, &rb->surf_desc);
172 ok(hr == D3D_OK, "Failed to get surface desc, hr %#lx.\n", hr);
173 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, rb->surf_desc.Width, rb->surf_desc.Height,
174 rb->surf_desc.Format, D3DPOOL_SYSTEMMEM, &rb->readback_surface, NULL);
175 ok(hr == D3D_OK, "Failed to create surface, hr %#lx.\n", hr);
177 hr = IDirect3DDevice9Ex_GetRenderTargetData(device, surface, rb->readback_surface);
178 ok(hr == D3D_OK, "Failed to get render target data, hr %#lx.\n", hr);
180 hr = IDirect3DSurface9_LockRect(rb->readback_surface, &rb->map_desc, NULL, 0);
181 ok(hr == D3D_OK, "Failed to lock surface, hr %#lx.\n", hr);
183 IDirect3DDevice9_Release(device);
186 static void release_d3d9_surface_readback(struct d3d9_surface_readback *rb, BOOL upload)
188 ULONG refcount;
189 HRESULT hr;
191 hr = IDirect3DSurface9_UnlockRect(rb->readback_surface);
192 ok(hr == D3D_OK, "Failed to unlock surface, hr %#lx.\n", hr);
194 if (upload)
196 IDirect3DDevice9 *device;
198 IDirect3DSurface9_GetDevice(rb->surface, &device);
199 ok(hr == D3D_OK, "Failed to get device, hr %#lx.\n", hr);
201 hr = IDirect3DDevice9_UpdateSurface(device, rb->readback_surface, NULL, rb->surface, NULL);
202 ok(hr == D3D_OK, "Failed to update surface, hr %#lx.\n", hr);
204 IDirect3DDevice9_Release(device);
207 refcount = IDirect3DSurface9_Release(rb->readback_surface);
208 ok(refcount == 0, "Readback surface still has references.\n");
211 static void *get_d3d9_readback_data(struct d3d9_surface_readback *rb,
212 unsigned int x, unsigned int y, unsigned byte_width)
214 return (BYTE *)rb->map_desc.pBits + y * rb->map_desc.Pitch + x * byte_width;
217 static DWORD get_d3d9_readback_u32(struct d3d9_surface_readback *rb, unsigned int x, unsigned int y)
219 return *(DWORD *)get_d3d9_readback_data(rb, x, y, sizeof(DWORD));
222 static DWORD get_d3d9_readback_color(struct d3d9_surface_readback *rb, unsigned int x, unsigned int y)
224 return get_d3d9_readback_u32(rb, x, y);
227 static DWORD get_d3d9_surface_color(IDirect3DSurface9 *surface, unsigned int x, unsigned int y)
229 struct d3d9_surface_readback rb;
230 DWORD color;
232 get_d3d9_surface_readback(surface, &rb);
233 color = get_d3d9_readback_color(&rb, x, y);
234 release_d3d9_surface_readback(&rb, FALSE);
236 return color;
239 static void put_d3d9_readback_u32(struct d3d9_surface_readback *rb, unsigned int x, unsigned int y, DWORD color)
241 *(DWORD *)get_d3d9_readback_data(rb, x, y, sizeof(DWORD)) = color;
244 static void put_d3d9_readback_color(struct d3d9_surface_readback *rb, unsigned int x, unsigned int y, DWORD color)
246 put_d3d9_readback_u32(rb, x, y, color);
249 static void put_d3d9_surface_color(IDirect3DSurface9 *surface,
250 unsigned int x, unsigned int y, DWORD color)
252 struct d3d9_surface_readback rb;
254 get_d3d9_surface_readback(surface, &rb);
255 put_d3d9_readback_color(&rb, x, y, color);
256 release_d3d9_surface_readback(&rb, TRUE);
259 struct d3d11_resource_readback
261 ID3D11Resource *orig_resource, *resource;
262 D3D11_MAPPED_SUBRESOURCE map_desc;
263 ID3D11DeviceContext *immediate_context;
264 unsigned int width, height, depth, sub_resource_idx;
267 static void init_d3d11_resource_readback(ID3D11Resource *resource, ID3D11Resource *readback_resource,
268 unsigned int width, unsigned int height, unsigned int depth, unsigned int sub_resource_idx,
269 ID3D11Device *device, struct d3d11_resource_readback *rb)
271 HRESULT hr;
273 rb->orig_resource = resource;
274 rb->resource = readback_resource;
275 rb->width = width;
276 rb->height = height;
277 rb->depth = depth;
278 rb->sub_resource_idx = sub_resource_idx;
280 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
282 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, resource);
283 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context,
284 rb->resource, sub_resource_idx, D3D11_MAP_READ_WRITE, 0, &rb->map_desc)))
286 trace("Failed to map resource, hr %#lx.\n", hr);
287 ID3D11Resource_Release(rb->resource);
288 rb->resource = NULL;
289 ID3D11DeviceContext_Release(rb->immediate_context);
290 rb->immediate_context = NULL;
294 static void get_d3d11_texture2d_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
295 struct d3d11_resource_readback *rb)
297 D3D11_TEXTURE2D_DESC texture_desc;
298 ID3D11Resource *rb_texture;
299 unsigned int miplevel;
300 ID3D11Device *device;
301 HRESULT hr;
303 memset(rb, 0, sizeof(*rb));
305 ID3D11Texture2D_GetDevice(texture, &device);
307 ID3D11Texture2D_GetDesc(texture, &texture_desc);
308 texture_desc.Usage = D3D11_USAGE_STAGING;
309 texture_desc.BindFlags = 0;
310 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
311 texture_desc.MiscFlags = 0;
312 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb_texture)))
314 trace("Failed to create texture, hr %#lx.\n", hr);
315 ID3D11Device_Release(device);
316 return;
319 miplevel = sub_resource_idx % texture_desc.MipLevels;
320 init_d3d11_resource_readback((ID3D11Resource *)texture, rb_texture,
321 max(1, texture_desc.Width >> miplevel),
322 max(1, texture_desc.Height >> miplevel),
323 1, sub_resource_idx, device, rb);
325 ID3D11Device_Release(device);
328 static void release_d3d11_resource_readback(struct d3d11_resource_readback *rb, BOOL upload)
330 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
332 if (upload)
334 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->orig_resource, rb->resource);
337 ID3D11Resource_Release(rb->resource);
338 ID3D11DeviceContext_Release(rb->immediate_context);
341 static void *get_d3d11_readback_data(struct d3d11_resource_readback *rb,
342 unsigned int x, unsigned int y, unsigned int z, unsigned byte_width)
344 return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width;
347 static DWORD get_d3d11_readback_u32(struct d3d11_resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
349 return *(DWORD *)get_d3d11_readback_data(rb, x, y, z, sizeof(DWORD));
352 static DWORD get_d3d11_readback_color(struct d3d11_resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
354 return get_d3d11_readback_u32(rb, x, y, z);
357 static DWORD get_d3d11_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
359 struct d3d11_resource_readback rb;
360 DWORD color;
362 get_d3d11_texture2d_readback(texture, 0, &rb);
363 color = get_d3d11_readback_color(&rb, x, y, 0);
364 release_d3d11_resource_readback(&rb, FALSE);
366 return color;
369 static void put_d3d11_readback_u32(struct d3d11_resource_readback *rb,
370 unsigned int x, unsigned int y, unsigned int z, DWORD color)
372 *(DWORD *)get_d3d11_readback_data(rb, x, y, z, sizeof(DWORD)) = color;
375 static void put_d3d11_readback_color(struct d3d11_resource_readback *rb,
376 unsigned int x, unsigned int y, unsigned int z, DWORD color)
378 put_d3d11_readback_u32(rb, x, y, z, color);
381 static void put_d3d11_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y, DWORD color)
383 struct d3d11_resource_readback rb;
385 get_d3d11_texture2d_readback(texture, 0, &rb);
386 put_d3d11_readback_color(&rb, x, y, 0, color);
387 release_d3d11_resource_readback(&rb, TRUE);
390 static HRESULT (WINAPI *pD3D11CreateDevice)(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags,
391 const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out,
392 D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context);
393 static HRESULT (WINAPI *pD3D12CreateDevice)(IUnknown *adapter, D3D_FEATURE_LEVEL minimum_feature_level,
394 REFIID iid, void **device);
396 static HRESULT (WINAPI *pCoGetApartmentType)(APTTYPE *type, APTTYPEQUALIFIER *qualifier);
398 static HRESULT (WINAPI *pMFCopyImage)(BYTE *dest, LONG deststride, const BYTE *src, LONG srcstride,
399 DWORD width, DWORD lines);
400 static HRESULT (WINAPI *pMFCreateDXGIDeviceManager)(UINT *token, IMFDXGIDeviceManager **manager);
401 static HRESULT (WINAPI *pMFCreateSourceResolver)(IMFSourceResolver **resolver);
402 static HRESULT (WINAPI *pMFCreateMFByteStreamOnStream)(IStream *stream, IMFByteStream **bytestream);
403 static HRESULT (WINAPI *pMFPutWaitingWorkItem)(HANDLE event, LONG priority, IMFAsyncResult *result, MFWORKITEM_KEY *key);
404 static HRESULT (WINAPI *pMFAllocateSerialWorkQueue)(DWORD queue, DWORD *serial_queue);
405 static HRESULT (WINAPI *pMFAddPeriodicCallback)(MFPERIODICCALLBACK callback, IUnknown *context, DWORD *key);
406 static HRESULT (WINAPI *pMFRemovePeriodicCallback)(DWORD key);
407 static HRESULT (WINAPI *pMFRegisterLocalByteStreamHandler)(const WCHAR *extension, const WCHAR *mime,
408 IMFActivate *activate);
409 static HRESULT (WINAPI *pMFRegisterLocalSchemeHandler)(const WCHAR *scheme, IMFActivate *activate);
410 static HRESULT (WINAPI *pMFCreateTransformActivate)(IMFActivate **activate);
411 static HRESULT (WINAPI *pMFTRegisterLocal)(IClassFactory *factory, REFGUID category, LPCWSTR name,
412 UINT32 flags, UINT32 cinput, const MFT_REGISTER_TYPE_INFO *input_types, UINT32 coutput,
413 const MFT_REGISTER_TYPE_INFO* output_types);
414 static HRESULT (WINAPI *pMFTRegisterLocalByCLSID)(REFCLSID clsid, REFGUID category, LPCWSTR name, UINT32 flags,
415 UINT32 input_count, const MFT_REGISTER_TYPE_INFO *input_types, UINT32 output_count,
416 const MFT_REGISTER_TYPE_INFO *output_types);
417 static HRESULT (WINAPI *pMFTUnregisterLocal)(IClassFactory *factory);
418 static HRESULT (WINAPI *pMFTUnregisterLocalByCLSID)(CLSID clsid);
419 static HRESULT (WINAPI *pMFAllocateWorkQueueEx)(MFASYNC_WORKQUEUE_TYPE queue_type, DWORD *queue);
420 static HRESULT (WINAPI *pMFTEnumEx)(GUID category, UINT32 flags, const MFT_REGISTER_TYPE_INFO *input_type,
421 const MFT_REGISTER_TYPE_INFO *output_type, IMFActivate ***activate, UINT32 *count);
422 static HRESULT (WINAPI *pMFGetPlaneSize)(DWORD format, DWORD width, DWORD height, DWORD *size);
423 static HRESULT (WINAPI *pMFGetStrideForBitmapInfoHeader)(DWORD format, DWORD width, LONG *stride);
424 static HRESULT (WINAPI *pMFCreate2DMediaBuffer)(DWORD width, DWORD height, DWORD fourcc, BOOL bottom_up,
425 IMFMediaBuffer **buffer);
426 static HRESULT (WINAPI *pMFCreateMediaBufferFromMediaType)(IMFMediaType *media_type, LONGLONG duration, DWORD min_length,
427 DWORD min_alignment, IMFMediaBuffer **buffer);
428 static HRESULT (WINAPI *pMFCreatePathFromURL)(const WCHAR *url, WCHAR **path);
429 static HRESULT (WINAPI *pMFCreateDXSurfaceBuffer)(REFIID riid, IUnknown *surface, BOOL bottom_up, IMFMediaBuffer **buffer);
430 static HRESULT (WINAPI *pMFCreateTrackedSample)(IMFTrackedSample **sample);
431 static DWORD (WINAPI *pMFMapDXGIFormatToDX9Format)(DXGI_FORMAT dxgi_format);
432 static DXGI_FORMAT (WINAPI *pMFMapDX9FormatToDXGIFormat)(DWORD format);
433 static HRESULT (WINAPI *pMFCreateVideoSampleAllocatorEx)(REFIID riid, void **allocator);
434 static HRESULT (WINAPI *pMFCreateDXGISurfaceBuffer)(REFIID riid, IUnknown *surface, UINT subresource, BOOL bottomup,
435 IMFMediaBuffer **buffer);
436 static HRESULT (WINAPI *pMFCreateVideoMediaTypeFromSubtype)(const GUID *subtype, IMFVideoMediaType **media_type);
437 static HRESULT (WINAPI *pMFLockSharedWorkQueue)(const WCHAR *name, LONG base_priority, DWORD *taskid, DWORD *queue);
438 static HRESULT (WINAPI *pMFLockDXGIDeviceManager)(UINT *token, IMFDXGIDeviceManager **manager);
439 static HRESULT (WINAPI *pMFUnlockDXGIDeviceManager)(void);
440 static HRESULT (WINAPI *pMFInitVideoFormat_RGB)(MFVIDEOFORMAT *format, DWORD width, DWORD height, DWORD d3dformat);
442 static HWND create_window(void)
444 RECT r = {0, 0, 640, 480};
446 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
448 return CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
449 0, 0, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
452 static IDirect3DDevice9 *create_d3d9_device(IDirect3D9 *d3d9, HWND focus_window)
454 D3DPRESENT_PARAMETERS present_parameters = {0};
455 IDirect3DDevice9 *device = NULL;
457 present_parameters.BackBufferWidth = 640;
458 present_parameters.BackBufferHeight = 480;
459 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
460 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
461 present_parameters.hDeviceWindow = focus_window;
462 present_parameters.Windowed = TRUE;
463 present_parameters.EnableAutoDepthStencil = TRUE;
464 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
465 present_parameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
467 IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
468 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
470 return device;
473 static const WCHAR fileschemeW[] = L"file://";
475 static WCHAR *load_resource(const WCHAR *name)
477 static WCHAR pathW[MAX_PATH];
478 DWORD written;
479 HANDLE file;
480 HRSRC res;
481 void *ptr;
483 GetTempPathW(ARRAY_SIZE(pathW), pathW);
484 lstrcatW(pathW, name);
486 file = CreateFileW(pathW, GENERIC_READ|GENERIC_WRITE, 0,
487 NULL, CREATE_ALWAYS, 0, 0);
488 ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %ld\n",
489 wine_dbgstr_w(pathW), GetLastError());
491 res = FindResourceW(NULL, name, (LPCWSTR)RT_RCDATA);
492 ok(res != 0, "couldn't find resource\n");
493 ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res));
494 WriteFile(file, ptr, SizeofResource(GetModuleHandleA(NULL), res),
495 &written, NULL);
496 ok(written == SizeofResource(GetModuleHandleA(NULL), res),
497 "couldn't write resource\n" );
498 CloseHandle(file);
500 return pathW;
503 static BOOL is_MEDIASUBTYPE_RGB(const GUID *subtype)
505 return IsEqualGUID(subtype, &MEDIASUBTYPE_RGB8)
506 || IsEqualGUID(subtype, &MEDIASUBTYPE_RGB555)
507 || IsEqualGUID(subtype, &MEDIASUBTYPE_RGB565)
508 || IsEqualGUID(subtype, &MEDIASUBTYPE_RGB24)
509 || IsEqualGUID(subtype, &MEDIASUBTYPE_RGB32);
512 struct test_callback
514 IMFAsyncCallback IMFAsyncCallback_iface;
515 LONG refcount;
516 HANDLE event;
517 DWORD param;
518 IMFMediaEvent *media_event;
519 IMFAsyncResult *result;
522 static struct test_callback *impl_from_IMFAsyncCallback(IMFAsyncCallback *iface)
524 return CONTAINING_RECORD(iface, struct test_callback, IMFAsyncCallback_iface);
527 static HRESULT WINAPI testcallback_QueryInterface(IMFAsyncCallback *iface, REFIID riid, void **obj)
529 if (IsEqualIID(riid, &IID_IMFAsyncCallback) ||
530 IsEqualIID(riid, &IID_IUnknown))
532 *obj = iface;
533 IMFAsyncCallback_AddRef(iface);
534 return S_OK;
537 *obj = NULL;
538 return E_NOINTERFACE;
541 static ULONG WINAPI testcallback_AddRef(IMFAsyncCallback *iface)
543 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
544 return InterlockedIncrement(&callback->refcount);
547 static ULONG WINAPI testcallback_Release(IMFAsyncCallback *iface)
549 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
550 ULONG refcount = InterlockedDecrement(&callback->refcount);
552 if (!refcount)
554 CloseHandle(callback->event);
555 free(callback);
558 return refcount;
561 static HRESULT WINAPI testcallback_GetParameters(IMFAsyncCallback *iface, DWORD *flags, DWORD *queue)
563 ok(flags != NULL && queue != NULL, "Unexpected arguments.\n");
564 return E_NOTIMPL;
567 static HRESULT WINAPI test_async_callback_result_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
569 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
571 callback->result = result;
572 IMFAsyncResult_AddRef(callback->result);
573 SetEvent(callback->event);
575 return S_OK;
578 static const IMFAsyncCallbackVtbl test_async_callback_result_vtbl =
580 testcallback_QueryInterface,
581 testcallback_AddRef,
582 testcallback_Release,
583 testcallback_GetParameters,
584 test_async_callback_result_Invoke,
587 static DWORD wait_async_callback_result(IMFAsyncCallback *iface, DWORD timeout, IMFAsyncResult **result)
589 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
590 DWORD res = WaitForSingleObject(callback->event, timeout);
592 *result = callback->result;
593 callback->result = NULL;
595 return res;
598 static BOOL check_clsid(CLSID *clsids, UINT32 count)
600 int i;
601 for (i = 0; i < count; i++)
603 if (IsEqualGUID(&clsids[i], &DUMMY_CLSID))
604 return TRUE;
606 return FALSE;
609 static void test_register(void)
611 MFT_REGISTER_TYPE_INFO *in_types, *out_types;
612 WCHAR name[] = L"Wine test";
613 MFT_REGISTER_TYPE_INFO input[] =
615 { DUMMY_CLSID, DUMMY_GUID1 }
617 MFT_REGISTER_TYPE_INFO output[] =
619 { DUMMY_CLSID, DUMMY_GUID2 }
621 UINT32 count, in_count, out_count;
622 IMFAttributes *attributes;
623 WCHAR *mft_name;
624 CLSID *clsids;
625 HRESULT hr, ret;
627 ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 1, input, 1, output, NULL);
628 if (ret == E_ACCESSDENIED)
630 win_skip("Not enough permissions to register a transform.\n");
631 return;
633 ok(ret == S_OK, "Failed to register dummy transform, hr %#lx.\n", ret);
635 if(0)
637 /* NULL name crashes on windows */
638 ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, NULL, 0, 1, input, 1, output, NULL);
639 ok(ret == E_INVALIDARG, "Unexpected hr %#lx.\n", ret);
642 ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 0, NULL, 0, NULL, NULL);
643 ok(ret == S_OK, "Failed to register dummy filter: %lx\n", ret);
645 ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 1, NULL, 0, NULL, NULL);
646 ok(ret == S_OK, "Failed to register dummy filter: %lx\n", ret);
648 ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 0, NULL, 1, NULL, NULL);
649 ok(ret == S_OK, "Failed to register dummy filter: %lx\n", ret);
651 if(0)
653 /* NULL clsids/count crashes on windows (vista) */
654 count = 0;
655 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, NULL, NULL, NULL, &count);
656 ok(ret == E_POINTER, "Failed to enumerate filters: %lx\n", ret);
657 ok(count == 0, "Expected count == 0\n");
659 clsids = NULL;
660 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, NULL, NULL, &clsids, NULL);
661 ok(ret == E_POINTER, "Failed to enumerate filters: %lx\n", ret);
663 hr = MFTGetInfo(DUMMY_CLSID, &mft_name, NULL, NULL, NULL, NULL, NULL);
664 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
665 ok(!lstrcmpW(mft_name, L"Wine test"), "Unexpected name %s.\n", wine_dbgstr_w(mft_name));
666 CoTaskMemFree(mft_name);
668 hr = MFTGetInfo(DUMMY_CLSID, NULL, NULL, NULL, NULL, NULL, NULL);
669 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
671 in_count = out_count = 1;
672 hr = MFTGetInfo(DUMMY_CLSID, NULL, NULL, &in_count, NULL, &out_count, NULL);
673 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
674 ok(!in_count, "Unexpected count %u.\n", in_count);
675 ok(!out_count, "Unexpected count %u.\n", out_count);
677 hr = MFTGetInfo(DUMMY_CLSID, NULL, NULL, NULL, NULL, NULL, &attributes);
678 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
679 ok(!!attributes, "Unexpected attributes.\n");
680 IMFAttributes_Release(attributes);
682 hr = MFTGetInfo(DUMMY_CLSID, &mft_name, &in_types, &in_count, &out_types, &out_count, &attributes);
683 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
684 ok(!lstrcmpW(mft_name, L"Wine test"), "Unexpected name %s.\n", wine_dbgstr_w(mft_name));
685 ok(!!in_types, "Unexpected pointer.\n");
686 ok(!!out_types, "Unexpected pointer.\n");
687 ok(in_count == 1, "Unexpected count %u.\n", in_count);
688 ok(out_count == 1, "Unexpected count %u.\n", out_count);
689 ok(IsEqualGUID(&in_types->guidMajorType, &DUMMY_CLSID), "Unexpected type guid %s.\n",
690 wine_dbgstr_guid(&in_types->guidMajorType));
691 ok(IsEqualGUID(&in_types->guidSubtype, &DUMMY_GUID1), "Unexpected type guid %s.\n",
692 wine_dbgstr_guid(&in_types->guidSubtype));
693 ok(IsEqualGUID(&out_types->guidMajorType, &DUMMY_CLSID), "Unexpected type guid %s.\n",
694 wine_dbgstr_guid(&out_types->guidMajorType));
695 ok(IsEqualGUID(&out_types->guidSubtype, &DUMMY_GUID2), "Unexpected type guid %s.\n",
696 wine_dbgstr_guid(&out_types->guidSubtype));
697 ok(!!attributes, "Unexpected attributes.\n");
698 count = 1;
699 hr = IMFAttributes_GetCount(attributes, &count);
700 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
701 ok(!count, "Unexpected count %u.\n", count);
702 CoTaskMemFree(mft_name);
703 CoTaskMemFree(in_types);
704 CoTaskMemFree(out_types);
705 IMFAttributes_Release(attributes);
707 count = 0;
708 clsids = NULL;
709 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, NULL, NULL, &clsids, &count);
710 ok(ret == S_OK, "Failed to enumerate filters: %lx\n", ret);
711 ok(count > 0, "Expected count > 0\n");
712 ok(clsids != NULL, "Expected clsids != NULL\n");
713 ok(check_clsid(clsids, count), "Filter was not part of enumeration\n");
714 CoTaskMemFree(clsids);
716 count = 0;
717 clsids = NULL;
718 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, input, NULL, NULL, &clsids, &count);
719 ok(ret == S_OK, "Failed to enumerate filters: %lx\n", ret);
720 ok(count > 0, "Expected count > 0\n");
721 ok(clsids != NULL, "Expected clsids != NULL\n");
722 ok(check_clsid(clsids, count), "Filter was not part of enumeration\n");
723 CoTaskMemFree(clsids);
725 count = 0;
726 clsids = NULL;
727 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, output, NULL, &clsids, &count);
728 ok(ret == S_OK, "Failed to enumerate filters: %lx\n", ret);
729 ok(count > 0, "Expected count > 0\n");
730 ok(clsids != NULL, "Expected clsids != NULL\n");
731 ok(check_clsid(clsids, count), "Filter was not part of enumeration\n");
732 CoTaskMemFree(clsids);
734 count = 0;
735 clsids = NULL;
736 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, input, output, NULL, &clsids, &count);
737 ok(ret == S_OK, "Failed to enumerate filters: %lx\n", ret);
738 ok(count > 0, "Expected count > 0\n");
739 ok(clsids != NULL, "Expected clsids != NULL\n");
740 ok(check_clsid(clsids, count), "Filter was not part of enumeration\n");
741 CoTaskMemFree(clsids);
743 /* exchange input and output */
744 count = 0;
745 clsids = NULL;
746 ret = MFTEnum(MFT_CATEGORY_OTHER, 0, output, input, NULL, &clsids, &count);
747 ok(ret == S_OK, "Failed to enumerate filters: %lx\n", ret);
748 ok(!count, "got %d\n", count);
749 ok(clsids == NULL, "Expected clsids == NULL\n");
751 ret = MFTUnregister(DUMMY_CLSID);
752 ok(ret == S_OK ||
753 /* w7pro64 */
754 broken(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)), "Unexpected hr %#lx.\n", ret);
756 ret = MFTUnregister(DUMMY_CLSID);
757 ok(ret == S_OK || broken(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)), "Unexpected hr %#lx.\n", ret);
760 static HRESULT WINAPI test_create_from_url_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
762 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
763 IMFSourceResolver *resolver;
764 IUnknown *object, *object2;
765 MF_OBJECT_TYPE obj_type;
766 HRESULT hr;
768 ok(!!result, "Unexpected result object.\n");
770 resolver = (IMFSourceResolver *)IMFAsyncResult_GetStateNoAddRef(result);
772 object = NULL;
773 hr = IMFSourceResolver_EndCreateObjectFromURL(resolver, result, &obj_type, &object);
774 ok(hr == S_OK, "Failed to create an object, hr %#lx.\n", hr);
776 hr = IMFAsyncResult_GetObject(result, &object2);
777 ok(hr == S_OK, "Failed to get result object, hr %#lx.\n", hr);
778 ok(object2 == object, "Unexpected object.\n");
780 if (object)
781 IUnknown_Release(object);
782 IUnknown_Release(object2);
784 SetEvent(callback->event);
786 return S_OK;
789 static const IMFAsyncCallbackVtbl test_create_from_url_callback_vtbl =
791 testcallback_QueryInterface,
792 testcallback_AddRef,
793 testcallback_Release,
794 testcallback_GetParameters,
795 test_create_from_url_callback_Invoke,
798 static HRESULT WINAPI test_create_from_file_handler_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
800 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
801 IMFSchemeHandler *handler;
802 IUnknown *object, *object2;
803 MF_OBJECT_TYPE obj_type;
804 HRESULT hr;
806 ok(!!result, "Unexpected result object.\n");
808 handler = (IMFSchemeHandler *)IMFAsyncResult_GetStateNoAddRef(result);
810 hr = IMFSchemeHandler_EndCreateObject(handler, result, &obj_type, &object);
811 ok(hr == S_OK, "Failed to create an object, hr %#lx.\n", hr);
812 todo_wine ok(obj_type == MF_OBJECT_BYTESTREAM, "Got object type %#x.\n", obj_type);
814 hr = IMFAsyncResult_GetObject(result, (IUnknown **)&object2);
815 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
817 if (obj_type == MF_OBJECT_MEDIASOURCE)
819 IMFMediaSource *media_source;
821 hr = IUnknown_QueryInterface(object, &IID_IMFMediaSource, (void **)&media_source);
822 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
824 hr = IMFMediaSource_Shutdown(media_source);
825 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
826 IMFMediaSource_Release(media_source);
829 IUnknown_Release(object);
831 SetEvent(callback->event);
833 return S_OK;
836 static const IMFAsyncCallbackVtbl test_create_from_file_handler_callback_vtbl =
838 testcallback_QueryInterface,
839 testcallback_AddRef,
840 testcallback_Release,
841 testcallback_GetParameters,
842 test_create_from_file_handler_callback_Invoke,
845 static HRESULT WINAPI source_events_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
847 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
848 IMFMediaEventGenerator *generator;
849 HRESULT hr;
851 ok(!!result, "Unexpected result object.\n");
853 generator = (IMFMediaEventGenerator *)IMFAsyncResult_GetStateNoAddRef(result);
855 hr = IMFMediaEventGenerator_EndGetEvent(generator, result, &callback->media_event);
856 ok(hr == S_OK, "Failed to create an object, hr %#lx.\n", hr);
858 SetEvent(callback->event);
860 return S_OK;
863 static const IMFAsyncCallbackVtbl events_callback_vtbl =
865 testcallback_QueryInterface,
866 testcallback_AddRef,
867 testcallback_Release,
868 testcallback_GetParameters,
869 source_events_callback_Invoke,
872 static const IMFAsyncCallbackVtbl testcallbackvtbl;
874 static struct test_callback * create_test_callback(const IMFAsyncCallbackVtbl *vtbl)
876 struct test_callback *callback = calloc(1, sizeof(*callback));
878 callback->IMFAsyncCallback_iface.lpVtbl = vtbl ? vtbl : &testcallbackvtbl;
879 callback->refcount = 1;
880 callback->event = CreateEventA(NULL, FALSE, FALSE, NULL);
882 return callback;
885 static BOOL get_event(IMFMediaEventGenerator *generator, MediaEventType expected_event_type, PROPVARIANT *value)
887 struct test_callback *callback;
888 MediaEventType event_type;
889 BOOL ret = FALSE;
890 HRESULT hr;
892 callback = create_test_callback(&events_callback_vtbl);
894 for (;;)
896 hr = IMFMediaEventGenerator_BeginGetEvent(generator, &callback->IMFAsyncCallback_iface,
897 (IUnknown *)generator);
898 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
900 if (WaitForSingleObject(callback->event, 1000) == WAIT_TIMEOUT)
902 ok(0, "timeout\n");
903 break;
906 Sleep(10);
908 hr = IMFMediaEvent_GetType(callback->media_event, &event_type);
909 ok(hr == S_OK, "Failed to event type, hr %#lx.\n", hr);
911 if ((ret = (event_type == expected_event_type)))
913 if (value)
915 hr = IMFMediaEvent_GetValue(callback->media_event, value);
916 ok(hr == S_OK, "Failed to get value of event, hr %#lx.\n", hr);
919 break;
923 if (callback->media_event)
924 IMFMediaEvent_Release(callback->media_event);
925 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
927 return ret;
930 static const IMFByteStreamVtbl *bytestream_vtbl_orig;
932 static int bytestream_closed = 0;
933 static HRESULT WINAPI bytestream_wrapper_Close(IMFByteStream *iface)
935 bytestream_closed = 1;
936 return bytestream_vtbl_orig->Close(iface);
939 static void test_source_resolver(void)
941 struct test_callback *callback, *callback2;
942 IMFByteStreamVtbl bytestream_vtbl_wrapper;
943 IMFSourceResolver *resolver, *resolver2;
944 IMFPresentationDescriptor *descriptor;
945 IMFSchemeHandler *scheme_handler;
946 IMFMediaStream *video_stream;
947 IMFAttributes *attributes;
948 IMFMediaSource *mediasource;
949 IMFMediaTypeHandler *handler;
950 IMFMediaType *media_type;
951 BOOL selected, do_uninit;
952 MF_OBJECT_TYPE obj_type;
953 IMFStreamDescriptor *sd;
954 IUnknown *cancel_cookie;
955 IMFByteStream *stream;
956 IMFGetService *get_service;
957 IMFRateSupport *rate_support;
958 WCHAR pathW[MAX_PATH];
959 int i, sample_count;
960 WCHAR *filename;
961 PROPVARIANT var;
962 HRESULT hr;
963 GUID guid;
964 float rate;
965 UINT32 rotation;
967 if (!pMFCreateSourceResolver)
969 win_skip("MFCreateSourceResolver() not found\n");
970 return;
973 callback = create_test_callback(&test_create_from_url_callback_vtbl);
974 callback2 = create_test_callback(&test_create_from_file_handler_callback_vtbl);
976 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
977 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
979 hr = pMFCreateSourceResolver(NULL);
980 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
982 hr = pMFCreateSourceResolver(&resolver);
983 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
985 hr = pMFCreateSourceResolver(&resolver2);
986 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
987 ok(resolver != resolver2, "Expected new instance\n");
989 IMFSourceResolver_Release(resolver2);
991 filename = load_resource(L"test.mp4");
993 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &stream);
994 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
996 hr = IMFSourceResolver_CreateObjectFromByteStream(
997 resolver, NULL, NULL, MF_RESOLUTION_MEDIASOURCE, NULL,
998 &obj_type, (IUnknown **)&mediasource);
999 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1001 hr = IMFSourceResolver_CreateObjectFromByteStream(resolver, stream, NULL, MF_RESOLUTION_MEDIASOURCE, NULL,
1002 NULL, (IUnknown **)&mediasource);
1003 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1005 hr = IMFSourceResolver_CreateObjectFromByteStream(resolver, stream, NULL, MF_RESOLUTION_MEDIASOURCE, NULL,
1006 &obj_type, NULL);
1007 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
1009 IMFByteStream_Release(stream);
1011 /* Create from URL. */
1013 hr = IMFSourceResolver_CreateObjectFromURL(resolver, L"nonexisting.mp4", MF_RESOLUTION_BYTESTREAM, NULL, &obj_type,
1014 (IUnknown **)&stream);
1015 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Unexpected hr %#lx.\n", hr);
1017 hr = IMFSourceResolver_CreateObjectFromURL(resolver, filename, MF_RESOLUTION_BYTESTREAM, NULL, &obj_type,
1018 (IUnknown **)&stream);
1019 ok(hr == S_OK, "Failed to resolve url, hr %#lx.\n", hr);
1020 IMFByteStream_Release(stream);
1022 hr = IMFSourceResolver_BeginCreateObjectFromURL(resolver, filename, MF_RESOLUTION_BYTESTREAM, NULL,
1023 &cancel_cookie, &callback->IMFAsyncCallback_iface, (IUnknown *)resolver);
1024 ok(hr == S_OK, "Create request failed, hr %#lx.\n", hr);
1025 ok(cancel_cookie != NULL, "Unexpected cancel object.\n");
1026 IUnknown_Release(cancel_cookie);
1028 if (SUCCEEDED(hr))
1029 WaitForSingleObject(callback->event, INFINITE);
1031 /* With explicit scheme. */
1032 lstrcpyW(pathW, fileschemeW);
1033 lstrcatW(pathW, filename);
1035 hr = IMFSourceResolver_CreateObjectFromURL(resolver, pathW, MF_RESOLUTION_BYTESTREAM, NULL, &obj_type,
1036 (IUnknown **)&stream);
1037 ok(hr == S_OK, "Failed to resolve url, hr %#lx.\n", hr);
1038 IMFByteStream_Release(stream);
1040 /* We have to create a new bytestream here, because all following
1041 * calls to CreateObjectFromByteStream will fail. */
1042 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &stream);
1043 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1045 /* Wrap ::Close to test when the media source calls it */
1046 bytestream_vtbl_orig = stream->lpVtbl;
1047 bytestream_vtbl_wrapper = *bytestream_vtbl_orig;
1048 bytestream_vtbl_wrapper.Close = bytestream_wrapper_Close;
1049 stream->lpVtbl = &bytestream_vtbl_wrapper;
1051 hr = IMFByteStream_QueryInterface(stream, &IID_IMFAttributes, (void **)&attributes);
1052 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1053 hr = IMFAttributes_SetString(attributes, &MF_BYTESTREAM_CONTENT_TYPE, L"video/mp4");
1054 ok(hr == S_OK, "Failed to set string value, hr %#lx.\n", hr);
1055 IMFAttributes_Release(attributes);
1057 /* Start of gstreamer dependent tests */
1059 hr = IMFSourceResolver_CreateObjectFromByteStream(resolver, stream, NULL, MF_RESOLUTION_MEDIASOURCE, NULL,
1060 &obj_type, (IUnknown **)&mediasource);
1061 if (strcmp(winetest_platform, "wine"))
1062 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1063 if (FAILED(hr))
1065 IMFByteStream_Release(stream);
1066 IMFSourceResolver_Release(resolver);
1068 hr = MFShutdown();
1069 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
1071 DeleteFileW(filename);
1072 return;
1074 ok(mediasource != NULL, "got %p\n", mediasource);
1075 ok(obj_type == MF_OBJECT_MEDIASOURCE, "got %d\n", obj_type);
1077 check_interface(mediasource, &IID_IMFGetService, TRUE);
1078 check_service_interface(mediasource, &MF_RATE_CONTROL_SERVICE, &IID_IMFRateSupport, TRUE);
1080 hr = IMFMediaSource_QueryInterface(mediasource, &IID_IMFGetService, (void**)&get_service);
1081 ok(hr == S_OK, "Failed to get service interface, hr %#lx.\n", hr);
1083 hr = IMFGetService_GetService(get_service, &MF_RATE_CONTROL_SERVICE, &IID_IMFRateSupport, (void**)&rate_support);
1084 ok(hr == S_OK, "Failed to get rate support interface, hr %#lx.\n", hr);
1086 hr = IMFRateSupport_GetFastestRate(rate_support, MFRATE_FORWARD, FALSE, &rate);
1087 ok(hr == S_OK, "Failed to query fastest rate, hr %#lx.\n", hr);
1088 ok(rate == 1e6f, "Unexpected fastest rate %f.\n", rate);
1089 hr = IMFRateSupport_GetFastestRate(rate_support, MFRATE_FORWARD, TRUE, &rate);
1090 ok(hr == S_OK, "Failed to query fastest rate, hr %#lx.\n", hr);
1091 ok(rate == 1e6f, "Unexpected fastest rate %f.\n", rate);
1092 hr = IMFRateSupport_GetFastestRate(rate_support, MFRATE_REVERSE, FALSE, &rate);
1093 ok(hr == S_OK, "Failed to query fastest rate, hr %#lx.\n", hr);
1094 ok(rate == -1e6f, "Unexpected fastest rate %f.\n", rate);
1095 hr = IMFRateSupport_GetFastestRate(rate_support, MFRATE_REVERSE, TRUE, &rate);
1096 ok(hr == S_OK, "Failed to query fastest rate, hr %#lx.\n", hr);
1097 ok(rate == -1e6f, "Unexpected fastest rate %f.\n", rate);
1099 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_FORWARD, FALSE, &rate);
1100 ok(hr == S_OK, "Failed to query slowest rate, hr %#lx.\n", hr);
1101 ok(rate == 0.0f, "Unexpected slowest rate %f.\n", rate);
1102 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_FORWARD, TRUE, &rate);
1103 ok(hr == S_OK, "Failed to query slowest rate, hr %#lx.\n", hr);
1104 ok(rate == 0.0f, "Unexpected slowest rate %f.\n", rate);
1105 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_REVERSE, FALSE, &rate);
1106 ok(hr == S_OK, "Failed to query slowest rate, hr %#lx.\n", hr);
1107 ok(rate == 0.0f, "Unexpected slowest rate %f.\n", rate);
1108 hr = IMFRateSupport_GetSlowestRate(rate_support, MFRATE_REVERSE, TRUE, &rate);
1109 ok(hr == S_OK, "Failed to query slowest rate, hr %#lx.\n", hr);
1110 ok(rate == 0.0f, "Unexpected slowest rate %f.\n", rate);
1112 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, 0.0f, NULL);
1113 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1114 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, 0.0f, &rate);
1115 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1116 ok(rate == 0.0f, "Unexpected rate %f.\n", rate);
1118 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, 1.0f, &rate);
1119 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1120 ok(rate == 1.0f, "Unexpected rate %f.\n", rate);
1121 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, -1.0f, &rate);
1122 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1123 ok(rate == -1.0f, "Unexpected rate %f.\n", rate);
1124 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, 1e6f + 1.0f, &rate);
1125 ok(hr == MF_E_UNSUPPORTED_RATE, "Unexpected hr %#lx.\n", hr);
1126 ok(rate == 1e6f + 1.0f || broken(rate == 1e6f) /* Win7 */, "Unexpected %f.\n", rate);
1127 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, -1e6f, &rate);
1128 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1129 ok(rate == -1e6f, "Unexpected rate %f.\n", rate);
1131 hr = IMFRateSupport_IsRateSupported(rate_support, FALSE, -1e6f - 1.0f, &rate);
1132 ok(hr == MF_E_UNSUPPORTED_RATE, "Unexpected hr %#lx.\n", hr);
1133 ok(rate == -1e6f - 1.0f || broken(rate == -1e6f) /* Win7 */, "Unexpected rate %f.\n", rate);
1135 check_service_interface(mediasource, &MF_RATE_CONTROL_SERVICE, &IID_IMFRateControl, TRUE);
1136 hr = IMFMediaSource_CreatePresentationDescriptor(mediasource, &descriptor);
1137 ok(hr == S_OK, "Failed to get presentation descriptor, hr %#lx.\n", hr);
1138 ok(descriptor != NULL, "got %p\n", descriptor);
1140 hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(descriptor, 0, &selected, &sd);
1141 ok(hr == S_OK, "Failed to get stream descriptor, hr %#lx.\n", hr);
1143 hr = IMFStreamDescriptor_GetMediaTypeHandler(sd, &handler);
1144 ok(hr == S_OK, "Failed to get type handler, hr %#lx.\n", hr);
1145 IMFStreamDescriptor_Release(sd);
1147 hr = IMFMediaTypeHandler_GetMajorType(handler, &guid);
1148 ok(hr == S_OK, "Failed to get stream major type, hr %#lx.\n", hr);
1150 /* Check major/minor type for the test media. */
1151 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected major type %s.\n", debugstr_guid(&guid));
1153 hr = IMFMediaTypeHandler_GetCurrentMediaType(handler, &media_type);
1154 ok(hr == S_OK, "Failed to get current media type, hr %#lx.\n", hr);
1155 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
1156 ok(hr == S_OK, "Failed to get media sub type, hr %#lx.\n", hr);
1157 todo_wine
1158 ok(IsEqualGUID(&guid, &MFVideoFormat_M4S2), "Unexpected sub type %s.\n", debugstr_guid(&guid));
1160 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_ROTATION, &rotation);
1161 ok(hr == S_OK || broken(hr == MF_E_ATTRIBUTENOTFOUND) /* Win7 */, "Failed to get rotation, hr %#lx.\n", hr);
1162 if (hr == S_OK)
1163 ok(rotation == MFVideoRotationFormat_0, "Got wrong rotation %u.\n", rotation);
1165 IMFMediaType_Release(media_type);
1167 hr = IMFPresentationDescriptor_SelectStream(descriptor, 0);
1168 ok(hr == S_OK, "Failed to select video stream, hr %#lx.\n", hr);
1170 var.vt = VT_EMPTY;
1171 hr = IMFMediaSource_Start(mediasource, descriptor, &GUID_NULL, &var);
1172 ok(hr == S_OK, "Failed to start media source, hr %#lx.\n", hr);
1174 video_stream = NULL;
1175 if (get_event((IMFMediaEventGenerator *)mediasource, MENewStream, &var))
1177 ok(var.vt == VT_UNKNOWN, "Unexpected value type.\n");
1178 video_stream = (IMFMediaStream *)var.punkVal;
1181 hr = IMFMediaSource_Pause(mediasource);
1182 ok(hr == S_OK, "Failed to pause media source, hr %#lx.\n", hr);
1183 if (get_event((IMFMediaEventGenerator *)mediasource, MESourcePaused, &var))
1184 ok(var.vt == VT_EMPTY, "Unexpected value type.\n");
1186 var.vt = VT_EMPTY;
1187 hr = IMFMediaSource_Start(mediasource, descriptor, &GUID_NULL, &var);
1188 ok(hr == S_OK, "Failed to start media source, hr %#lx.\n", hr);
1190 if (get_event((IMFMediaEventGenerator *)mediasource, MESourceStarted, &var))
1191 ok(var.vt == VT_EMPTY, "Unexpected value type.\n");
1193 hr = IMFMediaSource_Pause(mediasource);
1194 ok(hr == S_OK, "Failed to pause media source, hr %#lx.\n", hr);
1195 if (get_event((IMFMediaEventGenerator *)mediasource, MESourcePaused, &var))
1196 ok(var.vt == VT_EMPTY, "Unexpected value type.\n");
1198 var.vt = VT_I8;
1199 var.uhVal.QuadPart = 0;
1200 hr = IMFMediaSource_Start(mediasource, descriptor, &GUID_NULL, &var);
1201 ok(hr == S_OK, "Failed to start media source, hr %#lx.\n", hr);
1203 if (get_event((IMFMediaEventGenerator *)mediasource, MESourceSeeked, &var))
1204 ok(var.vt == VT_I8, "Unexpected value type.\n");
1206 hr = IMFMediaSource_Stop(mediasource);
1207 ok(hr == S_OK, "Failed to pause media source, hr %#lx.\n", hr);
1208 if (get_event((IMFMediaEventGenerator *)mediasource, MESourceStopped, &var))
1209 ok(var.vt == VT_EMPTY, "Unexpected value type.\n");
1211 var.vt = VT_I8;
1212 var.uhVal.QuadPart = 0;
1213 hr = IMFMediaSource_Start(mediasource, descriptor, &GUID_NULL, &var);
1214 ok(hr == S_OK, "Failed to start media source, hr %#lx.\n", hr);
1216 if (get_event((IMFMediaEventGenerator *)mediasource, MESourceStarted, &var))
1217 ok(var.vt == VT_I8, "Unexpected value type.\n");
1219 sample_count = 10;
1221 for (i = 0; i < sample_count; ++i)
1223 hr = IMFMediaStream_RequestSample(video_stream, NULL);
1224 ok(hr == S_OK, "Failed to request sample %u, hr %#lx.\n", i + 1, hr);
1225 if (hr != S_OK)
1226 break;
1229 for (i = 0; i < sample_count; ++i)
1231 static const LONGLONG MILLI_TO_100_NANO = 10000;
1232 LONGLONG duration, time;
1233 DWORD buffer_count;
1234 IMFSample *sample;
1235 BOOL ret;
1237 ret = get_event((IMFMediaEventGenerator *)video_stream, MEMediaSample, &var);
1238 ok(ret, "Sample %u not received.\n", i + 1);
1239 if (!ret)
1240 break;
1242 ok(var.vt == VT_UNKNOWN, "Unexpected value type %u from MEMediaSample event.\n", var.vt);
1243 sample = (IMFSample *)var.punkVal;
1245 hr = IMFSample_GetBufferCount(sample, &buffer_count);
1246 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
1247 ok(buffer_count == 1, "Unexpected buffer count %lu.\n", buffer_count);
1249 hr = IMFSample_GetSampleDuration(sample, &duration);
1250 ok(hr == S_OK, "Failed to get sample duration, hr %#lx.\n", hr);
1251 ok(duration == 40 * MILLI_TO_100_NANO, "Unexpected duration %s.\n", wine_dbgstr_longlong(duration));
1253 hr = IMFSample_GetSampleTime(sample, &time);
1254 ok(hr == S_OK, "Failed to get sample time, hr %#lx.\n", hr);
1255 ok(time == i * 40 * MILLI_TO_100_NANO, "Unexpected time %s.\n", wine_dbgstr_longlong(time));
1257 IMFSample_Release(sample);
1260 if (i == sample_count)
1262 IMFMediaEvent *event;
1264 /* MEEndOfStream isn't queued until after a one request beyond the last frame is submitted */
1265 Sleep(100);
1266 hr = IMFMediaEventGenerator_GetEvent((IMFMediaEventGenerator *)video_stream, MF_EVENT_FLAG_NO_WAIT, &event);
1267 ok (hr == MF_E_NO_EVENTS_AVAILABLE, "Unexpected hr %#lx.\n", hr);
1269 hr = IMFMediaStream_RequestSample(video_stream, NULL);
1270 ok (hr == S_OK || hr == MF_E_END_OF_STREAM, "Unexpected hr %#lx.\n", hr);
1271 get_event((IMFMediaEventGenerator *)video_stream, MEEndOfStream, NULL);
1275 hr = IMFMediaStream_RequestSample(video_stream, NULL);
1276 ok(hr == MF_E_END_OF_STREAM, "Unexpected hr %#lx.\n", hr);
1278 get_event((IMFMediaEventGenerator *)mediasource, MEEndOfPresentation, NULL);
1280 IMFMediaStream_Release(video_stream);
1281 IMFMediaTypeHandler_Release(handler);
1282 IMFPresentationDescriptor_Release(descriptor);
1284 ok(!bytestream_closed, "IMFByteStream::Close called unexpectedly\n");
1286 hr = IMFMediaSource_Shutdown(mediasource);
1287 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1289 ok(bytestream_closed, "Missing IMFByteStream::Close call\n");
1291 hr = IMFMediaSource_CreatePresentationDescriptor(mediasource, NULL);
1292 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
1294 IMFRateSupport_Release(rate_support);
1295 IMFGetService_Release(get_service);
1296 IMFMediaSource_Release(mediasource);
1297 IMFByteStream_Release(stream);
1299 /* Create directly through scheme handler. */
1300 hr = CoInitialize(NULL);
1301 ok(SUCCEEDED(hr), "Failed to initialize, hr %#lx.\n", hr);
1302 do_uninit = hr == S_OK;
1304 hr = CoCreateInstance(&CLSID_FileSchemePlugin, NULL, CLSCTX_INPROC_SERVER, &IID_IMFSchemeHandler,
1305 (void **)&scheme_handler);
1306 ok(hr == S_OK, "Failed to create handler object, hr %#lx.\n", hr);
1308 cancel_cookie = NULL;
1309 hr = IMFSchemeHandler_BeginCreateObject(scheme_handler, pathW, MF_RESOLUTION_MEDIASOURCE, NULL, &cancel_cookie,
1310 &callback2->IMFAsyncCallback_iface, (IUnknown *)scheme_handler);
1311 ok(hr == S_OK, "Create request failed, hr %#lx.\n", hr);
1312 ok(!!cancel_cookie, "Unexpected cancel object.\n");
1313 IUnknown_Release(cancel_cookie);
1315 WaitForSingleObject(callback2->event, INFINITE);
1317 IMFSchemeHandler_Release(scheme_handler);
1319 if (do_uninit)
1320 CoUninitialize();
1322 IMFSourceResolver_Release(resolver);
1324 hr = MFShutdown();
1325 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
1327 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
1328 IMFAsyncCallback_Release(&callback2->IMFAsyncCallback_iface);
1330 DeleteFileW(filename);
1333 static void init_functions(void)
1335 HMODULE mod = GetModuleHandleA("mfplat.dll");
1337 #define X(f) p##f = (void*)GetProcAddress(mod, #f)
1338 X(MFAddPeriodicCallback);
1339 X(MFAllocateSerialWorkQueue);
1340 X(MFAllocateWorkQueueEx);
1341 X(MFCopyImage);
1342 X(MFCreate2DMediaBuffer);
1343 X(MFCreateDXGIDeviceManager);
1344 X(MFCreateDXGISurfaceBuffer);
1345 X(MFCreateDXSurfaceBuffer);
1346 X(MFCreateSourceResolver);
1347 X(MFCreateMediaBufferFromMediaType);
1348 X(MFCreateMFByteStreamOnStream);
1349 X(MFCreatePathFromURL);
1350 X(MFCreateTrackedSample);
1351 X(MFCreateTransformActivate);
1352 X(MFCreateVideoMediaTypeFromSubtype);
1353 X(MFCreateVideoSampleAllocatorEx);
1354 X(MFGetPlaneSize);
1355 X(MFGetStrideForBitmapInfoHeader);
1356 X(MFInitVideoFormat_RGB);
1357 X(MFLockDXGIDeviceManager);
1358 X(MFLockSharedWorkQueue);
1359 X(MFMapDX9FormatToDXGIFormat);
1360 X(MFMapDXGIFormatToDX9Format);
1361 X(MFPutWaitingWorkItem);
1362 X(MFRegisterLocalByteStreamHandler);
1363 X(MFRegisterLocalSchemeHandler);
1364 X(MFRemovePeriodicCallback);
1365 X(MFTEnumEx);
1366 X(MFTRegisterLocal);
1367 X(MFTRegisterLocalByCLSID);
1368 X(MFTUnregisterLocal);
1369 X(MFTUnregisterLocalByCLSID);
1370 X(MFUnlockDXGIDeviceManager);
1372 if ((mod = LoadLibraryA("d3d11.dll")))
1374 X(D3D11CreateDevice);
1377 if ((mod = LoadLibraryA("d3d12.dll")))
1379 X(D3D12CreateDevice);
1382 mod = GetModuleHandleA("ole32.dll");
1384 X(CoGetApartmentType);
1385 #undef X
1387 is_win8_plus = pMFPutWaitingWorkItem != NULL;
1390 static void test_media_type(void)
1392 IMFMediaType *mediatype, *mediatype2;
1393 IMFVideoMediaType *video_type;
1394 IUnknown *unk, *unk2;
1395 BOOL compressed;
1396 DWORD flags;
1397 UINT count;
1398 HRESULT hr;
1399 GUID guid;
1401 if(0)
1403 /* Crash on Windows Vista/7 */
1404 hr = MFCreateMediaType(NULL);
1405 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1408 hr = MFCreateMediaType(&mediatype);
1409 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1411 hr = IMFMediaType_GetMajorType(mediatype, &guid);
1412 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
1414 compressed = FALSE;
1415 hr = IMFMediaType_IsCompressedFormat(mediatype, &compressed);
1416 ok(hr == S_OK, "Failed to get media type property, hr %#lx.\n", hr);
1417 ok(compressed, "Unexpected value %d.\n", compressed);
1419 hr = IMFMediaType_SetUINT32(mediatype, &MF_MT_ALL_SAMPLES_INDEPENDENT, 0);
1420 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1422 compressed = FALSE;
1423 hr = IMFMediaType_IsCompressedFormat(mediatype, &compressed);
1424 ok(hr == S_OK, "Failed to get media type property, hr %#lx.\n", hr);
1425 ok(compressed, "Unexpected value %d.\n", compressed);
1427 hr = IMFMediaType_SetUINT32(mediatype, &MF_MT_COMPRESSED, 0);
1428 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1430 compressed = FALSE;
1431 hr = IMFMediaType_IsCompressedFormat(mediatype, &compressed);
1432 ok(hr == S_OK, "Failed to get media type property, hr %#lx.\n", hr);
1433 ok(compressed, "Unexpected value %d.\n", compressed);
1435 hr = IMFMediaType_SetUINT32(mediatype, &MF_MT_ALL_SAMPLES_INDEPENDENT, 1);
1436 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1438 hr = IMFMediaType_SetUINT32(mediatype, &MF_MT_COMPRESSED, 1);
1439 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1441 compressed = TRUE;
1442 hr = IMFMediaType_IsCompressedFormat(mediatype, &compressed);
1443 ok(hr == S_OK, "Failed to get media type property, hr %#lx.\n", hr);
1444 ok(!compressed, "Unexpected value %d.\n", compressed);
1446 hr = IMFMediaType_DeleteItem(mediatype, &MF_MT_COMPRESSED);
1447 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1449 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
1450 ok(hr == S_OK, "Failed to set GUID value, hr %#lx.\n", hr);
1452 hr = IMFMediaType_GetMajorType(mediatype, &guid);
1453 ok(hr == S_OK, "Failed to get major type, hr %#lx.\n", hr);
1454 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected major type.\n");
1456 /* IsEqual() */
1457 hr = MFCreateMediaType(&mediatype2);
1458 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
1460 flags = 0xdeadbeef;
1461 hr = IMFMediaType_IsEqual(mediatype, mediatype2, &flags);
1462 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1463 ok(flags == 0, "Unexpected flags %#lx.\n", flags);
1465 /* Different major types. */
1466 hr = IMFMediaType_SetGUID(mediatype2, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
1467 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
1469 flags = 0;
1470 hr = IMFMediaType_IsEqual(mediatype, mediatype2, &flags);
1471 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
1472 ok(flags == (MF_MEDIATYPE_EQUAL_FORMAT_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA),
1473 "Unexpected flags %#lx.\n", flags);
1475 /* Same major types, different subtypes. */
1476 hr = IMFMediaType_SetGUID(mediatype2, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
1477 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
1479 flags = 0;
1480 hr = IMFMediaType_IsEqual(mediatype, mediatype2, &flags);
1481 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1482 ok(flags == (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_DATA
1483 | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA), "Unexpected flags %#lx.\n", flags);
1485 /* Different user data. */
1486 hr = IMFMediaType_SetBlob(mediatype, &MF_MT_USER_DATA, (const UINT8 *)&flags, sizeof(flags));
1487 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
1489 flags = 0;
1490 hr = IMFMediaType_IsEqual(mediatype, mediatype2, &flags);
1491 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
1492 ok(flags == (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_DATA),
1493 "Unexpected flags %#lx.\n", flags);
1495 hr = IMFMediaType_DeleteItem(mediatype, &MF_MT_USER_DATA);
1496 ok(hr == S_OK, "Failed to delete item, hr %#lx.\n", hr);
1498 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
1499 ok(hr == S_OK, "Failed to set subtype, hr %#lx.\n", hr);
1501 flags = 0;
1502 hr = IMFMediaType_IsEqual(mediatype, mediatype2, &flags);
1503 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
1504 ok(flags == (MF_MEDIATYPE_EQUAL_MAJOR_TYPES | MF_MEDIATYPE_EQUAL_FORMAT_DATA | MF_MEDIATYPE_EQUAL_FORMAT_USER_DATA),
1505 "Unexpected flags %#lx.\n", flags);
1507 IMFMediaType_Release(mediatype2);
1508 IMFMediaType_Release(mediatype);
1510 /* IMFVideoMediaType */
1511 hr = MFCreateMediaType(&mediatype);
1512 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1514 check_interface(mediatype, &IID_IMFVideoMediaType, FALSE);
1516 hr = IMFMediaType_QueryInterface(mediatype, &IID_IUnknown, (void **)&unk);
1517 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1518 ok(unk == (IUnknown *)mediatype, "Unexpected pointer.\n");
1519 IUnknown_Release(unk);
1521 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
1522 ok(hr == S_OK, "Failed to set GUID value, hr %#lx.\n", hr);
1524 hr = IMFMediaType_QueryInterface(mediatype, &IID_IMFVideoMediaType, (void **)&unk);
1525 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1527 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
1528 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1529 ok(unk2 == (IUnknown *)mediatype, "Unexpected pointer.\n");
1530 IUnknown_Release(unk2);
1532 hr = IUnknown_QueryInterface(unk, &IID_IMFAttributes, (void **)&unk2);
1533 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1534 ok(unk2 == (IUnknown *)mediatype, "Unexpected pointer.\n");
1535 IUnknown_Release(unk2);
1537 hr = IUnknown_QueryInterface(unk, &IID_IMFMediaType, (void **)&unk2);
1538 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1539 ok(unk2 == (IUnknown *)mediatype, "Unexpected pointer.\n");
1540 IUnknown_Release(unk2);
1542 IUnknown_Release(unk);
1543 IMFMediaType_Release(mediatype);
1545 if (pMFCreateVideoMediaTypeFromSubtype)
1547 hr = pMFCreateVideoMediaTypeFromSubtype(&MFVideoFormat_RGB555, &video_type);
1548 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1550 check_interface(video_type, &IID_IMFMediaType, TRUE);
1551 check_interface(video_type, &IID_IMFVideoMediaType, TRUE);
1553 /* Major and subtype are set on creation. */
1554 hr = IMFVideoMediaType_GetCount(video_type, &count);
1555 ok(count == 2, "Unexpected attribute count %#lx.\n", hr);
1557 hr = IMFVideoMediaType_DeleteAllItems(video_type);
1558 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1560 hr = IMFVideoMediaType_GetCount(video_type, &count);
1561 ok(!count, "Unexpected attribute count %#lx.\n", hr);
1563 check_interface(video_type, &IID_IMFVideoMediaType, FALSE);
1565 IMFVideoMediaType_Release(video_type);
1567 else
1568 win_skip("MFCreateVideoMediaTypeFromSubtype() is not available.\n");
1570 /* IMFAudioMediaType */
1571 hr = MFCreateMediaType(&mediatype);
1572 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1574 check_interface(mediatype, &IID_IMFAudioMediaType, FALSE);
1576 hr = IMFMediaType_QueryInterface(mediatype, &IID_IUnknown, (void **)&unk);
1577 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1578 ok(unk == (IUnknown *)mediatype, "Unexpected pointer.\n");
1579 IUnknown_Release(unk);
1581 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
1582 ok(hr == S_OK, "Failed to set GUID value, hr %#lx.\n", hr);
1584 hr = IMFMediaType_QueryInterface(mediatype, &IID_IMFAudioMediaType, (void **)&unk);
1585 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1587 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
1588 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1589 ok(unk2 == (IUnknown *)mediatype, "Unexpected pointer.\n");
1590 IUnknown_Release(unk2);
1592 hr = IUnknown_QueryInterface(unk, &IID_IMFAttributes, (void **)&unk2);
1593 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1594 ok(unk2 == (IUnknown *)mediatype, "Unexpected pointer.\n");
1595 IUnknown_Release(unk2);
1597 hr = IUnknown_QueryInterface(unk, &IID_IMFMediaType, (void **)&unk2);
1598 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1599 ok(unk2 == (IUnknown *)mediatype, "Unexpected pointer.\n");
1600 IUnknown_Release(unk2);
1602 IUnknown_Release(unk);
1604 IMFMediaType_Release(mediatype);
1607 static void test_MFCreateMediaEvent(void)
1609 HRESULT hr;
1610 IMFMediaEvent *mediaevent;
1612 MediaEventType type;
1613 GUID extended_type;
1614 HRESULT status;
1615 PROPVARIANT value;
1617 PropVariantInit(&value);
1618 value.vt = VT_UNKNOWN;
1620 hr = MFCreateMediaEvent(MEError, &GUID_NULL, E_FAIL, &value, &mediaevent);
1621 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1623 PropVariantClear(&value);
1625 hr = IMFMediaEvent_GetType(mediaevent, &type);
1626 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1627 ok(type == MEError, "got %#lx\n", type);
1629 hr = IMFMediaEvent_GetExtendedType(mediaevent, &extended_type);
1630 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1631 ok(IsEqualGUID(&extended_type, &GUID_NULL), "got %s\n",
1632 wine_dbgstr_guid(&extended_type));
1634 hr = IMFMediaEvent_GetStatus(mediaevent, &status);
1635 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1636 ok(status == E_FAIL, "Unexpected hr %#lx.\n", status);
1638 PropVariantInit(&value);
1639 hr = IMFMediaEvent_GetValue(mediaevent, &value);
1640 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1641 ok(value.vt == VT_UNKNOWN, "got %#x\n", value.vt);
1642 PropVariantClear(&value);
1644 IMFMediaEvent_Release(mediaevent);
1646 hr = MFCreateMediaEvent(MEUnknown, &DUMMY_GUID1, S_OK, NULL, &mediaevent);
1647 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1649 hr = IMFMediaEvent_GetType(mediaevent, &type);
1650 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1651 ok(type == MEUnknown, "got %#lx\n", type);
1653 hr = IMFMediaEvent_GetExtendedType(mediaevent, &extended_type);
1654 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1655 ok(IsEqualGUID(&extended_type, &DUMMY_GUID1), "got %s\n",
1656 wine_dbgstr_guid(&extended_type));
1658 hr = IMFMediaEvent_GetStatus(mediaevent, &status);
1659 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1660 ok(status == S_OK, "Unexpected hr %#lx.\n", status);
1662 PropVariantInit(&value);
1663 hr = IMFMediaEvent_GetValue(mediaevent, &value);
1664 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1665 ok(value.vt == VT_EMPTY, "got %#x\n", value.vt);
1666 PropVariantClear(&value);
1668 IMFMediaEvent_Release(mediaevent);
1671 #define CHECK_ATTR_COUNT(obj, expected) check_attr_count(obj, expected, __LINE__)
1672 static void check_attr_count(IMFAttributes* obj, UINT32 expected, int line)
1674 UINT32 count = expected + 1;
1675 HRESULT hr = IMFAttributes_GetCount(obj, &count);
1676 ok_(__FILE__, line)(hr == S_OK, "Failed to get attributes count, hr %#lx.\n", hr);
1677 ok_(__FILE__, line)(count == expected, "Unexpected count %u, expected %u.\n", count, expected);
1680 #define CHECK_ATTR_TYPE(obj, key, expected) check_attr_type(obj, key, expected, __LINE__)
1681 static void check_attr_type(IMFAttributes *obj, const GUID *key, MF_ATTRIBUTE_TYPE expected, int line)
1683 MF_ATTRIBUTE_TYPE type;
1684 HRESULT hr;
1686 hr = IMFAttributes_GetItemType(obj, key, &type);
1687 ok_(__FILE__, line)(hr == S_OK, "Failed to get item type, hr %#lx.\n", hr);
1688 ok_(__FILE__, line)(type == expected, "Unexpected item type %d, expected %d.\n", type, expected);
1691 static void test_attributes(void)
1693 static const WCHAR stringW[] = L"Wine";
1694 static const UINT8 blob[] = {0,1,2,3,4,5};
1695 IMFAttributes *attributes, *attributes1;
1696 UINT8 blob_value[256], *blob_buf = NULL;
1697 MF_ATTRIBUTES_MATCH_TYPE match_type;
1698 UINT32 value, string_length, size;
1699 PROPVARIANT propvar, ret_propvar;
1700 MF_ATTRIBUTE_TYPE type;
1701 double double_value;
1702 IUnknown *unk_value;
1703 WCHAR bufferW[256];
1704 UINT64 value64;
1705 WCHAR *string;
1706 BOOL result;
1707 HRESULT hr;
1708 GUID key;
1710 hr = MFCreateAttributes( &attributes, 3 );
1711 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1713 hr = IMFAttributes_GetItemType(attributes, &GUID_NULL, &type);
1714 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
1716 CHECK_ATTR_COUNT(attributes, 0);
1717 hr = IMFAttributes_SetUINT32(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 123);
1718 ok(hr == S_OK, "Failed to set UINT32 value, hr %#lx.\n", hr);
1719 CHECK_ATTR_COUNT(attributes, 1);
1720 CHECK_ATTR_TYPE(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, MF_ATTRIBUTE_UINT32);
1722 value = 0xdeadbeef;
1723 hr = IMFAttributes_GetUINT32(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &value);
1724 ok(hr == S_OK, "Failed to get UINT32 value, hr %#lx.\n", hr);
1725 ok(value == 123, "Unexpected value %u, expected: 123.\n", value);
1727 value64 = 0xdeadbeef;
1728 hr = IMFAttributes_GetUINT64(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &value64);
1729 ok(hr == MF_E_INVALIDTYPE, "Unexpected hr %#lx.\n", hr);
1730 ok(value64 == 0xdeadbeef, "Unexpected value.\n");
1732 hr = IMFAttributes_SetUINT64(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 65536);
1733 ok(hr == S_OK, "Failed to set UINT64 value, hr %#lx.\n", hr);
1734 CHECK_ATTR_COUNT(attributes, 1);
1735 CHECK_ATTR_TYPE(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, MF_ATTRIBUTE_UINT64);
1737 hr = IMFAttributes_GetUINT64(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &value64);
1738 ok(hr == S_OK, "Failed to get UINT64 value, hr %#lx.\n", hr);
1739 ok(value64 == 65536, "Unexpected value.\n");
1741 value = 0xdeadbeef;
1742 hr = IMFAttributes_GetUINT32(attributes, &MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, &value);
1743 ok(hr == MF_E_INVALIDTYPE, "Unexpected hr %#lx.\n", hr);
1744 ok(value == 0xdeadbeef, "Unexpected value.\n");
1746 IMFAttributes_Release(attributes);
1748 hr = MFCreateAttributes(&attributes, 0);
1749 ok(hr == S_OK, "Failed to create attributes object, hr %#lx.\n", hr);
1751 PropVariantInit(&propvar);
1752 propvar.vt = MF_ATTRIBUTE_UINT32;
1753 propvar.ulVal = 123;
1754 hr = IMFAttributes_SetItem(attributes, &DUMMY_GUID1, &propvar);
1755 ok(hr == S_OK, "Failed to set item, hr %#lx.\n", hr);
1756 PropVariantInit(&ret_propvar);
1757 ret_propvar.vt = MF_ATTRIBUTE_UINT32;
1758 ret_propvar.ulVal = 0xdeadbeef;
1759 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID1, &ret_propvar);
1760 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1761 ok(!PropVariantCompareEx(&propvar, &ret_propvar, 0, 0), "Unexpected item value.\n");
1762 PropVariantClear(&ret_propvar);
1763 CHECK_ATTR_COUNT(attributes, 1);
1765 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID1, NULL);
1766 ok(hr == S_OK, "Item check failed, hr %#lx.\n", hr);
1768 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID2, NULL);
1769 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
1771 PropVariantInit(&ret_propvar);
1772 ret_propvar.vt = MF_ATTRIBUTE_STRING;
1773 ret_propvar.pwszVal = NULL;
1774 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID1, &ret_propvar);
1775 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1776 ok(!PropVariantCompareEx(&propvar, &ret_propvar, 0, 0), "Unexpected item value.\n");
1777 PropVariantClear(&ret_propvar);
1779 PropVariantClear(&propvar);
1781 PropVariantInit(&propvar);
1782 propvar.vt = MF_ATTRIBUTE_UINT64;
1783 propvar.uhVal.QuadPart = 65536;
1784 hr = IMFAttributes_SetItem(attributes, &DUMMY_GUID1, &propvar);
1785 ok(hr == S_OK, "Failed to set item, hr %#lx.\n", hr);
1786 PropVariantInit(&ret_propvar);
1787 ret_propvar.vt = MF_ATTRIBUTE_UINT32;
1788 ret_propvar.ulVal = 0xdeadbeef;
1789 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID1, &ret_propvar);
1790 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1791 ok(!PropVariantCompareEx(&propvar, &ret_propvar, 0, 0), "Unexpected item value.\n");
1792 PropVariantClear(&ret_propvar);
1793 PropVariantClear(&propvar);
1794 CHECK_ATTR_COUNT(attributes, 1);
1796 PropVariantInit(&propvar);
1797 propvar.vt = VT_I4;
1798 propvar.lVal = 123;
1799 hr = IMFAttributes_SetItem(attributes, &DUMMY_GUID2, &propvar);
1800 ok(hr == MF_E_INVALIDTYPE, "Failed to set item, hr %#lx.\n", hr);
1801 PropVariantInit(&ret_propvar);
1802 ret_propvar.vt = MF_ATTRIBUTE_UINT32;
1803 ret_propvar.lVal = 0xdeadbeef;
1804 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID2, &ret_propvar);
1805 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1806 PropVariantClear(&propvar);
1807 ok(!PropVariantCompareEx(&propvar, &ret_propvar, 0, 0), "Unexpected item value.\n");
1808 PropVariantClear(&ret_propvar);
1810 PropVariantInit(&propvar);
1811 propvar.vt = MF_ATTRIBUTE_UINT32;
1812 propvar.ulVal = 123;
1813 hr = IMFAttributes_SetItem(attributes, &DUMMY_GUID3, &propvar);
1814 ok(hr == S_OK, "Failed to set item, hr %#lx.\n", hr);
1816 hr = IMFAttributes_DeleteItem(attributes, &DUMMY_GUID2);
1817 ok(hr == S_OK, "Failed to delete item, hr %#lx.\n", hr);
1818 CHECK_ATTR_COUNT(attributes, 2);
1820 hr = IMFAttributes_DeleteItem(attributes, &DUMMY_GUID2);
1821 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
1822 CHECK_ATTR_COUNT(attributes, 2);
1824 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID3, &ret_propvar);
1825 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1826 ok(!PropVariantCompareEx(&propvar, &ret_propvar, 0, 0), "Unexpected item value.\n");
1827 PropVariantClear(&ret_propvar);
1828 PropVariantClear(&propvar);
1830 propvar.vt = MF_ATTRIBUTE_UINT64;
1831 propvar.uhVal.QuadPart = 65536;
1833 hr = IMFAttributes_GetItem(attributes, &DUMMY_GUID1, &ret_propvar);
1834 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1835 ok(!PropVariantCompareEx(&propvar, &ret_propvar, 0, 0), "Unexpected item value.\n");
1836 PropVariantClear(&ret_propvar);
1837 PropVariantClear(&propvar);
1839 /* Item ordering is not consistent across Windows version. */
1840 hr = IMFAttributes_GetItemByIndex(attributes, 0, &key, &ret_propvar);
1841 ok(hr == S_OK, "Failed to get item, hr %#lx.\n", hr);
1842 PropVariantClear(&ret_propvar);
1844 hr = IMFAttributes_GetItemByIndex(attributes, 100, &key, &ret_propvar);
1845 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
1846 PropVariantClear(&ret_propvar);
1848 hr = IMFAttributes_SetDouble(attributes, &GUID_NULL, 22.0);
1849 ok(hr == S_OK, "Failed to set double value, hr %#lx.\n", hr);
1850 CHECK_ATTR_COUNT(attributes, 3);
1851 CHECK_ATTR_TYPE(attributes, &GUID_NULL, MF_ATTRIBUTE_DOUBLE);
1853 double_value = 0xdeadbeef;
1854 hr = IMFAttributes_GetDouble(attributes, &GUID_NULL, &double_value);
1855 ok(hr == S_OK, "Failed to get double value, hr %#lx.\n", hr);
1856 ok(double_value == 22.0, "Unexpected value: %f, expected: 22.0.\n", double_value);
1858 propvar.vt = MF_ATTRIBUTE_UINT64;
1859 propvar.uhVal.QuadPart = 22;
1860 hr = IMFAttributes_CompareItem(attributes, &GUID_NULL, &propvar, &result);
1861 ok(hr == S_OK, "Failed to compare items, hr %#lx.\n", hr);
1862 ok(!result, "Unexpected result.\n");
1864 propvar.vt = MF_ATTRIBUTE_DOUBLE;
1865 propvar.dblVal = 22.0;
1866 hr = IMFAttributes_CompareItem(attributes, &GUID_NULL, &propvar, &result);
1867 ok(hr == S_OK, "Failed to compare items, hr %#lx.\n", hr);
1868 ok(result, "Unexpected result.\n");
1870 hr = IMFAttributes_SetString(attributes, &DUMMY_GUID1, stringW);
1871 ok(hr == S_OK, "Failed to set string attribute, hr %#lx.\n", hr);
1872 CHECK_ATTR_COUNT(attributes, 3);
1873 CHECK_ATTR_TYPE(attributes, &DUMMY_GUID1, MF_ATTRIBUTE_STRING);
1875 hr = IMFAttributes_GetStringLength(attributes, &DUMMY_GUID1, &string_length);
1876 ok(hr == S_OK, "Failed to get string length, hr %#lx.\n", hr);
1877 ok(string_length == lstrlenW(stringW), "Unexpected length %u.\n", string_length);
1879 hr = IMFAttributes_GetAllocatedString(attributes, &DUMMY_GUID1, &string, NULL);
1880 ok(hr == S_OK, "Failed to get allocated string, hr %#lx.\n", hr);
1881 ok(!lstrcmpW(string, stringW), "Unexpected string %s.\n", wine_dbgstr_w(string));
1882 CoTaskMemFree(string);
1884 string_length = 0xdeadbeef;
1885 hr = IMFAttributes_GetAllocatedString(attributes, &DUMMY_GUID1, &string, &string_length);
1886 ok(hr == S_OK, "Failed to get allocated string, hr %#lx.\n", hr);
1887 ok(!lstrcmpW(string, stringW), "Unexpected string %s.\n", wine_dbgstr_w(string));
1888 ok(string_length == lstrlenW(stringW), "Unexpected length %u.\n", string_length);
1889 CoTaskMemFree(string);
1891 string_length = 0xdeadbeef;
1892 hr = IMFAttributes_GetString(attributes, &DUMMY_GUID1, bufferW, ARRAY_SIZE(bufferW), &string_length);
1893 ok(hr == S_OK, "Failed to get string value, hr %#lx.\n", hr);
1894 ok(!lstrcmpW(bufferW, stringW), "Unexpected string %s.\n", wine_dbgstr_w(bufferW));
1895 ok(string_length == lstrlenW(stringW), "Unexpected length %u.\n", string_length);
1896 memset(bufferW, 0, sizeof(bufferW));
1898 hr = IMFAttributes_GetString(attributes, &DUMMY_GUID1, bufferW, ARRAY_SIZE(bufferW), NULL);
1899 ok(hr == S_OK, "Failed to get string value, hr %#lx.\n", hr);
1900 ok(!lstrcmpW(bufferW, stringW), "Unexpected string %s.\n", wine_dbgstr_w(bufferW));
1901 memset(bufferW, 0, sizeof(bufferW));
1903 string_length = 0;
1904 hr = IMFAttributes_GetString(attributes, &DUMMY_GUID1, bufferW, 1, &string_length);
1905 ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Unexpected hr %#lx.\n", hr);
1906 ok(!bufferW[0], "Unexpected string %s.\n", wine_dbgstr_w(bufferW));
1907 ok(string_length, "Unexpected length.\n");
1909 string_length = 0xdeadbeef;
1910 hr = IMFAttributes_GetStringLength(attributes, &GUID_NULL, &string_length);
1911 ok(hr == MF_E_INVALIDTYPE, "Unexpected hr %#lx.\n", hr);
1912 ok(string_length == 0xdeadbeef, "Unexpected length %u.\n", string_length);
1914 /* VT_UNKNOWN */
1915 hr = IMFAttributes_SetUnknown(attributes, &DUMMY_GUID2, (IUnknown *)attributes);
1916 ok(hr == S_OK, "Failed to set value, hr %#lx.\n", hr);
1917 CHECK_ATTR_COUNT(attributes, 4);
1918 CHECK_ATTR_TYPE(attributes, &DUMMY_GUID2, MF_ATTRIBUTE_IUNKNOWN);
1920 hr = IMFAttributes_GetUnknown(attributes, &DUMMY_GUID2, &IID_IUnknown, (void **)&unk_value);
1921 ok(hr == S_OK, "Failed to get value, hr %#lx.\n", hr);
1922 IUnknown_Release(unk_value);
1924 hr = IMFAttributes_GetUnknown(attributes, &DUMMY_GUID2, &IID_IMFAttributes, (void **)&unk_value);
1925 ok(hr == S_OK, "Failed to get value, hr %#lx.\n", hr);
1926 IUnknown_Release(unk_value);
1928 hr = IMFAttributes_GetUnknown(attributes, &DUMMY_GUID2, &IID_IStream, (void **)&unk_value);
1929 ok(hr == E_NOINTERFACE, "Unexpected hr %#lx.\n", hr);
1931 hr = IMFAttributes_SetUnknown(attributes, &DUMMY_CLSID, NULL);
1932 ok(hr == S_OK, "Failed to set value, hr %#lx.\n", hr);
1933 CHECK_ATTR_COUNT(attributes, 5);
1935 unk_value = NULL;
1936 hr = IMFAttributes_GetUnknown(attributes, &DUMMY_CLSID, &IID_IUnknown, (void **)&unk_value);
1937 ok(hr == MF_E_INVALIDTYPE, "Unexpected hr %#lx.\n", hr);
1939 /* CopyAllItems() */
1940 hr = MFCreateAttributes(&attributes1, 0);
1941 ok(hr == S_OK, "Failed to create attributes object, hr %#lx.\n", hr);
1942 hr = IMFAttributes_CopyAllItems(attributes, attributes1);
1943 ok(hr == S_OK, "Failed to copy items, hr %#lx.\n", hr);
1944 CHECK_ATTR_COUNT(attributes, 5);
1945 CHECK_ATTR_COUNT(attributes1, 5);
1947 hr = IMFAttributes_DeleteAllItems(attributes1);
1948 ok(hr == S_OK, "Failed to delete items, hr %#lx.\n", hr);
1949 CHECK_ATTR_COUNT(attributes1, 0);
1951 propvar.vt = MF_ATTRIBUTE_UINT64;
1952 propvar.uhVal.QuadPart = 22;
1953 hr = IMFAttributes_CompareItem(attributes, &GUID_NULL, &propvar, &result);
1954 ok(hr == S_OK, "Failed to compare items, hr %#lx.\n", hr);
1955 ok(!result, "Unexpected result.\n");
1957 hr = IMFAttributes_CopyAllItems(attributes1, attributes);
1958 ok(hr == S_OK, "Failed to copy items, hr %#lx.\n", hr);
1959 CHECK_ATTR_COUNT(attributes, 0);
1961 /* Blob */
1962 hr = IMFAttributes_SetBlob(attributes, &DUMMY_GUID1, blob, sizeof(blob));
1963 ok(hr == S_OK, "Failed to set blob attribute, hr %#lx.\n", hr);
1964 CHECK_ATTR_COUNT(attributes, 1);
1965 CHECK_ATTR_TYPE(attributes, &DUMMY_GUID1, MF_ATTRIBUTE_BLOB);
1966 hr = IMFAttributes_GetBlobSize(attributes, &DUMMY_GUID1, &size);
1967 ok(hr == S_OK, "Failed to get blob size, hr %#lx.\n", hr);
1968 ok(size == sizeof(blob), "Unexpected blob size %u.\n", size);
1970 hr = IMFAttributes_GetBlobSize(attributes, &DUMMY_GUID2, &size);
1971 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
1973 size = 0;
1974 hr = IMFAttributes_GetBlob(attributes, &DUMMY_GUID1, blob_value, sizeof(blob_value), &size);
1975 ok(hr == S_OK, "Failed to get blob, hr %#lx.\n", hr);
1976 ok(size == sizeof(blob), "Unexpected blob size %u.\n", size);
1977 ok(!memcmp(blob_value, blob, size), "Unexpected blob.\n");
1979 hr = IMFAttributes_GetBlob(attributes, &DUMMY_GUID2, blob_value, sizeof(blob_value), &size);
1980 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
1982 memset(blob_value, 0, sizeof(blob_value));
1983 size = 0;
1984 hr = IMFAttributes_GetAllocatedBlob(attributes, &DUMMY_GUID1, &blob_buf, &size);
1985 ok(hr == S_OK, "Failed to get allocated blob, hr %#lx.\n", hr);
1986 ok(size == sizeof(blob), "Unexpected blob size %u.\n", size);
1987 ok(!memcmp(blob_buf, blob, size), "Unexpected blob.\n");
1988 CoTaskMemFree(blob_buf);
1990 hr = IMFAttributes_GetAllocatedBlob(attributes, &DUMMY_GUID1, &blob_buf, NULL);
1991 ok(hr == S_OK, "Failed to get allocated blob, hr %#lx.\n", hr);
1992 ok(!memcmp(blob_buf, blob, size), "Unexpected blob.\n");
1993 CoTaskMemFree(blob_buf);
1995 hr = IMFAttributes_GetAllocatedBlob(attributes, &DUMMY_GUID2, &blob_buf, &size);
1996 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
1998 hr = IMFAttributes_GetBlob(attributes, &DUMMY_GUID1, blob_value, sizeof(blob) - 1, NULL);
1999 ok(hr == E_NOT_SUFFICIENT_BUFFER, "Unexpected hr %#lx.\n", hr);
2001 IMFAttributes_Release(attributes);
2002 IMFAttributes_Release(attributes1);
2004 /* Compare() */
2005 hr = MFCreateAttributes(&attributes, 0);
2006 ok(hr == S_OK, "Failed to create attributes object, hr %#lx.\n", hr);
2007 hr = MFCreateAttributes(&attributes1, 0);
2008 ok(hr == S_OK, "Failed to create attributes object, hr %#lx.\n", hr);
2010 hr = IMFAttributes_Compare(attributes, attributes, MF_ATTRIBUTES_MATCH_SMALLER + 1, &result);
2011 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2013 for (match_type = MF_ATTRIBUTES_MATCH_OUR_ITEMS; match_type <= MF_ATTRIBUTES_MATCH_SMALLER; ++match_type)
2015 result = FALSE;
2016 hr = IMFAttributes_Compare(attributes, attributes, match_type, &result);
2017 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2018 ok(result, "Unexpected result %d.\n", result);
2020 result = FALSE;
2021 hr = IMFAttributes_Compare(attributes, attributes1, match_type, &result);
2022 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2023 ok(result, "Unexpected result %d.\n", result);
2026 hr = IMFAttributes_SetUINT32(attributes, &DUMMY_GUID1, 1);
2027 ok(hr == S_OK, "Failed to set value, hr %#lx.\n", hr);
2029 result = TRUE;
2030 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result);
2031 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2032 ok(!result, "Unexpected result %d.\n", result);
2034 result = TRUE;
2035 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2036 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2037 ok(!result, "Unexpected result %d.\n", result);
2039 result = FALSE;
2040 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2041 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2042 ok(result, "Unexpected result %d.\n", result);
2044 result = FALSE;
2045 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2046 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2047 ok(result, "Unexpected result %d.\n", result);
2049 hr = IMFAttributes_SetUINT32(attributes1, &DUMMY_GUID1, 2);
2050 ok(hr == S_OK, "Failed to set value, hr %#lx.\n", hr);
2052 result = TRUE;
2053 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2054 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2055 ok(!result, "Unexpected result %d.\n", result);
2057 result = TRUE;
2058 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result);
2059 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2060 ok(!result, "Unexpected result %d.\n", result);
2062 result = TRUE;
2063 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_THEIR_ITEMS, &result);
2064 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2065 ok(!result, "Unexpected result %d.\n", result);
2067 result = TRUE;
2068 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2069 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2070 ok(!result, "Unexpected result %d.\n", result);
2072 result = TRUE;
2073 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2074 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2075 ok(!result, "Unexpected result %d.\n", result);
2077 result = TRUE;
2078 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2079 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2080 ok(!result, "Unexpected result %d.\n", result);
2082 result = TRUE;
2083 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result);
2084 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2085 ok(!result, "Unexpected result %d.\n", result);
2087 result = TRUE;
2088 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_THEIR_ITEMS, &result);
2089 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2090 ok(!result, "Unexpected result %d.\n", result);
2092 result = TRUE;
2093 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2094 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2095 ok(!result, "Unexpected result %d.\n", result);
2097 result = TRUE;
2098 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2099 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2100 ok(!result, "Unexpected result %d.\n", result);
2102 hr = IMFAttributes_SetUINT32(attributes1, &DUMMY_GUID1, 1);
2103 ok(hr == S_OK, "Failed to set value, hr %#lx.\n", hr);
2105 result = FALSE;
2106 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2107 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2108 ok(result, "Unexpected result %d.\n", result);
2110 result = FALSE;
2111 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_THEIR_ITEMS, &result);
2112 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2113 ok(result, "Unexpected result %d.\n", result);
2115 result = FALSE;
2116 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2117 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2118 ok(result, "Unexpected result %d.\n", result);
2120 result = FALSE;
2121 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2122 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2123 ok(result, "Unexpected result %d.\n", result);
2125 result = FALSE;
2126 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2127 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2128 ok(result, "Unexpected result %d.\n", result);
2130 result = FALSE;
2131 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_THEIR_ITEMS, &result);
2132 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2133 ok(result, "Unexpected result %d.\n", result);
2135 result = FALSE;
2136 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2137 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2138 ok(result, "Unexpected result %d.\n", result);
2140 result = FALSE;
2141 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2142 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2143 ok(result, "Unexpected result %d.\n", result);
2145 hr = IMFAttributes_SetUINT32(attributes1, &DUMMY_GUID2, 2);
2146 ok(hr == S_OK, "Failed to set value, hr %#lx.\n", hr);
2148 result = TRUE;
2149 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2150 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2151 ok(!result, "Unexpected result %d.\n", result);
2153 result = TRUE;
2154 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_THEIR_ITEMS, &result);
2155 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2156 ok(!result, "Unexpected result %d.\n", result);
2158 result = FALSE;
2159 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result);
2160 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2161 ok(result, "Unexpected result %d.\n", result);
2163 result = FALSE;
2164 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2165 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2166 ok(result, "Unexpected result %d.\n", result);
2168 result = FALSE;
2169 hr = IMFAttributes_Compare(attributes, attributes1, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2170 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2171 ok(result, "Unexpected result %d.\n", result);
2173 result = TRUE;
2174 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_ALL_ITEMS, &result);
2175 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2176 ok(!result, "Unexpected result %d.\n", result);
2178 result = FALSE;
2179 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_THEIR_ITEMS, &result);
2180 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2181 ok(result, "Unexpected result %d.\n", result);
2183 result = TRUE;
2184 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_OUR_ITEMS, &result);
2185 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2186 ok(!result, "Unexpected result %d.\n", result);
2188 result = FALSE;
2189 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_INTERSECTION, &result);
2190 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2191 ok(result, "Unexpected result %d.\n", result);
2193 result = FALSE;
2194 hr = IMFAttributes_Compare(attributes1, attributes, MF_ATTRIBUTES_MATCH_SMALLER, &result);
2195 ok(hr == S_OK, "Failed to compare, hr %#lx.\n", hr);
2196 ok(result, "Unexpected result %d.\n", result);
2198 IMFAttributes_Release(attributes);
2199 IMFAttributes_Release(attributes1);
2202 struct test_stream
2204 IStream IStream_iface;
2205 LONG refcount;
2207 HANDLE read_event;
2208 HANDLE done_event;
2211 static struct test_stream *impl_from_IStream(IStream *iface)
2213 return CONTAINING_RECORD(iface, struct test_stream, IStream_iface);
2216 static HRESULT WINAPI test_stream_QueryInterface(IStream *iface, REFIID iid, void **out)
2218 if (IsEqualIID(iid, &IID_IUnknown)
2219 || IsEqualIID(iid, &IID_IStream))
2221 *out = iface;
2222 IStream_AddRef(iface);
2223 return S_OK;
2226 *out = NULL;
2227 return E_NOINTERFACE;
2230 static ULONG WINAPI test_stream_AddRef(IStream *iface)
2232 struct test_stream *stream = impl_from_IStream(iface);
2233 return InterlockedIncrement(&stream->refcount);
2236 static ULONG WINAPI test_stream_Release(IStream *iface)
2238 struct test_stream *stream = impl_from_IStream(iface);
2239 ULONG ref = InterlockedDecrement(&stream->refcount);
2241 if (!ref)
2243 CloseHandle(stream->read_event);
2244 CloseHandle(stream->done_event);
2245 free(stream);
2248 return ref;
2251 static HRESULT WINAPI test_stream_Read(IStream *iface, void *data, ULONG size, ULONG *ret_size)
2253 struct test_stream *stream = impl_from_IStream(iface);
2254 DWORD res;
2256 SetEvent(stream->read_event);
2257 res = WaitForSingleObject(stream->done_event, 1000);
2258 ok(res == 0, "got %#lx\n", res);
2260 *ret_size = size;
2261 return S_OK;
2264 static HRESULT WINAPI test_stream_Write(IStream *iface, const void *data, ULONG size, ULONG *ret_size)
2266 ok(0, "Unexpected call.\n");
2267 return E_NOTIMPL;
2270 static HRESULT WINAPI test_stream_Seek(IStream *iface, LARGE_INTEGER offset, DWORD method, ULARGE_INTEGER *ret_offset)
2272 return S_OK;
2275 static HRESULT WINAPI test_stream_SetSize(IStream *iface, ULARGE_INTEGER size)
2277 ok(0, "Unexpected call.\n");
2278 return E_NOTIMPL;
2281 static HRESULT WINAPI test_stream_CopyTo(IStream *iface, IStream *dest, ULARGE_INTEGER size,
2282 ULARGE_INTEGER *read_size, ULARGE_INTEGER *write_size)
2284 ok(0, "Unexpected call.\n");
2285 return E_NOTIMPL;
2288 static HRESULT WINAPI test_stream_Commit(IStream *iface, DWORD flags)
2290 ok(0, "Unexpected call.\n");
2291 return E_NOTIMPL;
2294 static HRESULT WINAPI test_stream_Revert(IStream *iface)
2296 ok(0, "Unexpected call.\n");
2297 return E_NOTIMPL;
2300 static HRESULT WINAPI test_stream_LockRegion(IStream *iface, ULARGE_INTEGER offset, ULARGE_INTEGER size, DWORD type)
2302 ok(0, "Unexpected call.\n");
2303 return E_NOTIMPL;
2306 static HRESULT WINAPI test_stream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset, ULARGE_INTEGER size, DWORD type)
2308 ok(0, "Unexpected call.\n");
2309 return E_NOTIMPL;
2312 static HRESULT WINAPI test_stream_Stat(IStream *iface, STATSTG *stat, DWORD flags)
2314 memset(stat, 0, sizeof(STATSTG));
2315 stat->pwcsName = NULL;
2316 stat->type = STGTY_STREAM;
2317 stat->cbSize.QuadPart = 16;
2318 return S_OK;
2321 static HRESULT WINAPI test_stream_Clone(IStream *iface, IStream **out)
2323 ok(0, "Unexpected call.\n");
2324 return E_NOTIMPL;
2327 static const IStreamVtbl test_stream_vtbl =
2329 test_stream_QueryInterface,
2330 test_stream_AddRef,
2331 test_stream_Release,
2332 test_stream_Read,
2333 test_stream_Write,
2334 test_stream_Seek,
2335 test_stream_SetSize,
2336 test_stream_CopyTo,
2337 test_stream_Commit,
2338 test_stream_Revert,
2339 test_stream_LockRegion,
2340 test_stream_UnlockRegion,
2341 test_stream_Stat,
2342 test_stream_Clone,
2345 static HRESULT test_stream_create(IStream **out)
2347 struct test_stream *stream;
2349 if (!(stream = calloc(1, sizeof(*stream))))
2350 return E_OUTOFMEMORY;
2352 stream->IStream_iface.lpVtbl = &test_stream_vtbl;
2353 stream->refcount = 1;
2355 stream->read_event = CreateEventW(NULL, FALSE, FALSE, NULL);
2356 stream->done_event = CreateEventW(NULL, FALSE, FALSE, NULL);
2358 *out = &stream->IStream_iface;
2359 return S_OK;
2362 static DWORD test_stream_wait_read(IStream *iface, DWORD timeout)
2364 struct test_stream *stream = impl_from_IStream(iface);
2365 return WaitForSingleObject(stream->read_event, timeout);
2368 static void test_stream_complete_read(IStream *iface)
2370 struct test_stream *stream = impl_from_IStream(iface);
2371 SetEvent(stream->done_event);
2374 static void test_MFCreateMFByteStreamOnStream(void)
2376 struct test_callback *read_callback, *test_callback;
2377 IMFByteStream *bytestream;
2378 IMFByteStream *bytestream2;
2379 IStream *stream;
2380 IMFAttributes *attributes = NULL;
2381 IMFAsyncResult *result;
2382 DWORD caps, written;
2383 IUnknown *unknown;
2384 BYTE buffer[16];
2385 ULONG ref, size;
2386 DWORD res, len;
2387 HRESULT hr;
2388 UINT count;
2389 QWORD to;
2391 if(!pMFCreateMFByteStreamOnStream)
2393 win_skip("MFCreateMFByteStreamOnStream() not found\n");
2394 return;
2397 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2398 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2400 caps = 0xffff0000;
2401 hr = IStream_Write(stream, &caps, sizeof(caps), &written);
2402 ok(hr == S_OK, "Failed to write, hr %#lx.\n", hr);
2404 hr = pMFCreateMFByteStreamOnStream(stream, &bytestream);
2405 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2407 hr = IMFByteStream_QueryInterface(bytestream, &IID_IUnknown,
2408 (void **)&unknown);
2409 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2410 ok((void *)unknown == (void *)bytestream, "got %p\n", unknown);
2411 ref = IUnknown_Release(unknown);
2412 ok(ref == 1, "got %lu\n", ref);
2414 hr = IUnknown_QueryInterface(unknown, &IID_IMFByteStream,
2415 (void **)&bytestream2);
2416 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2417 ok(bytestream2 == bytestream, "got %p\n", bytestream2);
2418 ref = IMFByteStream_Release(bytestream2);
2419 ok(ref == 1, "got %lu\n", ref);
2421 hr = IMFByteStream_QueryInterface(bytestream, &IID_IMFAttributes,
2422 (void **)&attributes);
2423 ok(hr == S_OK ||
2424 /* w7pro64 */
2425 broken(hr == E_NOINTERFACE), "Unexpected hr %#lx.\n", hr);
2427 if (hr != S_OK)
2429 win_skip("Cannot retrieve IMFAttributes interface from IMFByteStream\n");
2430 IStream_Release(stream);
2431 IMFByteStream_Release(bytestream);
2432 return;
2435 ok(attributes != NULL, "got NULL\n");
2436 hr = IMFAttributes_GetCount(attributes, &count);
2437 ok(hr == S_OK, "Failed to get attributes count, hr %#lx.\n", hr);
2438 ok(count == 0, "Unexpected attributes count %u.\n", count);
2440 hr = IMFAttributes_QueryInterface(attributes, &IID_IUnknown,
2441 (void **)&unknown);
2442 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2443 ok((void *)unknown == (void *)bytestream, "got %p\n", unknown);
2444 ref = IUnknown_Release(unknown);
2445 ok(ref == 2, "got %lu\n", ref);
2447 hr = IMFAttributes_QueryInterface(attributes, &IID_IMFByteStream,
2448 (void **)&bytestream2);
2449 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2450 ok(bytestream2 == bytestream, "got %p\n", bytestream2);
2451 ref = IMFByteStream_Release(bytestream2);
2452 ok(ref == 2, "got %lu\n", ref);
2454 check_interface(bytestream, &IID_IMFByteStreamBuffering, FALSE);
2455 check_interface(bytestream, &IID_IMFByteStreamCacheControl, FALSE);
2456 check_interface(bytestream, &IID_IMFMediaEventGenerator, FALSE);
2457 check_interface(bytestream, &IID_IMFGetService, FALSE);
2459 hr = IMFByteStream_GetCapabilities(bytestream, &caps);
2460 ok(hr == S_OK, "Failed to get stream capabilities, hr %#lx.\n", hr);
2461 ok(caps == (MFBYTESTREAM_IS_READABLE | MFBYTESTREAM_IS_SEEKABLE), "Unexpected caps %#lx.\n", caps);
2463 hr = IMFByteStream_Close(bytestream);
2464 ok(hr == S_OK, "Failed to close, hr %#lx.\n", hr);
2466 hr = IMFByteStream_Close(bytestream);
2467 ok(hr == S_OK, "Failed to close, hr %#lx.\n", hr);
2469 hr = IMFByteStream_GetCapabilities(bytestream, &caps);
2470 ok(hr == S_OK, "Failed to get stream capabilities, hr %#lx.\n", hr);
2471 ok(caps == (MFBYTESTREAM_IS_READABLE | MFBYTESTREAM_IS_SEEKABLE), "Unexpected caps %#lx.\n", caps);
2473 /* IMFByteStream maintains position separately from IStream */
2474 caps = 0;
2475 hr = IStream_Read(stream, &caps, sizeof(caps), &size);
2476 ok(hr == S_OK, "Failed to read from raw stream, hr %#lx.\n", hr);
2477 ok(size == 4, "Unexpected size.\n");
2478 ok(caps == 0xffff0000, "Unexpected content.\n");
2480 caps = 0;
2481 hr = IMFByteStream_Read(bytestream, (BYTE *)&caps, sizeof(caps), &size);
2482 ok(hr == S_OK, "Failed to read from stream, hr %#lx.\n", hr);
2483 ok(size == 4, "Unexpected size.\n");
2484 ok(caps == 0xffff0000, "Unexpected content.\n");
2486 caps = 0;
2487 hr = IStream_Read(stream, &caps, sizeof(caps), &size);
2488 ok(hr == S_OK, "Failed to read from raw stream, hr %#lx.\n", hr);
2489 ok(size == 0, "Unexpected size.\n");
2490 ok(caps == 0, "Unexpected content.\n");
2492 hr = IMFByteStream_Seek(bytestream, msoBegin, 0, 0, &to);
2493 ok(hr == S_OK, "Failed to read from stream, hr %#lx.\n", hr);
2495 hr = IStream_Read(stream, &caps, sizeof(caps), &size);
2496 ok(hr == S_OK, "Failed to read from raw stream, hr %#lx.\n", hr);
2497 ok(size == 0, "Unexpected size.\n");
2498 ok(caps == 0, "Unexpected content.\n");
2500 caps = 0;
2501 hr = IMFByteStream_Read(bytestream, (BYTE *)&caps, sizeof(caps), &size);
2502 ok(hr == S_OK, "Failed to read from stream, hr %#lx.\n", hr);
2503 ok(size == 4, "Unexpected size.\n");
2504 ok(caps == 0xffff0000, "Unexpected content.\n");
2506 caps = 0;
2507 hr = IMFByteStream_Read(bytestream, (BYTE *)&caps, sizeof(caps), &size);
2508 ok(hr == S_OK, "Failed to read from stream, hr %#lx.\n", hr);
2509 ok(size == 0, "Unexpected size.\n");
2510 ok(caps == 0, "Unexpected content.\n");
2512 IMFAttributes_Release(attributes);
2513 IMFByteStream_Release(bytestream);
2514 IStream_Release(stream);
2517 /* test that BeginRead doesn't use MFASYNC_CALLBACK_QUEUE_STANDARD */
2519 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
2520 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2522 read_callback = create_test_callback(&test_async_callback_result_vtbl);
2523 test_callback = create_test_callback(&test_async_callback_result_vtbl);
2525 hr = test_stream_create(&stream);
2526 ok(hr == S_OK, "got %#lx\n", hr);
2527 hr = pMFCreateMFByteStreamOnStream(stream, &bytestream);
2528 ok(hr == S_OK, "got %#lx\n", hr);
2530 hr = IMFByteStream_BeginRead(bytestream, buffer, 1, &read_callback->IMFAsyncCallback_iface, NULL);
2531 ok(hr == S_OK, "got %#lx\n", hr);
2533 res = test_stream_wait_read(stream, 1000);
2534 ok(res == 0, "got %#lx\n", res);
2535 res = wait_async_callback_result(&read_callback->IMFAsyncCallback_iface, 10, &result);
2536 ok(res == WAIT_TIMEOUT, "got %#lx\n", res);
2538 /* MFASYNC_CALLBACK_QUEUE_STANDARD is not blocked */
2539 hr = MFPutWorkItem(MFASYNC_CALLBACK_QUEUE_STANDARD, &test_callback->IMFAsyncCallback_iface, NULL);
2540 ok(hr == S_OK, "got %#lx\n", hr);
2541 res = wait_async_callback_result(&test_callback->IMFAsyncCallback_iface, 100, &result);
2542 ok(res == 0, "got %#lx\n", res);
2543 IMFAsyncResult_Release(result);
2545 test_stream_complete_read(stream);
2546 res = wait_async_callback_result(&read_callback->IMFAsyncCallback_iface, 1000, &result);
2547 ok(res == 0, "got %#lx\n", res);
2548 hr = IMFByteStream_EndRead(bytestream, result, &len);
2549 ok(hr == S_OK, "got %#lx\n", hr);
2550 ok(len == 1, "got %#lx\n", len);
2551 IMFAsyncResult_Release(result);
2553 IMFByteStream_Release(bytestream);
2554 IStream_Release(stream);
2556 IMFAsyncCallback_Release(&read_callback->IMFAsyncCallback_iface);
2557 IMFAsyncCallback_Release(&test_callback->IMFAsyncCallback_iface);
2559 hr = MFShutdown();
2560 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
2563 static void test_file_stream(void)
2565 static const WCHAR newfilename[] = L"new.mp4";
2566 IMFByteStream *bytestream, *bytestream2;
2567 QWORD bytestream_length, position;
2568 IMFAttributes *attributes = NULL;
2569 MF_ATTRIBUTE_TYPE item_type;
2570 WCHAR pathW[MAX_PATH];
2571 WCHAR *filename;
2572 HRESULT hr;
2573 WCHAR *str;
2574 DWORD caps;
2575 UINT count;
2576 BOOL eos;
2578 filename = load_resource(L"test.mp4");
2580 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
2581 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2583 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST,
2584 MF_FILEFLAGS_NONE, filename, &bytestream);
2585 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2587 check_interface(bytestream, &IID_IMFByteStreamBuffering, FALSE);
2588 check_interface(bytestream, &IID_IMFByteStreamCacheControl, FALSE);
2589 check_interface(bytestream, &IID_IMFMediaEventGenerator, FALSE);
2590 check_interface(bytestream, &IID_IMFGetService, TRUE);
2592 hr = IMFByteStream_GetCapabilities(bytestream, &caps);
2593 ok(hr == S_OK, "Failed to get stream capabilities, hr %#lx.\n", hr);
2594 if (is_win8_plus)
2596 ok(caps == (MFBYTESTREAM_IS_READABLE | MFBYTESTREAM_IS_SEEKABLE | MFBYTESTREAM_DOES_NOT_USE_NETWORK),
2597 "Unexpected caps %#lx.\n", caps);
2599 else
2600 ok(caps == (MFBYTESTREAM_IS_READABLE | MFBYTESTREAM_IS_SEEKABLE), "Unexpected caps %#lx.\n", caps);
2602 hr = IMFByteStream_QueryInterface(bytestream, &IID_IMFAttributes,
2603 (void **)&attributes);
2604 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2605 ok(attributes != NULL, "got NULL\n");
2607 hr = IMFAttributes_GetCount(attributes, &count);
2608 ok(hr == S_OK, "Failed to get attributes count, hr %#lx.\n", hr);
2609 ok(count == 2, "Unexpected attributes count %u.\n", count);
2611 /* Original file name. */
2612 hr = IMFAttributes_GetAllocatedString(attributes, &MF_BYTESTREAM_ORIGIN_NAME, &str, &count);
2613 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
2614 ok(!lstrcmpW(str, filename), "Unexpected name %s.\n", wine_dbgstr_w(str));
2615 CoTaskMemFree(str);
2617 /* Modification time. */
2618 hr = IMFAttributes_GetItemType(attributes, &MF_BYTESTREAM_LAST_MODIFIED_TIME, &item_type);
2619 ok(hr == S_OK, "Failed to get item type, hr %#lx.\n", hr);
2620 ok(item_type == MF_ATTRIBUTE_BLOB, "Unexpected item type.\n");
2622 IMFAttributes_Release(attributes);
2624 /* Length. */
2625 hr = IMFByteStream_GetLength(bytestream, NULL);
2626 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2628 bytestream_length = 0;
2629 hr = IMFByteStream_GetLength(bytestream, &bytestream_length);
2630 ok(hr == S_OK, "Failed to get bytestream length, hr %#lx.\n", hr);
2631 ok(bytestream_length > 0, "Unexpected bytestream length %s.\n", wine_dbgstr_longlong(bytestream_length));
2633 hr = IMFByteStream_SetCurrentPosition(bytestream, bytestream_length);
2634 ok(hr == S_OK, "Failed to set bytestream position, hr %#lx.\n", hr);
2636 hr = IMFByteStream_IsEndOfStream(bytestream, &eos);
2637 ok(hr == S_OK, "Failed query end of stream, hr %#lx.\n", hr);
2638 ok(eos == TRUE, "Unexpected IsEndOfStream result, %u.\n", eos);
2640 hr = IMFByteStream_SetCurrentPosition(bytestream, 2 * bytestream_length);
2641 ok(hr == S_OK, "Failed to set bytestream position, hr %#lx.\n", hr);
2643 hr = IMFByteStream_GetCurrentPosition(bytestream, NULL);
2644 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2646 hr = IMFByteStream_GetCurrentPosition(bytestream, &position);
2647 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2648 ok(position == 2 * bytestream_length, "Unexpected position.\n");
2650 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST,
2651 MF_FILEFLAGS_NONE, filename, &bytestream2);
2652 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2653 IMFByteStream_Release(bytestream2);
2655 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &bytestream2);
2656 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "Unexpected hr %#lx.\n", hr);
2658 hr = MFCreateFile(MF_ACCESSMODE_READWRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &bytestream2);
2659 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "Unexpected hr %#lx.\n", hr);
2661 IMFByteStream_Release(bytestream);
2663 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST,
2664 MF_FILEFLAGS_NONE, newfilename, &bytestream);
2665 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Unexpected hr %#lx.\n", hr);
2667 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_EXIST,
2668 MF_FILEFLAGS_NONE, filename, &bytestream);
2669 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "Unexpected hr %#lx.\n", hr);
2671 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_EXIST,
2672 MF_FILEFLAGS_NONE, newfilename, &bytestream);
2673 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2675 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, newfilename, &bytestream2);
2676 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "Unexpected hr %#lx.\n", hr);
2678 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, newfilename, &bytestream2);
2679 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "Unexpected hr %#lx.\n", hr);
2681 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_ALLOW_WRITE_SHARING,
2682 newfilename, &bytestream2);
2683 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "Unexpected hr %#lx.\n", hr);
2685 IMFByteStream_Release(bytestream);
2687 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST,
2688 MF_FILEFLAGS_ALLOW_WRITE_SHARING, newfilename, &bytestream);
2689 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2691 /* Opening the file again fails even though MF_FILEFLAGS_ALLOW_WRITE_SHARING is set. */
2692 hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_ALLOW_WRITE_SHARING,
2693 newfilename, &bytestream2);
2694 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "Unexpected hr %#lx.\n", hr);
2696 IMFByteStream_Release(bytestream);
2698 /* Explicit file: scheme */
2699 lstrcpyW(pathW, fileschemeW);
2700 lstrcatW(pathW, filename);
2701 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, pathW, &bytestream);
2702 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
2704 hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &bytestream);
2705 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2706 ok(DeleteFileW(filename), "failed to delete file\n");
2707 IMFByteStream_Release(bytestream);
2709 hr = MFShutdown();
2710 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
2712 DeleteFileW(newfilename);
2715 static void test_system_memory_buffer(void)
2717 IMFMediaBuffer *buffer;
2718 HRESULT hr;
2719 DWORD length, max;
2720 BYTE *data, *data2;
2722 hr = MFCreateMemoryBuffer(1024, NULL);
2723 ok(hr == E_INVALIDARG || hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2725 hr = MFCreateMemoryBuffer(0, &buffer);
2726 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2727 if(buffer)
2729 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
2730 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2731 ok(length == 0, "got %lu\n", length);
2733 IMFMediaBuffer_Release(buffer);
2736 hr = MFCreateMemoryBuffer(1024, &buffer);
2737 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2739 check_interface(buffer, &IID_IMFGetService, FALSE);
2741 hr = IMFMediaBuffer_GetMaxLength(buffer, NULL);
2742 ok(hr == E_INVALIDARG || hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2744 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
2745 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2746 ok(length == 1024, "got %lu\n", length);
2748 hr = IMFMediaBuffer_SetCurrentLength(buffer, 1025);
2749 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2751 hr = IMFMediaBuffer_SetCurrentLength(buffer, 10);
2752 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2754 hr = IMFMediaBuffer_GetCurrentLength(buffer, NULL);
2755 ok(hr == E_INVALIDARG || hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2757 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
2758 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2759 ok(length == 10, "got %lu\n", length);
2761 length = 0;
2762 max = 0;
2763 hr = IMFMediaBuffer_Lock(buffer, NULL, &length, &max);
2764 ok(hr == E_INVALIDARG || hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
2765 ok(length == 0, "got %lu\n", length);
2766 ok(max == 0, "got %lu\n", length);
2768 hr = IMFMediaBuffer_Lock(buffer, &data, &max, &length);
2769 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2770 ok(length == 10, "got %lu\n", length);
2771 ok(max == 1024, "got %lu\n", max);
2773 /* Attempt to lock the buffer twice */
2774 hr = IMFMediaBuffer_Lock(buffer, &data2, &max, &length);
2775 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2776 ok(data == data2, "Unexpected hr %#lx.\n", hr);
2778 hr = IMFMediaBuffer_Unlock(buffer);
2779 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2781 hr = IMFMediaBuffer_Unlock(buffer);
2782 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2784 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
2785 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2787 hr = IMFMediaBuffer_Unlock(buffer);
2788 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2790 /* Extra Unlock */
2791 hr = IMFMediaBuffer_Unlock(buffer);
2792 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2794 IMFMediaBuffer_Release(buffer);
2797 static void test_system_memory_aligned_buffer(void)
2799 static const DWORD alignments[] =
2801 MF_16_BYTE_ALIGNMENT,
2802 MF_32_BYTE_ALIGNMENT,
2803 MF_64_BYTE_ALIGNMENT,
2804 MF_128_BYTE_ALIGNMENT,
2805 MF_256_BYTE_ALIGNMENT,
2806 MF_512_BYTE_ALIGNMENT,
2808 IMFMediaBuffer *buffer;
2809 DWORD length, max;
2810 unsigned int i;
2811 BYTE *data;
2812 HRESULT hr;
2814 hr = MFCreateAlignedMemoryBuffer(16, MF_8_BYTE_ALIGNMENT, NULL);
2815 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
2817 hr = MFCreateAlignedMemoryBuffer(201, MF_8_BYTE_ALIGNMENT, &buffer);
2818 ok(hr == S_OK, "Failed to create memory buffer, hr %#lx.\n", hr);
2820 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
2821 ok(hr == S_OK, "Failed to get current length, hr %#lx.\n", hr);
2822 ok(length == 0, "Unexpected current length %lu.\n", length);
2824 hr = IMFMediaBuffer_SetCurrentLength(buffer, 1);
2825 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
2826 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
2827 ok(hr == S_OK, "Failed to get current length, hr %#lx.\n", hr);
2828 ok(length == 1, "Unexpected current length %lu.\n", length);
2830 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
2831 ok(hr == S_OK, "Failed to get max length, hr %#lx.\n", hr);
2832 ok(length == 201, "Unexpected max length %lu.\n", length);
2834 hr = IMFMediaBuffer_SetCurrentLength(buffer, 202);
2835 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2836 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
2837 ok(hr == S_OK, "Failed to get max length, hr %#lx.\n", hr);
2838 ok(length == 201, "Unexpected max length %lu.\n", length);
2839 hr = IMFMediaBuffer_SetCurrentLength(buffer, 10);
2840 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
2842 hr = IMFMediaBuffer_Lock(buffer, &data, &max, &length);
2843 ok(hr == S_OK, "Failed to lock, hr %#lx.\n", hr);
2844 ok(max == 201 && length == 10, "Unexpected length.\n");
2845 hr = IMFMediaBuffer_Unlock(buffer);
2846 ok(hr == S_OK, "Failed to unlock, hr %#lx.\n", hr);
2848 IMFMediaBuffer_Release(buffer);
2850 for (i = 0; i < ARRAY_SIZE(alignments); ++i)
2852 hr = MFCreateAlignedMemoryBuffer(200, alignments[i], &buffer);
2853 ok(hr == S_OK, "Failed to create memory buffer, hr %#lx.\n", hr);
2855 hr = IMFMediaBuffer_Lock(buffer, &data, &max, &length);
2856 ok(hr == S_OK, "Failed to lock, hr %#lx.\n", hr);
2857 ok(max == 200 && !length, "Unexpected length.\n");
2858 ok(!((uintptr_t)data & alignments[i]), "Data at %p is misaligned.\n", data);
2859 hr = IMFMediaBuffer_Unlock(buffer);
2860 ok(hr == S_OK, "Failed to unlock, hr %#lx.\n", hr);
2862 IMFMediaBuffer_Release(buffer);
2865 hr = MFCreateAlignedMemoryBuffer(200, 0, &buffer);
2866 ok(hr == S_OK, "Failed to create memory buffer, hr %#lx.\n", hr);
2867 IMFMediaBuffer_Release(buffer);
2870 static void test_sample(void)
2872 static const DWORD test_pattern = 0x22222222;
2873 IMFMediaBuffer *buffer, *buffer2, *buffer3;
2874 DWORD count, flags, length;
2875 IMFAttributes *attributes;
2876 IMFSample *sample;
2877 LONGLONG time;
2878 HRESULT hr;
2879 BYTE *data;
2881 hr = MFCreateSample( &sample );
2882 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2884 hr = IMFSample_QueryInterface(sample, &IID_IMFAttributes, (void **)&attributes);
2885 ok(hr == S_OK, "Failed to get attributes interface, hr %#lx.\n", hr);
2887 CHECK_ATTR_COUNT(attributes, 0);
2889 hr = IMFSample_GetBufferCount(sample, NULL);
2890 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2892 hr = IMFSample_GetBufferCount(sample, &count);
2893 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2894 ok(count == 0, "got %ld\n", count);
2896 hr = IMFSample_GetSampleFlags(sample, &flags);
2897 ok(hr == S_OK, "Failed to get sample flags, hr %#lx.\n", hr);
2898 ok(!flags, "Unexpected flags %#lx.\n", flags);
2900 hr = IMFSample_SetSampleFlags(sample, 0x123);
2901 ok(hr == S_OK, "Failed to set sample flags, hr %#lx.\n", hr);
2902 hr = IMFSample_GetSampleFlags(sample, &flags);
2903 ok(hr == S_OK, "Failed to get sample flags, hr %#lx.\n", hr);
2904 ok(flags == 0x123, "Unexpected flags %#lx.\n", flags);
2906 hr = IMFSample_GetSampleTime(sample, &time);
2907 ok(hr == MF_E_NO_SAMPLE_TIMESTAMP, "Unexpected hr %#lx.\n", hr);
2909 hr = IMFSample_GetSampleDuration(sample, &time);
2910 ok(hr == MF_E_NO_SAMPLE_DURATION, "Unexpected hr %#lx.\n", hr);
2912 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
2913 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2915 hr = IMFSample_RemoveBufferByIndex(sample, 0);
2916 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
2918 hr = IMFSample_RemoveAllBuffers(sample);
2919 ok(hr == S_OK, "Failed to remove all, hr %#lx.\n", hr);
2921 hr = IMFSample_GetTotalLength(sample, &length);
2922 ok(hr == S_OK, "Failed to get total length, hr %#lx.\n", hr);
2923 ok(!length, "Unexpected total length %lu.\n", length);
2925 hr = MFCreateMemoryBuffer(16, &buffer);
2926 ok(hr == S_OK, "Failed to create buffer, hr %#lx.\n", hr);
2928 hr = IMFSample_AddBuffer(sample, buffer);
2929 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
2931 hr = IMFSample_AddBuffer(sample, buffer);
2932 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
2934 hr = IMFSample_GetBufferCount(sample, &count);
2935 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
2936 ok(count == 2, "Unexpected buffer count %lu.\n", count);
2938 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer2);
2939 ok(hr == S_OK, "Failed to get buffer, hr %#lx.\n", hr);
2940 ok(buffer2 == buffer, "Unexpected object.\n");
2941 IMFMediaBuffer_Release(buffer2);
2943 hr = IMFSample_GetTotalLength(sample, &length);
2944 ok(hr == S_OK, "Failed to get total length, hr %#lx.\n", hr);
2945 ok(!length, "Unexpected total length %lu.\n", length);
2947 hr = IMFMediaBuffer_SetCurrentLength(buffer, 2);
2948 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
2950 hr = IMFSample_GetTotalLength(sample, &length);
2951 ok(hr == S_OK, "Failed to get total length, hr %#lx.\n", hr);
2952 ok(length == 4, "Unexpected total length %lu.\n", length);
2954 hr = IMFSample_RemoveBufferByIndex(sample, 1);
2955 ok(hr == S_OK, "Failed to remove buffer, hr %#lx.\n", hr);
2957 hr = IMFSample_GetTotalLength(sample, &length);
2958 ok(hr == S_OK, "Failed to get total length, hr %#lx.\n", hr);
2959 ok(length == 2, "Unexpected total length %lu.\n", length);
2961 IMFMediaBuffer_Release(buffer);
2963 /* Duration */
2964 hr = IMFSample_SetSampleDuration(sample, 10);
2965 ok(hr == S_OK, "Failed to set duration, hr %#lx.\n", hr);
2966 CHECK_ATTR_COUNT(attributes, 0);
2967 hr = IMFSample_GetSampleDuration(sample, &time);
2968 ok(hr == S_OK, "Failed to get sample duration, hr %#lx.\n", hr);
2969 ok(time == 10, "Unexpected duration.\n");
2971 /* Timestamp */
2972 hr = IMFSample_SetSampleTime(sample, 1);
2973 ok(hr == S_OK, "Failed to set timestamp, hr %#lx.\n", hr);
2974 CHECK_ATTR_COUNT(attributes, 0);
2975 hr = IMFSample_GetSampleTime(sample, &time);
2976 ok(hr == S_OK, "Failed to get sample time, hr %#lx.\n", hr);
2977 ok(time == 1, "Unexpected timestamp.\n");
2979 IMFAttributes_Release(attributes);
2980 IMFSample_Release(sample);
2982 /* CopyToBuffer() */
2983 hr = MFCreateSample(&sample);
2984 ok(hr == S_OK, "Failed to create a sample, hr %#lx.\n", hr);
2986 hr = MFCreateMemoryBuffer(16, &buffer2);
2987 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
2989 /* Sample with no buffers. */
2990 hr = IMFMediaBuffer_SetCurrentLength(buffer2, 1);
2991 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
2992 hr = IMFSample_CopyToBuffer(sample, buffer2);
2993 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
2994 hr = IMFMediaBuffer_GetCurrentLength(buffer2, &length);
2995 ok(hr == S_OK, "Failed to get current length, hr %#lx.\n", hr);
2996 ok(!length, "Unexpected length %lu.\n", length);
2998 /* Single buffer, larger destination. */
2999 hr = MFCreateMemoryBuffer(8, &buffer);
3000 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
3002 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
3003 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
3004 *(DWORD *)data = 0x11111111;
3005 hr = IMFMediaBuffer_Unlock(buffer);
3006 ok(hr == S_OK, "Failed to unlock, hr %#lx.\n", hr);
3007 hr = IMFMediaBuffer_SetCurrentLength(buffer, 4);
3008 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
3010 hr = IMFSample_AddBuffer(sample, buffer);
3011 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
3013 /* Existing content is overwritten. */
3014 hr = IMFMediaBuffer_SetCurrentLength(buffer2, 8);
3015 ok(hr == S_OK, "Failed to set length, hr %#lx.\n", hr);
3017 hr = IMFSample_CopyToBuffer(sample, buffer2);
3018 ok(hr == S_OK, "Failed to copy to buffer, hr %#lx.\n", hr);
3020 hr = IMFMediaBuffer_GetCurrentLength(buffer2, &length);
3021 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
3022 ok(length == 4, "Unexpected buffer length %lu.\n", length);
3024 /* Multiple buffers, matching total size. */
3025 hr = IMFSample_AddBuffer(sample, buffer);
3026 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
3028 hr = IMFSample_GetBufferCount(sample, &count);
3029 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
3030 ok(count == 2, "Unexpected buffer count %lu.\n", count);
3032 hr = IMFMediaBuffer_SetCurrentLength(buffer, 8);
3033 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
3035 hr = IMFSample_CopyToBuffer(sample, buffer2);
3036 ok(hr == S_OK, "Failed to copy to buffer, hr %#lx.\n", hr);
3038 hr = IMFMediaBuffer_GetCurrentLength(buffer2, &length);
3039 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
3040 ok(length == 16, "Unexpected buffer length %lu.\n", length);
3042 hr = IMFSample_AddBuffer(sample, buffer);
3043 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
3045 hr = IMFMediaBuffer_SetCurrentLength(buffer2, 1);
3046 ok(hr == S_OK, "Failed to set buffer length, hr %#lx.\n", hr);
3048 hr = IMFMediaBuffer_Lock(buffer2, &data, NULL, NULL);
3049 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
3050 *(DWORD *)data = test_pattern;
3051 hr = IMFMediaBuffer_Unlock(buffer2);
3052 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
3054 hr = IMFSample_CopyToBuffer(sample, buffer2);
3055 ok(hr == MF_E_BUFFERTOOSMALL, "Unexpected hr %#lx.\n", hr);
3057 hr = IMFMediaBuffer_Lock(buffer2, &data, NULL, NULL);
3058 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
3059 ok(!memcmp(data, &test_pattern, sizeof(test_pattern)), "Unexpected contents, %#lx\n", *(DWORD *)data);
3060 hr = IMFMediaBuffer_Unlock(buffer2);
3061 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
3063 hr = IMFMediaBuffer_GetCurrentLength(buffer2, &length);
3064 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
3065 ok(!length, "Unexpected buffer length %lu.\n", length);
3067 IMFMediaBuffer_Release(buffer2);
3068 IMFSample_Release(sample);
3070 /* ConvertToContiguousBuffer() */
3071 hr = MFCreateSample(&sample);
3072 ok(hr == S_OK, "Failed to create a sample, hr %#lx.\n", hr);
3074 hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer);
3075 ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
3077 hr = MFCreateMemoryBuffer(16, &buffer);
3078 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
3080 hr = IMFSample_AddBuffer(sample, buffer);
3081 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
3083 hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer2);
3084 ok(hr == S_OK, "Failed to convert, hr %#lx.\n", hr);
3085 ok(buffer2 == buffer, "Unexpected buffer instance.\n");
3086 IMFMediaBuffer_Release(buffer2);
3088 hr = IMFSample_ConvertToContiguousBuffer(sample, NULL);
3089 ok(hr == S_OK, "Failed to convert, hr %#lx.\n", hr);
3091 hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer2);
3092 ok(hr == S_OK, "Failed to convert, hr %#lx.\n", hr);
3093 ok(buffer2 == buffer, "Unexpected buffer instance.\n");
3094 IMFMediaBuffer_Release(buffer2);
3096 hr = IMFMediaBuffer_SetCurrentLength(buffer, 3);
3097 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3099 hr = MFCreateMemoryBuffer(16, &buffer2);
3100 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
3102 hr = IMFMediaBuffer_SetCurrentLength(buffer2, 4);
3103 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3105 hr = IMFSample_AddBuffer(sample, buffer2);
3106 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
3107 IMFMediaBuffer_Release(buffer2);
3109 hr = IMFSample_GetBufferCount(sample, &count);
3110 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
3111 ok(count == 2, "Unexpected buffer count %lu.\n", count);
3113 hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer3);
3114 ok(hr == S_OK, "Failed to convert, hr %#lx.\n", hr);
3116 hr = IMFMediaBuffer_GetMaxLength(buffer3, &length);
3117 ok(hr == S_OK, "Failed to get maximum length, hr %#lx.\n", hr);
3118 ok(length == 7, "Unexpected length %lu.\n", length);
3120 hr = IMFMediaBuffer_GetCurrentLength(buffer3, &length);
3121 ok(hr == S_OK, "Failed to get maximum length, hr %#lx.\n", hr);
3122 ok(length == 7, "Unexpected length %lu.\n", length);
3124 IMFMediaBuffer_Release(buffer3);
3126 hr = IMFSample_GetBufferCount(sample, &count);
3127 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
3128 ok(count == 1, "Unexpected buffer count %lu.\n", count);
3130 hr = IMFSample_AddBuffer(sample, buffer);
3131 ok(hr == S_OK, "Failed to add buffer, hr %#lx.\n", hr);
3133 hr = IMFSample_GetBufferCount(sample, &count);
3134 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
3135 ok(count == 2, "Unexpected buffer count %lu.\n", count);
3137 hr = IMFSample_ConvertToContiguousBuffer(sample, NULL);
3138 ok(hr == S_OK, "Failed to convert, hr %#lx.\n", hr);
3140 hr = IMFSample_GetBufferCount(sample, &count);
3141 ok(hr == S_OK, "Failed to get buffer count, hr %#lx.\n", hr);
3142 ok(count == 1, "Unexpected buffer count %lu.\n", count);
3144 IMFMediaBuffer_Release(buffer);
3146 IMFSample_Release(sample);
3149 static HRESULT WINAPI testcallback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
3151 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
3152 IMFMediaEventQueue *queue;
3153 IUnknown *state, *obj;
3154 HRESULT hr;
3156 ok(result != NULL, "Unexpected result object.\n");
3158 state = IMFAsyncResult_GetStateNoAddRef(result);
3159 if (state && SUCCEEDED(IUnknown_QueryInterface(state, &IID_IMFMediaEventQueue, (void **)&queue)))
3161 IMFMediaEvent *event = NULL, *event2;
3163 if (is_win8_plus)
3165 hr = IMFMediaEventQueue_GetEvent(queue, MF_EVENT_FLAG_NO_WAIT, &event);
3166 ok(hr == MF_E_MULTIPLE_SUBSCRIBERS, "Failed to get event, hr %#lx.\n", hr);
3168 hr = IMFMediaEventQueue_GetEvent(queue, 0, &event);
3169 ok(hr == MF_E_MULTIPLE_SUBSCRIBERS, "Failed to get event, hr %#lx.\n", hr);
3171 hr = IMFMediaEventQueue_EndGetEvent(queue, result, &event);
3172 ok(hr == S_OK, "Failed to finalize GetEvent, hr %#lx.\n", hr);
3174 hr = IMFMediaEventQueue_EndGetEvent(queue, result, &event2);
3175 ok(hr == E_FAIL, "Unexpected result, hr %#lx.\n", hr);
3177 if (event)
3178 IMFMediaEvent_Release(event);
3181 hr = IMFAsyncResult_GetObject(result, &obj);
3182 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3184 IMFMediaEventQueue_Release(queue);
3186 SetEvent(callback->event);
3189 return E_NOTIMPL;
3192 static const IMFAsyncCallbackVtbl testcallbackvtbl =
3194 testcallback_QueryInterface,
3195 testcallback_AddRef,
3196 testcallback_Release,
3197 testcallback_GetParameters,
3198 testcallback_Invoke,
3201 static void test_MFCreateAsyncResult(void)
3203 IMFAsyncResult *result, *result2;
3204 struct test_callback *callback;
3205 IUnknown *state, *object;
3206 MFASYNCRESULT *data;
3207 ULONG refcount;
3208 HANDLE event;
3209 DWORD flags;
3210 HRESULT hr;
3211 BOOL ret;
3213 callback = create_test_callback(NULL);
3215 hr = MFCreateAsyncResult(NULL, NULL, NULL, NULL);
3216 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
3218 hr = MFCreateAsyncResult(NULL, NULL, NULL, &result);
3219 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
3221 data = (MFASYNCRESULT *)result;
3222 ok(data->pCallback == NULL, "Unexpected callback value.\n");
3223 ok(data->hrStatusResult == S_OK, "Unexpected status %#lx.\n", data->hrStatusResult);
3224 ok(data->dwBytesTransferred == 0, "Unexpected byte length %lu.\n", data->dwBytesTransferred);
3225 ok(data->hEvent == NULL, "Unexpected event.\n");
3227 hr = IMFAsyncResult_GetState(result, NULL);
3228 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3230 state = (void *)0xdeadbeef;
3231 hr = IMFAsyncResult_GetState(result, &state);
3232 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3233 ok(state == (void *)0xdeadbeef, "Unexpected state.\n");
3235 hr = IMFAsyncResult_GetStatus(result);
3236 ok(hr == S_OK, "Unexpected status %#lx.\n", hr);
3238 data->hrStatusResult = 123;
3239 hr = IMFAsyncResult_GetStatus(result);
3240 ok(hr == 123, "Unexpected status %#lx.\n", hr);
3242 hr = IMFAsyncResult_SetStatus(result, E_FAIL);
3243 ok(hr == S_OK, "Failed to set status, hr %#lx.\n", hr);
3244 ok(data->hrStatusResult == E_FAIL, "Unexpected status %#lx.\n", hr);
3246 hr = IMFAsyncResult_GetObject(result, NULL);
3247 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3249 object = (void *)0xdeadbeef;
3250 hr = IMFAsyncResult_GetObject(result, &object);
3251 ok(hr == E_POINTER, "Failed to get object, hr %#lx.\n", hr);
3252 ok(object == (void *)0xdeadbeef, "Unexpected object.\n");
3254 state = IMFAsyncResult_GetStateNoAddRef(result);
3255 ok(state == NULL, "Unexpected state.\n");
3257 /* Object. */
3258 hr = MFCreateAsyncResult((IUnknown *)result, &callback->IMFAsyncCallback_iface, NULL, &result2);
3259 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
3261 data = (MFASYNCRESULT *)result2;
3262 ok(data->pCallback == &callback->IMFAsyncCallback_iface, "Unexpected callback value.\n");
3263 ok(data->hrStatusResult == S_OK, "Unexpected status %#lx.\n", data->hrStatusResult);
3264 ok(data->dwBytesTransferred == 0, "Unexpected byte length %lu.\n", data->dwBytesTransferred);
3265 ok(data->hEvent == NULL, "Unexpected event.\n");
3267 object = NULL;
3268 hr = IMFAsyncResult_GetObject(result2, &object);
3269 ok(hr == S_OK, "Failed to get object, hr %#lx.\n", hr);
3270 ok(object == (IUnknown *)result, "Unexpected object.\n");
3271 IUnknown_Release(object);
3273 IMFAsyncResult_Release(result2);
3275 /* State object. */
3276 hr = MFCreateAsyncResult(NULL, &callback->IMFAsyncCallback_iface, (IUnknown *)result, &result2);
3277 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
3279 data = (MFASYNCRESULT *)result2;
3280 ok(data->pCallback == &callback->IMFAsyncCallback_iface, "Unexpected callback value.\n");
3281 ok(data->hrStatusResult == S_OK, "Unexpected status %#lx.\n", data->hrStatusResult);
3282 ok(data->dwBytesTransferred == 0, "Unexpected byte length %lu.\n", data->dwBytesTransferred);
3283 ok(data->hEvent == NULL, "Unexpected event.\n");
3285 state = NULL;
3286 hr = IMFAsyncResult_GetState(result2, &state);
3287 ok(hr == S_OK, "Failed to get state object, hr %#lx.\n", hr);
3288 ok(state == (IUnknown *)result, "Unexpected state.\n");
3289 IUnknown_Release(state);
3291 state = IMFAsyncResult_GetStateNoAddRef(result2);
3292 ok(state == (IUnknown *)result, "Unexpected state.\n");
3294 refcount = IMFAsyncResult_Release(result2);
3295 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
3296 refcount = IMFAsyncResult_Release(result);
3297 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
3299 /* Event handle is closed on release. */
3300 hr = MFCreateAsyncResult(NULL, NULL, NULL, &result);
3301 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
3303 data = (MFASYNCRESULT *)result;
3304 data->hEvent = event = CreateEventA(NULL, FALSE, FALSE, NULL);
3305 ok(data->hEvent != NULL, "Failed to create event.\n");
3306 ret = GetHandleInformation(event, &flags);
3307 ok(ret, "Failed to get handle info.\n");
3309 refcount = IMFAsyncResult_Release(result);
3310 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
3311 ret = GetHandleInformation(event, &flags);
3312 ok(!ret, "Expected handle to be closed.\n");
3314 hr = MFCreateAsyncResult(NULL, &callback->IMFAsyncCallback_iface, NULL, &result);
3315 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
3317 data = (MFASYNCRESULT *)result;
3318 data->hEvent = event = CreateEventA(NULL, FALSE, FALSE, NULL);
3319 ok(data->hEvent != NULL, "Failed to create event.\n");
3320 ret = GetHandleInformation(event, &flags);
3321 ok(ret, "Failed to get handle info.\n");
3323 refcount = IMFAsyncResult_Release(result);
3324 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
3325 ret = GetHandleInformation(event, &flags);
3326 ok(!ret, "Expected handle to be closed.\n");
3328 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
3331 static void test_startup(void)
3333 DWORD queue;
3334 HRESULT hr;
3336 hr = MFStartup(MAKELONG(MF_API_VERSION, 0xdead), MFSTARTUP_FULL);
3337 ok(hr == MF_E_BAD_STARTUP_VERSION, "Unexpected hr %#lx.\n", hr);
3339 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3340 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3342 hr = MFAllocateWorkQueue(&queue);
3343 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3344 hr = MFUnlockWorkQueue(queue);
3345 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3347 hr = MFShutdown();
3348 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3350 hr = MFAllocateWorkQueue(&queue);
3351 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3353 /* Already shut down, has no effect. */
3354 hr = MFShutdown();
3355 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3357 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3358 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3360 hr = MFAllocateWorkQueue(&queue);
3361 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3362 hr = MFUnlockWorkQueue(queue);
3363 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3365 hr = MFShutdown();
3366 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3368 /* Platform lock. */
3369 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3370 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3372 hr = MFAllocateWorkQueue(&queue);
3373 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3374 hr = MFUnlockWorkQueue(queue);
3375 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3377 /* Unlocking implies shutdown. */
3378 hr = MFUnlockPlatform();
3379 ok(hr == S_OK, "Failed to unlock, %#lx.\n", hr);
3381 hr = MFAllocateWorkQueue(&queue);
3382 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3384 hr = MFLockPlatform();
3385 ok(hr == S_OK, "Failed to lock, %#lx.\n", hr);
3387 hr = MFAllocateWorkQueue(&queue);
3388 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3389 hr = MFUnlockWorkQueue(queue);
3390 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3392 hr = MFShutdown();
3393 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3396 static void test_allocate_queue(void)
3398 DWORD queue, queue2;
3399 HRESULT hr;
3401 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3402 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3404 hr = MFAllocateWorkQueue(&queue);
3405 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3406 ok(queue & MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK, "Unexpected queue id.\n");
3408 hr = MFUnlockWorkQueue(queue);
3409 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3411 hr = MFUnlockWorkQueue(queue);
3412 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
3414 hr = MFAllocateWorkQueue(&queue2);
3415 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3416 ok(queue2 & MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK, "Unexpected queue id.\n");
3418 hr = MFUnlockWorkQueue(queue2);
3419 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3421 /* Unlock in system queue range. */
3422 hr = MFUnlockWorkQueue(MFASYNC_CALLBACK_QUEUE_STANDARD);
3423 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3425 hr = MFUnlockWorkQueue(MFASYNC_CALLBACK_QUEUE_UNDEFINED);
3426 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3428 hr = MFUnlockWorkQueue(0x20);
3429 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3431 hr = MFShutdown();
3432 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3435 static void test_MFCopyImage(void)
3437 DWORD dest[4], src[4];
3438 HRESULT hr;
3440 if (!pMFCopyImage)
3442 win_skip("MFCopyImage() is not available.\n");
3443 return;
3446 memset(dest, 0xaa, sizeof(dest));
3447 memset(src, 0x11, sizeof(src));
3449 hr = pMFCopyImage((BYTE *)dest, 8, (const BYTE *)src, 8, 4, 1);
3450 ok(hr == S_OK, "Failed to copy image %#lx.\n", hr);
3451 ok(dest[0] == src[0] && dest[1] == 0xaaaaaaaa, "Unexpected buffer contents.\n");
3453 /* Negative destination stride. */
3454 memset(dest, 0xaa, sizeof(dest));
3456 src[0] = 0x11111111;
3457 src[1] = 0x22222222;
3458 src[2] = 0x33333333;
3459 src[3] = 0x44444444;
3461 hr = pMFCopyImage((BYTE *)(dest + 2), -8, (const BYTE *)src, 8, 4, 2);
3462 ok(hr == S_OK, "Failed to copy image %#lx.\n", hr);
3463 ok(dest[0] == 0x33333333, "Unexpected buffer contents %#lx.\n", dest[0]);
3464 ok(dest[1] == 0xaaaaaaaa, "Unexpected buffer contents %#lx.\n", dest[1]);
3465 ok(dest[2] == 0x11111111, "Unexpected buffer contents %#lx.\n", dest[2]);
3466 ok(dest[3] == 0xaaaaaaaa, "Unexpected buffer contents %#lx.\n", dest[3]);
3468 memset(dest, 0xaa, sizeof(dest));
3469 memset(src, 0x11, sizeof(src));
3471 hr = pMFCopyImage((BYTE *)dest, 8, (const BYTE *)src, 8, 16, 1);
3472 ok(hr == S_OK, "Failed to copy image %#lx.\n", hr);
3473 ok(!memcmp(dest, src, 16), "Unexpected buffer contents.\n");
3475 memset(dest, 0xaa, sizeof(dest));
3476 memset(src, 0x11, sizeof(src));
3478 hr = pMFCopyImage((BYTE *)dest, 8, (const BYTE *)src, 8, 8, 2);
3479 ok(hr == S_OK, "Failed to copy image %#lx.\n", hr);
3480 ok(!memcmp(dest, src, 16), "Unexpected buffer contents.\n");
3483 static void test_MFCreateCollection(void)
3485 IMFCollection *collection;
3486 IUnknown *element;
3487 DWORD count;
3488 HRESULT hr;
3490 hr = MFCreateCollection(NULL);
3491 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3493 hr = MFCreateCollection(&collection);
3494 ok(hr == S_OK, "Failed to create collection, hr %#lx.\n", hr);
3496 hr = IMFCollection_GetElementCount(collection, NULL);
3497 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3499 count = 1;
3500 hr = IMFCollection_GetElementCount(collection, &count);
3501 ok(hr == S_OK, "Failed to get element count, hr %#lx.\n", hr);
3502 ok(count == 0, "Unexpected count %lu.\n", count);
3504 hr = IMFCollection_GetElement(collection, 0, NULL);
3505 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3507 element = (void *)0xdeadbeef;
3508 hr = IMFCollection_GetElement(collection, 0, &element);
3509 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3510 ok(element == (void *)0xdeadbeef, "Unexpected pointer.\n");
3512 hr = IMFCollection_RemoveElement(collection, 0, NULL);
3513 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
3515 element = (void *)0xdeadbeef;
3516 hr = IMFCollection_RemoveElement(collection, 0, &element);
3517 ok(hr == E_INVALIDARG, "Failed to remove element, hr %#lx.\n", hr);
3518 ok(element == (void *)0xdeadbeef, "Unexpected pointer.\n");
3520 hr = IMFCollection_RemoveAllElements(collection);
3521 ok(hr == S_OK, "Failed to clear, hr %#lx.\n", hr);
3523 hr = IMFCollection_AddElement(collection, (IUnknown *)collection);
3524 ok(hr == S_OK, "Failed to add element, hr %#lx.\n", hr);
3526 count = 0;
3527 hr = IMFCollection_GetElementCount(collection, &count);
3528 ok(hr == S_OK, "Failed to get element count, hr %#lx.\n", hr);
3529 ok(count == 1, "Unexpected count %lu.\n", count);
3531 hr = IMFCollection_AddElement(collection, NULL);
3532 ok(hr == S_OK, "Failed to add element, hr %#lx.\n", hr);
3534 count = 0;
3535 hr = IMFCollection_GetElementCount(collection, &count);
3536 ok(hr == S_OK, "Failed to get element count, hr %#lx.\n", hr);
3537 ok(count == 2, "Unexpected count %lu.\n", count);
3539 hr = IMFCollection_InsertElementAt(collection, 10, (IUnknown *)collection);
3540 ok(hr == S_OK, "Failed to insert element, hr %#lx.\n", hr);
3542 count = 0;
3543 hr = IMFCollection_GetElementCount(collection, &count);
3544 ok(hr == S_OK, "Failed to get element count, hr %#lx.\n", hr);
3545 ok(count == 11, "Unexpected count %lu.\n", count);
3547 hr = IMFCollection_GetElement(collection, 0, &element);
3548 ok(hr == S_OK, "Failed to get element, hr %#lx.\n", hr);
3549 ok(element == (IUnknown *)collection, "Unexpected element.\n");
3550 IUnknown_Release(element);
3552 hr = IMFCollection_GetElement(collection, 1, &element);
3553 ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
3554 ok(!element, "Unexpected element.\n");
3556 hr = IMFCollection_GetElement(collection, 2, &element);
3557 ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
3558 ok(!element, "Unexpected element.\n");
3560 hr = IMFCollection_GetElement(collection, 10, &element);
3561 ok(hr == S_OK, "Failed to get element, hr %#lx.\n", hr);
3562 ok(element == (IUnknown *)collection, "Unexpected element.\n");
3563 IUnknown_Release(element);
3565 hr = IMFCollection_InsertElementAt(collection, 0, NULL);
3566 ok(hr == S_OK, "Failed to insert element, hr %#lx.\n", hr);
3568 hr = IMFCollection_GetElement(collection, 0, &element);
3569 ok(hr == E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
3571 hr = IMFCollection_RemoveAllElements(collection);
3572 ok(hr == S_OK, "Failed to clear, hr %#lx.\n", hr);
3574 count = 1;
3575 hr = IMFCollection_GetElementCount(collection, &count);
3576 ok(hr == S_OK, "Failed to get element count, hr %#lx.\n", hr);
3577 ok(count == 0, "Unexpected count %lu.\n", count);
3579 hr = IMFCollection_InsertElementAt(collection, 0, NULL);
3580 ok(hr == S_OK, "Failed to insert element, hr %#lx.\n", hr);
3582 IMFCollection_Release(collection);
3585 static void test_MFHeapAlloc(void)
3587 void *res;
3589 res = MFHeapAlloc(16, 0, NULL, 0, eAllocationTypeIgnore);
3590 ok(res != NULL, "MFHeapAlloc failed.\n");
3592 MFHeapFree(res);
3595 static void test_scheduled_items(void)
3597 struct test_callback *callback;
3598 IMFAsyncResult *result;
3599 MFWORKITEM_KEY key, key2;
3600 HRESULT hr;
3602 callback = create_test_callback(NULL);
3604 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3605 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3607 hr = MFScheduleWorkItem(&callback->IMFAsyncCallback_iface, NULL, -5000, &key);
3608 ok(hr == S_OK, "Failed to schedule item, hr %#lx.\n", hr);
3610 hr = MFCancelWorkItem(key);
3611 ok(hr == S_OK, "Failed to cancel item, hr %#lx.\n", hr);
3613 hr = MFCancelWorkItem(key);
3614 ok(hr == MF_E_NOT_FOUND || broken(hr == S_OK) /* < win10 */, "Unexpected hr %#lx.\n", hr);
3616 if (!pMFPutWaitingWorkItem)
3618 win_skip("Waiting items are not supported.\n");
3619 return;
3622 hr = MFCreateAsyncResult(NULL, &callback->IMFAsyncCallback_iface, NULL, &result);
3623 ok(hr == S_OK, "Failed to create result, hr %#lx.\n", hr);
3625 hr = pMFPutWaitingWorkItem(NULL, 0, result, &key);
3626 ok(hr == S_OK, "Failed to add waiting item, hr %#lx.\n", hr);
3628 hr = pMFPutWaitingWorkItem(NULL, 0, result, &key2);
3629 ok(hr == S_OK, "Failed to add waiting item, hr %#lx.\n", hr);
3631 hr = MFCancelWorkItem(key);
3632 ok(hr == S_OK, "Failed to cancel item, hr %#lx.\n", hr);
3634 hr = MFCancelWorkItem(key2);
3635 ok(hr == S_OK, "Failed to cancel item, hr %#lx.\n", hr);
3637 IMFAsyncResult_Release(result);
3639 hr = MFScheduleWorkItem(&callback->IMFAsyncCallback_iface, NULL, -5000, &key);
3640 ok(hr == S_OK, "Failed to schedule item, hr %#lx.\n", hr);
3642 hr = MFCancelWorkItem(key);
3643 ok(hr == S_OK, "Failed to cancel item, hr %#lx.\n", hr);
3645 hr = MFShutdown();
3646 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3648 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
3651 static void test_serial_queue(void)
3653 static const DWORD queue_ids[] =
3655 MFASYNC_CALLBACK_QUEUE_STANDARD,
3656 MFASYNC_CALLBACK_QUEUE_RT,
3657 MFASYNC_CALLBACK_QUEUE_IO,
3658 MFASYNC_CALLBACK_QUEUE_TIMER,
3659 MFASYNC_CALLBACK_QUEUE_MULTITHREADED,
3660 MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION,
3662 DWORD queue, serial_queue;
3663 unsigned int i;
3664 HRESULT hr;
3666 if (!pMFAllocateSerialWorkQueue)
3668 win_skip("Serial queues are not supported.\n");
3669 return;
3672 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3673 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3675 for (i = 0; i < ARRAY_SIZE(queue_ids); ++i)
3677 BOOL broken_types = queue_ids[i] == MFASYNC_CALLBACK_QUEUE_TIMER ||
3678 queue_ids[i] == MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION;
3680 hr = pMFAllocateSerialWorkQueue(queue_ids[i], &serial_queue);
3681 ok(hr == S_OK || broken(broken_types && hr == E_INVALIDARG) /* Win8 */,
3682 "%u: failed to allocate a queue, hr %#lx.\n", i, hr);
3684 if (SUCCEEDED(hr))
3686 hr = MFUnlockWorkQueue(serial_queue);
3687 ok(hr == S_OK, "%u: failed to unlock the queue, hr %#lx.\n", i, hr);
3691 /* Chain them together. */
3692 hr = pMFAllocateSerialWorkQueue(MFASYNC_CALLBACK_QUEUE_STANDARD, &serial_queue);
3693 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3695 hr = pMFAllocateSerialWorkQueue(serial_queue, &queue);
3696 ok(hr == S_OK, "Failed to allocate a queue, hr %#lx.\n", hr);
3698 hr = MFUnlockWorkQueue(serial_queue);
3699 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3701 hr = MFUnlockWorkQueue(queue);
3702 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
3704 hr = MFShutdown();
3705 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3708 static LONG periodic_counter;
3709 static void CALLBACK periodic_callback(IUnknown *context)
3711 InterlockedIncrement(&periodic_counter);
3714 static void test_periodic_callback(void)
3716 DWORD period, key;
3717 HRESULT hr;
3719 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3720 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3722 period = 0;
3723 hr = MFGetTimerPeriodicity(&period);
3724 ok(hr == S_OK, "Failed to get timer perdiod, hr %#lx.\n", hr);
3725 ok(period == 10, "Unexpected period %lu.\n", period);
3727 if (!pMFAddPeriodicCallback)
3729 win_skip("Periodic callbacks are not supported.\n");
3730 hr = MFShutdown();
3731 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3732 return;
3735 ok(periodic_counter == 0, "Unexpected counter value %lu.\n", periodic_counter);
3737 hr = pMFAddPeriodicCallback(periodic_callback, NULL, &key);
3738 ok(hr == S_OK, "Failed to add periodic callback, hr %#lx.\n", hr);
3739 ok(key != 0, "Unexpected key %#lx.\n", key);
3741 Sleep(10 * period);
3743 hr = pMFRemovePeriodicCallback(key);
3744 ok(hr == S_OK, "Failed to remove callback, hr %#lx.\n", hr);
3746 ok(periodic_counter > 0, "Unexpected counter value %lu.\n", periodic_counter);
3748 hr = MFShutdown();
3749 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3752 static void test_event_queue(void)
3754 struct test_callback *callback, *callback2;
3755 IMFMediaEvent *event, *event2;
3756 IMFMediaEventQueue *queue;
3757 IMFAsyncResult *result;
3758 HRESULT hr;
3759 DWORD ret;
3761 callback = create_test_callback(NULL);
3762 callback2 = create_test_callback(NULL);
3764 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
3765 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
3767 hr = MFCreateEventQueue(&queue);
3768 ok(hr == S_OK, "Failed to create event queue, hr %#lx.\n", hr);
3770 hr = IMFMediaEventQueue_GetEvent(queue, MF_EVENT_FLAG_NO_WAIT, &event);
3771 ok(hr == MF_E_NO_EVENTS_AVAILABLE, "Unexpected hr %#lx.\n", hr);
3773 hr = MFCreateMediaEvent(MEError, &GUID_NULL, E_FAIL, NULL, &event);
3774 ok(hr == S_OK, "Failed to create event object, hr %#lx.\n", hr);
3776 if (is_win8_plus)
3778 hr = IMFMediaEventQueue_QueueEvent(queue, event);
3779 ok(hr == S_OK, "Failed to queue event, hr %#lx.\n", hr);
3781 hr = IMFMediaEventQueue_GetEvent(queue, MF_EVENT_FLAG_NO_WAIT, &event2);
3782 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3783 ok(event2 == event, "Unexpected event object.\n");
3784 IMFMediaEvent_Release(event2);
3786 hr = IMFMediaEventQueue_QueueEvent(queue, event);
3787 ok(hr == S_OK, "Failed to queue event, hr %#lx.\n", hr);
3789 hr = IMFMediaEventQueue_GetEvent(queue, 0, &event2);
3790 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
3791 IMFMediaEvent_Release(event2);
3794 /* Async case. */
3795 hr = IMFMediaEventQueue_BeginGetEvent(queue, NULL, NULL);
3796 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3798 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback->IMFAsyncCallback_iface, (IUnknown *)queue);
3799 ok(hr == S_OK, "Failed to Begin*, hr %#lx.\n", hr);
3801 /* Same callback, same state. */
3802 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback->IMFAsyncCallback_iface, (IUnknown *)queue);
3803 ok(hr == MF_S_MULTIPLE_BEGIN, "Unexpected hr %#lx.\n", hr);
3805 /* Same callback, different state. */
3806 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback->IMFAsyncCallback_iface, (IUnknown *)&callback->IMFAsyncCallback_iface);
3807 ok(hr == MF_E_MULTIPLE_BEGIN, "Unexpected hr %#lx.\n", hr);
3809 /* Different callback, same state. */
3810 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback2->IMFAsyncCallback_iface, (IUnknown *)queue);
3811 ok(hr == MF_E_MULTIPLE_SUBSCRIBERS, "Unexpected hr %#lx.\n", hr);
3813 /* Different callback, different state. */
3814 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback2->IMFAsyncCallback_iface, (IUnknown *)&callback->IMFAsyncCallback_iface);
3815 ok(hr == MF_E_MULTIPLE_SUBSCRIBERS, "Unexpected hr %#lx.\n", hr);
3817 hr = IMFMediaEventQueue_QueueEvent(queue, event);
3818 ok(hr == S_OK, "Failed to queue event, hr %#lx.\n", hr);
3820 ret = WaitForSingleObject(callback->event, 500);
3821 ok(ret == WAIT_OBJECT_0, "Unexpected return value %#lx.\n", ret);
3823 IMFMediaEvent_Release(event);
3825 hr = MFCreateAsyncResult(NULL, &callback->IMFAsyncCallback_iface, NULL, &result);
3826 ok(hr == S_OK, "Failed to create result, hr %#lx.\n", hr);
3828 hr = IMFMediaEventQueue_EndGetEvent(queue, result, &event);
3829 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
3831 /* Shutdown behavior. */
3832 hr = IMFMediaEventQueue_Shutdown(queue);
3833 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3835 hr = IMFMediaEventQueue_GetEvent(queue, MF_EVENT_FLAG_NO_WAIT, &event);
3836 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3838 hr = MFCreateMediaEvent(MEError, &GUID_NULL, E_FAIL, NULL, &event);
3839 ok(hr == S_OK, "Failed to create event object, hr %#lx.\n", hr);
3840 hr = IMFMediaEventQueue_QueueEvent(queue, event);
3841 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3842 IMFMediaEvent_Release(event);
3844 hr = IMFMediaEventQueue_QueueEventParamUnk(queue, MEError, &GUID_NULL, E_FAIL, NULL);
3845 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3847 hr = IMFMediaEventQueue_QueueEventParamVar(queue, MEError, &GUID_NULL, E_FAIL, NULL);
3848 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3850 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback->IMFAsyncCallback_iface, NULL);
3851 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3853 hr = IMFMediaEventQueue_BeginGetEvent(queue, NULL, NULL);
3854 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3856 hr = IMFMediaEventQueue_EndGetEvent(queue, result, &event);
3857 ok(hr == MF_E_SHUTDOWN, "Unexpected hr %#lx.\n", hr);
3858 IMFAsyncResult_Release(result);
3860 /* Already shut down. */
3861 hr = IMFMediaEventQueue_Shutdown(queue);
3862 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3864 IMFMediaEventQueue_Release(queue);
3865 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
3867 /* Release while subscribed. */
3868 callback = create_test_callback(NULL);
3870 hr = MFCreateEventQueue(&queue);
3871 ok(hr == S_OK, "Failed to create event queue, hr %#lx.\n", hr);
3873 hr = IMFMediaEventQueue_BeginGetEvent(queue, &callback->IMFAsyncCallback_iface, NULL);
3874 ok(hr == S_OK, "Failed to Begin*, hr %#lx.\n", hr);
3875 EXPECT_REF(&callback->IMFAsyncCallback_iface, 2);
3877 IMFMediaEventQueue_Release(queue);
3878 ret = get_refcount(&callback->IMFAsyncCallback_iface);
3879 ok(ret == 1 || broken(ret == 2) /* Vista */,
3880 "Unexpected refcount %ld, expected 1.\n", ret);
3881 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
3883 hr = MFShutdown();
3884 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
3887 static void test_presentation_descriptor(void)
3889 IMFStreamDescriptor *stream_desc[2], *stream_desc2;
3890 IMFPresentationDescriptor *pd, *pd2;
3891 IMFMediaType *media_type;
3892 unsigned int i;
3893 BOOL selected;
3894 UINT64 value;
3895 DWORD count;
3896 HRESULT hr;
3898 hr = MFCreateMediaType(&media_type);
3899 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
3901 for (i = 0; i < ARRAY_SIZE(stream_desc); ++i)
3903 hr = MFCreateStreamDescriptor(0, 1, &media_type, &stream_desc[i]);
3904 ok(hr == S_OK, "Failed to create descriptor, hr %#lx.\n", hr);
3907 hr = MFCreatePresentationDescriptor(ARRAY_SIZE(stream_desc), stream_desc, &pd);
3908 ok(hr == S_OK, "Failed to create presentation descriptor, hr %#lx.\n", hr);
3910 hr = IMFPresentationDescriptor_GetStreamDescriptorCount(pd, &count);
3911 ok(count == ARRAY_SIZE(stream_desc), "Unexpected count %lu.\n", count);
3913 for (i = 0; i < count; ++i)
3915 hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd, i, &selected, &stream_desc2);
3916 ok(hr == S_OK, "Failed to get stream descriptor, hr %#lx.\n", hr);
3917 ok(!selected, "Unexpected selected state.\n");
3918 ok(stream_desc[i] == stream_desc2, "Unexpected object.\n");
3919 IMFStreamDescriptor_Release(stream_desc2);
3922 hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd, 10, &selected, &stream_desc2);
3923 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3925 hr = IMFPresentationDescriptor_SelectStream(pd, 10);
3926 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3928 hr = IMFPresentationDescriptor_SelectStream(pd, 0);
3929 ok(hr == S_OK, "Failed to select a stream, hr %#lx.\n", hr);
3931 hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd, 0, &selected, &stream_desc2);
3932 ok(hr == S_OK, "Failed to get stream descriptor, hr %#lx.\n", hr);
3933 ok(!!selected, "Unexpected selected state.\n");
3934 IMFStreamDescriptor_Release(stream_desc2);
3936 hr = IMFPresentationDescriptor_SetUINT64(pd, &MF_PD_TOTAL_FILE_SIZE, 1);
3937 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
3939 hr = IMFPresentationDescriptor_Clone(pd, &pd2);
3940 ok(hr == S_OK, "Failed to clone, hr %#lx.\n", hr);
3942 hr = IMFPresentationDescriptor_GetStreamDescriptorByIndex(pd2, 0, &selected, &stream_desc2);
3943 ok(hr == S_OK, "Failed to get stream descriptor, hr %#lx.\n", hr);
3944 ok(!!selected, "Unexpected selected state.\n");
3945 ok(stream_desc2 == stream_desc[0], "Unexpected stream descriptor.\n");
3946 IMFStreamDescriptor_Release(stream_desc2);
3948 value = 0;
3949 hr = IMFPresentationDescriptor_GetUINT64(pd2, &MF_PD_TOTAL_FILE_SIZE, &value);
3950 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
3951 ok(value == 1, "Unexpected attribute value.\n");
3953 IMFPresentationDescriptor_Release(pd2);
3954 IMFPresentationDescriptor_Release(pd);
3956 for (i = 0; i < ARRAY_SIZE(stream_desc); ++i)
3958 IMFStreamDescriptor_Release(stream_desc[i]);
3961 /* Partially initialized array. */
3962 hr = MFCreateStreamDescriptor(0, 1, &media_type, &stream_desc[1]);
3963 ok(hr == S_OK, "Failed to create descriptor, hr %#lx.\n", hr);
3964 stream_desc[0] = NULL;
3966 hr = MFCreatePresentationDescriptor(ARRAY_SIZE(stream_desc), stream_desc, &pd);
3967 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
3969 IMFStreamDescriptor_Release(stream_desc[1]);
3970 IMFMediaType_Release(media_type);
3973 enum clock_action
3975 CLOCK_START,
3976 CLOCK_STOP,
3977 CLOCK_PAUSE,
3978 CLOCK_RESTART,
3981 static void test_system_time_source(void)
3983 static const struct clock_state_test
3985 enum clock_action action;
3986 MFCLOCK_STATE state;
3987 BOOL is_invalid;
3989 clock_state_change[] =
3991 { CLOCK_STOP, MFCLOCK_STATE_INVALID },
3992 { CLOCK_RESTART, MFCLOCK_STATE_INVALID, TRUE },
3993 { CLOCK_PAUSE, MFCLOCK_STATE_PAUSED },
3994 { CLOCK_PAUSE, MFCLOCK_STATE_PAUSED, TRUE },
3995 { CLOCK_STOP, MFCLOCK_STATE_STOPPED },
3996 { CLOCK_STOP, MFCLOCK_STATE_STOPPED },
3997 { CLOCK_RESTART, MFCLOCK_STATE_STOPPED, TRUE },
3998 { CLOCK_START, MFCLOCK_STATE_RUNNING },
3999 { CLOCK_START, MFCLOCK_STATE_RUNNING },
4000 { CLOCK_RESTART, MFCLOCK_STATE_RUNNING, TRUE },
4001 { CLOCK_PAUSE, MFCLOCK_STATE_PAUSED },
4002 { CLOCK_START, MFCLOCK_STATE_RUNNING },
4003 { CLOCK_PAUSE, MFCLOCK_STATE_PAUSED },
4004 { CLOCK_RESTART, MFCLOCK_STATE_RUNNING },
4005 { CLOCK_RESTART, MFCLOCK_STATE_RUNNING, TRUE },
4006 { CLOCK_STOP, MFCLOCK_STATE_STOPPED },
4007 { CLOCK_PAUSE, MFCLOCK_STATE_STOPPED, TRUE },
4009 IMFPresentationTimeSource *time_source, *time_source2;
4010 IMFClockStateSink *statesink;
4011 IMFClock *clock, *clock2;
4012 MFCLOCK_PROPERTIES props;
4013 MFCLOCK_STATE state;
4014 unsigned int i;
4015 MFTIME systime;
4016 LONGLONG time;
4017 DWORD value;
4018 HRESULT hr;
4020 hr = MFCreateSystemTimeSource(&time_source);
4021 ok(hr == S_OK, "Failed to create time source, hr %#lx.\n", hr);
4023 hr = IMFPresentationTimeSource_GetClockCharacteristics(time_source, &value);
4024 ok(hr == S_OK, "Failed to get flags, hr %#lx.\n", hr);
4025 ok(value == (MFCLOCK_CHARACTERISTICS_FLAG_FREQUENCY_10MHZ | MFCLOCK_CHARACTERISTICS_FLAG_IS_SYSTEM_CLOCK),
4026 "Unexpected flags %#lx.\n", value);
4028 value = 1;
4029 hr = IMFPresentationTimeSource_GetContinuityKey(time_source, &value);
4030 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4031 ok(value == 0, "Unexpected value %lu.\n", value);
4033 hr = IMFPresentationTimeSource_GetState(time_source, 0, &state);
4034 ok(hr == S_OK, "Failed to get state, hr %#lx.\n", hr);
4035 ok(state == MFCLOCK_STATE_INVALID, "Unexpected state %d.\n", state);
4037 hr = IMFPresentationTimeSource_QueryInterface(time_source, &IID_IMFClockStateSink, (void **)&statesink);
4038 ok(hr == S_OK, "Failed to get state sink, hr %#lx.\n", hr);
4040 /* State changes. */
4041 for (i = 0; i < ARRAY_SIZE(clock_state_change); ++i)
4043 switch (clock_state_change[i].action)
4045 case CLOCK_STOP:
4046 hr = IMFClockStateSink_OnClockStop(statesink, 0);
4047 break;
4048 case CLOCK_RESTART:
4049 hr = IMFClockStateSink_OnClockRestart(statesink, 0);
4050 break;
4051 case CLOCK_PAUSE:
4052 hr = IMFClockStateSink_OnClockPause(statesink, 0);
4053 break;
4054 case CLOCK_START:
4055 hr = IMFClockStateSink_OnClockStart(statesink, 0, 0);
4056 break;
4057 default:
4060 ok(hr == (clock_state_change[i].is_invalid ? MF_E_INVALIDREQUEST : S_OK), "%u: unexpected hr %#lx.\n", i, hr);
4061 hr = IMFPresentationTimeSource_GetState(time_source, 0, &state);
4062 ok(hr == S_OK, "%u: failed to get state, hr %#lx.\n", i, hr);
4063 ok(state == clock_state_change[i].state, "%u: unexpected state %d.\n", i, state);
4066 IMFClockStateSink_Release(statesink);
4068 /* Properties. */
4069 hr = IMFPresentationTimeSource_GetProperties(time_source, NULL);
4070 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
4072 hr = IMFPresentationTimeSource_GetProperties(time_source, &props);
4073 ok(hr == S_OK, "Failed to get clock properties, hr %#lx.\n", hr);
4075 ok(props.qwCorrelationRate == 0, "Unexpected correlation rate %s.\n",
4076 wine_dbgstr_longlong(props.qwCorrelationRate));
4077 ok(IsEqualGUID(&props.guidClockId, &GUID_NULL), "Unexpected clock id %s.\n", wine_dbgstr_guid(&props.guidClockId));
4078 ok(props.dwClockFlags == 0, "Unexpected flags %#lx.\n", props.dwClockFlags);
4079 ok(props.qwClockFrequency == MFCLOCK_FREQUENCY_HNS, "Unexpected frequency %s.\n",
4080 wine_dbgstr_longlong(props.qwClockFrequency));
4081 ok(props.dwClockTolerance == MFCLOCK_TOLERANCE_UNKNOWN, "Unexpected tolerance %lu.\n", props.dwClockTolerance);
4082 ok(props.dwClockJitter == 1, "Unexpected jitter %lu.\n", props.dwClockJitter);
4084 /* Underlying clock. */
4085 hr = MFCreateSystemTimeSource(&time_source2);
4086 ok(hr == S_OK, "Failed to create time source, hr %#lx.\n", hr);
4087 EXPECT_REF(time_source2, 1);
4088 hr = IMFPresentationTimeSource_GetUnderlyingClock(time_source2, &clock2);
4089 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4090 EXPECT_REF(time_source2, 1);
4091 EXPECT_REF(clock2, 2);
4093 EXPECT_REF(time_source, 1);
4094 hr = IMFPresentationTimeSource_GetUnderlyingClock(time_source, &clock);
4095 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4096 EXPECT_REF(time_source, 1);
4097 EXPECT_REF(clock, 2);
4099 ok(clock != clock2, "Unexpected clock instance.\n");
4101 IMFPresentationTimeSource_Release(time_source2);
4102 IMFClock_Release(clock2);
4104 hr = IMFClock_GetClockCharacteristics(clock, &value);
4105 ok(hr == S_OK, "Failed to get clock flags, hr %#lx.\n", hr);
4106 ok(value == (MFCLOCK_CHARACTERISTICS_FLAG_FREQUENCY_10MHZ | MFCLOCK_CHARACTERISTICS_FLAG_ALWAYS_RUNNING |
4107 MFCLOCK_CHARACTERISTICS_FLAG_IS_SYSTEM_CLOCK), "Unexpected flags %#lx.\n", value);
4109 hr = IMFClock_GetContinuityKey(clock, &value);
4110 ok(hr == S_OK, "Failed to get clock key, hr %#lx.\n", hr);
4111 ok(value == 0, "Unexpected key value %lu.\n", value);
4113 hr = IMFClock_GetState(clock, 0, &state);
4114 ok(hr == S_OK, "Failed to get clock state, hr %#lx.\n", hr);
4115 ok(state == MFCLOCK_STATE_RUNNING, "Unexpected state %d.\n", state);
4117 hr = IMFClock_GetProperties(clock, &props);
4118 ok(hr == S_OK, "Failed to get clock properties, hr %#lx.\n", hr);
4120 ok(props.qwCorrelationRate == 0, "Unexpected correlation rate %s.\n",
4121 wine_dbgstr_longlong(props.qwCorrelationRate));
4122 ok(IsEqualGUID(&props.guidClockId, &GUID_NULL), "Unexpected clock id %s.\n", wine_dbgstr_guid(&props.guidClockId));
4123 ok(props.dwClockFlags == 0, "Unexpected flags %#lx.\n", props.dwClockFlags);
4124 ok(props.qwClockFrequency == MFCLOCK_FREQUENCY_HNS, "Unexpected frequency %s.\n",
4125 wine_dbgstr_longlong(props.qwClockFrequency));
4126 ok(props.dwClockTolerance == MFCLOCK_TOLERANCE_UNKNOWN, "Unexpected tolerance %lu.\n", props.dwClockTolerance);
4127 ok(props.dwClockJitter == 1, "Unexpected jitter %lu.\n", props.dwClockJitter);
4129 hr = IMFClock_GetCorrelatedTime(clock, 0, &time, &systime);
4130 ok(hr == S_OK, "Failed to get clock time, hr %#lx.\n", hr);
4131 ok(time == systime, "Unexpected time %s, %s.\n", wine_dbgstr_longlong(time), wine_dbgstr_longlong(systime));
4133 IMFClock_Release(clock);
4135 /* Test returned time regarding specified rate and offset. */
4136 hr = IMFPresentationTimeSource_QueryInterface(time_source, &IID_IMFClockStateSink, (void **)&statesink);
4137 ok(hr == S_OK, "Failed to get sink interface, hr %#lx.\n", hr);
4139 hr = IMFPresentationTimeSource_GetState(time_source, 0, &state);
4140 ok(hr == S_OK, "Failed to get state %#lx.\n", hr);
4141 ok(state == MFCLOCK_STATE_STOPPED, "Unexpected state %d.\n", state);
4143 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4144 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4145 ok(time == 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time), wine_dbgstr_longlong(systime));
4147 hr = IMFClockStateSink_OnClockStart(statesink, 0, 0);
4148 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4150 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4151 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4152 ok(time == systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time), wine_dbgstr_longlong(systime));
4154 hr = IMFClockStateSink_OnClockStart(statesink, 0, 1);
4155 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4157 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4158 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4159 ok(time == systime + 1, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4160 wine_dbgstr_longlong(systime));
4162 hr = IMFClockStateSink_OnClockPause(statesink, 2);
4163 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4165 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4166 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4167 ok(time == 3, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time), wine_dbgstr_longlong(systime));
4169 hr = IMFClockStateSink_OnClockRestart(statesink, 5);
4170 ok(hr == S_OK, "Failed to restart source, hr %#lx.\n", hr);
4172 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4173 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4174 ok(time == systime - 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4175 wine_dbgstr_longlong(systime));
4177 hr = IMFClockStateSink_OnClockPause(statesink, 0);
4178 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4180 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4181 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4182 ok(time == -2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4183 wine_dbgstr_longlong(systime));
4185 hr = IMFClockStateSink_OnClockStop(statesink, 123);
4186 ok(hr == S_OK, "Failed to stop source, hr %#lx.\n", hr);
4188 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4189 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4190 ok(time == 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time), wine_dbgstr_longlong(systime));
4192 /* Increased rate. */
4193 hr = IMFClockStateSink_OnClockSetRate(statesink, 0, 2.0f);
4194 ok(hr == S_OK, "Failed to set rate, hr %#lx.\n", hr);
4196 hr = IMFClockStateSink_OnClockStart(statesink, 0, 0);
4197 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4199 hr = IMFClockStateSink_OnClockSetRate(statesink, 5, 2.0f);
4200 ok(hr == S_OK, "Failed to set rate, hr %#lx.\n", hr);
4202 hr = IMFClockStateSink_OnClockPause(statesink, 6);
4203 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4205 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4206 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4207 ok(time == 12 && !!systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4208 wine_dbgstr_longlong(systime));
4210 hr = IMFClockStateSink_OnClockRestart(statesink, 7);
4211 ok(hr == S_OK, "Failed to restart source, hr %#lx.\n", hr);
4213 hr = IMFClockStateSink_OnClockPause(statesink, 8);
4214 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4216 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4217 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4218 ok(time == 14 && !!systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4219 wine_dbgstr_longlong(systime));
4221 hr = IMFClockStateSink_OnClockStart(statesink, 0, 0);
4222 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4224 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4225 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4226 ok(time == 2 * systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4227 wine_dbgstr_longlong(2 * systime));
4229 hr = IMFClockStateSink_OnClockStart(statesink, 0, 10);
4230 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4232 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4233 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4234 ok(time == 2 * systime + 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4235 wine_dbgstr_longlong(2 * systime));
4237 hr = IMFClockStateSink_OnClockPause(statesink, 2);
4238 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4240 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4241 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4242 ok(time == 10 + 2 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4243 wine_dbgstr_longlong(systime));
4245 hr = IMFClockStateSink_OnClockRestart(statesink, 5);
4246 ok(hr == S_OK, "Failed to restart source, hr %#lx.\n", hr);
4248 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4249 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4250 ok(time == 2 * systime + 14 - 5 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4251 wine_dbgstr_longlong(systime));
4253 hr = IMFClockStateSink_OnClockPause(statesink, 0);
4254 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4256 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4257 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4258 ok(time == 4, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4259 wine_dbgstr_longlong(systime));
4261 hr = IMFClockStateSink_OnClockStop(statesink, 123);
4262 ok(hr == S_OK, "Failed to stop source, hr %#lx.\n", hr);
4264 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4265 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4266 ok(time == 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time), wine_dbgstr_longlong(systime));
4268 hr = IMFClockStateSink_OnClockStart(statesink, 10, 0);
4269 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4271 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4272 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4273 ok(time == 2 * systime - 2 * 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4274 wine_dbgstr_longlong(2 * systime));
4276 hr = IMFClockStateSink_OnClockStop(statesink, 123);
4277 ok(hr == S_OK, "Failed to stop source, hr %#lx.\n", hr);
4279 hr = IMFClockStateSink_OnClockStart(statesink, 10, 20);
4280 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4282 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4283 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4284 ok(time == 2 * systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4285 wine_dbgstr_longlong(2 * systime));
4287 hr = IMFClockStateSink_OnClockPause(statesink, 2);
4288 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4290 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4291 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4292 ok(time == 2 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4293 wine_dbgstr_longlong(systime));
4295 hr = IMFClockStateSink_OnClockRestart(statesink, 5);
4296 ok(hr == S_OK, "Failed to restart source, hr %#lx.\n", hr);
4298 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4299 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4300 ok(time == 2 * systime + 4 - 5 * 2, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4301 wine_dbgstr_longlong(systime));
4303 hr = IMFClockStateSink_OnClockPause(statesink, 0);
4304 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4306 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4307 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4308 ok(time == -6, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4309 wine_dbgstr_longlong(systime));
4311 IMFClockStateSink_Release(statesink);
4312 IMFPresentationTimeSource_Release(time_source);
4314 /* PRESENTATION_CURRENT_POSITION */
4315 hr = MFCreateSystemTimeSource(&time_source);
4316 ok(hr == S_OK, "Failed to create time source, hr %#lx.\n", hr);
4318 hr = IMFPresentationTimeSource_QueryInterface(time_source, &IID_IMFClockStateSink, (void **)&statesink);
4319 ok(hr == S_OK, "Failed to get sink interface, hr %#lx.\n", hr);
4321 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4322 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4323 ok(!time && systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4324 wine_dbgstr_longlong(systime));
4326 /* INVALID -> RUNNING */
4327 hr = IMFClockStateSink_OnClockStart(statesink, 10, PRESENTATION_CURRENT_POSITION);
4328 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4330 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4331 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4332 ok(time == systime - 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4333 wine_dbgstr_longlong(systime));
4335 /* RUNNING -> RUNNING */
4336 hr = IMFClockStateSink_OnClockStart(statesink, 20, PRESENTATION_CURRENT_POSITION);
4337 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4339 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4340 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4341 ok(time == systime - 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4342 wine_dbgstr_longlong(systime));
4344 hr = IMFClockStateSink_OnClockStart(statesink, 0, PRESENTATION_CURRENT_POSITION);
4345 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4347 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4348 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4349 ok(time == systime - 10, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4350 wine_dbgstr_longlong(systime));
4352 hr = IMFClockStateSink_OnClockStart(statesink, 0, 0);
4353 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4355 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4356 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4357 ok(time == systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4358 wine_dbgstr_longlong(systime));
4360 hr = IMFClockStateSink_OnClockStart(statesink, 30, PRESENTATION_CURRENT_POSITION);
4361 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4363 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4364 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4365 ok(time == systime, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4366 wine_dbgstr_longlong(systime));
4368 /* STOPPED -> RUNNING */
4369 hr = IMFClockStateSink_OnClockStop(statesink, 567);
4370 ok(hr == S_OK, "Failed to stop source, hr %#lx.\n", hr);
4372 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4373 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4374 ok(!time && systime != 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4375 wine_dbgstr_longlong(systime));
4377 hr = IMFClockStateSink_OnClockStart(statesink, 30, PRESENTATION_CURRENT_POSITION);
4378 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4380 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4381 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4382 ok(time == systime - 30, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4383 wine_dbgstr_longlong(systime));
4385 /* PAUSED -> RUNNING */
4386 hr = IMFClockStateSink_OnClockPause(statesink, 8);
4387 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4389 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4390 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4391 ok(time == (-30 + 8) && systime != 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4392 wine_dbgstr_longlong(systime));
4394 hr = IMFClockStateSink_OnClockStart(statesink, 40, PRESENTATION_CURRENT_POSITION);
4395 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4397 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4398 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4399 ok(time == systime + (-30 + 8 - 40), "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4400 wine_dbgstr_longlong(systime));
4402 hr = IMFClockStateSink_OnClockPause(statesink, 7);
4403 ok(hr == S_OK, "Failed to pause source, hr %#lx.\n", hr);
4405 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4406 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4407 ok(time == (-30 + 8 - 40 + 7) && systime != 0, "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4408 wine_dbgstr_longlong(systime));
4410 hr = IMFClockStateSink_OnClockStart(statesink, 50, 7);
4411 ok(hr == S_OK, "Failed to start source, hr %#lx.\n", hr);
4413 hr = IMFPresentationTimeSource_GetCorrelatedTime(time_source, 0, &time, &systime);
4414 ok(hr == S_OK, "Failed to get time %#lx.\n", hr);
4415 ok(time == systime + (-50 + 7), "Unexpected time stamp %s, %s.\n", wine_dbgstr_longlong(time),
4416 wine_dbgstr_longlong(systime));
4418 IMFClockStateSink_Release(statesink);
4419 IMFPresentationTimeSource_Release(time_source);
4422 static void test_MFInvokeCallback(void)
4424 struct test_callback *callback;
4425 IMFAsyncResult *result;
4426 MFASYNCRESULT *data;
4427 ULONG refcount;
4428 HRESULT hr;
4429 DWORD ret;
4431 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
4432 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
4434 callback = create_test_callback(NULL);
4436 hr = MFCreateAsyncResult(NULL, &callback->IMFAsyncCallback_iface, NULL, &result);
4437 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
4439 data = (MFASYNCRESULT *)result;
4440 data->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
4441 ok(data->hEvent != NULL, "Failed to create event.\n");
4443 hr = MFInvokeCallback(result);
4444 ok(hr == S_OK, "Failed to invoke, hr %#lx.\n", hr);
4446 ret = WaitForSingleObject(data->hEvent, 100);
4447 ok(ret == WAIT_TIMEOUT, "Expected timeout, ret %#lx.\n", ret);
4449 refcount = IMFAsyncResult_Release(result);
4450 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
4452 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
4454 hr = MFShutdown();
4455 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
4458 static void test_stream_descriptor(void)
4460 IMFMediaType *media_types[2], *media_type, *media_type2, *media_type3;
4461 IMFMediaTypeHandler *type_handler;
4462 IMFStreamDescriptor *stream_desc;
4463 GUID major_type;
4464 DWORD id, count;
4465 unsigned int i;
4466 HRESULT hr;
4468 hr = MFCreateStreamDescriptor(123, 0, NULL, &stream_desc);
4469 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
4471 for (i = 0; i < ARRAY_SIZE(media_types); ++i)
4473 hr = MFCreateMediaType(&media_types[i]);
4474 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
4477 hr = MFCreateStreamDescriptor(123, 0, media_types, &stream_desc);
4478 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
4480 hr = MFCreateStreamDescriptor(123, ARRAY_SIZE(media_types), media_types, &stream_desc);
4481 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4483 hr = IMFStreamDescriptor_GetStreamIdentifier(stream_desc, &id);
4484 ok(hr == S_OK, "Failed to get descriptor id, hr %#lx.\n", hr);
4485 ok(id == 123, "Unexpected id %#lx.\n", id);
4487 hr = IMFStreamDescriptor_GetMediaTypeHandler(stream_desc, &type_handler);
4488 ok(hr == S_OK, "Failed to get type handler, hr %#lx.\n", hr);
4490 hr = IMFMediaTypeHandler_GetMediaTypeCount(type_handler, &count);
4491 ok(hr == S_OK, "Failed to get type count, hr %#lx.\n", hr);
4492 ok(count == ARRAY_SIZE(media_types), "Unexpected type count.\n");
4494 hr = IMFMediaTypeHandler_GetCurrentMediaType(type_handler, &media_type);
4495 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
4497 hr = IMFMediaTypeHandler_GetMajorType(type_handler, &major_type);
4498 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
4500 for (i = 0; i < ARRAY_SIZE(media_types); ++i)
4502 hr = IMFMediaTypeHandler_GetMediaTypeByIndex(type_handler, i, &media_type);
4503 ok(hr == S_OK, "Failed to get media type, hr %#lx.\n", hr);
4504 ok(media_type == media_types[i], "Unexpected object.\n");
4506 if (SUCCEEDED(hr))
4507 IMFMediaType_Release(media_type);
4510 hr = IMFMediaTypeHandler_GetMediaTypeByIndex(type_handler, 2, &media_type);
4511 ok(hr == MF_E_NO_MORE_TYPES, "Unexpected hr %#lx.\n", hr);
4513 /* IsMediaTypeSupported() */
4515 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, NULL, NULL);
4516 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
4518 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, NULL, &media_type2);
4519 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
4521 hr = MFCreateMediaType(&media_type);
4522 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
4524 hr = MFCreateMediaType(&media_type3);
4525 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
4527 media_type2 = (void *)0xdeadbeef;
4528 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type, &media_type2);
4529 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4530 ok(!media_type2, "Unexpected pointer.\n");
4532 hr = IMFMediaTypeHandler_SetCurrentMediaType(type_handler, NULL);
4533 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
4535 hr = IMFMediaTypeHandler_SetCurrentMediaType(type_handler, media_type);
4536 ok(hr == S_OK, "Failed to set current type, hr %#lx.\n", hr);
4538 media_type2 = (void *)0xdeadbeef;
4539 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type, &media_type2);
4540 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4541 ok(!media_type2, "Unexpected pointer.\n");
4543 hr = IMFMediaTypeHandler_GetMajorType(type_handler, &major_type);
4544 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
4546 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
4547 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
4549 hr = IMFMediaTypeHandler_GetMajorType(type_handler, &major_type);
4550 ok(hr == S_OK, "Failed to get major type, hr %#lx.\n", hr);
4551 ok(IsEqualGUID(&major_type, &MFMediaType_Audio), "Unexpected major type.\n");
4553 /* Mismatching major types. */
4554 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
4555 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
4557 media_type2 = (void *)0xdeadbeef;
4558 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4559 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4560 ok(!media_type2, "Unexpected pointer.\n");
4562 /* Subtype missing. */
4563 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
4564 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
4566 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
4567 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
4569 media_type2 = (void *)0xdeadbeef;
4570 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4571 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4572 ok(!media_type2, "Unexpected pointer.\n");
4574 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
4575 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
4577 media_type2 = (void *)0xdeadbeef;
4578 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4579 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4580 ok(!media_type2, "Unexpected pointer.\n");
4582 /* Mismatching subtype. */
4583 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_SUBTYPE, &MFAudioFormat_MP3);
4584 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
4586 media_type2 = (void *)0xdeadbeef;
4587 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4588 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4589 ok(!media_type2, "Unexpected pointer.\n");
4591 hr = IMFMediaTypeHandler_GetMediaTypeCount(type_handler, &count);
4592 ok(hr == S_OK, "Failed to get type count, hr %#lx.\n", hr);
4593 ok(count == ARRAY_SIZE(media_types), "Unexpected type count.\n");
4595 IMFMediaTypeHandler_Release(type_handler);
4596 IMFStreamDescriptor_Release(stream_desc);
4598 /* IsMediaTypeSupported() for unset current type. */
4599 hr = MFCreateStreamDescriptor(123, ARRAY_SIZE(media_types), media_types, &stream_desc);
4600 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4602 hr = IMFStreamDescriptor_GetMediaTypeHandler(stream_desc, &type_handler);
4603 ok(hr == S_OK, "Failed to get type handler, hr %#lx.\n", hr);
4605 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, NULL);
4606 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4608 /* Initialize one from initial type set. */
4609 hr = IMFMediaType_CopyAllItems(media_type3, (IMFAttributes *)media_types[0]);
4610 ok(hr == S_OK, "Failed to copy attributes, hr %#lx.\n", hr);
4612 media_type2 = (void *)0xdeadbeef;
4613 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4614 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4615 ok(!media_type2, "Unexpected pointer.\n");
4617 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
4618 ok(hr == S_OK, "Failed to copy attributes, hr %#lx.\n", hr);
4620 media_type2 = (void *)0xdeadbeef;
4621 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4622 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
4623 ok(!media_type2, "Unexpected pointer.\n");
4625 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_SUBTYPE, &MFAudioFormat_MP3);
4626 ok(hr == S_OK, "Failed to copy attributes, hr %#lx.\n", hr);
4628 media_type2 = (void *)0xdeadbeef;
4629 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4630 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4631 ok(!media_type2, "Unexpected pointer.\n");
4633 /* Now set current type that's not compatible. */
4634 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
4635 ok(hr == S_OK, "Failed to copy attributes, hr %#lx.\n", hr);
4637 hr = IMFMediaType_SetGUID(media_type3, &MF_MT_SUBTYPE, &MFVideoFormat_RGB8);
4638 ok(hr == S_OK, "Failed to copy attributes, hr %#lx.\n", hr);
4640 hr = IMFMediaTypeHandler_SetCurrentMediaType(type_handler, media_type3);
4641 ok(hr == S_OK, "Failed to set current type, hr %#lx.\n", hr);
4643 media_type2 = (void *)0xdeadbeef;
4644 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type3, &media_type2);
4645 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4646 ok(!media_type2, "Unexpected pointer.\n");
4648 hr = IMFMediaType_CopyAllItems(media_types[0], (IMFAttributes *)media_type);
4649 ok(hr == S_OK, "Failed to copy attributes, hr %#lx.\n", hr);
4651 media_type2 = (void *)0xdeadbeef;
4652 hr = IMFMediaTypeHandler_IsMediaTypeSupported(type_handler, media_type, &media_type2);
4653 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4654 ok(!media_type2, "Unexpected pointer.\n");
4656 IMFMediaType_Release(media_type);
4657 IMFMediaType_Release(media_type3);
4659 IMFMediaTypeHandler_Release(type_handler);
4661 IMFStreamDescriptor_Release(stream_desc);
4663 /* Major type is returned for first entry. */
4664 hr = MFCreateMediaType(&media_types[0]);
4665 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4666 hr = MFCreateMediaType(&media_types[1]);
4667 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4669 hr = IMFMediaType_SetGUID(media_types[0], &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
4670 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4671 hr = IMFMediaType_SetGUID(media_types[1], &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
4672 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4674 hr = MFCreateStreamDescriptor(0, 2, media_types, &stream_desc);
4675 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4677 hr = IMFStreamDescriptor_GetMediaTypeHandler(stream_desc, &type_handler);
4678 ok(hr == S_OK, "Failed to get type handler, hr %#lx.\n", hr);
4680 hr = IMFMediaTypeHandler_GetMajorType(type_handler, &major_type);
4681 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4682 ok(IsEqualGUID(&major_type, &MFMediaType_Audio), "Unexpected major type %s.\n", wine_dbgstr_guid(&major_type));
4684 hr = IMFMediaType_SetGUID(media_types[0], &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
4685 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4686 hr = IMFMediaType_SetGUID(media_types[1], &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
4687 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4689 hr = IMFMediaTypeHandler_GetMajorType(type_handler, &major_type);
4690 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4691 ok(IsEqualGUID(&major_type, &MFMediaType_Video), "Unexpected major type %s.\n", wine_dbgstr_guid(&major_type));
4693 IMFMediaType_Release(media_types[0]);
4694 IMFMediaType_Release(media_types[1]);
4696 IMFMediaTypeHandler_Release(type_handler);
4697 IMFStreamDescriptor_Release(stream_desc);
4700 static const struct image_size_test
4702 const GUID *subtype;
4703 UINT32 width;
4704 UINT32 height;
4705 UINT32 size;
4706 UINT32 plane_size; /* Matches image size when 0. */
4707 UINT32 max_length;
4708 UINT32 contiguous_length;
4709 UINT32 pitch;
4711 image_size_tests[] =
4713 /* RGB */
4714 { &MFVideoFormat_RGB8, 3, 5, 20, 0, 320, 20, 64 },
4715 { &MFVideoFormat_RGB8, 1, 1, 4, 0, 64, 4, 64 },
4716 { &MFVideoFormat_RGB8, 320, 240, 76800, 0, 76800, 76800, 320 },
4717 { &MFVideoFormat_RGB555, 3, 5, 40, 0, 320, 40, 64 },
4718 { &MFVideoFormat_RGB555, 1, 1, 4, 0, 64, 4, 64 },
4719 { &MFVideoFormat_RGB555, 320, 240, 153600, 0, 153600, 153600, 640 },
4720 { &MFVideoFormat_RGB565, 3, 5, 40, 0, 320, 40, 64 },
4721 { &MFVideoFormat_RGB565, 1, 1, 4, 0, 64, 4, 64 },
4722 { &MFVideoFormat_RGB565, 320, 240, 153600, 0, 153600, 153600, 640 },
4723 { &MFVideoFormat_RGB24, 3, 5, 60, 0, 320, 60, 64 },
4724 { &MFVideoFormat_RGB24, 1, 1, 4, 0, 64, 4, 64 },
4725 { &MFVideoFormat_RGB24, 4, 3, 36, 0, 192, 36, 64 },
4726 { &MFVideoFormat_RGB24, 320, 240, 230400, 0, 230400, 230400, 960 },
4727 { &MFVideoFormat_RGB32, 3, 5, 60, 0, 320, 60, 64 },
4728 { &MFVideoFormat_RGB32, 1, 1, 4, 0, 64, 4, 64 },
4729 { &MFVideoFormat_RGB32, 320, 240, 307200, 0, 307200, 307200, 1280 },
4730 { &MFVideoFormat_ARGB32, 3, 5, 60, 0, 320, 60, 64 },
4731 { &MFVideoFormat_ARGB32, 1, 1, 4, 0, 64, 4, 64 },
4732 { &MFVideoFormat_ARGB32, 320, 240, 307200, 0, 307200, 307200, 1280 },
4733 { &MFVideoFormat_A2R10G10B10, 3, 5, 60, 0, 320, 60, 64 },
4734 { &MFVideoFormat_A2R10G10B10, 1, 1, 4, 0, 64, 4, 64 },
4735 { &MFVideoFormat_A2R10G10B10, 320, 240, 307200, 0, 307200, 307200, 1280 },
4736 { &MFVideoFormat_A2B10G10R10, 3, 5, 60, 0, 320, 60, 64 },
4737 { &MFVideoFormat_A2B10G10R10, 1, 1, 4, 0, 64, 4, 64 },
4738 { &MFVideoFormat_A2B10G10R10, 320, 240, 307200, 0, 307200, 307200, 1280 },
4739 { &MFVideoFormat_A16B16G16R16F, 3, 5, 120, 0, 320, 120, 64 },
4740 { &MFVideoFormat_A16B16G16R16F, 1, 1, 8, 0, 64, 8, 64 },
4741 { &MFVideoFormat_A16B16G16R16F, 320, 240, 614400, 0, 614400, 614400, 2560 },
4743 { &MEDIASUBTYPE_RGB8, 3, 5, 20 },
4744 { &MEDIASUBTYPE_RGB8, 1, 1, 4 },
4745 { &MEDIASUBTYPE_RGB555, 3, 5, 40 },
4746 { &MEDIASUBTYPE_RGB555, 1, 1, 4 },
4747 { &MEDIASUBTYPE_RGB565, 3, 5, 40 },
4748 { &MEDIASUBTYPE_RGB565, 1, 1, 4 },
4749 { &MEDIASUBTYPE_RGB24, 3, 5, 60 },
4750 { &MEDIASUBTYPE_RGB24, 1, 1, 4 },
4751 { &MEDIASUBTYPE_RGB24, 4, 3, 36 },
4752 { &MEDIASUBTYPE_RGB32, 3, 5, 60 },
4753 { &MEDIASUBTYPE_RGB32, 1, 1, 4 },
4755 /* YUV 4:4:4, 32 bpp, packed */
4756 { &MFVideoFormat_AYUV, 1, 1, 4, 0, 64, 4, 64 },
4757 { &MFVideoFormat_AYUV, 2, 1, 8, 0, 64, 8, 64 },
4758 { &MFVideoFormat_AYUV, 1, 2, 8, 0, 128, 8, 64 },
4759 { &MFVideoFormat_AYUV, 4, 3, 48, 0, 192, 48, 64 },
4760 { &MFVideoFormat_AYUV, 320, 240, 307200, 0, 307200, 307200, 1280 },
4762 /* YUV 4:2:2, 16 bpp, packed */
4763 { &MFVideoFormat_YUY2, 2, 1, 4, 0, 64, 4, 64 },
4764 { &MFVideoFormat_YUY2, 4, 3, 24, 0, 192, 24, 64 },
4765 { &MFVideoFormat_YUY2, 128, 128, 32768, 0, 32768, 32768, 256 },
4766 { &MFVideoFormat_YUY2, 320, 240, 153600, 0, 153600, 153600, 640 },
4768 { &MFVideoFormat_UYVY, 2, 1, 4, 0, 64, 4, 64 },
4769 { &MFVideoFormat_UYVY, 4, 3, 24, 0, 192, 24, 64 },
4770 { &MFVideoFormat_UYVY, 128, 128, 32768, 0, 32768, 32768, 256 },
4771 { &MFVideoFormat_UYVY, 320, 240, 153600, 0, 153600, 153600, 640 },
4773 /* YUV 4:2:0, 16 bpp, planar (the secondary plane has the same
4774 * height, half the width and the same stride as the primary
4775 * one) */
4776 { &MFVideoFormat_IMC1, 1, 1, 4, 0, 256, 8, 128 },
4777 { &MFVideoFormat_IMC1, 2, 1, 4, 0, 256, 8, 128 },
4778 { &MFVideoFormat_IMC1, 1, 2, 8, 0, 512, 16, 128 },
4779 { &MFVideoFormat_IMC1, 2, 2, 8, 0, 512, 16, 128 },
4780 { &MFVideoFormat_IMC1, 2, 4, 16, 0, 1024, 32, 128 },
4781 { &MFVideoFormat_IMC1, 4, 2, 16, 0, 512, 32, 128 },
4782 { &MFVideoFormat_IMC1, 4, 3, 24, 0, 768, 48, 128 },
4783 { &MFVideoFormat_IMC1, 320, 240, 153600, 0, 307200, 307200, 640 },
4785 { &MFVideoFormat_IMC3, 1, 1, 4, 0, 256, 8, 128 },
4786 { &MFVideoFormat_IMC3, 2, 1, 4, 0, 256, 8, 128 },
4787 { &MFVideoFormat_IMC3, 1, 2, 8, 0, 512, 16, 128 },
4788 { &MFVideoFormat_IMC3, 2, 2, 8, 0, 512, 16, 128 },
4789 { &MFVideoFormat_IMC3, 2, 4, 16, 0, 1024, 32, 128 },
4790 { &MFVideoFormat_IMC3, 4, 2, 16, 0, 512, 32, 128 },
4791 { &MFVideoFormat_IMC3, 4, 3, 24, 0, 768, 48, 128 },
4792 { &MFVideoFormat_IMC3, 320, 240, 153600, 0, 307200, 307200, 640 },
4794 /* YUV 4:2:0, 12 bpp, planar, full stride (the secondary plane has
4795 * half the height, the same width and the same stride as the
4796 * primary one) */
4797 { &MFVideoFormat_NV12, 1, 3, 9, 4, 288, 4, 64 },
4798 { &MFVideoFormat_NV12, 1, 2, 6, 3, 192, 3, 64 },
4799 { &MFVideoFormat_NV12, 2, 2, 6, 6, 192, 6, 64 },
4800 { &MFVideoFormat_NV12, 2, 4, 12, 0, 384, 12, 64 },
4801 { &MFVideoFormat_NV12, 3, 2, 12, 9, 192, 9, 64 },
4802 { &MFVideoFormat_NV12, 4, 2, 12, 0, 192, 12, 64 },
4803 { &MFVideoFormat_NV12, 320, 240, 115200, 0, 115200, 115200, 320 },
4805 /* YUV 4:2:0, 12 bpp, planar, half stride (the secondary plane has
4806 * the same height, half the width and half the stride of the
4807 * primary one) */
4808 { &MFVideoFormat_IMC2, 1, 1, 3, 1, 192, 1, 128 },
4809 { &MFVideoFormat_IMC2, 1, 2, 6, 3, 384, 2, 128 },
4810 { &MFVideoFormat_IMC2, 1, 3, 9, 4, 576, 3, 128 },
4811 { &MFVideoFormat_IMC2, 2, 1, 3, 0, 192, 3, 128 },
4812 { &MFVideoFormat_IMC2, 2, 2, 6, 6, 384, 6, 128 },
4813 { &MFVideoFormat_IMC2, 2, 4, 12, 0, 768, 12, 128 },
4814 { &MFVideoFormat_IMC2, 3, 2, 12, 9, 384, 8, 128 },
4815 { &MFVideoFormat_IMC2, 3, 5, 30, 22, 960, 20, 128 },
4816 { &MFVideoFormat_IMC2, 4, 2, 12, 0, 384, 12, 128 },
4817 { &MFVideoFormat_IMC2, 4, 3, 18, 0, 576, 18, 128 },
4818 { &MFVideoFormat_IMC2, 320, 240, 115200, 0, 138240, 115200, 384 },
4820 { &MFVideoFormat_IMC4, 1, 1, 3, 1, 192, 1, 128 },
4821 { &MFVideoFormat_IMC4, 1, 2, 6, 3, 384, 2, 128 },
4822 { &MFVideoFormat_IMC4, 1, 3, 9, 4, 576, 3, 128 },
4823 { &MFVideoFormat_IMC4, 2, 1, 3, 0, 192, 3, 128 },
4824 { &MFVideoFormat_IMC4, 2, 2, 6, 6, 384, 6, 128 },
4825 { &MFVideoFormat_IMC4, 2, 4, 12, 0, 768, 12, 128 },
4826 { &MFVideoFormat_IMC4, 3, 2, 12, 9, 384, 8, 128 },
4827 { &MFVideoFormat_IMC4, 3, 5, 30, 22, 960, 20, 128 },
4828 { &MFVideoFormat_IMC4, 4, 2, 12, 0, 384, 12, 128 },
4829 { &MFVideoFormat_IMC4, 4, 3, 18, 0, 576, 18, 128 },
4830 { &MFVideoFormat_IMC4, 320, 240, 115200, 0, 138240, 115200, 384 },
4832 /* YUV 4:1:1, 12 bpp, semi-planar */
4833 { &MFVideoFormat_NV11, 1, 3, 18, 4, 576, 3, 128 },
4834 { &MFVideoFormat_NV11, 1, 2, 12, 3, 384, 2, 128 },
4835 { &MFVideoFormat_NV11, 2, 2, 12, 6, 384, 6, 128 },
4836 { &MFVideoFormat_NV11, 2, 4, 24, 12, 768, 12, 128 },
4837 { &MFVideoFormat_NV11, 3, 2, 12, 9, 384, 8, 128 },
4838 { &MFVideoFormat_NV11, 4, 2, 12, 0, 384, 12, 128 },
4839 { &MFVideoFormat_NV11, 320, 240, 115200, 0, 138240, 115200, 384 },
4841 { &MFVideoFormat_YV12, 1, 1, 3, 1, 192, 1, 128 },
4842 { &MFVideoFormat_YV12, 1, 2, 6, 3, 384, 2, 128 },
4843 { &MFVideoFormat_YV12, 1, 3, 9, 4, 576, 3, 128 },
4844 { &MFVideoFormat_YV12, 2, 1, 3, 0, 192, 3, 128 },
4845 { &MFVideoFormat_YV12, 2, 2, 6, 6, 384, 6, 128 },
4846 { &MFVideoFormat_YV12, 2, 4, 12, 0, 768, 12, 128 },
4847 { &MFVideoFormat_YV12, 3, 2, 12, 9, 384, 8, 128 },
4848 { &MFVideoFormat_YV12, 3, 5, 30, 22, 960, 20, 128 },
4849 { &MFVideoFormat_YV12, 4, 2, 12, 0, 384, 12, 128 },
4850 { &MFVideoFormat_YV12, 4, 3, 18, 0, 576, 18, 128 },
4851 { &MFVideoFormat_YV12, 320, 240, 115200, 0, 138240, 115200, 384 },
4853 { &MFVideoFormat_I420, 1, 1, 3, 1, 192, 1, 128 },
4854 { &MFVideoFormat_I420, 1, 2, 6, 3, 384, 2, 128 },
4855 { &MFVideoFormat_I420, 1, 3, 9, 4, 576, 3, 128 },
4856 { &MFVideoFormat_I420, 2, 1, 3, 0, 192, 3, 128 },
4857 { &MFVideoFormat_I420, 2, 2, 6, 6, 384, 6, 128 },
4858 { &MFVideoFormat_I420, 2, 4, 12, 0, 768, 12, 128 },
4859 { &MFVideoFormat_I420, 3, 2, 12, 9, 384, 8, 128 },
4860 { &MFVideoFormat_I420, 3, 5, 30, 22, 960, 20, 128 },
4861 { &MFVideoFormat_I420, 4, 2, 12, 0, 384, 12, 128 },
4862 { &MFVideoFormat_I420, 4, 3, 18, 0, 576, 18, 128 },
4863 { &MFVideoFormat_I420, 320, 240, 115200, 0, 138240, 115200, 384 },
4865 { &MFVideoFormat_IYUV, 1, 1, 3, 1, 192, 1, 128 },
4866 { &MFVideoFormat_IYUV, 1, 2, 6, 3, 384, 2, 128 },
4867 { &MFVideoFormat_IYUV, 1, 3, 9, 4, 576, 3, 128 },
4868 { &MFVideoFormat_IYUV, 2, 1, 3, 0, 192, 3, 128 },
4869 { &MFVideoFormat_IYUV, 2, 2, 6, 6, 384, 6, 128 },
4870 { &MFVideoFormat_IYUV, 2, 4, 12, 0, 768, 12, 128 },
4871 { &MFVideoFormat_IYUV, 3, 2, 12, 9, 384, 8, 128 },
4872 { &MFVideoFormat_IYUV, 3, 5, 30, 22, 960, 20, 128 },
4873 { &MFVideoFormat_IYUV, 4, 2, 12, 0, 384, 12, 128 },
4874 { &MFVideoFormat_IYUV, 4, 3, 18, 0, 576, 18, 128 },
4875 { &MFVideoFormat_IYUV, 320, 240, 115200, 0, 138240, 115200, 384 },
4878 static void test_MFCalculateImageSize(void)
4880 unsigned int i;
4881 UINT32 size;
4882 HRESULT hr;
4884 size = 1;
4885 hr = MFCalculateImageSize(&IID_IUnknown, 1, 1, &size);
4886 ok(hr == E_INVALIDARG || broken(hr == S_OK) /* Vista */, "Unexpected hr %#lx.\n", hr);
4887 ok(size == 0, "Unexpected size %u.\n", size);
4889 for (i = 0; i < ARRAY_SIZE(image_size_tests); ++i)
4891 const struct image_size_test *ptr = &image_size_tests[i];
4893 /* Those are supported since Win10. */
4894 BOOL is_broken = IsEqualGUID(ptr->subtype, &MFVideoFormat_A16B16G16R16F) ||
4895 IsEqualGUID(ptr->subtype, &MFVideoFormat_A2R10G10B10);
4897 hr = MFCalculateImageSize(ptr->subtype, ptr->width, ptr->height, &size);
4898 ok(hr == S_OK || (is_broken && hr == E_INVALIDARG), "%u: failed to calculate image size, hr %#lx.\n", i, hr);
4899 ok(size == ptr->size, "%u: unexpected image size %u, expected %u. Size %u x %u, format %s.\n", i, size, ptr->size,
4900 ptr->width, ptr->height, wine_dbgstr_an((char *)&ptr->subtype->Data1, 4));
4904 static void test_MFGetPlaneSize(void)
4906 unsigned int i;
4907 DWORD size;
4908 HRESULT hr;
4910 if (!pMFGetPlaneSize)
4912 win_skip("MFGetPlaneSize() is not available.\n");
4913 return;
4916 size = 1;
4917 hr = pMFGetPlaneSize(0xdeadbeef, 64, 64, &size);
4918 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
4919 ok(size == 0, "Unexpected size %lu.\n", size);
4921 for (i = 0; i < ARRAY_SIZE(image_size_tests); ++i)
4923 const struct image_size_test *ptr = &image_size_tests[i];
4924 unsigned int plane_size = ptr->plane_size ? ptr->plane_size : ptr->size;
4925 if ((is_MEDIASUBTYPE_RGB(ptr->subtype)))
4926 continue;
4928 hr = pMFGetPlaneSize(ptr->subtype->Data1, ptr->width, ptr->height, &size);
4929 ok(hr == S_OK, "%u: failed to get plane size, hr %#lx.\n", i, hr);
4930 ok(size == plane_size, "%u: unexpected plane size %lu, expected %u. Size %u x %u, format %s.\n", i, size, plane_size,
4931 ptr->width, ptr->height, wine_dbgstr_an((char*)&ptr->subtype->Data1, 4));
4935 static void test_MFCompareFullToPartialMediaType(void)
4937 IMFMediaType *full_type, *partial_type;
4938 HRESULT hr;
4939 BOOL ret;
4941 hr = MFCreateMediaType(&full_type);
4942 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
4944 hr = MFCreateMediaType(&partial_type);
4945 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
4947 ret = MFCompareFullToPartialMediaType(full_type, partial_type);
4948 ok(!ret, "Unexpected result %d.\n", ret);
4950 hr = IMFMediaType_SetGUID(full_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
4951 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
4953 hr = IMFMediaType_SetGUID(partial_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
4954 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
4956 ret = MFCompareFullToPartialMediaType(full_type, partial_type);
4957 ok(ret, "Unexpected result %d.\n", ret);
4959 hr = IMFMediaType_SetGUID(full_type, &MF_MT_SUBTYPE, &MFMediaType_Audio);
4960 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
4962 ret = MFCompareFullToPartialMediaType(full_type, partial_type);
4963 ok(ret, "Unexpected result %d.\n", ret);
4965 hr = IMFMediaType_SetGUID(partial_type, &MF_MT_SUBTYPE, &MFMediaType_Video);
4966 ok(hr == S_OK, "Failed to set major type, hr %#lx.\n", hr);
4968 ret = MFCompareFullToPartialMediaType(full_type, partial_type);
4969 ok(!ret, "Unexpected result %d.\n", ret);
4971 IMFMediaType_Release(full_type);
4972 IMFMediaType_Release(partial_type);
4975 static void test_attributes_serialization(void)
4977 static const UINT8 blob[] = {1,2,3};
4978 IMFAttributes *attributes, *dest;
4979 UINT32 size, count, value32;
4980 double value_dbl;
4981 UINT64 value64;
4982 UINT8 *buffer;
4983 IUnknown *obj;
4984 HRESULT hr;
4985 WCHAR *str;
4986 GUID guid;
4988 hr = MFCreateAttributes(&attributes, 0);
4989 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
4991 hr = MFCreateAttributes(&dest, 0);
4992 ok(hr == S_OK, "Failed to create object, hr %#lx.\n", hr);
4994 hr = MFGetAttributesAsBlobSize(attributes, &size);
4995 ok(hr == S_OK, "Failed to get blob size, hr %#lx.\n", hr);
4996 ok(size == 8, "Got size %u.\n", size);
4998 buffer = malloc(size);
5000 hr = MFGetAttributesAsBlob(attributes, buffer, size);
5001 ok(hr == S_OK, "Failed to serialize, hr %#lx.\n", hr);
5003 hr = MFGetAttributesAsBlob(attributes, buffer, size - 1);
5004 ok(hr == MF_E_BUFFERTOOSMALL, "Unexpected hr %#lx.\n", hr);
5006 hr = MFInitAttributesFromBlob(dest, buffer, size - 1);
5007 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5009 hr = IMFAttributes_SetUINT32(dest, &MF_MT_MAJOR_TYPE, 1);
5010 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5012 hr = MFInitAttributesFromBlob(dest, buffer, size);
5013 ok(hr == S_OK, "Failed to deserialize, hr %#lx.\n", hr);
5015 /* Previous items are cleared. */
5016 hr = IMFAttributes_GetCount(dest, &count);
5017 ok(hr == S_OK, "Failed to get attribute count, hr %#lx.\n", hr);
5018 ok(count == 0, "Unexpected count %u.\n", count);
5020 free(buffer);
5022 /* Set some attributes of various types. */
5023 IMFAttributes_SetUINT32(attributes, &MF_MT_MAJOR_TYPE, 456);
5024 IMFAttributes_SetUINT64(attributes, &MF_MT_SUBTYPE, 123);
5025 IMFAttributes_SetDouble(attributes, &IID_IUnknown, 0.5);
5026 IMFAttributes_SetUnknown(attributes, &IID_IMFAttributes, (IUnknown *)attributes);
5027 IMFAttributes_SetGUID(attributes, &GUID_NULL, &IID_IUnknown);
5028 IMFAttributes_SetString(attributes, &DUMMY_CLSID, L"Text");
5029 IMFAttributes_SetBlob(attributes, &DUMMY_GUID1, blob, sizeof(blob));
5031 hr = MFGetAttributesAsBlobSize(attributes, &size);
5032 ok(hr == S_OK, "Failed to get blob size, hr %#lx.\n", hr);
5033 ok(size > 8, "Got unexpected size %u.\n", size);
5035 buffer = malloc(size);
5036 hr = MFGetAttributesAsBlob(attributes, buffer, size);
5037 ok(hr == S_OK, "Failed to serialize, hr %#lx.\n", hr);
5038 hr = MFInitAttributesFromBlob(dest, buffer, size);
5039 ok(hr == S_OK, "Failed to deserialize, hr %#lx.\n", hr);
5040 free(buffer);
5042 hr = IMFAttributes_GetUINT32(dest, &MF_MT_MAJOR_TYPE, &value32);
5043 ok(hr == S_OK, "Failed to get get uint32 value, hr %#lx.\n", hr);
5044 ok(value32 == 456, "Unexpected value %u.\n", value32);
5045 hr = IMFAttributes_GetUINT64(dest, &MF_MT_SUBTYPE, &value64);
5046 ok(hr == S_OK, "Failed to get get uint64 value, hr %#lx.\n", hr);
5047 ok(value64 == 123, "Unexpected value.\n");
5048 hr = IMFAttributes_GetDouble(dest, &IID_IUnknown, &value_dbl);
5049 ok(hr == S_OK, "Failed to get get double value, hr %#lx.\n", hr);
5050 ok(value_dbl == 0.5, "Unexpected value.\n");
5051 hr = IMFAttributes_GetUnknown(dest, &IID_IMFAttributes, &IID_IUnknown, (void **)&obj);
5052 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
5053 hr = IMFAttributes_GetGUID(dest, &GUID_NULL, &guid);
5054 ok(hr == S_OK, "Failed to get guid value, hr %#lx.\n", hr);
5055 ok(IsEqualGUID(&guid, &IID_IUnknown), "Unexpected guid.\n");
5056 hr = IMFAttributes_GetAllocatedString(dest, &DUMMY_CLSID, &str, &size);
5057 ok(hr == S_OK, "Failed to get string value, hr %#lx.\n", hr);
5058 ok(!lstrcmpW(str, L"Text"), "Unexpected string.\n");
5059 CoTaskMemFree(str);
5060 hr = IMFAttributes_GetAllocatedBlob(dest, &DUMMY_GUID1, &buffer, &size);
5061 ok(hr == S_OK, "Failed to get blob value, hr %#lx.\n", hr);
5062 ok(!memcmp(buffer, blob, sizeof(blob)), "Unexpected blob.\n");
5063 CoTaskMemFree(buffer);
5065 IMFAttributes_Release(attributes);
5066 IMFAttributes_Release(dest);
5069 static void test_wrapped_media_type(void)
5071 IMFMediaType *mediatype, *mediatype2;
5072 MF_ATTRIBUTE_TYPE type;
5073 UINT32 count;
5074 HRESULT hr;
5075 GUID guid;
5077 hr = MFCreateMediaType(&mediatype);
5078 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
5080 hr = MFUnwrapMediaType(mediatype, &mediatype2);
5081 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
5083 hr = IMFMediaType_SetUINT32(mediatype, &GUID_NULL, 1);
5084 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5085 hr = IMFMediaType_SetUINT32(mediatype, &DUMMY_GUID1, 2);
5086 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5088 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
5089 ok(hr == S_OK, "Failed to set GUID value, hr %#lx.\n", hr);
5091 hr = MFWrapMediaType(mediatype, &MFMediaType_Audio, &IID_IUnknown, &mediatype2);
5092 ok(hr == S_OK, "Failed to create wrapped media type, hr %#lx.\n", hr);
5094 hr = IMFMediaType_GetGUID(mediatype2, &MF_MT_MAJOR_TYPE, &guid);
5095 ok(hr == S_OK, "Failed to get major type, hr %#lx.\n", hr);
5096 ok(IsEqualGUID(&guid, &MFMediaType_Audio), "Unexpected major type.\n");
5098 hr = IMFMediaType_GetGUID(mediatype2, &MF_MT_SUBTYPE, &guid);
5099 ok(hr == S_OK, "Failed to get subtype, hr %#lx.\n", hr);
5100 ok(IsEqualGUID(&guid, &IID_IUnknown), "Unexpected major type.\n");
5102 hr = IMFMediaType_GetCount(mediatype2, &count);
5103 ok(hr == S_OK, "Failed to get item count, hr %#lx.\n", hr);
5104 ok(count == 3, "Unexpected count %u.\n", count);
5106 hr = IMFMediaType_GetItemType(mediatype2, &MF_MT_WRAPPED_TYPE, &type);
5107 ok(hr == S_OK, "Failed to get item type, hr %#lx.\n", hr);
5108 ok(type == MF_ATTRIBUTE_BLOB, "Unexpected item type.\n");
5110 IMFMediaType_Release(mediatype);
5112 hr = MFUnwrapMediaType(mediatype2, &mediatype);
5113 ok(hr == S_OK, "Failed to unwrap, hr %#lx.\n", hr);
5115 hr = IMFMediaType_GetGUID(mediatype, &MF_MT_MAJOR_TYPE, &guid);
5116 ok(hr == S_OK, "Failed to get major type, hr %#lx.\n", hr);
5117 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected major type.\n");
5119 hr = IMFMediaType_GetGUID(mediatype, &MF_MT_SUBTYPE, &guid);
5120 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
5122 IMFMediaType_Release(mediatype);
5123 IMFMediaType_Release(mediatype2);
5126 static void test_MFCreateWaveFormatExFromMFMediaType(void)
5128 static const struct wave_fmt_test
5130 const GUID *subtype;
5131 WORD format_tag;
5133 wave_fmt_tests[] =
5135 { &MFAudioFormat_PCM, WAVE_FORMAT_PCM, },
5136 { &MFAudioFormat_Float, WAVE_FORMAT_IEEE_FLOAT, },
5138 WAVEFORMATEXTENSIBLE *format_ext;
5139 IMFMediaType *mediatype;
5140 WAVEFORMATEX *format;
5141 UINT32 size, i;
5142 HRESULT hr;
5144 hr = MFCreateMediaType(&mediatype);
5145 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
5147 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_Normal);
5148 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
5150 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
5151 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5153 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_Normal);
5154 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
5156 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, &MFMediaType_Video);
5157 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5159 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
5160 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5162 for (i = 0; i < ARRAY_SIZE(wave_fmt_tests); ++i)
5164 hr = IMFMediaType_SetGUID(mediatype, &MF_MT_SUBTYPE, wave_fmt_tests[i].subtype);
5165 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
5167 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_Normal);
5168 ok(hr == S_OK, "Failed to create format, hr %#lx.\n", hr);
5169 ok(format != NULL, "Expected format structure.\n");
5170 ok(size == sizeof(*format), "Unexpected size %u.\n", size);
5171 ok(format->wFormatTag == wave_fmt_tests[i].format_tag, "Expected tag %u, got %u.\n", wave_fmt_tests[i].format_tag, format->wFormatTag);
5172 ok(format->nChannels == 0, "Unexpected number of channels, %u.\n", format->nChannels);
5173 ok(format->nSamplesPerSec == 0, "Unexpected sample rate, %lu.\n", format->nSamplesPerSec);
5174 ok(format->nAvgBytesPerSec == 0, "Unexpected average data rate rate, %lu.\n", format->nAvgBytesPerSec);
5175 ok(format->nBlockAlign == 0, "Unexpected alignment, %u.\n", format->nBlockAlign);
5176 ok(format->wBitsPerSample == 0, "Unexpected sample size, %u.\n", format->wBitsPerSample);
5177 ok(format->cbSize == 0, "Unexpected size field, %u.\n", format->cbSize);
5178 CoTaskMemFree(format);
5180 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, (WAVEFORMATEX **)&format_ext, &size,
5181 MFWaveFormatExConvertFlag_ForceExtensible);
5182 ok(hr == S_OK, "Failed to create format, hr %#lx.\n", hr);
5183 ok(format_ext != NULL, "Expected format structure.\n");
5184 ok(size == sizeof(*format_ext), "Unexpected size %u.\n", size);
5185 ok(format_ext->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "Unexpected tag.\n");
5186 ok(format_ext->Format.nChannels == 0, "Unexpected number of channels, %u.\n", format_ext->Format.nChannels);
5187 ok(format_ext->Format.nSamplesPerSec == 0, "Unexpected sample rate, %lu.\n", format_ext->Format.nSamplesPerSec);
5188 ok(format_ext->Format.nAvgBytesPerSec == 0, "Unexpected average data rate rate, %lu.\n",
5189 format_ext->Format.nAvgBytesPerSec);
5190 ok(format_ext->Format.nBlockAlign == 0, "Unexpected alignment, %u.\n", format_ext->Format.nBlockAlign);
5191 ok(format_ext->Format.wBitsPerSample == 0, "Unexpected sample size, %u.\n", format_ext->Format.wBitsPerSample);
5192 ok(format_ext->Format.cbSize == sizeof(*format_ext) - sizeof(format_ext->Format), "Unexpected size field, %u.\n",
5193 format_ext->Format.cbSize);
5194 CoTaskMemFree(format_ext);
5196 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, &format, &size, MFWaveFormatExConvertFlag_ForceExtensible + 1);
5197 ok(hr == S_OK, "Failed to create format, hr %#lx.\n", hr);
5198 ok(size == sizeof(*format), "Unexpected size %u.\n", size);
5199 CoTaskMemFree(format);
5202 IMFMediaType_Release(mediatype);
5205 static HRESULT WINAPI test_create_file_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
5207 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
5208 IMFByteStream *stream;
5209 IUnknown *object;
5210 HRESULT hr;
5212 ok(!!result, "Unexpected result object.\n");
5214 ok((IUnknown *)iface == IMFAsyncResult_GetStateNoAddRef(result), "Unexpected result state.\n");
5216 hr = IMFAsyncResult_GetObject(result, &object);
5217 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
5219 hr = MFEndCreateFile(result, &stream);
5220 ok(hr == S_OK, "Failed to get file stream, hr %#lx.\n", hr);
5221 IMFByteStream_Release(stream);
5223 SetEvent(callback->event);
5225 return S_OK;
5228 static const IMFAsyncCallbackVtbl test_create_file_callback_vtbl =
5230 testcallback_QueryInterface,
5231 testcallback_AddRef,
5232 testcallback_Release,
5233 testcallback_GetParameters,
5234 test_create_file_callback_Invoke,
5237 static void test_async_create_file(void)
5239 WCHAR pathW[MAX_PATH], fileW[MAX_PATH];
5240 struct test_callback *callback;
5241 IUnknown *cancel_cookie;
5242 HRESULT hr;
5243 BOOL ret;
5245 callback = create_test_callback(&test_create_file_callback_vtbl);
5247 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
5248 ok(hr == S_OK, "Fail to start up, hr %#lx.\n", hr);
5250 GetTempPathW(ARRAY_SIZE(pathW), pathW);
5251 GetTempFileNameW(pathW, NULL, 0, fileW);
5253 hr = MFBeginCreateFile(MF_ACCESSMODE_READWRITE, MF_OPENMODE_DELETE_IF_EXIST, MF_FILEFLAGS_NONE, fileW,
5254 &callback->IMFAsyncCallback_iface, (IUnknown *)&callback->IMFAsyncCallback_iface, &cancel_cookie);
5255 ok(hr == S_OK, "Async create request failed, hr %#lx.\n", hr);
5256 ok(cancel_cookie != NULL, "Unexpected cancellation object.\n");
5258 WaitForSingleObject(callback->event, INFINITE);
5260 IUnknown_Release(cancel_cookie);
5262 hr = MFShutdown();
5263 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
5265 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
5267 ret = DeleteFileW(fileW);
5268 ok(ret, "Failed to delete test file.\n");
5271 struct activate_object
5273 IMFActivate IMFActivate_iface;
5274 LONG refcount;
5277 static HRESULT WINAPI activate_object_QueryInterface(IMFActivate *iface, REFIID riid, void **obj)
5279 if (IsEqualIID(riid, &IID_IMFActivate) ||
5280 IsEqualIID(riid, &IID_IMFAttributes) ||
5281 IsEqualIID(riid, &IID_IUnknown))
5283 *obj = iface;
5284 IMFActivate_AddRef(iface);
5285 return S_OK;
5288 *obj = NULL;
5289 return E_NOINTERFACE;
5292 static ULONG WINAPI activate_object_AddRef(IMFActivate *iface)
5294 return 2;
5297 static ULONG WINAPI activate_object_Release(IMFActivate *iface)
5299 return 1;
5302 static HRESULT WINAPI activate_object_GetItem(IMFActivate *iface, REFGUID key, PROPVARIANT *value)
5304 return E_NOTIMPL;
5307 static HRESULT WINAPI activate_object_GetItemType(IMFActivate *iface, REFGUID key, MF_ATTRIBUTE_TYPE *type)
5309 return E_NOTIMPL;
5312 static HRESULT WINAPI activate_object_CompareItem(IMFActivate *iface, REFGUID key, REFPROPVARIANT value, BOOL *result)
5314 return E_NOTIMPL;
5317 static HRESULT WINAPI activate_object_Compare(IMFActivate *iface, IMFAttributes *theirs, MF_ATTRIBUTES_MATCH_TYPE type,
5318 BOOL *result)
5320 return E_NOTIMPL;
5323 static HRESULT WINAPI activate_object_GetUINT32(IMFActivate *iface, REFGUID key, UINT32 *value)
5325 return E_NOTIMPL;
5328 static HRESULT WINAPI activate_object_GetUINT64(IMFActivate *iface, REFGUID key, UINT64 *value)
5330 return E_NOTIMPL;
5333 static HRESULT WINAPI activate_object_GetDouble(IMFActivate *iface, REFGUID key, double *value)
5335 return E_NOTIMPL;
5338 static HRESULT WINAPI activate_object_GetGUID(IMFActivate *iface, REFGUID key, GUID *value)
5340 return E_NOTIMPL;
5343 static HRESULT WINAPI activate_object_GetStringLength(IMFActivate *iface, REFGUID key, UINT32 *length)
5345 return E_NOTIMPL;
5348 static HRESULT WINAPI activate_object_GetString(IMFActivate *iface, REFGUID key, WCHAR *value,
5349 UINT32 size, UINT32 *length)
5351 return E_NOTIMPL;
5354 static HRESULT WINAPI activate_object_GetAllocatedString(IMFActivate *iface, REFGUID key,
5355 WCHAR **value, UINT32 *length)
5357 return E_NOTIMPL;
5360 static HRESULT WINAPI activate_object_GetBlobSize(IMFActivate *iface, REFGUID key, UINT32 *size)
5362 return E_NOTIMPL;
5365 static HRESULT WINAPI activate_object_GetBlob(IMFActivate *iface, REFGUID key, UINT8 *buf,
5366 UINT32 bufsize, UINT32 *blobsize)
5368 return E_NOTIMPL;
5371 static HRESULT WINAPI activate_object_GetAllocatedBlob(IMFActivate *iface, REFGUID key, UINT8 **buf, UINT32 *size)
5373 return E_NOTIMPL;
5376 static HRESULT WINAPI activate_object_GetUnknown(IMFActivate *iface, REFGUID key, REFIID riid, void **ppv)
5378 return E_NOTIMPL;
5381 static HRESULT WINAPI activate_object_SetItem(IMFActivate *iface, REFGUID key, REFPROPVARIANT value)
5383 return E_NOTIMPL;
5386 static HRESULT WINAPI activate_object_DeleteItem(IMFActivate *iface, REFGUID key)
5388 return E_NOTIMPL;
5391 static HRESULT WINAPI activate_object_DeleteAllItems(IMFActivate *iface)
5393 return E_NOTIMPL;
5396 static HRESULT WINAPI activate_object_SetUINT32(IMFActivate *iface, REFGUID key, UINT32 value)
5398 return E_NOTIMPL;
5401 static HRESULT WINAPI activate_object_SetUINT64(IMFActivate *iface, REFGUID key, UINT64 value)
5403 return E_NOTIMPL;
5406 static HRESULT WINAPI activate_object_SetDouble(IMFActivate *iface, REFGUID key, double value)
5408 return E_NOTIMPL;
5411 static HRESULT WINAPI activate_object_SetGUID(IMFActivate *iface, REFGUID key, REFGUID value)
5413 return E_NOTIMPL;
5416 static HRESULT WINAPI activate_object_SetString(IMFActivate *iface, REFGUID key, const WCHAR *value)
5418 return E_NOTIMPL;
5421 static HRESULT WINAPI activate_object_SetBlob(IMFActivate *iface, REFGUID key, const UINT8 *buf, UINT32 size)
5423 return E_NOTIMPL;
5426 static HRESULT WINAPI activate_object_SetUnknown(IMFActivate *iface, REFGUID key, IUnknown *unknown)
5428 return E_NOTIMPL;
5431 static HRESULT WINAPI activate_object_LockStore(IMFActivate *iface)
5433 return E_NOTIMPL;
5436 static HRESULT WINAPI activate_object_UnlockStore(IMFActivate *iface)
5438 return E_NOTIMPL;
5441 static HRESULT WINAPI activate_object_GetCount(IMFActivate *iface, UINT32 *count)
5443 return E_NOTIMPL;
5446 static HRESULT WINAPI activate_object_GetItemByIndex(IMFActivate *iface, UINT32 index, GUID *key, PROPVARIANT *value)
5448 return E_NOTIMPL;
5451 static HRESULT WINAPI activate_object_CopyAllItems(IMFActivate *iface, IMFAttributes *dest)
5453 return E_NOTIMPL;
5456 static HRESULT WINAPI activate_object_ActivateObject(IMFActivate *iface, REFIID riid, void **obj)
5458 return E_NOTIMPL;
5461 static HRESULT WINAPI activate_object_ShutdownObject(IMFActivate *iface)
5463 return E_NOTIMPL;
5466 static HRESULT WINAPI activate_object_DetachObject(IMFActivate *iface)
5468 return E_NOTIMPL;
5471 static const IMFActivateVtbl activate_object_vtbl =
5473 activate_object_QueryInterface,
5474 activate_object_AddRef,
5475 activate_object_Release,
5476 activate_object_GetItem,
5477 activate_object_GetItemType,
5478 activate_object_CompareItem,
5479 activate_object_Compare,
5480 activate_object_GetUINT32,
5481 activate_object_GetUINT64,
5482 activate_object_GetDouble,
5483 activate_object_GetGUID,
5484 activate_object_GetStringLength,
5485 activate_object_GetString,
5486 activate_object_GetAllocatedString,
5487 activate_object_GetBlobSize,
5488 activate_object_GetBlob,
5489 activate_object_GetAllocatedBlob,
5490 activate_object_GetUnknown,
5491 activate_object_SetItem,
5492 activate_object_DeleteItem,
5493 activate_object_DeleteAllItems,
5494 activate_object_SetUINT32,
5495 activate_object_SetUINT64,
5496 activate_object_SetDouble,
5497 activate_object_SetGUID,
5498 activate_object_SetString,
5499 activate_object_SetBlob,
5500 activate_object_SetUnknown,
5501 activate_object_LockStore,
5502 activate_object_UnlockStore,
5503 activate_object_GetCount,
5504 activate_object_GetItemByIndex,
5505 activate_object_CopyAllItems,
5506 activate_object_ActivateObject,
5507 activate_object_ShutdownObject,
5508 activate_object_DetachObject,
5511 static void test_local_handlers(void)
5513 IMFActivate local_activate = { &activate_object_vtbl };
5514 static const WCHAR localW[] = L"local";
5515 HRESULT hr;
5517 if (!pMFRegisterLocalSchemeHandler)
5519 win_skip("Local handlers are not supported.\n");
5520 return;
5523 hr = pMFRegisterLocalSchemeHandler(NULL, NULL);
5524 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5526 hr = pMFRegisterLocalSchemeHandler(localW, NULL);
5527 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5529 hr = pMFRegisterLocalSchemeHandler(NULL, &local_activate);
5530 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5532 hr = pMFRegisterLocalSchemeHandler(localW, &local_activate);
5533 ok(hr == S_OK, "Failed to register scheme handler, hr %#lx.\n", hr);
5535 hr = pMFRegisterLocalSchemeHandler(localW, &local_activate);
5536 ok(hr == S_OK, "Failed to register scheme handler, hr %#lx.\n", hr);
5538 hr = pMFRegisterLocalByteStreamHandler(NULL, NULL, NULL);
5539 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5541 hr = pMFRegisterLocalByteStreamHandler(NULL, NULL, &local_activate);
5542 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5544 hr = pMFRegisterLocalByteStreamHandler(NULL, localW, &local_activate);
5545 ok(hr == S_OK, "Failed to register stream handler, hr %#lx.\n", hr);
5547 hr = pMFRegisterLocalByteStreamHandler(localW, NULL, &local_activate);
5548 ok(hr == S_OK, "Failed to register stream handler, hr %#lx.\n", hr);
5550 hr = pMFRegisterLocalByteStreamHandler(localW, localW, &local_activate);
5551 ok(hr == S_OK, "Failed to register stream handler, hr %#lx.\n", hr);
5554 static void test_create_property_store(void)
5556 static const PROPERTYKEY test_pkey = {{0x12345678}, 9};
5557 IPropertyStore *store, *store2;
5558 PROPVARIANT value = {0};
5559 PROPERTYKEY key;
5560 ULONG refcount;
5561 DWORD count;
5562 HRESULT hr;
5564 hr = CreatePropertyStore(NULL);
5565 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5567 hr = CreatePropertyStore(&store);
5568 ok(hr == S_OK, "Failed to create property store, hr %#lx.\n", hr);
5570 hr = CreatePropertyStore(&store2);
5571 ok(hr == S_OK, "Failed to create property store, hr %#lx.\n", hr);
5572 ok(store2 != store, "Expected different store objects.\n");
5573 IPropertyStore_Release(store2);
5575 check_interface(store, &IID_IPropertyStoreCache, FALSE);
5576 check_interface(store, &IID_IPersistSerializedPropStorage, FALSE);
5578 hr = IPropertyStore_GetCount(store, NULL);
5579 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5581 count = 0xdeadbeef;
5582 hr = IPropertyStore_GetCount(store, &count);
5583 ok(hr == S_OK, "Failed to get count, hr %#lx.\n", hr);
5584 ok(!count, "Unexpected count %lu.\n", count);
5586 hr = IPropertyStore_Commit(store);
5587 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
5589 hr = IPropertyStore_GetAt(store, 0, &key);
5590 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5592 hr = IPropertyStore_GetValue(store, NULL, &value);
5593 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
5595 hr = IPropertyStore_GetValue(store, &test_pkey, NULL);
5596 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5598 hr = IPropertyStore_GetValue(store, &test_pkey, &value);
5599 ok(hr == S_FALSE, "Unexpected hr %#lx.\n", hr);
5601 memset(&value, 0, sizeof(PROPVARIANT));
5602 value.vt = VT_I4;
5603 value.lVal = 0xdeadbeef;
5604 hr = IPropertyStore_SetValue(store, &test_pkey, &value);
5605 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5607 if (0)
5609 /* crashes on Windows */
5610 hr = IPropertyStore_SetValue(store, NULL, &value);
5611 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5614 hr = IPropertyStore_GetCount(store, &count);
5615 ok(hr == S_OK, "Failed to get count, hr %#lx.\n", hr);
5616 ok(count == 1, "Unexpected count %lu.\n", count);
5618 hr = IPropertyStore_Commit(store);
5619 ok(hr == E_NOTIMPL, "Unexpected hr %#lx.\n", hr);
5621 hr = IPropertyStore_GetAt(store, 0, &key);
5622 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5623 ok(!memcmp(&key, &test_pkey, sizeof(PROPERTYKEY)), "Keys didn't match.\n");
5625 hr = IPropertyStore_GetAt(store, 1, &key);
5626 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5628 memset(&value, 0xcc, sizeof(PROPVARIANT));
5629 hr = IPropertyStore_GetValue(store, &test_pkey, &value);
5630 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5631 ok(value.vt == VT_I4, "Unexpected type %u.\n", value.vt);
5632 ok(value.lVal == 0xdeadbeef, "Unexpected value %#lx.\n", value.lVal);
5634 memset(&value, 0, sizeof(PROPVARIANT));
5635 hr = IPropertyStore_SetValue(store, &test_pkey, &value);
5636 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5638 hr = IPropertyStore_GetCount(store, &count);
5639 ok(hr == S_OK, "Failed to get count, hr %#lx.\n", hr);
5640 ok(count == 1, "Unexpected count %lu.\n", count);
5642 memset(&value, 0xcc, sizeof(PROPVARIANT));
5643 hr = IPropertyStore_GetValue(store, &test_pkey, &value);
5644 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5645 ok(value.vt == VT_EMPTY, "Unexpected type %u.\n", value.vt);
5646 ok(!value.lVal, "Unexpected value %#lx.\n", value.lVal);
5648 refcount = IPropertyStore_Release(store);
5649 ok(!refcount, "Unexpected refcount %lu.\n", refcount);
5652 struct test_thread_param
5654 IMFDXGIDeviceManager *manager;
5655 HANDLE handle;
5656 BOOL lock;
5659 static DWORD WINAPI test_device_manager_thread(void *arg)
5661 struct test_thread_param *param = arg;
5662 ID3D11Device *device;
5663 HRESULT hr;
5665 if (param->lock)
5667 hr = IMFDXGIDeviceManager_LockDevice(param->manager, param->handle, &IID_ID3D11Device,
5668 (void **)&device, FALSE);
5669 if (SUCCEEDED(hr))
5670 ID3D11Device_Release(device);
5672 else
5673 hr = IMFDXGIDeviceManager_UnlockDevice(param->manager, param->handle, FALSE);
5675 return hr;
5678 static void test_dxgi_device_manager(void)
5680 IMFDXGIDeviceManager *manager, *manager2;
5681 ID3D11Device *device, *d3d11_dev, *d3d11_dev2;
5682 struct test_thread_param param;
5683 HANDLE handle1, handle, thread;
5684 UINT token, token2;
5685 IUnknown *unk;
5686 HRESULT hr;
5688 if (!pMFCreateDXGIDeviceManager)
5690 win_skip("MFCreateDXGIDeviceManager not found.\n");
5691 return;
5694 hr = pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
5695 NULL, 0, D3D11_SDK_VERSION, &d3d11_dev, NULL, NULL);
5696 if (FAILED(hr))
5698 skip("Failed to create D3D11 device object.\n");
5699 return;
5701 ok(hr == S_OK, "D3D11CreateDevice failed: %#lx.\n", hr);
5702 EXPECT_REF(d3d11_dev, 1);
5704 hr = pMFCreateDXGIDeviceManager(NULL, &manager);
5705 ok(hr == E_POINTER, "MFCreateDXGIDeviceManager should failed: %#lx.\n", hr);
5707 token = 0;
5708 hr = pMFCreateDXGIDeviceManager(&token, NULL);
5709 ok(hr == E_POINTER, "MFCreateDXGIDeviceManager should failed: %#lx.\n", hr);
5710 ok(!token, "got wrong token: %u.\n", token);
5712 hr = pMFCreateDXGIDeviceManager(&token, &manager);
5713 ok(hr == S_OK, "MFCreateDXGIDeviceManager failed: %#lx.\n", hr);
5714 EXPECT_REF(manager, 1);
5715 ok(!!token, "got wrong token: %u.\n", token);
5717 Sleep(50);
5718 token2 = 0;
5719 hr = pMFCreateDXGIDeviceManager(&token2, &manager2);
5720 ok(hr == S_OK, "MFCreateDXGIDeviceManager failed: %#lx.\n", hr);
5721 EXPECT_REF(manager2, 1);
5722 ok(token2 && token2 != token, "got wrong token: %u, %u.\n", token2, token);
5723 ok(manager != manager2, "got wrong pointer: %p.\n", manager2);
5724 EXPECT_REF(manager, 1);
5726 hr = IMFDXGIDeviceManager_GetVideoService(manager, NULL, &IID_ID3D11Device, (void **)&unk);
5727 ok(hr == MF_E_DXGI_DEVICE_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
5729 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle);
5730 ok(hr == MF_E_DXGI_DEVICE_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
5732 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, 0);
5733 ok(hr == E_HANDLE, "Unexpected hr %#lx.\n", hr);
5735 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)d3d11_dev, token - 1);
5736 ok(hr == E_INVALIDARG, "IMFDXGIDeviceManager_ResetDevice should failed: %#lx.\n", hr);
5737 EXPECT_REF(d3d11_dev, 1);
5739 hr = IMFDXGIDeviceManager_ResetDevice(manager, NULL, token);
5740 ok(hr == E_INVALIDARG, "IMFDXGIDeviceManager_ResetDevice should failed: %#lx.\n", hr);
5742 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)d3d11_dev, token);
5743 ok(hr == S_OK, "IMFDXGIDeviceManager_ResetDevice failed: %#lx.\n", hr);
5744 EXPECT_REF(manager, 1);
5745 EXPECT_REF(d3d11_dev, 2);
5747 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)manager2, token);
5748 ok(hr == E_INVALIDARG, "IMFDXGIDeviceManager_ResetDevice should failed: %#lx.\n", hr);
5749 EXPECT_REF(manager2, 1);
5750 EXPECT_REF(d3d11_dev, 2);
5752 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)d3d11_dev, token);
5753 ok(hr == S_OK, "IMFDXGIDeviceManager_ResetDevice failed: %#lx.\n", hr);
5754 EXPECT_REF(manager, 1);
5755 EXPECT_REF(d3d11_dev, 2);
5757 /* GetVideoService() on device change. */
5758 handle = NULL;
5759 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle);
5760 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5761 ok(!!handle, "Unexpected handle value %p.\n", handle);
5763 hr = pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0,
5764 NULL, 0, D3D11_SDK_VERSION, &d3d11_dev2, NULL, NULL);
5765 ok(hr == S_OK, "D3D11CreateDevice failed: %#lx.\n", hr);
5766 EXPECT_REF(d3d11_dev2, 1);
5767 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)d3d11_dev2, token);
5768 ok(hr == S_OK, "IMFDXGIDeviceManager_ResetDevice failed: %#lx.\n", hr);
5769 EXPECT_REF(manager, 1);
5770 EXPECT_REF(d3d11_dev2, 2);
5771 EXPECT_REF(d3d11_dev, 1);
5773 hr = IMFDXGIDeviceManager_GetVideoService(manager, handle, &IID_ID3D11Device, (void **)&unk);
5774 ok(hr == MF_E_DXGI_NEW_VIDEO_DEVICE, "Unexpected hr %#lx.\n", hr);
5776 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle);
5777 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5779 handle = NULL;
5780 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle);
5781 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5782 ok(!!handle, "Unexpected handle value %p.\n", handle);
5784 hr = IMFDXGIDeviceManager_GetVideoService(manager, NULL, &IID_ID3D11Device, (void **)&unk);
5785 ok(hr == E_HANDLE, "Unexpected hr %#lx.\n", hr);
5787 hr = IMFDXGIDeviceManager_GetVideoService(manager, handle, &IID_ID3D11Device, (void **)&unk);
5788 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5789 IUnknown_Release(unk);
5791 hr = IMFDXGIDeviceManager_GetVideoService(manager, handle, &IID_IUnknown, (void **)&unk);
5792 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5793 IUnknown_Release(unk);
5795 hr = IMFDXGIDeviceManager_GetVideoService(manager, handle, &IID_IDXGIDevice, (void **)&unk);
5796 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5797 IUnknown_Release(unk);
5799 handle1 = NULL;
5800 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle1);
5801 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5802 ok(handle != handle1, "Unexpected handle.\n");
5804 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle);
5805 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5807 /* Already closed. */
5808 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle);
5809 ok(hr == E_HANDLE, "Unexpected hr %#lx.\n", hr);
5811 handle = NULL;
5812 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle);
5813 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5815 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle1);
5816 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5818 hr = IMFDXGIDeviceManager_TestDevice(manager, handle1);
5819 ok(hr == E_HANDLE, "Unexpected hr %#lx.\n", hr);
5821 hr = IMFDXGIDeviceManager_LockDevice(manager, handle, &IID_ID3D11Device, (void **)&device, FALSE);
5822 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5823 ok(device == d3d11_dev2, "Unexpected device pointer.\n");
5824 ID3D11Device_Release(device);
5826 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle, FALSE);
5827 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5829 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle, FALSE);
5830 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5832 hr = IMFDXGIDeviceManager_UnlockDevice(manager, UlongToHandle(100), FALSE);
5833 ok(hr == E_FAIL, "Unexpected hr %#lx.\n", hr);
5835 /* Locked with one handle, unlock with another. */
5836 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle1);
5837 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5839 hr = IMFDXGIDeviceManager_LockDevice(manager, handle, &IID_ID3D11Device, (void **)&device, FALSE);
5840 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5842 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle1, FALSE);
5843 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5845 ID3D11Device_Release(device);
5847 /* Closing unlocks the device. */
5848 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle);
5849 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5851 hr = IMFDXGIDeviceManager_LockDevice(manager, handle1, &IID_ID3D11Device, (void **)&device, FALSE);
5852 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5853 ID3D11Device_Release(device);
5855 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle1);
5856 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5858 /* Open two handles. */
5859 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle);
5860 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5862 hr = IMFDXGIDeviceManager_OpenDeviceHandle(manager, &handle1);
5863 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5865 hr = IMFDXGIDeviceManager_LockDevice(manager, handle, &IID_ID3D11Device, (void **)&device, FALSE);
5866 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5867 ID3D11Device_Release(device);
5869 hr = IMFDXGIDeviceManager_LockDevice(manager, handle1, &IID_ID3D11Device, (void **)&device, FALSE);
5870 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5871 ID3D11Device_Release(device);
5873 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle, FALSE);
5874 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5876 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle, FALSE);
5877 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5879 param.manager = manager;
5880 param.handle = handle;
5881 param.lock = TRUE;
5882 thread = CreateThread(NULL, 0, test_device_manager_thread, &param, 0, NULL);
5883 ok(!WaitForSingleObject(thread, 1000), "Wait for a test thread failed.\n");
5884 GetExitCodeThread(thread, (DWORD *)&hr);
5885 ok(hr == MF_E_DXGI_VIDEO_DEVICE_LOCKED, "Unexpected hr %#lx.\n", hr);
5886 CloseHandle(thread);
5888 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle1, FALSE);
5889 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5891 hr = IMFDXGIDeviceManager_UnlockDevice(manager, handle1, FALSE);
5892 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
5894 /* Lock on main thread, unlock on another. */
5895 hr = IMFDXGIDeviceManager_LockDevice(manager, handle, &IID_ID3D11Device, (void **)&device, FALSE);
5896 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5897 ID3D11Device_Release(device);
5899 param.manager = manager;
5900 param.handle = handle;
5901 param.lock = FALSE;
5902 thread = CreateThread(NULL, 0, test_device_manager_thread, &param, 0, NULL);
5903 ok(!WaitForSingleObject(thread, 1000), "Wait for a test thread failed.\n");
5904 GetExitCodeThread(thread, (DWORD *)&hr);
5905 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5906 CloseHandle(thread);
5908 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle1);
5909 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5911 hr = IMFDXGIDeviceManager_CloseDeviceHandle(manager, handle);
5912 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
5914 IMFDXGIDeviceManager_Release(manager);
5915 EXPECT_REF(d3d11_dev2, 1);
5916 ID3D11Device_Release(d3d11_dev);
5917 ID3D11Device_Release(d3d11_dev2);
5918 IMFDXGIDeviceManager_Release(manager2);
5921 static void test_MFCreateTransformActivate(void)
5923 IMFActivate *activate;
5924 UINT32 count;
5925 HRESULT hr;
5927 if (!pMFCreateTransformActivate)
5929 win_skip("MFCreateTransformActivate() is not available.\n");
5930 return;
5933 hr = pMFCreateTransformActivate(&activate);
5934 ok(hr == S_OK, "Failed to create activator, hr %#lx.\n", hr);
5936 hr = IMFActivate_GetCount(activate, &count);
5937 ok(hr == S_OK, "Failed to get count, hr %#lx.\n", hr);
5938 ok(!count, "Unexpected attribute count %u.\n", count);
5940 IMFActivate_Release(activate);
5943 static HRESULT WINAPI test_mft_factory_QueryInterface(IClassFactory *iface, REFIID riid, void **obj)
5945 if (IsEqualIID(riid, &IID_IClassFactory) ||
5946 IsEqualIID(riid, &IID_IUnknown))
5948 *obj = iface;
5949 IClassFactory_AddRef(iface);
5950 return S_OK;
5953 *obj = NULL;
5954 return E_NOINTERFACE;
5957 static ULONG WINAPI test_mft_factory_AddRef(IClassFactory *iface)
5959 return 2;
5962 static ULONG WINAPI test_mft_factory_Release(IClassFactory *iface)
5964 return 1;
5967 static HRESULT WINAPI test_mft_factory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **obj)
5969 ok(0, "Unexpected call.\n");
5970 return E_NOTIMPL;
5973 static HRESULT WINAPI test_mft_factory_LockServer(IClassFactory *iface, BOOL fLock)
5975 return S_OK;
5978 static const IClassFactoryVtbl test_mft_factory_vtbl =
5980 test_mft_factory_QueryInterface,
5981 test_mft_factory_AddRef,
5982 test_mft_factory_Release,
5983 test_mft_factory_CreateInstance,
5984 test_mft_factory_LockServer,
5987 static void test_MFTRegisterLocal(void)
5989 IClassFactory test_factory = { &test_mft_factory_vtbl };
5990 MFT_REGISTER_TYPE_INFO input_types[1], *in_types, *out_types;
5991 IMFAttributes *attributes;
5992 IMFActivate **activate;
5993 UINT32 count, count2;
5994 WCHAR *name;
5995 HRESULT hr;
5997 if (!pMFTRegisterLocal)
5999 win_skip("MFTRegisterLocal() is not available.\n");
6000 return;
6003 input_types[0].guidMajorType = MFMediaType_Audio;
6004 input_types[0].guidSubtype = MFAudioFormat_PCM;
6005 hr = pMFTRegisterLocal(&test_factory, &MFT_CATEGORY_OTHER, L"Local MFT name", 0, 1, input_types, 0, NULL);
6006 ok(hr == S_OK, "Failed to register MFT, hr %#lx.\n", hr);
6008 hr = pMFTRegisterLocal(&test_factory, &MFT_CATEGORY_OTHER, L"Local MFT name", 0, 1, input_types, 0, NULL);
6009 ok(hr == S_OK, "Failed to register MFT, hr %#lx.\n", hr);
6011 hr = pMFTEnumEx(MFT_CATEGORY_OTHER, MFT_ENUM_FLAG_LOCALMFT, NULL, NULL, &activate, &count);
6012 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6013 ok(count > 0, "Unexpected count %u.\n", count);
6014 CoTaskMemFree(activate);
6016 hr = pMFTUnregisterLocal(&test_factory);
6017 ok(hr == S_OK, "Failed to unregister MFT, hr %#lx.\n", hr);
6019 hr = pMFTEnumEx(MFT_CATEGORY_OTHER, MFT_ENUM_FLAG_LOCALMFT, NULL, NULL, &activate, &count2);
6020 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6021 ok(count2 < count, "Unexpected count %u.\n", count2);
6022 CoTaskMemFree(activate);
6024 hr = pMFTUnregisterLocal(&test_factory);
6025 ok(hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "Unexpected hr %#lx.\n", hr);
6027 hr = pMFTUnregisterLocal(NULL);
6028 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6030 hr = pMFTRegisterLocalByCLSID(&MFT_CATEGORY_OTHER, &MFT_CATEGORY_OTHER, L"Local MFT name 2", 0, 1, input_types,
6031 0, NULL);
6032 ok(hr == S_OK, "Failed to register MFT, hr %#lx.\n", hr);
6034 hr = MFTGetInfo(MFT_CATEGORY_OTHER, &name, &in_types, &count, &out_types, &count2, &attributes);
6035 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Unexpected hr %#lx.\n", hr);
6037 hr = pMFTUnregisterLocal(NULL);
6038 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6040 hr = pMFTUnregisterLocalByCLSID(MFT_CATEGORY_OTHER);
6041 ok(hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "Unexpected hr %#lx.\n", hr);
6043 hr = pMFTRegisterLocalByCLSID(&MFT_CATEGORY_OTHER, &MFT_CATEGORY_OTHER, L"Local MFT name 2", 0, 1, input_types,
6044 0, NULL);
6045 ok(hr == S_OK, "Failed to register MFT, hr %#lx.\n", hr);
6047 hr = pMFTUnregisterLocalByCLSID(MFT_CATEGORY_OTHER);
6048 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6051 static void test_queue_com(void)
6053 static int system_queues[] =
6055 MFASYNC_CALLBACK_QUEUE_STANDARD,
6056 MFASYNC_CALLBACK_QUEUE_RT,
6057 MFASYNC_CALLBACK_QUEUE_IO,
6058 MFASYNC_CALLBACK_QUEUE_TIMER,
6059 MFASYNC_CALLBACK_QUEUE_MULTITHREADED,
6060 MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION,
6063 static int user_queues[] =
6065 MF_STANDARD_WORKQUEUE,
6066 MF_WINDOW_WORKQUEUE,
6067 MF_MULTITHREADED_WORKQUEUE,
6070 char path_name[MAX_PATH];
6071 PROCESS_INFORMATION info;
6072 STARTUPINFOA startup;
6073 char **argv;
6074 int i;
6076 if (!pCoGetApartmentType)
6078 win_skip("CoGetApartmentType() is not available.\n");
6079 return;
6082 winetest_get_mainargs(&argv);
6084 for (i = 0; i < ARRAY_SIZE(system_queues); ++i)
6086 memset(&startup, 0, sizeof(startup));
6087 startup.cb = sizeof(startup);
6088 sprintf(path_name, "%s mfplat s%d", argv[0], system_queues[i]);
6089 ok(CreateProcessA( NULL, path_name, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info),
6090 "CreateProcess failed.\n" );
6091 wait_child_process(info.hProcess);
6092 CloseHandle(info.hProcess);
6093 CloseHandle(info.hThread);
6096 for (i = 0; i < ARRAY_SIZE(user_queues); ++i)
6098 memset(&startup, 0, sizeof(startup));
6099 startup.cb = sizeof(startup);
6100 sprintf(path_name, "%s mfplat u%d", argv[0], user_queues[i]);
6101 ok(CreateProcessA( NULL, path_name, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info),
6102 "CreateProcess failed.\n" );
6103 wait_child_process(info.hProcess);
6104 CloseHandle(info.hProcess);
6105 CloseHandle(info.hThread);
6109 static HRESULT WINAPI test_queue_com_state_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result)
6111 struct test_callback *callback = impl_from_IMFAsyncCallback(iface);
6112 APTTYPEQUALIFIER qualifier;
6113 APTTYPE com_type;
6114 HRESULT hr;
6116 hr = pCoGetApartmentType(&com_type, &qualifier);
6117 ok(SUCCEEDED(hr), "Failed to get apartment type, hr %#lx.\n", hr);
6118 if (SUCCEEDED(hr))
6120 todo_wine {
6121 if (callback->param == MFASYNC_CALLBACK_QUEUE_LONG_FUNCTION)
6122 ok(com_type == APTTYPE_MAINSTA && qualifier == APTTYPEQUALIFIER_NONE,
6123 "%#lx: unexpected type %u, qualifier %u.\n", callback->param, com_type, qualifier);
6124 else
6125 ok(com_type == APTTYPE_MTA && qualifier == APTTYPEQUALIFIER_NONE,
6126 "%#lx: unexpected type %u, qualifier %u.\n", callback->param, com_type, qualifier);
6130 SetEvent(callback->event);
6131 return S_OK;
6134 static const IMFAsyncCallbackVtbl test_queue_com_state_callback_vtbl =
6136 testcallback_QueryInterface,
6137 testcallback_AddRef,
6138 testcallback_Release,
6139 testcallback_GetParameters,
6140 test_queue_com_state_callback_Invoke,
6143 static void test_queue_com_state(const char *name)
6145 struct test_callback *callback;
6146 DWORD queue, queue_type;
6147 HRESULT hr;
6149 callback = create_test_callback(&test_queue_com_state_callback_vtbl);
6151 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
6152 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
6154 if (name[0] == 's')
6156 callback->param = name[1] - '0';
6157 hr = MFPutWorkItem(callback->param, &callback->IMFAsyncCallback_iface, NULL);
6158 ok(SUCCEEDED(hr), "Failed to queue work item, hr %#lx.\n", hr);
6159 WaitForSingleObject(callback->event, INFINITE);
6161 else if (name[0] == 'u')
6163 queue_type = name[1] - '0';
6165 hr = pMFAllocateWorkQueueEx(queue_type, &queue);
6166 ok(hr == S_OK || broken(queue_type == MF_MULTITHREADED_WORKQUEUE && hr == E_INVALIDARG) /* Win7 */,
6167 "Failed to allocate a queue of type %lu, hr %#lx.\n", queue_type, hr);
6169 if (SUCCEEDED(hr))
6171 callback->param = queue;
6172 hr = MFPutWorkItem(queue, &callback->IMFAsyncCallback_iface, NULL);
6173 ok(SUCCEEDED(hr), "Failed to queue work item, hr %#lx.\n", hr);
6174 WaitForSingleObject(callback->event, INFINITE);
6176 hr = MFUnlockWorkQueue(queue);
6177 ok(hr == S_OK, "Failed to unlock the queue, hr %#lx.\n", hr);
6181 hr = MFShutdown();
6182 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
6184 IMFAsyncCallback_Release(&callback->IMFAsyncCallback_iface);
6187 static void test_MFGetStrideForBitmapInfoHeader(void)
6189 static const struct stride_test
6191 const GUID *subtype;
6192 unsigned int width;
6193 LONG stride;
6195 stride_tests[] =
6197 { &MFVideoFormat_RGB8, 3, -4 },
6198 { &MFVideoFormat_RGB8, 1, -4 },
6199 { &MFVideoFormat_RGB555, 3, -8 },
6200 { &MFVideoFormat_RGB555, 1, -4 },
6201 { &MFVideoFormat_RGB565, 3, -8 },
6202 { &MFVideoFormat_RGB565, 1, -4 },
6203 { &MFVideoFormat_RGB24, 3, -12 },
6204 { &MFVideoFormat_RGB24, 1, -4 },
6205 { &MFVideoFormat_RGB32, 3, -12 },
6206 { &MFVideoFormat_RGB32, 1, -4 },
6207 { &MFVideoFormat_ARGB32, 3, -12 },
6208 { &MFVideoFormat_ARGB32, 1, -4 },
6209 { &MFVideoFormat_A2R10G10B10, 3, -12 },
6210 { &MFVideoFormat_A2R10G10B10, 1, -4 },
6211 { &MFVideoFormat_A2B10G10R10, 3, -12 },
6212 { &MFVideoFormat_A2B10G10R10, 1, -4 },
6213 { &MFVideoFormat_A16B16G16R16F, 3, -24 },
6214 { &MFVideoFormat_A16B16G16R16F, 1, -8 },
6216 /* YUV */
6217 { &MFVideoFormat_NV12, 1, 1 },
6218 { &MFVideoFormat_NV12, 2, 2 },
6219 { &MFVideoFormat_NV12, 3, 3 },
6220 { &MFVideoFormat_AYUV, 1, 4 },
6221 { &MFVideoFormat_AYUV, 4, 16 },
6222 { &MFVideoFormat_AYUV, 5, 20 },
6223 { &MFVideoFormat_IMC1, 1, 4 },
6224 { &MFVideoFormat_IMC1, 2, 4 },
6225 { &MFVideoFormat_IMC1, 3, 8 },
6226 { &MFVideoFormat_IMC3, 1, 4 },
6227 { &MFVideoFormat_IMC3, 2, 4 },
6228 { &MFVideoFormat_IMC3, 3, 8 },
6229 { &MFVideoFormat_IMC2, 1, 1 },
6230 { &MFVideoFormat_IMC2, 2, 2 },
6231 { &MFVideoFormat_IMC2, 3, 3 },
6232 { &MFVideoFormat_IMC4, 1, 1 },
6233 { &MFVideoFormat_IMC4, 2, 2 },
6234 { &MFVideoFormat_IMC4, 3, 3 },
6235 { &MFVideoFormat_YV12, 1, 1 },
6236 { &MFVideoFormat_YV12, 2, 2 },
6237 { &MFVideoFormat_YV12, 3, 3 },
6238 { &MFVideoFormat_YV12, 320, 320 },
6239 { &MFVideoFormat_I420, 1, 1 },
6240 { &MFVideoFormat_I420, 2, 2 },
6241 { &MFVideoFormat_I420, 3, 3 },
6242 { &MFVideoFormat_I420, 320, 320 },
6243 { &MFVideoFormat_IYUV, 1, 1 },
6244 { &MFVideoFormat_IYUV, 2, 2 },
6245 { &MFVideoFormat_IYUV, 3, 3 },
6246 { &MFVideoFormat_IYUV, 320, 320 },
6247 { &MFVideoFormat_NV11, 1, 1 },
6248 { &MFVideoFormat_NV11, 2, 2 },
6249 { &MFVideoFormat_NV11, 3, 3 },
6251 unsigned int i;
6252 LONG stride;
6253 HRESULT hr;
6255 if (!pMFGetStrideForBitmapInfoHeader)
6257 win_skip("MFGetStrideForBitmapInfoHeader() is not available.\n");
6258 return;
6261 hr = pMFGetStrideForBitmapInfoHeader(MAKEFOURCC('H','2','6','4'), 1, &stride);
6262 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
6264 for (i = 0; i < ARRAY_SIZE(stride_tests); ++i)
6266 hr = pMFGetStrideForBitmapInfoHeader(stride_tests[i].subtype->Data1, stride_tests[i].width, &stride);
6267 ok(hr == S_OK, "%u: failed to get stride, hr %#lx.\n", i, hr);
6268 ok(stride == stride_tests[i].stride, "%u: format %s, unexpected stride %ld, expected %ld.\n", i,
6269 wine_dbgstr_an((char *)&stride_tests[i].subtype->Data1, 4), stride, stride_tests[i].stride);
6273 static void test_MFCreate2DMediaBuffer(void)
6275 static const char two_aas[] = { 0xaa, 0xaa };
6276 static const char eight_bbs[] = { 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb };
6277 DWORD max_length, length, length2;
6278 BYTE *buffer_start, *data, *data2;
6279 LONG pitch, pitch2, stride;
6280 IMF2DBuffer2 *_2dbuffer2;
6281 IMF2DBuffer *_2dbuffer;
6282 IMFMediaBuffer *buffer;
6283 int i, j, k;
6284 HRESULT hr;
6285 BOOL ret;
6287 if (!pMFCreate2DMediaBuffer)
6289 win_skip("MFCreate2DMediaBuffer() is not available.\n");
6290 return;
6293 hr = pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('H','2','6','4'), FALSE, &buffer);
6294 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
6296 hr = pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('N','V','1','2'), FALSE, NULL);
6297 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
6299 /* YUV formats can't be bottom-up. */
6300 hr = pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('N','V','1','2'), TRUE, &buffer);
6301 ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#lx.\n", hr);
6303 hr = pMFCreate2DMediaBuffer(2, 3, MAKEFOURCC('N','V','1','2'), FALSE, &buffer);
6304 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
6306 check_interface(buffer, &IID_IMFGetService, TRUE);
6307 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
6309 /* Full backing buffer size, with 64 bytes per row alignment. */
6310 hr = IMFMediaBuffer_GetMaxLength(buffer, &max_length);
6311 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
6312 ok(max_length > 0, "Unexpected length %lu.\n", max_length);
6314 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
6315 ok(hr == S_OK, "Failed to get current length, hr %#lx.\n", hr);
6316 ok(!length, "Unexpected length.\n");
6318 hr = IMFMediaBuffer_SetCurrentLength(buffer, 10);
6319 ok(hr == S_OK, "Failed to set current length, hr %#lx.\n", hr);
6321 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
6322 ok(hr == S_OK, "Failed to get current length, hr %#lx.\n", hr);
6323 ok(length == 10, "Unexpected length.\n");
6325 /* Linear lock/unlock. */
6327 hr = IMFMediaBuffer_Lock(buffer, NULL, &max_length, &length);
6328 ok(FAILED(hr), "Unexpected hr %#lx.\n", hr);
6330 /* Linear locking call returns plane size.*/
6331 hr = IMFMediaBuffer_Lock(buffer, &data, &max_length, &length);
6332 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6333 ok(max_length == length, "Unexpected length.\n");
6335 memset(data, 0xaa, length);
6337 length = 0;
6338 pMFGetPlaneSize(MAKEFOURCC('N','V','1','2'), 2, 3, &length);
6339 ok(max_length == length && length == 9, "Unexpected length %lu.\n", length);
6341 /* Already locked */
6342 hr = IMFMediaBuffer_Lock(buffer, &data2, NULL, NULL);
6343 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6344 ok(data2 == data, "Unexpected pointer.\n");
6346 hr = IMFMediaBuffer_Unlock(buffer);
6347 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6349 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2dbuffer);
6350 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
6352 hr = IMF2DBuffer_GetContiguousLength(_2dbuffer, NULL);
6353 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6355 hr = IMF2DBuffer_GetContiguousLength(_2dbuffer, &length);
6356 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
6357 ok(length == 9, "Unexpected length %lu.\n", length);
6359 hr = IMF2DBuffer_IsContiguousFormat(_2dbuffer, NULL);
6360 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6362 /* 2D lock. */
6363 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
6364 ok(hr == MF_E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
6366 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, &data, &pitch);
6367 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
6369 hr = IMFMediaBuffer_Unlock(buffer);
6370 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6372 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, &data, &pitch);
6373 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
6375 hr = IMF2DBuffer_Lock2D(_2dbuffer, NULL, NULL);
6376 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6378 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, NULL);
6379 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6381 hr = IMF2DBuffer_Lock2D(_2dbuffer, NULL, &pitch);
6382 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6384 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
6385 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6386 ok(!!data, "Expected data pointer.\n");
6387 ok(pitch == 64, "Unexpected pitch %ld.\n", pitch);
6389 for (i = 0; i < 4; i++)
6390 ok(memcmp(&data[64 * i], two_aas, sizeof(two_aas)) == 0, "Invalid data instead of 0xaa.\n");
6391 memset(data, 0xbb, 194);
6393 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data2, &pitch);
6394 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6395 ok(data == data2, "Expected data pointer.\n");
6397 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, NULL, &pitch);
6398 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6400 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, &data, NULL);
6401 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6403 /* Active 2D lock */
6404 hr = IMFMediaBuffer_Lock(buffer, &data2, NULL, NULL);
6405 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
6407 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6408 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6410 hr = IMFMediaBuffer_Lock(buffer, &data2, NULL, NULL);
6411 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
6413 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6414 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6416 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6417 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
6419 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
6420 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6422 ok(memcmp(data, eight_bbs, sizeof(eight_bbs)) == 0, "Invalid data instead of 0xbb.\n");
6424 hr = IMFMediaBuffer_Unlock(buffer);
6425 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6427 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2);
6428 ok(hr == S_OK || broken(hr == E_NOINTERFACE), "Failed to get interface, hr %#lx.\n", hr);
6430 if (SUCCEEDED(hr))
6432 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
6433 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6435 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data2, &pitch, &buffer_start, &length);
6436 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6438 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6439 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6441 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6442 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6444 /* Flags are ignored. */
6445 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data2, &pitch, &buffer_start, &length);
6446 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6448 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data2, &pitch, &buffer_start, &length);
6449 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6451 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6452 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6454 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6455 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6457 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data2, &pitch, NULL, &length);
6458 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6460 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data2, &pitch, &buffer_start, NULL);
6461 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
6463 IMF2DBuffer2_Release(_2dbuffer2);
6465 else
6466 win_skip("IMF2DBuffer2 is not supported.\n");
6468 IMF2DBuffer_Release(_2dbuffer);
6470 IMFMediaBuffer_Release(buffer);
6472 for (i = 0; i < ARRAY_SIZE(image_size_tests); ++i)
6474 const struct image_size_test *ptr = &image_size_tests[i];
6476 if (is_MEDIASUBTYPE_RGB(ptr->subtype))
6477 continue;
6479 winetest_push_context("%u, %u x %u, format %s", i, ptr->width, ptr->height, wine_dbgstr_guid(ptr->subtype));
6481 hr = pMFCreate2DMediaBuffer(ptr->width, ptr->height, ptr->subtype->Data1, FALSE, &buffer);
6482 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
6484 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
6485 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6486 ok(length == ptr->max_length, "Unexpected maximum length %lu.\n", length);
6488 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2dbuffer);
6489 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
6491 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2);
6492 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
6494 hr = IMF2DBuffer_GetContiguousLength(_2dbuffer, &length);
6495 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
6496 ok(length == ptr->contiguous_length, "Unexpected contiguous length %lu.\n", length);
6498 data2 = malloc(ptr->contiguous_length + 16);
6499 ok(!!data2, "Failed to allocate buffer.\n");
6501 for (j = 0; j < ptr->contiguous_length + 16; j++)
6502 data2[j] = j & 0x7f;
6504 hr = IMF2DBuffer2_ContiguousCopyFrom(_2dbuffer2, data2, ptr->contiguous_length - 1);
6505 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
6507 hr = IMFMediaBuffer_Lock(buffer, &data, &length2, NULL);
6508 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6509 ok(length2 == ptr->contiguous_length, "Unexpected linear buffer length %lu.\n", length2);
6511 memset(data, 0xff, length2);
6513 hr = IMFMediaBuffer_Unlock(buffer);
6514 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6516 hr = IMF2DBuffer2_ContiguousCopyFrom(_2dbuffer2, data2, ptr->contiguous_length + 16);
6517 ok(hr == S_OK, "Failed to copy from contiguous buffer, hr %#lx.\n", hr);
6519 hr = IMFMediaBuffer_Lock(buffer, &data, &length2, NULL);
6520 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6521 ok(length2 == ptr->contiguous_length, "%d: unexpected linear buffer length %lu for %u x %u, format %s.\n",
6522 i, length2, ptr->width, ptr->height, wine_dbgstr_guid(ptr->subtype));
6524 for (j = 0; j < ptr->contiguous_length; j++)
6526 if (IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC1) || IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC3))
6528 if (j < ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width)
6529 continue;
6530 if (j >= ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width / 2)
6531 continue;
6533 if (data[j] != (j & 0x7f))
6534 break;
6536 ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data[j], j & 0x7f, j);
6538 memset(data, 0xff, length2);
6540 hr = IMFMediaBuffer_Unlock(buffer);
6541 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6543 hr = IMF2DBuffer2_ContiguousCopyFrom(_2dbuffer2, data2, ptr->contiguous_length);
6544 ok(hr == S_OK, "Failed to copy from contiguous buffer, hr %#lx.\n", hr);
6546 hr = IMFMediaBuffer_Lock(buffer, &data, &length2, NULL);
6547 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6548 ok(length2 == ptr->contiguous_length, "%d: unexpected linear buffer length %lu for %u x %u, format %s.\n",
6549 i, length2, ptr->width, ptr->height, wine_dbgstr_guid(ptr->subtype));
6551 for (j = 0; j < ptr->contiguous_length; j++)
6553 if (IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC1) || IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC3))
6555 if (j < ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width)
6556 continue;
6557 if (j >= ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width / 2)
6558 continue;
6560 if (data[j] != (j & 0x7f))
6561 break;
6563 ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data[j], j & 0x7f, j);
6565 hr = IMFMediaBuffer_Unlock(buffer);
6566 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6568 hr = IMF2DBuffer2_ContiguousCopyTo(_2dbuffer2, data2, ptr->contiguous_length - 1);
6569 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
6571 memset(data2, 0xff, ptr->contiguous_length + 16);
6573 hr = IMF2DBuffer2_ContiguousCopyTo(_2dbuffer2, data2, ptr->contiguous_length + 16);
6574 ok(hr == S_OK, "Failed to copy to contiguous buffer, hr %#lx.\n", hr);
6576 for (j = 0; j < ptr->contiguous_length; j++)
6578 if (IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC1) || IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC3))
6580 if (j < ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width)
6581 continue;
6582 if (j >= ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width / 2)
6583 continue;
6585 if (data2[j] != (j & 0x7f))
6586 break;
6588 ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data2[j], j & 0x7f, j);
6590 memset(data2, 0xff, ptr->contiguous_length + 16);
6592 hr = IMF2DBuffer2_ContiguousCopyTo(_2dbuffer2, data2, ptr->contiguous_length);
6593 ok(hr == S_OK, "Failed to copy to contiguous buffer, hr %#lx.\n", hr);
6595 for (j = 0; j < ptr->contiguous_length; j++)
6597 if (IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC1) || IsEqualGUID(ptr->subtype, &MFVideoFormat_IMC3))
6599 if (j < ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width)
6600 continue;
6601 if (j >= ptr->height * ptr->pitch && j % ptr->pitch >= ptr->width / 2)
6602 continue;
6604 if (data2[j] != (j & 0x7f))
6605 break;
6607 ok(j == ptr->contiguous_length, "Unexpected byte %02x instead of %02x at position %u.\n", data2[j], j & 0x7f, j);
6609 free(data2);
6611 hr = IMFMediaBuffer_Lock(buffer, &data, &length2, NULL);
6612 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6613 ok(length2 == ptr->contiguous_length, "%d: unexpected linear buffer length %lu for %u x %u, format %s.\n",
6614 i, length2, ptr->width, ptr->height, wine_dbgstr_guid(ptr->subtype));
6616 hr = pMFGetStrideForBitmapInfoHeader(ptr->subtype->Data1, ptr->width, &stride);
6617 ok(hr == S_OK, "Failed to get stride, hr %#lx.\n", hr);
6618 stride = abs(stride);
6620 /* primary plane */
6621 ok(ptr->height * stride <= length2, "Insufficient buffer space: expected at least %lu bytes, got only %lu\n",
6622 ptr->height * stride, length2);
6623 for (j = 0; j < ptr->height; j++)
6624 for (k = 0; k < stride; k++)
6625 data[j * stride + k] = ((j % 16) << 4) + (k % 16);
6627 data += ptr->height * stride;
6629 /* secondary planes */
6630 switch (ptr->subtype->Data1)
6632 case MAKEFOURCC('I','M','C','1'):
6633 case MAKEFOURCC('I','M','C','3'):
6634 ok(2 * ptr->height * stride <= length2, "Insufficient buffer space: expected at least %lu bytes, got only %lu\n",
6635 2 * ptr->height * stride, length2);
6636 for (j = 0; j < ptr->height; j++)
6637 for (k = 0; k < stride / 2; k++)
6638 data[j * stride + k] = (((j + ptr->height) % 16) << 4) + (k % 16);
6639 break;
6641 case MAKEFOURCC('I','M','C','2'):
6642 case MAKEFOURCC('I','M','C','4'):
6643 case MAKEFOURCC('N','V','1','1'):
6644 case MAKEFOURCC('Y','V','1','2'):
6645 case MAKEFOURCC('I','4','2','0'):
6646 case MAKEFOURCC('I','Y','U','V'):
6647 ok(stride * 3 / 2 * ptr->height <= length2, "Insufficient buffer space: expected at least %lu bytes, got only %lu\n",
6648 stride * 3 / 2 * ptr->height, length2);
6649 for (j = 0; j < ptr->height; j++)
6650 for (k = 0; k < stride / 2; k++)
6651 data[j * (stride / 2) + k] = (((j + ptr->height) % 16) << 4) + (k % 16);
6652 break;
6654 case MAKEFOURCC('N','V','1','2'):
6655 ok(stride * ptr->height * 3 / 2 <= length2, "Insufficient buffer space: expected at least %lu bytes, got only %lu\n",
6656 stride * ptr->height * 3 / 2, length2);
6657 for (j = 0; j < ptr->height / 2; j++)
6658 for (k = 0; k < stride; k++)
6659 data[j * stride + k] = (((j + ptr->height) % 16) << 4) + (k % 16);
6660 break;
6663 hr = IMFMediaBuffer_Unlock(buffer);
6664 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6666 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
6667 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6669 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, &data2, &pitch2);
6670 ok(hr == S_OK, "Failed to get scanline, hr %#lx.\n", hr);
6671 ok(data2 == data, "Unexpected data pointer.\n");
6672 ok(pitch == pitch2, "Unexpected pitch.\n");
6674 /* primary plane */
6675 for (j = 0; j < ptr->height; j++)
6676 for (k = 0; k < stride; k++)
6677 ok(data[j * pitch + k] == ((j % 16) << 4) + (k % 16),
6678 "Unexpected byte %02x instead of %02x at row %d column %d.\n",
6679 data[j * pitch + k], ((j % 16) << 4) + (k % 16), j, k);
6681 data += ptr->height * pitch;
6683 /* secondary planes */
6684 switch (ptr->subtype->Data1)
6686 case MAKEFOURCC('I','M','C','1'):
6687 case MAKEFOURCC('I','M','C','3'):
6688 for (j = 0; j < ptr->height; j++)
6689 for (k = 0; k < stride / 2; k++)
6690 ok(data[j * pitch + k] == (((j + ptr->height) % 16) << 4) + (k % 16),
6691 "Unexpected byte %02x instead of %02x at row %d column %d.\n",
6692 data[j * pitch + k], (((j + ptr->height) % 16) << 4) + (k % 16), j + ptr->height, k);
6693 break;
6695 case MAKEFOURCC('I','M','C','2'):
6696 case MAKEFOURCC('I','M','C','4'):
6697 case MAKEFOURCC('N','V','1','1'):
6698 case MAKEFOURCC('Y','V','1','2'):
6699 case MAKEFOURCC('I','4','2','0'):
6700 case MAKEFOURCC('I','Y','U','V'):
6701 for (j = 0; j < ptr->height; j++)
6702 for (k = 0; k < stride / 2; k++)
6703 ok(data[j * (pitch / 2) + k] == (((j + ptr->height) % 16) << 4) + (k % 16),
6704 "Unexpected byte %02x instead of %02x at row %d column %d.\n",
6705 data[j * (pitch / 2) + k], (((j + ptr->height) % 16) << 4) + (k % 16), j + ptr->height, k);
6706 break;
6708 case MAKEFOURCC('N','V','1','2'):
6709 for (j = 0; j < ptr->height / 2; j++)
6710 for (k = 0; k < stride; k++)
6711 ok(data[j * pitch + k] == (((j + ptr->height) % 16) << 4) + (k % 16),
6712 "Unexpected byte %02x instead of %02x at row %d column %d.\n",
6713 data[j * pitch + k], (((j + ptr->height) % 16) << 4) + (k % 16), j + ptr->height, k);
6714 break;
6716 default:
6720 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6721 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6723 ok(pitch == ptr->pitch, "Unexpected pitch %ld, expected %d.\n", pitch, ptr->pitch);
6725 ret = TRUE;
6726 hr = IMF2DBuffer_IsContiguousFormat(_2dbuffer, &ret);
6727 ok(hr == S_OK, "Failed to get format flag, hr %#lx.\n", hr);
6728 ok(!ret, "%d: unexpected format flag %d.\n", i, ret);
6730 IMF2DBuffer_Release(_2dbuffer);
6731 IMF2DBuffer2_Release(_2dbuffer2);
6733 IMFMediaBuffer_Release(buffer);
6735 winetest_pop_context();
6738 /* Alignment tests */
6739 for (i = 0; i < ARRAY_SIZE(image_size_tests); ++i)
6741 const struct image_size_test *ptr = &image_size_tests[i];
6743 if (is_MEDIASUBTYPE_RGB(ptr->subtype))
6744 continue;
6746 hr = pMFCreate2DMediaBuffer(ptr->width, ptr->height, ptr->subtype->Data1, FALSE, &buffer);
6747 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
6749 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2dbuffer);
6750 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
6752 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
6753 ok(hr == S_OK, "Failed to lock buffer, hr %#lx.\n", hr);
6754 ok(((uintptr_t)data & MF_64_BYTE_ALIGNMENT) == 0, "Misaligned data at %p.\n", data);
6756 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
6757 ok(hr == S_OK, "Failed to unlock buffer, hr %#lx.\n", hr);
6759 IMF2DBuffer_Release(_2dbuffer);
6760 IMFMediaBuffer_Release(buffer);
6764 static void test_MFCreateMediaBufferFromMediaType(void)
6766 static struct audio_buffer_test
6768 unsigned int duration;
6769 unsigned int min_length;
6770 unsigned int min_alignment;
6771 unsigned int block_alignment;
6772 unsigned int bytes_per_second;
6773 unsigned int buffer_length;
6774 } audio_tests[] =
6776 { 0, 0, 0, 4, 0, 20 },
6777 { 0, 16, 0, 4, 0, 20 },
6778 { 0, 0, 32, 4, 0, 36 },
6779 { 0, 64, 32, 4, 0, 64 },
6780 { 1, 0, 0, 4, 16, 36 },
6781 { 2, 0, 0, 4, 16, 52 },
6782 { 2, 0, 64, 4, 16, 68 },
6783 { 2, 0, 128, 4, 16,132 },
6785 IMFMediaType *media_type, *media_type2;
6786 unsigned int i, alignment;
6787 IMFMediaBuffer *buffer;
6788 DWORD length, max;
6789 BYTE *data;
6790 HRESULT hr;
6792 if (!pMFCreateMediaBufferFromMediaType)
6794 win_skip("MFCreateMediaBufferFromMediaType() is not available.\n");
6795 return;
6798 hr = pMFCreateMediaBufferFromMediaType(NULL, 0, 0, 0, &buffer);
6799 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
6801 hr = MFCreateMediaType(&media_type);
6802 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
6804 hr = MFCreateMediaType(&media_type2);
6805 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
6807 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
6808 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
6810 hr = IMFMediaType_CopyAllItems(media_type, (IMFAttributes *)media_type2);
6811 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6813 for (i = 0; i < ARRAY_SIZE(audio_tests); ++i)
6815 const struct audio_buffer_test *ptr = &audio_tests[i];
6817 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, ptr->block_alignment);
6818 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
6820 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, ptr->bytes_per_second);
6821 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
6823 hr = pMFCreateMediaBufferFromMediaType(media_type, ptr->duration * 10000000, ptr->min_length,
6824 ptr->min_alignment, &buffer);
6825 ok(hr == S_OK || broken(FAILED(hr)) /* Win8 */, "Unexpected hr %#lx.\n", hr);
6826 if (FAILED(hr))
6827 break;
6829 check_interface(buffer, &IID_IMFGetService, FALSE);
6831 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
6832 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
6833 ok(ptr->buffer_length == length, "%d: unexpected buffer length %lu, expected %u.\n", i, length, ptr->buffer_length);
6835 alignment = ptr->min_alignment ? ptr->min_alignment - 1 : MF_16_BYTE_ALIGNMENT;
6836 hr = IMFMediaBuffer_Lock(buffer, &data, &max, &length);
6837 ok(hr == S_OK, "Failed to lock, hr %#lx.\n", hr);
6838 ok(ptr->buffer_length == max && !length, "Unexpected length.\n");
6839 ok(!((uintptr_t)data & alignment), "%u: data at %p is misaligned.\n", i, data);
6840 hr = IMFMediaBuffer_Unlock(buffer);
6841 ok(hr == S_OK, "Failed to unlock, hr %#lx.\n", hr);
6843 IMFMediaBuffer_Release(buffer);
6845 /* Only major type is set. */
6846 hr = pMFCreateMediaBufferFromMediaType(media_type2, ptr->duration * 10000000, ptr->min_length,
6847 ptr->min_alignment, &buffer);
6848 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
6850 hr = IMFMediaBuffer_GetMaxLength(buffer, &length);
6851 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
6852 ok(ptr->min_length == length, "%u: unexpected buffer length %lu, expected %u.\n", i, length, ptr->min_length);
6854 hr = IMFMediaBuffer_Lock(buffer, &data, &max, &length);
6855 ok(hr == S_OK, "Failed to lock, hr %#lx.\n", hr);
6856 ok(ptr->min_length == max && !length, "Unexpected length.\n");
6857 ok(!((uintptr_t)data & alignment), "%u: data at %p is misaligned.\n", i, data);
6858 hr = IMFMediaBuffer_Unlock(buffer);
6859 ok(hr == S_OK, "Failed to unlock, hr %#lx.\n", hr);
6861 IMFMediaBuffer_Release(buffer);
6864 IMFMediaType_Release(media_type);
6865 IMFMediaType_Release(media_type2);
6868 static void validate_media_type(IMFMediaType *mediatype, const WAVEFORMATEX *format)
6870 GUID guid, subtype;
6871 UINT32 value;
6872 HRESULT hr;
6874 hr = IMFMediaType_GetMajorType(mediatype, &guid);
6875 ok(hr == S_OK, "Failed to get major type, hr %#lx.\n", hr);
6876 ok(IsEqualGUID(&guid, &MFMediaType_Audio), "Unexpected major type %s.\n", wine_dbgstr_guid(&guid));
6878 hr = IMFMediaType_GetGUID(mediatype, &MF_MT_SUBTYPE, &guid);
6879 ok(hr == S_OK, "Failed to get subtype, hr %#lx.\n", hr);
6881 if (format->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
6883 const WAVEFORMATEXTENSIBLE *fex = (const WAVEFORMATEXTENSIBLE *)format;
6884 ok(IsEqualGUID(&guid, &fex->SubFormat), "Unexpected subtype %s.\n", wine_dbgstr_guid(&guid));
6886 if (fex->dwChannelMask)
6888 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_CHANNEL_MASK, &value);
6889 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6890 ok(value == fex->dwChannelMask, "Unexpected CHANNEL_MASK %#x.\n", value);
6893 if (format->wBitsPerSample && fex->Samples.wValidBitsPerSample)
6895 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, &value);
6896 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6897 ok(value == fex->Samples.wValidBitsPerSample, "Unexpected VALID_BITS_PER_SAMPLE %#x.\n", value);
6900 else
6902 memcpy(&subtype, &MFAudioFormat_Base, sizeof(subtype));
6903 subtype.Data1 = format->wFormatTag;
6904 ok(IsEqualGUID(&guid, &subtype), "Unexpected subtype %s.\n", wine_dbgstr_guid(&guid));
6906 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_PREFER_WAVEFORMATEX, &value);
6907 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6908 ok(value, "Unexpected value.\n");
6911 if (format->nChannels)
6913 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_NUM_CHANNELS, &value);
6914 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6915 ok(value == format->nChannels, "Unexpected NUM_CHANNELS %u.\n", value);
6918 if (format->nSamplesPerSec)
6920 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_SAMPLES_PER_SECOND, &value);
6921 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6922 ok(value == format->nSamplesPerSec, "Unexpected SAMPLES_PER_SECOND %u.\n", value);
6925 if (format->nAvgBytesPerSec)
6927 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, &value);
6928 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6929 ok(value == format->nAvgBytesPerSec, "Unexpected AVG_BYTES_PER_SECOND %u.\n", value);
6932 if (format->nBlockAlign)
6934 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BLOCK_ALIGNMENT, &value);
6935 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6936 ok(value == format->nBlockAlign, "Unexpected BLOCK_ALIGNMENT %u.\n", value);
6939 if (format->wBitsPerSample)
6941 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AUDIO_BITS_PER_SAMPLE, &value);
6942 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6943 ok(value == format->wBitsPerSample, "Unexpected BITS_PER_SAMPLE %u.\n", value);
6946 /* Only set for uncompressed formats. */
6947 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value);
6948 if (IsEqualGUID(&guid, &MFAudioFormat_Float) ||
6949 IsEqualGUID(&guid, &MFAudioFormat_PCM))
6951 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
6952 ok(value, "Unexpected ALL_SAMPLES_INDEPENDENT value.\n");
6954 else
6955 ok(FAILED(hr), "Unexpected ALL_SAMPLES_INDEPENDENT.\n");
6957 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_FIXED_SIZE_SAMPLES, &value);
6958 ok(FAILED(hr), "Unexpected FIXED_SIZE_SAMPLES.\n");
6959 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_COMPRESSED, &value);
6960 ok(FAILED(hr), "Unexpected COMPRESSED.\n");
6963 static void test_MFInitMediaTypeFromWaveFormatEx(void)
6965 static const WAVEFORMATEX waveformatex_tests[] =
6967 { WAVE_FORMAT_PCM, 2, 44100, 0, 2, 8 },
6968 { WAVE_FORMAT_PCM, 2, 44100, 1, 2, 8 },
6969 { WAVE_FORMAT_PCM, 0, 44100, 0, 0, 0 },
6970 { WAVE_FORMAT_PCM, 0, 0, 0, 0, 0 },
6971 { WAVE_FORMAT_IEEE_FLOAT, 2, 44100, 1, 2, 8 },
6972 { 1234, 0, 0, 0, 0, 0 },
6973 { WAVE_FORMAT_ALAW },
6974 { WAVE_FORMAT_CREATIVE_ADPCM },
6975 { WAVE_FORMAT_MPEGLAYER3 },
6976 { WAVE_FORMAT_MPEG_ADTS_AAC },
6977 { WAVE_FORMAT_ALAC },
6978 { WAVE_FORMAT_AMR_NB },
6979 { WAVE_FORMAT_AMR_WB },
6980 { WAVE_FORMAT_AMR_WP },
6981 { WAVE_FORMAT_DOLBY_AC3_SPDIF },
6982 { WAVE_FORMAT_DRM },
6983 { WAVE_FORMAT_DTS },
6984 { WAVE_FORMAT_FLAC },
6985 { WAVE_FORMAT_MPEG },
6986 { WAVE_FORMAT_WMAVOICE9 },
6987 { WAVE_FORMAT_OPUS },
6988 { WAVE_FORMAT_WMAUDIO2 },
6989 { WAVE_FORMAT_WMAUDIO3 },
6990 { WAVE_FORMAT_WMAUDIO_LOSSLESS },
6991 { WAVE_FORMAT_WMASPDIF },
6994 UINT8 buff[1024];
6995 WAVEFORMATEXTENSIBLE waveformatext;
6996 MPEGLAYER3WAVEFORMAT mp3format;
6997 WAVEFORMATEXTENSIBLE *format;
6998 HEAACWAVEFORMAT aacformat;
6999 IMFMediaType *mediatype;
7000 unsigned int i, size;
7001 UINT32 value;
7002 HRESULT hr;
7004 hr = MFCreateMediaType(&mediatype);
7005 ok(hr == S_OK, "Failed to create mediatype, hr %#lx.\n", hr);
7007 for (i = 0; i < ARRAY_SIZE(waveformatex_tests); ++i)
7009 hr = MFInitMediaTypeFromWaveFormatEx(mediatype, &waveformatex_tests[i], sizeof(waveformatex_tests[i]));
7010 ok(hr == S_OK, "%d: format %#x, failed to initialize media type, hr %#lx.\n", i, waveformatex_tests[i].wFormatTag, hr);
7012 validate_media_type(mediatype, &waveformatex_tests[i]);
7014 waveformatext.Format = waveformatex_tests[i];
7015 waveformatext.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
7016 waveformatext.Format.cbSize = sizeof(waveformatext) - sizeof(waveformatext.Format);
7017 waveformatext.Samples.wSamplesPerBlock = 123;
7018 waveformatext.dwChannelMask = 0x8;
7019 memcpy(&waveformatext.SubFormat, &MFAudioFormat_Base, sizeof(waveformatext.SubFormat));
7020 waveformatext.SubFormat.Data1 = waveformatex_tests[i].wFormatTag;
7022 hr = MFInitMediaTypeFromWaveFormatEx(mediatype, &waveformatext.Format, sizeof(waveformatext));
7023 ok(hr == S_OK, "Failed to initialize media type, hr %#lx.\n", hr);
7025 hr = IMFMediaType_GetItem(mediatype, &MF_MT_USER_DATA, NULL);
7026 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7028 validate_media_type(mediatype, &waveformatext.Format);
7031 /* MPEGLAYER3WAVEFORMAT */
7032 mp3format.wfx.wFormatTag = WAVE_FORMAT_MPEGLAYER3;
7033 mp3format.wfx.nChannels = 2;
7034 mp3format.wfx.nSamplesPerSec = 44100;
7035 mp3format.wfx.nAvgBytesPerSec = 16000;
7036 mp3format.wfx.nBlockAlign = 1;
7037 mp3format.wfx.wBitsPerSample = 0;
7038 mp3format.wfx.cbSize = MPEGLAYER3_WFX_EXTRA_BYTES;
7039 mp3format.wID = MPEGLAYER3_ID_MPEG;
7040 mp3format.fdwFlags = 0;
7041 mp3format.nBlockSize = 417;
7042 mp3format.nFramesPerBlock = 0;
7043 mp3format.nCodecDelay = 0;
7045 hr = MFInitMediaTypeFromWaveFormatEx(mediatype, (WAVEFORMATEX *)&mp3format, sizeof(mp3format));
7046 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7048 validate_media_type(mediatype, &mp3format.wfx);
7049 hr = IMFMediaType_GetBlob(mediatype, &MF_MT_USER_DATA, buff, sizeof(buff), &size);
7050 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7051 ok(size == mp3format.wfx.cbSize, "Unexpected size %u.\n", size);
7052 ok(!memcmp(buff, (WAVEFORMATEX *)&mp3format + 1, size), "Unexpected user data.\n");
7054 /* HEAACWAVEFORMAT */
7055 aacformat.wfInfo.wfx.wFormatTag = WAVE_FORMAT_MPEG_HEAAC;
7056 aacformat.wfInfo.wfx.nChannels = 2;
7057 aacformat.wfInfo.wfx.nSamplesPerSec = 44100;
7058 aacformat.wfInfo.wfx.nAvgBytesPerSec = 16000;
7059 aacformat.wfInfo.wfx.nBlockAlign = 1;
7060 aacformat.wfInfo.wfx.wBitsPerSample = 0;
7061 aacformat.wfInfo.wPayloadType = 2;
7062 aacformat.wfInfo.wAudioProfileLevelIndication = 1;
7063 aacformat.pbAudioSpecificConfig[0] = 0xcd;
7065 /* test with invalid format size */
7066 aacformat.wfInfo.wfx.cbSize = sizeof(aacformat) - 2 - sizeof(WAVEFORMATEX);
7067 hr = MFInitMediaTypeFromWaveFormatEx(mediatype, (WAVEFORMATEX *)&aacformat, sizeof(aacformat) - 2);
7068 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
7070 aacformat.wfInfo.wfx.cbSize = sizeof(aacformat) - sizeof(WAVEFORMATEX);
7071 hr = MFInitMediaTypeFromWaveFormatEx(mediatype, (WAVEFORMATEX *)&aacformat, sizeof(aacformat));
7072 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7074 validate_media_type(mediatype, &aacformat.wfInfo.wfx);
7076 value = 0xdeadbeef;
7077 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION, &value);
7078 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
7079 ok(value == aacformat.wfInfo.wAudioProfileLevelIndication, "Unexpected AAC_AUDIO_PROFILE_LEVEL_INDICATION %u.\n", value);
7080 value = 0xdeadbeef;
7081 hr = IMFMediaType_GetUINT32(mediatype, &MF_MT_AAC_PAYLOAD_TYPE, &value);
7082 ok(hr == S_OK, "Failed to get attribute, hr %#lx.\n", hr);
7083 ok(value == aacformat.wfInfo.wPayloadType, "Unexpected AAC_PAYLOAD_TYPE %u.\n", value);
7085 hr = IMFMediaType_GetBlob(mediatype, &MF_MT_USER_DATA, buff, sizeof(buff), &size);
7086 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7087 ok(size == aacformat.wfInfo.wfx.cbSize, "Unexpected size %u.\n", size);
7088 ok(!memcmp(buff, (WAVEFORMATEX *)&aacformat + 1, size), "Unexpected user data.\n");
7090 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, (WAVEFORMATEX **)&format, &size, MFWaveFormatExConvertFlag_ForceExtensible);
7091 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7092 ok(format->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "got wFormatTag %#x\n", format->Format.wFormatTag);
7093 ok(format->Format.cbSize == aacformat.wfInfo.wfx.cbSize + sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX),
7094 "got cbSize %u\n", format->Format.cbSize);
7095 ok(IsEqualGUID(&format->SubFormat, &MFAudioFormat_AAC), "got SubFormat %s\n", debugstr_guid(&format->SubFormat));
7096 ok(format->dwChannelMask == 3, "got dwChannelMask %#lx\n", format->dwChannelMask);
7097 ok(format->Samples.wSamplesPerBlock == 0, "got wSamplesPerBlock %u\n", format->Samples.wSamplesPerBlock);
7098 ok(!memcmp(format + 1, &aacformat.wfInfo.wfx + 1, aacformat.wfInfo.wfx.cbSize), "Unexpected user data.\n");
7099 CoTaskMemFree(format);
7101 /* test with invalid format size */
7102 aacformat.wfInfo.wfx.cbSize = 1;
7103 hr = IMFMediaType_SetBlob(mediatype, &MF_MT_USER_DATA, buff, aacformat.wfInfo.wfx.cbSize);
7104 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7105 hr = MFCreateWaveFormatExFromMFMediaType(mediatype, (WAVEFORMATEX **)&format, &size, MFWaveFormatExConvertFlag_ForceExtensible);
7106 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7107 ok(format->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "got wFormatTag %#x\n", format->Format.wFormatTag);
7108 ok(format->Format.cbSize == aacformat.wfInfo.wfx.cbSize + sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX),
7109 "got cbSize %u\n", format->Format.cbSize);
7110 ok(IsEqualGUID(&format->SubFormat, &MFAudioFormat_AAC), "got SubFormat %s\n", debugstr_guid(&format->SubFormat));
7111 ok(format->dwChannelMask == 3, "got dwChannelMask %#lx\n", format->dwChannelMask);
7112 ok(format->Samples.wSamplesPerBlock == 0, "got wSamplesPerBlock %u\n", format->Samples.wSamplesPerBlock);
7113 ok(!memcmp(format + 1, &aacformat.wfInfo.wfx + 1, aacformat.wfInfo.wfx.cbSize), "Unexpected user data.\n");
7114 CoTaskMemFree(format);
7116 IMFMediaType_Release(mediatype);
7119 static void test_MFCreateMFVideoFormatFromMFMediaType(void)
7121 MFVIDEOFORMAT *video_format;
7122 IMFMediaType *media_type;
7123 UINT32 size, expect_size;
7124 PALETTEENTRY palette[64];
7125 BYTE codec_data[32];
7126 HRESULT hr;
7129 hr = MFCreateMediaType(&media_type);
7130 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
7132 expect_size = sizeof(*video_format);
7133 hr = MFCreateMFVideoFormatFromMFMediaType(media_type, &video_format, &size);
7134 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7135 ok(!!video_format, "Unexpected format.\n");
7136 ok(size == expect_size, "Unexpected size %u.\n", size);
7137 ok(video_format->dwSize == size, "Unexpected size %u.\n", size);
7138 CoTaskMemFree(video_format);
7141 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7142 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7143 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7144 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7145 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7146 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7147 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, 123 * 456 * 4);
7148 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7149 hr = MFCreateMFVideoFormatFromMFMediaType(media_type, &video_format, &size);
7150 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7151 ok(video_format->videoInfo.dwWidth == 123, "got %lu.\n", video_format->videoInfo.dwWidth);
7152 ok(video_format->videoInfo.dwHeight == 456, "got %lu.\n", video_format->videoInfo.dwHeight);
7153 ok(video_format->videoInfo.VideoFlags == 0, "got %#I64x.\n", video_format->videoInfo.VideoFlags);
7154 CoTaskMemFree(video_format);
7156 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, 123 * 4);
7157 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7158 hr = MFCreateMFVideoFormatFromMFMediaType(media_type, &video_format, &size);
7159 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7160 ok(video_format->videoInfo.VideoFlags == 0, "got %#I64x.\n", video_format->videoInfo.VideoFlags);
7161 CoTaskMemFree(video_format);
7163 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, -123 * 4);
7164 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7165 hr = MFCreateMFVideoFormatFromMFMediaType(media_type, &video_format, &size);
7166 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7167 ok(video_format->videoInfo.VideoFlags == MFVideoFlag_BottomUpLinearRep, "got %#I64x.\n", video_format->videoInfo.VideoFlags);
7168 CoTaskMemFree(video_format);
7171 memset(palette, 0xa5, sizeof(palette));
7172 expect_size = offsetof(MFVIDEOFORMAT, surfaceInfo.Palette[ARRAY_SIZE(palette) + 1]);
7173 hr = IMFMediaType_SetBlob(media_type, &MF_MT_PALETTE, (BYTE *)palette, sizeof(palette));
7174 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7175 hr = MFCreateMFVideoFormatFromMFMediaType(media_type, &video_format, &size);
7176 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7177 ok(!!video_format, "Unexpected format.\n");
7178 ok(size == expect_size, "Unexpected size %u.\n", size);
7179 ok(video_format->dwSize == size, "Unexpected size %u.\n", size);
7180 CoTaskMemFree(video_format);
7182 memset(codec_data, 0xcd, sizeof(codec_data));
7183 expect_size += sizeof(codec_data);
7184 hr = IMFMediaType_SetBlob(media_type, &MF_MT_USER_DATA, codec_data, sizeof(codec_data));
7185 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7186 hr = MFCreateMFVideoFormatFromMFMediaType(media_type, &video_format, &size);
7187 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7188 ok(!!video_format, "Unexpected format.\n");
7189 ok(size == expect_size, "Unexpected size %u.\n", size);
7190 ok(video_format->dwSize == size, "Unexpected size %u.\n", size);
7191 CoTaskMemFree(video_format);
7193 IMFMediaType_Release(media_type);
7196 static void test_MFInitAMMediaTypeFromMFMediaType(void)
7198 static const MFVideoArea aperture = {.OffsetX = {.fract = 1, .value = 2}, .OffsetY = {.fract = 3, .value = 4}, .Area={56,78}};
7199 static const BYTE dummy_user_data[] = {0x01,0x02,0x03};
7201 WAVEFORMATEXTENSIBLE *wave_format_ext;
7202 VIDEOINFOHEADER *video_info;
7203 WAVEFORMATEX *wave_format;
7204 IMFMediaType *media_type, *other_type;
7205 AM_MEDIA_TYPE am_type;
7206 MFVideoArea *area;
7207 UINT32 value32;
7208 HRESULT hr;
7210 hr = MFCreateMediaType(&media_type);
7211 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
7213 /* test basic media type attributes mapping and valid formats */
7215 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7216 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7217 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7218 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7219 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7220 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7221 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7222 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7223 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7224 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7226 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7227 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7228 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7229 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7230 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_VideoInfo, &am_type);
7231 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
7232 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7233 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7234 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Audio), "got %s.\n", debugstr_guid(&am_type.majortype));
7235 ok(IsEqualGUID(&am_type.subtype, &MFAudioFormat_PCM), "got %s.\n", debugstr_guid(&am_type.subtype));
7236 ok(IsEqualGUID(&am_type.formattype, &FORMAT_WaveFormatEx), "got %s.\n", debugstr_guid(&am_type.formattype));
7237 ok(am_type.cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type.cbFormat);
7238 CoTaskMemFree(am_type.pbFormat);
7239 hr = MFInitAMMediaTypeFromMFMediaType(media_type, AM_MEDIA_TYPE_REPRESENTATION, &am_type);
7240 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7241 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Audio), "got %s.\n", debugstr_guid(&am_type.majortype));
7242 ok(IsEqualGUID(&am_type.subtype, &MFAudioFormat_PCM), "got %s.\n", debugstr_guid(&am_type.subtype));
7243 ok(IsEqualGUID(&am_type.formattype, &GUID_NULL), "got %s.\n", debugstr_guid(&am_type.formattype));
7244 ok(am_type.cbFormat == 0, "got %lu\n", am_type.cbFormat);
7245 CoTaskMemFree(am_type.pbFormat);
7246 IMFMediaType_DeleteAllItems(media_type);
7248 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7249 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7250 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7251 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7252 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_WaveFormatEx, &am_type);
7253 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
7254 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7255 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7256 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Video), "got %s.\n", debugstr_guid(&am_type.majortype));
7257 ok(IsEqualGUID(&am_type.subtype, &MEDIASUBTYPE_RGB32), "got %s.\n", debugstr_guid(&am_type.subtype));
7258 ok(IsEqualGUID(&am_type.formattype, &FORMAT_VideoInfo), "got %s.\n", debugstr_guid(&am_type.formattype));
7259 ok(am_type.cbFormat == sizeof(VIDEOINFOHEADER), "got %lu\n", am_type.cbFormat);
7260 CoTaskMemFree(am_type.pbFormat);
7261 hr = MFInitAMMediaTypeFromMFMediaType(media_type, AM_MEDIA_TYPE_REPRESENTATION, &am_type);
7262 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7263 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Video), "got %s.\n", debugstr_guid(&am_type.majortype));
7264 ok(IsEqualGUID(&am_type.subtype, &MFVideoFormat_RGB32), "got %s.\n", debugstr_guid(&am_type.subtype));
7265 ok(IsEqualGUID(&am_type.formattype, &GUID_NULL), "got %s.\n", debugstr_guid(&am_type.formattype));
7266 ok(am_type.cbFormat == 0, "got %lu\n", am_type.cbFormat);
7267 CoTaskMemFree(am_type.pbFormat);
7268 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_VideoInfo, &am_type);
7269 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7270 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Video), "got %s.\n", debugstr_guid(&am_type.majortype));
7271 ok(IsEqualGUID(&am_type.subtype, &MEDIASUBTYPE_RGB32), "got %s.\n", debugstr_guid(&am_type.subtype));
7272 ok(IsEqualGUID(&am_type.formattype, &FORMAT_VideoInfo), "got %s.\n", debugstr_guid(&am_type.formattype));
7273 ok(am_type.cbFormat == sizeof(VIDEOINFOHEADER), "got %lu\n", am_type.cbFormat);
7274 CoTaskMemFree(am_type.pbFormat);
7275 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_VideoInfo2, &am_type);
7276 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7277 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Video), "got %s.\n", debugstr_guid(&am_type.majortype));
7278 ok(IsEqualGUID(&am_type.subtype, &MEDIASUBTYPE_RGB32), "got %s.\n", debugstr_guid(&am_type.subtype));
7279 ok(IsEqualGUID(&am_type.formattype, &FORMAT_VideoInfo2), "got %s.\n", debugstr_guid(&am_type.formattype));
7280 ok(am_type.cbFormat == sizeof(VIDEOINFOHEADER2), "got %lu\n", am_type.cbFormat);
7281 CoTaskMemFree(am_type.pbFormat);
7282 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_MFVideoFormat, &am_type);
7283 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7284 ok(IsEqualGUID(&am_type.majortype, &MFMediaType_Video), "got %s.\n", debugstr_guid(&am_type.majortype));
7285 ok(IsEqualGUID(&am_type.subtype, &MFVideoFormat_RGB32), "got %s.\n", debugstr_guid(&am_type.subtype));
7286 ok(IsEqualGUID(&am_type.formattype, &FORMAT_MFVideoFormat), "got %s.\n", debugstr_guid(&am_type.formattype));
7287 ok(am_type.cbFormat == sizeof(MFVIDEOFORMAT), "got %lu\n", am_type.cbFormat);
7288 CoTaskMemFree(am_type.pbFormat);
7291 /* test WAVEFORMATEX mapping */
7293 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7294 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7295 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7296 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7297 hr = IMFMediaType_SetBlob(media_type, &MF_MT_USER_DATA, dummy_user_data, sizeof(dummy_user_data));
7298 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7299 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7300 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7301 ok(am_type.cbFormat == sizeof(WAVEFORMATEX) + sizeof(dummy_user_data), "got %lu\n", am_type.cbFormat);
7302 wave_format = (WAVEFORMATEX *)am_type.pbFormat;
7303 ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "got %u\n", wave_format->wFormatTag);
7304 ok(wave_format->nChannels == 0, "got %u\n", wave_format->nChannels);
7305 ok(wave_format->nSamplesPerSec == 0, "got %lu\n", wave_format->nSamplesPerSec);
7306 ok(wave_format->nAvgBytesPerSec == 0, "got %lu\n", wave_format->nAvgBytesPerSec);
7307 ok(wave_format->nBlockAlign == 0, "got %u\n", wave_format->nBlockAlign);
7308 ok(wave_format->wBitsPerSample == 0, "got %u\n", wave_format->wBitsPerSample);
7309 ok(wave_format->cbSize == sizeof(dummy_user_data), "got %u\n", wave_format->cbSize);
7310 ok(!memcmp(wave_format + 1, dummy_user_data, sizeof(dummy_user_data)), "got unexpected data\n");
7311 CoTaskMemFree(am_type.pbFormat);
7312 IMFMediaType_DeleteAllItems(media_type);
7314 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7315 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7316 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7317 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7318 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_NUM_CHANNELS, 2);
7319 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7320 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7321 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7322 ok(am_type.cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type.cbFormat);
7323 wave_format = (WAVEFORMATEX *)am_type.pbFormat;
7324 ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "got %u\n", wave_format->wFormatTag);
7325 ok(wave_format->nChannels == 2, "got %u\n", wave_format->nChannels);
7326 ok(wave_format->cbSize == 0, "got %u\n", wave_format->cbSize);
7327 CoTaskMemFree(am_type.pbFormat);
7328 IMFMediaType_DeleteAllItems(media_type);
7330 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7331 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7332 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7333 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7334 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_NUM_CHANNELS, 2);
7335 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7336 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_BITS_PER_SAMPLE, 16);
7337 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7338 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7339 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7340 ok(am_type.cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type.cbFormat);
7341 wave_format = (WAVEFORMATEX *)am_type.pbFormat;
7342 ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "got %u\n", wave_format->wFormatTag);
7343 ok(wave_format->wBitsPerSample == 16, "got %u\n", wave_format->wBitsPerSample);
7344 ok(wave_format->nBlockAlign == 0, "got %u\n", wave_format->nBlockAlign);
7345 ok(wave_format->cbSize == 0, "got %u\n", wave_format->cbSize);
7346 CoTaskMemFree(am_type.pbFormat);
7347 IMFMediaType_DeleteAllItems(media_type);
7349 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7350 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7351 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7352 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7353 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_BLOCK_ALIGNMENT, 16);
7354 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7355 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7356 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7357 ok(am_type.cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type.cbFormat);
7358 wave_format = (WAVEFORMATEX *)am_type.pbFormat;
7359 ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "got %u\n", wave_format->wFormatTag);
7360 ok(wave_format->nBlockAlign == 16, "got %u\n", wave_format->nBlockAlign);
7361 ok(wave_format->cbSize == 0, "got %u\n", wave_format->cbSize);
7362 CoTaskMemFree(am_type.pbFormat);
7363 IMFMediaType_DeleteAllItems(media_type);
7365 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7366 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7367 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7368 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7369 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_SAMPLES_PER_SECOND, 44100);
7370 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7371 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7372 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7373 ok(am_type.cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type.cbFormat);
7374 wave_format = (WAVEFORMATEX *)am_type.pbFormat;
7375 ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "got %u\n", wave_format->wFormatTag);
7376 ok(wave_format->nSamplesPerSec == 44100, "got %lu\n", wave_format->nSamplesPerSec);
7377 ok(wave_format->cbSize == 0, "got %u\n", wave_format->cbSize);
7378 CoTaskMemFree(am_type.pbFormat);
7379 IMFMediaType_DeleteAllItems(media_type);
7381 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7382 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7383 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7384 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7385 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND, 176400);
7386 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7387 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7388 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7389 ok(am_type.cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type.cbFormat);
7390 wave_format = (WAVEFORMATEX *)am_type.pbFormat;
7391 ok(wave_format->wFormatTag == WAVE_FORMAT_PCM, "got %u\n", wave_format->wFormatTag);
7392 ok(wave_format->nAvgBytesPerSec == 176400, "got %lu\n", wave_format->nAvgBytesPerSec);
7393 ok(wave_format->cbSize == 0, "got %u\n", wave_format->cbSize);
7394 CoTaskMemFree(am_type.pbFormat);
7395 IMFMediaType_DeleteAllItems(media_type);
7397 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7398 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7399 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7400 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7401 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_NUM_CHANNELS, 3);
7402 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7403 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7404 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7405 ok(am_type.cbFormat == sizeof(WAVEFORMATEXTENSIBLE), "got %lu\n", am_type.cbFormat);
7406 wave_format_ext = (WAVEFORMATEXTENSIBLE *)am_type.pbFormat;
7407 ok(wave_format_ext->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE, "got %u\n", wave_format_ext->Format.wFormatTag);
7408 ok(wave_format_ext->Format.nChannels == 3, "got %u\n", wave_format_ext->Format.nChannels);
7409 ok(IsEqualGUID(&wave_format_ext->SubFormat, &MFAudioFormat_PCM),
7410 "got %s\n", debugstr_guid(&wave_format_ext->SubFormat));
7411 ok(wave_format_ext->dwChannelMask == 7, "got %#lx\n", wave_format_ext->dwChannelMask);
7412 ok(wave_format_ext->Samples.wSamplesPerBlock == 0, "got %u\n",
7413 wave_format_ext->Samples.wSamplesPerBlock);
7414 ok(wave_format_ext->Format.cbSize == sizeof(*wave_format_ext) - sizeof(*wave_format),
7415 "got %u\n", wave_format_ext->Format.cbSize);
7416 CoTaskMemFree(am_type.pbFormat);
7417 IMFMediaType_DeleteAllItems(media_type);
7419 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7420 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7421 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7422 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7423 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_CHANNEL_MASK, 3);
7424 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7425 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7426 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7427 ok(am_type.cbFormat == sizeof(WAVEFORMATEXTENSIBLE), "got %lu\n", am_type.cbFormat);
7428 wave_format_ext = (WAVEFORMATEXTENSIBLE *)am_type.pbFormat;
7429 ok(wave_format_ext->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE,
7430 "got %u\n", wave_format_ext->Format.wFormatTag);
7431 ok(IsEqualGUID(&wave_format_ext->SubFormat, &MFAudioFormat_PCM),
7432 "got %s\n", debugstr_guid(&wave_format_ext->SubFormat));
7433 ok(wave_format_ext->dwChannelMask == 3, "got %#lx\n", wave_format_ext->dwChannelMask);
7434 ok(wave_format_ext->Samples.wSamplesPerBlock == 0, "got %u\n",
7435 wave_format_ext->Samples.wSamplesPerBlock);
7436 ok(wave_format_ext->Format.cbSize == sizeof(*wave_format_ext) - sizeof(*wave_format),
7437 "got %u\n", wave_format_ext->Format.cbSize);
7438 CoTaskMemFree(am_type.pbFormat);
7439 IMFMediaType_DeleteAllItems(media_type);
7441 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7442 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7443 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7444 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7445 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_VALID_BITS_PER_SAMPLE, 3);
7446 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7447 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AUDIO_SAMPLES_PER_BLOCK, 4);
7448 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7449 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7450 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7451 ok(am_type.cbFormat == sizeof(WAVEFORMATEXTENSIBLE), "got %lu\n", am_type.cbFormat);
7452 wave_format_ext = (WAVEFORMATEXTENSIBLE *)am_type.pbFormat;
7453 ok(wave_format_ext->Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE,
7454 "got %u\n", wave_format_ext->Format.wFormatTag);
7455 ok(IsEqualGUID(&wave_format_ext->SubFormat, &MFAudioFormat_PCM),
7456 "got %s\n", debugstr_guid(&wave_format_ext->SubFormat));
7457 ok(wave_format_ext->dwChannelMask == 0, "got %#lx\n", wave_format_ext->dwChannelMask);
7458 ok(wave_format_ext->Samples.wSamplesPerBlock == 4, "got %u\n",
7459 wave_format_ext->Samples.wSamplesPerBlock);
7460 ok(wave_format_ext->Format.cbSize == sizeof(*wave_format_ext) - sizeof(*wave_format),
7461 "got %u\n", wave_format_ext->Format.cbSize);
7462 CoTaskMemFree(am_type.pbFormat);
7463 IMFMediaType_DeleteAllItems(media_type);
7466 /* test VIDEOINFOHEADER mapping */
7468 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7469 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7470 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7471 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7472 hr = IMFMediaType_SetBlob(media_type, &MF_MT_USER_DATA, dummy_user_data, sizeof(dummy_user_data));
7473 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7474 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7475 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7476 ok(am_type.cbFormat == sizeof(VIDEOINFOHEADER) + sizeof(dummy_user_data), "got %lu\n", am_type.cbFormat);
7477 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7478 ok(video_info->rcSource.right == 0, "got %lu\n", video_info->rcSource.right);
7479 ok(video_info->rcSource.bottom == 0, "got %lu\n", video_info->rcSource.bottom);
7480 ok(video_info->rcTarget.right == 0, "got %lu\n", video_info->rcTarget.right);
7481 ok(video_info->rcTarget.bottom == 0, "got %lu\n", video_info->rcTarget.bottom);
7482 ok(video_info->dwBitRate == 0, "got %lu\n", video_info->dwBitRate);
7483 ok(video_info->dwBitErrorRate == 0, "got %lu\n", video_info->dwBitErrorRate);
7484 ok(video_info->AvgTimePerFrame == 0, "got %I64d\n", video_info->AvgTimePerFrame);
7485 ok(video_info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER) + sizeof(dummy_user_data),
7486 "got %lu\n", video_info->bmiHeader.biSize);
7487 ok(video_info->bmiHeader.biWidth == 0, "got %lu\n", video_info->bmiHeader.biWidth);
7488 ok(video_info->bmiHeader.biHeight == 0, "got %lu\n", video_info->bmiHeader.biHeight);
7489 ok(video_info->bmiHeader.biPlanes == 1, "got %u\n", video_info->bmiHeader.biPlanes);
7490 ok(video_info->bmiHeader.biBitCount == 32, "got %u\n", video_info->bmiHeader.biBitCount);
7491 ok(video_info->bmiHeader.biCompression == BI_RGB, "got %lu\n", video_info->bmiHeader.biCompression);
7492 ok(video_info->bmiHeader.biSizeImage == 0, "got %lu\n", video_info->bmiHeader.biSizeImage);
7493 ok(!memcmp(video_info + 1, dummy_user_data, sizeof(dummy_user_data)),
7494 "got unexpected data\n");
7495 CoTaskMemFree(am_type.pbFormat);
7496 IMFMediaType_DeleteAllItems(media_type);
7498 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7499 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7500 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7501 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7502 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, 1);
7503 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7504 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7505 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7506 ok(am_type.bFixedSizeSamples == 1, "got %u.\n", am_type.bFixedSizeSamples);
7507 CoTaskMemFree(am_type.pbFormat);
7508 IMFMediaType_DeleteAllItems(media_type);
7510 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7511 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7512 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7513 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7514 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, 123456);
7515 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7516 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7517 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7518 ok(am_type.lSampleSize == 123456, "got %lu.\n", am_type.lSampleSize);
7519 CoTaskMemFree(am_type.pbFormat);
7520 IMFMediaType_DeleteAllItems(media_type);
7522 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7523 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7524 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7525 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7526 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7527 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7528 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7529 ok(video_info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER), "got %lu\n", video_info->bmiHeader.biSize);
7530 ok(video_info->bmiHeader.biBitCount == 32, "got %u\n", video_info->bmiHeader.biBitCount);
7531 ok(video_info->bmiHeader.biCompression == BI_RGB, "got %lu\n", video_info->bmiHeader.biCompression);
7532 CoTaskMemFree(am_type.pbFormat);
7533 IMFMediaType_DeleteAllItems(media_type);
7535 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7536 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7537 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB565);
7538 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7539 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7540 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7541 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7542 ok(video_info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER), "got %lu\n", video_info->bmiHeader.biSize);
7543 ok(video_info->bmiHeader.biBitCount == 16, "got %u\n", video_info->bmiHeader.biBitCount);
7544 ok(video_info->bmiHeader.biCompression == BI_BITFIELDS, "got %lu\n", video_info->bmiHeader.biCompression);
7545 CoTaskMemFree(am_type.pbFormat);
7546 IMFMediaType_DeleteAllItems(media_type);
7548 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7549 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7550 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_NV12);
7551 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7552 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7553 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7554 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7555 ok(video_info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER), "got %lu\n", video_info->bmiHeader.biSize);
7556 ok(video_info->bmiHeader.biBitCount == 12, "got %u\n", video_info->bmiHeader.biBitCount);
7557 ok(video_info->bmiHeader.biCompression == MFVideoFormat_NV12.Data1, "got %lu\n", video_info->bmiHeader.biCompression);
7558 CoTaskMemFree(am_type.pbFormat);
7559 IMFMediaType_DeleteAllItems(media_type);
7561 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7562 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7563 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_WMV2);
7564 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7565 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7566 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7567 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7568 ok(video_info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER), "got %lu\n", video_info->bmiHeader.biSize);
7569 ok(video_info->bmiHeader.biBitCount == 0, "got %u\n", video_info->bmiHeader.biBitCount);
7570 ok(video_info->bmiHeader.biCompression == MFVideoFormat_WMV2.Data1, "got %lu\n", video_info->bmiHeader.biCompression);
7571 CoTaskMemFree(am_type.pbFormat);
7572 IMFMediaType_DeleteAllItems(media_type);
7574 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7575 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7576 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_NV12);
7577 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7578 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_RATE, (UINT64)123 << 32 | 456);
7579 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7580 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7581 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7582 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7583 ok(video_info->AvgTimePerFrame == 37073171, "got %I64d\n", video_info->AvgTimePerFrame);
7584 CoTaskMemFree(am_type.pbFormat);
7585 IMFMediaType_DeleteAllItems(media_type);
7587 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7588 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7589 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_NV12);
7590 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7591 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AVG_BITRATE, 123456);
7592 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7593 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, 654321);
7594 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7595 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7596 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7597 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7598 ok(video_info->dwBitRate == 123456, "got %lu\n", video_info->dwBitRate);
7599 ok(video_info->dwBitErrorRate == 654321, "got %lu\n", video_info->dwBitErrorRate);
7600 CoTaskMemFree(am_type.pbFormat);
7601 IMFMediaType_DeleteAllItems(media_type);
7603 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7604 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7605 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_NV12);
7606 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7607 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, 123456);
7608 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7609 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7610 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7611 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7612 ok(video_info->bmiHeader.biSizeImage == 123456, "got %lu\n", video_info->bmiHeader.biSizeImage);
7613 CoTaskMemFree(am_type.pbFormat);
7614 IMFMediaType_DeleteAllItems(media_type);
7616 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7617 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7618 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7619 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7620 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7621 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7622 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7623 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7624 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7625 ok(video_info->bmiHeader.biWidth == 123, "got %lu\n", video_info->bmiHeader.biWidth);
7626 ok(video_info->bmiHeader.biHeight == 456, "got %lu\n", video_info->bmiHeader.biHeight);
7627 ok(video_info->bmiHeader.biSizeImage == 123 * 456 * 4, "got %lu\n", video_info->bmiHeader.biSizeImage);
7628 CoTaskMemFree(am_type.pbFormat);
7629 IMFMediaType_DeleteAllItems(media_type);
7631 /* MF_MT_MINIMUM_DISPLAY_APERTURE has no effect */
7632 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7633 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7634 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7635 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7636 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7637 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7638 hr = IMFMediaType_SetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture));
7639 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7640 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, 12345678);
7641 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7642 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7643 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7644 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7645 ok(video_info->rcSource.left == 0, "got %lu\n", video_info->rcSource.left);
7646 ok(video_info->rcSource.right == 0, "got %lu\n", video_info->rcSource.right);
7647 ok(video_info->rcSource.top == 0, "got %lu\n", video_info->rcSource.top);
7648 ok(video_info->rcSource.bottom == 0, "got %lu\n", video_info->rcSource.bottom);
7649 ok(video_info->rcTarget.left == 0, "got %lu\n", video_info->rcTarget.left);
7650 ok(video_info->rcTarget.right == 0, "got %lu\n", video_info->rcTarget.right);
7651 ok(video_info->rcTarget.top == 0, "got %lu\n", video_info->rcTarget.top);
7652 ok(video_info->rcTarget.bottom == 0, "got %lu\n", video_info->rcTarget.bottom);
7653 ok(video_info->bmiHeader.biWidth == 123, "got %lu\n", video_info->bmiHeader.biWidth);
7654 ok(video_info->bmiHeader.biHeight == 456, "got %lu\n", video_info->bmiHeader.biHeight);
7655 ok(video_info->bmiHeader.biSizeImage == 123 * 456 * 4, "got %lu\n", video_info->bmiHeader.biSizeImage);
7656 CoTaskMemFree(am_type.pbFormat);
7657 IMFMediaType_DeleteAllItems(media_type);
7659 /* MF_MT_DEFAULT_STRIDE / MF_MT_FRAME_SIZE mismatch is translated into rcSource / rcTarget */
7660 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7661 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7662 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7663 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7664 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7665 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7666 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, -246 * 4);
7667 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7668 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, 12345678);
7669 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7670 hr = IMFMediaType_SetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture));
7671 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7672 hr = IMFMediaType_SetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (BYTE *)&aperture, sizeof(aperture));
7673 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7674 hr = IMFMediaType_SetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture));
7675 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7676 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, 1);
7677 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7678 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7679 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7680 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7681 ok(video_info->rcSource.left == 0, "got %lu\n", video_info->rcSource.left);
7682 ok(video_info->rcSource.right == 123, "got %lu\n", video_info->rcSource.right);
7683 ok(video_info->rcSource.top == 0, "got %lu\n", video_info->rcSource.top);
7684 ok(video_info->rcSource.bottom == 456, "got %lu\n", video_info->rcSource.bottom);
7685 ok(video_info->rcTarget.left == 0, "got %lu\n", video_info->rcTarget.left);
7686 ok(video_info->rcTarget.right == 123, "got %lu\n", video_info->rcTarget.right);
7687 ok(video_info->rcTarget.top == 0, "got %lu\n", video_info->rcTarget.top);
7688 ok(video_info->rcTarget.bottom == 456, "got %lu\n", video_info->rcTarget.bottom);
7689 ok(video_info->bmiHeader.biWidth == 246, "got %lu\n", video_info->bmiHeader.biWidth);
7690 ok(video_info->bmiHeader.biHeight == 456, "got %ld\n", video_info->bmiHeader.biHeight);
7691 ok(video_info->bmiHeader.biSizeImage == 246 * 456 * 4, "got %lu\n", video_info->bmiHeader.biSizeImage);
7692 CoTaskMemFree(am_type.pbFormat);
7694 /* positive stride only changes biHeight */
7695 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, 246 * 4);
7696 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7697 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7698 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7699 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7700 ok(video_info->rcSource.left == 0, "got %lu\n", video_info->rcSource.left);
7701 ok(video_info->rcSource.right == 123, "got %lu\n", video_info->rcSource.right);
7702 ok(video_info->rcSource.top == 0, "got %lu\n", video_info->rcSource.top);
7703 ok(video_info->rcSource.bottom == 456, "got %lu\n", video_info->rcSource.bottom);
7704 ok(video_info->rcTarget.left == 0, "got %lu\n", video_info->rcTarget.left);
7705 ok(video_info->rcTarget.right == 123, "got %lu\n", video_info->rcTarget.right);
7706 ok(video_info->rcTarget.top == 0, "got %lu\n", video_info->rcTarget.top);
7707 ok(video_info->rcTarget.bottom == 456, "got %lu\n", video_info->rcTarget.bottom);
7708 ok(video_info->bmiHeader.biWidth == 246, "got %lu\n", video_info->bmiHeader.biWidth);
7709 ok(video_info->bmiHeader.biHeight == -456, "got %ld\n", video_info->bmiHeader.biHeight);
7710 ok(video_info->bmiHeader.biSizeImage == 246 * 456 * 4, "got %lu\n", video_info->bmiHeader.biSizeImage);
7711 CoTaskMemFree(am_type.pbFormat);
7712 IMFMediaType_DeleteAllItems(media_type);
7714 /* same thing happens with other formats */
7715 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7716 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7717 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_NV12);
7718 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7719 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7720 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7721 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, 246);
7722 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7723 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_SAMPLE_SIZE, 12345678);
7724 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7725 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7726 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7727 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7728 ok(video_info->rcSource.left == 0, "got %lu\n", video_info->rcSource.left);
7729 ok(video_info->rcSource.right == 123, "got %lu\n", video_info->rcSource.right);
7730 ok(video_info->rcSource.top == 0, "got %lu\n", video_info->rcSource.top);
7731 ok(video_info->rcSource.bottom == 456, "got %lu\n", video_info->rcSource.bottom);
7732 ok(video_info->rcTarget.left == 0, "got %lu\n", video_info->rcTarget.left);
7733 ok(video_info->rcTarget.right == 123, "got %lu\n", video_info->rcTarget.right);
7734 ok(video_info->rcTarget.top == 0, "got %lu\n", video_info->rcTarget.top);
7735 ok(video_info->rcTarget.bottom == 456, "got %lu\n", video_info->rcTarget.bottom);
7736 ok(video_info->bmiHeader.biWidth == 246, "got %lu\n", video_info->bmiHeader.biWidth);
7737 ok(video_info->bmiHeader.biHeight == 456, "got %ld\n", video_info->bmiHeader.biHeight);
7738 ok(video_info->bmiHeader.biSizeImage == 246 * 456 * 3 / 2, "got %lu\n", video_info->bmiHeader.biSizeImage);
7739 CoTaskMemFree(am_type.pbFormat);
7740 IMFMediaType_DeleteAllItems(media_type);
7742 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7743 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7744 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7745 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7746 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7747 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7748 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, -246 * 4);
7749 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7750 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7751 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7752 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7753 ok(video_info->bmiHeader.biWidth == 246, "got %lu\n", video_info->bmiHeader.biWidth);
7754 ok(video_info->bmiHeader.biHeight == 456, "got %ld\n", video_info->bmiHeader.biHeight);
7755 ok(video_info->bmiHeader.biSizeImage == 246 * 456 * 4, "got %lu\n", video_info->bmiHeader.biSizeImage);
7756 CoTaskMemFree(am_type.pbFormat);
7757 IMFMediaType_DeleteAllItems(media_type);
7759 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7760 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7761 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_RGB32);
7762 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7763 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)123 << 32 | 456);
7764 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7765 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, 246 * 4);
7766 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7767 hr = MFInitAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7768 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7769 video_info = (VIDEOINFOHEADER *)am_type.pbFormat;
7770 ok(video_info->bmiHeader.biWidth == 246, "got %lu\n", video_info->bmiHeader.biWidth);
7771 ok(video_info->bmiHeader.biHeight == -456, "got %ld\n", video_info->bmiHeader.biHeight);
7772 ok(video_info->bmiHeader.biSizeImage == 246 * 456 * 4, "got %lu\n", video_info->bmiHeader.biSizeImage);
7773 CoTaskMemFree(am_type.pbFormat);
7774 IMFMediaType_DeleteAllItems(media_type);
7776 /* aperture is lost with VIDEOINFOHEADER(2), preserved with MFVIDEOFORMAT */
7777 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7778 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7779 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_NV12);
7780 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7781 hr = IMFMediaType_SetUINT64(media_type, &MF_MT_FRAME_SIZE, (UINT64)1920 << 32 | 1088);
7782 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7783 hr = IMFMediaType_SetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture));
7784 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7786 hr = MFCreateMediaType(&other_type);
7787 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7789 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_VideoInfo, &am_type);
7790 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7791 hr = MFInitMediaTypeFromAMMediaType(other_type, &am_type);
7792 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7793 hr = IMFMediaType_GetAllocatedBlob(other_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE **)&area, &value32);
7794 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7795 IMFMediaType_DeleteAllItems(other_type);
7796 CoTaskMemFree(am_type.pbFormat);
7798 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_VideoInfo2, &am_type);
7799 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7800 hr = MFInitMediaTypeFromAMMediaType(other_type, &am_type);
7801 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7802 hr = IMFMediaType_GetAllocatedBlob(other_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE **)&area, &value32);
7803 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7804 IMFMediaType_DeleteAllItems(other_type);
7805 CoTaskMemFree(am_type.pbFormat);
7807 hr = MFInitAMMediaTypeFromMFMediaType(media_type, FORMAT_MFVideoFormat, &am_type);
7808 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7809 hr = MFInitMediaTypeFromAMMediaType(other_type, &am_type);
7810 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7811 hr = IMFMediaType_GetAllocatedBlob(other_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE **)&area, &value32);
7812 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7813 if (hr == S_OK) CoTaskMemFree(area);
7814 IMFMediaType_DeleteAllItems(other_type);
7815 CoTaskMemFree(am_type.pbFormat);
7817 IMFMediaType_Release(other_type);
7819 IMFMediaType_Release(media_type);
7822 static void test_MFCreateAMMediaTypeFromMFMediaType(void)
7824 IMFMediaType *media_type;
7825 AM_MEDIA_TYPE *am_type;
7826 HRESULT hr;
7828 hr = MFCreateMediaType(&media_type);
7829 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
7831 hr = MFCreateAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7832 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7833 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7834 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7835 hr = MFCreateAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7836 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7837 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
7838 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7839 hr = MFCreateAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7840 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7842 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
7843 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7844 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
7845 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7846 hr = MFCreateAMMediaTypeFromMFMediaType(media_type, GUID_NULL, &am_type);
7847 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7848 ok(IsEqualGUID(&am_type->majortype, &MFMediaType_Audio), "got %s.\n", debugstr_guid(&am_type->majortype));
7849 ok(IsEqualGUID(&am_type->subtype, &MFAudioFormat_PCM), "got %s.\n", debugstr_guid(&am_type->subtype));
7850 ok(IsEqualGUID(&am_type->formattype, &FORMAT_WaveFormatEx), "got %s.\n", debugstr_guid(&am_type->formattype));
7851 ok(am_type->cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type->cbFormat);
7852 CoTaskMemFree(am_type->pbFormat);
7853 CoTaskMemFree(am_type);
7855 IMFMediaType_Release(media_type);
7858 static void test_MFInitMediaTypeFromMFVideoFormat(void)
7860 static const MFPaletteEntry expect_palette[] = {{{1}},{{2}},{{3}},{{4}},{{5}},{{6}},{{7}},{{8}}};
7861 static const BYTE expect_user_data[] = {6,5,4,3,2,1};
7862 MFPaletteEntry palette[ARRAY_SIZE(expect_palette)];
7863 BYTE user_data[sizeof(expect_user_data)];
7864 char buffer[sizeof(MFVIDEOFORMAT) + sizeof(palette) + sizeof(user_data)];
7865 MFVIDEOFORMAT format, *format_buf = (MFVIDEOFORMAT *)buffer;
7866 IMFMediaType *media_type;
7867 MFVideoArea aperture;
7868 UINT32 i, value32;
7869 UINT64 value64;
7870 HRESULT hr;
7871 GUID guid;
7873 hr = MFCreateMediaType(&media_type);
7874 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7876 hr = MFInitMediaTypeFromMFVideoFormat(media_type, NULL, 0);
7877 todo_wine
7878 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
7880 memset(&format, 0, sizeof(format));
7881 format.dwSize = sizeof(format) - 1;
7882 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format) - 1);
7883 todo_wine
7884 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
7885 format.dwSize = sizeof(format);
7886 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format) - 1);
7887 todo_wine
7888 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
7890 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7891 todo_wine
7892 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7893 memset(&guid, 0xcd, sizeof(guid));
7894 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
7895 todo_wine
7896 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7897 todo_wine
7898 ok(IsEqualGUID(&guid, &MFMediaType_Video), "got %s.\n", debugstr_guid(&guid));
7899 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
7900 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7901 IMFMediaType_DeleteAllItems(media_type);
7903 format.guidFormat = MFVideoFormat_H264;
7904 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7905 todo_wine
7906 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7907 memset(&guid, 0xcd, sizeof(guid));
7908 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
7909 todo_wine
7910 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7911 todo_wine
7912 ok(IsEqualGUID(&guid, &MFVideoFormat_H264), "got %s.\n", debugstr_guid(&guid));
7913 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
7914 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7915 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
7916 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7917 IMFMediaType_DeleteAllItems(media_type);
7919 format.guidFormat = MFVideoFormat_RGB32;
7920 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7921 todo_wine
7922 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7923 memset(&guid, 0xcd, sizeof(guid));
7924 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
7925 todo_wine
7926 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7927 todo_wine
7928 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "got %s.\n", debugstr_guid(&guid));
7929 value32 = 0xdeadbeef;
7930 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
7931 todo_wine
7932 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7933 todo_wine
7934 ok(value32 == 1, "got %u.\n", value32);
7935 value32 = 0xdeadbeef;
7936 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
7937 todo_wine
7938 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7939 todo_wine
7940 ok(value32 == 1, "got %u.\n", value32);
7941 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
7942 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7943 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
7944 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7945 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
7946 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7947 IMFMediaType_DeleteAllItems(media_type);
7949 format.videoInfo.dwWidth = -123;
7950 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7951 todo_wine
7952 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "Unexpected hr %#lx.\n", hr);
7953 format.videoInfo.dwWidth = 123;
7954 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7955 todo_wine
7956 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7957 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
7958 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7959 IMFMediaType_DeleteAllItems(media_type);
7960 format.videoInfo.dwHeight = -456;
7961 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7962 todo_wine
7963 ok(hr == HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW), "Unexpected hr %#lx.\n", hr);
7964 format.videoInfo.dwHeight = 456;
7965 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7966 todo_wine
7967 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7968 value64 = 0xdeadbeef;
7969 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
7970 todo_wine
7971 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7972 todo_wine
7973 ok(value64 == (((UINT64)123 << 32) | 456), "got %#I64x.\n", value64);
7974 value32 = 0xdeadbeef;
7975 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
7976 todo_wine
7977 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7978 todo_wine
7979 ok(value32 == 123 * 4, "got %u.\n", value32);
7980 value32 = 0xdeadbeef;
7981 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
7982 todo_wine
7983 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7984 todo_wine
7985 ok(value32 == 123 * 4 * 456, "got %u.\n", value32);
7986 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
7987 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
7988 IMFMediaType_DeleteAllItems(media_type);
7990 /* MFVideoFlag_BottomUpLinearRep flag inverts the stride */
7991 format.videoInfo.VideoFlags = MFVideoFlag_BottomUpLinearRep;
7992 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
7993 todo_wine
7994 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7995 value32 = 0xdeadbeef;
7996 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
7997 todo_wine
7998 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
7999 todo_wine
8000 ok(value32 == -123 * 4, "got %u.\n", value32);
8001 value32 = 0xdeadbeef;
8002 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
8003 todo_wine
8004 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8005 todo_wine
8006 ok(value32 == 123 * 4 * 456, "got %u.\n", value32);
8007 IMFMediaType_DeleteAllItems(media_type);
8009 /* MFVideoFlag_BottomUpLinearRep flag only works with RGB formats */
8010 format.guidFormat = MFVideoFormat_H264;
8011 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8012 todo_wine
8013 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8014 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
8015 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8016 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
8017 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8018 IMFMediaType_DeleteAllItems(media_type);
8020 format.guidFormat = MFVideoFormat_NV12;
8021 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8022 todo_wine
8023 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8024 value32 = 0xdeadbeef;
8025 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
8026 todo_wine
8027 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8028 todo_wine
8029 ok(value32 == 124, "got %u.\n", value32);
8030 value32 = 0xdeadbeef;
8031 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
8032 todo_wine
8033 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8034 todo_wine
8035 ok(value32 == 124 * 456 * 3 / 2, "got %u.\n", value32);
8036 IMFMediaType_DeleteAllItems(media_type);
8038 format.videoInfo.PixelAspectRatio.Numerator = 7;
8039 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8040 todo_wine
8041 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8042 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
8043 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8044 IMFMediaType_DeleteAllItems(media_type);
8045 format.videoInfo.PixelAspectRatio.Denominator = 8;
8046 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8047 todo_wine
8048 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8049 value64 = 0xdeadbeef;
8050 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
8051 todo_wine
8052 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8053 todo_wine
8054 ok(value64 == (((UINT64)7 << 32) | 8), "got %#I64x.\n", value64);
8055 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_CHROMA_SITING, &value32);
8056 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8057 IMFMediaType_DeleteAllItems(media_type);
8059 format.videoInfo.SourceChromaSubsampling = MFVideoChromaSubsampling_MPEG2;
8060 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8061 todo_wine
8062 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8063 value32 = 0xdeadbeef;
8064 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_CHROMA_SITING, &value32);
8065 todo_wine
8066 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8067 todo_wine
8068 ok(value32 == MFVideoChromaSubsampling_MPEG2, "got %u.\n", value32);
8069 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
8070 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8071 IMFMediaType_DeleteAllItems(media_type);
8073 format.videoInfo.InterlaceMode = MFVideoInterlace_MixedInterlaceOrProgressive;
8074 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8075 todo_wine
8076 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8077 value32 = 0xdeadbeef;
8078 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
8079 todo_wine
8080 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8081 todo_wine
8082 ok(value32 == MFVideoInterlace_MixedInterlaceOrProgressive, "got %u.\n", value32);
8083 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_TRANSFER_FUNCTION, &value32);
8084 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8085 IMFMediaType_DeleteAllItems(media_type);
8087 format.videoInfo.TransferFunction = MFVideoTransFunc_709;
8088 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8089 todo_wine
8090 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8091 value32 = 0xdeadbeef;
8092 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_TRANSFER_FUNCTION, &value32);
8093 todo_wine
8094 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8095 todo_wine
8096 ok(value32 == MFVideoTransFunc_709, "got %u.\n", value32);
8097 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_PRIMARIES, &value32);
8098 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8099 IMFMediaType_DeleteAllItems(media_type);
8101 format.videoInfo.ColorPrimaries = MFVideoPrimaries_BT709;
8102 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8103 todo_wine
8104 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8105 value32 = 0xdeadbeef;
8106 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_PRIMARIES, &value32);
8107 todo_wine
8108 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8109 todo_wine
8110 ok(value32 == MFVideoPrimaries_BT709, "got %u.\n", value32);
8111 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &value32);
8112 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8113 IMFMediaType_DeleteAllItems(media_type);
8115 format.videoInfo.TransferMatrix = MFVideoTransferMatrix_BT709;
8116 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8117 todo_wine
8118 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8119 value32 = 0xdeadbeef;
8120 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &value32);
8121 todo_wine
8122 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8123 todo_wine
8124 ok(value32 == MFVideoTransferMatrix_BT709, "got %u.\n", value32);
8125 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_LIGHTING, &value32);
8126 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8127 IMFMediaType_DeleteAllItems(media_type);
8129 format.videoInfo.SourceLighting = MFVideoLighting_bright;
8130 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8131 todo_wine
8132 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8133 value32 = 0xdeadbeef;
8134 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_LIGHTING, &value32);
8135 todo_wine
8136 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8137 todo_wine
8138 ok(value32 == MFVideoLighting_bright, "got %u.\n", value32);
8139 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
8140 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8141 IMFMediaType_DeleteAllItems(media_type);
8143 format.videoInfo.FramesPerSecond.Numerator = 30000;
8144 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8145 todo_wine
8146 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8147 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
8148 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8149 IMFMediaType_DeleteAllItems(media_type);
8150 format.videoInfo.FramesPerSecond.Denominator = 1001;
8151 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8152 todo_wine
8153 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8154 value64 = 0xdeadbeef;
8155 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
8156 todo_wine
8157 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8158 todo_wine
8159 ok(value64 == (((UINT64)30000 << 32) | 1001), "got %#I64x.\n", value64);
8160 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &value32);
8161 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8162 IMFMediaType_DeleteAllItems(media_type);
8164 format.videoInfo.NominalRange = MFNominalRange_Wide;
8165 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8166 todo_wine
8167 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8168 value32 = 0xdeadbeef;
8169 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &value32);
8170 todo_wine
8171 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8172 todo_wine
8173 ok(value32 == MFNominalRange_Wide, "got %u.\n", value32);
8174 hr = IMFMediaType_GetBlobSize(media_type, &MF_MT_GEOMETRIC_APERTURE, &value32);
8175 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8176 IMFMediaType_DeleteAllItems(media_type);
8178 format.videoInfo.GeometricAperture.OffsetX.value = 1;
8179 format.videoInfo.GeometricAperture.OffsetX.fract = 2;
8180 format.videoInfo.GeometricAperture.OffsetY.value = 3;
8181 format.videoInfo.GeometricAperture.OffsetY.fract = 4;
8182 format.videoInfo.GeometricAperture.Area.cx = -120;
8183 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8184 todo_wine
8185 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8186 hr = IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
8187 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8188 format.videoInfo.GeometricAperture.Area.cy = -450;
8189 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8190 todo_wine
8191 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8192 value32 = 0xdeadbeef;
8193 memset(&aperture, 0xcd, sizeof(aperture));
8194 hr = IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
8195 todo_wine
8196 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8197 todo_wine
8198 ok(value32 == sizeof(aperture), "got %u.\n", value32);
8199 todo_wine
8200 ok(!memcmp(&format.videoInfo.GeometricAperture, &aperture, sizeof(aperture)), "Unexpected aperture.\n");
8201 hr = IMFMediaType_GetBlobSize(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, &value32);
8202 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8203 IMFMediaType_DeleteAllItems(media_type);
8205 format.videoInfo.MinimumDisplayAperture.OffsetX.value = 1;
8206 format.videoInfo.MinimumDisplayAperture.OffsetX.fract = 2;
8207 format.videoInfo.MinimumDisplayAperture.OffsetY.value = 3;
8208 format.videoInfo.MinimumDisplayAperture.OffsetY.fract = 4;
8209 format.videoInfo.MinimumDisplayAperture.Area.cx = 120;
8210 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8211 todo_wine
8212 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8213 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
8214 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8215 format.videoInfo.MinimumDisplayAperture.Area.cy = 450;
8216 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8217 todo_wine
8218 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8219 value32 = 0xdeadbeef;
8220 memset(&aperture, 0xcd, sizeof(aperture));
8221 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
8222 todo_wine
8223 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8224 todo_wine
8225 ok(value32 == sizeof(aperture), "got %u.\n", value32);
8226 todo_wine
8227 ok(!memcmp(&format.videoInfo.MinimumDisplayAperture, &aperture, sizeof(aperture)), "Unexpected aperture.\n");
8228 hr = IMFMediaType_GetBlobSize(media_type, &MF_MT_PAN_SCAN_APERTURE, &value32);
8229 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8230 IMFMediaType_DeleteAllItems(media_type);
8232 format.videoInfo.PanScanAperture.OffsetX.value = 1;
8233 format.videoInfo.PanScanAperture.OffsetX.fract = 2;
8234 format.videoInfo.PanScanAperture.OffsetY.value = 3;
8235 format.videoInfo.PanScanAperture.OffsetY.fract = 4;
8236 format.videoInfo.PanScanAperture.Area.cx = 120;
8237 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8238 todo_wine
8239 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8240 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
8241 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8242 format.videoInfo.PanScanAperture.Area.cy = 450;
8243 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8244 todo_wine
8245 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8246 value32 = 0xdeadbeef;
8247 memset(&aperture, 0xcd, sizeof(aperture));
8248 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
8249 todo_wine
8250 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8251 todo_wine
8252 ok(value32 == sizeof(aperture), "got %u.\n", value32);
8253 todo_wine
8254 ok(!memcmp(&format.videoInfo.PanScanAperture, &aperture, sizeof(aperture)), "Unexpected aperture.\n");
8255 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &value32);
8256 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8257 IMFMediaType_DeleteAllItems(media_type);
8259 format.videoInfo.VideoFlags |= MFVideoFlag_PanScanEnabled;
8260 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8261 todo_wine
8262 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8263 value32 = 0xdeadbeef;
8264 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &value32);
8265 todo_wine
8266 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8267 todo_wine
8268 ok(value32 == 1, "got %u.\n", value32);
8269 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAD_CONTROL_FLAGS, &value32);
8270 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8271 IMFMediaType_DeleteAllItems(media_type);
8273 format.videoInfo.VideoFlags |= MFVideoFlag_PAD_TO_16x9;
8274 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8275 todo_wine
8276 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8277 value32 = 0xdeadbeef;
8278 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAD_CONTROL_FLAGS, &value32);
8279 todo_wine
8280 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8281 todo_wine
8282 ok(value32 == 2, "got %u.\n", value32);
8283 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SOURCE_CONTENT_HINT, &value32);
8284 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8285 IMFMediaType_DeleteAllItems(media_type);
8287 format.videoInfo.VideoFlags |= MFVideoFlag_SrcContentHint16x9;
8288 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8289 todo_wine
8290 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8291 value32 = 0xdeadbeef;
8292 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SOURCE_CONTENT_HINT, &value32);
8293 todo_wine
8294 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8295 todo_wine
8296 ok(value32 == 1, "got %u.\n", value32);
8297 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DRM_FLAGS, &value32);
8298 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8299 IMFMediaType_DeleteAllItems(media_type);
8301 format.videoInfo.VideoFlags |= MFVideoFlag_DigitallyProtected;
8302 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8303 todo_wine
8304 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8305 value32 = 0xdeadbeef;
8306 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DRM_FLAGS, &value32);
8307 todo_wine
8308 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8309 todo_wine
8310 ok(value32 == 2, "got %u.\n", value32);
8311 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value32);
8312 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8313 IMFMediaType_DeleteAllItems(media_type);
8315 format.compressedInfo.AvgBitrate = 123456;
8316 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8317 todo_wine
8318 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8319 value32 = 0xdeadbeef;
8320 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value32);
8321 todo_wine
8322 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8323 todo_wine
8324 ok(value32 == 123456, "got %u.\n", value32);
8325 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value32);
8326 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8327 IMFMediaType_DeleteAllItems(media_type);
8329 format.compressedInfo.AvgBitErrorRate = 654321;
8330 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8331 todo_wine
8332 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8333 value32 = 0xdeadbeef;
8334 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value32);
8335 todo_wine
8336 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8337 todo_wine
8338 ok(value32 == 654321, "got %u.\n", value32);
8339 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_MAX_KEYFRAME_SPACING, &value32);
8340 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8341 IMFMediaType_DeleteAllItems(media_type);
8343 format.compressedInfo.MaxKeyFrameSpacing = -123;
8344 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8345 todo_wine
8346 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8347 value32 = 0xdeadbeef;
8348 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_MAX_KEYFRAME_SPACING, &value32);
8349 todo_wine
8350 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8351 todo_wine
8352 ok(value32 == -123, "got %u.\n", value32);
8353 hr = IMFMediaType_GetBlobSize(media_type, &MF_MT_PALETTE, &value32);
8354 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8355 IMFMediaType_DeleteAllItems(media_type);
8357 /* any subtype works here */
8358 format.guidFormat = MFVideoFormat_H264;
8359 format.surfaceInfo.Format = MFVideoFormat_H264.Data1;
8360 hr = MFInitMediaTypeFromMFVideoFormat(media_type, &format, sizeof(format));
8361 todo_wine
8362 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8363 hr = IMFMediaType_GetBlobSize(media_type, &MF_MT_PALETTE, &value32);
8364 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8365 IMFMediaType_DeleteAllItems(media_type);
8367 *format_buf = format;
8368 for (i = 0; i < ARRAY_SIZE(expect_palette); i++)
8369 format_buf->surfaceInfo.Palette[i] = expect_palette[i];
8370 format_buf->surfaceInfo.PaletteEntries = ARRAY_SIZE(expect_palette);
8372 /* format sizes needs to include an extra palette entry */
8373 format_buf->dwSize = offsetof(MFVIDEOFORMAT, surfaceInfo.Palette[ARRAY_SIZE(expect_palette)]);
8374 hr = MFInitMediaTypeFromMFVideoFormat(media_type, format_buf, sizeof(format));
8375 todo_wine
8376 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
8378 format_buf->dwSize = offsetof(MFVIDEOFORMAT, surfaceInfo.Palette[ARRAY_SIZE(expect_palette) + 1]);
8379 hr = MFInitMediaTypeFromMFVideoFormat(media_type, format_buf, format_buf->dwSize);
8380 todo_wine
8381 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8382 value32 = 0xdeadbeef;
8383 memset(&palette, 0xcd, sizeof(palette));
8384 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PALETTE, (BYTE *)&palette, sizeof(palette), &value32);
8385 todo_wine
8386 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8387 todo_wine
8388 ok(value32 == sizeof(expect_palette), "got %u.\n", value32);
8389 todo_wine
8390 ok(!memcmp(palette, expect_palette, value32), "Unexpected palette.\n");
8391 hr = IMFMediaType_GetBlobSize(media_type, &MF_MT_USER_DATA, &value32);
8392 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8393 IMFMediaType_DeleteAllItems(media_type);
8395 memcpy(buffer + format_buf->dwSize, expect_user_data, sizeof(expect_user_data));
8396 format_buf->dwSize += sizeof(expect_user_data);
8397 hr = MFInitMediaTypeFromMFVideoFormat(media_type, format_buf, format_buf->dwSize);
8398 todo_wine
8399 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8400 value32 = 0xdeadbeef;
8401 memset(&user_data, 0xcd, sizeof(user_data));
8402 hr = IMFMediaType_GetBlob(media_type, &MF_MT_USER_DATA, (BYTE *)user_data, sizeof(user_data), &value32);
8403 todo_wine
8404 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8405 todo_wine
8406 ok(value32 == sizeof(expect_user_data), "got %u.\n", value32);
8407 todo_wine
8408 ok(!memcmp(user_data, expect_user_data, value32), "Unexpected user data.\n");
8409 IMFMediaType_DeleteAllItems(media_type);
8411 IMFMediaType_Release(media_type);
8414 static void test_IMFMediaType_GetRepresentation(void)
8416 WAVEFORMATEX wfx = {.wFormatTag = WAVE_FORMAT_PCM};
8417 IMFMediaType *media_type;
8418 AM_MEDIA_TYPE *am_type;
8419 HRESULT hr;
8421 hr = MFCreateMediaType(&media_type);
8422 ok(hr == S_OK, "Failed to create media type, hr %#lx.\n", hr);
8424 hr = IMFMediaType_GetRepresentation(media_type, GUID_NULL, (void **)&am_type);
8425 ok(hr == MF_E_UNSUPPORTED_REPRESENTATION, "Unexpected hr %#lx.\n", hr);
8426 hr = IMFMediaType_GetRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, (void **)&am_type);
8427 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8428 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
8429 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8430 hr = IMFMediaType_GetRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, (void **)&am_type);
8431 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8432 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
8433 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8434 hr = IMFMediaType_GetRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, (void **)&am_type);
8435 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
8437 hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Audio);
8438 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8439 hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFAudioFormat_PCM);
8440 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8441 hr = IMFMediaType_GetRepresentation(media_type, FORMAT_VideoInfo, (void **)&am_type);
8442 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
8443 hr = IMFMediaType_GetRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, (void **)&am_type);
8444 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8445 ok(IsEqualGUID(&am_type->majortype, &MFMediaType_Audio), "got %s.\n", debugstr_guid(&am_type->majortype));
8446 ok(IsEqualGUID(&am_type->subtype, &MFAudioFormat_PCM), "got %s.\n", debugstr_guid(&am_type->subtype));
8447 ok(IsEqualGUID(&am_type->formattype, &FORMAT_WaveFormatEx), "got %s.\n", debugstr_guid(&am_type->formattype));
8448 ok(am_type->cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type->cbFormat);
8449 hr = IMFMediaType_FreeRepresentation(media_type, IID_IUnknown /* invalid format */, am_type);
8450 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8451 IMFMediaType_Release(media_type);
8453 hr = MFCreateAudioMediaType(&wfx, (IMFAudioMediaType **)&media_type);
8454 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8455 hr = IMFMediaType_GetRepresentation(media_type, GUID_NULL, (void **)&am_type);
8456 ok(hr == MF_E_UNSUPPORTED_REPRESENTATION, "Unexpected hr %#lx.\n", hr);
8457 hr = IMFMediaType_GetRepresentation(media_type, FORMAT_VideoInfo, (void **)&am_type);
8458 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
8459 hr = IMFMediaType_GetRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, (void **)&am_type);
8460 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8461 ok(IsEqualGUID(&am_type->majortype, &MFMediaType_Audio), "got %s.\n", debugstr_guid(&am_type->majortype));
8462 ok(IsEqualGUID(&am_type->subtype, &MFAudioFormat_PCM), "got %s.\n", debugstr_guid(&am_type->subtype));
8463 ok(IsEqualGUID(&am_type->formattype, &FORMAT_WaveFormatEx), "got %s.\n", debugstr_guid(&am_type->formattype));
8464 ok(am_type->cbFormat == sizeof(WAVEFORMATEX), "got %lu\n", am_type->cbFormat);
8465 hr = IMFMediaType_FreeRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, am_type);
8466 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8467 IMFMediaType_Release(media_type);
8469 hr = MFCreateVideoMediaTypeFromSubtype(&MFVideoFormat_RGB32, (IMFVideoMediaType **)&media_type);
8470 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8471 hr = IMFMediaType_GetRepresentation(media_type, GUID_NULL, (void **)&am_type);
8472 ok(hr == MF_E_UNSUPPORTED_REPRESENTATION, "Unexpected hr %#lx.\n", hr);
8473 hr = IMFMediaType_GetRepresentation(media_type, FORMAT_WaveFormatEx, (void **)&am_type);
8474 ok(hr == MF_E_UNSUPPORTED_REPRESENTATION, "Unexpected hr %#lx.\n", hr);
8475 hr = IMFMediaType_GetRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, (void **)&am_type);
8476 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8477 ok(IsEqualGUID(&am_type->majortype, &MFMediaType_Video), "got %s.\n", debugstr_guid(&am_type->majortype));
8478 ok(IsEqualGUID(&am_type->subtype, &MEDIASUBTYPE_RGB32), "got %s.\n", debugstr_guid(&am_type->subtype));
8479 ok(IsEqualGUID(&am_type->formattype, &FORMAT_VideoInfo), "got %s.\n", debugstr_guid(&am_type->formattype));
8480 ok(am_type->cbFormat == sizeof(VIDEOINFOHEADER), "got %lu\n", am_type->cbFormat);
8481 hr = IMFMediaType_FreeRepresentation(media_type, AM_MEDIA_TYPE_REPRESENTATION, am_type);
8482 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8484 IMFMediaType_Release(media_type);
8487 static void test_MFCreateDXSurfaceBuffer(void)
8489 IDirect3DSurface9 *backbuffer = NULL, *surface;
8490 IDirect3DSwapChain9 *swapchain;
8491 D3DLOCKED_RECT locked_rect;
8492 DWORD length, max_length;
8493 IDirect3DDevice9 *device;
8494 IMF2DBuffer2 *_2dbuffer2;
8495 BOOL value, broken_test;
8496 IMFMediaBuffer *buffer;
8497 IMF2DBuffer *_2dbuffer;
8498 BYTE *data, *data2;
8499 IMFGetService *gs;
8500 IDirect3D9 *d3d;
8501 DWORD color;
8502 HWND window;
8503 HRESULT hr;
8504 LONG pitch;
8506 if (!pMFCreateDXSurfaceBuffer)
8508 win_skip("MFCreateDXSurfaceBuffer is not available.\n");
8509 return;
8512 d3d = Direct3DCreate9(D3D_SDK_VERSION);
8513 if (!d3d)
8515 skip("Failed to create a D3D9 object, skipping tests.\n");
8516 return;
8518 window = create_window();
8519 if (!(device = create_d3d9_device(d3d, window)))
8521 skip("Failed to create a D3D device, skipping tests.\n");
8522 goto done;
8525 hr = IDirect3DDevice9_GetSwapChain(device, 0, &swapchain);
8526 ok(SUCCEEDED(hr), "Failed to get the implicit swapchain (%08lx)\n", hr);
8528 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
8529 ok(SUCCEEDED(hr), "Failed to get the back buffer (%08lx)\n", hr);
8530 ok(backbuffer != NULL, "The back buffer is NULL\n");
8532 IDirect3DSwapChain9_Release(swapchain);
8534 hr = pMFCreateDXSurfaceBuffer(&IID_IUnknown, (IUnknown *)backbuffer, FALSE, &buffer);
8535 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
8537 hr = pMFCreateDXSurfaceBuffer(&IID_IDirect3DSurface9, (IUnknown *)backbuffer, FALSE, &buffer);
8538 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
8540 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
8541 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
8542 check_interface(buffer, &IID_IMFGetService, TRUE);
8544 /* Surface is accessible. */
8545 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFGetService, (void **)&gs);
8546 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8547 hr = IMFGetService_GetService(gs, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, (void **)&surface);
8548 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8549 ok(surface == backbuffer, "Unexpected surface pointer.\n");
8550 IDirect3DSurface9_Release(surface);
8551 IMFGetService_Release(gs);
8553 max_length = 0;
8554 hr = IMFMediaBuffer_GetMaxLength(buffer, &max_length);
8555 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8556 ok(!!max_length, "Unexpected length %lu.\n", max_length);
8558 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
8559 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
8560 ok(!length, "Unexpected length %lu.\n", length);
8562 hr = IMFMediaBuffer_SetCurrentLength(buffer, 2 * max_length);
8563 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
8565 hr = IMFMediaBuffer_GetCurrentLength(buffer, &length);
8566 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
8567 ok(length == 2 * max_length, "Unexpected length %lu.\n", length);
8569 hr = IDirect3DSurface9_LockRect(backbuffer, &locked_rect, NULL, 0);
8570 ok(hr == S_OK, "Failed to lock back buffer, hr %#lx.\n", hr);
8572 /* Cannot lock while the surface is locked. */
8573 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, &length);
8574 ok(hr == D3DERR_INVALIDCALL, "Unexpected hr %#lx.\n", hr);
8576 hr = IDirect3DSurface9_UnlockRect(backbuffer);
8577 ok(hr == S_OK, "Failed to unlock back buffer, hr %#lx.\n", hr);
8579 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, &length);
8580 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8581 /* Broken on Windows 8 and 10 v1507 */
8582 broken_test = length == 0;
8583 ok(length == max_length || broken(broken_test), "Unexpected length %lu instead of %lu.\n", length, max_length);
8585 /* You can lock the surface while the media buffer is locked. */
8586 hr = IDirect3DSurface9_LockRect(backbuffer, &locked_rect, NULL, 0);
8587 ok(hr == S_OK, "Failed to lock back buffer, hr %#lx.\n", hr);
8589 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, &length);
8590 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8592 hr = IMFMediaBuffer_Unlock(buffer);
8593 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8595 hr = IDirect3DSurface9_UnlockRect(backbuffer);
8596 ok(hr == S_OK, "Failed to unlock back buffer, hr %#lx.\n", hr);
8598 /* Unlock twice. */
8599 hr = IMFMediaBuffer_Unlock(buffer);
8600 ok(hr == S_OK || broken(broken_test), "Unexpected hr %#lx.\n", hr);
8602 hr = IMFMediaBuffer_Unlock(buffer);
8603 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
8605 /* Lock twice. */
8606 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
8607 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8609 hr = IMFMediaBuffer_Lock(buffer, &data2, NULL, NULL);
8610 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8611 ok(data == data2, "Unexpected pointer.\n");
8613 hr = IMFMediaBuffer_Unlock(buffer);
8614 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8616 hr = IMFMediaBuffer_Unlock(buffer);
8617 ok(hr == S_OK || broken(broken_test), "Unexpected hr %#lx.\n", hr);
8619 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2dbuffer);
8620 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8622 /* Unlocked. */
8623 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, &data, &pitch);
8624 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
8626 hr = IDirect3DSurface9_LockRect(backbuffer, &locked_rect, NULL, 0);
8627 ok(hr == S_OK, "Failed to lock back buffer, hr %#lx.\n", hr);
8629 /* Cannot lock the buffer while the surface is locked. */
8630 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8631 ok(hr == D3DERR_INVALIDCALL, "Unexpected hr %#lx.\n", hr);
8633 hr = IDirect3DSurface9_UnlockRect(backbuffer);
8634 ok(hr == S_OK, "Failed to unlock back buffer, hr %#lx.\n", hr);
8636 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8637 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8639 /* Cannot lock the surface once the buffer is locked. */
8640 hr = IDirect3DSurface9_LockRect(backbuffer, &locked_rect, NULL, 0);
8641 ok(hr == D3DERR_INVALIDCALL, "Unexpected hr %#lx.\n", hr);
8643 hr = IMF2DBuffer_GetScanline0AndPitch(_2dbuffer, &data, &pitch);
8644 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8646 hr = IMFMediaBuffer_Lock(buffer, &data2, NULL, NULL);
8647 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
8649 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8650 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8652 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
8653 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8655 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
8656 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8658 hr = IMF2DBuffer_Unlock2D(_2dbuffer);
8659 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
8661 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
8662 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8664 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8665 ok(hr == MF_E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
8667 hr = IMFMediaBuffer_Unlock(buffer);
8668 ok(hr == S_OK || broken(broken_test), "Unexpected hr %#lx.\n", hr);
8670 hr = IMF2DBuffer_IsContiguousFormat(_2dbuffer, &value);
8671 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8672 ok(!value, "Unexpected return value %d.\n", value);
8674 hr = IMF2DBuffer_GetContiguousLength(_2dbuffer, NULL);
8675 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
8676 hr = IMF2DBuffer_GetContiguousLength(_2dbuffer, &length);
8677 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8678 ok(length == max_length, "Unexpected length %lu.\n", length);
8680 IMF2DBuffer_Release(_2dbuffer);
8682 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2);
8683 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8685 /* Lock flags are ignored, so writing is allowed when locking for
8686 * reading and viceversa. */
8687 put_d3d9_surface_color(backbuffer, 0, 0, 0xcdcdcdcd);
8688 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
8689 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8690 ok(data == data2, "Unexpected scanline pointer.\n");
8691 ok(data[0] == 0xcd, "Unexpected leading byte.\n");
8692 memset(data, 0xab, 4);
8693 IMF2DBuffer2_Unlock2D(_2dbuffer2);
8695 color = get_d3d9_surface_color(backbuffer, 0, 0);
8696 ok(color == 0xabababab, "Unexpected leading dword.\n");
8697 put_d3d9_surface_color(backbuffer, 0, 0, 0xefefefef);
8699 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
8700 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8701 ok(data[0] == 0xef, "Unexpected leading byte.\n");
8702 memset(data, 0x89, 4);
8703 IMF2DBuffer2_Unlock2D(_2dbuffer2);
8705 color = get_d3d9_surface_color(backbuffer, 0, 0);
8706 ok(color == 0x89898989, "Unexpected leading dword.\n");
8708 /* Also, flags incompatibilities are not taken into account even
8709 * if a buffer is already locked. */
8710 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
8711 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8712 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
8713 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8714 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
8715 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8716 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
8717 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8718 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8719 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8720 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8721 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8722 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8723 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8724 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8725 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8726 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8727 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8728 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8729 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8731 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
8732 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8733 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
8734 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8735 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
8736 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8737 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
8738 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8739 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8740 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8741 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8742 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8743 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8744 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8745 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8746 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8747 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8748 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8749 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8750 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8752 /* Except when originally locking for writing. */
8753 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
8754 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8755 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
8756 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8757 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
8758 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_LOCKED), "Unexpected hr %#lx.\n", hr);
8759 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
8760 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_LOCKED), "Unexpected hr %#lx.\n", hr);
8761 hr = IMF2DBuffer_Lock2D(_2dbuffer, &data, &pitch);
8762 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_LOCKED), "Unexpected hr %#lx.\n", hr);
8763 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8764 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8765 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8766 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8768 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
8769 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
8771 IMF2DBuffer2_Release(_2dbuffer2);
8773 IMFMediaBuffer_Release(buffer);
8774 IDirect3DDevice9_Release(device);
8776 done:
8777 if (backbuffer)
8778 IDirect3DSurface9_Release(backbuffer);
8779 ok(!IDirect3D9_Release(d3d), "Unexpected refcount.\n");
8780 DestroyWindow(window);
8783 static void test_MFCreateTrackedSample(void)
8785 IMFTrackedSample *tracked_sample;
8786 IMFSample *sample;
8787 IUnknown *unk;
8788 HRESULT hr;
8790 if (!pMFCreateTrackedSample)
8792 win_skip("MFCreateTrackedSample() is not available.\n");
8793 return;
8796 hr = pMFCreateTrackedSample(&tracked_sample);
8797 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8799 /* It's actually a sample. */
8800 hr = IMFTrackedSample_QueryInterface(tracked_sample, &IID_IMFSample, (void **)&sample);
8801 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8803 hr = IMFTrackedSample_QueryInterface(tracked_sample, &IID_IUnknown, (void **)&unk);
8804 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8805 ok(unk == (IUnknown *)sample, "Unexpected pointer.\n");
8806 IUnknown_Release(unk);
8808 IMFSample_Release(sample);
8810 check_interface(tracked_sample, &IID_IMFDesiredSample, FALSE);
8812 IMFTrackedSample_Release(tracked_sample);
8815 static void test_MFFrameRateToAverageTimePerFrame(void)
8817 static const struct frame_rate_test
8819 unsigned int numerator;
8820 unsigned int denominator;
8821 UINT64 avgtime;
8822 } frame_rate_tests[] =
8824 { 60000, 1001, 166833 },
8825 { 30000, 1001, 333667 },
8826 { 24000, 1001, 417188 },
8827 { 60, 1, 166667 },
8828 { 30, 1, 333333 },
8829 { 50, 1, 200000 },
8830 { 25, 1, 400000 },
8831 { 24, 1, 416667 },
8833 { 39, 1, 256410 },
8834 { 120, 1, 83333 },
8836 unsigned int i;
8837 UINT64 avgtime;
8838 HRESULT hr;
8840 avgtime = 1;
8841 hr = MFFrameRateToAverageTimePerFrame(0, 0, &avgtime);
8842 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8843 ok(!avgtime, "Unexpected frame time.\n");
8845 avgtime = 1;
8846 hr = MFFrameRateToAverageTimePerFrame(0, 1001, &avgtime);
8847 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8848 ok(!avgtime, "Unexpected frame time.\n");
8850 for (i = 0; i < ARRAY_SIZE(frame_rate_tests); ++i)
8852 avgtime = 0;
8853 hr = MFFrameRateToAverageTimePerFrame(frame_rate_tests[i].numerator,
8854 frame_rate_tests[i].denominator, &avgtime);
8855 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8856 ok(avgtime == frame_rate_tests[i].avgtime, "%u: unexpected frame time %s, expected %s.\n",
8857 i, wine_dbgstr_longlong(avgtime), wine_dbgstr_longlong(frame_rate_tests[i].avgtime));
8861 static void test_MFAverageTimePerFrameToFrameRate(void)
8863 static const struct frame_rate_test
8865 unsigned int numerator;
8866 unsigned int denominator;
8867 UINT64 avgtime;
8868 } frame_rate_tests[] =
8870 { 60000, 1001, 166863 },
8871 { 60000, 1001, 166833 },
8872 { 60000, 1001, 166803 },
8874 { 30000, 1001, 333697 },
8875 { 30000, 1001, 333667 },
8876 { 30000, 1001, 333637 },
8878 { 24000, 1001, 417218 },
8879 { 24000, 1001, 417188 },
8880 { 24000, 1001, 417158 },
8882 { 60, 1, 166697 },
8883 { 60, 1, 166667 },
8884 { 60, 1, 166637 },
8886 { 30, 1, 333363 },
8887 { 30, 1, 333333 },
8888 { 30, 1, 333303 },
8890 { 50, 1, 200030 },
8891 { 50, 1, 200000 },
8892 { 50, 1, 199970 },
8894 { 25, 1, 400030 },
8895 { 25, 1, 400000 },
8896 { 25, 1, 399970 },
8898 { 24, 1, 416697 },
8899 { 24, 1, 416667 },
8900 { 24, 1, 416637 },
8902 { 1000000, 25641, 256410 },
8903 { 10000000, 83333, 83333 },
8904 { 1, 10, 100000000 },
8905 { 1, 10, 100000001 },
8906 { 1, 10, 200000000 },
8907 { 1, 1, 10000000 },
8908 { 1, 2, 20000000 },
8909 { 5, 1, 2000000 },
8910 { 10, 1, 1000000 },
8912 unsigned int i, numerator, denominator;
8913 HRESULT hr;
8915 numerator = denominator = 1;
8916 hr = MFAverageTimePerFrameToFrameRate(0, &numerator, &denominator);
8917 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8918 ok(!numerator && !denominator, "Unexpected output %u/%u.\n", numerator, denominator);
8920 for (i = 0; i < ARRAY_SIZE(frame_rate_tests); ++i)
8922 numerator = denominator = 12345;
8923 hr = MFAverageTimePerFrameToFrameRate(frame_rate_tests[i].avgtime, &numerator, &denominator);
8924 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
8925 ok(numerator == frame_rate_tests[i].numerator && denominator == frame_rate_tests[i].denominator,
8926 "%u: unexpected %u/%u, expected %u/%u.\n", i, numerator, denominator, frame_rate_tests[i].numerator,
8927 frame_rate_tests[i].denominator);
8931 static void test_MFMapDXGIFormatToDX9Format(void)
8933 static const struct format_pair
8935 DXGI_FORMAT dxgi_format;
8936 DWORD d3d9_format;
8938 formats_map[] =
8940 { DXGI_FORMAT_R32G32B32A32_FLOAT, D3DFMT_A32B32G32R32F },
8941 { DXGI_FORMAT_R16G16B16A16_FLOAT, D3DFMT_A16B16G16R16F },
8942 { DXGI_FORMAT_R16G16B16A16_UNORM, D3DFMT_A16B16G16R16 },
8943 { DXGI_FORMAT_R16G16B16A16_SNORM, D3DFMT_Q16W16V16U16 },
8944 { DXGI_FORMAT_R32G32_FLOAT, D3DFMT_G32R32F },
8945 { DXGI_FORMAT_R10G10B10A2_UNORM, D3DFMT_A2B10G10R10 },
8946 { DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3DFMT_A8R8G8B8 },
8947 { DXGI_FORMAT_R8G8B8A8_SNORM, D3DFMT_Q8W8V8U8 },
8948 { DXGI_FORMAT_R16G16_FLOAT, D3DFMT_G16R16F },
8949 { DXGI_FORMAT_R16G16_UNORM, D3DFMT_G16R16 },
8950 { DXGI_FORMAT_R16G16_SNORM, D3DFMT_V16U16 },
8951 { DXGI_FORMAT_D32_FLOAT, D3DFMT_D32F_LOCKABLE },
8952 { DXGI_FORMAT_R32_FLOAT, D3DFMT_R32F },
8953 { DXGI_FORMAT_D24_UNORM_S8_UINT, D3DFMT_D24S8 },
8954 { DXGI_FORMAT_R8G8_SNORM, D3DFMT_V8U8 },
8955 { DXGI_FORMAT_R16_FLOAT, D3DFMT_R16F },
8956 { DXGI_FORMAT_R16_UNORM, D3DFMT_L16 },
8957 { DXGI_FORMAT_R8_UNORM, D3DFMT_L8 },
8958 { DXGI_FORMAT_A8_UNORM, D3DFMT_A8 },
8959 { DXGI_FORMAT_BC1_UNORM, D3DFMT_DXT1 },
8960 { DXGI_FORMAT_BC1_UNORM_SRGB, D3DFMT_DXT1 },
8961 { DXGI_FORMAT_BC2_UNORM, D3DFMT_DXT2 },
8962 { DXGI_FORMAT_BC2_UNORM_SRGB, D3DFMT_DXT2 },
8963 { DXGI_FORMAT_BC3_UNORM, D3DFMT_DXT4 },
8964 { DXGI_FORMAT_BC3_UNORM_SRGB, D3DFMT_DXT4 },
8965 { DXGI_FORMAT_B8G8R8A8_UNORM, D3DFMT_A8R8G8B8 },
8966 { DXGI_FORMAT_B8G8R8X8_UNORM, D3DFMT_X8R8G8B8 },
8967 { DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3DFMT_A8R8G8B8 },
8968 { DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, D3DFMT_X8R8G8B8 },
8969 { DXGI_FORMAT_AYUV, MAKEFOURCC('A','Y','U','V') },
8970 { DXGI_FORMAT_Y410, MAKEFOURCC('Y','4','1','0') },
8971 { DXGI_FORMAT_Y416, MAKEFOURCC('Y','4','1','6') },
8972 { DXGI_FORMAT_NV12, MAKEFOURCC('N','V','1','2') },
8973 { DXGI_FORMAT_P010, MAKEFOURCC('P','0','1','0') },
8974 { DXGI_FORMAT_P016, MAKEFOURCC('P','0','1','6') },
8975 { DXGI_FORMAT_420_OPAQUE, MAKEFOURCC('4','2','0','O') },
8976 { DXGI_FORMAT_YUY2, D3DFMT_YUY2 },
8977 { DXGI_FORMAT_Y210, MAKEFOURCC('Y','2','1','0') },
8978 { DXGI_FORMAT_Y216, MAKEFOURCC('Y','2','1','6') },
8979 { DXGI_FORMAT_NV11, MAKEFOURCC('N','V','1','1') },
8980 { DXGI_FORMAT_AI44, MAKEFOURCC('A','I','4','4') },
8981 { DXGI_FORMAT_IA44, MAKEFOURCC('I','A','4','4') },
8982 { DXGI_FORMAT_P8, D3DFMT_P8 },
8983 { DXGI_FORMAT_A8P8, D3DFMT_A8P8 },
8985 unsigned int i;
8986 DWORD format;
8988 if (!pMFMapDXGIFormatToDX9Format)
8990 win_skip("MFMapDXGIFormatToDX9Format is not available.\n");
8991 return;
8994 for (i = 0; i < ARRAY_SIZE(formats_map); ++i)
8996 format = pMFMapDXGIFormatToDX9Format(formats_map[i].dxgi_format);
8997 ok(format == formats_map[i].d3d9_format, "Unexpected d3d9 format %#lx, dxgi format %#x.\n", format, formats_map[i].dxgi_format);
9001 static void test_MFMapDX9FormatToDXGIFormat(void)
9003 static const struct format_pair
9005 DXGI_FORMAT dxgi_format;
9006 DWORD d3d9_format;
9008 formats_map[] =
9010 { DXGI_FORMAT_R32G32B32A32_FLOAT, D3DFMT_A32B32G32R32F },
9011 { DXGI_FORMAT_R16G16B16A16_FLOAT, D3DFMT_A16B16G16R16F },
9012 { DXGI_FORMAT_R16G16B16A16_UNORM, D3DFMT_A16B16G16R16 },
9013 { DXGI_FORMAT_R16G16B16A16_SNORM, D3DFMT_Q16W16V16U16 },
9014 { DXGI_FORMAT_R32G32_FLOAT, D3DFMT_G32R32F },
9015 { DXGI_FORMAT_R10G10B10A2_UNORM, D3DFMT_A2B10G10R10 },
9016 { 0, D3DFMT_A2R10G10B10 }, /* doesn't map to DXGI */
9017 { DXGI_FORMAT_R8G8B8A8_SNORM, D3DFMT_Q8W8V8U8 },
9018 { DXGI_FORMAT_R16G16_FLOAT, D3DFMT_G16R16F },
9019 { DXGI_FORMAT_R16G16_UNORM, D3DFMT_G16R16 },
9020 { DXGI_FORMAT_R16G16_SNORM, D3DFMT_V16U16 },
9021 { DXGI_FORMAT_D32_FLOAT, D3DFMT_D32F_LOCKABLE },
9022 { DXGI_FORMAT_R32_FLOAT, D3DFMT_R32F },
9023 { DXGI_FORMAT_D24_UNORM_S8_UINT, D3DFMT_D24S8 },
9024 { DXGI_FORMAT_R8G8_SNORM, D3DFMT_V8U8 },
9025 { DXGI_FORMAT_R16_FLOAT, D3DFMT_R16F },
9026 { DXGI_FORMAT_R16_UNORM, D3DFMT_L16 },
9027 { DXGI_FORMAT_R8_UNORM, D3DFMT_L8 },
9028 { DXGI_FORMAT_A8_UNORM, D3DFMT_A8 },
9029 { DXGI_FORMAT_BC1_UNORM, D3DFMT_DXT1 },
9030 { DXGI_FORMAT_BC2_UNORM, D3DFMT_DXT2 },
9031 { DXGI_FORMAT_BC3_UNORM, D3DFMT_DXT4 },
9032 { DXGI_FORMAT_B8G8R8A8_UNORM, D3DFMT_A8R8G8B8 },
9033 { DXGI_FORMAT_B8G8R8X8_UNORM, D3DFMT_X8R8G8B8 },
9034 { DXGI_FORMAT_AYUV, MAKEFOURCC('A','Y','U','V') },
9035 { DXGI_FORMAT_Y410, MAKEFOURCC('Y','4','1','0') },
9036 { DXGI_FORMAT_Y416, MAKEFOURCC('Y','4','1','6') },
9037 { DXGI_FORMAT_NV12, MAKEFOURCC('N','V','1','2') },
9038 { DXGI_FORMAT_P010, MAKEFOURCC('P','0','1','0') },
9039 { DXGI_FORMAT_P016, MAKEFOURCC('P','0','1','6') },
9040 { DXGI_FORMAT_420_OPAQUE, MAKEFOURCC('4','2','0','O') },
9041 { DXGI_FORMAT_YUY2, D3DFMT_YUY2 },
9042 { DXGI_FORMAT_Y210, MAKEFOURCC('Y','2','1','0') },
9043 { DXGI_FORMAT_Y216, MAKEFOURCC('Y','2','1','6') },
9044 { DXGI_FORMAT_NV11, MAKEFOURCC('N','V','1','1') },
9045 { DXGI_FORMAT_AI44, MAKEFOURCC('A','I','4','4') },
9046 { DXGI_FORMAT_IA44, MAKEFOURCC('I','A','4','4') },
9047 { DXGI_FORMAT_P8, D3DFMT_P8 },
9048 { DXGI_FORMAT_A8P8, D3DFMT_A8P8 },
9050 DXGI_FORMAT format;
9051 unsigned int i;
9053 if (!pMFMapDX9FormatToDXGIFormat)
9055 win_skip("MFMapDX9FormatToDXGIFormat() is not available.\n");
9056 return;
9059 for (i = 0; i < ARRAY_SIZE(formats_map); ++i)
9061 format = pMFMapDX9FormatToDXGIFormat(formats_map[i].d3d9_format);
9062 ok(format == formats_map[i].dxgi_format, "Unexpected DXGI format %#x, d3d9 format %#lx.\n",
9063 format, formats_map[i].d3d9_format);
9067 static HRESULT WINAPI test_notify_callback_QueryInterface(IMFVideoSampleAllocatorNotify *iface,
9068 REFIID riid, void **obj)
9070 if (IsEqualIID(riid, &IID_IMFVideoSampleAllocatorNotify) ||
9071 IsEqualIID(riid, &IID_IUnknown))
9073 *obj = iface;
9074 IMFVideoSampleAllocatorNotify_AddRef(iface);
9075 return S_OK;
9078 *obj = NULL;
9079 return E_NOINTERFACE;
9082 static ULONG WINAPI test_notify_callback_AddRef(IMFVideoSampleAllocatorNotify *iface)
9084 return 2;
9087 static ULONG WINAPI test_notify_callback_Release(IMFVideoSampleAllocatorNotify *iface)
9089 return 1;
9092 static HRESULT WINAPI test_notify_callback_NotifyRelease(IMFVideoSampleAllocatorNotify *iface)
9094 return E_NOTIMPL;
9097 static const IMFVideoSampleAllocatorNotifyVtbl test_notify_callback_vtbl =
9099 test_notify_callback_QueryInterface,
9100 test_notify_callback_AddRef,
9101 test_notify_callback_Release,
9102 test_notify_callback_NotifyRelease,
9105 static IMFMediaType * create_video_type(const GUID *subtype)
9107 IMFMediaType *video_type;
9108 HRESULT hr;
9110 hr = MFCreateMediaType(&video_type);
9111 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9113 hr = IMFMediaType_SetGUID(video_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video);
9114 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9116 hr = IMFMediaType_SetGUID(video_type, &MF_MT_SUBTYPE, subtype);
9117 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9119 return video_type;
9122 static ID3D11Device *create_d3d11_device(void)
9124 static const D3D_FEATURE_LEVEL default_feature_level[] =
9126 D3D_FEATURE_LEVEL_11_0,
9127 D3D_FEATURE_LEVEL_10_1,
9128 D3D_FEATURE_LEVEL_10_0,
9130 const D3D_FEATURE_LEVEL *feature_level;
9131 unsigned int feature_level_count;
9132 ID3D11Device *device;
9134 feature_level = default_feature_level;
9135 feature_level_count = ARRAY_SIZE(default_feature_level);
9137 if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0,
9138 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
9139 return device;
9140 if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0,
9141 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
9142 return device;
9143 if (SUCCEEDED(pD3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0,
9144 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
9145 return device;
9147 return NULL;
9150 static void update_d3d11_texture(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
9151 const BYTE *data, unsigned int src_pitch)
9153 ID3D11DeviceContext *immediate_context;
9154 ID3D11Device *device;
9156 ID3D11Texture2D_GetDevice(texture, &device);
9157 ID3D11Device_GetImmediateContext(device, &immediate_context);
9159 ID3D11DeviceContext_UpdateSubresource(immediate_context, (ID3D11Resource *)texture,
9160 sub_resource_idx, NULL, data, src_pitch, 0);
9162 ID3D11DeviceContext_Release(immediate_context);
9163 ID3D11Device_Release(device);
9166 static ID3D12Device *create_d3d12_device(void)
9168 ID3D12Device *device;
9169 HRESULT hr;
9171 if (!pD3D12CreateDevice) return NULL;
9173 hr = pD3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&device);
9174 if (FAILED(hr))
9175 return NULL;
9177 return device;
9180 static void test_d3d11_surface_buffer(void)
9182 DWORD max_length, cur_length, length, color;
9183 BYTE *data, *data2, *buffer_start;
9184 IMFDXGIBuffer *dxgi_buffer;
9185 D3D11_TEXTURE2D_DESC desc;
9186 IMF2DBuffer2 *_2dbuffer2;
9187 ID3D11Texture2D *texture;
9188 IMF2DBuffer *_2d_buffer;
9189 IMFMediaBuffer *buffer;
9190 ID3D11Device *device;
9191 BYTE buff[64 * 64 * 4];
9192 LONG pitch, pitch2;
9193 UINT index, size;
9194 IUnknown *obj;
9195 HRESULT hr;
9197 if (!pMFCreateDXGISurfaceBuffer)
9199 win_skip("MFCreateDXGISurfaceBuffer() is not available.\n");
9200 return;
9203 /* d3d11 */
9204 if (!(device = create_d3d11_device()))
9206 skip("Failed to create a D3D11 device, skipping tests.\n");
9207 return;
9210 memset(&desc, 0, sizeof(desc));
9211 desc.Width = 64;
9212 desc.Height = 64;
9213 desc.ArraySize = 1;
9214 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
9215 desc.SampleDesc.Count = 1;
9216 desc.SampleDesc.Quality = 0;
9218 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9219 ok(hr == S_OK, "Failed to create a texture, hr %#lx.\n", hr);
9221 hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown *)texture, 0, FALSE, &buffer);
9222 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
9224 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
9225 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
9226 check_interface(buffer, &IID_IMFDXGIBuffer, TRUE);
9227 check_interface(buffer, &IID_IMFGetService, FALSE);
9229 max_length = 0;
9230 hr = IMFMediaBuffer_GetMaxLength(buffer, &max_length);
9231 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9232 ok(!!max_length, "Unexpected length %lu.\n", max_length);
9234 hr = IMFMediaBuffer_GetCurrentLength(buffer, &cur_length);
9235 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
9236 ok(!cur_length, "Unexpected length %lu.\n", cur_length);
9238 hr = IMFMediaBuffer_SetCurrentLength(buffer, 2 * max_length);
9239 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
9241 hr = IMFMediaBuffer_GetCurrentLength(buffer, &cur_length);
9242 ok(hr == S_OK, "Failed to get length, hr %#lx.\n", hr);
9243 ok(cur_length == 2 * max_length, "Unexpected length %lu.\n", cur_length);
9245 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2d_buffer);
9246 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9248 hr = IMF2DBuffer_GetContiguousLength(_2d_buffer, NULL);
9249 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
9250 hr = IMF2DBuffer_GetContiguousLength(_2d_buffer, &length);
9251 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9252 ok(length == max_length, "Unexpected length %lu.\n", length);
9253 IMF2DBuffer_Release(_2d_buffer);
9255 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
9256 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
9258 EXPECT_REF(texture, 2);
9259 hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D11Texture2D, (void **)&obj);
9260 ok(hr == S_OK, "Failed to get resource, hr %#lx.\n", hr);
9261 EXPECT_REF(texture, 3);
9262 ok(obj == (IUnknown *)texture, "Unexpected resource pointer.\n");
9263 IUnknown_Release(obj);
9265 hr = IMFDXGIBuffer_GetSubresourceIndex(dxgi_buffer, NULL);
9266 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
9268 hr = IMFDXGIBuffer_GetSubresourceIndex(dxgi_buffer, &index);
9269 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9270 ok(index == 0, "Unexpected subresource index.\n");
9272 hr = IMFDXGIBuffer_SetUnknown(dxgi_buffer, &IID_IMFDXGIBuffer, NULL);
9273 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9275 hr = IMFDXGIBuffer_SetUnknown(dxgi_buffer, &IID_IMFDXGIBuffer, (void *)device);
9276 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9278 hr = IMFDXGIBuffer_SetUnknown(dxgi_buffer, &IID_IMFDXGIBuffer, (void *)device);
9279 ok(hr == HRESULT_FROM_WIN32(ERROR_OBJECT_ALREADY_EXISTS), "Unexpected hr %#lx.\n", hr);
9281 hr = ID3D11Texture2D_GetPrivateData(texture, &IID_IMFDXGIBuffer, &size, &data);
9282 ok(hr == DXGI_ERROR_NOT_FOUND, "Unexpected hr %#lx.\n", hr);
9284 hr = IMFDXGIBuffer_GetUnknown(dxgi_buffer, &IID_IMFDXGIBuffer, &IID_ID3D11Device, (void **)&obj);
9285 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9286 ok(obj == (IUnknown *)device, "Unexpected pointer.\n");
9287 IUnknown_Release(obj);
9289 hr = IMFDXGIBuffer_SetUnknown(dxgi_buffer, &IID_IMFDXGIBuffer, NULL);
9290 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9292 hr = IMFDXGIBuffer_GetUnknown(dxgi_buffer, &IID_IMFDXGIBuffer, &IID_IUnknown, (void **)&obj);
9293 ok(hr == MF_E_NOT_FOUND, "Unexpected hr %#lx.\n", hr);
9295 IMFDXGIBuffer_Release(dxgi_buffer);
9297 /* Texture updates. */
9298 color = get_d3d11_texture_color(texture, 0, 0);
9299 ok(!color, "Unexpected texture color %#lx.\n", color);
9301 max_length = cur_length = 0;
9302 data = NULL;
9303 hr = IMFMediaBuffer_Lock(buffer, &data, &max_length, &cur_length);
9304 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9305 ok(max_length && max_length == cur_length, "Unexpected length %lu.\n", max_length);
9306 if (data) *(DWORD *)data = ~0u;
9308 color = get_d3d11_texture_color(texture, 0, 0);
9309 ok(!color, "Unexpected texture color %#lx.\n", color);
9311 hr = IMFMediaBuffer_Unlock(buffer);
9312 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9314 color = get_d3d11_texture_color(texture, 0, 0);
9315 ok(color == ~0u, "Unexpected texture color %#lx.\n", color);
9317 hr = IMFMediaBuffer_Lock(buffer, &data, &max_length, &cur_length);
9318 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9319 ok(*(DWORD *)data == ~0u, "Unexpected buffer %#lx.\n", *(DWORD *)data);
9321 hr = IMFMediaBuffer_Unlock(buffer);
9322 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9324 /* Lock2D()/Unlock2D() */
9325 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2d_buffer);
9326 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9328 hr = IMF2DBuffer_GetScanline0AndPitch(_2d_buffer, &data2, &pitch2);
9329 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
9331 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9332 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9333 ok(!!data && pitch == desc.Width * 4, "Unexpected pitch %ld.\n", pitch);
9335 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9336 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9337 ok(!!data && pitch == desc.Width * 4, "Unexpected pitch %ld.\n", pitch);
9339 hr = IMF2DBuffer_GetScanline0AndPitch(_2d_buffer, &data2, &pitch2);
9340 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9341 ok(data2 == data && pitch2 == pitch, "Unexpected data/pitch.\n");
9343 hr = IMFMediaBuffer_Lock(buffer, &data, &max_length, &cur_length);
9344 ok(hr == MF_E_INVALIDREQUEST, "Unexpected hr %#lx.\n", hr);
9346 hr = IMF2DBuffer_Unlock2D(_2d_buffer);
9347 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9349 hr = IMF2DBuffer_Unlock2D(_2d_buffer);
9350 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9352 hr = IMF2DBuffer_Unlock2D(_2d_buffer);
9353 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
9355 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
9356 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9358 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9359 ok(hr == MF_E_UNEXPECTED, "Unexpected hr %#lx.\n", hr);
9361 hr = IMFMediaBuffer_Unlock(buffer);
9362 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9364 IMF2DBuffer_Release(_2d_buffer);
9366 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2);
9367 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9369 /* Lock flags are honored, so reads and writes are discarded if
9370 * the flags are not correct. Also, previous content is discarded
9371 * when locking for writing and not for reading. */
9372 put_d3d11_texture_color(texture, 0, 0, 0xcdcdcdcd);
9373 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
9374 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9375 ok(data == data2, "Unexpected scanline pointer.\n");
9376 ok(*(DWORD *)data == 0xcdcdcdcd, "Unexpected leading dword %#lx.\n", *(DWORD *)data);
9377 memset(data, 0xab, 4);
9378 IMF2DBuffer2_Unlock2D(_2dbuffer2);
9380 color = get_d3d11_texture_color(texture, 0, 0);
9381 ok(color == 0xcdcdcdcd, "Unexpected leading dword %#lx.\n", color);
9382 put_d3d11_texture_color(texture, 0, 0, 0xefefefef);
9384 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9385 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9386 ok(*(DWORD *)data != 0xefefefef, "Unexpected leading dword.\n");
9387 IMF2DBuffer2_Unlock2D(_2dbuffer2);
9389 color = get_d3d11_texture_color(texture, 0, 0);
9390 ok(color != 0xefefefef, "Unexpected leading dword.\n");
9392 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9393 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9394 ok(*(DWORD *)data != 0xefefefef, "Unexpected leading dword.\n");
9395 memset(data, 0x89, 4);
9396 IMF2DBuffer2_Unlock2D(_2dbuffer2);
9398 color = get_d3d11_texture_color(texture, 0, 0);
9399 ok(color == 0x89898989, "Unexpected leading dword %#lx.\n", color);
9401 /* When relocking for writing, stores are committed even if they
9402 * were issued before relocking. */
9403 put_d3d11_texture_color(texture, 0, 0, 0xcdcdcdcd);
9404 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
9405 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9406 memset(data, 0xab, 4);
9407 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9408 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9409 IMF2DBuffer2_Unlock2D(_2dbuffer2);
9410 IMF2DBuffer2_Unlock2D(_2dbuffer2);
9412 color = get_d3d11_texture_color(texture, 0, 0);
9413 ok(color == 0xabababab, "Unexpected leading dword %#lx.\n", color);
9415 /* Flags incompatibilities. */
9416 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
9417 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9418 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
9419 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9420 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
9421 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9422 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9423 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9424 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9425 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9426 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9427 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9428 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9429 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9430 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9431 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9432 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9433 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9434 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9435 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9437 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
9438 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9439 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
9440 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9441 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
9442 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9443 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9444 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9445 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9446 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9447 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9448 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9449 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9450 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9451 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9452 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9453 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9454 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9455 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9456 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9458 /* Except when originally locking for writing. */
9459 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9460 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9461 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Write, &data, &pitch, &data2, &length);
9462 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9463 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_ReadWrite, &data, &pitch, &data2, &length);
9464 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_LOCKED), "Unexpected hr %#lx.\n", hr);
9465 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &data2, &length);
9466 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_LOCKED), "Unexpected hr %#lx.\n", hr);
9467 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9468 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_LOCKED), "Unexpected hr %#lx.\n", hr);
9469 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9470 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9471 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9472 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9474 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9475 ok(hr == HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED), "Unexpected hr %#lx.\n", hr);
9477 IMF2DBuffer2_Release(_2dbuffer2);
9478 IMFMediaBuffer_Release(buffer);
9480 /* Bottom up. */
9481 hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown *)texture, 0, TRUE, &buffer);
9482 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
9484 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2d_buffer);
9485 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9487 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9488 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9489 ok(!!data && pitch == desc.Width * 4, "Unexpected pitch %ld.\n", pitch);
9491 hr = IMF2DBuffer_GetScanline0AndPitch(_2d_buffer, &data2, &pitch2);
9492 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9493 ok(data2 == data && pitch2 == pitch, "Unexpected data/pitch.\n");
9495 hr = IMF2DBuffer_Unlock2D(_2d_buffer);
9496 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9498 IMF2DBuffer_Release(_2d_buffer);
9499 IMFMediaBuffer_Release(buffer);
9501 ID3D11Texture2D_Release(texture);
9503 memset(&desc, 0, sizeof(desc));
9504 desc.Width = 64;
9505 desc.Height = 64;
9506 desc.ArraySize = 1;
9507 desc.MipLevels = 1;
9508 desc.Format = DXGI_FORMAT_NV12;
9509 desc.SampleDesc.Count = 1;
9510 desc.SampleDesc.Quality = 0;
9512 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9513 if (SUCCEEDED(hr))
9515 hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown *)texture, 0, FALSE, &buffer);
9516 ok(hr == S_OK, "got %#lx.\n", hr);
9517 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&_2dbuffer2);
9518 ok(hr == S_OK, "got %#lx.\n", hr);
9520 hr = IMF2DBuffer2_Lock2DSize(_2dbuffer2, MF2DBuffer_LockFlags_Read, &data, &pitch, &buffer_start, &length);
9521 ok(hr == S_OK, "got %#lx.\n", hr);
9523 ok(pitch >= desc.Width, "got %ld.\n", pitch);
9524 ok(length == pitch * desc.Height * 3 / 2, "got %lu.\n", length);
9526 hr = IMF2DBuffer2_Unlock2D(_2dbuffer2);
9527 ok(hr == S_OK, "got %#lx.\n", hr);
9529 IMF2DBuffer2_Release(_2dbuffer2);
9530 IMFMediaBuffer_Release(buffer);
9531 ID3D11Texture2D_Release(texture);
9533 else
9535 win_skip("Failed to create NV12 texture, hr %#lx, skipping test.\n", hr);
9536 ID3D11Device_Release(device);
9537 return;
9540 /* Subresource index 1.
9541 * When WARP d3d11 device is used, this test leaves the device in a broken state, so it should
9542 * be kept last. */
9543 memset(&desc, 0, sizeof(desc));
9544 desc.Width = 64;
9545 desc.Height = 64;
9546 desc.ArraySize = 1;
9547 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
9548 desc.SampleDesc.Count = 1;
9549 desc.SampleDesc.Quality = 0;
9551 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
9552 ok(hr == S_OK, "Failed to create a texture, hr %#lx.\n", hr);
9554 hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown *)texture, 1, FALSE, &buffer);
9555 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
9557 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer, (void **)&_2d_buffer);
9558 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9560 /* Pitch reflects top level. */
9561 memset(buff, 0, sizeof(buff));
9562 *(DWORD *)buff = 0xff00ff00;
9563 update_d3d11_texture(texture, 1, buff, 64 * 4);
9565 hr = IMF2DBuffer_Lock2D(_2d_buffer, &data, &pitch);
9566 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9567 ok(pitch == desc.Width * 4, "Unexpected pitch %ld.\n", pitch);
9568 ok(*(DWORD *)data == 0xff00ff00, "Unexpected color %#lx.\n", *(DWORD *)data);
9570 hr = IMF2DBuffer_Unlock2D(_2d_buffer);
9571 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9573 IMF2DBuffer_Release(_2d_buffer);
9574 IMFMediaBuffer_Release(buffer);
9575 ID3D11Texture2D_Release(texture);
9577 ID3D11Device_Release(device);
9580 static void test_d3d12_surface_buffer(void)
9582 IMFDXGIBuffer *dxgi_buffer;
9583 D3D12_HEAP_PROPERTIES heap_props;
9584 D3D12_RESOURCE_DESC desc;
9585 ID3D12Resource *resource;
9586 IMFMediaBuffer *buffer;
9587 unsigned int refcount;
9588 ID3D12Device *device;
9589 IUnknown *obj;
9590 HRESULT hr;
9592 /* d3d12 */
9593 if (!(device = create_d3d12_device()))
9595 skip("Failed to create a D3D12 device, skipping tests.\n");
9596 return;
9599 memset(&heap_props, 0, sizeof(heap_props));
9600 heap_props.Type = D3D12_HEAP_TYPE_DEFAULT;
9602 memset(&desc, 0, sizeof(desc));
9603 desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
9604 desc.Alignment = 0;
9605 desc.Width = 32;
9606 desc.Height = 32;
9607 desc.DepthOrArraySize = 1;
9608 desc.MipLevels = 1;
9609 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
9610 desc.SampleDesc.Count = 1;
9611 desc.SampleDesc.Quality = 0;
9612 desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
9613 desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
9615 hr = ID3D12Device_CreateCommittedResource(device, &heap_props, D3D12_HEAP_FLAG_NONE,
9616 &desc, D3D12_RESOURCE_STATE_RENDER_TARGET, NULL, &IID_ID3D12Resource, (void **)&resource);
9617 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9619 hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D12Resource, (IUnknown *)resource, 0, FALSE, &buffer);
9620 if (hr == E_INVALIDARG)
9622 todo_wine
9623 win_skip("D3D12 resource buffers are not supported.\n");
9624 goto notsupported;
9626 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
9628 if (SUCCEEDED(hr))
9630 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
9631 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
9632 check_interface(buffer, &IID_IMFDXGIBuffer, TRUE);
9633 check_interface(buffer, &IID_IMFGetService, FALSE);
9635 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
9636 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
9638 hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D12Resource, (void **)&obj);
9639 ok(hr == S_OK, "Failed to get resource, hr %#lx.\n", hr);
9640 ok(obj == (IUnknown *)resource, "Unexpected resource pointer.\n");
9641 IUnknown_Release(obj);
9643 IMFDXGIBuffer_Release(dxgi_buffer);
9644 IMFMediaBuffer_Release(buffer);
9647 notsupported:
9648 ID3D12Resource_Release(resource);
9649 refcount = ID3D12Device_Release(device);
9650 ok(!refcount, "Unexpected device refcount %u.\n", refcount);
9653 static void test_sample_allocator_sysmem(void)
9655 IMFVideoSampleAllocatorNotify test_notify = { &test_notify_callback_vtbl };
9656 IMFMediaType *media_type, *video_type, *video_type2;
9657 IMFVideoSampleAllocatorCallback *allocator_cb;
9658 IMFVideoSampleAllocatorEx *allocatorex;
9659 IMFVideoSampleAllocator *allocator;
9660 IMFSample *sample, *sample2;
9661 IMFAttributes *attributes;
9662 IMFMediaBuffer *buffer;
9663 LONG refcount, count;
9664 DWORD buffer_count;
9665 IUnknown *unk;
9666 HRESULT hr;
9668 if (!pMFCreateVideoSampleAllocatorEx)
9669 return;
9671 hr = pMFCreateVideoSampleAllocatorEx(&IID_IUnknown, (void **)&unk);
9672 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9674 check_interface(unk, &IID_IMFVideoSampleAllocator, TRUE);
9675 check_interface(unk, &IID_IMFVideoSampleAllocatorEx, TRUE);
9676 check_interface(unk, &IID_IMFVideoSampleAllocatorCallback, TRUE);
9678 IUnknown_Release(unk);
9680 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator, (void **)&allocator);
9681 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9683 hr = IMFVideoSampleAllocator_QueryInterface(allocator, &IID_IMFVideoSampleAllocatorCallback, (void **)&allocator_cb);
9684 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9686 hr = IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb, NULL);
9687 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9689 hr = IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb, &test_notify);
9690 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9692 hr = IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb, NULL);
9693 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9695 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, NULL);
9696 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
9698 count = 10;
9699 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
9700 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9701 ok(!count, "Unexpected count %ld.\n", count);
9703 hr = IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator);
9704 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9706 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
9707 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
9709 hr = IMFVideoSampleAllocator_SetDirectXManager(allocator, NULL);
9710 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9712 hr = MFCreateMediaType(&media_type);
9713 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9715 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, media_type);
9716 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
9718 video_type = create_video_type(&MFVideoFormat_RGB32);
9719 video_type2 = create_video_type(&MFVideoFormat_RGB32);
9721 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, video_type);
9722 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
9724 /* Frame size is required. */
9725 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 320 << 32 | 240);
9726 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9728 hr = IMFMediaType_SetUINT64(video_type2, &MF_MT_FRAME_SIZE, (UINT64) 320 << 32 | 240);
9729 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9731 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 0, video_type);
9732 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
9734 EXPECT_REF(video_type, 1);
9735 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type);
9736 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9737 EXPECT_REF(video_type, 2);
9739 hr = IMFMediaType_SetUINT64(video_type2, &IID_IUnknown, (UINT64) 320 << 32 | 240);
9740 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9742 /* Setting identical type does not replace it. */
9743 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type2);
9744 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9745 EXPECT_REF(video_type, 2);
9746 EXPECT_REF(video_type2, 1);
9748 hr = IMFMediaType_SetUINT64(video_type2, &MF_MT_FRAME_SIZE, (UINT64) 64 << 32 | 64);
9749 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9751 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type2);
9752 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9753 EXPECT_REF(video_type2, 2);
9754 EXPECT_REF(video_type, 1);
9756 /* Modify referenced type. */
9757 hr = IMFMediaType_SetUINT64(video_type2, &MF_MT_FRAME_SIZE, (UINT64) 320 << 32 | 64);
9758 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9760 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type);
9761 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9762 EXPECT_REF(video_type, 2);
9763 EXPECT_REF(video_type2, 1);
9765 count = 0;
9766 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
9767 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9768 ok(count == 1, "Unexpected count %ld.\n", count);
9770 sample = NULL;
9771 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
9772 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9773 refcount = get_refcount(sample);
9775 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
9776 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9777 ok(!count, "Unexpected count %ld.\n", count);
9779 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample2);
9780 ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#lx.\n", hr);
9782 /* Reinitialize with active sample. */
9783 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, video_type);
9784 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9785 ok(refcount == get_refcount(sample), "Unexpected refcount %lu.\n", get_refcount(sample));
9786 EXPECT_REF(video_type, 2);
9788 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
9789 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9790 todo_wine
9791 ok(!count, "Unexpected count %ld.\n", count);
9793 check_interface(sample, &IID_IMFTrackedSample, TRUE);
9794 check_interface(sample, &IID_IMFDesiredSample, FALSE);
9796 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
9797 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9799 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
9800 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
9801 check_interface(buffer, &IID_IMFGetService, TRUE);
9802 check_interface(buffer, &IID_IMFDXGIBuffer, FALSE);
9804 IMFMediaBuffer_Release(buffer);
9806 hr = IMFSample_GetBufferCount(sample, &buffer_count);
9807 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9808 ok(buffer_count == 1, "Unexpected buffer count %lu.\n", buffer_count);
9810 IMFSample_Release(sample);
9812 hr = IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator);
9813 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9814 todo_wine
9815 EXPECT_REF(video_type, 2);
9817 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
9818 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9819 ok(!count, "Unexpected count %ld.\n", count);
9821 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
9822 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
9824 IMFVideoSampleAllocatorCallback_Release(allocator_cb);
9825 IMFVideoSampleAllocator_Release(allocator);
9827 /* IMFVideoSampleAllocatorEx */
9828 hr = MFCreateAttributes(&attributes, 0);
9829 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9831 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx, (void **)&allocatorex);
9832 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9834 hr = IMFVideoSampleAllocatorEx_QueryInterface(allocatorex, &IID_IMFVideoSampleAllocatorCallback, (void **)&allocator_cb);
9835 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9837 hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex, 1, 0, NULL, video_type);
9838 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
9840 hr = IMFAttributes_SetUINT32(attributes, &MF_SA_BUFFERS_PER_SAMPLE, 2);
9841 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9843 hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample);
9844 ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#lx.\n", hr);
9846 EXPECT_REF(attributes, 1);
9847 hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex, 0, 0, attributes, video_type);
9848 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9849 EXPECT_REF(attributes, 2);
9851 count = 0;
9852 hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
9853 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9854 ok(count == 1, "Unexpected count %ld.\n", count);
9856 hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample);
9857 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9859 hr = IMFSample_GetBufferCount(sample, &buffer_count);
9860 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9861 ok(buffer_count == 2, "Unexpected buffer count %lu.\n", buffer_count);
9863 hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample2);
9864 ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#lx.\n", hr);
9866 /* Reinitialize with already allocated samples. */
9867 hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex, 0, 0, NULL, video_type);
9868 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9869 EXPECT_REF(attributes, 1);
9871 hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample2);
9872 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9873 IMFSample_Release(sample2);
9875 IMFSample_Release(sample);
9877 IMFVideoSampleAllocatorCallback_Release(allocator_cb);
9878 IMFVideoSampleAllocatorEx_Release(allocatorex);
9879 IMFAttributes_Release(attributes);
9882 static void test_sample_allocator_d3d9(void)
9884 IDirect3DDeviceManager9 *d3d9_manager;
9885 IMFVideoSampleAllocator *allocator;
9886 IDirect3DDevice9 *d3d9_device;
9887 IMFMediaType *video_type;
9888 IMFMediaBuffer *buffer;
9889 unsigned int token;
9890 IMFSample *sample;
9891 IDirect3D9 *d3d9;
9892 HWND window;
9893 HRESULT hr;
9895 if (!pMFCreateVideoSampleAllocatorEx)
9896 return;
9898 d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
9899 if (!d3d9)
9901 skip("Failed to create a D3D9 object, skipping tests.\n");
9902 return;
9904 window = create_window();
9905 if (!(d3d9_device = create_d3d9_device(d3d9, window)))
9907 skip("Failed to create a D3D9 device, skipping tests.\n");
9908 goto done;
9911 hr = DXVA2CreateDirect3DDeviceManager9(&token, &d3d9_manager);
9912 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9914 hr = IDirect3DDeviceManager9_ResetDevice(d3d9_manager, d3d9_device, token);
9915 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9917 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator, (void **)&allocator);
9918 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9920 hr = IMFVideoSampleAllocator_SetDirectXManager(allocator, (IUnknown *)d3d9_manager);
9921 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9923 video_type = create_video_type(&MFVideoFormat_RGB32);
9925 /* Frame size is required. */
9926 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 64 << 32 | 64);
9927 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9929 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type);
9930 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9932 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
9933 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9935 check_interface(sample, &IID_IMFTrackedSample, TRUE);
9936 check_interface(sample, &IID_IMFDesiredSample, FALSE);
9938 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
9939 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
9941 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
9942 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
9943 check_interface(buffer, &IID_IMFGetService, TRUE);
9944 check_interface(buffer, &IID_IMFDXGIBuffer, FALSE);
9946 IMFSample_Release(sample);
9947 IMFMediaBuffer_Release(buffer);
9949 IMFVideoSampleAllocator_Release(allocator);
9950 IMFMediaType_Release(video_type);
9951 IDirect3DDeviceManager9_Release(d3d9_manager);
9952 IDirect3DDevice9_Release(d3d9_device);
9954 done:
9955 IDirect3D9_Release(d3d9);
9956 DestroyWindow(window);
9959 static void test_sample_allocator_d3d11(void)
9961 IMFMediaType *video_type;
9962 IMFVideoSampleAllocatorEx *allocatorex;
9963 IMFVideoSampleAllocator *allocator;
9964 unsigned int i, token;
9965 IMFDXGIDeviceManager *manager;
9966 IMFSample *sample;
9967 IMFDXGIBuffer *dxgi_buffer;
9968 IMFAttributes *attributes;
9969 D3D11_TEXTURE2D_DESC desc;
9970 ID3D11Texture2D *texture;
9971 IMFMediaBuffer *buffer;
9972 ID3D11Device *device;
9973 HRESULT hr;
9974 BYTE *data;
9975 static const unsigned int usage[] =
9977 D3D11_USAGE_DEFAULT,
9978 D3D11_USAGE_IMMUTABLE,
9979 D3D11_USAGE_DYNAMIC,
9980 D3D11_USAGE_STAGING,
9981 D3D11_USAGE_STAGING + 1,
9983 static const unsigned int sharing[] =
9985 D3D11_RESOURCE_MISC_SHARED | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
9986 D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
9987 D3D11_RESOURCE_MISC_SHARED,
9990 if (!pMFCreateVideoSampleAllocatorEx)
9991 return;
9993 if (!(device = create_d3d11_device()))
9995 skip("Failed to create a D3D11 device, skipping tests.\n");
9996 return;
9999 hr = pMFCreateDXGIDeviceManager(&token, &manager);
10000 ok(hr == S_OK, "Failed to create device manager, hr %#lx.\n", hr);
10002 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)device, token);
10003 ok(hr == S_OK, "Failed to set a device, hr %#lx.\n", hr);
10005 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator, (void **)&allocator);
10006 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10008 EXPECT_REF(manager, 1);
10009 hr = IMFVideoSampleAllocator_SetDirectXManager(allocator, (IUnknown *)manager);
10010 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10011 EXPECT_REF(manager, 2);
10013 video_type = create_video_type(&MFVideoFormat_RGB32);
10014 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 64 << 32 | 64);
10015 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10017 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type);
10018 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10020 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
10021 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10023 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
10024 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10026 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
10027 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
10028 check_interface(buffer, &IID_IMFDXGIBuffer, TRUE);
10029 check_interface(buffer, &IID_IMFGetService, FALSE);
10031 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
10032 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
10034 hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D11Texture2D, (void **)&texture);
10035 ok(hr == S_OK, "Failed to get resource, hr %#lx.\n", hr);
10037 ID3D11Texture2D_GetDesc(texture, &desc);
10038 ok(desc.Width == 64, "Unexpected width %u.\n", desc.Width);
10039 ok(desc.Height == 64, "Unexpected height %u.\n", desc.Height);
10040 ok(desc.MipLevels == 1, "Unexpected miplevels %u.\n", desc.MipLevels);
10041 ok(desc.ArraySize == 1, "Unexpected array size %u.\n", desc.ArraySize);
10042 ok(desc.Format == DXGI_FORMAT_B8G8R8X8_UNORM, "Unexpected format %u.\n", desc.Format);
10043 ok(desc.SampleDesc.Count == 1, "Unexpected sample count %u.\n", desc.SampleDesc.Count);
10044 ok(!desc.SampleDesc.Quality, "Unexpected sample quality %u.\n", desc.SampleDesc.Quality);
10045 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Unexpected usage %u.\n", desc.Usage);
10046 ok(desc.BindFlags == (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET), "Unexpected bind flags %#x.\n",
10047 desc.BindFlags);
10048 ok(!desc.CPUAccessFlags, "Unexpected CPU access flags %#x.\n", desc.CPUAccessFlags);
10049 ok(!desc.MiscFlags, "Unexpected misc flags %#x.\n", desc.MiscFlags);
10051 ID3D11Texture2D_Release(texture);
10052 IMFDXGIBuffer_Release(dxgi_buffer);
10054 hr = IMFMediaBuffer_Lock(buffer, &data, NULL, NULL);
10055 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10057 hr = IMFMediaBuffer_Unlock(buffer);
10058 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10060 IMFMediaBuffer_Release(buffer);
10061 IMFSample_Release(sample);
10063 IMFVideoSampleAllocator_Release(allocator);
10065 /* MF_SA_D3D11_USAGE */
10066 hr = MFCreateAttributes(&attributes, 1);
10067 ok(hr == S_OK, "Failed to create attributes, hr %#lx.\n", hr);
10069 for (i = 0; i < ARRAY_SIZE(usage); ++i)
10071 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx, (void **)&allocatorex);
10072 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10074 hr = IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex, (IUnknown *)manager);
10075 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10077 hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_USAGE, usage[i]);
10078 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
10080 hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex, 0, 0, attributes, video_type);
10081 if (usage[i] == D3D11_USAGE_IMMUTABLE || usage[i] > D3D11_USAGE_STAGING)
10083 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10084 IMFVideoSampleAllocatorEx_Release(allocatorex);
10085 continue;
10087 ok(hr == S_OK, "%u: Unexpected hr %#lx.\n", usage[i], hr);
10089 hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_USAGE, D3D11_USAGE_DEFAULT);
10090 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
10092 hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample);
10093 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10095 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
10096 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10098 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
10099 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
10101 hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D11Texture2D, (void **)&texture);
10102 ok(hr == S_OK, "Failed to get resource, hr %#lx.\n", hr);
10104 ID3D11Texture2D_GetDesc(texture, &desc);
10105 ok(desc.Usage == usage[i], "Unexpected usage %u.\n", desc.Usage);
10106 if (usage[i] == D3D11_USAGE_DEFAULT)
10108 ok(desc.BindFlags == (D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET), "Unexpected bind flags %#x.\n",
10109 desc.BindFlags);
10110 ok(!desc.CPUAccessFlags, "Unexpected CPU access flags %#x.\n", desc.CPUAccessFlags);
10112 else if (usage[i] == D3D11_USAGE_DYNAMIC)
10114 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Unexpected bind flags %#x.\n", desc.BindFlags);
10115 ok(desc.CPUAccessFlags == D3D11_CPU_ACCESS_WRITE, "Unexpected CPU access flags %#x.\n", desc.CPUAccessFlags);
10117 else if (usage[i] == D3D11_USAGE_STAGING)
10119 ok(!desc.BindFlags, "Unexpected bind flags %#x.\n", desc.BindFlags);
10120 ok(desc.CPUAccessFlags == (D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ), "Unexpected CPU access flags %#x.\n",
10121 desc.CPUAccessFlags);
10123 ok(!desc.MiscFlags, "Unexpected misc flags %#x.\n", desc.MiscFlags);
10125 ID3D11Texture2D_Release(texture);
10126 IMFDXGIBuffer_Release(dxgi_buffer);
10127 IMFMediaBuffer_Release(buffer);
10129 IMFSample_Release(sample);
10131 IMFVideoSampleAllocatorEx_Release(allocatorex);
10134 /* MF_SA_D3D11_SHARED, MF_SA_D3D11_SHARED_WITHOUT_MUTEX */
10135 for (i = 0; i < ARRAY_SIZE(sharing); ++i)
10137 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx, (void **)&allocatorex);
10138 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10140 hr = IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex, (IUnknown *)manager);
10141 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10143 hr = IMFAttributes_DeleteAllItems(attributes);
10144 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10146 hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_USAGE, D3D11_USAGE_DEFAULT);
10147 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
10149 if (sharing[i] & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)
10151 hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_SHARED, TRUE);
10152 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
10155 if (sharing[i] & D3D11_RESOURCE_MISC_SHARED)
10157 hr = IMFAttributes_SetUINT32(attributes, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX, TRUE);
10158 ok(hr == S_OK, "Failed to set attribute, hr %#lx.\n", hr);
10161 hr = IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex, 0, 0, attributes, video_type);
10162 if (sharing[i] == (D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED))
10164 todo_wine
10165 ok(hr == E_INVALIDARG, "%u: Unexpected hr %#lx.\n", i, hr);
10166 IMFVideoSampleAllocatorEx_Release(allocatorex);
10167 continue;
10169 ok(hr == S_OK, "%u: Unexpected hr %#lx.\n", i, hr);
10171 hr = IMFVideoSampleAllocatorEx_AllocateSample(allocatorex, &sample);
10172 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10174 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
10175 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10177 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
10178 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
10180 hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D11Texture2D, (void **)&texture);
10181 ok(hr == S_OK, "Failed to get resource, hr %#lx.\n", hr);
10183 ID3D11Texture2D_GetDesc(texture, &desc);
10184 ok(desc.MiscFlags == sharing[i], "%u: unexpected misc flags %#x.\n", i, desc.MiscFlags);
10186 ID3D11Texture2D_Release(texture);
10187 IMFDXGIBuffer_Release(dxgi_buffer);
10188 IMFMediaBuffer_Release(buffer);
10190 IMFSample_Release(sample);
10192 IMFVideoSampleAllocatorEx_Release(allocatorex);
10195 IMFAttributes_Release(attributes);
10197 IMFDXGIDeviceManager_Release(manager);
10198 ID3D11Device_Release(device);
10201 static void test_sample_allocator_d3d12(void)
10203 IMFVideoSampleAllocator *allocator = NULL;
10204 D3D12_HEAP_PROPERTIES heap_props;
10205 IMFDXGIDeviceManager *manager;
10206 D3D12_HEAP_FLAGS heap_flags;
10207 IMFDXGIBuffer *dxgi_buffer;
10208 IMFMediaType *video_type;
10209 ID3D12Resource *resource;
10210 D3D12_RESOURCE_DESC desc;
10211 IMFMediaBuffer *buffer;
10212 ID3D12Device *device;
10213 unsigned int token;
10214 IMFSample *sample;
10215 HRESULT hr;
10217 if (!(device = create_d3d12_device()))
10219 skip("Failed to create a D3D12 device, skipping tests.\n");
10220 return;
10223 hr = pMFCreateDXGIDeviceManager(&token, &manager);
10224 ok(hr == S_OK, "Failed to create device manager, hr %#lx.\n", hr);
10226 hr = IMFDXGIDeviceManager_ResetDevice(manager, (IUnknown *)device, token);
10227 if (FAILED(hr))
10229 win_skip("Device manager does not support D3D12 devices.\n");
10230 goto done;
10232 ok(hr == S_OK, "Failed to set a device, hr %#lx.\n", hr);
10234 hr = pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator, (void **)&allocator);
10235 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10237 EXPECT_REF(manager, 1);
10238 hr = IMFVideoSampleAllocator_SetDirectXManager(allocator, (IUnknown *)manager);
10239 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10240 EXPECT_REF(manager, 2);
10242 video_type = create_video_type(&MFVideoFormat_RGB32);
10243 hr = IMFMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 64 << 32 | 64);
10244 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10245 hr = IMFMediaType_SetUINT32(video_type, &MF_MT_D3D_RESOURCE_VERSION, MF_D3D12_RESOURCE);
10246 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10248 hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 1, video_type);
10249 todo_wine
10250 ok(hr == S_OK || broken(hr == MF_E_UNEXPECTED) /* Some Win10 versions fail. */, "Unexpected hr %#lx.\n", hr);
10251 if (FAILED(hr)) goto done;
10253 hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
10254 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10256 hr = IMFSample_GetBufferByIndex(sample, 0, &buffer);
10257 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10259 check_interface(buffer, &IID_IMF2DBuffer, TRUE);
10260 check_interface(buffer, &IID_IMF2DBuffer2, TRUE);
10261 check_interface(buffer, &IID_IMFDXGIBuffer, TRUE);
10262 check_interface(buffer, &IID_IMFGetService, FALSE);
10264 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer);
10265 ok(hr == S_OK, "Failed to get interface, hr %#lx.\n", hr);
10267 hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_ID3D12Resource, (void **)&resource);
10268 ok(hr == S_OK, "Failed to get resource, hr %#lx.\n", hr);
10270 resource->lpVtbl->GetDesc(resource, &desc);
10271 ok(desc.Width == 64, "Unexpected width.\n");
10272 ok(desc.Height == 64, "Unexpected height.\n");
10273 ok(desc.DepthOrArraySize == 1, "Unexpected array size %u.\n", desc.DepthOrArraySize);
10274 ok(desc.MipLevels == 1, "Unexpected miplevels %u.\n", desc.MipLevels);
10275 ok(desc.Format == DXGI_FORMAT_B8G8R8X8_UNORM, "Unexpected format %u.\n", desc.Format);
10276 ok(desc.SampleDesc.Count == 1, "Unexpected sample count %u.\n", desc.SampleDesc.Count);
10277 ok(!desc.SampleDesc.Quality, "Unexpected sample quality %u.\n", desc.SampleDesc.Quality);
10278 ok(!desc.Layout, "Unexpected layout %u.\n", desc.Layout);
10279 ok(!desc.Flags, "Unexpected flags %#x.\n", desc.Flags);
10281 hr = ID3D12Resource_GetHeapProperties(resource, &heap_props, &heap_flags);
10282 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10283 ok(heap_props.Type == D3D12_HEAP_TYPE_DEFAULT, "Unexpected heap type %u.\n", heap_props.Type);
10284 ok(heap_props.CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_UNKNOWN, "Unexpected page property %u.\n",
10285 heap_props.CPUPageProperty);
10286 ok(!heap_props.MemoryPoolPreference, "Unexpected pool preference %u.\n", heap_props.MemoryPoolPreference);
10287 ok(heap_flags == D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES, "Unexpected heap flags %#x.\n", heap_flags);
10289 ID3D12Resource_Release(resource);
10290 IMFDXGIBuffer_Release(dxgi_buffer);
10291 IMFMediaBuffer_Release(buffer);
10292 IMFSample_Release(sample);
10294 done:
10295 if (allocator)
10296 IMFVideoSampleAllocator_Release(allocator);
10297 IMFDXGIDeviceManager_Release(manager);
10298 ID3D12Device_Release(device);
10301 static void test_MFLockSharedWorkQueue(void)
10303 DWORD taskid, queue, queue2;
10304 HRESULT hr;
10306 if (!pMFLockSharedWorkQueue)
10308 win_skip("MFLockSharedWorkQueue() is not available.\n");
10309 return;
10312 hr = MFStartup(MF_VERSION, MFSTARTUP_FULL);
10313 ok(hr == S_OK, "Failed to start up, hr %#lx.\n", hr);
10315 hr = pMFLockSharedWorkQueue(NULL, 0, &taskid, &queue);
10316 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
10318 hr = pMFLockSharedWorkQueue(NULL, 0, NULL, &queue);
10319 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
10321 taskid = 0;
10322 hr = pMFLockSharedWorkQueue(L"", 0, &taskid, &queue);
10323 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10325 queue = 0;
10326 hr = pMFLockSharedWorkQueue(L"", 0, NULL, &queue);
10327 ok(queue & MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK, "Unexpected queue id.\n");
10329 queue2 = 0;
10330 hr = pMFLockSharedWorkQueue(L"", 0, NULL, &queue2);
10331 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10332 ok(queue == queue2, "Unexpected queue %#lx.\n", queue2);
10334 hr = MFUnlockWorkQueue(queue2);
10335 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10337 hr = MFUnlockWorkQueue(queue);
10338 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10340 hr = MFShutdown();
10341 ok(hr == S_OK, "Failed to shut down, hr %#lx.\n", hr);
10344 static void test_MFllMulDiv(void)
10346 /* (a * b + d) / c */
10347 static const struct muldivtest
10349 LONGLONG a;
10350 LONGLONG b;
10351 LONGLONG c;
10352 LONGLONG d;
10353 LONGLONG result;
10355 muldivtests[] =
10357 { 0, 0, 0, 0, _I64_MAX },
10358 { 1000000, 1000000, 2, 0, 500000000000 },
10359 { _I64_MAX, 3, _I64_MAX, 0, 3 },
10360 { _I64_MAX, 3, _I64_MAX, 1, 3 },
10361 { -10000, 3, 100, 0, -300 },
10362 { 2, 0, 3, 5, 1 },
10363 { 2, 1, 1, -3, -1 },
10364 /* a * b product does not fit in uint64_t */
10365 { _I64_MAX, 4, 8, 0, _I64_MAX / 2 },
10366 /* Large a * b product, large denominator */
10367 { _I64_MAX, 4, 0x100000000, 0, 0x1ffffffff },
10369 unsigned int i;
10371 for (i = 0; i < ARRAY_SIZE(muldivtests); ++i)
10373 LONGLONG result;
10375 result = MFllMulDiv(muldivtests[i].a, muldivtests[i].b, muldivtests[i].c, muldivtests[i].d);
10376 ok(result == muldivtests[i].result, "%u: unexpected result %s, expected %s.\n", i,
10377 wine_dbgstr_longlong(result), wine_dbgstr_longlong(muldivtests[i].result));
10381 static void test_shared_dxgi_device_manager(void)
10383 IMFDXGIDeviceManager *manager;
10384 HRESULT hr;
10385 UINT token;
10387 if (!pMFLockDXGIDeviceManager)
10389 win_skip("Shared DXGI device manager is not supported.\n");
10390 return;
10393 hr = pMFUnlockDXGIDeviceManager();
10394 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10396 manager = NULL;
10397 hr = pMFLockDXGIDeviceManager(NULL, &manager);
10398 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10399 ok(!!manager, "Unexpected instance.\n");
10401 hr = pMFLockDXGIDeviceManager(&token, &manager);
10402 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10404 EXPECT_REF(manager, 3);
10406 hr = pMFUnlockDXGIDeviceManager();
10407 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10409 EXPECT_REF(manager, 2);
10411 hr = pMFUnlockDXGIDeviceManager();
10412 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10415 static void check_video_format(const MFVIDEOFORMAT *format, unsigned int width, unsigned int height,
10416 DWORD d3dformat)
10418 unsigned int transfer_function;
10419 GUID guid;
10421 if (!d3dformat) d3dformat = D3DFMT_X8R8G8B8;
10423 switch (d3dformat)
10425 case D3DFMT_X8R8G8B8:
10426 case D3DFMT_R8G8B8:
10427 case D3DFMT_A8R8G8B8:
10428 case D3DFMT_R5G6B5:
10429 case D3DFMT_X1R5G5B5:
10430 case D3DFMT_A2B10G10R10:
10431 case D3DFMT_A2R10G10B10:
10432 case D3DFMT_P8:
10433 transfer_function = MFVideoTransFunc_sRGB;
10434 break;
10435 default:
10436 transfer_function = MFVideoTransFunc_10;
10439 memcpy(&guid, &MFVideoFormat_Base, sizeof(guid));
10440 guid.Data1 = d3dformat;
10442 ok(format->dwSize == sizeof(*format), "Unexpected format size.\n");
10443 ok(format->videoInfo.dwWidth == width, "Unexpected width %lu.\n", format->videoInfo.dwWidth);
10444 ok(format->videoInfo.dwHeight == height, "Unexpected height %lu.\n", format->videoInfo.dwHeight);
10445 ok(format->videoInfo.PixelAspectRatio.Numerator == 1 &&
10446 format->videoInfo.PixelAspectRatio.Denominator == 1, "Unexpected PAR.\n");
10447 ok(format->videoInfo.SourceChromaSubsampling == MFVideoChromaSubsampling_Unknown, "Unexpected chroma subsampling.\n");
10448 ok(format->videoInfo.InterlaceMode == MFVideoInterlace_Progressive, "Unexpected interlace mode %u.\n",
10449 format->videoInfo.InterlaceMode);
10450 ok(format->videoInfo.TransferFunction == transfer_function, "Unexpected transfer function %u.\n",
10451 format->videoInfo.TransferFunction);
10452 ok(format->videoInfo.ColorPrimaries == MFVideoPrimaries_BT709, "Unexpected color primaries %u.\n",
10453 format->videoInfo.ColorPrimaries);
10454 ok(format->videoInfo.TransferMatrix == MFVideoTransferMatrix_Unknown, "Unexpected transfer matrix.\n");
10455 ok(format->videoInfo.SourceLighting == MFVideoLighting_office, "Unexpected source lighting %u.\n",
10456 format->videoInfo.SourceLighting);
10457 ok(format->videoInfo.FramesPerSecond.Numerator == 60 &&
10458 format->videoInfo.FramesPerSecond.Denominator == 1, "Unexpected frame rate %lu/%lu.\n",
10459 format->videoInfo.FramesPerSecond.Numerator, format->videoInfo.FramesPerSecond.Denominator);
10460 ok(format->videoInfo.NominalRange == MFNominalRange_Normal, "Unexpected nominal range %u.\n",
10461 format->videoInfo.NominalRange);
10462 ok(format->videoInfo.GeometricAperture.Area.cx == width && format->videoInfo.GeometricAperture.Area.cy == height,
10463 "Unexpected geometric aperture.\n");
10464 ok(!memcmp(&format->videoInfo.GeometricAperture, &format->videoInfo.MinimumDisplayAperture, sizeof(MFVideoArea)),
10465 "Unexpected minimum display aperture.\n");
10466 ok(format->videoInfo.PanScanAperture.Area.cx == 0 && format->videoInfo.PanScanAperture.Area.cy == 0,
10467 "Unexpected geometric aperture.\n");
10468 ok(format->videoInfo.VideoFlags == 0, "Unexpected video flags.\n");
10469 ok(IsEqualGUID(&format->guidFormat, &guid), "Unexpected format guid %s.\n", wine_dbgstr_guid(&format->guidFormat));
10470 ok(format->compressedInfo.AvgBitrate == 0, "Unexpected bitrate.\n");
10471 ok(format->compressedInfo.AvgBitErrorRate == 0, "Unexpected error bitrate.\n");
10472 ok(format->compressedInfo.MaxKeyFrameSpacing == 0, "Unexpected MaxKeyFrameSpacing.\n");
10473 ok(format->surfaceInfo.Format == d3dformat, "Unexpected format %lu.\n", format->surfaceInfo.Format);
10474 ok(format->surfaceInfo.PaletteEntries == 0, "Unexpected palette size %lu.\n", format->surfaceInfo.PaletteEntries);
10477 static void test_MFInitVideoFormat_RGB(void)
10479 static const DWORD formats[] =
10481 0, /* same D3DFMT_X8R8G8B8 */
10482 D3DFMT_X8R8G8B8,
10483 D3DFMT_R8G8B8,
10484 D3DFMT_A8R8G8B8,
10485 D3DFMT_R5G6B5,
10486 D3DFMT_X1R5G5B5,
10487 D3DFMT_A2B10G10R10,
10488 D3DFMT_A2R10G10B10,
10489 D3DFMT_P8,
10490 D3DFMT_L8,
10491 D3DFMT_YUY2,
10492 D3DFMT_DXT1,
10493 D3DFMT_D16,
10494 D3DFMT_L16,
10495 D3DFMT_A16B16G16R16F,
10497 MFVIDEOFORMAT format;
10498 unsigned int i;
10499 HRESULT hr;
10501 if (!pMFInitVideoFormat_RGB)
10503 win_skip("MFInitVideoFormat_RGB is not available.\n");
10504 return;
10507 hr = pMFInitVideoFormat_RGB(NULL, 64, 32, 0);
10508 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10510 for (i = 0; i < ARRAY_SIZE(formats); ++i)
10512 memset(&format, 0, sizeof(format));
10513 hr = pMFInitVideoFormat_RGB(&format, 64, 32, formats[i]);
10514 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10515 if (SUCCEEDED(hr))
10516 check_video_format(&format, 64, 32, formats[i]);
10520 static void test_MFCreateVideoMediaTypeFromVideoInfoHeader(void)
10522 IMFVideoMediaType *media_type;
10523 KS_VIDEOINFOHEADER vih;
10524 UINT32 value32;
10525 UINT64 value64;
10526 HRESULT hr;
10527 GUID guid;
10529 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(NULL, 0, 0, 0, MFVideoInterlace_Unknown, 0, NULL, &media_type);
10530 todo_wine
10531 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10533 memset(&vih, 0, sizeof(vih));
10534 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(&vih, 0, 0, 0, MFVideoInterlace_Unknown, 0, NULL, &media_type);
10535 todo_wine
10536 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10537 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(&vih, sizeof(vih), 0, 0, MFVideoInterlace_Unknown, 0, NULL, &media_type);
10538 todo_wine
10539 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10540 vih.bmiHeader.biSize = sizeof(vih.bmiHeader);
10541 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(&vih, sizeof(vih), 0, 0, MFVideoInterlace_Unknown, 0, NULL, &media_type);
10542 todo_wine
10543 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10545 vih.bmiHeader.biSize = sizeof(vih.bmiHeader);
10546 vih.bmiHeader.biPlanes = 1;
10547 vih.bmiHeader.biWidth = 16;
10548 vih.bmiHeader.biHeight = 32;
10549 vih.bmiHeader.biBitCount = 32;
10551 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(&vih, sizeof(vih), 3, 2, MFVideoInterlace_Progressive,
10552 MFVideoFlag_AnalogProtected, &GUID_NULL, &media_type);
10553 todo_wine
10554 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10555 if (FAILED(hr)) return;
10556 IMFVideoMediaType_Release(media_type);
10558 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(&vih, sizeof(vih), 3, 2, MFVideoInterlace_Progressive,
10559 MFVideoFlag_AnalogProtected, NULL, &media_type);
10560 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10562 hr = IMFVideoMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
10563 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10564 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
10565 hr = IMFVideoMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
10566 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10567 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
10568 hr = IMFVideoMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10569 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10570 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10571 hr = IMFVideoMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10572 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10573 ok(value64 == ((UINT64)3 << 32 | 2), "Unexpected value %#I64x.\n", value64);
10574 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_DRM_FLAGS, &value32);
10575 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10576 ok(value32 == MFVideoDRMFlag_AnalogProtected, "Unexpected value %#x.\n", value32);
10577 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
10578 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10579 ok(value32 == MFVideoInterlace_Progressive, "Unexpected value %#x.\n", value32);
10580 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
10581 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10582 ok(value32 == 2048, "Unexpected value %u.\n", value32);
10583 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10584 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10585 ok(value32 == -64, "Unexpected value %d.\n", value32);
10586 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
10587 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10588 ok(!!value32, "Unexpected value %#x.\n", value32);
10589 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
10590 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10591 ok(!!value32, "Unexpected value %#x.\n", value32);
10593 IMFVideoMediaType_Release(media_type);
10595 /* Negative height. */
10596 vih.bmiHeader.biHeight = -32;
10597 hr = MFCreateVideoMediaTypeFromVideoInfoHeader(&vih, sizeof(vih), 3, 2, MFVideoInterlace_Progressive,
10598 MFVideoFlag_AnalogProtected, NULL, &media_type);
10599 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10600 hr = IMFVideoMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10601 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10602 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10603 hr = IMFVideoMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10604 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10605 ok(value32 == 64, "Unexpected value %d.\n", value32);
10606 IMFVideoMediaType_Release(media_type);
10609 static void test_MFInitMediaTypeFromVideoInfoHeader(void)
10611 static const MFVideoArea expect_aperture = {.OffsetX = {.value = 1}, .OffsetY = {.value = 2}, .Area = {.cx = 3, .cy = 5}};
10612 static const RECT source = {1, 2, 4, 7}, target = {3, 2, 12, 9};
10613 IMFMediaType *media_type;
10614 MFVideoArea aperture;
10615 VIDEOINFOHEADER vih;
10616 UINT32 value32;
10617 UINT64 value64;
10618 HRESULT hr;
10619 GUID guid;
10621 hr = MFCreateMediaType(&media_type);
10622 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10624 memset(&vih, 0, sizeof(vih));
10625 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, 0, NULL);
10626 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10627 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
10628 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10630 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10631 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10632 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
10633 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10634 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
10635 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
10636 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10637 ok(IsEqualGUID(&guid, &GUID_NULL), "Unexpected guid %s.\n", debugstr_guid(&guid));
10638 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10639 todo_wine
10640 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10642 vih.bmiHeader.biWidth = 16;
10643 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10644 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10645 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10646 todo_wine
10647 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10648 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10649 todo_wine
10650 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10651 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
10652 todo_wine
10653 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10655 vih.bmiHeader.biHeight = -32;
10656 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10657 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10658 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10659 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10660 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10661 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10662 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10664 vih.bmiHeader.biHeight = 32;
10665 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10666 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10667 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10668 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10669 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10670 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10671 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10672 ok(value64 == ((UINT64)1 << 32 | 1), "Unexpected value %#I64x.\n", value64);
10673 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
10674 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10675 ok(value32 == MFVideoInterlace_Progressive, "Unexpected value %#x.\n", value32);
10676 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10677 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10678 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
10679 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10681 value32 = 0xdeadbeef;
10682 vih.bmiHeader.biSizeImage = 12345;
10683 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10684 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10685 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
10686 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10687 ok(value32 == 12345, "Unexpected value %#x.\n", value32);
10688 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value32);
10689 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10691 value32 = 0xdeadbeef;
10692 vih.dwBitRate = 678910;
10693 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10694 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10695 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value32);
10696 todo_wine
10697 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10698 todo_wine
10699 ok(value32 == 678910, "Unexpected value %#x.\n", value32);
10700 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value32);
10701 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10703 value32 = 0xdeadbeef;
10704 vih.dwBitErrorRate = 11121314;
10705 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10706 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10707 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value32);
10708 todo_wine
10709 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10710 todo_wine
10711 ok(value32 == 11121314, "Unexpected value %#x.\n", value32);
10712 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
10713 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10715 value64 = 0xdeadbeef;
10716 vih.AvgTimePerFrame = 1151617;
10717 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10718 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10719 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
10720 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10721 ok(value64 == ((UINT64)10000000 << 32 | 1151617), "Unexpected value %#I64x.\n", value64);
10723 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
10724 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10725 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
10726 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10728 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
10729 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10730 hr = IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
10731 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10732 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
10733 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10734 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &value32);
10735 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10737 /* only rcSource is considered, translated into both MF_MT_MINIMUM_DISPLAY_APERTURE and MF_MT_PAN_SCAN_APERTURE */
10738 value32 = 0xdeadbeef;
10739 vih.rcSource = source;
10740 vih.rcTarget = target;
10741 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &GUID_NULL);
10742 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10743 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10744 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10745 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10746 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
10747 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10748 ok(value32 == 12345, "Unexpected value %#x.\n", value32);
10749 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10750 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10752 value32 = 0xdeadbeef;
10753 memset(&aperture, 0xcd, sizeof(aperture));
10754 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
10755 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10756 ok(value32 == sizeof(aperture), "got %d.\n", value32);
10757 ok(!memcmp(&aperture, &expect_aperture, sizeof(aperture)), "unexpected aperture\n");
10759 value32 = 0xdeadbeef;
10760 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &value32);
10761 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10762 ok(value32 == 1, "got %d.\n", (UINT32)value32);
10764 value32 = 0xdeadbeef;
10765 memset(&aperture, 0xcd, sizeof(aperture));
10766 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
10767 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10768 ok(value32 == sizeof(aperture), "got %d.\n", value32);
10769 ok(!memcmp(&aperture, &expect_aperture, sizeof(aperture)), "unexpected aperture\n");
10771 hr = IMFMediaType_GetItem(media_type, &MF_MT_GEOMETRIC_APERTURE, NULL);
10772 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10775 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), &MFVideoFormat_NV12);
10776 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10777 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
10778 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10779 ok(value32 == 1, "Unexpected value %#x.\n", value32);
10780 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
10781 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10782 ok(value32 == 1, "Unexpected value %#x.\n", value32);
10785 /* biBitCount is used for implicit RGB format if GUID is NULL */
10786 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
10787 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10789 for (vih.bmiHeader.biBitCount = 1; vih.bmiHeader.biBitCount <= 32; vih.bmiHeader.biBitCount++)
10791 winetest_push_context("%u", vih.bmiHeader.biBitCount);
10793 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
10794 if (vih.bmiHeader.biBitCount != 1 && vih.bmiHeader.biBitCount != 4 && vih.bmiHeader.biBitCount != 8
10795 && vih.bmiHeader.biBitCount != 16 && vih.bmiHeader.biBitCount != 24 && vih.bmiHeader.biBitCount != 32)
10796 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10797 else
10799 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10801 memset(&guid, 0xcd, sizeof(guid));
10802 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
10803 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10804 if (vih.bmiHeader.biBitCount == 32)
10805 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
10806 else if (vih.bmiHeader.biBitCount == 24)
10807 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB24), "Unexpected guid %s.\n", debugstr_guid(&guid));
10808 else if (vih.bmiHeader.biBitCount == 16)
10809 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB555), "Unexpected guid %s.\n", debugstr_guid(&guid));
10810 else if (vih.bmiHeader.biBitCount == 8)
10811 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB8), "Unexpected guid %s.\n", debugstr_guid(&guid));
10812 else if (vih.bmiHeader.biBitCount == 4)
10813 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB4), "Unexpected guid %s.\n", debugstr_guid(&guid));
10814 else if (vih.bmiHeader.biBitCount == 1)
10815 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB1), "Unexpected guid %s.\n", debugstr_guid(&guid));
10817 value32 = 0xdeadbeef;
10818 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10819 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10820 if (vih.bmiHeader.biBitCount > 1)
10821 ok(value32 == 16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32);
10822 else
10823 todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);
10825 hr = IMFMediaType_GetItem(media_type, &MF_MT_PALETTE, NULL);
10826 if (vih.bmiHeader.biBitCount > 1)
10827 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10828 else
10829 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10831 value32 = 0xdeadbeef;
10832 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
10833 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10834 ok(value32 == 1, "Unexpected value %#x.\n", value32);
10835 value32 = 0xdeadbeef;
10836 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
10837 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10838 ok(value32 == 1, "Unexpected value %#x.\n", value32);
10840 value32 = 0xdeadbeef;
10841 vih.bmiHeader.biHeight = 32;
10842 hr = MFInitMediaTypeFromVideoInfoHeader(media_type, &vih, sizeof(vih), NULL);
10843 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10844 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10845 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10846 if (vih.bmiHeader.biBitCount > 1)
10847 ok(value32 == -16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32);
10848 else
10849 todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);
10851 vih.bmiHeader.biHeight = -32;
10854 winetest_pop_context();
10857 IMFMediaType_Release(media_type);
10860 static void test_MFInitMediaTypeFromVideoInfoHeader2(void)
10862 static const MFVideoArea expect_aperture = {.OffsetX = {.value = 1}, .OffsetY = {.value = 2}, .Area = {.cx = 3, .cy = 5}};
10863 static const RECT source = {1, 2, 4, 7}, target = {3, 2, 12, 9};
10864 IMFMediaType *media_type;
10865 VIDEOINFOHEADER2 vih;
10866 MFVideoArea aperture;
10867 UINT32 value32;
10868 UINT64 value64;
10869 HRESULT hr;
10870 GUID guid;
10872 hr = MFCreateMediaType(&media_type);
10873 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10875 memset(&vih, 0, sizeof(vih));
10876 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, 0, NULL);
10877 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10878 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), NULL);
10879 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
10881 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10882 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10883 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
10884 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10885 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
10886 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
10887 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10888 ok(IsEqualGUID(&guid, &GUID_NULL), "Unexpected guid %s.\n", debugstr_guid(&guid));
10889 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10890 todo_wine
10891 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10893 vih.bmiHeader.biWidth = 16;
10894 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10895 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10896 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10897 todo_wine
10898 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10899 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10900 todo_wine
10901 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10902 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
10903 todo_wine
10904 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10906 vih.bmiHeader.biHeight = -32;
10907 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10908 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10909 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10910 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10911 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10912 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10913 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10915 vih.bmiHeader.biHeight = 32;
10916 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10917 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10918 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
10919 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10920 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
10921 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
10922 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10923 ok(value32 == MFVideoInterlace_Progressive, "Unexpected value %#x.\n", value32);
10924 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
10925 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10926 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10927 todo_wine
10928 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10929 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
10930 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10932 value32 = 0xdeadbeef;
10933 vih.bmiHeader.biSizeImage = 12345;
10934 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10935 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10936 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
10937 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10938 ok(value32 == 12345, "Unexpected value %#x.\n", value32);
10939 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value32);
10940 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10942 value32 = 0xdeadbeef;
10943 vih.dwBitRate = 678910;
10944 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10945 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10946 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BITRATE, &value32);
10947 todo_wine
10948 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10949 todo_wine
10950 ok(value32 == 678910, "Unexpected value %#x.\n", value32);
10951 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value32);
10952 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10954 value32 = 0xdeadbeef;
10955 vih.dwBitErrorRate = 11121314;
10956 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10957 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10958 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_AVG_BIT_ERROR_RATE, &value32);
10959 todo_wine
10960 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10961 todo_wine
10962 ok(value32 == 11121314, "Unexpected value %#x.\n", value32);
10963 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
10964 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10966 value64 = 0xdeadbeef;
10967 vih.AvgTimePerFrame = 1151617;
10968 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10969 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10970 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_RATE, &value64);
10971 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10972 ok(value64 == ((UINT64)10000000 << 32 | 1151617), "Unexpected value %#I64x.\n", value64);
10974 value32 = 0xdeadbeef;
10975 vih.dwInterlaceFlags = AMINTERLACE_IsInterlaced | AMINTERLACE_DisplayModeBobOrWeave;
10976 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10977 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10978 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
10979 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10980 ok(value32 == MFVideoInterlace_MixedInterlaceOrProgressive, "Unexpected value %#x.\n", value32);
10982 vih.dwPictAspectRatioX = 123;
10983 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10984 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10985 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10986 todo_wine
10987 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
10989 value64 = 0xdeadbeef;
10990 vih.dwPictAspectRatioY = 456;
10991 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
10992 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10993 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
10994 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
10995 todo_wine
10996 ok(value64 == ((UINT64)41 << 32 | 76), "Unexpected value %#I64x.\n", value64);
10998 vih.dwControlFlags = AMCONTROL_COLORINFO_PRESENT;
10999 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
11000 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11001 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &value32);
11002 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11004 value32 = 0xdeadbeef;
11005 vih.dwControlFlags = AMCONTROL_COLORINFO_PRESENT | (MFVideoTransferMatrix_SMPTE240M << 15);
11006 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
11007 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11008 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_YUV_MATRIX, &value32);
11009 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11010 ok(value32 == MFVideoTransferMatrix_SMPTE240M, "Unexpected value %#x.\n", value32);
11011 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &value32);
11012 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11014 value32 = 0xdeadbeef;
11015 vih.dwControlFlags = AMCONTROL_COLORINFO_PRESENT | (MFVideoTransferMatrix_SMPTE240M << 15) | (MFNominalRange_Wide << 12);
11016 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
11017 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11018 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_VIDEO_NOMINAL_RANGE, &value32);
11019 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11020 ok(value32 == MFNominalRange_Wide, "Unexpected value %#x.\n", value32);
11022 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
11023 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11024 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
11025 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11027 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &MFVideoFormat_NV12);
11028 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11029 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
11030 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11031 ok(value32 == 1, "Unexpected value %#x.\n", value32);
11032 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
11033 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11034 ok(value32 == 1, "Unexpected value %#x.\n", value32);
11036 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
11037 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11038 hr = IMFMediaType_GetBlob(media_type, &MF_MT_GEOMETRIC_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
11039 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11040 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
11041 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11042 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &value32);
11043 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11045 /* only rcSource is considered, translated into both MF_MT_MINIMUM_DISPLAY_APERTURE and MF_MT_PAN_SCAN_APERTURE */
11046 value32 = 0xdeadbeef;
11047 vih.rcSource = source;
11048 vih.rcTarget = target;
11049 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), &GUID_NULL);
11050 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11051 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
11052 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11053 ok(value64 == ((UINT64)16 << 32 | 32), "Unexpected value %#I64x.\n", value64);
11054 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
11055 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11056 ok(value32 == 12345, "Unexpected value %#x.\n", value32);
11057 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11058 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11060 value32 = 0xdeadbeef;
11061 memset(&aperture, 0xcd, sizeof(aperture));
11062 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
11063 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11064 ok(value32 == sizeof(aperture), "got %d.\n", value32);
11065 ok(!memcmp(&aperture, &expect_aperture, sizeof(aperture)), "unexpected aperture\n");
11067 value32 = 0xdeadbeef;
11068 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_PAN_SCAN_ENABLED, &value32);
11069 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11070 ok(value32 == 1, "got %d.\n", (UINT32)value32);
11072 value32 = 0xdeadbeef;
11073 memset(&aperture, 0xcd, sizeof(aperture));
11074 hr = IMFMediaType_GetBlob(media_type, &MF_MT_PAN_SCAN_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
11075 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11076 ok(value32 == sizeof(aperture), "got %d.\n", value32);
11077 ok(!memcmp(&aperture, &expect_aperture, sizeof(aperture)), "unexpected aperture\n");
11079 hr = IMFMediaType_GetItem(media_type, &MF_MT_GEOMETRIC_APERTURE, NULL);
11080 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11083 /* biBitCount is used for implicit RGB format if GUID is NULL */
11084 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), NULL);
11085 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
11087 for (vih.bmiHeader.biBitCount = 1; vih.bmiHeader.biBitCount <= 32; vih.bmiHeader.biBitCount++)
11089 winetest_push_context("%u", vih.bmiHeader.biBitCount);
11091 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), NULL);
11092 if (vih.bmiHeader.biBitCount != 1 && vih.bmiHeader.biBitCount != 4 && vih.bmiHeader.biBitCount != 8
11093 && vih.bmiHeader.biBitCount != 16 && vih.bmiHeader.biBitCount != 24 && vih.bmiHeader.biBitCount != 32)
11094 ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr);
11095 else
11097 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11099 memset(&guid, 0xcd, sizeof(guid));
11100 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
11101 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11102 if (vih.bmiHeader.biBitCount == 32)
11103 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
11104 else if (vih.bmiHeader.biBitCount == 24)
11105 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB24), "Unexpected guid %s.\n", debugstr_guid(&guid));
11106 else if (vih.bmiHeader.biBitCount == 16)
11107 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB555), "Unexpected guid %s.\n", debugstr_guid(&guid));
11108 else if (vih.bmiHeader.biBitCount == 8)
11109 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB8), "Unexpected guid %s.\n", debugstr_guid(&guid));
11110 else if (vih.bmiHeader.biBitCount == 4)
11111 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB4), "Unexpected guid %s.\n", debugstr_guid(&guid));
11112 else if (vih.bmiHeader.biBitCount == 1)
11113 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB1), "Unexpected guid %s.\n", debugstr_guid(&guid));
11115 value32 = 0xdeadbeef;
11116 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11117 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11118 if (vih.bmiHeader.biBitCount > 1)
11119 ok(value32 == 16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32);
11120 else
11121 todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);
11123 hr = IMFMediaType_GetItem(media_type, &MF_MT_PALETTE, NULL);
11124 if (vih.bmiHeader.biBitCount > 1)
11125 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11126 else
11127 todo_wine ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11129 value32 = 0xdeadbeef;
11130 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
11131 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11132 ok(value32 == 1, "Unexpected value %#x.\n", value32);
11133 value32 = 0xdeadbeef;
11134 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
11135 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11136 ok(value32 == 1, "Unexpected value %#x.\n", value32);
11138 value32 = 0xdeadbeef;
11139 vih.bmiHeader.biHeight = 32;
11140 hr = MFInitMediaTypeFromVideoInfoHeader2(media_type, &vih, sizeof(vih), NULL);
11141 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11142 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11143 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11144 if (vih.bmiHeader.biBitCount > 1)
11145 ok(value32 == -16 * vih.bmiHeader.biBitCount / 8, "Unexpected value %#x.\n", value32);
11146 else
11147 todo_wine ok(value32 == -4, "Unexpected value %#x.\n", value32);
11149 vih.bmiHeader.biHeight = -32;
11152 winetest_pop_context();
11155 IMFMediaType_Release(media_type);
11158 static void test_MFInitMediaTypeFromAMMediaType(void)
11160 static const MFVideoArea expect_aperture = {.OffsetX = {.value = 13}, .OffsetY = {.value = 46}, .Area = {.cx = 110, .cy = 410}};
11161 static const RECT source = {13, 46, 123, 456}, target = {25, 34, 107, 409};
11162 IMFMediaType *media_type;
11163 AM_MEDIA_TYPE mt;
11164 UINT32 value32;
11165 UINT64 value64;
11166 HRESULT hr;
11167 GUID guid;
11168 VIDEOINFOHEADER vih =
11170 {0}, {0}, 0, 0, 0,
11171 {sizeof(BITMAPINFOHEADER), 32, 24, 1, 0, 0xdeadbeef}
11173 static const struct guid_type_pair
11175 const GUID *am_type;
11176 const GUID *mf_type;
11177 } guid_types[] =
11179 /* these RGB formats are converted, MEDIASUBTYPE variant isn't
11180 * defined using DEFINE_MEDIATYPE_GUID */
11181 { &MEDIASUBTYPE_RGB1, &MFVideoFormat_RGB1 },
11182 { &MEDIASUBTYPE_RGB4, &MFVideoFormat_RGB4 },
11183 { &MEDIASUBTYPE_RGB8, &MFVideoFormat_RGB8 },
11184 { &MEDIASUBTYPE_RGB555, &MFVideoFormat_RGB555 },
11185 { &MEDIASUBTYPE_RGB565, &MFVideoFormat_RGB565 },
11186 { &MEDIASUBTYPE_RGB24, &MFVideoFormat_RGB24 },
11187 { &MEDIASUBTYPE_RGB32, &MFVideoFormat_RGB32 },
11188 { &MEDIASUBTYPE_ARGB1555, &MFVideoFormat_ARGB1555 },
11189 { &MEDIASUBTYPE_ARGB4444, &MFVideoFormat_ARGB4444 },
11190 { &MEDIASUBTYPE_ARGB32, &MFVideoFormat_ARGB32 },
11191 { &MEDIASUBTYPE_A2R10G10B10, &MFVideoFormat_A2B10G10R10 },
11192 { &MEDIASUBTYPE_A2B10G10R10, &MFVideoFormat_A2R10G10B10 },
11194 /* any other GUID is passed through */
11195 { &MEDIASUBTYPE_I420, &MFVideoFormat_I420 },
11196 { &MEDIASUBTYPE_AYUV, &MFVideoFormat_AYUV },
11197 { &MEDIASUBTYPE_YV12, &MFVideoFormat_YV12 },
11198 { &MEDIASUBTYPE_YUY2, &MFVideoFormat_YUY2 },
11199 { &MEDIASUBTYPE_UYVY, &MFVideoFormat_UYVY },
11200 { &MEDIASUBTYPE_YVYU, &MFVideoFormat_YVYU },
11201 { &MEDIASUBTYPE_NV12, &MFVideoFormat_NV12 },
11203 /* even formats that don't exist in MF */
11204 { &DUMMY_GUID3, &DUMMY_GUID3 },
11205 { &MEDIASUBTYPE_NV24, &MEDIASUBTYPE_NV24 },
11206 { &MEDIASUBTYPE_P208, &MEDIASUBTYPE_P208 },
11208 /* if the mapping is ambiguous, it is not corrected */
11209 { &MEDIASUBTYPE_h264, &MEDIASUBTYPE_h264 },
11210 { &MEDIASUBTYPE_H264, &MFVideoFormat_H264 },
11212 MFVideoArea aperture;
11213 unsigned int i;
11215 hr = MFCreateMediaType(&media_type);
11216 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11218 memset(&mt, 0, sizeof(mt));
11219 mt.majortype = MEDIATYPE_Video;
11220 mt.formattype = FORMAT_VideoInfo;
11221 mt.cbFormat = sizeof(VIDEOINFOHEADER);
11222 mt.pbFormat = (BYTE *)&vih;
11224 hr = IMFMediaType_SetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, 123);
11225 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11227 hr = MFInitMediaTypeFromAMMediaType(media_type, &mt);
11228 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11230 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
11231 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11232 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
11233 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
11234 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11235 ok(IsEqualGUID(&guid, &GUID_NULL), "Unexpected guid %s.\n", debugstr_guid(&guid));
11236 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
11237 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11238 ok(value64 == ((UINT64)32 << 32 | 24), "Unexpected value %#I64x.\n", value64);
11239 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
11240 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11241 ok(value64 == ((UINT64)1 << 32 | 1), "Unexpected value %#I64x.\n", value64);
11242 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
11243 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11244 ok(value32 == MFVideoInterlace_Progressive, "Unexpected value %#x.\n", value32);
11245 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
11246 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11247 ok(!!value32, "Unexpected value %#x.\n", value32);
11249 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11250 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11251 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
11252 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11253 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
11254 ok(hr == MF_E_ATTRIBUTENOTFOUND, "Unexpected hr %#lx.\n", hr);
11256 vih.bmiHeader.biHeight = -24;
11258 hr = MFInitMediaTypeFromAMMediaType(media_type, &mt);
11259 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11260 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
11261 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11262 ok(value64 == ((UINT64)32 << 32 | 24), "Unexpected value %#I64x.\n", value64);
11264 memcpy(&mt.subtype, &MEDIASUBTYPE_RGB32, sizeof(GUID));
11265 vih.bmiHeader.biHeight = 24;
11267 hr = MFInitMediaTypeFromAMMediaType(media_type, &mt);
11268 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11270 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
11271 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11272 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
11273 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
11274 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11275 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
11276 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
11277 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11278 ok(value64 == ((UINT64)32 << 32 | 24), "Unexpected value %#I64x.\n", value64);
11279 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
11280 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11281 ok(value64 == ((UINT64)1 << 32 | 1), "Unexpected value %#I64x.\n", value64);
11282 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
11283 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11284 ok(value32 == MFVideoInterlace_Progressive, "Unexpected value %#x.\n", value32);
11285 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
11286 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11287 ok(value32 == 3072, "Unexpected value %u.\n", value32);
11288 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
11289 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11290 ok(!!value32, "Unexpected value %#x.\n", value32);
11291 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
11292 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11293 ok(!!value32, "Unexpected value %u.\n", value32);
11294 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11295 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11296 ok(value32 == -128, "Unexpected value %d.\n", value32);
11298 /* Negative height. */
11299 vih.bmiHeader.biHeight = -24;
11301 hr = MFInitMediaTypeFromAMMediaType(media_type, &mt);
11302 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11304 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
11305 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11306 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
11307 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
11308 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11309 ok(IsEqualGUID(&guid, &MFVideoFormat_RGB32), "Unexpected guid %s.\n", debugstr_guid(&guid));
11310 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
11311 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11312 ok(value64 == ((UINT64)32 << 32 | 24), "Unexpected value %#I64x.\n", value64);
11313 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_PIXEL_ASPECT_RATIO, &value64);
11314 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11315 ok(value64 == ((UINT64)1 << 32 | 1), "Unexpected value %#I64x.\n", value64);
11316 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_INTERLACE_MODE, &value32);
11317 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11318 ok(value32 == MFVideoInterlace_Progressive, "Unexpected value %#x.\n", value32);
11319 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
11320 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11321 ok(value32 == 3072, "Unexpected value %u.\n", value32);
11322 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_ALL_SAMPLES_INDEPENDENT, &value32);
11323 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11324 ok(!!value32, "Unexpected value %#x.\n", value32);
11325 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_FIXED_SIZE_SAMPLES, &value32);
11326 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11327 ok(!!value32, "Unexpected value %u.\n", value32);
11328 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11329 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11330 ok(value32 == 128, "Unexpected value %d.\n", value32);
11332 /* only rcSource is considered, lSampleSize is ignored if biSizeImage was present */
11333 memcpy(&mt.subtype, &MEDIASUBTYPE_RGB32, sizeof(GUID));
11334 vih.rcSource = source;
11335 vih.rcTarget = target;
11336 vih.bmiHeader.biWidth = 432;
11337 vih.bmiHeader.biHeight = -654;
11338 vih.bmiHeader.biSizeImage = 12345678;
11339 mt.lSampleSize = 87654321;
11340 hr = MFInitMediaTypeFromAMMediaType(media_type, &mt);
11341 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11343 hr = IMFMediaType_GetUINT64(media_type, &MF_MT_FRAME_SIZE, &value64);
11344 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11345 ok((UINT32)(value64 >> 32) == 432, "got %d.\n", (UINT32)(value64 >> 32));
11346 ok((UINT32)value64 == 654, "got %d.\n", (UINT32)value64);
11347 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_DEFAULT_STRIDE, &value32);
11348 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11349 ok(value32 == 432 * 4, "got %d.\n", (UINT32)value32);
11350 hr = IMFMediaType_GetUINT32(media_type, &MF_MT_SAMPLE_SIZE, &value32);
11351 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11352 ok(value32 == 12345678, "got %d.\n", (UINT32)value32);
11353 hr = IMFMediaType_GetBlob(media_type, &MF_MT_MINIMUM_DISPLAY_APERTURE, (BYTE *)&aperture, sizeof(aperture), &value32);
11354 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11355 ok(value32 == sizeof(aperture), "got %d.\n", value32);
11356 ok(!memcmp(&aperture, &expect_aperture, sizeof(aperture)), "unexpected aperture\n");
11358 vih.bmiHeader.biHeight = 24;
11359 for (i = 0; i < ARRAY_SIZE(guid_types); ++i)
11361 winetest_push_context("%s", debugstr_guid(guid_types[i].am_type));
11362 memcpy(&mt.subtype, guid_types[i].am_type, sizeof(GUID));
11364 hr = MFInitMediaTypeFromAMMediaType(media_type, &mt);
11365 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11367 hr = IMFMediaType_GetGUID(media_type, &MF_MT_MAJOR_TYPE, &guid);
11368 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11369 ok(IsEqualGUID(&guid, &MFMediaType_Video), "Unexpected guid %s.\n", debugstr_guid(&guid));
11370 hr = IMFMediaType_GetGUID(media_type, &MF_MT_SUBTYPE, &guid);
11371 ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
11372 ok(IsEqualGUID(&guid, guid_types[i].mf_type), "Unexpected guid %s.\n", debugstr_guid(&guid));
11373 winetest_pop_context();
11376 IMFMediaType_Release(media_type);
11379 static void test_MFCreatePathFromURL(void)
11381 static const struct
11383 const WCHAR *url;
11384 const WCHAR *path;
11385 HRESULT hr;
11387 tests[] =
11389 /* 0 leading slash */
11390 { L"file:c:/foo/bar", L"c:\\foo\\bar" },
11391 { L"file:c|/foo/bar", L"c:\\foo\\bar" },
11392 { L"file:cx|/foo/bar", L"cx|\\foo\\bar" },
11393 { L"file:c:foo/bar", L"c:foo\\bar" },
11394 { L"file:c|foo/bar", L"c:foo\\bar" },
11395 { L"file:c:/foo%20ba%2fr", L"c:\\foo ba/r" },
11396 { L"file:foo%20ba%2fr", L"foo ba/r" },
11397 { L"file:foo/bar/", L"foo\\bar\\" },
11399 /* 1 leading (back)slash */
11400 { L"file:/c:/foo/bar", L"c:\\foo\\bar" },
11401 { L"file:\\c:/foo/bar", L"c:\\foo\\bar" },
11402 { L"file:/c|/foo/bar", L"c:\\foo\\bar" },
11403 { L"file:/cx|/foo/bar", L"\\cx|\\foo\\bar" },
11404 { L"file:/c:foo/bar", L"c:foo\\bar" },
11405 { L"file:/c|foo/bar", L"c:foo\\bar" },
11406 { L"file:/c:/foo%20ba%2fr", L"c:\\foo ba/r" },
11407 { L"file:/foo%20ba%2fr", L"\\foo ba/r" },
11408 { L"file:/foo/bar/", L"\\foo\\bar\\" },
11410 /* 2 leading (back)slashes */
11411 { L"file://c:/foo/bar", L"c:\\foo\\bar" },
11412 { L"file://c:/d:/foo/bar", L"c:\\d:\\foo\\bar" },
11413 { L"file://c|/d|/foo/bar", L"c:\\d|\\foo\\bar" },
11414 { L"file://cx|/foo/bar", L"\\\\cx|\\foo\\bar" },
11415 { L"file://c:foo/bar", L"c:foo\\bar" },
11416 { L"file://c|foo/bar", L"c:foo\\bar" },
11417 { L"file://c:/foo%20ba%2fr", L"c:\\foo%20ba%2fr" },
11418 { L"file://c%3a/foo/../bar", L"\\\\c:\\foo\\..\\bar" },
11419 { L"file://c%7c/foo/../bar", L"\\\\c|\\foo\\..\\bar" },
11420 { L"file://foo%20ba%2fr", L"\\\\foo ba/r" },
11421 { L"file://localhost/c:/foo/bar", L"c:\\foo\\bar" },
11422 { L"file://localhost/c:/foo%20ba%5Cr", L"c:\\foo ba\\r" },
11423 { L"file://LocalHost/c:/foo/bar", L"c:\\foo\\bar" },
11424 { L"file:\\\\localhost\\c:\\foo\\bar", L"c:\\foo\\bar" },
11425 { L"file://incomplete", L"\\\\incomplete" },
11427 /* 3 leading (back)slashes (omitting hostname) */
11428 { L"file:///c:/foo/bar", L"c:\\foo\\bar" },
11429 { L"File:///c:/foo/bar", L"c:\\foo\\bar" },
11430 { L"file:///c:/foo%20ba%2fr", L"c:\\foo ba/r" },
11431 { L"file:///foo%20ba%2fr", L"\\foo ba/r" },
11432 { L"file:///foo/bar/", L"\\foo\\bar\\" },
11433 { L"file:///localhost/c:/foo/bar", L"\\localhost\\c:\\foo\\bar" },
11435 /* 4 leading (back)slashes */
11436 { L"file:////c:/foo/bar", L"c:\\foo\\bar" },
11437 { L"file:////c:/foo%20ba%2fr", L"c:\\foo%20ba%2fr" },
11438 { L"file:////foo%20ba%2fr", L"\\\\foo%20ba%2fr" },
11440 /* 5 and more leading (back)slashes */
11441 { L"file://///c:/foo/bar", L"\\\\c:\\foo\\bar" },
11442 { L"file://///c:/foo%20ba%2fr", L"\\\\c:\\foo ba/r" },
11443 { L"file://///foo%20ba%2fr", L"\\\\foo ba/r" },
11444 { L"file://////c:/foo/bar", L"\\\\c:\\foo\\bar" },
11446 /* Leading (back)slashes cannot be escaped */
11447 { L"file:%2f%2flocalhost%2fc:/foo/bar", L"//localhost/c:\\foo\\bar" },
11448 { L"file:%5C%5Clocalhost%5Cc:/foo/bar", L"\\\\localhost\\c:\\foo\\bar" },
11450 /* Hostname handling */
11451 { L"file://l%6fcalhost/c:/foo/bar", L"\\\\localhostc:\\foo\\bar" },
11452 { L"file://localhost:80/c:/foo/bar", L"\\\\localhost:80c:\\foo\\bar" },
11453 { L"file://host/c:/foo/bar", L"\\\\hostc:\\foo\\bar" },
11454 { L"file://host//c:/foo/bar", L"\\\\host\\\\c:\\foo\\bar" },
11455 { L"file://host/\\c:/foo/bar", L"\\\\host\\\\c:\\foo\\bar" },
11456 { L"file://host/c:foo/bar", L"\\\\hostc:foo\\bar" },
11457 { L"file://host/foo/bar", L"\\\\host\\foo\\bar" },
11458 { L"file:\\\\host\\c:\\foo\\bar", L"\\\\hostc:\\foo\\bar" },
11459 { L"file:\\\\host\\ca\\foo\\bar", L"\\\\host\\ca\\foo\\bar" },
11460 { L"file:\\\\host\\c|\\foo\\bar", L"\\\\hostc|\\foo\\bar" },
11461 { L"file:\\%5Chost\\c:\\foo\\bar", L"\\\\host\\c:\\foo\\bar" },
11462 { L"file:\\\\host\\cx:\\foo\\bar", L"\\\\host\\cx:\\foo\\bar" },
11463 { L"file:///host/c:/foo/bar", L"\\host\\c:\\foo\\bar" },
11465 /* Not file URLs */
11466 { L"c:\\foo\\bar", NULL, E_INVALIDARG },
11467 { L"foo/bar", NULL, E_INVALIDARG },
11468 { L"http://foo/bar", NULL, E_INVALIDARG },
11470 unsigned int i;
11471 WCHAR *path;
11472 HRESULT hr;
11474 if (!pMFCreatePathFromURL)
11476 win_skip("MFCreatePathFromURL() is not available.\n");
11477 return;
11480 hr = pMFCreatePathFromURL(NULL, NULL);
11481 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
11483 path = (void *)0xdeadbeef;
11484 hr = pMFCreatePathFromURL(NULL, &path);
11485 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
11486 ok(path == (void *)0xdeadbeef, "Unexpected pointer %p.\n", path);
11488 hr = pMFCreatePathFromURL(L"file://foo", NULL);
11489 ok(hr == E_POINTER, "Unexpected hr %#lx.\n", hr);
11491 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11493 hr = pMFCreatePathFromURL(tests[i].url, &path);
11494 ok(hr == tests[i].hr, "Unexpected hr %#lx, expected %#lx.\n", hr, tests[i].hr);
11495 if (SUCCEEDED(hr))
11497 ok(!wcscmp(path, tests[i].path), "Unexpected path %s, expected %s.\n",
11498 debugstr_w(path), debugstr_w(tests[i].path));
11499 CoTaskMemFree(path);
11504 #define check_reset_data(a, b, c, d, e) check_reset_data_(__LINE__, a, b, c, d, e)
11505 static void check_reset_data_(unsigned int line, IMF2DBuffer2 *buffer2d, const BYTE *data, BOOL bottom_up,
11506 DWORD width, DWORD height)
11508 BYTE *scanline0, *buffer_start;
11509 DWORD length, max_length;
11510 IMFMediaBuffer *buffer;
11511 LONG pitch;
11512 BYTE *lock;
11513 HRESULT hr;
11514 int i;
11516 hr = IMF2DBuffer2_QueryInterface(buffer2d, &IID_IMFMediaBuffer, (void **)&buffer);
11517 ok(hr == S_OK, "got hr %#lx.\n", hr);
11519 hr = IMF2DBuffer2_Lock2DSize(buffer2d, MF2DBuffer_LockFlags_Read, &scanline0, &pitch, &buffer_start, &length);
11520 ok(hr == S_OK, "got hr %#lx.\n", hr);
11521 if (bottom_up)
11523 ok(pitch < 0, "got pitch %ld.\n", pitch);
11524 ok(buffer_start == scanline0 + pitch * (LONG)(height - 1), "buffer start mismatch.\n");
11526 else
11528 ok(pitch > 0, "got pitch %ld.\n", pitch);
11529 ok(buffer_start == scanline0, "buffer start mismatch.\n");
11531 for (i = 0; i < height; ++i)
11532 ok_(__FILE__,line)(!memcmp(buffer_start + abs(pitch) * i, data + width * i * 4, width * 4),
11533 "2D Data mismatch, scaline %d.\n", i);
11534 hr = IMF2DBuffer2_Unlock2D(buffer2d);
11535 ok(hr == S_OK, "got hr %#lx.\n", hr);
11537 hr = IMFMediaBuffer_Lock(buffer, &lock, &max_length, &length);
11538 ok(hr == S_OK, "got hr %#lx.\n", hr);
11539 ok_(__FILE__,line)(max_length == width * height * 4, "got max_length %lu.\n", max_length);
11540 ok_(__FILE__,line)(length == width * height * 4, "got length %lu.\n", length);
11541 ok_(__FILE__,line)(!memcmp(lock, data, length), "contiguous data mismatch.\n");
11542 memset(lock, 0xcc, length);
11543 hr = IMFMediaBuffer_Unlock(buffer);
11544 ok(hr == S_OK, "got hr %#lx.\n", hr);
11546 IMFMediaBuffer_Release(buffer);
11549 static void test_2dbuffer_copy_(IMFMediaBuffer *buffer, BOOL bottom_up, DWORD width, DWORD height)
11551 static const unsigned int test_data[] =
11553 0x01010101, 0x01010101,
11554 0x02020202, 0x02020202,
11557 BYTE data[sizeof(test_data)];
11558 IMFMediaBuffer *src_buffer;
11559 DWORD length, max_length;
11560 IMF2DBuffer2 *buffer2d;
11561 IMFSample *sample;
11562 BYTE *lock;
11563 HRESULT hr;
11564 ULONG ref;
11566 hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMF2DBuffer2, (void **)&buffer2d);
11567 ok(hr == S_OK, "got hr %#lx.\n", hr);
11569 hr = MFCreateSample(&sample);
11570 ok(hr == S_OK, "got hr %#lx.\n", hr);
11571 hr = MFCreateMemoryBuffer(sizeof(test_data) * 2, &src_buffer);
11572 ok(hr == S_OK, "got hr %#lx.\n", hr);
11573 hr = IMFSample_AddBuffer(sample, src_buffer);
11574 ok(hr == S_OK, "got hr %#lx.\n", hr);
11576 hr = IMFMediaBuffer_Lock(src_buffer, &lock, &max_length, &length);
11577 ok(hr == S_OK, "got hr %#lx.\n", hr);
11578 ok(max_length == sizeof(test_data) * 2, "got %lu.\n", max_length);
11579 memcpy(lock, test_data, sizeof(test_data));
11580 hr = IMFMediaBuffer_Unlock(src_buffer);
11581 ok(hr == S_OK, "got hr %#lx.\n", hr);
11583 hr = IMFMediaBuffer_Lock(buffer, &lock, &max_length, &length);
11584 ok(hr == S_OK, "got hr %#lx.\n", hr);
11585 ok(max_length == 16, "got %lu.\n", max_length);
11586 ok(length == 16, "got %lu.\n", length);
11587 memset(lock, 0xcc, length);
11588 hr = IMFMediaBuffer_Unlock(buffer);
11589 ok(hr == S_OK, "got hr %#lx.\n", hr);
11591 hr = IMFMediaBuffer_SetCurrentLength(src_buffer, 1);
11592 ok(hr == S_OK, "got hr %#lx.\n", hr);
11593 hr = IMFSample_CopyToBuffer(sample, buffer);
11594 ok(hr == S_OK, "got hr %#lx.\n", hr);
11596 memset(data, 0xcc, sizeof(data));
11597 data[0] = ((BYTE *)test_data)[0];
11598 check_reset_data(buffer2d, data, bottom_up, width, height);
11600 hr = IMF2DBuffer2_ContiguousCopyFrom(buffer2d, (BYTE *)test_data, sizeof(test_data));
11601 ok(hr == S_OK, "got hr %#lx.\n", hr);
11602 hr = IMF2DBuffer2_ContiguousCopyTo(buffer2d, data, sizeof(data));
11603 ok(hr == S_OK, "got hr %#lx.\n", hr);
11604 ok(!memcmp(data, test_data, sizeof(data)), "data mismatch.\n");
11606 check_reset_data(buffer2d, (const BYTE *)test_data, bottom_up, width, height);
11608 hr = IMFMediaBuffer_SetCurrentLength(src_buffer, sizeof(test_data) + 1);
11609 ok(hr == S_OK, "got hr %#lx.\n", hr);
11610 hr = IMFSample_CopyToBuffer(sample, buffer);
11611 ok(hr == MF_E_BUFFERTOOSMALL, "got hr %#lx.\n", hr);
11613 hr = IMFMediaBuffer_SetCurrentLength(src_buffer, sizeof(test_data));
11614 ok(hr == S_OK, "got hr %#lx.\n", hr);
11615 hr = IMFSample_CopyToBuffer(sample, buffer);
11616 ok(hr == S_OK, "got hr %#lx.\n", hr);
11618 check_reset_data(buffer2d, (const BYTE *)test_data, bottom_up, width, height);
11620 IMF2DBuffer2_Release(buffer2d);
11621 ref = IMFSample_Release(sample);
11622 ok(!ref, "got %lu.\n", ref);
11623 ref = IMFMediaBuffer_Release(src_buffer);
11624 ok(!ref, "got %lu.\n", ref);
11627 static void test_2dbuffer_copy(void)
11629 D3D11_TEXTURE2D_DESC desc;
11630 ID3D11Texture2D *texture;
11631 IMFMediaBuffer *buffer;
11632 ID3D11Device *device;
11633 HRESULT hr;
11634 ULONG ref;
11636 if (!pMFCreate2DMediaBuffer)
11638 win_skip("MFCreate2DMediaBuffer() is not available.\n");
11639 return;
11642 winetest_push_context("top down");
11643 hr = pMFCreate2DMediaBuffer(2, 2, D3DFMT_A8R8G8B8, FALSE, &buffer);
11644 ok(hr == S_OK, "got hr %#lx.\n", hr);
11645 test_2dbuffer_copy_(buffer, FALSE, 2, 2);
11646 ref = IMFMediaBuffer_Release(buffer);
11647 ok(!ref, "got %lu.\n", ref);
11648 winetest_pop_context();
11650 winetest_push_context("bottom up");
11651 hr = pMFCreate2DMediaBuffer(2, 2, D3DFMT_A8R8G8B8, TRUE, &buffer);
11652 ok(hr == S_OK, "got hr %#lx.\n", hr);
11653 test_2dbuffer_copy_(buffer, TRUE, 2, 2);
11654 ref = IMFMediaBuffer_Release(buffer);
11655 ok(!ref, "got %lu.\n", ref);
11656 winetest_pop_context();
11658 if (!pMFCreateDXGISurfaceBuffer)
11660 win_skip("MFCreateDXGISurfaceBuffer() is not available.\n");
11661 return;
11664 if (!(device = create_d3d11_device()))
11666 skip("Failed to create a D3D11 device, skipping tests.\n");
11667 return;
11670 memset(&desc, 0, sizeof(desc));
11671 desc.Width = 2;
11672 desc.Height = 2;
11673 desc.ArraySize = 1;
11674 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
11675 desc.SampleDesc.Count = 1;
11676 desc.SampleDesc.Quality = 0;
11677 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
11678 ok(hr == S_OK, "Failed to create a texture, hr %#lx.\n", hr);
11680 hr = pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D, (IUnknown *)texture, 0, FALSE, &buffer);
11681 ok(hr == S_OK, "Failed to create a buffer, hr %#lx.\n", hr);
11682 test_2dbuffer_copy_(buffer, FALSE, 2, 2);
11684 ID3D11Texture2D_Release(texture);
11685 ref = IMFMediaBuffer_Release(buffer);
11686 ok(!ref, "got %lu.\n", ref);
11687 ID3D11Device_Release(device);
11690 START_TEST(mfplat)
11692 char **argv;
11693 int argc;
11695 init_functions();
11697 argc = winetest_get_mainargs(&argv);
11698 if (argc >= 3)
11700 test_queue_com_state(argv[2]);
11701 return;
11704 if (!pMFCreateVideoSampleAllocatorEx)
11705 win_skip("MFCreateVideoSampleAllocatorEx() is not available. Some tests will be skipped.\n");
11707 if (!pD3D12CreateDevice)
11708 skip("Missing d3d12 support, some tests will be skipped.\n");
11710 CoInitialize(NULL);
11712 test_startup();
11713 test_register();
11714 test_media_type();
11715 test_MFCreateMediaEvent();
11716 test_attributes();
11717 test_sample();
11718 test_file_stream();
11719 test_MFCreateMFByteStreamOnStream();
11720 test_system_memory_buffer();
11721 test_system_memory_aligned_buffer();
11722 test_source_resolver();
11723 test_MFCreateAsyncResult();
11724 test_allocate_queue();
11725 test_MFLockSharedWorkQueue();
11726 test_MFCopyImage();
11727 test_MFCreateCollection();
11728 test_MFHeapAlloc();
11729 test_scheduled_items();
11730 test_serial_queue();
11731 test_periodic_callback();
11732 test_event_queue();
11733 test_presentation_descriptor();
11734 test_system_time_source();
11735 test_MFInvokeCallback();
11736 test_stream_descriptor();
11737 test_MFCalculateImageSize();
11738 test_MFGetPlaneSize();
11739 test_MFCompareFullToPartialMediaType();
11740 test_attributes_serialization();
11741 test_wrapped_media_type();
11742 test_MFCreateWaveFormatExFromMFMediaType();
11743 test_async_create_file();
11744 test_local_handlers();
11745 test_create_property_store();
11746 test_dxgi_device_manager();
11747 test_MFCreateTransformActivate();
11748 test_MFTRegisterLocal();
11749 test_queue_com();
11750 test_MFGetStrideForBitmapInfoHeader();
11751 test_MFCreate2DMediaBuffer();
11752 test_MFCreateMediaBufferFromMediaType();
11753 test_MFInitMediaTypeFromWaveFormatEx();
11754 test_MFCreateMFVideoFormatFromMFMediaType();
11755 test_MFInitAMMediaTypeFromMFMediaType();
11756 test_MFCreateAMMediaTypeFromMFMediaType();
11757 test_MFInitMediaTypeFromMFVideoFormat();
11758 test_IMFMediaType_GetRepresentation();
11759 test_MFCreateDXSurfaceBuffer();
11760 test_MFCreateTrackedSample();
11761 test_MFFrameRateToAverageTimePerFrame();
11762 test_MFAverageTimePerFrameToFrameRate();
11763 test_MFMapDXGIFormatToDX9Format();
11764 test_d3d11_surface_buffer();
11765 test_d3d12_surface_buffer();
11766 test_sample_allocator_sysmem();
11767 test_sample_allocator_d3d9();
11768 test_sample_allocator_d3d11();
11769 test_sample_allocator_d3d12();
11770 test_MFMapDX9FormatToDXGIFormat();
11771 test_MFllMulDiv();
11772 test_shared_dxgi_device_manager();
11773 test_MFInitVideoFormat_RGB();
11774 test_MFCreateVideoMediaTypeFromVideoInfoHeader();
11775 test_MFInitMediaTypeFromVideoInfoHeader();
11776 test_MFInitMediaTypeFromVideoInfoHeader2();
11777 test_MFInitMediaTypeFromAMMediaType();
11778 test_MFCreatePathFromURL();
11779 test_2dbuffer_copy();
11781 CoUninitialize();