[PATCH 2/5] quartz/filesource: Clean up FileAsyncReader_RequestAllocator().
Zebediah Figura
z.figura12 at gmail.com
Wed Jan 29 19:57:00 CST 2020
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/quartz/filesource.c | 102 +++++++++++++--------------------------
1 file changed, 34 insertions(+), 68 deletions(-)
diff --git a/dlls/quartz/filesource.c b/dlls/quartz/filesource.c
index 7ea67ccc12f..ea0ae8361ed 100644
--- a/dlls/quartz/filesource.c
+++ b/dlls/quartz/filesource.c
@@ -353,7 +353,7 @@ static void async_reader_destroy(struct strmbase_filter *iface)
{
for (i = 0; i < filter->max_requests; ++i)
CloseHandle(filter->requests[i].ovl.hEvent);
- CoTaskMemFree(filter->requests);
+ free(filter->requests);
}
CloseHandle(filter->file);
filter->sample_cs.DebugInfo->Spare[0] = 0;
@@ -702,88 +702,54 @@ static ULONG WINAPI FileAsyncReader_Release(IAsyncReader * iface)
return IPin_Release(&filter->source.pin.IPin_iface);
}
-#define DEF_ALIGNMENT 1
-
-static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader * iface, IMemAllocator * pPreferred, ALLOCATOR_PROPERTIES * pProps, IMemAllocator ** ppActual)
+static HRESULT WINAPI FileAsyncReader_RequestAllocator(IAsyncReader *iface,
+ IMemAllocator *preferred, ALLOCATOR_PROPERTIES *props, IMemAllocator **ret_allocator)
{
- AsyncReader *This = impl_from_IAsyncReader(iface);
- HRESULT hr = S_OK;
-
- TRACE("%p->(%p, %p, %p)\n", This, pPreferred, pProps, ppActual);
+ AsyncReader *filter = impl_from_IAsyncReader(iface);
+ IMemAllocator *allocator;
+ unsigned int i;
+ HRESULT hr;
- if (!pProps->cbAlign || (pProps->cbAlign % DEF_ALIGNMENT) != 0)
- pProps->cbAlign = DEF_ALIGNMENT;
+ TRACE("filter %p, preferred %p, props %p, ret_allocator %p.\n", filter, preferred, props, ret_allocator);
- if (pPreferred)
- {
- hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
- /* FIXME: check we are still aligned */
- if (SUCCEEDED(hr))
- {
- IMemAllocator_AddRef(pPreferred);
- *ppActual = pPreferred;
- TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
- goto done;
- }
- }
+ if (!props->cbAlign)
+ props->cbAlign = 1;
- pPreferred = NULL;
+ *ret_allocator = NULL;
- hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC, &IID_IMemAllocator, (LPVOID *)&pPreferred);
+ if (preferred)
+ IMemAllocator_AddRef(allocator = preferred);
+ else if (FAILED(hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL,
+ CLSCTX_INPROC, &IID_IMemAllocator, (void **)&allocator)))
+ return hr;
- if (SUCCEEDED(hr))
+ if (FAILED(hr = IMemAllocator_SetProperties(allocator, props, props)))
{
- hr = IMemAllocator_SetProperties(pPreferred, pProps, pProps);
- /* FIXME: check we are still aligned */
- if (SUCCEEDED(hr))
- {
- *ppActual = pPreferred;
- TRACE("FileAsyncReader_RequestAllocator -- %x\n", hr);
- }
+ IMemAllocator_Release(allocator);
+ return hr;
}
-done:
- if (SUCCEEDED(hr))
+ if (filter->requests)
{
- if (This->requests)
- {
- unsigned int i;
-
- for (i = 0; i < This->max_requests; ++i)
- CloseHandle(This->requests[i].ovl.hEvent);
- CoTaskMemFree(This->requests);
- }
-
- This->max_requests = pProps->cBuffers;
- TRACE("Maximum request count: %u.\n", This->max_requests);
- This->requests = CoTaskMemAlloc(sizeof(This->requests[0]) * pProps->cBuffers);
-
- if (This->requests)
- {
- int x;
- ZeroMemory(This->requests, sizeof(This->requests[0]) * pProps->cBuffers);
- for (x = 0; x < This->max_requests; ++x)
- This->requests[x].ovl.hEvent = CreateEventW(NULL, 0, 0, NULL);
- This->allocProps = *pProps;
- }
- else
- {
- hr = E_OUTOFMEMORY;
- CoTaskMemFree(This->requests);
- This->max_requests = 0;
- This->requests = NULL;
- }
+ for (i = 0; i < filter->max_requests; ++i)
+ CloseHandle(filter->requests[i].ovl.hEvent);
+ free(filter->requests);
}
- if (FAILED(hr))
+ filter->max_requests = props->cBuffers;
+ TRACE("Maximum request count: %u.\n", filter->max_requests);
+ if (!(filter->requests = calloc(filter->max_requests, sizeof(filter->requests[0]))))
{
- *ppActual = NULL;
- if (pPreferred)
- IMemAllocator_Release(pPreferred);
+ IMemAllocator_Release(allocator);
+ return E_OUTOFMEMORY;
}
- TRACE("-- %x\n", hr);
- return hr;
+ for (i = 0; i < filter->max_requests; ++i)
+ filter->requests[i].ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+ filter->allocProps = *props;
+
+ *ret_allocator = allocator;
+ return S_OK;
}
static HRESULT WINAPI FileAsyncReader_Request(IAsyncReader *iface, IMediaSample *sample, DWORD_PTR cookie)
--
2.25.0
More information about the wine-devel
mailing list