[PATCH 4/4] mfplat: Implement IMFByteStream::{Read,Write,GetCurrentPosition} for bytestream from file.

Jactry Zeng jzeng at codeweavers.com
Wed Jan 30 08:03:52 CST 2019


Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
---
 dlls/mfplat/main.c         | 40 ++++++++++++++++++++++++++++++-----
 dlls/mfplat/tests/mfplat.c | 43 +++++++++++++++++++-------------------
 2 files changed, 57 insertions(+), 26 deletions(-)

diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c
index 80c1b3e3ba..a606592638 100644
--- a/dlls/mfplat/main.c
+++ b/dlls/mfplat/main.c
@@ -858,6 +858,7 @@ typedef struct _mfbytestream
             HANDLE handle;
             LARGE_INTEGER length;
             QWORD position;
+            DWORD mode;
         } file;
     } u;
 } mfbytestream;
@@ -964,7 +965,9 @@ static HRESULT WINAPI mfbytestream_GetCurrentPosition(IMFByteStream *iface, QWOR
 
     FIXME("%p, %p\n", This, position);
 
-    return E_NOTIMPL;
+    *position = This->u.file.position;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI mfbytestream_SetCurrentPosition(IMFByteStream *iface, QWORD position)
@@ -991,10 +994,21 @@ static HRESULT WINAPI mfbytestream_IsEndOfStream(IMFByteStream *iface, BOOL *end
 static HRESULT WINAPI mfbytestream_Read(IMFByteStream *iface, BYTE *data, ULONG count, ULONG *byte_read)
 {
     mfbytestream *This = impl_from_IMFByteStream(iface);
+    DWORD read = 0;
 
-    FIXME("%p, %p, %u, %p\n", This, data, count, byte_read);
+    TRACE("%p, %p, %u, %p\n", This, data, count, byte_read);
 
-    return E_NOTIMPL;
+    if(This->u.file.mode == MF_ACCESSMODE_WRITE)
+        return E_ACCESSDENIED;
+
+    if(!ReadFile(This->u.file.handle, data, count, &read, NULL))
+        return S_FALSE;
+
+    This->u.file.position += read;
+    if(byte_read)
+        *byte_read = read;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI mfbytestream_BeginRead(IMFByteStream *iface, BYTE *data, ULONG count,
@@ -1019,10 +1033,25 @@ static HRESULT WINAPI mfbytestream_EndRead(IMFByteStream *iface, IMFAsyncResult
 static HRESULT WINAPI mfbytestream_Write(IMFByteStream *iface, const BYTE *data, ULONG count, ULONG *written)
 {
     mfbytestream *This = impl_from_IMFByteStream(iface);
+    DWORD written_len = 0;
 
-    FIXME("%p, %p, %u, %p\n", This, data, count, written);
+    TRACE("%p, %p, %u, %p\n", This, data, count, written);
 
-    return E_NOTIMPL;
+    if(This->u.file.mode == MF_ACCESSMODE_READ)
+        return E_ACCESSDENIED;
+
+    if(!WriteFile(This->u.file.handle, data, count, &written_len, NULL))
+        return E_FAIL;
+
+    if(!GetFileSizeEx(This->u.file.handle, &This->u.file.length))
+        return E_FAIL;
+
+    This->u.file.position = SetFilePointer(This->u.file.handle, 0, NULL, FILE_CURRENT);
+
+    if(written)
+        *written = written_len;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI mfbytestream_BeginWrite(IMFByteStream *iface, const BYTE *data, ULONG count,
@@ -1429,6 +1458,7 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open
         return E_FAIL;
     }
     object->u.file.position = 0;
+    object->u.file.mode = accessmode;
 
     *bytestream = &object->IMFByteStream_iface;
 
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c
index 712b4abe2c..1d8473c1bc 100644
--- a/dlls/mfplat/tests/mfplat.c
+++ b/dlls/mfplat/tests/mfplat.c
@@ -630,7 +630,7 @@ static void test_MFCreateFile(void)
                       MF_FILEFLAGS_ALLOW_WRITE_SHARING, filename, &bytestream);
     ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr);
     CHECK_BS_LEN(bytestream, file_size);
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
     IMFByteStream_Release(bytestream);
 
     /* test MF_OPENMODE_RESET_IF_EXIST */
@@ -638,7 +638,7 @@ static void test_MFCreateFile(void)
                       MF_FILEFLAGS_ALLOW_WRITE_SHARING, filename, &bytestream);
     ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr);
     CHECK_BS_LEN(bytestream, 0);
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
     IMFByteStream_Release(bytestream);
     handle = CreateFileW(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
     file_size = GetFileSize(handle, NULL);
@@ -776,17 +776,17 @@ static void test_bytestream_from_file(void)
     hr = MFCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST,
                       MF_FILEFLAGS_NONE, asffile, &bytestream);
     ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr);
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
     CHECK_BS_LEN(bytestream, sizeof(asf_header));
     read = 0;
     hr = IMFByteStream_Read(bytestream, buffer, sizeof(buffer), &read);
-    todo_wine ok(hr == S_OK, "IMFByteStream_Read failed: 0x%08x.\n", hr);
-    todo_wine ok(read == sizeof(asf_header), "got wrong read length: %d\n", read);
-    todo_wine ok(!memcmp(buffer, asf_header, sizeof(asf_header)), "got wrong content.\n");
-    todo_wine CHECK_BS_POS(bytestream, sizeof(asf_header));
+    ok(hr == S_OK, "IMFByteStream_Read failed: 0x%08x.\n", hr);
+    ok(read == sizeof(asf_header), "got wrong read length: %d\n", read);
+    ok(!memcmp(buffer, asf_header, sizeof(asf_header)), "got wrong content.\n");
+    CHECK_BS_POS(bytestream, sizeof(asf_header));
     memset(buffer, 0, sizeof(buffer));
     hr = IMFByteStream_Write(bytestream, asf_header, sizeof(asf_header), &written);
-    todo_wine ok(hr == E_ACCESSDENIED, "IMFByteStream_Write should fail: 0x%08x.\n", hr);
+    ok(hr == E_ACCESSDENIED, "IMFByteStream_Write should fail: 0x%08x.\n", hr);
     hr = IMFByteStream_Flush(bytestream);
     todo_wine ok(hr == E_ACCESSDENIED, "IMFByteStream_Flush should fail: 0x%08x.\n", hr);
     hr = IMFByteStream_SetLength(bytestream, 200);
@@ -797,17 +797,17 @@ static void test_bytestream_from_file(void)
                       MF_FILEFLAGS_NONE, asffile, &bytestream);
     ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr);
     hr = IMFByteStream_Read(bytestream, buffer, sizeof(buffer), &read);
