From 68d2b338dad95ac2b8c8641c9bba6096b7c62e20 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 10 Feb 2022 11:21:27 +0300 Subject: [PATCH] mfplat: Implement MFCreateTempFile(). Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/mfplat/Makefile.in | 3 +- dlls/mfplat/main.c | 66 +++++++++++++++++++++++++++++++++-------- dlls/mfplat/mfplat.spec | 2 +- include/mfapi.h | 2 ++ 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/dlls/mfplat/Makefile.in b/dlls/mfplat/Makefile.in index 79af7650de6..f4ef8e5649c 100644 --- a/dlls/mfplat/Makefile.in +++ b/dlls/mfplat/Makefile.in @@ -1,7 +1,8 @@ EXTRADEFS = -DWINE_NO_LONG_TYPES MODULE = mfplat.dll IMPORTLIB = mfplat -IMPORTS = advapi32 ole32 mfuuid propsys rtworkq +IMPORTS = advapi32 ole32 mfuuid propsys rtworkq kernelbase +DELAYIMPORTS = bcrypt EXTRADLLFLAGS = -Wb,--prefer-native diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c index 7e2527fc024..7a1f10dac24 100644 --- a/dlls/mfplat/main.c +++ b/dlls/mfplat/main.c @@ -52,6 +52,9 @@ #include "initguid.h" #include "mfd3d12.h" +#include "bcrypt.h" +#include "pathcch.h" + WINE_DEFAULT_DEBUG_CHANNEL(mfplat); struct local_handler @@ -4576,11 +4579,8 @@ static const IMFGetServiceVtbl bytestream_file_getservice_vtbl = bytestream_file_getservice_GetService, }; -/*********************************************************************** - * MFCreateFile (mfplat.@) - */ -HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE openmode, MF_FILE_FLAGS flags, - LPCWSTR url, IMFByteStream **bytestream) +static HRESULT create_file_bytestream(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE openmode, MF_FILE_FLAGS flags, + const WCHAR *path, BOOL is_tempfile, IMFByteStream **bytestream) { DWORD capabilities = MFBYTESTREAM_IS_SEEKABLE | MFBYTESTREAM_DOES_NOT_USE_NETWORK; DWORD filecreation_disposition = 0, fileaccessmode = 0, fileattributes = 0; @@ -4590,8 +4590,6 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open HANDLE file; HRESULT hr; - TRACE("%d, %d, %#x, %s, %p.\n", accessmode, openmode, flags, debugstr_w(url), bytestream); - switch (accessmode) { case MF_ACCESSMODE_READ: @@ -4630,12 +4628,12 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open if (flags & MF_FILEFLAGS_NOBUFFERING) fileattributes |= FILE_FLAG_NO_BUFFERING; + if (is_tempfile) + fileattributes |= FILE_FLAG_DELETE_ON_CLOSE; /* Open HANDLE to file */ - file = CreateFileW(url, fileaccessmode, filesharemode, NULL, - filecreation_disposition, fileattributes, 0); - - if(file == INVALID_HANDLE_VALUE) + file = CreateFileW(path, fileaccessmode, filesharemode, NULL, filecreation_disposition, fileattributes, 0); + if (file == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError()); if (!(object = calloc(1, sizeof(*object)))) @@ -4660,19 +4658,61 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open object->capabilities = capabilities; object->hfile = file; - if (GetFileTime(file, NULL, NULL, &writetime)) + if (!is_tempfile && GetFileTime(file, NULL, NULL, &writetime)) { IMFAttributes_SetBlob(&object->attributes.IMFAttributes_iface, &MF_BYTESTREAM_LAST_MODIFIED_TIME, (const UINT8 *)&writetime, sizeof(writetime)); } - IMFAttributes_SetString(&object->attributes.IMFAttributes_iface, &MF_BYTESTREAM_ORIGIN_NAME, url); + IMFAttributes_SetString(&object->attributes.IMFAttributes_iface, &MF_BYTESTREAM_ORIGIN_NAME, path); *bytestream = &object->IMFByteStream_iface; return S_OK; } +/*********************************************************************** + * MFCreateFile (mfplat.@) + */ +HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE openmode, MF_FILE_FLAGS flags, + const WCHAR *path, IMFByteStream **bytestream) +{ + TRACE("%d, %d, %#x, %s, %p.\n", accessmode, openmode, flags, debugstr_w(path), bytestream); + + return create_file_bytestream(accessmode, openmode, flags, path, FALSE, bytestream); +} + +/*********************************************************************** + * MFCreateTempFile (mfplat.@) + */ +HRESULT WINAPI MFCreateTempFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE openmode, MF_FILE_FLAGS flags, + IMFByteStream **bytestream) +{ + WCHAR name[24], tmppath[MAX_PATH], *path; + ULONG64 rnd; + size_t len; + HRESULT hr; + + TRACE("%d, %d, %#x, %p.\n", accessmode, openmode, flags, bytestream); + + BCryptGenRandom(NULL, (UCHAR *)&rnd, sizeof(rnd), BCRYPT_USE_SYSTEM_PREFERRED_RNG); + swprintf(name, ARRAY_SIZE(name), L"MFP%llX.TMP", rnd); + GetTempPathW(ARRAY_SIZE(tmppath), tmppath); + + len = wcslen(tmppath) + wcslen(name) + 2; + if (!(path = malloc(len * sizeof(*path)))) + return E_OUTOFMEMORY; + + wcscpy(path, tmppath); + PathCchAppend(path, len, name); + + hr = create_file_bytestream(accessmode, openmode, flags, path, TRUE, bytestream); + + free(path); + + return hr; +} + struct bytestream_wrapper { IMFByteStreamCacheControl IMFByteStreamCacheControl_iface; diff --git a/dlls/mfplat/mfplat.spec b/dlls/mfplat/mfplat.spec index 57f4e3c0d6c..5d177732fa8 100644 --- a/dlls/mfplat/mfplat.spec +++ b/dlls/mfplat/mfplat.spec @@ -71,7 +71,7 @@ @ stdcall MFCreateStreamDescriptor(long long ptr ptr) @ stdcall MFCreateSystemTimeSource(ptr) @ stub MFCreateSystemUnderlyingClock -@ stub MFCreateTempFile +@ stdcall MFCreateTempFile(long long long ptr) @ stdcall MFCreateTrackedSample(ptr) @ stdcall MFCreateTransformActivate(ptr) @ stub MFCreateURLFromPath diff --git a/include/mfapi.h b/include/mfapi.h index d4493501624..105613693c9 100644 --- a/include/mfapi.h +++ b/include/mfapi.h @@ -533,6 +533,8 @@ HRESULT WINAPI MFCreateMediaEvent(MediaEventType type, REFGUID extended_type, HR HRESULT WINAPI MFCreateMediaType(IMFMediaType **type); HRESULT WINAPI MFCreateMFVideoFormatFromMFMediaType(IMFMediaType *media_type, MFVIDEOFORMAT **video_format, UINT32 *size); HRESULT WINAPI MFCreateSample(IMFSample **sample); +HRESULT WINAPI MFCreateTempFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE openmode, MF_FILE_FLAGS flags, + IMFByteStream **bytestream); HRESULT WINAPI MFCreateVideoMediaTypeFromSubtype(const GUID *subtype, IMFVideoMediaType **media_type); HRESULT WINAPI MFCreateVideoSampleAllocatorEx(REFIID riid, void **allocator); HRESULT WINAPI MFCreateMemoryBuffer(DWORD max_length, IMFMediaBuffer **buffer);