Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- This test doesn't work with Wine because Wine doesn't support shareable resources, but it works with DXVK.
Also, it doesn't work on the testbot, possibly because of the testbot's D3D drivers. However, it runs fine on my Windows 10 machine.
For both these reasons, I am not sure this commit is appropriate for Wine, but I am providing it anyway in case it is useful for reviewers. --- dlls/mfreadwrite/tests/Makefile.in | 2 +- dlls/mfreadwrite/tests/mfplat.c | 141 +++++++++++++++++++++++++++++ dlls/mfreadwrite/tests/resource.rc | 2 + dlls/mfreadwrite/tests/test.mp4 | Bin 0 -> 1846 bytes 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 dlls/mfreadwrite/tests/test.mp4
diff --git a/dlls/mfreadwrite/tests/Makefile.in b/dlls/mfreadwrite/tests/Makefile.in index c7476c14c6b..765f3c49932 100644 --- a/dlls/mfreadwrite/tests/Makefile.in +++ b/dlls/mfreadwrite/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = mfreadwrite.dll -IMPORTS = ole32 user32 d3d9 dxva2 mfplat mfreadwrite mfuuid +IMPORTS = ole32 user32 d3d9 dxva2 mfplat mfreadwrite mfuuid d3d11 dxguid
C_SRCS = \ mfplat.c diff --git a/dlls/mfreadwrite/tests/mfplat.c b/dlls/mfreadwrite/tests/mfplat.c index fcf642859d5..929224a66cb 100644 --- a/dlls/mfreadwrite/tests/mfplat.c +++ b/dlls/mfreadwrite/tests/mfplat.c @@ -38,6 +38,8 @@ DEFINE_GUID(GUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); #include "mferror.h" #include "mfreadwrite.h" #include "d3d9.h" +#include "d3d11.h" +#include "dxgi.h" #include "dxva2api.h"
#include "wine/test.h" @@ -1225,6 +1227,144 @@ done: DestroyWindow(window); }
+static WCHAR *load_resource(const WCHAR *name) +{ + static WCHAR pathW[MAX_PATH]; + DWORD written; + HANDLE file; + HRSRC res; + void *ptr; + + GetTempPathW(ARRAY_SIZE(pathW), pathW); + lstrcatW(pathW, name); + + file = CreateFileW(pathW, GENERIC_READ|GENERIC_WRITE, 0, + NULL, CREATE_ALWAYS, 0, 0); + ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", + wine_dbgstr_w(pathW), GetLastError()); + + res = FindResourceW(NULL, name, (LPCWSTR)RT_RCDATA); + ok(res != 0, "couldn't find resource\n"); + ptr = LockResource(LoadResource(GetModuleHandleA(NULL), res)); + WriteFile(file, ptr, SizeofResource(GetModuleHandleA(NULL), res), + &written, NULL); + ok(written == SizeofResource(GetModuleHandleA(NULL), res), + "couldn't write resource\n" ); + CloseHandle(file); + + return pathW; +} + +static void test_reader_dxgi(void) +{ + IMFDXGIDeviceManager *device_manager; + ID3D11Device *device; + IMFAttributes *attributes, *output_attributes; + IMFSourceReader *reader; + HRESULT hr; + UINT token; + DWORD stream_idx, flags; + LONGLONG timestamp; + IMFSample *sample; + IMFMediaType *media_type; + WCHAR *filename; + IMFMediaBuffer *buffer; + IMFDXGIBuffer *dxgi_buffer; + IDXGIResource *dxgi_resource; + IMFTransform *transform; + + hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device, NULL, NULL); + ok(hr == S_OK, "Cannot create D3D11 device, hr %#x.\n", hr); + + if (hr != S_OK) + { + skip("Failed to create a D3D11 device, skipping tests.\n"); + return; + } + + hr = MFCreateDXGIDeviceManager(&token, &device_manager); + ok(hr == S_OK, "Cannot create DXGI device manager, hr %#x.\n", hr); + + hr = IMFDXGIDeviceManager_ResetDevice(device_manager, (IUnknown *)device, token); + ok(hr == S_OK, "Cannot reset device, hr %#x.\n", hr); + + hr = MFCreateAttributes(&attributes, 1); + ok(hr == S_OK, "Failed to create attributes object, hr %#x.\n", hr); + + hr = IMFAttributes_SetUnknown(attributes, &MF_SOURCE_READER_D3D_MANAGER, (IUnknown *)device_manager); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + hr = IMFAttributes_SetUINT32(attributes, &MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING, TRUE); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + + filename = load_resource(L"test.mp4"); + hr = MFCreateSourceReaderFromURL(filename, attributes, &reader); + ok(hr == S_OK, "Failed to create source reader, hr %#x.\n", hr); + + IMFAttributes_Release(attributes); + + hr = MFCreateMediaType(&media_type); + ok(hr == S_OK, "Failed to create media type, hr %#x.\n", hr); + + hr = IMFMediaType_SetGUID(media_type, &MF_MT_MAJOR_TYPE, &MFMediaType_Video); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + hr = IMFMediaType_SetGUID(media_type, &MF_MT_SUBTYPE, &MFVideoFormat_ARGB32); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + + hr = IMFSourceReader_SetStreamSelection(reader, MF_SOURCE_READER_ALL_STREAMS, FALSE); + ok(hr == S_OK, "Failed to select first video stream, hr %#x.\n", hr); + hr = IMFSourceReader_SetStreamSelection(reader, MF_SOURCE_READER_FIRST_VIDEO_STREAM, TRUE); + ok(hr == S_OK, "Failed to select first video stream, hr %#x.\n", hr); + + hr = IMFSourceReader_SetCurrentMediaType(reader, MF_SOURCE_READER_FIRST_VIDEO_STREAM, NULL, media_type); + ok(hr == S_OK, "Failed to select current media type, hr %#x.\n", hr); + + IMFMediaType_Release(media_type); + + hr = IMFSourceReader_GetServiceForStream(reader, MF_SOURCE_READER_FIRST_VIDEO_STREAM, &GUID_NULL, &IID_IMFTransform, (void **)&transform); + ok(hr == S_OK, "Failed to get transform, hr %#x.\n", hr); + + hr = IMFTransform_GetOutputStreamAttributes(transform, 0, &output_attributes); + ok(hr == S_OK, "Failed to get output stream attributes, hr %#x.\n", hr); + + hr = IMFAttributes_SetUINT32(output_attributes, &MF_SA_D3D11_USAGE, D3D11_USAGE_DEFAULT); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + hr = IMFAttributes_SetUINT32(output_attributes, &MF_SA_D3D11_SHARED_WITHOUT_MUTEX, TRUE); + ok(hr == S_OK, "Failed to set attribute, hr %#x.\n", hr); + + IMFAttributes_Release(output_attributes); + IMFTransform_Release(transform); + + hr = IMFSourceReader_ReadSample(reader, MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, &stream_idx, &flags, ×tamp, &sample); + ok(hr == S_OK, "Failed to read sample, hr %#x.\n", hr); + + hr = IMFSample_ConvertToContiguousBuffer(sample, &buffer); + ok(hr == S_OK, "Failed to convert sample to contiguous buffer, hr %#x.\n", hr); + + hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFDXGIBuffer, (void **)&dxgi_buffer); + ok(hr == S_OK, "Failed to query DXGI buffer, hr %#x.\n", hr); + + hr = IMFDXGIBuffer_GetResource(dxgi_buffer, &IID_IDXGIResource, (void **)&dxgi_resource); + todo_wine ok(hr == S_OK, "Failed to get the DXGI buffer resource, hr %#x.\n", hr); + if (hr == S_OK) + { + HANDLE handle; + + hr = IDXGIResource_GetSharedHandle(dxgi_resource, &handle); + ok(hr == S_OK, "Failed to get shared handle, hr %#x.\n", hr); + ok(handle != NULL, "Got NULL shared handle.\n"); + + IDXGIResource_Release(dxgi_resource); + } + + IMFDXGIBuffer_Release(dxgi_buffer); + IMFMediaBuffer_Release(buffer); + IMFSample_Release(sample); + IMFSourceReader_Release(reader); + + IMFDXGIDeviceManager_Release(device_manager); + ID3D11Device_Release(device); +} + START_TEST(mfplat) { HRESULT hr; @@ -1238,6 +1378,7 @@ START_TEST(mfplat) test_source_reader(); test_source_reader_from_media_source(); test_reader_d3d9(); + test_reader_dxgi();
hr = MFShutdown(); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); diff --git a/dlls/mfreadwrite/tests/resource.rc b/dlls/mfreadwrite/tests/resource.rc index f54212a8c8f..9d7cf12249d 100644 --- a/dlls/mfreadwrite/tests/resource.rc +++ b/dlls/mfreadwrite/tests/resource.rc @@ -20,3 +20,5 @@
/* @makedep: test.wav */ test.wav RCDATA test.wav +/* @makedep: test.mp4 */ +test.mp4 RCDATA test.mp4 diff --git a/dlls/mfreadwrite/tests/test.mp4 b/dlls/mfreadwrite/tests/test.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..ebfce3031f5460b4c955cda4cc40eb9e71640db9 GIT binary patch literal 1846 zcmah~O=w(I6uy&asi7LhC=nvuYLqTAllNxQ$q#+tBnBh4po>;f;d$r2J9)2pf4T2w zGE)UzsJL*UAO*X~&Yy^gAm~ckg$tnzaU%vSGzg*yN_XkPjNf@PNv5gbfqTz){_nZ> z%p1lSZ<ux(WJ$!>03(i77ENhK>6FbFJKE4nF*f*8<Ou_xFOJ;V>3sIf;ve7swzc%l z#fhK!)}w#@-6~h7c#+FQD{faUt}B*pbLpvBF<XIQsRW0~GtVwQRh;6ra|`hFl!Rd+ zN!y`n7+$ulO0jH}Ehv3s(z(gW_4V~qGw@Urinx^M<w>ei@=X-NCrM3^#MvB|qAsLk zbFCUqg?p+VCUV8G=d3x4i&%v1OgUDoGH11HyTT*o_^QRTwK~u=PqQ{cvAf!H?2?5b zY&;5D%5y2BjR;qZcv(4il}leIk#G@ebE8!l1{u&yYsQlXK(0oPg(C>>LJ}*dY){}4 z8X_}pnymyWd2|!3rf$+`WXd?jGB>_P1SJZSWJUN8+yh+}1`=o4Q&>FKc?}sv!q7Q_ z*eD$eI6+?z*R*K6GKo@QAWK}4(ISYE0*+dcPeY4HWw@-mo3?=i&nW{7Po&gE-K_^A zqauM;d0*=)SoTdFwj@=tyPTx3c9khYS5zCho$^Vm2i+)$A@WSBSjjcxOj&eHE$B+M z%6x=t>F&2nb}b#L8$7DxUa2hzPPtOD_$oEySS3u=YD$T7E?Q1?7K+TM)S2Qzibujg z;0=*Wtm6IYHQ5`OV6NVIlTCMaw+DAdet7lfyXUVxr#^n*>ib_O58fEQ@l0nJK6lkF zjfV@b?`}R$BVXH?Z@twS`;l;ALzwx?$FFy>JP*7LJY2ivKmBRV|M2utx3l{}5vrlu z#@mbcO-$|wenf%fj3l2>;Pr0cCIUkQKHu409K}!Tt0+mDFojXm_rUvT@OQ=v@38{* zKJBdn47V5=d!pa>c07Qe@in~03QRAXmAvL)pIa{*>K>*;b^f#N2?Wt%Y+QLJ10Pdi zhEGRM$Uu4T=$(1sY~%$379M$rdoM#h!p?q|#}$1q)H%XNAB8<k{2YBGmPG7@ihKqb z#-sr-(v0$?{l^~ny0$S7vq-@pvL9R1A@AbCmCV#bVDN13LCEJz`YwVK_2=wrPN3~2 zKw3n%dvx^&`)H>Fp^B^v1&<ANw%J3=;Gb`uxv8!^iOHaQ8f4#}TDtf`fgSPx{PpT1 zSN_@Ap$zw?B1^%k3at_RaC(<K{~BYo*l1?*2LQ}{hUjiUBj}4BhG;MT6?xzbKhmRk z&PnW-NhCSX1^$2bJkJ<v$~-cU&Fl8+uv4&I=-G%tKkyUy-B`!^*8RZu9FozCOrRs8 zUM#Honr8&~i;>DXAUobaKo~kL(v;qKpNc_uN*~)a2_<|O|96yxlCsmH**G~<ny!{? G%la1p5|z~e
literal 0 HcmV?d00001