-    todo_wine ok(hr == E_ACCESSDENIED, "IMFByteStream_Read should fail: 0x%08x.\n", hr);
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    ok(hr == E_ACCESSDENIED, "IMFByteStream_Read should fail: 0x%08x.\n", hr);
+    CHECK_BS_POS(bytestream, 0);
     written = 0xdeadbeef;
     hr = IMFByteStream_Write(bytestream, asf_header, sizeof(asf_header), &written);
-    todo_wine ok(hr == S_OK, "IMFByteStream_Write failed: 0x%08x.\n", hr);
-    todo_wine ok(written == sizeof(asf_header), "got wrong written length: %d\n", written);
+    ok(hr == S_OK, "IMFByteStream_Write failed: 0x%08x.\n", hr);
+    ok(written == sizeof(asf_header), "got wrong written length: %d\n", written);
     CHECK_BS_LEN(bytestream, sizeof(asf_header));
-    todo_wine CHECK_BS_POS(bytestream, sizeof(asf_header));
+    CHECK_BS_POS(bytestream, sizeof(asf_header));
     hr = IMFByteStream_Flush(bytestream);
     todo_wine ok(hr == S_OK, "IMFByteStream_Flush failed: 0x%08x.\n", hr);
-    todo_wine CHECK_BS_POS(bytestream, sizeof(asf_header));
+    CHECK_BS_POS(bytestream, sizeof(asf_header));
     CHECK_BS_LEN(bytestream, sizeof(asf_header));
 
     hr = IMFByteStream_SetLength(bytestream, sizeof(asf_header) + 2);
@@ -817,7 +817,7 @@ static void test_bytestream_from_file(void)
     ok(hr == S_OK, "IMFByteStream_GetLength failed: 0x%08x.\n", hr);
     ok(length == sizeof(asf_header) || length == (sizeof(asf_header) + 2) /* xp */,
        "got wrong length: %s.\n", wine_dbgstr_longlong(length));
-    todo_wine CHECK_BS_POS(bytestream, sizeof(asf_header));
+    CHECK_BS_POS(bytestream, sizeof(asf_header));
     IMFByteStream_Release(bytestream);
     file = CreateFileW(asffile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
     ReadFile(file, buffer, sizeof(buffer), &read, NULL);
@@ -829,20 +829,20 @@ static void test_bytestream_from_file(void)
     hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_APPEND_IF_EXIST,
                       MF_FILEFLAGS_NONE, asffile, &bytestream);
     ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr);
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
     CHECK_BS_LEN(bytestream, sizeof(asf_header) + 2);
     written = 0xdeadbeef;
     hr = IMFByteStream_Write(bytestream, test_data, sizeof(test_data), &written);
-    todo_wine ok(hr == S_OK, "IMFByteStream_Write failed: 0x%08x.\n", hr);
-    todo_wine ok(written == sizeof(test_data), "got wrong written length: %d\n", written);
+    ok(hr == S_OK, "IMFByteStream_Write failed: 0x%08x.\n", hr);
+    ok(written == sizeof(test_data), "got wrong written length: %d\n", written);
     CHECK_BS_LEN(bytestream, sizeof(asf_header) + 2);
-    todo_wine CHECK_BS_POS(bytestream, sizeof(test_data));
+    CHECK_BS_POS(bytestream, sizeof(test_data));
     IMFByteStream_Release(bytestream);
 
     hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_RESET_IF_EXIST,
                       MF_FILEFLAGS_NONE, asffile, &bytestream);
     ok(hr == S_OK, "MFCreateFile failed: 0x%08x.\n", hr);
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
     CHECK_BS_LEN(bytestream, 0);
     hr = IMFByteStream_SetLength(bytestream, 2000);
     ok(hr == S_OK, "IMFByteStream_SetLength failed: 0x%08x.\n", hr);
@@ -850,7 +850,8 @@ static void test_bytestream_from_file(void)
     hr = IMFByteStream_GetLength(bytestream, &length);
     ok(hr == S_OK, "IMFByteStream_GetLength failed: 0x%08x.\n", hr);
     ok(length == 0 || length == 2000 /* xp */, "got wrong length: %s.\n", wine_dbgstr_longlong(length));
-    todo_wine CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
+    CHECK_BS_POS(bytestream, 0);
     IMFByteStream_Release(bytestream);
 
     DeleteFileW(asffile);
-- 
2.20.1




More information about the wine-devel mailing list