Superseded patch 157464.
ChangeLog: v2: - Remove unused IMFByteStream_Release().
Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/mfplat/main.c | 21 +++++++----- dlls/mfplat/tests/mfplat.c | 66 ++++++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 21 deletions(-)
diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c index 9497e304cd..a4fd7329e8 100644 --- a/dlls/mfplat/main.c +++ b/dlls/mfplat/main.c @@ -850,7 +850,11 @@ typedef struct _mfbytestream mfattributes attributes; IMFByteStream IMFByteStream_iface;
- IStream *stream; + union + { + IStream *stream; + HANDLE file; + } u; } mfbytestream;
static inline mfbytestream *impl_from_IMFByteStream(IMFByteStream *iface) @@ -903,6 +907,7 @@ static ULONG WINAPI mfbytestream_Release(IMFByteStream *iface)
if (!ref) { + CloseHandle(This->u.file); HeapFree(GetProcessHeap(), 0, This); }
@@ -1081,7 +1086,7 @@ static ULONG WINAPI stream_mfbytestream_Release(IMFByteStream *iface)
if(!ref) { - IStream_Release(This->stream); + IStream_Release(This->u.stream); heap_free(This); }
@@ -1323,7 +1328,7 @@ HRESULT WINAPI MFCreateMFByteStreamOnStream(IStream *stream, IMFByteStream **byt init_attribute_object(&object->attributes, 0); object->IMFByteStream_iface.lpVtbl = &stream_mfbytestream_vtbl; object->attributes.IMFAttributes_iface.lpVtbl = &mfbytestream_attributes_vtbl; - hr = IStream_QueryInterface(stream, &IID_IStream, (void **)&object->stream); + hr = IStream_QueryInterface(stream, &IID_IStream, (void **)&object->u.stream); if(FAILED(hr)) { heap_free(object); @@ -1345,7 +1350,7 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open DWORD fileattributes = 0; HANDLE file;
- FIXME("(%d, %d, %d, %s, %p): stub\n", accessmode, openmode, flags, debugstr_w(url), bytestream); + TRACE("(%d, %d, %d, %s, %p): stub\n", accessmode, openmode, flags, debugstr_w(url), bytestream);
switch (accessmode) { @@ -1383,23 +1388,23 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open if (flags & MF_FILEFLAGS_NOBUFFERING) fileattributes |= FILE_FLAG_NO_BUFFERING;
- /* Open HANDLE to file */ file = CreateFileW(url, fileaccessmode, filesharemode, NULL, filecreation_disposition, fileattributes, 0);
if(file == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(GetLastError());
- /* Close the file again, since we don't do anything with it yet */ - CloseHandle(file); - object = heap_alloc( sizeof(*object) ); if(!object) + { + CloseHandle(file); return E_OUTOFMEMORY; + }
init_attribute_object(&object->attributes, 0); object->IMFByteStream_iface.lpVtbl = &mfbytestream_vtbl; object->attributes.IMFAttributes_iface.lpVtbl = &mfbytestream_attributes_vtbl; + object->u.file = file;
*bytestream = &object->IMFByteStream_iface;
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 0ccc680aca..56575b9538 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -63,6 +63,28 @@ static void _check_ref(IUnknown* obj, ULONG ref, int line) ok_(__FILE__,line)(rc == ref, "expected refcount %d, got %d\n", ref, rc); }
+#define CHECK_BS_POS(obj,pos) _check_bs_pos(obj, pos, __LINE__) +static void _check_bs_pos(IMFByteStream* obj, QWORD pos, int line) +{ + QWORD position = 0xdeadbeef; + HRESULT hr; + hr = IMFByteStream_GetCurrentPosition(obj, &position); + ok_(__FILE__,line)(hr == S_OK, "IMFByteStream_GetCurrentPosition failed: 0x%08x.\n", hr); + ok_(__FILE__,line)(position == pos, "got wrong position: %s.\n", + wine_dbgstr_longlong(position)); +} + +#define CHECK_BS_LEN(obj,len) _check_bs_len(obj, len, __LINE__) +static void _check_bs_len(IMFByteStream* obj, QWORD len, int line) +{ + QWORD length = 0xdeadbeef; + HRESULT hr; + hr = IMFByteStream_GetLength(obj, &length); + ok_(__FILE__,line)(hr == S_OK, "IMFByteStream_GetLength failed: 0x%08x.\n", hr); + ok_(__FILE__,line)(length == len, "got wrong length: %s.\n", + wine_dbgstr_longlong(length)); +} + static WCHAR *load_resource(const WCHAR *name) { static WCHAR pathW[MAX_PATH]; @@ -520,7 +542,8 @@ static void test_MFCreateFile(void) IMFAttributes *attributes = NULL; HRESULT hr; WCHAR *filename; - + LONG file_size; + HANDLE handle; static const WCHAR newfilename[] = {'n','e','w','.','m','p','4',0};
filename = load_resource(mp4file); @@ -545,13 +568,11 @@ static void test_MFCreateFile(void)
hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &bytestream2); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); - if (hr == S_OK) IMFByteStream_Release(bytestream2); + ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr);
hr = MFCreateFile(MF_ACCESSMODE_READWRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, filename, &bytestream2); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); - if (hr == S_OK) IMFByteStream_Release(bytestream2); + ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr);
IMFByteStream_Release(bytestream);
@@ -569,18 +590,15 @@ static void test_MFCreateFile(void)
hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, newfilename, &bytestream2); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); - if (hr == S_OK) IMFByteStream_Release(bytestream2); + ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr);
hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, newfilename, &bytestream2); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); - if (hr == S_OK) IMFByteStream_Release(bytestream2); + ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr);
hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_ALLOW_WRITE_SHARING, newfilename, &bytestream2); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); - if (hr == S_OK) IMFByteStream_Release(bytestream2); + ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr);
IMFByteStream_Release(bytestream);
@@ -591,10 +609,32 @@ static void test_MFCreateFile(void) /* Opening the file again fails even though MF_FILEFLAGS_ALLOW_WRITE_SHARING is set. */ hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_ALLOW_WRITE_SHARING, newfilename, &bytestream2); - todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); - if (hr == S_OK) IMFByteStream_Release(bytestream2); + ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "got 0x%08x\n", hr); + + IMFByteStream_Release(bytestream); + + /* test MF_OPENMODE_APPEND_IF_EXIST */ + handle = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0); + file_size = GetFileSize(handle, NULL); + CloseHandle(handle); + hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_APPEND_IF_EXIST, + MF_FILEFLAGS_ALLOW_WRITE_SHARING, filename, &bytestream); + ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr); + todo_wine CHECK_BS_LEN(bytestream, file_size); + todo_wine CHECK_BS_POS(bytestream, 0); + IMFByteStream_Release(bytestream);
+ /* test MF_OPENMODE_RESET_IF_EXIST */ + hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_RESET_IF_EXIST, + MF_FILEFLAGS_ALLOW_WRITE_SHARING, filename, &bytestream); + ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr); + todo_wine CHECK_BS_LEN(bytestream, 0); + todo_wine CHECK_BS_POS(bytestream, 0); IMFByteStream_Release(bytestream); + handle = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0); + file_size = GetFileSize(handle, NULL); + ok(file_size == 0, "got wrong file size: %d.\n", file_size); + CloseHandle(handle);
MFShutdown();
On 2019/1/30 下午10:45, Jactry Zeng wrote:
- IStream *stream;
- union
- {
IStream *stream;
HANDLE file;
- } u;
} mfbytestream;
Please ignore this series at first.
I tried to implement it(both IStream-based and file-based) with IStream and SHCreateStreamOnFileW() before I submitted these. But I found that it is impossible to handle MF_OPENMODE_RESET_IF_EXIST in that way. So I used CreateFileW for file-based IMFByteStream in this series.
Today I found that it may be a bug of Wine's IStream implementation. So it's still hopeful to make thing more simple by using IStream directly. Will have more tests of IStream.
Sorry for spam! Any comment will be appreciative.