mfplat: Implement MFCreateTempFile().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2022-02-10 11:21:27 +03:00 committed by Alexandre Julliard
parent c058e562fc
commit 68d2b338da
4 changed files with 58 additions and 15 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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);