Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/filesource.c | 35 ++++++++++++++++++---------------- dlls/quartz/tests/filesource.c | 2 -- 2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/dlls/quartz/filesource.c b/dlls/quartz/filesource.c index 6b8bfa3353..11b9712c2c 100644 --- a/dlls/quartz/filesource.c +++ b/dlls/quartz/filesource.c @@ -1309,34 +1309,37 @@ static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMed return hr; }
-static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer) +static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader *iface, + LONGLONG offset, LONG length, BYTE *buffer) { OVERLAPPED ovl; - HRESULT hr = S_OK; - FileAsyncReader *This = impl_from_IAsyncReader(iface); + FileAsyncReader *filter = impl_from_IAsyncReader(iface); + DWORD read_len; + HRESULT hr; + BOOL ret;
- TRACE("%p->(%s, %d, %p)\n", This, wine_dbgstr_longlong(llPosition), lLength, pBuffer); + TRACE("filter %p, offset %s, length %d, buffer %p.\n", + filter, wine_dbgstr_longlong(offset), length, buffer);
ZeroMemory(&ovl, sizeof(ovl));
ovl.hEvent = CreateEventW(NULL, 0, 0, NULL); /* NOTE: llPosition is the actual byte position to start reading from */ - ovl.u.s.Offset = (DWORD) llPosition; - ovl.u.s.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8)); - - if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl)) - hr = HRESULT_FROM_WIN32(GetLastError()); - - if (hr == HRESULT_FROM_WIN32(ERROR_IO_PENDING)) - hr = S_OK; + ovl.u.s.Offset = (DWORD)offset; + ovl.u.s.OffsetHigh = (DWORD)(offset >> (sizeof(DWORD) * 8));
- if (SUCCEEDED(hr)) + ret = ReadFile(filter->hFile, buffer, length, NULL, &ovl); + if (ret || GetLastError() == ERROR_IO_PENDING) { - DWORD dwBytesRead; - - if (!GetOverlappedResult(This->hFile, &ovl, &dwBytesRead, TRUE)) + if (GetOverlappedResult(filter->hFile, &ovl, &read_len, TRUE)) + hr = (read_len == length) ? S_OK : S_FALSE; + else hr = HRESULT_FROM_WIN32(GetLastError()); } + else if (GetLastError() == ERROR_HANDLE_EOF) + hr = S_FALSE; + else + hr = HRESULT_FROM_WIN32(GetLastError());
CloseHandle(ovl.hEvent);
diff --git a/dlls/quartz/tests/filesource.c b/dlls/quartz/tests/filesource.c index 7f25596ae3..e13cb05a70 100644 --- a/dlls/quartz/tests/filesource.c +++ b/dlls/quartz/tests/filesource.c @@ -722,7 +722,6 @@ static void test_async_reader(void) ok(buffer[i] == (10 + i) % 111, "Got wrong byte %02x at %u.\n", buffer[i], i);
hr = IAsyncReader_SyncRead(reader, 590, 20, buffer); -todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); for (i = 0; i < 10; i++) ok(buffer[i] == (590 + i) % 111, "Got wrong byte %02x at %u.\n", buffer[i], i); @@ -731,7 +730,6 @@ todo_wine
memset(buffer, 0xcc, sizeof(buffer)); hr = IAsyncReader_SyncRead(reader, 600, 10, buffer); -todo_wine ok(hr == S_FALSE, "Got hr %#x.\n", hr); ok(buffer[0] == 0xcc, "Got wrong byte %02x.\n", buffer[0]);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/tests/memallocator.c | 113 ++++++++++++++++--------------- 1 file changed, 57 insertions(+), 56 deletions(-)
diff --git a/dlls/quartz/tests/memallocator.c b/dlls/quartz/tests/memallocator.c index 1086ed5ec6..ee6a409d01 100644 --- a/dlls/quartz/tests/memallocator.c +++ b/dlls/quartz/tests/memallocator.c @@ -1,5 +1,5 @@ /* - * Unit tests for Direct Show functions + * Memory allocator unit tests * * Copyright (C) 2005 Christian Costa * @@ -19,72 +19,73 @@ */
#define COBJMACROS - -#include "wine/test.h" -#include "uuids.h" #include "dshow.h" -#include "control.h" +#include "wine/test.h"
-static void CommitDecommitTest(void) +static IMemAllocator *create_allocator(void) { - IMemAllocator* pMemAllocator; + IMemAllocator *allocator = NULL; + HRESULT hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, + &IID_IMemAllocator, (void **)&allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + return allocator; +} + +static void test_commit(void) +{ + ALLOCATOR_PROPERTIES req_props = {2, 65536, 1, 0}, ret_props; + IMemAllocator *allocator = create_allocator(); + IMediaSample *sample, *sample2; HRESULT hr; + BYTE *data; + + hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0); + ok(hr == VFW_E_NOT_COMMITTED, "Got hr %#x.\n", hr); + + hr = IMemAllocator_Commit(allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemAllocator_Commit(allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + IMediaSample_Release(sample); + + hr = IMemAllocator_Decommit(allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IMemAllocator_Decommit(allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + /* Extant samples remain valid even after Decommit() is called. */ + hr = IMemAllocator_Commit(allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaSample_GetPointer(sample, &data); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMemAllocator_Decommit(allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + memset(data, 0xcc, 65536); + + hr = IMemAllocator_GetBuffer(allocator, &sample2, NULL, NULL, 0); + ok(hr == VFW_E_NOT_COMMITTED, "Got hr %#x.\n", hr);
- hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (LPVOID*)&pMemAllocator); - ok(hr==S_OK, "Unable to create memory allocator %x\n", hr); - - if (hr == S_OK) - { - ALLOCATOR_PROPERTIES RequestedProps; - ALLOCATOR_PROPERTIES ActualProps; - - IMediaSample *sample = NULL, *sample2 = NULL; - - RequestedProps.cBuffers = 2; - RequestedProps.cbBuffer = 65536; - RequestedProps.cbAlign = 1; - RequestedProps.cbPrefix = 0; - - hr = IMemAllocator_SetProperties(pMemAllocator, &RequestedProps, &ActualProps); - ok(hr==S_OK, "SetProperties returned: %x\n", hr); - - hr = IMemAllocator_Commit(pMemAllocator); - ok(hr==S_OK, "Commit returned: %x\n", hr); - hr = IMemAllocator_Commit(pMemAllocator); - ok(hr==S_OK, "Commit returned: %x\n", hr); - - hr = IMemAllocator_GetBuffer(pMemAllocator, &sample, NULL, NULL, 0); - ok(hr==S_OK, "Could not get a buffer: %x\n", hr); - - hr = IMemAllocator_Decommit(pMemAllocator); - ok(hr==S_OK, "Decommit returned: %x\n", hr); - hr = IMemAllocator_Decommit(pMemAllocator); - ok(hr==S_OK, "Cecommit returned: %x\n", hr); - - /* Decommit and recommit while holding a sample */ - if (sample) - { - hr = IMemAllocator_Commit(pMemAllocator); - ok(hr==S_OK, "Commit returned: %x\n", hr); - - hr = IMemAllocator_GetBuffer(pMemAllocator, &sample2, NULL, NULL, 0); - ok(hr==S_OK, "Could not get a buffer: %x\n", hr); - IMediaSample_Release(sample); - if (sample2) - IMediaSample_Release(sample2); - - hr = IMemAllocator_Decommit(pMemAllocator); - ok(hr==S_OK, "Cecommit returned: %x\n", hr); - } - IMemAllocator_Release(pMemAllocator); - } + IMediaSample_Release(sample); + IMemAllocator_Release(allocator); }
START_TEST(memallocator) { CoInitialize(NULL);
- CommitDecommitTest(); + test_commit();
CoUninitialize(); }
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/tests/memallocator.c | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
diff --git a/dlls/quartz/tests/memallocator.c b/dlls/quartz/tests/memallocator.c index ee6a409d01..53e56985a9 100644 --- a/dlls/quartz/tests/memallocator.c +++ b/dlls/quartz/tests/memallocator.c @@ -31,6 +31,96 @@ static IMemAllocator *create_allocator(void) return allocator; }
+static void test_properties(void) +{ + ALLOCATOR_PROPERTIES req_props = {0}, ret_props; + IMemAllocator *allocator = create_allocator(); + IMediaSample *sample; + LONG size, ret_size; + unsigned int i; + HRESULT hr; + + static const ALLOCATOR_PROPERTIES tests[] = + { + {0, 0, 1, 0}, + {1, 0, 1, 0}, + {1, 1, 1, 0}, + {1, 1, 4, 0}, + {2, 1, 1, 0}, + {1, 2, 4, 0}, + {1, 1, 16, 0}, + {1, 16, 16, 0}, + {1, 17, 16, 0}, + {1, 32, 16, 0}, + {1, 1, 16, 1}, + {1, 15, 16, 1}, + {1, 16, 16, 1}, + {1, 17, 16, 1}, + {1, 0, 16, 16}, + {1, 1, 16, 16}, + {1, 16, 16, 16}, + }; + + memset(&ret_props, 0xcc, sizeof(ret_props)); + hr = IMemAllocator_GetProperties(allocator, &ret_props); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!ret_props.cBuffers, "Got %d buffers.\n", ret_props.cBuffers); + ok(!ret_props.cbBuffer, "Got size %d.\n", ret_props.cbBuffer); + ok(!ret_props.cbAlign, "Got align %d.\n", ret_props.cbAlign); + ok(!ret_props.cbPrefix, "Got prefix %d.\n", ret_props.cbPrefix); + + hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props); + ok(hr == VFW_E_BADALIGN, "Got hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(tests); i++) + { + req_props = tests[i]; + hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props); + ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr); + ok(!memcmp(&req_props, &tests[i], sizeof(req_props)), "Test %u: Requested props should not be changed.\n", i); + ok(ret_props.cBuffers == req_props.cBuffers, "Test %u: Got %d buffers.\n", i, ret_props.cBuffers); + ok(ret_props.cbBuffer >= req_props.cbBuffer, "Test %u: Got size %d.\n", i, ret_props.cbBuffer); + ok(ret_props.cbAlign == req_props.cbAlign, "Test %u: Got alignment %d.\n", i, ret_props.cbAlign); + ok(ret_props.cbPrefix == req_props.cbPrefix, "Test %u: Got prefix %d.\n", i, ret_props.cbPrefix); + ret_size = ret_props.cbBuffer; + + hr = IMemAllocator_GetProperties(allocator, &ret_props); + ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr); + ok(ret_props.cBuffers == req_props.cBuffers, "Test %u: Got %d buffers.\n", i, ret_props.cBuffers); + ok(ret_props.cbBuffer == ret_size, "Test %u: Got size %d.\n", i, ret_props.cbBuffer); + ok(ret_props.cbAlign == req_props.cbAlign, "Test %u: Got alignment %d.\n", i, ret_props.cbAlign); + ok(ret_props.cbPrefix == req_props.cbPrefix, "Test %u: Got prefix %d.\n", i, ret_props.cbPrefix); + + hr = IMemAllocator_Commit(allocator); + if (!req_props.cbBuffer) + { + ok(hr == VFW_E_SIZENOTSET, "Test %u: Got hr %#x.\n", i, hr); + continue; + } + ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr); + + hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props); + ok(hr == VFW_E_ALREADY_COMMITTED, "Test %u: Got hr %#x.\n", i, hr); + + hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0); + ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr); + + size = IMediaSample_GetSize(sample); + ok(size == ret_size, "Test %u: Got size %d.\n", i, size); + + hr = IMemAllocator_Decommit(allocator); + ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr); + + hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props); + ok(hr == VFW_E_BUFFERS_OUTSTANDING, "Test %u: Got hr %#x.\n", i, hr); + + hr = IMediaSample_Release(sample); + ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr); + } + + IMemAllocator_Release(allocator); +} + static void test_commit(void) { ALLOCATOR_PROPERTIES req_props = {2, 65536, 1, 0}, ret_props; @@ -85,6 +175,7 @@ START_TEST(memallocator) { CoInitialize(NULL);
+ test_properties(); test_commit();
CoUninitialize();
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/tests/filesource.c | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
diff --git a/dlls/quartz/tests/filesource.c b/dlls/quartz/tests/filesource.c index e13cb05a70..32b007f69a 100644 --- a/dlls/quartz/tests/filesource.c +++ b/dlls/quartz/tests/filesource.c @@ -666,11 +666,71 @@ todo_wine ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void test_sync_read_aligned(IAsyncReader *reader, IMemAllocator *allocator) +{ + REFERENCE_TIME start_time, end_time; + IMediaSample *sample; + HRESULT hr; + BYTE *data; + LONG len; + int i; + + IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0); + IMediaSample_GetPointer(sample, &data); + + start_time = 0; + end_time = 512 * (LONGLONG)10000000; + hr = IMediaSample_SetTime(sample, &start_time, &end_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAsyncReader_SyncReadAligned(reader, sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + len = IMediaSample_GetActualDataLength(sample); +todo_wine + ok(len == 512, "Got length %d.\n", len); + + for (i = 0; i < 512; i++) + ok(data[i] == i % 111, "Got wrong byte %02x at %u.\n", data[i], i); + + start_time = 512 * (LONGLONG)10000000; + end_time = 1024 * (LONGLONG)10000000; + hr = IMediaSample_SetTime(sample, &start_time, &end_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAsyncReader_SyncReadAligned(reader, sample); + ok(hr == S_FALSE, "Got hr %#x.\n", hr); + + len = IMediaSample_GetActualDataLength(sample); +todo_wine + ok(len == 88, "Got length %d.\n", len); + + for (i = 0; i < 88; i++) + ok(data[i] == (512 + i) % 111, "Got wrong byte %02x at %u.\n", data[i], i); + + start_time = 1024 * (LONGLONG)10000000; + end_time = 1536 * (LONGLONG)10000000; + hr = IMediaSample_SetTime(sample, &start_time, &end_time); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAsyncReader_SyncReadAligned(reader, sample); +todo_wine + ok(hr == S_OK, "Got hr %#x.\n", hr); + + len = IMediaSample_GetActualDataLength(sample); +todo_wine + ok(len == 0, "Got length %d.\n", len); + + IMediaSample_Release(sample); +} + static void test_async_reader(void) { + ALLOCATOR_PROPERTIES req_props = {2, 1024, 512, 0}, ret_props; IBaseFilter *filter = create_file_source(); IFileSourceFilter *filesource; LONGLONG length, available; + IMemAllocator *allocator; WCHAR filename[MAX_PATH]; IAsyncReader *reader; BYTE buffer[20]; @@ -733,6 +793,19 @@ static void test_async_reader(void) ok(hr == S_FALSE, "Got hr %#x.\n", hr); ok(buffer[0] == 0xcc, "Got wrong byte %02x.\n", buffer[0]);
+ ret_props = req_props; + hr = IAsyncReader_RequestAllocator(reader, NULL, &ret_props, &allocator); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ret_props.cBuffers == 2, "Got %d buffers.\n", ret_props.cBuffers); + ok(ret_props.cbBuffer == 1024, "Got size %d.\n", ret_props.cbBuffer); + ok(ret_props.cbAlign == 512, "Got alignment %d.\n", ret_props.cbAlign); + ok(ret_props.cbPrefix == 0, "Got prefix %d.\n", ret_props.cbPrefix); + + IMemAllocator_Commit(allocator); + + test_sync_read_aligned(reader, allocator); + + IMemAllocator_Release(allocator); IAsyncReader_Release(reader); IPin_Release(pin); IFileSourceFilter_Release(filesource);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/quartz/filesource.c | 73 +++++++++++++++++++--------------- dlls/quartz/tests/filesource.c | 1 - 2 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/dlls/quartz/filesource.c b/dlls/quartz/filesource.c index 11b9712c2c..71724af700 100644 --- a/dlls/quartz/filesource.c +++ b/dlls/quartz/filesource.c @@ -1283,36 +1283,60 @@ static HRESULT WINAPI FileAsyncReader_WaitForNext(IAsyncReader * iface, DWORD dw return hr; }
-static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader * iface, LONGLONG llPosition, LONG lLength, BYTE * pBuffer); +static BOOL sync_read(HANDLE file, LONGLONG offset, LONG length, BYTE *buffer, DWORD *read_len) +{ + OVERLAPPED ovl = {0}; + BOOL ret;
-static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader * iface, IMediaSample * pSample) + ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); + ovl.u.s.Offset = (DWORD)offset; + ovl.u.s.OffsetHigh = offset >> 32; + + ret = ReadFile(file, buffer, length, NULL, &ovl); + if (ret || GetLastError() == ERROR_IO_PENDING) + ret = GetOverlappedResult(file, &ovl, read_len, TRUE); + + TRACE("Returning %u bytes.\n", *read_len); + + CloseHandle(ovl.hEvent); + return ret; +} + +static HRESULT WINAPI FileAsyncReader_SyncReadAligned(IAsyncReader *iface, IMediaSample *sample) { - BYTE * pBuffer; - REFERENCE_TIME tStart; - REFERENCE_TIME tStop; + FileAsyncReader *filter = impl_from_IAsyncReader(iface); + REFERENCE_TIME start_time, end_time; + DWORD read_len; + BYTE *buffer; + LONG length; HRESULT hr; + BOOL ret;
- TRACE("(%p)\n", pSample); + TRACE("filter %p, sample %p.\n", filter, sample);
- hr = IMediaSample_GetTime(pSample, &tStart, &tStop); + hr = IMediaSample_GetTime(sample, &start_time, &end_time);
if (SUCCEEDED(hr)) - hr = IMediaSample_GetPointer(pSample, &pBuffer); + hr = IMediaSample_GetPointer(sample, &buffer);
if (SUCCEEDED(hr)) - hr = FileAsyncReader_SyncRead(iface, - BYTES_FROM_MEDIATIME(tStart), - (LONG) BYTES_FROM_MEDIATIME(tStop - tStart), - pBuffer); + { + length = BYTES_FROM_MEDIATIME(end_time - start_time); + ret = sync_read(filter->hFile, BYTES_FROM_MEDIATIME(start_time), length, buffer, &read_len); + if (ret) + hr = (read_len == length) ? S_OK : S_FALSE; + else if (GetLastError() == ERROR_HANDLE_EOF) + hr = S_OK; + else + hr = HRESULT_FROM_WIN32(GetLastError()); + }
- TRACE("-- %x\n", hr); return hr; }
static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader *iface, LONGLONG offset, LONG length, BYTE *buffer) { - OVERLAPPED ovl; FileAsyncReader *filter = impl_from_IAsyncReader(iface); DWORD read_len; HRESULT hr; @@ -1321,29 +1345,14 @@ static HRESULT WINAPI FileAsyncReader_SyncRead(IAsyncReader *iface, TRACE("filter %p, offset %s, length %d, buffer %p.\n", filter, wine_dbgstr_longlong(offset), length, buffer);
- ZeroMemory(&ovl, sizeof(ovl)); - - ovl.hEvent = CreateEventW(NULL, 0, 0, NULL); - /* NOTE: llPosition is the actual byte position to start reading from */ - ovl.u.s.Offset = (DWORD)offset; - ovl.u.s.OffsetHigh = (DWORD)(offset >> (sizeof(DWORD) * 8)); - - ret = ReadFile(filter->hFile, buffer, length, NULL, &ovl); - if (ret || GetLastError() == ERROR_IO_PENDING) - { - if (GetOverlappedResult(filter->hFile, &ovl, &read_len, TRUE)) - hr = (read_len == length) ? S_OK : S_FALSE; - else - hr = HRESULT_FROM_WIN32(GetLastError()); - } + ret = sync_read(filter->hFile, offset, length, buffer, &read_len); + if (ret) + hr = (read_len == length) ? S_OK : S_FALSE; else if (GetLastError() == ERROR_HANDLE_EOF) hr = S_FALSE; else hr = HRESULT_FROM_WIN32(GetLastError());
- CloseHandle(ovl.hEvent); - - TRACE("-- %x\n", hr); return hr; }
diff --git a/dlls/quartz/tests/filesource.c b/dlls/quartz/tests/filesource.c index 32b007f69a..340d1c4e2e 100644 --- a/dlls/quartz/tests/filesource.c +++ b/dlls/quartz/tests/filesource.c @@ -714,7 +714,6 @@ todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IAsyncReader_SyncReadAligned(reader, sample); -todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
len = IMediaSample_GetActualDataLength(sample);