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
38 #include "mfreadwrite.h"
39 #include "propvarutil.h"
43 #include "mfmediaengine.h"
45 #include "wine/test.h"
47 #define D3D11_INIT_GUID
51 #include "d3d9types.h"
57 #define EXTERN_GUID DEFINE_GUID
59 #include "wmcodecdsp.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
)
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
;
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
);
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
;
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
);
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
;
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
)
191 hr
= IDirect3DSurface9_UnlockRect(rb
->readback_surface
);
192 ok(hr
== D3D_OK
, "Failed to unlock surface, hr %#lx.\n", hr
);
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
;
232 get_d3d9_surface_readback(surface
, &rb
);
233 color
= get_d3d9_readback_color(&rb
, x
, y
);
234 release_d3d9_surface_readback(&rb
, FALSE
);
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
)
273 rb
->orig_resource
= resource
;
274 rb
->resource
= readback_resource
;
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
);
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
;
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
);
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
);
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
;
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
);
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
);
473 static const WCHAR fileschemeW
[] = L
"file://";
475 static WCHAR
*load_resource(const WCHAR
*name
)
477 static WCHAR pathW
[MAX_PATH
];
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
),
496 ok(written
== SizeofResource(GetModuleHandleA(NULL
), res
),
497 "couldn't write resource\n" );
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
);
514 IMFAsyncCallback IMFAsyncCallback_iface
;
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
))
533 IMFAsyncCallback_AddRef(iface
);
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
);
554 CloseHandle(callback
->event
);
561 static HRESULT WINAPI
testcallback_GetParameters(IMFAsyncCallback
*iface
, DWORD
*flags
, DWORD
*queue
)
563 ok(flags
!= NULL
&& queue
!= NULL
, "Unexpected arguments.\n");
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
);
578 static const IMFAsyncCallbackVtbl test_async_callback_result_vtbl
=
580 testcallback_QueryInterface
,
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
;
598 static BOOL
check_clsid(CLSID
*clsids
, UINT32 count
)
601 for (i
= 0; i
< count
; i
++)
603 if (IsEqualGUID(&clsids
[i
], &DUMMY_CLSID
))
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
;
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");
633 ok(ret
== S_OK
, "Failed to register dummy transform, hr %#lx.\n", ret
);
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
);
653 /* NULL clsids/count crashes on windows (vista) */
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");
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");
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
);
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
);
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
);
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
);
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 */
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
);
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
;
768 ok(!!result
, "Unexpected result object.\n");
770 resolver
= (IMFSourceResolver
*)IMFAsyncResult_GetStateNoAddRef(result
);
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");
781 IUnknown_Release(object
);
782 IUnknown_Release(object2
);
784 SetEvent(callback
->event
);
789 static const IMFAsyncCallbackVtbl test_create_from_url_callback_vtbl
=
791 testcallback_QueryInterface
,
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
;
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
);
836 static const IMFAsyncCallbackVtbl test_create_from_file_handler_callback_vtbl
=
838 testcallback_QueryInterface
,
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
;
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
);
863 static const IMFAsyncCallbackVtbl events_callback_vtbl
=
865 testcallback_QueryInterface
,
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
);
885 static BOOL
get_event(IMFMediaEventGenerator
*generator
, MediaEventType expected_event_type
, PROPVARIANT
*value
)
887 struct test_callback
*callback
;
888 MediaEventType event_type
;
892 callback
= create_test_callback(&events_callback_vtbl
);
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
)
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
)))
915 hr
= IMFMediaEvent_GetValue(callback
->media_event
, value
);
916 ok(hr
== S_OK
, "Failed to get value of event, hr %#lx.\n", hr
);
923 if (callback
->media_event
)
924 IMFMediaEvent_Release(callback
->media_event
);
925 IMFAsyncCallback_Release(&callback
->IMFAsyncCallback_iface
);
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
];
967 if (!pMFCreateSourceResolver
)
969 win_skip("MFCreateSourceResolver() not found\n");
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
,
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
);
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
);
1065 IMFByteStream_Release(stream
);
1066 IMFSourceResolver_Release(resolver
);
1069 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
1071 DeleteFileW(filename
);
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
);
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
);
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
);
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");
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");
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");
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");
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
);
1229 for (i
= 0; i
< sample_count
; ++i
)
1231 static const LONGLONG MILLI_TO_100_NANO
= 10000;
1232 LONGLONG duration
, time
;
1237 ret
= get_event((IMFMediaEventGenerator
*)video_stream
, MEMediaSample
, &var
);
1238 ok(ret
, "Sample %u not received.\n", i
+ 1);
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 */
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
);
1322 IMFSourceResolver_Release(resolver
);
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
);
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
);
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
);
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
);
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
;
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
);
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
);
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
);
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
);
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");
1457 hr
= MFCreateMediaType(&mediatype2
);
1458 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
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
);
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
);
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
);
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
);
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
);
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)
1610 IMFMediaEvent
*mediaevent
;
1612 MediaEventType type
;
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
;
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
;
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
);
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");
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
);
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
));
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
);
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);
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);
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
);
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
));
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
);
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
)
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
2204 IStream IStream_iface
;
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
))
2222 IStream_AddRef(iface
);
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
);
2243 CloseHandle(stream
->read_event
);
2244 CloseHandle(stream
->done_event
);
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
);
2256 SetEvent(stream
->read_event
);
2257 res
= WaitForSingleObject(stream
->done_event
, 1000);
2258 ok(res
== 0, "got %#lx\n", res
);
2264 static HRESULT WINAPI
test_stream_Write(IStream
*iface
, const void *data
, ULONG size
, ULONG
*ret_size
)
2266 ok(0, "Unexpected call.\n");
2270 static HRESULT WINAPI
test_stream_Seek(IStream
*iface
, LARGE_INTEGER offset
, DWORD method
, ULARGE_INTEGER
*ret_offset
)
2275 static HRESULT WINAPI
test_stream_SetSize(IStream
*iface
, ULARGE_INTEGER size
)
2277 ok(0, "Unexpected call.\n");
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");
2288 static HRESULT WINAPI
test_stream_Commit(IStream
*iface
, DWORD flags
)
2290 ok(0, "Unexpected call.\n");
2294 static HRESULT WINAPI
test_stream_Revert(IStream
*iface
)
2296 ok(0, "Unexpected call.\n");
2300 static HRESULT WINAPI
test_stream_LockRegion(IStream
*iface
, ULARGE_INTEGER offset
, ULARGE_INTEGER size
, DWORD type
)
2302 ok(0, "Unexpected call.\n");
2306 static HRESULT WINAPI
test_stream_UnlockRegion(IStream
*iface
, ULARGE_INTEGER offset
, ULARGE_INTEGER size
, DWORD type
)
2308 ok(0, "Unexpected call.\n");
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;
2321 static HRESULT WINAPI
test_stream_Clone(IStream
*iface
, IStream
**out
)
2323 ok(0, "Unexpected call.\n");
2327 static const IStreamVtbl test_stream_vtbl
=
2329 test_stream_QueryInterface
,
2331 test_stream_Release
,
2335 test_stream_SetSize
,
2339 test_stream_LockRegion
,
2340 test_stream_UnlockRegion
,
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
;
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
;
2380 IMFAttributes
*attributes
= NULL
;
2381 IMFAsyncResult
*result
;
2382 DWORD caps
, written
;
2391 if(!pMFCreateMFByteStreamOnStream
)
2393 win_skip("MFCreateMFByteStreamOnStream() not found\n");
2397 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
2398 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
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
,
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
);
2425 broken(hr
== E_NOINTERFACE
), "Unexpected hr %#lx.\n", hr
);
2429 win_skip("Cannot retrieve IMFAttributes interface from IMFByteStream\n");
2430 IStream_Release(stream
);
2431 IMFByteStream_Release(bytestream
);
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
,
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 */
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");
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");
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");
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");
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
);
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
];
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
);
2596 ok(caps
== (MFBYTESTREAM_IS_READABLE
| MFBYTESTREAM_IS_SEEKABLE
| MFBYTESTREAM_DOES_NOT_USE_NETWORK
),
2597 "Unexpected caps %#lx.\n", caps
);
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
));
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
);
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
);
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
;
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
);
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
);
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
);
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
;
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
;
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
);
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");
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
;
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
;
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
);
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
);
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
;
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");
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");
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
);
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");
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)
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
);
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. */
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
);
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
);
3393 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
3396 static void test_allocate_queue(void)
3398 DWORD queue
, queue2
;
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
);
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];
3442 win_skip("MFCopyImage() is not available.\n");
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
;
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
);
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
);
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
);
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
);
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
);
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)
3589 res
= MFHeapAlloc(16, 0, NULL
, 0, eAllocationTypeIgnore
);
3590 ok(res
!= NULL
, "MFHeapAlloc failed.\n");
3595 static void test_scheduled_items(void)
3597 struct test_callback
*callback
;
3598 IMFAsyncResult
*result
;
3599 MFWORKITEM_KEY key
, key2
;
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");
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
);
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
;
3666 if (!pMFAllocateSerialWorkQueue
)
3668 win_skip("Serial queues are not supported.\n");
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
);
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
);
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)
3719 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
3720 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
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");
3731 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
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
);
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
);
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
;
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
);
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
);
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
);
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
;
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
);
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
);
3981 static void test_system_time_source(void)
3983 static const struct clock_state_test
3985 enum clock_action action
;
3986 MFCLOCK_STATE state
;
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
;
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
);
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
)
4046 hr
= IMFClockStateSink_OnClockStop(statesink
, 0);
4049 hr
= IMFClockStateSink_OnClockRestart(statesink
, 0);
4052 hr
= IMFClockStateSink_OnClockPause(statesink
, 0);
4055 hr
= IMFClockStateSink_OnClockStart(statesink
, 0, 0);
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
);
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
;
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
);
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
;
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");
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
;
4706 UINT32 plane_size
; /* Matches image size when 0. */
4708 UINT32 contiguous_length
;
4711 image_size_tests
[] =
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
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
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
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)
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)
4910 if (!pMFGetPlaneSize
)
4912 win_skip("MFGetPlaneSize() is not available.\n");
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
)))
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
;
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
;
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
);
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
);
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");
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
;
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
;
5135 { &MFAudioFormat_PCM
, WAVE_FORMAT_PCM
, },
5136 { &MFAudioFormat_Float
, WAVE_FORMAT_IEEE_FLOAT
, },
5138 WAVEFORMATEXTENSIBLE
*format_ext
;
5139 IMFMediaType
*mediatype
;
5140 WAVEFORMATEX
*format
;
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
;
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
);
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
;
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
);
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
;
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
))
5284 IMFActivate_AddRef(iface
);
5289 return E_NOINTERFACE
;
5292 static ULONG WINAPI
activate_object_AddRef(IMFActivate
*iface
)
5297 static ULONG WINAPI
activate_object_Release(IMFActivate
*iface
)
5302 static HRESULT WINAPI
activate_object_GetItem(IMFActivate
*iface
, REFGUID key
, PROPVARIANT
*value
)
5307 static HRESULT WINAPI
activate_object_GetItemType(IMFActivate
*iface
, REFGUID key
, MF_ATTRIBUTE_TYPE
*type
)
5312 static HRESULT WINAPI
activate_object_CompareItem(IMFActivate
*iface
, REFGUID key
, REFPROPVARIANT value
, BOOL
*result
)
5317 static HRESULT WINAPI
activate_object_Compare(IMFActivate
*iface
, IMFAttributes
*theirs
, MF_ATTRIBUTES_MATCH_TYPE type
,
5323 static HRESULT WINAPI
activate_object_GetUINT32(IMFActivate
*iface
, REFGUID key
, UINT32
*value
)
5328 static HRESULT WINAPI
activate_object_GetUINT64(IMFActivate
*iface
, REFGUID key
, UINT64
*value
)
5333 static HRESULT WINAPI
activate_object_GetDouble(IMFActivate
*iface
, REFGUID key
, double *value
)
5338 static HRESULT WINAPI
activate_object_GetGUID(IMFActivate
*iface
, REFGUID key
, GUID
*value
)
5343 static HRESULT WINAPI
activate_object_GetStringLength(IMFActivate
*iface
, REFGUID key
, UINT32
*length
)
5348 static HRESULT WINAPI
activate_object_GetString(IMFActivate
*iface
, REFGUID key
, WCHAR
*value
,
5349 UINT32 size
, UINT32
*length
)
5354 static HRESULT WINAPI
activate_object_GetAllocatedString(IMFActivate
*iface
, REFGUID key
,
5355 WCHAR
**value
, UINT32
*length
)
5360 static HRESULT WINAPI
activate_object_GetBlobSize(IMFActivate
*iface
, REFGUID key
, UINT32
*size
)
5365 static HRESULT WINAPI
activate_object_GetBlob(IMFActivate
*iface
, REFGUID key
, UINT8
*buf
,
5366 UINT32 bufsize
, UINT32
*blobsize
)
5371 static HRESULT WINAPI
activate_object_GetAllocatedBlob(IMFActivate
*iface
, REFGUID key
, UINT8
**buf
, UINT32
*size
)
5376 static HRESULT WINAPI
activate_object_GetUnknown(IMFActivate
*iface
, REFGUID key
, REFIID riid
, void **ppv
)
5381 static HRESULT WINAPI
activate_object_SetItem(IMFActivate
*iface
, REFGUID key
, REFPROPVARIANT value
)
5386 static HRESULT WINAPI
activate_object_DeleteItem(IMFActivate
*iface
, REFGUID key
)
5391 static HRESULT WINAPI
activate_object_DeleteAllItems(IMFActivate
*iface
)
5396 static HRESULT WINAPI
activate_object_SetUINT32(IMFActivate
*iface
, REFGUID key
, UINT32 value
)
5401 static HRESULT WINAPI
activate_object_SetUINT64(IMFActivate
*iface
, REFGUID key
, UINT64 value
)
5406 static HRESULT WINAPI
activate_object_SetDouble(IMFActivate
*iface
, REFGUID key
, double value
)
5411 static HRESULT WINAPI
activate_object_SetGUID(IMFActivate
*iface
, REFGUID key
, REFGUID value
)
5416 static HRESULT WINAPI
activate_object_SetString(IMFActivate
*iface
, REFGUID key
, const WCHAR
*value
)
5421 static HRESULT WINAPI
activate_object_SetBlob(IMFActivate
*iface
, REFGUID key
, const UINT8
*buf
, UINT32 size
)
5426 static HRESULT WINAPI
activate_object_SetUnknown(IMFActivate
*iface
, REFGUID key
, IUnknown
*unknown
)
5431 static HRESULT WINAPI
activate_object_LockStore(IMFActivate
*iface
)
5436 static HRESULT WINAPI
activate_object_UnlockStore(IMFActivate
*iface
)
5441 static HRESULT WINAPI
activate_object_GetCount(IMFActivate
*iface
, UINT32
*count
)
5446 static HRESULT WINAPI
activate_object_GetItemByIndex(IMFActivate
*iface
, UINT32 index
, GUID
*key
, PROPVARIANT
*value
)
5451 static HRESULT WINAPI
activate_object_CopyAllItems(IMFActivate
*iface
, IMFAttributes
*dest
)
5456 static HRESULT WINAPI
activate_object_ActivateObject(IMFActivate
*iface
, REFIID riid
, void **obj
)
5461 static HRESULT WINAPI
activate_object_ShutdownObject(IMFActivate
*iface
)
5466 static HRESULT WINAPI
activate_object_DetachObject(IMFActivate
*iface
)
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";
5517 if (!pMFRegisterLocalSchemeHandler
)
5519 win_skip("Local handlers are not supported.\n");
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};
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
);
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
));
5603 value
.lVal
= 0xdeadbeef;
5604 hr
= IPropertyStore_SetValue(store
, &test_pkey
, &value
);
5605 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
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
;
5659 static DWORD WINAPI
test_device_manager_thread(void *arg
)
5661 struct test_thread_param
*param
= arg
;
5662 ID3D11Device
*device
;
5667 hr
= IMFDXGIDeviceManager_LockDevice(param
->manager
, param
->handle
, &IID_ID3D11Device
,
5668 (void **)&device
, FALSE
);
5670 ID3D11Device_Release(device
);
5673 hr
= IMFDXGIDeviceManager_UnlockDevice(param
->manager
, param
->handle
, FALSE
);
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
;
5688 if (!pMFCreateDXGIDeviceManager
)
5690 win_skip("MFCreateDXGIDeviceManager not found.\n");
5694 hr
= pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, D3D11_CREATE_DEVICE_VIDEO_SUPPORT
,
5695 NULL
, 0, D3D11_SDK_VERSION
, &d3d11_dev
, NULL
, NULL
);
5698 skip("Failed to create D3D11 device object.\n");
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
);
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
);
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. */
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
);
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
);
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
);
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
;
5882 thread
= CreateThread(NULL
, 0, test_device_manager_thread
, ¶m
, 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
;
5902 thread
= CreateThread(NULL
, 0, test_device_manager_thread
, ¶m
, 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
;
5927 if (!pMFCreateTransformActivate
)
5929 win_skip("MFCreateTransformActivate() is not available.\n");
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
))
5949 IClassFactory_AddRef(iface
);
5954 return E_NOINTERFACE
;
5957 static ULONG WINAPI
test_mft_factory_AddRef(IClassFactory
*iface
)
5962 static ULONG WINAPI
test_mft_factory_Release(IClassFactory
*iface
)
5967 static HRESULT WINAPI
test_mft_factory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **obj
)
5969 ok(0, "Unexpected call.\n");
5973 static HRESULT WINAPI
test_mft_factory_LockServer(IClassFactory
*iface
, BOOL fLock
)
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
;
5997 if (!pMFTRegisterLocal
)
5999 win_skip("MFTRegisterLocal() is not available.\n");
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
,
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
,
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
;
6076 if (!pCoGetApartmentType
)
6078 win_skip("CoGetApartmentType() is not available.\n");
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
;
6116 hr
= pCoGetApartmentType(&com_type
, &qualifier
);
6117 ok(SUCCEEDED(hr
), "Failed to get apartment type, hr %#lx.\n", hr
);
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
);
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
);
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
;
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
);
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
);
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
);
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
;
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 },
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 },
6255 if (!pMFGetStrideForBitmapInfoHeader
)
6257 win_skip("MFGetStrideForBitmapInfoHeader() is not available.\n");
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
;
6287 if (!pMFCreate2DMediaBuffer
)
6289 win_skip("MFCreate2DMediaBuffer() is not available.\n");
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
);
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
);
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
);
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
);
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
))
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
)
6530 if (j
>= ptr
->height
* ptr
->pitch
&& j
% ptr
->pitch
>= ptr
->width
/ 2)
6533 if (data
[j
] != (j
& 0x7f))
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
)
6557 if (j
>= ptr
->height
* ptr
->pitch
&& j
% ptr
->pitch
>= ptr
->width
/ 2)
6560 if (data
[j
] != (j
& 0x7f))
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
)
6582 if (j
>= ptr
->height
* ptr
->pitch
&& j
% ptr
->pitch
>= ptr
->width
/ 2)
6585 if (data2
[j
] != (j
& 0x7f))
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
)
6601 if (j
>= ptr
->height
* ptr
->pitch
&& j
% ptr
->pitch
>= ptr
->width
/ 2)
6604 if (data2
[j
] != (j
& 0x7f))
6607 ok(j
== ptr
->contiguous_length
, "Unexpected byte %02x instead of %02x at position %u.\n", data2
[j
], j
& 0x7f, j
);
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
);
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);
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);
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);
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");
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
);
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
);
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
);
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
);
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
))
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
;
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
;
6792 if (!pMFCreateMediaBufferFromMediaType
)
6794 win_skip("MFCreateMediaBufferFromMediaType() is not available.\n");
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
);
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
)
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
);
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");
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
},
6995 WAVEFORMATEXTENSIBLE waveformatext
;
6996 MPEGLAYER3WAVEFORMAT mp3format
;
6997 WAVEFORMATEXTENSIBLE
*format
;
6998 HEAACWAVEFORMAT aacformat
;
6999 IMFMediaType
*mediatype
;
7000 unsigned int i
, size
;
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
);
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
);
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
;
7126 hr
= MFCreateMediaType(&media_type
);
7127 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
7129 hr
= MFCreateMFVideoFormatFromMFMediaType(media_type
, &video_format
, &size
);
7130 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7131 ok(!!video_format
, "Unexpected format.\n");
7132 ok(video_format
->dwSize
== size
&& size
== sizeof(*video_format
), "Unexpected size %u.\n", size
);
7133 CoTaskMemFree(video_format
);
7135 IMFMediaType_Release(media_type
);
7138 static void test_MFInitAMMediaTypeFromMFMediaType(void)
7140 static const MFVideoArea aperture
= {.OffsetX
= {.fract
= 1, .value
= 2}, .OffsetY
= {.fract
= 3, .value
= 4}, .Area
={56,78}};
7141 static const BYTE dummy_user_data
[] = {0x01,0x02,0x03};
7143 WAVEFORMATEXTENSIBLE
*wave_format_ext
;
7144 VIDEOINFOHEADER
*video_info
;
7145 WAVEFORMATEX
*wave_format
;
7146 IMFMediaType
*media_type
;
7147 AM_MEDIA_TYPE am_type
;
7150 hr
= MFCreateMediaType(&media_type
);
7151 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
7153 /* test basic media type attributes mapping and valid formats */
7155 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7156 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7157 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7158 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7159 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7160 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7161 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7162 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7163 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7164 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7166 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7167 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7168 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7169 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7170 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, FORMAT_VideoInfo
, &am_type
);
7171 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7172 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7173 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7174 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Audio
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7175 ok(IsEqualGUID(&am_type
.subtype
, &MFAudioFormat_PCM
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7176 ok(IsEqualGUID(&am_type
.formattype
, &FORMAT_WaveFormatEx
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7177 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
.cbFormat
);
7178 CoTaskMemFree(am_type
.pbFormat
);
7179 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, &am_type
);
7180 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7181 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Audio
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7182 ok(IsEqualGUID(&am_type
.subtype
, &MFAudioFormat_PCM
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7183 ok(IsEqualGUID(&am_type
.formattype
, &GUID_NULL
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7184 ok(am_type
.cbFormat
== 0, "got %lu\n", am_type
.cbFormat
);
7185 CoTaskMemFree(am_type
.pbFormat
);
7186 IMFMediaType_DeleteAllItems(media_type
);
7188 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7189 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7190 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7191 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7192 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, FORMAT_WaveFormatEx
, &am_type
);
7193 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7194 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7195 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7196 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Video
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7197 ok(IsEqualGUID(&am_type
.subtype
, &MEDIASUBTYPE_RGB32
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7198 ok(IsEqualGUID(&am_type
.formattype
, &FORMAT_VideoInfo
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7199 ok(am_type
.cbFormat
== sizeof(VIDEOINFOHEADER
), "got %lu\n", am_type
.cbFormat
);
7200 CoTaskMemFree(am_type
.pbFormat
);
7201 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, &am_type
);
7202 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7203 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Video
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7204 ok(IsEqualGUID(&am_type
.subtype
, &MFVideoFormat_RGB32
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7205 ok(IsEqualGUID(&am_type
.formattype
, &GUID_NULL
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7206 ok(am_type
.cbFormat
== 0, "got %lu\n", am_type
.cbFormat
);
7207 CoTaskMemFree(am_type
.pbFormat
);
7208 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, FORMAT_VideoInfo
, &am_type
);
7209 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7210 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Video
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7211 ok(IsEqualGUID(&am_type
.subtype
, &MEDIASUBTYPE_RGB32
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7212 ok(IsEqualGUID(&am_type
.formattype
, &FORMAT_VideoInfo
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7213 ok(am_type
.cbFormat
== sizeof(VIDEOINFOHEADER
), "got %lu\n", am_type
.cbFormat
);
7214 CoTaskMemFree(am_type
.pbFormat
);
7215 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, FORMAT_VideoInfo2
, &am_type
);
7216 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7217 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Video
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7218 ok(IsEqualGUID(&am_type
.subtype
, &MEDIASUBTYPE_RGB32
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7219 ok(IsEqualGUID(&am_type
.formattype
, &FORMAT_VideoInfo2
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7220 ok(am_type
.cbFormat
== sizeof(VIDEOINFOHEADER2
), "got %lu\n", am_type
.cbFormat
);
7221 CoTaskMemFree(am_type
.pbFormat
);
7222 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, FORMAT_MFVideoFormat
, &am_type
);
7223 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7224 ok(IsEqualGUID(&am_type
.majortype
, &MFMediaType_Video
), "got %s.\n", debugstr_guid(&am_type
.majortype
));
7225 ok(IsEqualGUID(&am_type
.subtype
, &MFVideoFormat_RGB32
), "got %s.\n", debugstr_guid(&am_type
.subtype
));
7226 ok(IsEqualGUID(&am_type
.formattype
, &FORMAT_MFVideoFormat
), "got %s.\n", debugstr_guid(&am_type
.formattype
));
7227 ok(am_type
.cbFormat
== sizeof(MFVIDEOFORMAT
), "got %lu\n", am_type
.cbFormat
);
7228 CoTaskMemFree(am_type
.pbFormat
);
7231 /* test WAVEFORMATEX mapping */
7233 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7234 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7235 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7236 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7237 hr
= IMFMediaType_SetBlob(media_type
, &MF_MT_USER_DATA
, dummy_user_data
, sizeof(dummy_user_data
));
7238 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7239 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7240 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7241 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
) + sizeof(dummy_user_data
), "got %lu\n", am_type
.cbFormat
);
7242 wave_format
= (WAVEFORMATEX
*)am_type
.pbFormat
;
7243 ok(wave_format
->wFormatTag
== WAVE_FORMAT_PCM
, "got %u\n", wave_format
->wFormatTag
);
7244 ok(wave_format
->nChannels
== 0, "got %u\n", wave_format
->nChannels
);
7245 ok(wave_format
->nSamplesPerSec
== 0, "got %lu\n", wave_format
->nSamplesPerSec
);
7246 ok(wave_format
->nAvgBytesPerSec
== 0, "got %lu\n", wave_format
->nAvgBytesPerSec
);
7247 ok(wave_format
->nBlockAlign
== 0, "got %u\n", wave_format
->nBlockAlign
);
7248 ok(wave_format
->wBitsPerSample
== 0, "got %u\n", wave_format
->wBitsPerSample
);
7249 ok(wave_format
->cbSize
== sizeof(dummy_user_data
), "got %u\n", wave_format
->cbSize
);
7250 ok(!memcmp(wave_format
+ 1, dummy_user_data
, sizeof(dummy_user_data
)), "got unexpected data\n");
7251 CoTaskMemFree(am_type
.pbFormat
);
7252 IMFMediaType_DeleteAllItems(media_type
);
7254 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7255 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7256 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7257 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7258 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_NUM_CHANNELS
, 2);
7259 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7260 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7261 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7262 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
.cbFormat
);
7263 wave_format
= (WAVEFORMATEX
*)am_type
.pbFormat
;
7264 ok(wave_format
->wFormatTag
== WAVE_FORMAT_PCM
, "got %u\n", wave_format
->wFormatTag
);
7265 ok(wave_format
->nChannels
== 2, "got %u\n", wave_format
->nChannels
);
7266 ok(wave_format
->cbSize
== 0, "got %u\n", wave_format
->cbSize
);
7267 CoTaskMemFree(am_type
.pbFormat
);
7268 IMFMediaType_DeleteAllItems(media_type
);
7270 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7271 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7272 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7273 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7274 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_NUM_CHANNELS
, 2);
7275 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7276 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_BITS_PER_SAMPLE
, 16);
7277 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7278 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7279 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7280 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
.cbFormat
);
7281 wave_format
= (WAVEFORMATEX
*)am_type
.pbFormat
;
7282 ok(wave_format
->wFormatTag
== WAVE_FORMAT_PCM
, "got %u\n", wave_format
->wFormatTag
);
7283 ok(wave_format
->wBitsPerSample
== 16, "got %u\n", wave_format
->wBitsPerSample
);
7284 ok(wave_format
->nBlockAlign
== 0, "got %u\n", wave_format
->nBlockAlign
);
7285 ok(wave_format
->cbSize
== 0, "got %u\n", wave_format
->cbSize
);
7286 CoTaskMemFree(am_type
.pbFormat
);
7287 IMFMediaType_DeleteAllItems(media_type
);
7289 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7290 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7291 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7292 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7293 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_BLOCK_ALIGNMENT
, 16);
7294 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7295 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7296 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7297 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
.cbFormat
);
7298 wave_format
= (WAVEFORMATEX
*)am_type
.pbFormat
;
7299 ok(wave_format
->wFormatTag
== WAVE_FORMAT_PCM
, "got %u\n", wave_format
->wFormatTag
);
7300 ok(wave_format
->nBlockAlign
== 16, "got %u\n", wave_format
->nBlockAlign
);
7301 ok(wave_format
->cbSize
== 0, "got %u\n", wave_format
->cbSize
);
7302 CoTaskMemFree(am_type
.pbFormat
);
7303 IMFMediaType_DeleteAllItems(media_type
);
7305 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7306 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7307 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7308 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7309 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_SAMPLES_PER_SECOND
, 44100);
7310 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7311 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7312 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7313 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
.cbFormat
);
7314 wave_format
= (WAVEFORMATEX
*)am_type
.pbFormat
;
7315 ok(wave_format
->wFormatTag
== WAVE_FORMAT_PCM
, "got %u\n", wave_format
->wFormatTag
);
7316 ok(wave_format
->nSamplesPerSec
== 44100, "got %lu\n", wave_format
->nSamplesPerSec
);
7317 ok(wave_format
->cbSize
== 0, "got %u\n", wave_format
->cbSize
);
7318 CoTaskMemFree(am_type
.pbFormat
);
7319 IMFMediaType_DeleteAllItems(media_type
);
7321 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7322 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7323 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7324 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7325 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_AVG_BYTES_PER_SECOND
, 176400);
7326 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7327 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7328 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7329 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
.cbFormat
);
7330 wave_format
= (WAVEFORMATEX
*)am_type
.pbFormat
;
7331 ok(wave_format
->wFormatTag
== WAVE_FORMAT_PCM
, "got %u\n", wave_format
->wFormatTag
);
7332 ok(wave_format
->nAvgBytesPerSec
== 176400, "got %lu\n", wave_format
->nAvgBytesPerSec
);
7333 ok(wave_format
->cbSize
== 0, "got %u\n", wave_format
->cbSize
);
7334 CoTaskMemFree(am_type
.pbFormat
);
7335 IMFMediaType_DeleteAllItems(media_type
);
7337 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7338 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7339 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7340 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7341 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_NUM_CHANNELS
, 3);
7342 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7343 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7344 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7345 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEXTENSIBLE
), "got %lu\n", am_type
.cbFormat
);
7346 wave_format_ext
= (WAVEFORMATEXTENSIBLE
*)am_type
.pbFormat
;
7347 ok(wave_format_ext
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
, "got %u\n", wave_format_ext
->Format
.wFormatTag
);
7348 ok(wave_format_ext
->Format
.nChannels
== 3, "got %u\n", wave_format_ext
->Format
.nChannels
);
7349 ok(IsEqualGUID(&wave_format_ext
->SubFormat
, &MFAudioFormat_PCM
),
7350 "got %s\n", debugstr_guid(&wave_format_ext
->SubFormat
));
7351 ok(wave_format_ext
->dwChannelMask
== 7, "got %#lx\n", wave_format_ext
->dwChannelMask
);
7352 ok(wave_format_ext
->Samples
.wSamplesPerBlock
== 0, "got %u\n",
7353 wave_format_ext
->Samples
.wSamplesPerBlock
);
7354 ok(wave_format_ext
->Format
.cbSize
== sizeof(*wave_format_ext
) - sizeof(*wave_format
),
7355 "got %u\n", wave_format_ext
->Format
.cbSize
);
7356 CoTaskMemFree(am_type
.pbFormat
);
7357 IMFMediaType_DeleteAllItems(media_type
);
7359 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7360 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7361 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7362 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7363 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_CHANNEL_MASK
, 3);
7364 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7365 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7366 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7367 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEXTENSIBLE
), "got %lu\n", am_type
.cbFormat
);
7368 wave_format_ext
= (WAVEFORMATEXTENSIBLE
*)am_type
.pbFormat
;
7369 ok(wave_format_ext
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
,
7370 "got %u\n", wave_format_ext
->Format
.wFormatTag
);
7371 ok(IsEqualGUID(&wave_format_ext
->SubFormat
, &MFAudioFormat_PCM
),
7372 "got %s\n", debugstr_guid(&wave_format_ext
->SubFormat
));
7373 ok(wave_format_ext
->dwChannelMask
== 3, "got %#lx\n", wave_format_ext
->dwChannelMask
);
7374 ok(wave_format_ext
->Samples
.wSamplesPerBlock
== 0, "got %u\n",
7375 wave_format_ext
->Samples
.wSamplesPerBlock
);
7376 ok(wave_format_ext
->Format
.cbSize
== sizeof(*wave_format_ext
) - sizeof(*wave_format
),
7377 "got %u\n", wave_format_ext
->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_VALID_BITS_PER_SAMPLE
, 3);
7386 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7387 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AUDIO_SAMPLES_PER_BLOCK
, 4);
7388 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7389 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7390 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7391 ok(am_type
.cbFormat
== sizeof(WAVEFORMATEXTENSIBLE
), "got %lu\n", am_type
.cbFormat
);
7392 wave_format_ext
= (WAVEFORMATEXTENSIBLE
*)am_type
.pbFormat
;
7393 ok(wave_format_ext
->Format
.wFormatTag
== WAVE_FORMAT_EXTENSIBLE
,
7394 "got %u\n", wave_format_ext
->Format
.wFormatTag
);
7395 ok(IsEqualGUID(&wave_format_ext
->SubFormat
, &MFAudioFormat_PCM
),
7396 "got %s\n", debugstr_guid(&wave_format_ext
->SubFormat
));
7397 ok(wave_format_ext
->dwChannelMask
== 0, "got %#lx\n", wave_format_ext
->dwChannelMask
);
7398 ok(wave_format_ext
->Samples
.wSamplesPerBlock
== 4, "got %u\n",
7399 wave_format_ext
->Samples
.wSamplesPerBlock
);
7400 ok(wave_format_ext
->Format
.cbSize
== sizeof(*wave_format_ext
) - sizeof(*wave_format
),
7401 "got %u\n", wave_format_ext
->Format
.cbSize
);
7402 CoTaskMemFree(am_type
.pbFormat
);
7403 IMFMediaType_DeleteAllItems(media_type
);
7406 /* test VIDEOINFOHEADER mapping */
7408 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7409 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7410 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7411 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7412 hr
= IMFMediaType_SetBlob(media_type
, &MF_MT_USER_DATA
, dummy_user_data
, sizeof(dummy_user_data
));
7413 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7414 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7415 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7416 ok(am_type
.cbFormat
== sizeof(VIDEOINFOHEADER
) + sizeof(dummy_user_data
), "got %lu\n", am_type
.cbFormat
);
7417 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7418 ok(video_info
->rcSource
.right
== 0, "got %lu\n", video_info
->rcSource
.right
);
7419 ok(video_info
->rcSource
.bottom
== 0, "got %lu\n", video_info
->rcSource
.bottom
);
7420 ok(video_info
->rcTarget
.right
== 0, "got %lu\n", video_info
->rcTarget
.right
);
7421 ok(video_info
->rcTarget
.bottom
== 0, "got %lu\n", video_info
->rcTarget
.bottom
);
7422 ok(video_info
->dwBitRate
== 0, "got %lu\n", video_info
->dwBitRate
);
7423 ok(video_info
->dwBitErrorRate
== 0, "got %lu\n", video_info
->dwBitErrorRate
);
7424 ok(video_info
->AvgTimePerFrame
== 0, "got %I64d\n", video_info
->AvgTimePerFrame
);
7425 ok(video_info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
) + sizeof(dummy_user_data
),
7426 "got %lu\n", video_info
->bmiHeader
.biSize
);
7427 ok(video_info
->bmiHeader
.biWidth
== 0, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7428 ok(video_info
->bmiHeader
.biHeight
== 0, "got %lu\n", video_info
->bmiHeader
.biHeight
);
7429 ok(video_info
->bmiHeader
.biPlanes
== 1, "got %u\n", video_info
->bmiHeader
.biPlanes
);
7430 ok(video_info
->bmiHeader
.biBitCount
== 32, "got %u\n", video_info
->bmiHeader
.biBitCount
);
7431 ok(video_info
->bmiHeader
.biCompression
== BI_RGB
, "got %lu\n", video_info
->bmiHeader
.biCompression
);
7432 ok(video_info
->bmiHeader
.biSizeImage
== 0, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7433 ok(!memcmp(video_info
+ 1, dummy_user_data
, sizeof(dummy_user_data
)),
7434 "got unexpected data\n");
7435 CoTaskMemFree(am_type
.pbFormat
);
7436 IMFMediaType_DeleteAllItems(media_type
);
7438 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7439 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7440 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7441 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7442 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, 1);
7443 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7444 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7445 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7446 ok(am_type
.bFixedSizeSamples
== 1, "got %u.\n", am_type
.bFixedSizeSamples
);
7447 CoTaskMemFree(am_type
.pbFormat
);
7448 IMFMediaType_DeleteAllItems(media_type
);
7450 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7451 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7452 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7453 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7454 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, 123456);
7455 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7456 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7457 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7458 ok(am_type
.lSampleSize
== 123456, "got %lu.\n", am_type
.lSampleSize
);
7459 CoTaskMemFree(am_type
.pbFormat
);
7460 IMFMediaType_DeleteAllItems(media_type
);
7462 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7463 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7464 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7465 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7466 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7467 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7468 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7469 ok(video_info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
), "got %lu\n", video_info
->bmiHeader
.biSize
);
7470 ok(video_info
->bmiHeader
.biBitCount
== 32, "got %u\n", video_info
->bmiHeader
.biBitCount
);
7471 ok(video_info
->bmiHeader
.biCompression
== BI_RGB
, "got %lu\n", video_info
->bmiHeader
.biCompression
);
7472 CoTaskMemFree(am_type
.pbFormat
);
7473 IMFMediaType_DeleteAllItems(media_type
);
7475 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7476 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7477 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB565
);
7478 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7479 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7480 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7481 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7482 ok(video_info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
), "got %lu\n", video_info
->bmiHeader
.biSize
);
7483 ok(video_info
->bmiHeader
.biBitCount
== 16, "got %u\n", video_info
->bmiHeader
.biBitCount
);
7484 ok(video_info
->bmiHeader
.biCompression
== BI_BITFIELDS
, "got %lu\n", video_info
->bmiHeader
.biCompression
);
7485 CoTaskMemFree(am_type
.pbFormat
);
7486 IMFMediaType_DeleteAllItems(media_type
);
7488 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7489 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7490 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_NV12
);
7491 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7492 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7493 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7494 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7495 ok(video_info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
), "got %lu\n", video_info
->bmiHeader
.biSize
);
7496 ok(video_info
->bmiHeader
.biBitCount
== 12, "got %u\n", video_info
->bmiHeader
.biBitCount
);
7497 ok(video_info
->bmiHeader
.biCompression
== MFVideoFormat_NV12
.Data1
, "got %lu\n", video_info
->bmiHeader
.biCompression
);
7498 CoTaskMemFree(am_type
.pbFormat
);
7499 IMFMediaType_DeleteAllItems(media_type
);
7501 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7502 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7503 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_WMV2
);
7504 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7505 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7506 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7507 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7508 ok(video_info
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
), "got %lu\n", video_info
->bmiHeader
.biSize
);
7509 ok(video_info
->bmiHeader
.biBitCount
== 0, "got %u\n", video_info
->bmiHeader
.biBitCount
);
7510 ok(video_info
->bmiHeader
.biCompression
== MFVideoFormat_WMV2
.Data1
, "got %lu\n", video_info
->bmiHeader
.biCompression
);
7511 CoTaskMemFree(am_type
.pbFormat
);
7512 IMFMediaType_DeleteAllItems(media_type
);
7514 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7515 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7516 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_NV12
);
7517 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7518 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_RATE
, (UINT64
)123 << 32 | 456);
7519 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7520 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7521 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7522 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7523 ok(video_info
->AvgTimePerFrame
== 37073171, "got %I64d\n", video_info
->AvgTimePerFrame
);
7524 CoTaskMemFree(am_type
.pbFormat
);
7525 IMFMediaType_DeleteAllItems(media_type
);
7527 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7528 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7529 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_NV12
);
7530 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7531 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AVG_BITRATE
, 123456);
7532 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7533 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_AVG_BIT_ERROR_RATE
, 654321);
7534 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7535 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7536 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7537 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7538 ok(video_info
->dwBitRate
== 123456, "got %lu\n", video_info
->dwBitRate
);
7539 ok(video_info
->dwBitErrorRate
== 654321, "got %lu\n", video_info
->dwBitErrorRate
);
7540 CoTaskMemFree(am_type
.pbFormat
);
7541 IMFMediaType_DeleteAllItems(media_type
);
7543 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7544 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7545 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_NV12
);
7546 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7547 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, 123456);
7548 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7549 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7550 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7551 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7552 ok(video_info
->bmiHeader
.biSizeImage
== 123456, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7553 CoTaskMemFree(am_type
.pbFormat
);
7554 IMFMediaType_DeleteAllItems(media_type
);
7556 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7557 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7558 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7559 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7560 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_SIZE
, (UINT64
)123 << 32 | 456);
7561 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7562 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7563 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7564 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7565 ok(video_info
->bmiHeader
.biWidth
== 123, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7566 ok(video_info
->bmiHeader
.biHeight
== 456, "got %lu\n", video_info
->bmiHeader
.biHeight
);
7567 ok(video_info
->bmiHeader
.biSizeImage
== 123 * 456 * 4, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7568 CoTaskMemFree(am_type
.pbFormat
);
7569 IMFMediaType_DeleteAllItems(media_type
);
7571 /* MF_MT_MINIMUM_DISPLAY_APERTURE has no effect */
7572 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7573 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7574 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7575 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7576 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_SIZE
, (UINT64
)123 << 32 | 456);
7577 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7578 hr
= IMFMediaType_SetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
));
7579 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7580 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, 12345678);
7581 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7582 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7583 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7584 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7585 ok(video_info
->rcSource
.left
== 0, "got %lu\n", video_info
->rcSource
.left
);
7586 ok(video_info
->rcSource
.right
== 0, "got %lu\n", video_info
->rcSource
.right
);
7587 ok(video_info
->rcSource
.top
== 0, "got %lu\n", video_info
->rcSource
.top
);
7588 ok(video_info
->rcSource
.bottom
== 0, "got %lu\n", video_info
->rcSource
.bottom
);
7589 ok(video_info
->rcTarget
.left
== 0, "got %lu\n", video_info
->rcTarget
.left
);
7590 ok(video_info
->rcTarget
.right
== 0, "got %lu\n", video_info
->rcTarget
.right
);
7591 ok(video_info
->rcTarget
.top
== 0, "got %lu\n", video_info
->rcTarget
.top
);
7592 ok(video_info
->rcTarget
.bottom
== 0, "got %lu\n", video_info
->rcTarget
.bottom
);
7593 ok(video_info
->bmiHeader
.biWidth
== 123, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7594 ok(video_info
->bmiHeader
.biHeight
== 456, "got %lu\n", video_info
->bmiHeader
.biHeight
);
7595 ok(video_info
->bmiHeader
.biSizeImage
== 123 * 456 * 4, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7596 CoTaskMemFree(am_type
.pbFormat
);
7597 IMFMediaType_DeleteAllItems(media_type
);
7599 /* MF_MT_DEFAULT_STRIDE / MF_MT_FRAME_SIZE mismatch is translated into rcSource / rcTarget */
7600 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7601 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7602 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7603 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7604 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_SIZE
, (UINT64
)123 << 32 | 456);
7605 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7606 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, -246 * 4);
7607 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7608 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, 12345678);
7609 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7610 hr
= IMFMediaType_SetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
));
7611 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7612 hr
= IMFMediaType_SetBlob(media_type
, &MF_MT_GEOMETRIC_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
));
7613 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7614 hr
= IMFMediaType_SetBlob(media_type
, &MF_MT_PAN_SCAN_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
));
7615 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7616 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_PAN_SCAN_ENABLED
, 1);
7617 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7618 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7619 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7620 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7621 ok(video_info
->rcSource
.left
== 0, "got %lu\n", video_info
->rcSource
.left
);
7622 ok(video_info
->rcSource
.right
== 123, "got %lu\n", video_info
->rcSource
.right
);
7623 ok(video_info
->rcSource
.top
== 0, "got %lu\n", video_info
->rcSource
.top
);
7624 ok(video_info
->rcSource
.bottom
== 456, "got %lu\n", video_info
->rcSource
.bottom
);
7625 ok(video_info
->rcTarget
.left
== 0, "got %lu\n", video_info
->rcTarget
.left
);
7626 ok(video_info
->rcTarget
.right
== 123, "got %lu\n", video_info
->rcTarget
.right
);
7627 ok(video_info
->rcTarget
.top
== 0, "got %lu\n", video_info
->rcTarget
.top
);
7628 ok(video_info
->rcTarget
.bottom
== 456, "got %lu\n", video_info
->rcTarget
.bottom
);
7629 ok(video_info
->bmiHeader
.biWidth
== 246, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7630 ok(video_info
->bmiHeader
.biHeight
== 456, "got %ld\n", video_info
->bmiHeader
.biHeight
);
7631 ok(video_info
->bmiHeader
.biSizeImage
== 246 * 456 * 4, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7632 CoTaskMemFree(am_type
.pbFormat
);
7634 /* positive stride only changes biHeight */
7635 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, 246 * 4);
7636 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7637 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7638 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7639 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7640 ok(video_info
->rcSource
.left
== 0, "got %lu\n", video_info
->rcSource
.left
);
7641 ok(video_info
->rcSource
.right
== 123, "got %lu\n", video_info
->rcSource
.right
);
7642 ok(video_info
->rcSource
.top
== 0, "got %lu\n", video_info
->rcSource
.top
);
7643 ok(video_info
->rcSource
.bottom
== 456, "got %lu\n", video_info
->rcSource
.bottom
);
7644 ok(video_info
->rcTarget
.left
== 0, "got %lu\n", video_info
->rcTarget
.left
);
7645 ok(video_info
->rcTarget
.right
== 123, "got %lu\n", video_info
->rcTarget
.right
);
7646 ok(video_info
->rcTarget
.top
== 0, "got %lu\n", video_info
->rcTarget
.top
);
7647 ok(video_info
->rcTarget
.bottom
== 456, "got %lu\n", video_info
->rcTarget
.bottom
);
7648 ok(video_info
->bmiHeader
.biWidth
== 246, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7649 ok(video_info
->bmiHeader
.biHeight
== -456, "got %ld\n", video_info
->bmiHeader
.biHeight
);
7650 ok(video_info
->bmiHeader
.biSizeImage
== 246 * 456 * 4, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7651 CoTaskMemFree(am_type
.pbFormat
);
7652 IMFMediaType_DeleteAllItems(media_type
);
7654 /* same thing happens with other formats */
7655 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7656 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7657 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_NV12
);
7658 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7659 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_SIZE
, (UINT64
)123 << 32 | 456);
7660 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7661 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, 246);
7662 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7663 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, 12345678);
7664 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7665 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7666 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7667 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7668 ok(video_info
->rcSource
.left
== 0, "got %lu\n", video_info
->rcSource
.left
);
7669 ok(video_info
->rcSource
.right
== 123, "got %lu\n", video_info
->rcSource
.right
);
7670 ok(video_info
->rcSource
.top
== 0, "got %lu\n", video_info
->rcSource
.top
);
7671 ok(video_info
->rcSource
.bottom
== 456, "got %lu\n", video_info
->rcSource
.bottom
);
7672 ok(video_info
->rcTarget
.left
== 0, "got %lu\n", video_info
->rcTarget
.left
);
7673 ok(video_info
->rcTarget
.right
== 123, "got %lu\n", video_info
->rcTarget
.right
);
7674 ok(video_info
->rcTarget
.top
== 0, "got %lu\n", video_info
->rcTarget
.top
);
7675 ok(video_info
->rcTarget
.bottom
== 456, "got %lu\n", video_info
->rcTarget
.bottom
);
7676 ok(video_info
->bmiHeader
.biWidth
== 246, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7677 ok(video_info
->bmiHeader
.biHeight
== 456, "got %ld\n", video_info
->bmiHeader
.biHeight
);
7678 ok(video_info
->bmiHeader
.biSizeImage
== 246 * 456 * 3 / 2, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7679 CoTaskMemFree(am_type
.pbFormat
);
7680 IMFMediaType_DeleteAllItems(media_type
);
7682 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7683 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7684 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7685 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7686 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_SIZE
, (UINT64
)123 << 32 | 456);
7687 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7688 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, -246 * 4);
7689 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7690 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7691 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7692 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7693 ok(video_info
->bmiHeader
.biWidth
== 246, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7694 ok(video_info
->bmiHeader
.biHeight
== 456, "got %ld\n", video_info
->bmiHeader
.biHeight
);
7695 ok(video_info
->bmiHeader
.biSizeImage
== 246 * 456 * 4, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7696 CoTaskMemFree(am_type
.pbFormat
);
7697 IMFMediaType_DeleteAllItems(media_type
);
7699 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7700 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7701 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFVideoFormat_RGB32
);
7702 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7703 hr
= IMFMediaType_SetUINT64(media_type
, &MF_MT_FRAME_SIZE
, (UINT64
)123 << 32 | 456);
7704 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7705 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, 246 * 4);
7706 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7707 hr
= MFInitAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7708 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7709 video_info
= (VIDEOINFOHEADER
*)am_type
.pbFormat
;
7710 ok(video_info
->bmiHeader
.biWidth
== 246, "got %lu\n", video_info
->bmiHeader
.biWidth
);
7711 ok(video_info
->bmiHeader
.biHeight
== -456, "got %ld\n", video_info
->bmiHeader
.biHeight
);
7712 ok(video_info
->bmiHeader
.biSizeImage
== 246 * 456 * 4, "got %lu\n", video_info
->bmiHeader
.biSizeImage
);
7713 CoTaskMemFree(am_type
.pbFormat
);
7714 IMFMediaType_DeleteAllItems(media_type
);
7716 IMFMediaType_Release(media_type
);
7719 static void test_MFCreateAMMediaTypeFromMFMediaType(void)
7721 IMFMediaType
*media_type
;
7722 AM_MEDIA_TYPE
*am_type
;
7725 hr
= MFCreateMediaType(&media_type
);
7726 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
7728 hr
= MFCreateAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7729 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7730 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7731 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7732 hr
= MFCreateAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7733 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7734 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7735 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7736 hr
= MFCreateAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7737 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7739 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7740 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7741 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7742 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7743 hr
= MFCreateAMMediaTypeFromMFMediaType(media_type
, GUID_NULL
, &am_type
);
7744 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7745 ok(IsEqualGUID(&am_type
->majortype
, &MFMediaType_Audio
), "got %s.\n", debugstr_guid(&am_type
->majortype
));
7746 ok(IsEqualGUID(&am_type
->subtype
, &MFAudioFormat_PCM
), "got %s.\n", debugstr_guid(&am_type
->subtype
));
7747 ok(IsEqualGUID(&am_type
->formattype
, &FORMAT_WaveFormatEx
), "got %s.\n", debugstr_guid(&am_type
->formattype
));
7748 ok(am_type
->cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
->cbFormat
);
7749 CoTaskMemFree(am_type
->pbFormat
);
7750 CoTaskMemFree(am_type
);
7752 IMFMediaType_Release(media_type
);
7755 static void test_IMFMediaType_GetRepresentation(void)
7757 WAVEFORMATEX wfx
= {.wFormatTag
= WAVE_FORMAT_PCM
};
7758 IMFMediaType
*media_type
;
7759 AM_MEDIA_TYPE
*am_type
;
7762 hr
= MFCreateMediaType(&media_type
);
7763 ok(hr
== S_OK
, "Failed to create media type, hr %#lx.\n", hr
);
7765 hr
= IMFMediaType_GetRepresentation(media_type
, GUID_NULL
, (void **)&am_type
);
7766 ok(hr
== MF_E_UNSUPPORTED_REPRESENTATION
, "Unexpected hr %#lx.\n", hr
);
7767 hr
= IMFMediaType_GetRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, (void **)&am_type
);
7768 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7769 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7770 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7771 hr
= IMFMediaType_GetRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, (void **)&am_type
);
7772 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7773 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
7774 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7775 hr
= IMFMediaType_GetRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, (void **)&am_type
);
7776 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
7778 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Audio
);
7779 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7780 hr
= IMFMediaType_SetGUID(media_type
, &MF_MT_SUBTYPE
, &MFAudioFormat_PCM
);
7781 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7782 hr
= IMFMediaType_GetRepresentation(media_type
, FORMAT_VideoInfo
, (void **)&am_type
);
7783 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7784 hr
= IMFMediaType_GetRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, (void **)&am_type
);
7785 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7786 ok(IsEqualGUID(&am_type
->majortype
, &MFMediaType_Audio
), "got %s.\n", debugstr_guid(&am_type
->majortype
));
7787 ok(IsEqualGUID(&am_type
->subtype
, &MFAudioFormat_PCM
), "got %s.\n", debugstr_guid(&am_type
->subtype
));
7788 ok(IsEqualGUID(&am_type
->formattype
, &FORMAT_WaveFormatEx
), "got %s.\n", debugstr_guid(&am_type
->formattype
));
7789 ok(am_type
->cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
->cbFormat
);
7790 hr
= IMFMediaType_FreeRepresentation(media_type
, IID_IUnknown
/* invalid format */, am_type
);
7791 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7792 IMFMediaType_Release(media_type
);
7794 hr
= MFCreateAudioMediaType(&wfx
, (IMFAudioMediaType
**)&media_type
);
7795 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7796 hr
= IMFMediaType_GetRepresentation(media_type
, GUID_NULL
, (void **)&am_type
);
7797 ok(hr
== MF_E_UNSUPPORTED_REPRESENTATION
, "Unexpected hr %#lx.\n", hr
);
7798 hr
= IMFMediaType_GetRepresentation(media_type
, FORMAT_VideoInfo
, (void **)&am_type
);
7799 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7800 hr
= IMFMediaType_GetRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, (void **)&am_type
);
7801 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7802 ok(IsEqualGUID(&am_type
->majortype
, &MFMediaType_Audio
), "got %s.\n", debugstr_guid(&am_type
->majortype
));
7803 ok(IsEqualGUID(&am_type
->subtype
, &MFAudioFormat_PCM
), "got %s.\n", debugstr_guid(&am_type
->subtype
));
7804 ok(IsEqualGUID(&am_type
->formattype
, &FORMAT_WaveFormatEx
), "got %s.\n", debugstr_guid(&am_type
->formattype
));
7805 ok(am_type
->cbFormat
== sizeof(WAVEFORMATEX
), "got %lu\n", am_type
->cbFormat
);
7806 hr
= IMFMediaType_FreeRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, am_type
);
7807 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7808 IMFMediaType_Release(media_type
);
7810 hr
= MFCreateVideoMediaTypeFromSubtype(&MFVideoFormat_RGB32
, (IMFVideoMediaType
**)&media_type
);
7811 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7812 hr
= IMFMediaType_GetRepresentation(media_type
, GUID_NULL
, (void **)&am_type
);
7813 ok(hr
== MF_E_UNSUPPORTED_REPRESENTATION
, "Unexpected hr %#lx.\n", hr
);
7814 hr
= IMFMediaType_GetRepresentation(media_type
, FORMAT_WaveFormatEx
, (void **)&am_type
);
7815 ok(hr
== MF_E_UNSUPPORTED_REPRESENTATION
, "Unexpected hr %#lx.\n", hr
);
7816 hr
= IMFMediaType_GetRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, (void **)&am_type
);
7817 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7818 ok(IsEqualGUID(&am_type
->majortype
, &MFMediaType_Video
), "got %s.\n", debugstr_guid(&am_type
->majortype
));
7819 ok(IsEqualGUID(&am_type
->subtype
, &MEDIASUBTYPE_RGB32
), "got %s.\n", debugstr_guid(&am_type
->subtype
));
7820 ok(IsEqualGUID(&am_type
->formattype
, &FORMAT_VideoInfo
), "got %s.\n", debugstr_guid(&am_type
->formattype
));
7821 ok(am_type
->cbFormat
== sizeof(VIDEOINFOHEADER
), "got %lu\n", am_type
->cbFormat
);
7822 hr
= IMFMediaType_FreeRepresentation(media_type
, AM_MEDIA_TYPE_REPRESENTATION
, am_type
);
7823 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7825 IMFMediaType_Release(media_type
);
7828 static void test_MFCreateDXSurfaceBuffer(void)
7830 IDirect3DSurface9
*backbuffer
= NULL
, *surface
;
7831 IDirect3DSwapChain9
*swapchain
;
7832 D3DLOCKED_RECT locked_rect
;
7833 DWORD length
, max_length
;
7834 IDirect3DDevice9
*device
;
7835 IMF2DBuffer2
*_2dbuffer2
;
7836 BOOL value
, broken_test
;
7837 IMFMediaBuffer
*buffer
;
7838 IMF2DBuffer
*_2dbuffer
;
7847 if (!pMFCreateDXSurfaceBuffer
)
7849 win_skip("MFCreateDXSurfaceBuffer is not available.\n");
7853 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
7856 skip("Failed to create a D3D9 object, skipping tests.\n");
7859 window
= create_window();
7860 if (!(device
= create_d3d9_device(d3d
, window
)))
7862 skip("Failed to create a D3D device, skipping tests.\n");
7866 hr
= IDirect3DDevice9_GetSwapChain(device
, 0, &swapchain
);
7867 ok(SUCCEEDED(hr
), "Failed to get the implicit swapchain (%08lx)\n", hr
);
7869 hr
= IDirect3DSwapChain9_GetBackBuffer(swapchain
, 0, D3DBACKBUFFER_TYPE_MONO
, &backbuffer
);
7870 ok(SUCCEEDED(hr
), "Failed to get the back buffer (%08lx)\n", hr
);
7871 ok(backbuffer
!= NULL
, "The back buffer is NULL\n");
7873 IDirect3DSwapChain9_Release(swapchain
);
7875 hr
= pMFCreateDXSurfaceBuffer(&IID_IUnknown
, (IUnknown
*)backbuffer
, FALSE
, &buffer
);
7876 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
7878 hr
= pMFCreateDXSurfaceBuffer(&IID_IDirect3DSurface9
, (IUnknown
*)backbuffer
, FALSE
, &buffer
);
7879 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
7881 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
7882 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
7883 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
7885 /* Surface is accessible. */
7886 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFGetService
, (void **)&gs
);
7887 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7888 hr
= IMFGetService_GetService(gs
, &MR_BUFFER_SERVICE
, &IID_IDirect3DSurface9
, (void **)&surface
);
7889 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7890 ok(surface
== backbuffer
, "Unexpected surface pointer.\n");
7891 IDirect3DSurface9_Release(surface
);
7892 IMFGetService_Release(gs
);
7895 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &max_length
);
7896 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7897 ok(!!max_length
, "Unexpected length %lu.\n", max_length
);
7899 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
7900 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
7901 ok(!length
, "Unexpected length %lu.\n", length
);
7903 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 2 * max_length
);
7904 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
7906 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &length
);
7907 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
7908 ok(length
== 2 * max_length
, "Unexpected length %lu.\n", length
);
7910 hr
= IDirect3DSurface9_LockRect(backbuffer
, &locked_rect
, NULL
, 0);
7911 ok(hr
== S_OK
, "Failed to lock back buffer, hr %#lx.\n", hr
);
7913 /* Cannot lock while the surface is locked. */
7914 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, &length
);
7915 ok(hr
== D3DERR_INVALIDCALL
, "Unexpected hr %#lx.\n", hr
);
7917 hr
= IDirect3DSurface9_UnlockRect(backbuffer
);
7918 ok(hr
== S_OK
, "Failed to unlock back buffer, hr %#lx.\n", hr
);
7920 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, &length
);
7921 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7922 /* Broken on Windows 8 and 10 v1507 */
7923 broken_test
= length
== 0;
7924 ok(length
== max_length
|| broken(broken_test
), "Unexpected length %lu instead of %lu.\n", length
, max_length
);
7926 /* You can lock the surface while the media buffer is locked. */
7927 hr
= IDirect3DSurface9_LockRect(backbuffer
, &locked_rect
, NULL
, 0);
7928 ok(hr
== S_OK
, "Failed to lock back buffer, hr %#lx.\n", hr
);
7930 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, &length
);
7931 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7933 hr
= IMFMediaBuffer_Unlock(buffer
);
7934 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7936 hr
= IDirect3DSurface9_UnlockRect(backbuffer
);
7937 ok(hr
== S_OK
, "Failed to unlock back buffer, hr %#lx.\n", hr
);
7940 hr
= IMFMediaBuffer_Unlock(buffer
);
7941 ok(hr
== S_OK
|| broken(broken_test
), "Unexpected hr %#lx.\n", hr
);
7943 hr
= IMFMediaBuffer_Unlock(buffer
);
7944 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
7947 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
7948 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7950 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
7951 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7952 ok(data
== data2
, "Unexpected pointer.\n");
7954 hr
= IMFMediaBuffer_Unlock(buffer
);
7955 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7957 hr
= IMFMediaBuffer_Unlock(buffer
);
7958 ok(hr
== S_OK
|| broken(broken_test
), "Unexpected hr %#lx.\n", hr
);
7960 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2dbuffer
);
7961 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7964 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, &pitch
);
7965 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
7967 hr
= IDirect3DSurface9_LockRect(backbuffer
, &locked_rect
, NULL
, 0);
7968 ok(hr
== S_OK
, "Failed to lock back buffer, hr %#lx.\n", hr
);
7970 /* Cannot lock the buffer while the surface is locked. */
7971 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
7972 ok(hr
== D3DERR_INVALIDCALL
, "Unexpected hr %#lx.\n", hr
);
7974 hr
= IDirect3DSurface9_UnlockRect(backbuffer
);
7975 ok(hr
== S_OK
, "Failed to unlock back buffer, hr %#lx.\n", hr
);
7977 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
7978 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7980 /* Cannot lock the surface once the buffer is locked. */
7981 hr
= IDirect3DSurface9_LockRect(backbuffer
, &locked_rect
, NULL
, 0);
7982 ok(hr
== D3DERR_INVALIDCALL
, "Unexpected hr %#lx.\n", hr
);
7984 hr
= IMF2DBuffer_GetScanline0AndPitch(_2dbuffer
, &data
, &pitch
);
7985 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7987 hr
= IMFMediaBuffer_Lock(buffer
, &data2
, NULL
, NULL
);
7988 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
7990 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
7991 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7993 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
7994 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7996 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
7997 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
7999 hr
= IMF2DBuffer_Unlock2D(_2dbuffer
);
8000 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
8002 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
8003 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8005 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
8006 ok(hr
== MF_E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
8008 hr
= IMFMediaBuffer_Unlock(buffer
);
8009 ok(hr
== S_OK
|| broken(broken_test
), "Unexpected hr %#lx.\n", hr
);
8011 hr
= IMF2DBuffer_IsContiguousFormat(_2dbuffer
, &value
);
8012 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8013 ok(!value
, "Unexpected return value %d.\n", value
);
8015 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, NULL
);
8016 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
8017 hr
= IMF2DBuffer_GetContiguousLength(_2dbuffer
, &length
);
8018 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8019 ok(length
== max_length
, "Unexpected length %lu.\n", length
);
8021 IMF2DBuffer_Release(_2dbuffer
);
8023 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer2
, (void **)&_2dbuffer2
);
8024 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8026 /* Lock flags are ignored, so writing is allowed when locking for
8027 * reading and viceversa. */
8028 put_d3d9_surface_color(backbuffer
, 0, 0, 0xcdcdcdcd);
8029 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8030 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8031 ok(data
== data2
, "Unexpected scanline pointer.\n");
8032 ok(data
[0] == 0xcd, "Unexpected leading byte.\n");
8033 memset(data
, 0xab, 4);
8034 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8036 color
= get_d3d9_surface_color(backbuffer
, 0, 0);
8037 ok(color
== 0xabababab, "Unexpected leading dword.\n");
8038 put_d3d9_surface_color(backbuffer
, 0, 0, 0xefefefef);
8040 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8041 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8042 ok(data
[0] == 0xef, "Unexpected leading byte.\n");
8043 memset(data
, 0x89, 4);
8044 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8046 color
= get_d3d9_surface_color(backbuffer
, 0, 0);
8047 ok(color
== 0x89898989, "Unexpected leading dword.\n");
8049 /* Also, flags incompatibilities are not taken into account even
8050 * if a buffer is already locked. */
8051 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8052 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8053 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8054 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8055 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8056 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8057 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8058 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8059 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
8060 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8061 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8062 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8063 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8064 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8065 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8066 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8067 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8068 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8069 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8070 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8072 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8073 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8074 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8075 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8076 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8077 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8078 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8079 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8080 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
8081 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8082 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8083 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8084 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8085 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8086 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8087 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8088 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8089 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8090 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8091 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8093 /* Except when originally locking for writing. */
8094 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8095 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8096 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8097 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8098 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8099 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_LOCKED
), "Unexpected hr %#lx.\n", hr
);
8100 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8101 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_LOCKED
), "Unexpected hr %#lx.\n", hr
);
8102 hr
= IMF2DBuffer_Lock2D(_2dbuffer
, &data
, &pitch
);
8103 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_LOCKED
), "Unexpected hr %#lx.\n", hr
);
8104 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8105 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8106 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8107 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8109 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8110 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
8112 IMF2DBuffer2_Release(_2dbuffer2
);
8114 IMFMediaBuffer_Release(buffer
);
8115 IDirect3DDevice9_Release(device
);
8119 IDirect3DSurface9_Release(backbuffer
);
8120 ok(!IDirect3D9_Release(d3d
), "Unexpected refcount.\n");
8121 DestroyWindow(window
);
8124 static void test_MFCreateTrackedSample(void)
8126 IMFTrackedSample
*tracked_sample
;
8131 if (!pMFCreateTrackedSample
)
8133 win_skip("MFCreateTrackedSample() is not available.\n");
8137 hr
= pMFCreateTrackedSample(&tracked_sample
);
8138 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8140 /* It's actually a sample. */
8141 hr
= IMFTrackedSample_QueryInterface(tracked_sample
, &IID_IMFSample
, (void **)&sample
);
8142 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8144 hr
= IMFTrackedSample_QueryInterface(tracked_sample
, &IID_IUnknown
, (void **)&unk
);
8145 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8146 ok(unk
== (IUnknown
*)sample
, "Unexpected pointer.\n");
8147 IUnknown_Release(unk
);
8149 IMFSample_Release(sample
);
8151 check_interface(tracked_sample
, &IID_IMFDesiredSample
, FALSE
);
8153 IMFTrackedSample_Release(tracked_sample
);
8156 static void test_MFFrameRateToAverageTimePerFrame(void)
8158 static const struct frame_rate_test
8160 unsigned int numerator
;
8161 unsigned int denominator
;
8163 } frame_rate_tests
[] =
8165 { 60000, 1001, 166833 },
8166 { 30000, 1001, 333667 },
8167 { 24000, 1001, 417188 },
8182 hr
= MFFrameRateToAverageTimePerFrame(0, 0, &avgtime
);
8183 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8184 ok(!avgtime
, "Unexpected frame time.\n");
8187 hr
= MFFrameRateToAverageTimePerFrame(0, 1001, &avgtime
);
8188 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8189 ok(!avgtime
, "Unexpected frame time.\n");
8191 for (i
= 0; i
< ARRAY_SIZE(frame_rate_tests
); ++i
)
8194 hr
= MFFrameRateToAverageTimePerFrame(frame_rate_tests
[i
].numerator
,
8195 frame_rate_tests
[i
].denominator
, &avgtime
);
8196 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8197 ok(avgtime
== frame_rate_tests
[i
].avgtime
, "%u: unexpected frame time %s, expected %s.\n",
8198 i
, wine_dbgstr_longlong(avgtime
), wine_dbgstr_longlong(frame_rate_tests
[i
].avgtime
));
8202 static void test_MFAverageTimePerFrameToFrameRate(void)
8204 static const struct frame_rate_test
8206 unsigned int numerator
;
8207 unsigned int denominator
;
8209 } frame_rate_tests
[] =
8211 { 60000, 1001, 166863 },
8212 { 60000, 1001, 166833 },
8213 { 60000, 1001, 166803 },
8215 { 30000, 1001, 333697 },
8216 { 30000, 1001, 333667 },
8217 { 30000, 1001, 333637 },
8219 { 24000, 1001, 417218 },
8220 { 24000, 1001, 417188 },
8221 { 24000, 1001, 417158 },
8243 { 1000000, 25641, 256410 },
8244 { 10000000, 83333, 83333 },
8245 { 1, 10, 100000000 },
8246 { 1, 10, 100000001 },
8247 { 1, 10, 200000000 },
8253 unsigned int i
, numerator
, denominator
;
8256 numerator
= denominator
= 1;
8257 hr
= MFAverageTimePerFrameToFrameRate(0, &numerator
, &denominator
);
8258 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8259 ok(!numerator
&& !denominator
, "Unexpected output %u/%u.\n", numerator
, denominator
);
8261 for (i
= 0; i
< ARRAY_SIZE(frame_rate_tests
); ++i
)
8263 numerator
= denominator
= 12345;
8264 hr
= MFAverageTimePerFrameToFrameRate(frame_rate_tests
[i
].avgtime
, &numerator
, &denominator
);
8265 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8266 ok(numerator
== frame_rate_tests
[i
].numerator
&& denominator
== frame_rate_tests
[i
].denominator
,
8267 "%u: unexpected %u/%u, expected %u/%u.\n", i
, numerator
, denominator
, frame_rate_tests
[i
].numerator
,
8268 frame_rate_tests
[i
].denominator
);
8272 static void test_MFMapDXGIFormatToDX9Format(void)
8274 static const struct format_pair
8276 DXGI_FORMAT dxgi_format
;
8281 { DXGI_FORMAT_R32G32B32A32_FLOAT
, D3DFMT_A32B32G32R32F
},
8282 { DXGI_FORMAT_R16G16B16A16_FLOAT
, D3DFMT_A16B16G16R16F
},
8283 { DXGI_FORMAT_R16G16B16A16_UNORM
, D3DFMT_A16B16G16R16
},
8284 { DXGI_FORMAT_R16G16B16A16_SNORM
, D3DFMT_Q16W16V16U16
},
8285 { DXGI_FORMAT_R32G32_FLOAT
, D3DFMT_G32R32F
},
8286 { DXGI_FORMAT_R10G10B10A2_UNORM
, D3DFMT_A2B10G10R10
},
8287 { DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
, D3DFMT_A8R8G8B8
},
8288 { DXGI_FORMAT_R8G8B8A8_SNORM
, D3DFMT_Q8W8V8U8
},
8289 { DXGI_FORMAT_R16G16_FLOAT
, D3DFMT_G16R16F
},
8290 { DXGI_FORMAT_R16G16_UNORM
, D3DFMT_G16R16
},
8291 { DXGI_FORMAT_R16G16_SNORM
, D3DFMT_V16U16
},
8292 { DXGI_FORMAT_D32_FLOAT
, D3DFMT_D32F_LOCKABLE
},
8293 { DXGI_FORMAT_R32_FLOAT
, D3DFMT_R32F
},
8294 { DXGI_FORMAT_D24_UNORM_S8_UINT
, D3DFMT_D24S8
},
8295 { DXGI_FORMAT_R8G8_SNORM
, D3DFMT_V8U8
},
8296 { DXGI_FORMAT_R16_FLOAT
, D3DFMT_R16F
},
8297 { DXGI_FORMAT_R16_UNORM
, D3DFMT_L16
},
8298 { DXGI_FORMAT_R8_UNORM
, D3DFMT_L8
},
8299 { DXGI_FORMAT_A8_UNORM
, D3DFMT_A8
},
8300 { DXGI_FORMAT_BC1_UNORM
, D3DFMT_DXT1
},
8301 { DXGI_FORMAT_BC1_UNORM_SRGB
, D3DFMT_DXT1
},
8302 { DXGI_FORMAT_BC2_UNORM
, D3DFMT_DXT2
},
8303 { DXGI_FORMAT_BC2_UNORM_SRGB
, D3DFMT_DXT2
},
8304 { DXGI_FORMAT_BC3_UNORM
, D3DFMT_DXT4
},
8305 { DXGI_FORMAT_BC3_UNORM_SRGB
, D3DFMT_DXT4
},
8306 { DXGI_FORMAT_B8G8R8A8_UNORM
, D3DFMT_A8R8G8B8
},
8307 { DXGI_FORMAT_B8G8R8X8_UNORM
, D3DFMT_X8R8G8B8
},
8308 { DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
, D3DFMT_A8R8G8B8
},
8309 { DXGI_FORMAT_B8G8R8X8_UNORM_SRGB
, D3DFMT_X8R8G8B8
},
8310 { DXGI_FORMAT_AYUV
, MAKEFOURCC('A','Y','U','V') },
8311 { DXGI_FORMAT_Y410
, MAKEFOURCC('Y','4','1','0') },
8312 { DXGI_FORMAT_Y416
, MAKEFOURCC('Y','4','1','6') },
8313 { DXGI_FORMAT_NV12
, MAKEFOURCC('N','V','1','2') },
8314 { DXGI_FORMAT_P010
, MAKEFOURCC('P','0','1','0') },
8315 { DXGI_FORMAT_P016
, MAKEFOURCC('P','0','1','6') },
8316 { DXGI_FORMAT_420_OPAQUE
, MAKEFOURCC('4','2','0','O') },
8317 { DXGI_FORMAT_YUY2
, D3DFMT_YUY2
},
8318 { DXGI_FORMAT_Y210
, MAKEFOURCC('Y','2','1','0') },
8319 { DXGI_FORMAT_Y216
, MAKEFOURCC('Y','2','1','6') },
8320 { DXGI_FORMAT_NV11
, MAKEFOURCC('N','V','1','1') },
8321 { DXGI_FORMAT_AI44
, MAKEFOURCC('A','I','4','4') },
8322 { DXGI_FORMAT_IA44
, MAKEFOURCC('I','A','4','4') },
8323 { DXGI_FORMAT_P8
, D3DFMT_P8
},
8324 { DXGI_FORMAT_A8P8
, D3DFMT_A8P8
},
8329 if (!pMFMapDXGIFormatToDX9Format
)
8331 win_skip("MFMapDXGIFormatToDX9Format is not available.\n");
8335 for (i
= 0; i
< ARRAY_SIZE(formats_map
); ++i
)
8337 format
= pMFMapDXGIFormatToDX9Format(formats_map
[i
].dxgi_format
);
8338 ok(format
== formats_map
[i
].d3d9_format
, "Unexpected d3d9 format %#lx, dxgi format %#x.\n", format
, formats_map
[i
].dxgi_format
);
8342 static void test_MFMapDX9FormatToDXGIFormat(void)
8344 static const struct format_pair
8346 DXGI_FORMAT dxgi_format
;
8351 { DXGI_FORMAT_R32G32B32A32_FLOAT
, D3DFMT_A32B32G32R32F
},
8352 { DXGI_FORMAT_R16G16B16A16_FLOAT
, D3DFMT_A16B16G16R16F
},
8353 { DXGI_FORMAT_R16G16B16A16_UNORM
, D3DFMT_A16B16G16R16
},
8354 { DXGI_FORMAT_R16G16B16A16_SNORM
, D3DFMT_Q16W16V16U16
},
8355 { DXGI_FORMAT_R32G32_FLOAT
, D3DFMT_G32R32F
},
8356 { DXGI_FORMAT_R10G10B10A2_UNORM
, D3DFMT_A2B10G10R10
},
8357 { 0, D3DFMT_A2R10G10B10
}, /* doesn't map to DXGI */
8358 { DXGI_FORMAT_R8G8B8A8_SNORM
, D3DFMT_Q8W8V8U8
},
8359 { DXGI_FORMAT_R16G16_FLOAT
, D3DFMT_G16R16F
},
8360 { DXGI_FORMAT_R16G16_UNORM
, D3DFMT_G16R16
},
8361 { DXGI_FORMAT_R16G16_SNORM
, D3DFMT_V16U16
},
8362 { DXGI_FORMAT_D32_FLOAT
, D3DFMT_D32F_LOCKABLE
},
8363 { DXGI_FORMAT_R32_FLOAT
, D3DFMT_R32F
},
8364 { DXGI_FORMAT_D24_UNORM_S8_UINT
, D3DFMT_D24S8
},
8365 { DXGI_FORMAT_R8G8_SNORM
, D3DFMT_V8U8
},
8366 { DXGI_FORMAT_R16_FLOAT
, D3DFMT_R16F
},
8367 { DXGI_FORMAT_R16_UNORM
, D3DFMT_L16
},
8368 { DXGI_FORMAT_R8_UNORM
, D3DFMT_L8
},
8369 { DXGI_FORMAT_A8_UNORM
, D3DFMT_A8
},
8370 { DXGI_FORMAT_BC1_UNORM
, D3DFMT_DXT1
},
8371 { DXGI_FORMAT_BC2_UNORM
, D3DFMT_DXT2
},
8372 { DXGI_FORMAT_BC3_UNORM
, D3DFMT_DXT4
},
8373 { DXGI_FORMAT_B8G8R8A8_UNORM
, D3DFMT_A8R8G8B8
},
8374 { DXGI_FORMAT_B8G8R8X8_UNORM
, D3DFMT_X8R8G8B8
},
8375 { DXGI_FORMAT_AYUV
, MAKEFOURCC('A','Y','U','V') },
8376 { DXGI_FORMAT_Y410
, MAKEFOURCC('Y','4','1','0') },
8377 { DXGI_FORMAT_Y416
, MAKEFOURCC('Y','4','1','6') },
8378 { DXGI_FORMAT_NV12
, MAKEFOURCC('N','V','1','2') },
8379 { DXGI_FORMAT_P010
, MAKEFOURCC('P','0','1','0') },
8380 { DXGI_FORMAT_P016
, MAKEFOURCC('P','0','1','6') },
8381 { DXGI_FORMAT_420_OPAQUE
, MAKEFOURCC('4','2','0','O') },
8382 { DXGI_FORMAT_YUY2
, D3DFMT_YUY2
},
8383 { DXGI_FORMAT_Y210
, MAKEFOURCC('Y','2','1','0') },
8384 { DXGI_FORMAT_Y216
, MAKEFOURCC('Y','2','1','6') },
8385 { DXGI_FORMAT_NV11
, MAKEFOURCC('N','V','1','1') },
8386 { DXGI_FORMAT_AI44
, MAKEFOURCC('A','I','4','4') },
8387 { DXGI_FORMAT_IA44
, MAKEFOURCC('I','A','4','4') },
8388 { DXGI_FORMAT_P8
, D3DFMT_P8
},
8389 { DXGI_FORMAT_A8P8
, D3DFMT_A8P8
},
8394 if (!pMFMapDX9FormatToDXGIFormat
)
8396 win_skip("MFMapDX9FormatToDXGIFormat() is not available.\n");
8400 for (i
= 0; i
< ARRAY_SIZE(formats_map
); ++i
)
8402 format
= pMFMapDX9FormatToDXGIFormat(formats_map
[i
].d3d9_format
);
8403 ok(format
== formats_map
[i
].dxgi_format
, "Unexpected DXGI format %#x, d3d9 format %#lx.\n",
8404 format
, formats_map
[i
].d3d9_format
);
8408 static HRESULT WINAPI
test_notify_callback_QueryInterface(IMFVideoSampleAllocatorNotify
*iface
,
8409 REFIID riid
, void **obj
)
8411 if (IsEqualIID(riid
, &IID_IMFVideoSampleAllocatorNotify
) ||
8412 IsEqualIID(riid
, &IID_IUnknown
))
8415 IMFVideoSampleAllocatorNotify_AddRef(iface
);
8420 return E_NOINTERFACE
;
8423 static ULONG WINAPI
test_notify_callback_AddRef(IMFVideoSampleAllocatorNotify
*iface
)
8428 static ULONG WINAPI
test_notify_callback_Release(IMFVideoSampleAllocatorNotify
*iface
)
8433 static HRESULT WINAPI
test_notify_callback_NotifyRelease(IMFVideoSampleAllocatorNotify
*iface
)
8438 static const IMFVideoSampleAllocatorNotifyVtbl test_notify_callback_vtbl
=
8440 test_notify_callback_QueryInterface
,
8441 test_notify_callback_AddRef
,
8442 test_notify_callback_Release
,
8443 test_notify_callback_NotifyRelease
,
8446 static IMFMediaType
* create_video_type(const GUID
*subtype
)
8448 IMFMediaType
*video_type
;
8451 hr
= MFCreateMediaType(&video_type
);
8452 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8454 hr
= IMFMediaType_SetGUID(video_type
, &MF_MT_MAJOR_TYPE
, &MFMediaType_Video
);
8455 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8457 hr
= IMFMediaType_SetGUID(video_type
, &MF_MT_SUBTYPE
, subtype
);
8458 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8463 static ID3D11Device
*create_d3d11_device(void)
8465 static const D3D_FEATURE_LEVEL default_feature_level
[] =
8467 D3D_FEATURE_LEVEL_11_0
,
8468 D3D_FEATURE_LEVEL_10_1
,
8469 D3D_FEATURE_LEVEL_10_0
,
8471 const D3D_FEATURE_LEVEL
*feature_level
;
8472 unsigned int feature_level_count
;
8473 ID3D11Device
*device
;
8475 feature_level
= default_feature_level
;
8476 feature_level_count
= ARRAY_SIZE(default_feature_level
);
8478 if (SUCCEEDED(pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_HARDWARE
, NULL
, 0,
8479 feature_level
, feature_level_count
, D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
8481 if (SUCCEEDED(pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_WARP
, NULL
, 0,
8482 feature_level
, feature_level_count
, D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
8484 if (SUCCEEDED(pD3D11CreateDevice(NULL
, D3D_DRIVER_TYPE_REFERENCE
, NULL
, 0,
8485 feature_level
, feature_level_count
, D3D11_SDK_VERSION
, &device
, NULL
, NULL
)))
8491 static void update_d3d11_texture(ID3D11Texture2D
*texture
, unsigned int sub_resource_idx
,
8492 const BYTE
*data
, unsigned int src_pitch
)
8494 ID3D11DeviceContext
*immediate_context
;
8495 ID3D11Device
*device
;
8497 ID3D11Texture2D_GetDevice(texture
, &device
);
8498 ID3D11Device_GetImmediateContext(device
, &immediate_context
);
8500 ID3D11DeviceContext_UpdateSubresource(immediate_context
, (ID3D11Resource
*)texture
,
8501 sub_resource_idx
, NULL
, data
, src_pitch
, 0);
8503 ID3D11DeviceContext_Release(immediate_context
);
8504 ID3D11Device_Release(device
);
8507 static ID3D12Device
*create_d3d12_device(void)
8509 ID3D12Device
*device
;
8512 if (!pD3D12CreateDevice
) return NULL
;
8514 hr
= pD3D12CreateDevice(NULL
, D3D_FEATURE_LEVEL_11_0
, &IID_ID3D12Device
, (void **)&device
);
8521 static void test_d3d11_surface_buffer(void)
8523 DWORD max_length
, cur_length
, length
, color
;
8524 BYTE
*data
, *data2
, *buffer_start
;
8525 IMFDXGIBuffer
*dxgi_buffer
;
8526 D3D11_TEXTURE2D_DESC desc
;
8527 IMF2DBuffer2
*_2dbuffer2
;
8528 ID3D11Texture2D
*texture
;
8529 IMF2DBuffer
*_2d_buffer
;
8530 IMFMediaBuffer
*buffer
;
8531 ID3D11Device
*device
;
8532 BYTE buff
[64 * 64 * 4];
8538 if (!pMFCreateDXGISurfaceBuffer
)
8540 win_skip("MFCreateDXGISurfaceBuffer() is not available.\n");
8545 if (!(device
= create_d3d11_device()))
8547 skip("Failed to create a D3D11 device, skipping tests.\n");
8551 memset(&desc
, 0, sizeof(desc
));
8555 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
8556 desc
.SampleDesc
.Count
= 1;
8557 desc
.SampleDesc
.Quality
= 0;
8559 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
8560 ok(hr
== S_OK
, "Failed to create a texture, hr %#lx.\n", hr
);
8562 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 0, FALSE
, &buffer
);
8563 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
8565 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
8566 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
8567 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
8568 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
8571 hr
= IMFMediaBuffer_GetMaxLength(buffer
, &max_length
);
8572 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8573 ok(!!max_length
, "Unexpected length %lu.\n", max_length
);
8575 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &cur_length
);
8576 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
8577 ok(!cur_length
, "Unexpected length %lu.\n", cur_length
);
8579 hr
= IMFMediaBuffer_SetCurrentLength(buffer
, 2 * max_length
);
8580 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
8582 hr
= IMFMediaBuffer_GetCurrentLength(buffer
, &cur_length
);
8583 ok(hr
== S_OK
, "Failed to get length, hr %#lx.\n", hr
);
8584 ok(cur_length
== 2 * max_length
, "Unexpected length %lu.\n", cur_length
);
8586 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
8587 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8589 hr
= IMF2DBuffer_GetContiguousLength(_2d_buffer
, NULL
);
8590 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
8591 hr
= IMF2DBuffer_GetContiguousLength(_2d_buffer
, &length
);
8592 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8593 ok(length
== max_length
, "Unexpected length %lu.\n", length
);
8594 IMF2DBuffer_Release(_2d_buffer
);
8596 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
8597 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
8599 EXPECT_REF(texture
, 2);
8600 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&obj
);
8601 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
8602 EXPECT_REF(texture
, 3);
8603 ok(obj
== (IUnknown
*)texture
, "Unexpected resource pointer.\n");
8604 IUnknown_Release(obj
);
8606 hr
= IMFDXGIBuffer_GetSubresourceIndex(dxgi_buffer
, NULL
);
8607 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
8609 hr
= IMFDXGIBuffer_GetSubresourceIndex(dxgi_buffer
, &index
);
8610 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8611 ok(index
== 0, "Unexpected subresource index.\n");
8613 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, NULL
);
8614 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8616 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, (void *)device
);
8617 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8619 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, (void *)device
);
8620 ok(hr
== HRESULT_FROM_WIN32(ERROR_OBJECT_ALREADY_EXISTS
), "Unexpected hr %#lx.\n", hr
);
8622 hr
= ID3D11Texture2D_GetPrivateData(texture
, &IID_IMFDXGIBuffer
, &size
, &data
);
8623 ok(hr
== DXGI_ERROR_NOT_FOUND
, "Unexpected hr %#lx.\n", hr
);
8625 hr
= IMFDXGIBuffer_GetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, &IID_ID3D11Device
, (void **)&obj
);
8626 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8627 ok(obj
== (IUnknown
*)device
, "Unexpected pointer.\n");
8628 IUnknown_Release(obj
);
8630 hr
= IMFDXGIBuffer_SetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, NULL
);
8631 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8633 hr
= IMFDXGIBuffer_GetUnknown(dxgi_buffer
, &IID_IMFDXGIBuffer
, &IID_IUnknown
, (void **)&obj
);
8634 ok(hr
== MF_E_NOT_FOUND
, "Unexpected hr %#lx.\n", hr
);
8636 IMFDXGIBuffer_Release(dxgi_buffer
);
8638 /* Texture updates. */
8639 color
= get_d3d11_texture_color(texture
, 0, 0);
8640 ok(!color
, "Unexpected texture color %#lx.\n", color
);
8642 max_length
= cur_length
= 0;
8644 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &cur_length
);
8645 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8646 ok(max_length
&& max_length
== cur_length
, "Unexpected length %lu.\n", max_length
);
8647 if (data
) *(DWORD
*)data
= ~0u;
8649 color
= get_d3d11_texture_color(texture
, 0, 0);
8650 ok(!color
, "Unexpected texture color %#lx.\n", color
);
8652 hr
= IMFMediaBuffer_Unlock(buffer
);
8653 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8655 color
= get_d3d11_texture_color(texture
, 0, 0);
8656 ok(color
== ~0u, "Unexpected texture color %#lx.\n", color
);
8658 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &cur_length
);
8659 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8660 ok(*(DWORD
*)data
== ~0u, "Unexpected buffer %#lx.\n", *(DWORD
*)data
);
8662 hr
= IMFMediaBuffer_Unlock(buffer
);
8663 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8665 /* Lock2D()/Unlock2D() */
8666 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
8667 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8669 hr
= IMF2DBuffer_GetScanline0AndPitch(_2d_buffer
, &data2
, &pitch2
);
8670 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
8672 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8673 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8674 ok(!!data
&& pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
8676 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8677 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8678 ok(!!data
&& pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
8680 hr
= IMF2DBuffer_GetScanline0AndPitch(_2d_buffer
, &data2
, &pitch2
);
8681 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8682 ok(data2
== data
&& pitch2
== pitch
, "Unexpected data/pitch.\n");
8684 hr
= IMFMediaBuffer_Lock(buffer
, &data
, &max_length
, &cur_length
);
8685 ok(hr
== MF_E_INVALIDREQUEST
, "Unexpected hr %#lx.\n", hr
);
8687 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
8688 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8690 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
8691 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8693 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
8694 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
8696 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
8697 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8699 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8700 ok(hr
== MF_E_UNEXPECTED
, "Unexpected hr %#lx.\n", hr
);
8702 hr
= IMFMediaBuffer_Unlock(buffer
);
8703 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8705 IMF2DBuffer_Release(_2d_buffer
);
8707 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer2
, (void **)&_2dbuffer2
);
8708 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8710 /* Lock flags are honored, so reads and writes are discarded if
8711 * the flags are not correct. Also, previous content is discarded
8712 * when locking for writing and not for reading. */
8713 put_d3d11_texture_color(texture
, 0, 0, 0xcdcdcdcd);
8714 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8715 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8716 ok(data
== data2
, "Unexpected scanline pointer.\n");
8717 ok(*(DWORD
*)data
== 0xcdcdcdcd, "Unexpected leading dword %#lx.\n", *(DWORD
*)data
);
8718 memset(data
, 0xab, 4);
8719 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8721 color
= get_d3d11_texture_color(texture
, 0, 0);
8722 ok(color
== 0xcdcdcdcd, "Unexpected leading dword %#lx.\n", color
);
8723 put_d3d11_texture_color(texture
, 0, 0, 0xefefefef);
8725 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8726 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8727 ok(*(DWORD
*)data
!= 0xefefefef, "Unexpected leading dword.\n");
8728 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8730 color
= get_d3d11_texture_color(texture
, 0, 0);
8731 ok(color
!= 0xefefefef, "Unexpected leading dword.\n");
8733 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8734 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8735 ok(*(DWORD
*)data
!= 0xefefefef, "Unexpected leading dword.\n");
8736 memset(data
, 0x89, 4);
8737 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8739 color
= get_d3d11_texture_color(texture
, 0, 0);
8740 ok(color
== 0x89898989, "Unexpected leading dword %#lx.\n", color
);
8742 /* When relocking for writing, stores are committed even if they
8743 * were issued before relocking. */
8744 put_d3d11_texture_color(texture
, 0, 0, 0xcdcdcdcd);
8745 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8746 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8747 memset(data
, 0xab, 4);
8748 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8749 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8750 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8751 IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8753 color
= get_d3d11_texture_color(texture
, 0, 0);
8754 ok(color
== 0xabababab, "Unexpected leading dword %#lx.\n", color
);
8756 /* Flags incompatibilities. */
8757 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8758 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8759 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8760 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8761 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8762 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8763 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8764 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8765 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8766 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8767 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8768 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8769 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8770 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8771 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8772 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8773 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8774 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8775 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8776 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8778 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8779 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8780 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8781 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8782 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8783 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8784 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8785 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8786 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8787 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8788 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8789 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8790 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8791 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8792 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8793 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8794 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8795 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8796 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8797 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8799 /* Except when originally locking for writing. */
8800 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8801 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8802 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Write
, &data
, &pitch
, &data2
, &length
);
8803 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8804 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_ReadWrite
, &data
, &pitch
, &data2
, &length
);
8805 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_LOCKED
), "Unexpected hr %#lx.\n", hr
);
8806 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &data2
, &length
);
8807 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_LOCKED
), "Unexpected hr %#lx.\n", hr
);
8808 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8809 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_LOCKED
), "Unexpected hr %#lx.\n", hr
);
8810 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8811 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8812 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8813 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8815 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8816 ok(hr
== HRESULT_FROM_WIN32(ERROR_WAS_UNLOCKED
), "Unexpected hr %#lx.\n", hr
);
8818 IMF2DBuffer2_Release(_2dbuffer2
);
8819 IMFMediaBuffer_Release(buffer
);
8822 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 0, TRUE
, &buffer
);
8823 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
8825 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
8826 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8828 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8829 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8830 ok(!!data
&& pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
8832 hr
= IMF2DBuffer_GetScanline0AndPitch(_2d_buffer
, &data2
, &pitch2
);
8833 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8834 ok(data2
== data
&& pitch2
== pitch
, "Unexpected data/pitch.\n");
8836 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
8837 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8839 IMF2DBuffer_Release(_2d_buffer
);
8840 IMFMediaBuffer_Release(buffer
);
8842 ID3D11Texture2D_Release(texture
);
8844 memset(&desc
, 0, sizeof(desc
));
8849 desc
.Format
= DXGI_FORMAT_NV12
;
8850 desc
.SampleDesc
.Count
= 1;
8851 desc
.SampleDesc
.Quality
= 0;
8853 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
8856 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 0, FALSE
, &buffer
);
8857 ok(hr
== S_OK
, "got %#lx.\n", hr
);
8858 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer2
, (void **)&_2dbuffer2
);
8859 ok(hr
== S_OK
, "got %#lx.\n", hr
);
8861 hr
= IMF2DBuffer2_Lock2DSize(_2dbuffer2
, MF2DBuffer_LockFlags_Read
, &data
, &pitch
, &buffer_start
, &length
);
8862 ok(hr
== S_OK
, "got %#lx.\n", hr
);
8864 ok(pitch
>= desc
.Width
, "got %ld.\n", pitch
);
8865 ok(length
== pitch
* desc
.Height
* 3 / 2, "got %lu.\n", length
);
8867 hr
= IMF2DBuffer2_Unlock2D(_2dbuffer2
);
8868 ok(hr
== S_OK
, "got %#lx.\n", hr
);
8870 IMF2DBuffer2_Release(_2dbuffer2
);
8871 IMFMediaBuffer_Release(buffer
);
8872 ID3D11Texture2D_Release(texture
);
8876 win_skip("Failed to create NV12 texture, hr %#lx, skipping test.\n", hr
);
8877 ID3D11Device_Release(device
);
8881 /* Subresource index 1.
8882 * When WARP d3d11 device is used, this test leaves the device in a broken state, so it should
8884 memset(&desc
, 0, sizeof(desc
));
8888 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
8889 desc
.SampleDesc
.Count
= 1;
8890 desc
.SampleDesc
.Quality
= 0;
8892 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
8893 ok(hr
== S_OK
, "Failed to create a texture, hr %#lx.\n", hr
);
8895 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 1, FALSE
, &buffer
);
8896 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
8898 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer
, (void **)&_2d_buffer
);
8899 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8901 /* Pitch reflects top level. */
8902 memset(buff
, 0, sizeof(buff
));
8903 *(DWORD
*)buff
= 0xff00ff00;
8904 update_d3d11_texture(texture
, 1, buff
, 64 * 4);
8906 hr
= IMF2DBuffer_Lock2D(_2d_buffer
, &data
, &pitch
);
8907 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8908 ok(pitch
== desc
.Width
* 4, "Unexpected pitch %ld.\n", pitch
);
8909 ok(*(DWORD
*)data
== 0xff00ff00, "Unexpected color %#lx.\n", *(DWORD
*)data
);
8911 hr
= IMF2DBuffer_Unlock2D(_2d_buffer
);
8912 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8914 IMF2DBuffer_Release(_2d_buffer
);
8915 IMFMediaBuffer_Release(buffer
);
8916 ID3D11Texture2D_Release(texture
);
8918 ID3D11Device_Release(device
);
8921 static void test_d3d12_surface_buffer(void)
8923 IMFDXGIBuffer
*dxgi_buffer
;
8924 D3D12_HEAP_PROPERTIES heap_props
;
8925 D3D12_RESOURCE_DESC desc
;
8926 ID3D12Resource
*resource
;
8927 IMFMediaBuffer
*buffer
;
8928 unsigned int refcount
;
8929 ID3D12Device
*device
;
8934 if (!(device
= create_d3d12_device()))
8936 skip("Failed to create a D3D12 device, skipping tests.\n");
8940 memset(&heap_props
, 0, sizeof(heap_props
));
8941 heap_props
.Type
= D3D12_HEAP_TYPE_DEFAULT
;
8943 memset(&desc
, 0, sizeof(desc
));
8944 desc
.Dimension
= D3D12_RESOURCE_DIMENSION_TEXTURE2D
;
8948 desc
.DepthOrArraySize
= 1;
8950 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
8951 desc
.SampleDesc
.Count
= 1;
8952 desc
.SampleDesc
.Quality
= 0;
8953 desc
.Layout
= D3D12_TEXTURE_LAYOUT_UNKNOWN
;
8954 desc
.Flags
= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET
;
8956 hr
= ID3D12Device_CreateCommittedResource(device
, &heap_props
, D3D12_HEAP_FLAG_NONE
,
8957 &desc
, D3D12_RESOURCE_STATE_RENDER_TARGET
, NULL
, &IID_ID3D12Resource
, (void **)&resource
);
8958 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
8960 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D12Resource
, (IUnknown
*)resource
, 0, FALSE
, &buffer
);
8961 if (hr
== E_INVALIDARG
)
8964 win_skip("D3D12 resource buffers are not supported.\n");
8967 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
8971 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
8972 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
8973 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
8974 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
8976 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
8977 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
8979 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D12Resource
, (void **)&obj
);
8980 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
8981 ok(obj
== (IUnknown
*)resource
, "Unexpected resource pointer.\n");
8982 IUnknown_Release(obj
);
8984 IMFDXGIBuffer_Release(dxgi_buffer
);
8985 IMFMediaBuffer_Release(buffer
);
8989 ID3D12Resource_Release(resource
);
8990 refcount
= ID3D12Device_Release(device
);
8991 ok(!refcount
, "Unexpected device refcount %u.\n", refcount
);
8994 static void test_sample_allocator_sysmem(void)
8996 IMFVideoSampleAllocatorNotify test_notify
= { &test_notify_callback_vtbl
};
8997 IMFMediaType
*media_type
, *video_type
, *video_type2
;
8998 IMFVideoSampleAllocatorCallback
*allocator_cb
;
8999 IMFVideoSampleAllocatorEx
*allocatorex
;
9000 IMFVideoSampleAllocator
*allocator
;
9001 IMFSample
*sample
, *sample2
;
9002 IMFAttributes
*attributes
;
9003 IMFMediaBuffer
*buffer
;
9004 LONG refcount
, count
;
9009 if (!pMFCreateVideoSampleAllocatorEx
)
9012 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IUnknown
, (void **)&unk
);
9013 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9015 check_interface(unk
, &IID_IMFVideoSampleAllocator
, TRUE
);
9016 check_interface(unk
, &IID_IMFVideoSampleAllocatorEx
, TRUE
);
9017 check_interface(unk
, &IID_IMFVideoSampleAllocatorCallback
, TRUE
);
9019 IUnknown_Release(unk
);
9021 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
9022 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9024 hr
= IMFVideoSampleAllocator_QueryInterface(allocator
, &IID_IMFVideoSampleAllocatorCallback
, (void **)&allocator_cb
);
9025 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9027 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, NULL
);
9028 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9030 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, &test_notify
);
9031 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9033 hr
= IMFVideoSampleAllocatorCallback_SetCallback(allocator_cb
, NULL
);
9034 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9036 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, NULL
);
9037 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
9040 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
9041 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9042 ok(!count
, "Unexpected count %ld.\n", count
);
9044 hr
= IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator
);
9045 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9047 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
9048 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
9050 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, NULL
);
9051 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9053 hr
= MFCreateMediaType(&media_type
);
9054 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9056 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, media_type
);
9057 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
9059 video_type
= create_video_type(&MFVideoFormat_RGB32
);
9060 video_type2
= create_video_type(&MFVideoFormat_RGB32
);
9062 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, video_type
);
9063 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
9065 /* Frame size is required. */
9066 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 240);
9067 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9069 hr
= IMFMediaType_SetUINT64(video_type2
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 240);
9070 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9072 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 0, video_type
);
9073 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9075 EXPECT_REF(video_type
, 1);
9076 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
9077 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9078 EXPECT_REF(video_type
, 2);
9080 hr
= IMFMediaType_SetUINT64(video_type2
, &IID_IUnknown
, (UINT64
) 320 << 32 | 240);
9081 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9083 /* Setting identical type does not replace it. */
9084 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type2
);
9085 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9086 EXPECT_REF(video_type
, 2);
9087 EXPECT_REF(video_type2
, 1);
9089 hr
= IMFMediaType_SetUINT64(video_type2
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
9090 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9092 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type2
);
9093 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9094 EXPECT_REF(video_type2
, 2);
9095 EXPECT_REF(video_type
, 1);
9097 /* Modify referenced type. */
9098 hr
= IMFMediaType_SetUINT64(video_type2
, &MF_MT_FRAME_SIZE
, (UINT64
) 320 << 32 | 64);
9099 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9101 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
9102 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9103 EXPECT_REF(video_type
, 2);
9104 EXPECT_REF(video_type2
, 1);
9107 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
9108 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9109 ok(count
== 1, "Unexpected count %ld.\n", count
);
9112 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
9113 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9114 refcount
= get_refcount(sample
);
9116 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
9117 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9118 ok(!count
, "Unexpected count %ld.\n", count
);
9120 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample2
);
9121 ok(hr
== MF_E_SAMPLEALLOCATOR_EMPTY
, "Unexpected hr %#lx.\n", hr
);
9123 /* Reinitialize with active sample. */
9124 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 2, video_type
);
9125 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9126 ok(refcount
== get_refcount(sample
), "Unexpected refcount %lu.\n", get_refcount(sample
));
9127 EXPECT_REF(video_type
, 2);
9129 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
9130 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9132 ok(!count
, "Unexpected count %ld.\n", count
);
9134 check_interface(sample
, &IID_IMFTrackedSample
, TRUE
);
9135 check_interface(sample
, &IID_IMFDesiredSample
, FALSE
);
9137 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
9138 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9140 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
9141 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
9142 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
9143 check_interface(buffer
, &IID_IMFDXGIBuffer
, FALSE
);
9145 IMFMediaBuffer_Release(buffer
);
9147 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
9148 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9149 ok(buffer_count
== 1, "Unexpected buffer count %lu.\n", buffer_count
);
9151 IMFSample_Release(sample
);
9153 hr
= IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator
);
9154 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9156 EXPECT_REF(video_type
, 2);
9158 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
9159 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9160 ok(!count
, "Unexpected count %ld.\n", count
);
9162 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
9163 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
9165 IMFVideoSampleAllocatorCallback_Release(allocator_cb
);
9166 IMFVideoSampleAllocator_Release(allocator
);
9168 /* IMFVideoSampleAllocatorEx */
9169 hr
= MFCreateAttributes(&attributes
, 0);
9170 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9172 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx
, (void **)&allocatorex
);
9173 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9175 hr
= IMFVideoSampleAllocatorEx_QueryInterface(allocatorex
, &IID_IMFVideoSampleAllocatorCallback
, (void **)&allocator_cb
);
9176 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9178 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 1, 0, NULL
, video_type
);
9179 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9181 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_BUFFERS_PER_SAMPLE
, 2);
9182 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9184 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
9185 ok(hr
== MF_E_NOT_INITIALIZED
, "Unexpected hr %#lx.\n", hr
);
9187 EXPECT_REF(attributes
, 1);
9188 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, attributes
, video_type
);
9189 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9190 EXPECT_REF(attributes
, 2);
9193 hr
= IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb
, &count
);
9194 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9195 ok(count
== 1, "Unexpected count %ld.\n", count
);
9197 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
9198 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9200 hr
= IMFSample_GetBufferCount(sample
, &buffer_count
);
9201 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9202 ok(buffer_count
== 2, "Unexpected buffer count %lu.\n", buffer_count
);
9204 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample2
);
9205 ok(hr
== MF_E_SAMPLEALLOCATOR_EMPTY
, "Unexpected hr %#lx.\n", hr
);
9207 /* Reinitialize with already allocated samples. */
9208 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, NULL
, video_type
);
9209 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9210 EXPECT_REF(attributes
, 1);
9212 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample2
);
9213 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9214 IMFSample_Release(sample2
);
9216 IMFSample_Release(sample
);
9218 IMFVideoSampleAllocatorCallback_Release(allocator_cb
);
9219 IMFVideoSampleAllocatorEx_Release(allocatorex
);
9220 IMFAttributes_Release(attributes
);
9223 static void test_sample_allocator_d3d9(void)
9225 IDirect3DDeviceManager9
*d3d9_manager
;
9226 IMFVideoSampleAllocator
*allocator
;
9227 IDirect3DDevice9
*d3d9_device
;
9228 IMFMediaType
*video_type
;
9229 IMFMediaBuffer
*buffer
;
9236 if (!pMFCreateVideoSampleAllocatorEx
)
9239 d3d9
= Direct3DCreate9(D3D_SDK_VERSION
);
9242 skip("Failed to create a D3D9 object, skipping tests.\n");
9245 window
= create_window();
9246 if (!(d3d9_device
= create_d3d9_device(d3d9
, window
)))
9248 skip("Failed to create a D3D9 device, skipping tests.\n");
9252 hr
= DXVA2CreateDirect3DDeviceManager9(&token
, &d3d9_manager
);
9253 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9255 hr
= IDirect3DDeviceManager9_ResetDevice(d3d9_manager
, d3d9_device
, token
);
9256 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9258 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
9259 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9261 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)d3d9_manager
);
9262 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9264 video_type
= create_video_type(&MFVideoFormat_RGB32
);
9266 /* Frame size is required. */
9267 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
9268 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9270 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
9271 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9273 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
9274 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9276 check_interface(sample
, &IID_IMFTrackedSample
, TRUE
);
9277 check_interface(sample
, &IID_IMFDesiredSample
, FALSE
);
9279 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
9280 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9282 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
9283 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
9284 check_interface(buffer
, &IID_IMFGetService
, TRUE
);
9285 check_interface(buffer
, &IID_IMFDXGIBuffer
, FALSE
);
9287 IMFSample_Release(sample
);
9288 IMFMediaBuffer_Release(buffer
);
9290 IMFVideoSampleAllocator_Release(allocator
);
9291 IMFMediaType_Release(video_type
);
9292 IDirect3DDeviceManager9_Release(d3d9_manager
);
9293 IDirect3DDevice9_Release(d3d9_device
);
9296 IDirect3D9_Release(d3d9
);
9297 DestroyWindow(window
);
9300 static void test_sample_allocator_d3d11(void)
9302 IMFMediaType
*video_type
;
9303 IMFVideoSampleAllocatorEx
*allocatorex
;
9304 IMFVideoSampleAllocator
*allocator
;
9305 unsigned int i
, token
;
9306 IMFDXGIDeviceManager
*manager
;
9308 IMFDXGIBuffer
*dxgi_buffer
;
9309 IMFAttributes
*attributes
;
9310 D3D11_TEXTURE2D_DESC desc
;
9311 ID3D11Texture2D
*texture
;
9312 IMFMediaBuffer
*buffer
;
9313 ID3D11Device
*device
;
9316 static const unsigned int usage
[] =
9318 D3D11_USAGE_DEFAULT
,
9319 D3D11_USAGE_IMMUTABLE
,
9320 D3D11_USAGE_DYNAMIC
,
9321 D3D11_USAGE_STAGING
,
9322 D3D11_USAGE_STAGING
+ 1,
9324 static const unsigned int sharing
[] =
9326 D3D11_RESOURCE_MISC_SHARED
| D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
9327 D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
,
9328 D3D11_RESOURCE_MISC_SHARED
,
9331 if (!pMFCreateVideoSampleAllocatorEx
)
9334 if (!(device
= create_d3d11_device()))
9336 skip("Failed to create a D3D11 device, skipping tests.\n");
9340 hr
= pMFCreateDXGIDeviceManager(&token
, &manager
);
9341 ok(hr
== S_OK
, "Failed to create device manager, hr %#lx.\n", hr
);
9343 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)device
, token
);
9344 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
9346 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
9347 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9349 EXPECT_REF(manager
, 1);
9350 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)manager
);
9351 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9352 EXPECT_REF(manager
, 2);
9354 video_type
= create_video_type(&MFVideoFormat_RGB32
);
9355 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
9356 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9358 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
9359 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9361 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
9362 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9364 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
9365 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9367 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
9368 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
9369 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
9370 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
9372 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
9373 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
9375 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&texture
);
9376 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
9378 ID3D11Texture2D_GetDesc(texture
, &desc
);
9379 ok(desc
.Width
== 64, "Unexpected width %u.\n", desc
.Width
);
9380 ok(desc
.Height
== 64, "Unexpected height %u.\n", desc
.Height
);
9381 ok(desc
.MipLevels
== 1, "Unexpected miplevels %u.\n", desc
.MipLevels
);
9382 ok(desc
.ArraySize
== 1, "Unexpected array size %u.\n", desc
.ArraySize
);
9383 ok(desc
.Format
== DXGI_FORMAT_B8G8R8X8_UNORM
, "Unexpected format %u.\n", desc
.Format
);
9384 ok(desc
.SampleDesc
.Count
== 1, "Unexpected sample count %u.\n", desc
.SampleDesc
.Count
);
9385 ok(!desc
.SampleDesc
.Quality
, "Unexpected sample quality %u.\n", desc
.SampleDesc
.Quality
);
9386 ok(desc
.Usage
== D3D11_USAGE_DEFAULT
, "Unexpected usage %u.\n", desc
.Usage
);
9387 ok(desc
.BindFlags
== (D3D11_BIND_SHADER_RESOURCE
| D3D11_BIND_RENDER_TARGET
), "Unexpected bind flags %#x.\n",
9389 ok(!desc
.CPUAccessFlags
, "Unexpected CPU access flags %#x.\n", desc
.CPUAccessFlags
);
9390 ok(!desc
.MiscFlags
, "Unexpected misc flags %#x.\n", desc
.MiscFlags
);
9392 ID3D11Texture2D_Release(texture
);
9393 IMFDXGIBuffer_Release(dxgi_buffer
);
9395 hr
= IMFMediaBuffer_Lock(buffer
, &data
, NULL
, NULL
);
9396 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9398 hr
= IMFMediaBuffer_Unlock(buffer
);
9399 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9401 IMFMediaBuffer_Release(buffer
);
9402 IMFSample_Release(sample
);
9404 IMFVideoSampleAllocator_Release(allocator
);
9406 /* MF_SA_D3D11_USAGE */
9407 hr
= MFCreateAttributes(&attributes
, 1);
9408 ok(hr
== S_OK
, "Failed to create attributes, hr %#lx.\n", hr
);
9410 for (i
= 0; i
< ARRAY_SIZE(usage
); ++i
)
9412 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx
, (void **)&allocatorex
);
9413 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9415 hr
= IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex
, (IUnknown
*)manager
);
9416 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9418 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_USAGE
, usage
[i
]);
9419 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
9421 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, attributes
, video_type
);
9422 if (usage
[i
] == D3D11_USAGE_IMMUTABLE
|| usage
[i
] > D3D11_USAGE_STAGING
)
9424 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9425 IMFVideoSampleAllocatorEx_Release(allocatorex
);
9428 ok(hr
== S_OK
, "%u: Unexpected hr %#lx.\n", usage
[i
], hr
);
9430 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_USAGE
, D3D11_USAGE_DEFAULT
);
9431 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
9433 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
9434 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9436 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
9437 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9439 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
9440 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
9442 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&texture
);
9443 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
9445 ID3D11Texture2D_GetDesc(texture
, &desc
);
9446 ok(desc
.Usage
== usage
[i
], "Unexpected usage %u.\n", desc
.Usage
);
9447 if (usage
[i
] == D3D11_USAGE_DEFAULT
)
9449 ok(desc
.BindFlags
== (D3D11_BIND_SHADER_RESOURCE
| D3D11_BIND_RENDER_TARGET
), "Unexpected bind flags %#x.\n",
9451 ok(!desc
.CPUAccessFlags
, "Unexpected CPU access flags %#x.\n", desc
.CPUAccessFlags
);
9453 else if (usage
[i
] == D3D11_USAGE_DYNAMIC
)
9455 ok(desc
.BindFlags
== D3D11_BIND_SHADER_RESOURCE
, "Unexpected bind flags %#x.\n", desc
.BindFlags
);
9456 ok(desc
.CPUAccessFlags
== D3D11_CPU_ACCESS_WRITE
, "Unexpected CPU access flags %#x.\n", desc
.CPUAccessFlags
);
9458 else if (usage
[i
] == D3D11_USAGE_STAGING
)
9460 ok(!desc
.BindFlags
, "Unexpected bind flags %#x.\n", desc
.BindFlags
);
9461 ok(desc
.CPUAccessFlags
== (D3D11_CPU_ACCESS_WRITE
| D3D11_CPU_ACCESS_READ
), "Unexpected CPU access flags %#x.\n",
9462 desc
.CPUAccessFlags
);
9464 ok(!desc
.MiscFlags
, "Unexpected misc flags %#x.\n", desc
.MiscFlags
);
9466 ID3D11Texture2D_Release(texture
);
9467 IMFDXGIBuffer_Release(dxgi_buffer
);
9468 IMFMediaBuffer_Release(buffer
);
9470 IMFSample_Release(sample
);
9472 IMFVideoSampleAllocatorEx_Release(allocatorex
);
9475 /* MF_SA_D3D11_SHARED, MF_SA_D3D11_SHARED_WITHOUT_MUTEX */
9476 for (i
= 0; i
< ARRAY_SIZE(sharing
); ++i
)
9478 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocatorEx
, (void **)&allocatorex
);
9479 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9481 hr
= IMFVideoSampleAllocatorEx_SetDirectXManager(allocatorex
, (IUnknown
*)manager
);
9482 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9484 hr
= IMFAttributes_DeleteAllItems(attributes
);
9485 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9487 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_USAGE
, D3D11_USAGE_DEFAULT
);
9488 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
9490 if (sharing
[i
] & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
)
9492 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_SHARED
, TRUE
);
9493 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
9496 if (sharing
[i
] & D3D11_RESOURCE_MISC_SHARED
)
9498 hr
= IMFAttributes_SetUINT32(attributes
, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX
, TRUE
);
9499 ok(hr
== S_OK
, "Failed to set attribute, hr %#lx.\n", hr
);
9502 hr
= IMFVideoSampleAllocatorEx_InitializeSampleAllocatorEx(allocatorex
, 0, 0, attributes
, video_type
);
9503 if (sharing
[i
] == (D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX
| D3D11_RESOURCE_MISC_SHARED
))
9506 ok(hr
== E_INVALIDARG
, "%u: Unexpected hr %#lx.\n", i
, hr
);
9507 IMFVideoSampleAllocatorEx_Release(allocatorex
);
9510 ok(hr
== S_OK
, "%u: Unexpected hr %#lx.\n", i
, hr
);
9512 hr
= IMFVideoSampleAllocatorEx_AllocateSample(allocatorex
, &sample
);
9513 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9515 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
9516 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9518 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
9519 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
9521 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D11Texture2D
, (void **)&texture
);
9522 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
9524 ID3D11Texture2D_GetDesc(texture
, &desc
);
9525 ok(desc
.MiscFlags
== sharing
[i
], "%u: unexpected misc flags %#x.\n", i
, desc
.MiscFlags
);
9527 ID3D11Texture2D_Release(texture
);
9528 IMFDXGIBuffer_Release(dxgi_buffer
);
9529 IMFMediaBuffer_Release(buffer
);
9531 IMFSample_Release(sample
);
9533 IMFVideoSampleAllocatorEx_Release(allocatorex
);
9536 IMFAttributes_Release(attributes
);
9538 IMFDXGIDeviceManager_Release(manager
);
9539 ID3D11Device_Release(device
);
9542 static void test_sample_allocator_d3d12(void)
9544 IMFVideoSampleAllocator
*allocator
= NULL
;
9545 D3D12_HEAP_PROPERTIES heap_props
;
9546 IMFDXGIDeviceManager
*manager
;
9547 D3D12_HEAP_FLAGS heap_flags
;
9548 IMFDXGIBuffer
*dxgi_buffer
;
9549 IMFMediaType
*video_type
;
9550 ID3D12Resource
*resource
;
9551 D3D12_RESOURCE_DESC desc
;
9552 IMFMediaBuffer
*buffer
;
9553 ID3D12Device
*device
;
9558 if (!(device
= create_d3d12_device()))
9560 skip("Failed to create a D3D12 device, skipping tests.\n");
9564 hr
= pMFCreateDXGIDeviceManager(&token
, &manager
);
9565 ok(hr
== S_OK
, "Failed to create device manager, hr %#lx.\n", hr
);
9567 hr
= IMFDXGIDeviceManager_ResetDevice(manager
, (IUnknown
*)device
, token
);
9570 win_skip("Device manager does not support D3D12 devices.\n");
9573 ok(hr
== S_OK
, "Failed to set a device, hr %#lx.\n", hr
);
9575 hr
= pMFCreateVideoSampleAllocatorEx(&IID_IMFVideoSampleAllocator
, (void **)&allocator
);
9576 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9578 EXPECT_REF(manager
, 1);
9579 hr
= IMFVideoSampleAllocator_SetDirectXManager(allocator
, (IUnknown
*)manager
);
9580 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9581 EXPECT_REF(manager
, 2);
9583 video_type
= create_video_type(&MFVideoFormat_RGB32
);
9584 hr
= IMFMediaType_SetUINT64(video_type
, &MF_MT_FRAME_SIZE
, (UINT64
) 64 << 32 | 64);
9585 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9586 hr
= IMFMediaType_SetUINT32(video_type
, &MF_MT_D3D_RESOURCE_VERSION
, MF_D3D12_RESOURCE
);
9587 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9589 hr
= IMFVideoSampleAllocator_InitializeSampleAllocator(allocator
, 1, video_type
);
9591 ok(hr
== S_OK
|| broken(hr
== MF_E_UNEXPECTED
) /* Some Win10 versions fail. */, "Unexpected hr %#lx.\n", hr
);
9592 if (FAILED(hr
)) goto done
;
9594 hr
= IMFVideoSampleAllocator_AllocateSample(allocator
, &sample
);
9595 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9597 hr
= IMFSample_GetBufferByIndex(sample
, 0, &buffer
);
9598 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9600 check_interface(buffer
, &IID_IMF2DBuffer
, TRUE
);
9601 check_interface(buffer
, &IID_IMF2DBuffer2
, TRUE
);
9602 check_interface(buffer
, &IID_IMFDXGIBuffer
, TRUE
);
9603 check_interface(buffer
, &IID_IMFGetService
, FALSE
);
9605 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMFDXGIBuffer
, (void **)&dxgi_buffer
);
9606 ok(hr
== S_OK
, "Failed to get interface, hr %#lx.\n", hr
);
9608 hr
= IMFDXGIBuffer_GetResource(dxgi_buffer
, &IID_ID3D12Resource
, (void **)&resource
);
9609 ok(hr
== S_OK
, "Failed to get resource, hr %#lx.\n", hr
);
9611 resource
->lpVtbl
->GetDesc(resource
, &desc
);
9612 ok(desc
.Width
== 64, "Unexpected width.\n");
9613 ok(desc
.Height
== 64, "Unexpected height.\n");
9614 ok(desc
.DepthOrArraySize
== 1, "Unexpected array size %u.\n", desc
.DepthOrArraySize
);
9615 ok(desc
.MipLevels
== 1, "Unexpected miplevels %u.\n", desc
.MipLevels
);
9616 ok(desc
.Format
== DXGI_FORMAT_B8G8R8X8_UNORM
, "Unexpected format %u.\n", desc
.Format
);
9617 ok(desc
.SampleDesc
.Count
== 1, "Unexpected sample count %u.\n", desc
.SampleDesc
.Count
);
9618 ok(!desc
.SampleDesc
.Quality
, "Unexpected sample quality %u.\n", desc
.SampleDesc
.Quality
);
9619 ok(!desc
.Layout
, "Unexpected layout %u.\n", desc
.Layout
);
9620 ok(!desc
.Flags
, "Unexpected flags %#x.\n", desc
.Flags
);
9622 hr
= ID3D12Resource_GetHeapProperties(resource
, &heap_props
, &heap_flags
);
9623 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9624 ok(heap_props
.Type
== D3D12_HEAP_TYPE_DEFAULT
, "Unexpected heap type %u.\n", heap_props
.Type
);
9625 ok(heap_props
.CPUPageProperty
== D3D12_CPU_PAGE_PROPERTY_UNKNOWN
, "Unexpected page property %u.\n",
9626 heap_props
.CPUPageProperty
);
9627 ok(!heap_props
.MemoryPoolPreference
, "Unexpected pool preference %u.\n", heap_props
.MemoryPoolPreference
);
9628 ok(heap_flags
== D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES
, "Unexpected heap flags %#x.\n", heap_flags
);
9630 ID3D12Resource_Release(resource
);
9631 IMFDXGIBuffer_Release(dxgi_buffer
);
9632 IMFMediaBuffer_Release(buffer
);
9633 IMFSample_Release(sample
);
9637 IMFVideoSampleAllocator_Release(allocator
);
9638 IMFDXGIDeviceManager_Release(manager
);
9639 ID3D12Device_Release(device
);
9642 static void test_MFLockSharedWorkQueue(void)
9644 DWORD taskid
, queue
, queue2
;
9647 if (!pMFLockSharedWorkQueue
)
9649 win_skip("MFLockSharedWorkQueue() is not available.\n");
9653 hr
= MFStartup(MF_VERSION
, MFSTARTUP_FULL
);
9654 ok(hr
== S_OK
, "Failed to start up, hr %#lx.\n", hr
);
9656 hr
= pMFLockSharedWorkQueue(NULL
, 0, &taskid
, &queue
);
9657 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
9659 hr
= pMFLockSharedWorkQueue(NULL
, 0, NULL
, &queue
);
9660 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
9663 hr
= pMFLockSharedWorkQueue(L
"", 0, &taskid
, &queue
);
9664 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9667 hr
= pMFLockSharedWorkQueue(L
"", 0, NULL
, &queue
);
9668 ok(queue
& MFASYNC_CALLBACK_QUEUE_PRIVATE_MASK
, "Unexpected queue id.\n");
9671 hr
= pMFLockSharedWorkQueue(L
"", 0, NULL
, &queue2
);
9672 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9673 ok(queue
== queue2
, "Unexpected queue %#lx.\n", queue2
);
9675 hr
= MFUnlockWorkQueue(queue2
);
9676 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9678 hr
= MFUnlockWorkQueue(queue
);
9679 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9682 ok(hr
== S_OK
, "Failed to shut down, hr %#lx.\n", hr
);
9685 static void test_MFllMulDiv(void)
9687 /* (a * b + d) / c */
9688 static const struct muldivtest
9698 { 0, 0, 0, 0, _I64_MAX
},
9699 { 1000000, 1000000, 2, 0, 500000000000 },
9700 { _I64_MAX
, 3, _I64_MAX
, 0, 3 },
9701 { _I64_MAX
, 3, _I64_MAX
, 1, 3 },
9702 { -10000, 3, 100, 0, -300 },
9704 { 2, 1, 1, -3, -1 },
9705 /* a * b product does not fit in uint64_t */
9706 { _I64_MAX
, 4, 8, 0, _I64_MAX
/ 2 },
9707 /* Large a * b product, large denominator */
9708 { _I64_MAX
, 4, 0x100000000, 0, 0x1ffffffff },
9712 for (i
= 0; i
< ARRAY_SIZE(muldivtests
); ++i
)
9716 result
= MFllMulDiv(muldivtests
[i
].a
, muldivtests
[i
].b
, muldivtests
[i
].c
, muldivtests
[i
].d
);
9717 ok(result
== muldivtests
[i
].result
, "%u: unexpected result %s, expected %s.\n", i
,
9718 wine_dbgstr_longlong(result
), wine_dbgstr_longlong(muldivtests
[i
].result
));
9722 static void test_shared_dxgi_device_manager(void)
9724 IMFDXGIDeviceManager
*manager
;
9728 if (!pMFLockDXGIDeviceManager
)
9730 win_skip("Shared DXGI device manager is not supported.\n");
9734 hr
= pMFUnlockDXGIDeviceManager();
9735 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9738 hr
= pMFLockDXGIDeviceManager(NULL
, &manager
);
9739 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9740 ok(!!manager
, "Unexpected instance.\n");
9742 hr
= pMFLockDXGIDeviceManager(&token
, &manager
);
9743 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9745 EXPECT_REF(manager
, 3);
9747 hr
= pMFUnlockDXGIDeviceManager();
9748 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9750 EXPECT_REF(manager
, 2);
9752 hr
= pMFUnlockDXGIDeviceManager();
9753 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9756 static void check_video_format(const MFVIDEOFORMAT
*format
, unsigned int width
, unsigned int height
,
9759 unsigned int transfer_function
;
9762 if (!d3dformat
) d3dformat
= D3DFMT_X8R8G8B8
;
9766 case D3DFMT_X8R8G8B8
:
9768 case D3DFMT_A8R8G8B8
:
9770 case D3DFMT_X1R5G5B5
:
9771 case D3DFMT_A2B10G10R10
:
9772 case D3DFMT_A2R10G10B10
:
9774 transfer_function
= MFVideoTransFunc_sRGB
;
9777 transfer_function
= MFVideoTransFunc_10
;
9780 memcpy(&guid
, &MFVideoFormat_Base
, sizeof(guid
));
9781 guid
.Data1
= d3dformat
;
9783 ok(format
->dwSize
== sizeof(*format
), "Unexpected format size.\n");
9784 ok(format
->videoInfo
.dwWidth
== width
, "Unexpected width %lu.\n", format
->videoInfo
.dwWidth
);
9785 ok(format
->videoInfo
.dwHeight
== height
, "Unexpected height %lu.\n", format
->videoInfo
.dwHeight
);
9786 ok(format
->videoInfo
.PixelAspectRatio
.Numerator
== 1 &&
9787 format
->videoInfo
.PixelAspectRatio
.Denominator
== 1, "Unexpected PAR.\n");
9788 ok(format
->videoInfo
.SourceChromaSubsampling
== MFVideoChromaSubsampling_Unknown
, "Unexpected chroma subsampling.\n");
9789 ok(format
->videoInfo
.InterlaceMode
== MFVideoInterlace_Progressive
, "Unexpected interlace mode %u.\n",
9790 format
->videoInfo
.InterlaceMode
);
9791 ok(format
->videoInfo
.TransferFunction
== transfer_function
, "Unexpected transfer function %u.\n",
9792 format
->videoInfo
.TransferFunction
);
9793 ok(format
->videoInfo
.ColorPrimaries
== MFVideoPrimaries_BT709
, "Unexpected color primaries %u.\n",
9794 format
->videoInfo
.ColorPrimaries
);
9795 ok(format
->videoInfo
.TransferMatrix
== MFVideoTransferMatrix_Unknown
, "Unexpected transfer matrix.\n");
9796 ok(format
->videoInfo
.SourceLighting
== MFVideoLighting_office
, "Unexpected source lighting %u.\n",
9797 format
->videoInfo
.SourceLighting
);
9798 ok(format
->videoInfo
.FramesPerSecond
.Numerator
== 60 &&
9799 format
->videoInfo
.FramesPerSecond
.Denominator
== 1, "Unexpected frame rate %lu/%lu.\n",
9800 format
->videoInfo
.FramesPerSecond
.Numerator
, format
->videoInfo
.FramesPerSecond
.Denominator
);
9801 ok(format
->videoInfo
.NominalRange
== MFNominalRange_Normal
, "Unexpected nominal range %u.\n",
9802 format
->videoInfo
.NominalRange
);
9803 ok(format
->videoInfo
.GeometricAperture
.Area
.cx
== width
&& format
->videoInfo
.GeometricAperture
.Area
.cy
== height
,
9804 "Unexpected geometric aperture.\n");
9805 ok(!memcmp(&format
->videoInfo
.GeometricAperture
, &format
->videoInfo
.MinimumDisplayAperture
, sizeof(MFVideoArea
)),
9806 "Unexpected minimum display aperture.\n");
9807 ok(format
->videoInfo
.PanScanAperture
.Area
.cx
== 0 && format
->videoInfo
.PanScanAperture
.Area
.cy
== 0,
9808 "Unexpected geometric aperture.\n");
9809 ok(format
->videoInfo
.VideoFlags
== 0, "Unexpected video flags.\n");
9810 ok(IsEqualGUID(&format
->guidFormat
, &guid
), "Unexpected format guid %s.\n", wine_dbgstr_guid(&format
->guidFormat
));
9811 ok(format
->compressedInfo
.AvgBitrate
== 0, "Unexpected bitrate.\n");
9812 ok(format
->compressedInfo
.AvgBitErrorRate
== 0, "Unexpected error bitrate.\n");
9813 ok(format
->compressedInfo
.MaxKeyFrameSpacing
== 0, "Unexpected MaxKeyFrameSpacing.\n");
9814 ok(format
->surfaceInfo
.Format
== d3dformat
, "Unexpected format %lu.\n", format
->surfaceInfo
.Format
);
9815 ok(format
->surfaceInfo
.PaletteEntries
== 0, "Unexpected palette size %lu.\n", format
->surfaceInfo
.PaletteEntries
);
9818 static void test_MFInitVideoFormat_RGB(void)
9820 static const DWORD formats
[] =
9822 0, /* same D3DFMT_X8R8G8B8 */
9836 D3DFMT_A16B16G16R16F
,
9838 MFVIDEOFORMAT format
;
9842 if (!pMFInitVideoFormat_RGB
)
9844 win_skip("MFInitVideoFormat_RGB is not available.\n");
9848 hr
= pMFInitVideoFormat_RGB(NULL
, 64, 32, 0);
9849 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9851 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
9853 memset(&format
, 0, sizeof(format
));
9854 hr
= pMFInitVideoFormat_RGB(&format
, 64, 32, formats
[i
]);
9855 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9857 check_video_format(&format
, 64, 32, formats
[i
]);
9861 static void test_MFCreateVideoMediaTypeFromVideoInfoHeader(void)
9863 IMFVideoMediaType
*media_type
;
9864 KS_VIDEOINFOHEADER vih
;
9870 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(NULL
, 0, 0, 0, MFVideoInterlace_Unknown
, 0, NULL
, &media_type
);
9872 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9874 memset(&vih
, 0, sizeof(vih
));
9875 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(&vih
, 0, 0, 0, MFVideoInterlace_Unknown
, 0, NULL
, &media_type
);
9877 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9878 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(&vih
, sizeof(vih
), 0, 0, MFVideoInterlace_Unknown
, 0, NULL
, &media_type
);
9880 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9881 vih
.bmiHeader
.biSize
= sizeof(vih
.bmiHeader
);
9882 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(&vih
, sizeof(vih
), 0, 0, MFVideoInterlace_Unknown
, 0, NULL
, &media_type
);
9884 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9886 vih
.bmiHeader
.biSize
= sizeof(vih
.bmiHeader
);
9887 vih
.bmiHeader
.biPlanes
= 1;
9888 vih
.bmiHeader
.biWidth
= 16;
9889 vih
.bmiHeader
.biHeight
= 32;
9890 vih
.bmiHeader
.biBitCount
= 32;
9892 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(&vih
, sizeof(vih
), 3, 2, MFVideoInterlace_Progressive
,
9893 MFVideoFlag_AnalogProtected
, &GUID_NULL
, &media_type
);
9895 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9896 if (FAILED(hr
)) return;
9897 IMFVideoMediaType_Release(media_type
);
9899 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(&vih
, sizeof(vih
), 3, 2, MFVideoInterlace_Progressive
,
9900 MFVideoFlag_AnalogProtected
, NULL
, &media_type
);
9901 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9903 hr
= IMFVideoMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
9904 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9905 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
9906 hr
= IMFVideoMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
9907 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9908 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB32
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
9909 hr
= IMFVideoMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
9910 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9911 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
9912 hr
= IMFVideoMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
9913 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9914 ok(value64
== ((UINT64
)3 << 32 | 2), "Unexpected value %#I64x.\n", value64
);
9915 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_DRM_FLAGS
, &value32
);
9916 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9917 ok(value32
== MFVideoDRMFlag_AnalogProtected
, "Unexpected value %#x.\n", value32
);
9918 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
9919 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9920 ok(value32
== MFVideoInterlace_Progressive
, "Unexpected value %#x.\n", value32
);
9921 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
9922 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9923 ok(value32
== 2048, "Unexpected value %u.\n", value32
);
9924 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
9925 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9926 ok(value32
== -64, "Unexpected value %d.\n", value32
);
9927 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
9928 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9929 ok(!!value32
, "Unexpected value %#x.\n", value32
);
9930 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
9931 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9932 ok(!!value32
, "Unexpected value %#x.\n", value32
);
9934 IMFVideoMediaType_Release(media_type
);
9936 /* Negative height. */
9937 vih
.bmiHeader
.biHeight
= -32;
9938 hr
= MFCreateVideoMediaTypeFromVideoInfoHeader(&vih
, sizeof(vih
), 3, 2, MFVideoInterlace_Progressive
,
9939 MFVideoFlag_AnalogProtected
, NULL
, &media_type
);
9940 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9941 hr
= IMFVideoMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
9942 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9943 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
9944 hr
= IMFVideoMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
9945 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9946 ok(value32
== 64, "Unexpected value %d.\n", value32
);
9947 IMFVideoMediaType_Release(media_type
);
9950 static void test_MFInitMediaTypeFromVideoInfoHeader(void)
9952 static const MFVideoArea expect_aperture
= {.OffsetX
= {.value
= 1}, .OffsetY
= {.value
= 2}, .Area
= {.cx
= 3, .cy
= 5}};
9953 static const RECT source
= {1, 2, 4, 7}, target
= {3, 2, 12, 9};
9954 IMFMediaType
*media_type
;
9955 MFVideoArea aperture
;
9956 VIDEOINFOHEADER vih
;
9962 hr
= MFCreateMediaType(&media_type
);
9963 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9965 memset(&vih
, 0, sizeof(vih
));
9966 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, 0, NULL
);
9967 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9968 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), NULL
);
9969 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
9971 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
9972 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9973 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
9974 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9975 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
9976 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
9977 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9978 ok(IsEqualGUID(&guid
, &GUID_NULL
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
9979 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
9981 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
9983 vih
.bmiHeader
.biWidth
= 16;
9984 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
9985 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9986 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
9988 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
9989 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
9991 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
9992 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
9994 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
9996 vih
.bmiHeader
.biHeight
= -32;
9997 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
9998 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
9999 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10000 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10001 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
10002 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10003 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10005 vih
.bmiHeader
.biHeight
= 32;
10006 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10007 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10008 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10009 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10010 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
10011 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10012 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10013 ok(value64
== ((UINT64
)1 << 32 | 1), "Unexpected value %#I64x.\n", value64
);
10014 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10015 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10016 ok(value32
== MFVideoInterlace_Progressive
, "Unexpected value %#x.\n", value32
);
10017 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10018 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10019 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10020 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10022 value32
= 0xdeadbeef;
10023 vih
.bmiHeader
.biSizeImage
= 12345;
10024 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10025 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10026 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10027 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10028 ok(value32
== 12345, "Unexpected value %#x.\n", value32
);
10029 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BITRATE
, &value32
);
10030 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10032 value32
= 0xdeadbeef;
10033 vih
.dwBitRate
= 678910;
10034 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10035 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10036 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BITRATE
, &value32
);
10038 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10040 ok(value32
== 678910, "Unexpected value %#x.\n", value32
);
10041 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BIT_ERROR_RATE
, &value32
);
10042 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10044 value32
= 0xdeadbeef;
10045 vih
.dwBitErrorRate
= 11121314;
10046 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10047 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10048 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BIT_ERROR_RATE
, &value32
);
10050 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10052 ok(value32
== 11121314, "Unexpected value %#x.\n", value32
);
10053 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_RATE
, &value64
);
10054 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10056 value64
= 0xdeadbeef;
10057 vih
.AvgTimePerFrame
= 1151617;
10058 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10059 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10060 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_RATE
, &value64
);
10061 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10062 ok(value64
== ((UINT64
)10000000 << 32 | 1151617), "Unexpected value %#I64x.\n", value64
);
10064 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10065 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10066 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10067 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10069 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10070 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10071 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_GEOMETRIC_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10072 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10073 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_PAN_SCAN_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10074 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10075 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_PAN_SCAN_ENABLED
, &value32
);
10076 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10078 /* only rcSource is considered, translated into both MF_MT_MINIMUM_DISPLAY_APERTURE and MF_MT_PAN_SCAN_APERTURE */
10079 value32
= 0xdeadbeef;
10080 vih
.rcSource
= source
;
10081 vih
.rcTarget
= target
;
10082 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10083 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10084 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10085 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10086 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
10087 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10088 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10089 ok(value32
== 12345, "Unexpected value %#x.\n", value32
);
10090 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10091 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10093 value32
= 0xdeadbeef;
10094 memset(&aperture
, 0xcd, sizeof(aperture
));
10095 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10096 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10097 ok(value32
== sizeof(aperture
), "got %d.\n", value32
);
10098 ok(!memcmp(&aperture
, &expect_aperture
, sizeof(aperture
)), "unexpected aperture\n");
10100 value32
= 0xdeadbeef;
10101 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_PAN_SCAN_ENABLED
, &value32
);
10102 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10103 ok(value32
== 1, "got %d.\n", (UINT32
)value32
);
10105 value32
= 0xdeadbeef;
10106 memset(&aperture
, 0xcd, sizeof(aperture
));
10107 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_PAN_SCAN_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10108 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10109 ok(value32
== sizeof(aperture
), "got %d.\n", value32
);
10110 ok(!memcmp(&aperture
, &expect_aperture
, sizeof(aperture
)), "unexpected aperture\n");
10112 hr
= IMFMediaType_GetItem(media_type
, &MF_MT_GEOMETRIC_APERTURE
, NULL
);
10113 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10116 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), &MFVideoFormat_NV12
);
10117 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10118 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10119 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10120 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10121 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10122 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10123 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10126 /* biBitCount is used for implicit RGB format if GUID is NULL */
10127 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), NULL
);
10128 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
10130 for (vih
.bmiHeader
.biBitCount
= 1; vih
.bmiHeader
.biBitCount
<= 32; vih
.bmiHeader
.biBitCount
++)
10132 winetest_push_context("%u", vih
.bmiHeader
.biBitCount
);
10134 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), NULL
);
10135 if (vih
.bmiHeader
.biBitCount
!= 1 && vih
.bmiHeader
.biBitCount
!= 4 && vih
.bmiHeader
.biBitCount
!= 8
10136 && vih
.bmiHeader
.biBitCount
!= 16 && vih
.bmiHeader
.biBitCount
!= 24 && vih
.bmiHeader
.biBitCount
!= 32)
10137 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
10140 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10142 memset(&guid
, 0xcd, sizeof(guid
));
10143 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10144 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10145 if (vih
.bmiHeader
.biBitCount
== 32)
10146 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB32
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10147 else if (vih
.bmiHeader
.biBitCount
== 24)
10148 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB24
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10149 else if (vih
.bmiHeader
.biBitCount
== 16)
10150 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB555
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10151 else if (vih
.bmiHeader
.biBitCount
== 8)
10152 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB8
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10153 else if (vih
.bmiHeader
.biBitCount
== 4)
10154 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB4
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10155 else if (vih
.bmiHeader
.biBitCount
== 1)
10156 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB1
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10158 value32
= 0xdeadbeef;
10159 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10160 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10161 if (vih
.bmiHeader
.biBitCount
> 1)
10162 ok(value32
== 16 * vih
.bmiHeader
.biBitCount
/ 8, "Unexpected value %#x.\n", value32
);
10164 todo_wine
ok(value32
== -4, "Unexpected value %#x.\n", value32
);
10166 hr
= IMFMediaType_GetItem(media_type
, &MF_MT_PALETTE
, NULL
);
10167 if (vih
.bmiHeader
.biBitCount
> 1)
10168 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10170 todo_wine
ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10172 value32
= 0xdeadbeef;
10173 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10174 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10175 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10176 value32
= 0xdeadbeef;
10177 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10178 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10179 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10181 value32
= 0xdeadbeef;
10182 vih
.bmiHeader
.biHeight
= 32;
10183 hr
= MFInitMediaTypeFromVideoInfoHeader(media_type
, &vih
, sizeof(vih
), NULL
);
10184 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10185 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10186 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10187 if (vih
.bmiHeader
.biBitCount
> 1)
10188 ok(value32
== -16 * vih
.bmiHeader
.biBitCount
/ 8, "Unexpected value %#x.\n", value32
);
10190 todo_wine
ok(value32
== -4, "Unexpected value %#x.\n", value32
);
10192 vih
.bmiHeader
.biHeight
= -32;
10195 winetest_pop_context();
10198 IMFMediaType_Release(media_type
);
10201 static void test_MFInitMediaTypeFromVideoInfoHeader2(void)
10203 static const MFVideoArea expect_aperture
= {.OffsetX
= {.value
= 1}, .OffsetY
= {.value
= 2}, .Area
= {.cx
= 3, .cy
= 5}};
10204 static const RECT source
= {1, 2, 4, 7}, target
= {3, 2, 12, 9};
10205 IMFMediaType
*media_type
;
10206 VIDEOINFOHEADER2 vih
;
10207 MFVideoArea aperture
;
10213 hr
= MFCreateMediaType(&media_type
);
10214 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10216 memset(&vih
, 0, sizeof(vih
));
10217 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, 0, NULL
);
10218 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
10219 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), NULL
);
10220 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
10222 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10223 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10224 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
10225 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10226 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10227 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10228 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10229 ok(IsEqualGUID(&guid
, &GUID_NULL
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10230 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10232 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10234 vih
.bmiHeader
.biWidth
= 16;
10235 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10236 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10237 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10239 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10240 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10242 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10243 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10245 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10247 vih
.bmiHeader
.biHeight
= -32;
10248 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10249 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10250 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10251 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10252 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
10253 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10254 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10256 vih
.bmiHeader
.biHeight
= 32;
10257 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10258 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10259 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10260 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10261 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
10262 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10263 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10264 ok(value32
== MFVideoInterlace_Progressive
, "Unexpected value %#x.\n", value32
);
10265 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10266 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10267 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10269 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10270 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10271 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10273 value32
= 0xdeadbeef;
10274 vih
.bmiHeader
.biSizeImage
= 12345;
10275 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10276 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10277 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10278 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10279 ok(value32
== 12345, "Unexpected value %#x.\n", value32
);
10280 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BITRATE
, &value32
);
10281 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10283 value32
= 0xdeadbeef;
10284 vih
.dwBitRate
= 678910;
10285 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10286 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10287 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BITRATE
, &value32
);
10289 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10291 ok(value32
== 678910, "Unexpected value %#x.\n", value32
);
10292 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BIT_ERROR_RATE
, &value32
);
10293 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10295 value32
= 0xdeadbeef;
10296 vih
.dwBitErrorRate
= 11121314;
10297 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10298 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10299 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_AVG_BIT_ERROR_RATE
, &value32
);
10301 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10303 ok(value32
== 11121314, "Unexpected value %#x.\n", value32
);
10304 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_RATE
, &value64
);
10305 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10307 value64
= 0xdeadbeef;
10308 vih
.AvgTimePerFrame
= 1151617;
10309 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10310 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10311 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_RATE
, &value64
);
10312 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10313 ok(value64
== ((UINT64
)10000000 << 32 | 1151617), "Unexpected value %#I64x.\n", value64
);
10315 value32
= 0xdeadbeef;
10316 vih
.dwInterlaceFlags
= AMINTERLACE_IsInterlaced
| AMINTERLACE_DisplayModeBobOrWeave
;
10317 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10318 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10319 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10320 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10322 ok(value32
== MFVideoInterlace_MixedInterlaceOrProgressive
, "Unexpected value %#x.\n", value32
);
10324 vih
.dwPictAspectRatioX
= 123;
10325 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10326 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10327 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10329 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10331 value64
= 0xdeadbeef;
10332 vih
.dwPictAspectRatioY
= 456;
10333 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10334 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10335 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10336 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10338 ok(value64
== ((UINT64
)41 << 32 | 76), "Unexpected value %#I64x.\n", value64
);
10340 vih
.dwControlFlags
= AMCONTROL_COLORINFO_PRESENT
;
10341 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10342 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10343 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_YUV_MATRIX
, &value32
);
10344 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10346 value32
= 0xdeadbeef;
10347 vih
.dwControlFlags
= AMCONTROL_COLORINFO_PRESENT
| (MFVideoTransferMatrix_SMPTE240M
<< 15);
10348 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10349 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10350 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_YUV_MATRIX
, &value32
);
10352 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10354 ok(value32
== MFVideoTransferMatrix_SMPTE240M
, "Unexpected value %#x.\n", value32
);
10355 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_NOMINAL_RANGE
, &value32
);
10356 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10358 value32
= 0xdeadbeef;
10359 vih
.dwControlFlags
= AMCONTROL_COLORINFO_PRESENT
| (MFVideoTransferMatrix_SMPTE240M
<< 15) | (MFNominalRange_Wide
<< 12);
10360 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10361 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10362 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_VIDEO_NOMINAL_RANGE
, &value32
);
10364 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10366 ok(value32
== MFNominalRange_Wide
, "Unexpected value %#x.\n", value32
);
10368 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10369 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10370 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10371 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10373 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &MFVideoFormat_NV12
);
10374 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10375 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10376 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10377 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10378 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10379 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10380 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10382 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10383 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10384 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_GEOMETRIC_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10385 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10386 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_PAN_SCAN_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10387 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10388 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_PAN_SCAN_ENABLED
, &value32
);
10389 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10391 /* only rcSource is considered, translated into both MF_MT_MINIMUM_DISPLAY_APERTURE and MF_MT_PAN_SCAN_APERTURE */
10392 value32
= 0xdeadbeef;
10393 vih
.rcSource
= source
;
10394 vih
.rcTarget
= target
;
10395 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), &GUID_NULL
);
10396 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10397 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10398 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10399 ok(value64
== ((UINT64
)16 << 32 | 32), "Unexpected value %#I64x.\n", value64
);
10400 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10401 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10402 ok(value32
== 12345, "Unexpected value %#x.\n", value32
);
10403 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10404 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10406 value32
= 0xdeadbeef;
10407 memset(&aperture
, 0xcd, sizeof(aperture
));
10408 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10409 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10410 ok(value32
== sizeof(aperture
), "got %d.\n", value32
);
10411 ok(!memcmp(&aperture
, &expect_aperture
, sizeof(aperture
)), "unexpected aperture\n");
10413 value32
= 0xdeadbeef;
10414 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_PAN_SCAN_ENABLED
, &value32
);
10415 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10416 ok(value32
== 1, "got %d.\n", (UINT32
)value32
);
10418 value32
= 0xdeadbeef;
10419 memset(&aperture
, 0xcd, sizeof(aperture
));
10420 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_PAN_SCAN_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10421 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10422 ok(value32
== sizeof(aperture
), "got %d.\n", value32
);
10423 ok(!memcmp(&aperture
, &expect_aperture
, sizeof(aperture
)), "unexpected aperture\n");
10425 hr
= IMFMediaType_GetItem(media_type
, &MF_MT_GEOMETRIC_APERTURE
, NULL
);
10426 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10429 /* biBitCount is used for implicit RGB format if GUID is NULL */
10430 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), NULL
);
10431 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
10433 for (vih
.bmiHeader
.biBitCount
= 1; vih
.bmiHeader
.biBitCount
<= 32; vih
.bmiHeader
.biBitCount
++)
10435 winetest_push_context("%u", vih
.bmiHeader
.biBitCount
);
10437 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), NULL
);
10438 if (vih
.bmiHeader
.biBitCount
!= 1 && vih
.bmiHeader
.biBitCount
!= 4 && vih
.bmiHeader
.biBitCount
!= 8
10439 && vih
.bmiHeader
.biBitCount
!= 16 && vih
.bmiHeader
.biBitCount
!= 24 && vih
.bmiHeader
.biBitCount
!= 32)
10440 ok(hr
== E_INVALIDARG
, "Unexpected hr %#lx.\n", hr
);
10443 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10445 memset(&guid
, 0xcd, sizeof(guid
));
10446 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10447 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10448 if (vih
.bmiHeader
.biBitCount
== 32)
10449 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB32
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10450 else if (vih
.bmiHeader
.biBitCount
== 24)
10451 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB24
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10452 else if (vih
.bmiHeader
.biBitCount
== 16)
10453 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB555
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10454 else if (vih
.bmiHeader
.biBitCount
== 8)
10455 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB8
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10456 else if (vih
.bmiHeader
.biBitCount
== 4)
10457 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB4
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10458 else if (vih
.bmiHeader
.biBitCount
== 1)
10459 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB1
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10461 value32
= 0xdeadbeef;
10462 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10463 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10464 if (vih
.bmiHeader
.biBitCount
> 1)
10465 ok(value32
== 16 * vih
.bmiHeader
.biBitCount
/ 8, "Unexpected value %#x.\n", value32
);
10467 todo_wine
ok(value32
== -4, "Unexpected value %#x.\n", value32
);
10469 hr
= IMFMediaType_GetItem(media_type
, &MF_MT_PALETTE
, NULL
);
10470 if (vih
.bmiHeader
.biBitCount
> 1)
10471 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10473 todo_wine
ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10475 value32
= 0xdeadbeef;
10476 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10477 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10478 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10479 value32
= 0xdeadbeef;
10480 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10481 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10482 ok(value32
== 1, "Unexpected value %#x.\n", value32
);
10484 value32
= 0xdeadbeef;
10485 vih
.bmiHeader
.biHeight
= 32;
10486 hr
= MFInitMediaTypeFromVideoInfoHeader2(media_type
, &vih
, sizeof(vih
), NULL
);
10487 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10488 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10489 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10490 if (vih
.bmiHeader
.biBitCount
> 1)
10491 ok(value32
== -16 * vih
.bmiHeader
.biBitCount
/ 8, "Unexpected value %#x.\n", value32
);
10493 todo_wine
ok(value32
== -4, "Unexpected value %#x.\n", value32
);
10495 vih
.bmiHeader
.biHeight
= -32;
10498 winetest_pop_context();
10501 IMFMediaType_Release(media_type
);
10504 static void test_MFInitMediaTypeFromAMMediaType(void)
10506 static const MFVideoArea expect_aperture
= {.OffsetX
= {.value
= 13}, .OffsetY
= {.value
= 46}, .Area
= {.cx
= 110, .cy
= 410}};
10507 static const RECT source
= {13, 46, 123, 456}, target
= {25, 34, 107, 409};
10508 IMFMediaType
*media_type
;
10514 VIDEOINFOHEADER vih
=
10517 {sizeof(BITMAPINFOHEADER
), 32, 24, 1, 0, 0xdeadbeef}
10519 static const struct guid_type_pair
10521 const GUID
*am_type
;
10522 const GUID
*mf_type
;
10525 /* these RGB formats are converted, MEDIASUBTYPE variant isn't
10526 * defined using DEFINE_MEDIATYPE_GUID */
10527 { &MEDIASUBTYPE_RGB1
, &MFVideoFormat_RGB1
},
10528 { &MEDIASUBTYPE_RGB4
, &MFVideoFormat_RGB4
},
10529 { &MEDIASUBTYPE_RGB8
, &MFVideoFormat_RGB8
},
10530 { &MEDIASUBTYPE_RGB555
, &MFVideoFormat_RGB555
},
10531 { &MEDIASUBTYPE_RGB565
, &MFVideoFormat_RGB565
},
10532 { &MEDIASUBTYPE_RGB24
, &MFVideoFormat_RGB24
},
10533 { &MEDIASUBTYPE_RGB32
, &MFVideoFormat_RGB32
},
10534 { &MEDIASUBTYPE_ARGB1555
, &MFVideoFormat_ARGB1555
},
10535 { &MEDIASUBTYPE_ARGB4444
, &MFVideoFormat_ARGB4444
},
10536 { &MEDIASUBTYPE_ARGB32
, &MFVideoFormat_ARGB32
},
10537 { &MEDIASUBTYPE_A2R10G10B10
, &MFVideoFormat_A2B10G10R10
},
10538 { &MEDIASUBTYPE_A2B10G10R10
, &MFVideoFormat_A2R10G10B10
},
10540 /* any other GUID is passed through */
10541 { &MEDIASUBTYPE_I420
, &MFVideoFormat_I420
},
10542 { &MEDIASUBTYPE_AYUV
, &MFVideoFormat_AYUV
},
10543 { &MEDIASUBTYPE_YV12
, &MFVideoFormat_YV12
},
10544 { &MEDIASUBTYPE_YUY2
, &MFVideoFormat_YUY2
},
10545 { &MEDIASUBTYPE_UYVY
, &MFVideoFormat_UYVY
},
10546 { &MEDIASUBTYPE_YVYU
, &MFVideoFormat_YVYU
},
10547 { &MEDIASUBTYPE_NV12
, &MFVideoFormat_NV12
},
10549 /* even formats that don't exist in MF */
10550 { &DUMMY_GUID3
, &DUMMY_GUID3
},
10551 { &MEDIASUBTYPE_NV24
, &MEDIASUBTYPE_NV24
},
10552 { &MEDIASUBTYPE_P208
, &MEDIASUBTYPE_P208
},
10554 /* if the mapping is ambiguous, it is not corrected */
10555 { &MEDIASUBTYPE_h264
, &MEDIASUBTYPE_h264
},
10556 { &MEDIASUBTYPE_H264
, &MFVideoFormat_H264
},
10558 MFVideoArea aperture
;
10561 hr
= MFCreateMediaType(&media_type
);
10562 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10564 memset(&mt
, 0, sizeof(mt
));
10565 mt
.majortype
= MEDIATYPE_Video
;
10566 mt
.formattype
= FORMAT_VideoInfo
;
10567 mt
.cbFormat
= sizeof(VIDEOINFOHEADER
);
10568 mt
.pbFormat
= (BYTE
*)&vih
;
10570 hr
= IMFMediaType_SetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, 123);
10571 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10573 hr
= MFInitMediaTypeFromAMMediaType(media_type
, &mt
);
10574 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10576 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
10577 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10578 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10579 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10580 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10581 ok(IsEqualGUID(&guid
, &GUID_NULL
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10582 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10583 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10584 ok(value64
== ((UINT64
)32 << 32 | 24), "Unexpected value %#I64x.\n", value64
);
10585 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10586 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10587 ok(value64
== ((UINT64
)1 << 32 | 1), "Unexpected value %#I64x.\n", value64
);
10588 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10589 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10590 ok(value32
== MFVideoInterlace_Progressive
, "Unexpected value %#x.\n", value32
);
10591 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10592 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10593 ok(!!value32
, "Unexpected value %#x.\n", value32
);
10595 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10596 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10597 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10598 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10599 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10600 ok(hr
== MF_E_ATTRIBUTENOTFOUND
, "Unexpected hr %#lx.\n", hr
);
10602 vih
.bmiHeader
.biHeight
= -24;
10604 hr
= MFInitMediaTypeFromAMMediaType(media_type
, &mt
);
10605 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10606 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10607 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10608 ok(value64
== ((UINT64
)32 << 32 | 24), "Unexpected value %#I64x.\n", value64
);
10610 memcpy(&mt
.subtype
, &MEDIASUBTYPE_RGB32
, sizeof(GUID
));
10611 vih
.bmiHeader
.biHeight
= 24;
10613 hr
= MFInitMediaTypeFromAMMediaType(media_type
, &mt
);
10614 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10616 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
10617 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10618 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10619 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10620 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10621 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB32
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10622 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10623 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10624 ok(value64
== ((UINT64
)32 << 32 | 24), "Unexpected value %#I64x.\n", value64
);
10625 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10626 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10627 ok(value64
== ((UINT64
)1 << 32 | 1), "Unexpected value %#I64x.\n", value64
);
10628 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10629 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10630 ok(value32
== MFVideoInterlace_Progressive
, "Unexpected value %#x.\n", value32
);
10631 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10632 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10633 ok(value32
== 3072, "Unexpected value %u.\n", value32
);
10634 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10635 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10636 ok(!!value32
, "Unexpected value %#x.\n", value32
);
10637 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10638 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10639 ok(!!value32
, "Unexpected value %u.\n", value32
);
10640 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10641 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10642 ok(value32
== -128, "Unexpected value %d.\n", value32
);
10644 /* Negative height. */
10645 vih
.bmiHeader
.biHeight
= -24;
10647 hr
= MFInitMediaTypeFromAMMediaType(media_type
, &mt
);
10648 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10650 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
10651 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10652 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10653 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10654 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10655 ok(IsEqualGUID(&guid
, &MFVideoFormat_RGB32
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10656 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10657 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10658 ok(value64
== ((UINT64
)32 << 32 | 24), "Unexpected value %#I64x.\n", value64
);
10659 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_PIXEL_ASPECT_RATIO
, &value64
);
10660 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10661 ok(value64
== ((UINT64
)1 << 32 | 1), "Unexpected value %#I64x.\n", value64
);
10662 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_INTERLACE_MODE
, &value32
);
10663 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10664 ok(value32
== MFVideoInterlace_Progressive
, "Unexpected value %#x.\n", value32
);
10665 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10666 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10667 ok(value32
== 3072, "Unexpected value %u.\n", value32
);
10668 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_ALL_SAMPLES_INDEPENDENT
, &value32
);
10669 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10670 ok(!!value32
, "Unexpected value %#x.\n", value32
);
10671 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_FIXED_SIZE_SAMPLES
, &value32
);
10672 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10673 ok(!!value32
, "Unexpected value %u.\n", value32
);
10674 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10675 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10676 ok(value32
== 128, "Unexpected value %d.\n", value32
);
10678 /* only rcSource is considered, lSampleSize is ignored if biSizeImage was present */
10679 memcpy(&mt
.subtype
, &MEDIASUBTYPE_RGB32
, sizeof(GUID
));
10680 vih
.rcSource
= source
;
10681 vih
.rcTarget
= target
;
10682 vih
.bmiHeader
.biWidth
= 432;
10683 vih
.bmiHeader
.biHeight
= -654;
10684 vih
.bmiHeader
.biSizeImage
= 12345678;
10685 mt
.lSampleSize
= 87654321;
10686 hr
= MFInitMediaTypeFromAMMediaType(media_type
, &mt
);
10687 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10689 hr
= IMFMediaType_GetUINT64(media_type
, &MF_MT_FRAME_SIZE
, &value64
);
10690 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10691 ok((UINT32
)(value64
>> 32) == 432, "got %d.\n", (UINT32
)(value64
>> 32));
10692 ok((UINT32
)value64
== 654, "got %d.\n", (UINT32
)value64
);
10693 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_DEFAULT_STRIDE
, &value32
);
10694 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10695 ok(value32
== 432 * 4, "got %d.\n", (UINT32
)value32
);
10696 hr
= IMFMediaType_GetUINT32(media_type
, &MF_MT_SAMPLE_SIZE
, &value32
);
10697 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10698 ok(value32
== 12345678, "got %d.\n", (UINT32
)value32
);
10699 hr
= IMFMediaType_GetBlob(media_type
, &MF_MT_MINIMUM_DISPLAY_APERTURE
, (BYTE
*)&aperture
, sizeof(aperture
), &value32
);
10700 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10701 ok(value32
== sizeof(aperture
), "got %d.\n", value32
);
10702 ok(!memcmp(&aperture
, &expect_aperture
, sizeof(aperture
)), "unexpected aperture\n");
10704 vih
.bmiHeader
.biHeight
= 24;
10705 for (i
= 0; i
< ARRAY_SIZE(guid_types
); ++i
)
10707 winetest_push_context("%s", debugstr_guid(guid_types
[i
].am_type
));
10708 memcpy(&mt
.subtype
, guid_types
[i
].am_type
, sizeof(GUID
));
10710 hr
= MFInitMediaTypeFromAMMediaType(media_type
, &mt
);
10711 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10713 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_MAJOR_TYPE
, &guid
);
10714 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10715 ok(IsEqualGUID(&guid
, &MFMediaType_Video
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10716 hr
= IMFMediaType_GetGUID(media_type
, &MF_MT_SUBTYPE
, &guid
);
10717 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
10718 ok(IsEqualGUID(&guid
, guid_types
[i
].mf_type
), "Unexpected guid %s.\n", debugstr_guid(&guid
));
10719 winetest_pop_context();
10722 IMFMediaType_Release(media_type
);
10725 static void test_MFCreatePathFromURL(void)
10727 static const struct
10735 /* 0 leading slash */
10736 { L
"file:c:/foo/bar", L
"c:\\foo\\bar" },
10737 { L
"file:c|/foo/bar", L
"c:\\foo\\bar" },
10738 { L
"file:cx|/foo/bar", L
"cx|\\foo\\bar" },
10739 { L
"file:c:foo/bar", L
"c:foo\\bar" },
10740 { L
"file:c|foo/bar", L
"c:foo\\bar" },
10741 { L
"file:c:/foo%20ba%2fr", L
"c:\\foo ba/r" },
10742 { L
"file:foo%20ba%2fr", L
"foo ba/r" },
10743 { L
"file:foo/bar/", L
"foo\\bar\\" },
10745 /* 1 leading (back)slash */
10746 { L
"file:/c:/foo/bar", L
"c:\\foo\\bar" },
10747 { L
"file:\\c:/foo/bar", L
"c:\\foo\\bar" },
10748 { L
"file:/c|/foo/bar", L
"c:\\foo\\bar" },
10749 { L
"file:/cx|/foo/bar", L
"\\cx|\\foo\\bar" },
10750 { L
"file:/c:foo/bar", L
"c:foo\\bar" },
10751 { L
"file:/c|foo/bar", L
"c:foo\\bar" },
10752 { L
"file:/c:/foo%20ba%2fr", L
"c:\\foo ba/r" },
10753 { L
"file:/foo%20ba%2fr", L
"\\foo ba/r" },
10754 { L
"file:/foo/bar/", L
"\\foo\\bar\\" },
10756 /* 2 leading (back)slashes */
10757 { L
"file://c:/foo/bar", L
"c:\\foo\\bar" },
10758 { L
"file://c:/d:/foo/bar", L
"c:\\d:\\foo\\bar" },
10759 { L
"file://c|/d|/foo/bar", L
"c:\\d|\\foo\\bar" },
10760 { L
"file://cx|/foo/bar", L
"\\\\cx|\\foo\\bar" },
10761 { L
"file://c:foo/bar", L
"c:foo\\bar" },
10762 { L
"file://c|foo/bar", L
"c:foo\\bar" },
10763 { L
"file://c:/foo%20ba%2fr", L
"c:\\foo%20ba%2fr" },
10764 { L
"file://c%3a/foo/../bar", L
"\\\\c:\\foo\\..\\bar" },
10765 { L
"file://c%7c/foo/../bar", L
"\\\\c|\\foo\\..\\bar" },
10766 { L
"file://foo%20ba%2fr", L
"\\\\foo ba/r" },
10767 { L
"file://localhost/c:/foo/bar", L
"c:\\foo\\bar" },
10768 { L
"file://localhost/c:/foo%20ba%5Cr", L
"c:\\foo ba\\r" },
10769 { L
"file://LocalHost/c:/foo/bar", L
"c:\\foo\\bar" },
10770 { L
"file:\\\\localhost\\c:\\foo\\bar", L
"c:\\foo\\bar" },
10771 { L
"file://incomplete", L
"\\\\incomplete" },
10773 /* 3 leading (back)slashes (omitting hostname) */
10774 { L
"file:///c:/foo/bar", L
"c:\\foo\\bar" },
10775 { L
"File:///c:/foo/bar", L
"c:\\foo\\bar" },
10776 { L
"file:///c:/foo%20ba%2fr", L
"c:\\foo ba/r" },
10777 { L
"file:///foo%20ba%2fr", L
"\\foo ba/r" },
10778 { L
"file:///foo/bar/", L
"\\foo\\bar\\" },
10779 { L
"file:///localhost/c:/foo/bar", L
"\\localhost\\c:\\foo\\bar" },
10781 /* 4 leading (back)slashes */
10782 { L
"file:////c:/foo/bar", L
"c:\\foo\\bar" },
10783 { L
"file:////c:/foo%20ba%2fr", L
"c:\\foo%20ba%2fr" },
10784 { L
"file:////foo%20ba%2fr", L
"\\\\foo%20ba%2fr" },
10786 /* 5 and more leading (back)slashes */
10787 { L
"file://///c:/foo/bar", L
"\\\\c:\\foo\\bar" },
10788 { L
"file://///c:/foo%20ba%2fr", L
"\\\\c:\\foo ba/r" },
10789 { L
"file://///foo%20ba%2fr", L
"\\\\foo ba/r" },
10790 { L
"file://////c:/foo/bar", L
"\\\\c:\\foo\\bar" },
10792 /* Leading (back)slashes cannot be escaped */
10793 { L
"file:%2f%2flocalhost%2fc:/foo/bar", L
"//localhost/c:\\foo\\bar" },
10794 { L
"file:%5C%5Clocalhost%5Cc:/foo/bar", L
"\\\\localhost\\c:\\foo\\bar" },
10796 /* Hostname handling */
10797 { L
"file://l%6fcalhost/c:/foo/bar", L
"\\\\localhostc:\\foo\\bar" },
10798 { L
"file://localhost:80/c:/foo/bar", L
"\\\\localhost:80c:\\foo\\bar" },
10799 { L
"file://host/c:/foo/bar", L
"\\\\hostc:\\foo\\bar" },
10800 { L
"file://host//c:/foo/bar", L
"\\\\host\\\\c:\\foo\\bar" },
10801 { L
"file://host/\\c:/foo/bar", L
"\\\\host\\\\c:\\foo\\bar" },
10802 { L
"file://host/c:foo/bar", L
"\\\\hostc:foo\\bar" },
10803 { L
"file://host/foo/bar", L
"\\\\host\\foo\\bar" },
10804 { L
"file:\\\\host\\c:\\foo\\bar", L
"\\\\hostc:\\foo\\bar" },
10805 { L
"file:\\\\host\\ca\\foo\\bar", L
"\\\\host\\ca\\foo\\bar" },
10806 { L
"file:\\\\host\\c|\\foo\\bar", L
"\\\\hostc|\\foo\\bar" },
10807 { L
"file:\\%5Chost\\c:\\foo\\bar", L
"\\\\host\\c:\\foo\\bar" },
10808 { L
"file:\\\\host\\cx:\\foo\\bar", L
"\\\\host\\cx:\\foo\\bar" },
10809 { L
"file:///host/c:/foo/bar", L
"\\host\\c:\\foo\\bar" },
10811 /* Not file URLs */
10812 { L
"c:\\foo\\bar", NULL
, E_INVALIDARG
},
10813 { L
"foo/bar", NULL
, E_INVALIDARG
},
10814 { L
"http://foo/bar", NULL
, E_INVALIDARG
},
10820 if (!pMFCreatePathFromURL
)
10822 win_skip("MFCreatePathFromURL() is not available.\n");
10826 hr
= pMFCreatePathFromURL(NULL
, NULL
);
10827 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
10829 path
= (void *)0xdeadbeef;
10830 hr
= pMFCreatePathFromURL(NULL
, &path
);
10831 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
10832 ok(path
== (void *)0xdeadbeef, "Unexpected pointer %p.\n", path
);
10834 hr
= pMFCreatePathFromURL(L
"file://foo", NULL
);
10835 ok(hr
== E_POINTER
, "Unexpected hr %#lx.\n", hr
);
10837 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
10839 hr
= pMFCreatePathFromURL(tests
[i
].url
, &path
);
10840 ok(hr
== tests
[i
].hr
, "Unexpected hr %#lx, expected %#lx.\n", hr
, tests
[i
].hr
);
10843 ok(!wcscmp(path
, tests
[i
].path
), "Unexpected path %s, expected %s.\n",
10844 debugstr_w(path
), debugstr_w(tests
[i
].path
));
10845 CoTaskMemFree(path
);
10850 #define check_reset_data(a, b, c, d, e) check_reset_data_(__LINE__, a, b, c, d, e)
10851 static void check_reset_data_(unsigned int line
, IMF2DBuffer2
*buffer2d
, const BYTE
*data
, BOOL bottom_up
,
10852 DWORD width
, DWORD height
)
10854 BYTE
*scanline0
, *buffer_start
;
10855 DWORD length
, max_length
;
10856 IMFMediaBuffer
*buffer
;
10862 hr
= IMF2DBuffer2_QueryInterface(buffer2d
, &IID_IMFMediaBuffer
, (void **)&buffer
);
10863 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10865 hr
= IMF2DBuffer2_Lock2DSize(buffer2d
, MF2DBuffer_LockFlags_Read
, &scanline0
, &pitch
, &buffer_start
, &length
);
10866 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10869 ok(pitch
< 0, "got pitch %ld.\n", pitch
);
10870 ok(buffer_start
== scanline0
+ pitch
* (LONG
)(height
- 1), "buffer start mismatch.\n");
10874 ok(pitch
> 0, "got pitch %ld.\n", pitch
);
10875 ok(buffer_start
== scanline0
, "buffer start mismatch.\n");
10877 for (i
= 0; i
< height
; ++i
)
10878 ok_(__FILE__
,line
)(!memcmp(buffer_start
+ abs(pitch
) * i
, data
+ width
* i
* 4, width
* 4),
10879 "2D Data mismatch, scaline %d.\n", i
);
10880 hr
= IMF2DBuffer2_Unlock2D(buffer2d
);
10881 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10883 hr
= IMFMediaBuffer_Lock(buffer
, &lock
, &max_length
, &length
);
10884 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10885 ok_(__FILE__
,line
)(max_length
== width
* height
* 4, "got max_length %lu.\n", max_length
);
10886 ok_(__FILE__
,line
)(length
== width
* height
* 4, "got length %lu.\n", length
);
10887 ok_(__FILE__
,line
)(!memcmp(lock
, data
, length
), "contiguous data mismatch.\n");
10888 memset(lock
, 0xcc, length
);
10889 hr
= IMFMediaBuffer_Unlock(buffer
);
10890 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10892 IMFMediaBuffer_Release(buffer
);
10895 static void test_2dbuffer_copy_(IMFMediaBuffer
*buffer
, BOOL bottom_up
, DWORD width
, DWORD height
)
10897 static const unsigned int test_data
[] =
10899 0x01010101, 0x01010101,
10900 0x02020202, 0x02020202,
10903 BYTE data
[sizeof(test_data
)];
10904 IMFMediaBuffer
*src_buffer
;
10905 DWORD length
, max_length
;
10906 IMF2DBuffer2
*buffer2d
;
10912 hr
= IMFMediaBuffer_QueryInterface(buffer
, &IID_IMF2DBuffer2
, (void **)&buffer2d
);
10913 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10915 hr
= MFCreateSample(&sample
);
10916 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10917 hr
= MFCreateMemoryBuffer(sizeof(test_data
) * 2, &src_buffer
);
10918 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10919 hr
= IMFSample_AddBuffer(sample
, src_buffer
);
10920 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10922 hr
= IMFMediaBuffer_Lock(src_buffer
, &lock
, &max_length
, &length
);
10923 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10924 ok(max_length
== sizeof(test_data
) * 2, "got %lu.\n", max_length
);
10925 memcpy(lock
, test_data
, sizeof(test_data
));
10926 hr
= IMFMediaBuffer_Unlock(src_buffer
);
10927 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10929 hr
= IMFMediaBuffer_Lock(buffer
, &lock
, &max_length
, &length
);
10930 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10931 ok(max_length
== 16, "got %lu.\n", max_length
);
10932 ok(length
== 16, "got %lu.\n", length
);
10933 memset(lock
, 0xcc, length
);
10934 hr
= IMFMediaBuffer_Unlock(buffer
);
10935 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10937 hr
= IMFMediaBuffer_SetCurrentLength(src_buffer
, 1);
10938 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10939 hr
= IMFSample_CopyToBuffer(sample
, buffer
);
10940 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10942 memset(data
, 0xcc, sizeof(data
));
10943 data
[0] = ((BYTE
*)test_data
)[0];
10944 check_reset_data(buffer2d
, data
, bottom_up
, width
, height
);
10946 hr
= IMF2DBuffer2_ContiguousCopyFrom(buffer2d
, (BYTE
*)test_data
, sizeof(test_data
));
10947 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10948 hr
= IMF2DBuffer2_ContiguousCopyTo(buffer2d
, data
, sizeof(data
));
10949 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10950 ok(!memcmp(data
, test_data
, sizeof(data
)), "data mismatch.\n");
10952 check_reset_data(buffer2d
, (const BYTE
*)test_data
, bottom_up
, width
, height
);
10954 hr
= IMFMediaBuffer_SetCurrentLength(src_buffer
, sizeof(test_data
) + 1);
10955 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10956 hr
= IMFSample_CopyToBuffer(sample
, buffer
);
10957 ok(hr
== MF_E_BUFFERTOOSMALL
, "got hr %#lx.\n", hr
);
10959 hr
= IMFMediaBuffer_SetCurrentLength(src_buffer
, sizeof(test_data
));
10960 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10961 hr
= IMFSample_CopyToBuffer(sample
, buffer
);
10962 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10964 check_reset_data(buffer2d
, (const BYTE
*)test_data
, bottom_up
, width
, height
);
10966 IMF2DBuffer2_Release(buffer2d
);
10967 ref
= IMFSample_Release(sample
);
10968 ok(!ref
, "got %lu.\n", ref
);
10969 ref
= IMFMediaBuffer_Release(src_buffer
);
10970 ok(!ref
, "got %lu.\n", ref
);
10973 static void test_2dbuffer_copy(void)
10975 D3D11_TEXTURE2D_DESC desc
;
10976 ID3D11Texture2D
*texture
;
10977 IMFMediaBuffer
*buffer
;
10978 ID3D11Device
*device
;
10982 if (!pMFCreate2DMediaBuffer
)
10984 win_skip("MFCreate2DMediaBuffer() is not available.\n");
10988 winetest_push_context("top down");
10989 hr
= pMFCreate2DMediaBuffer(2, 2, D3DFMT_A8R8G8B8
, FALSE
, &buffer
);
10990 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10991 test_2dbuffer_copy_(buffer
, FALSE
, 2, 2);
10992 ref
= IMFMediaBuffer_Release(buffer
);
10993 ok(!ref
, "got %lu.\n", ref
);
10994 winetest_pop_context();
10996 winetest_push_context("bottom up");
10997 hr
= pMFCreate2DMediaBuffer(2, 2, D3DFMT_A8R8G8B8
, TRUE
, &buffer
);
10998 ok(hr
== S_OK
, "got hr %#lx.\n", hr
);
10999 test_2dbuffer_copy_(buffer
, TRUE
, 2, 2);
11000 ref
= IMFMediaBuffer_Release(buffer
);
11001 ok(!ref
, "got %lu.\n", ref
);
11002 winetest_pop_context();
11004 if (!pMFCreateDXGISurfaceBuffer
)
11006 win_skip("MFCreateDXGISurfaceBuffer() is not available.\n");
11010 if (!(device
= create_d3d11_device()))
11012 skip("Failed to create a D3D11 device, skipping tests.\n");
11016 memset(&desc
, 0, sizeof(desc
));
11019 desc
.ArraySize
= 1;
11020 desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
11021 desc
.SampleDesc
.Count
= 1;
11022 desc
.SampleDesc
.Quality
= 0;
11023 hr
= ID3D11Device_CreateTexture2D(device
, &desc
, NULL
, &texture
);
11024 ok(hr
== S_OK
, "Failed to create a texture, hr %#lx.\n", hr
);
11026 hr
= pMFCreateDXGISurfaceBuffer(&IID_ID3D11Texture2D
, (IUnknown
*)texture
, 0, FALSE
, &buffer
);
11027 ok(hr
== S_OK
, "Failed to create a buffer, hr %#lx.\n", hr
);
11028 test_2dbuffer_copy_(buffer
, FALSE
, 2, 2);
11030 ID3D11Texture2D_Release(texture
);
11031 ref
= IMFMediaBuffer_Release(buffer
);
11032 ok(!ref
, "got %lu.\n", ref
);
11033 ID3D11Device_Release(device
);
11043 argc
= winetest_get_mainargs(&argv
);
11046 test_queue_com_state(argv
[2]);
11050 if (!pMFCreateVideoSampleAllocatorEx
)
11051 win_skip("MFCreateVideoSampleAllocatorEx() is not available. Some tests will be skipped.\n");
11053 if (!pD3D12CreateDevice
)
11054 skip("Missing d3d12 support, some tests will be skipped.\n");
11056 CoInitialize(NULL
);
11061 test_MFCreateMediaEvent();
11064 test_file_stream();
11065 test_MFCreateMFByteStreamOnStream();
11066 test_system_memory_buffer();
11067 test_system_memory_aligned_buffer();
11068 test_source_resolver();
11069 test_MFCreateAsyncResult();
11070 test_allocate_queue();
11071 test_MFLockSharedWorkQueue();
11072 test_MFCopyImage();
11073 test_MFCreateCollection();
11074 test_MFHeapAlloc();
11075 test_scheduled_items();
11076 test_serial_queue();
11077 test_periodic_callback();
11078 test_event_queue();
11079 test_presentation_descriptor();
11080 test_system_time_source();
11081 test_MFInvokeCallback();
11082 test_stream_descriptor();
11083 test_MFCalculateImageSize();
11084 test_MFGetPlaneSize();
11085 test_MFCompareFullToPartialMediaType();
11086 test_attributes_serialization();
11087 test_wrapped_media_type();
11088 test_MFCreateWaveFormatExFromMFMediaType();
11089 test_async_create_file();
11090 test_local_handlers();
11091 test_create_property_store();
11092 test_dxgi_device_manager();
11093 test_MFCreateTransformActivate();
11094 test_MFTRegisterLocal();
11096 test_MFGetStrideForBitmapInfoHeader();
11097 test_MFCreate2DMediaBuffer();
11098 test_MFCreateMediaBufferFromMediaType();
11099 test_MFInitMediaTypeFromWaveFormatEx();
11100 test_MFCreateMFVideoFormatFromMFMediaType();
11101 test_MFInitAMMediaTypeFromMFMediaType();
11102 test_MFCreateAMMediaTypeFromMFMediaType();
11103 test_IMFMediaType_GetRepresentation();
11104 test_MFCreateDXSurfaceBuffer();
11105 test_MFCreateTrackedSample();
11106 test_MFFrameRateToAverageTimePerFrame();
11107 test_MFAverageTimePerFrameToFrameRate();
11108 test_MFMapDXGIFormatToDX9Format();
11109 test_d3d11_surface_buffer();
11110 test_d3d12_surface_buffer();
11111 test_sample_allocator_sysmem();
11112 test_sample_allocator_d3d9();
11113 test_sample_allocator_d3d11();
11114 test_sample_allocator_d3d12();
11115 test_MFMapDX9FormatToDXGIFormat();
11117 test_shared_dxgi_device_manager();
11118 test_MFInitVideoFormat_RGB();
11119 test_MFCreateVideoMediaTypeFromVideoInfoHeader();
11120 test_MFInitMediaTypeFromVideoInfoHeader();
11121 test_MFInitMediaTypeFromVideoInfoHeader2();
11122 test_MFInitMediaTypeFromAMMediaType();
11123 test_MFCreatePathFromURL();
11124 test_2dbuffer_copy();