From: Santino Mazza smazza@codeweavers.com
--- dlls/amstream/ddrawstream.c | 50 +++++++++++++++++++++++----------- dlls/amstream/tests/amstream.c | 17 +++++++++--- 2 files changed, 47 insertions(+), 20 deletions(-)
diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c index e6ffc0ef69e..f8dd77ec81f 100644 --- a/dlls/amstream/ddrawstream.c +++ b/dlls/amstream/ddrawstream.c @@ -56,6 +56,7 @@ struct ddraw_stream
IPin *peer; IMemAllocator *allocator; + IMemAllocator *private_allocator; AM_MEDIA_TYPE mt; struct format format; FILTER_STATE state; @@ -1306,34 +1307,46 @@ static ULONG WINAPI ddraw_mem_allocator_Release(IMemAllocator *iface)
static HRESULT WINAPI ddraw_mem_allocator_SetProperties(IMemAllocator *iface, ALLOCATOR_PROPERTIES *request, ALLOCATOR_PROPERTIES *actual) { - return E_NOTIMPL; + struct ddraw_stream *stream = impl_from_IMemAllocator(iface); + + return IMemAllocator_SetProperties(stream->private_allocator, request, actual); }
static HRESULT WINAPI ddraw_mem_allocator_GetProperties(IMemAllocator *iface,ALLOCATOR_PROPERTIES *props) { - return E_NOTIMPL; + struct ddraw_stream *stream = impl_from_IMemAllocator(iface); + + return IMemAllocator_GetProperties(stream->private_allocator, props); }
static HRESULT WINAPI ddraw_mem_allocator_Commit(IMemAllocator *iface) { - return E_NOTIMPL; + struct ddraw_stream *stream = impl_from_IMemAllocator(iface); + + return IMemAllocator_Commit(stream->private_allocator); }
static HRESULT WINAPI ddraw_mem_allocator_Decommit(IMemAllocator *iface) { - return E_NOTIMPL; + struct ddraw_stream *stream = impl_from_IMemAllocator(iface); + + return IMemAllocator_Decommit(stream->private_allocator); }
static HRESULT WINAPI ddraw_mem_allocator_GetBuffer(IMemAllocator *iface, IMediaSample **buf, REFERENCE_TIME *start_time, REFERENCE_TIME *end_time, DWORD flags) { - return E_NOTIMPL; + struct ddraw_stream *stream = impl_from_IMemAllocator(iface); + + return IMemAllocator_GetBuffer(stream->private_allocator, buf, start_time, end_time, flags); }
static HRESULT WINAPI ddraw_mem_allocator_ReleaseBuffer(IMemAllocator *iface,IMediaSample *buf) { - return E_NOTIMPL; + struct ddraw_stream *stream = impl_from_IMemAllocator(iface); + + return IMemAllocator_ReleaseBuffer(stream->private_allocator, buf); }
static const IMemAllocatorVtbl ddraw_mem_allocator_vtbl = @@ -1378,14 +1391,8 @@ static HRESULT WINAPI ddraw_meminput_GetAllocator(IMemInputPin *iface, IMemAlloc
TRACE("stream %p, allocator %p.\n", stream, allocator);
- if (stream->allocator) - { - IMemAllocator_AddRef(*allocator = stream->allocator); - return S_OK; - } - - *allocator = NULL; - return VFW_E_NO_ALLOCATOR; + IMemAllocator_AddRef(*allocator = &stream->IMemAllocator_iface); + return S_OK; }
static HRESULT WINAPI ddraw_meminput_NotifyAllocator(IMemInputPin *iface, IMemAllocator *allocator, BOOL readonly) @@ -1397,10 +1404,11 @@ static HRESULT WINAPI ddraw_meminput_NotifyAllocator(IMemInputPin *iface, IMemAl if (!allocator) return E_POINTER;
- if (allocator) - IMemAllocator_AddRef(allocator); + IMemAllocator_AddRef(allocator); + if (stream->allocator) IMemAllocator_Release(stream->allocator); + stream->allocator = allocator;
return S_OK; @@ -1548,6 +1556,7 @@ static const IMemInputPinVtbl ddraw_meminput_vtbl = HRESULT ddraw_stream_create(IUnknown *outer, void **out) { struct ddraw_stream *object; + HRESULT hr;
if (outer) return CLASS_E_NOAGGREGATION; @@ -1558,6 +1567,7 @@ HRESULT ddraw_stream_create(IUnknown *outer, void **out) object->IAMMediaStream_iface.lpVtbl = &ddraw_IAMMediaStream_vtbl; object->IDirectDrawMediaStream_iface.lpVtbl = &ddraw_IDirectDrawMediaStream_Vtbl; object->IMemInputPin_iface.lpVtbl = &ddraw_meminput_vtbl; + object->IMemAllocator_iface.lpVtbl = &ddraw_mem_allocator_vtbl; object->IPin_iface.lpVtbl = &ddraw_sink_vtbl; object->IMemAllocator_iface.lpVtbl = &ddraw_mem_allocator_vtbl; object->ref = 1; @@ -1565,6 +1575,14 @@ HRESULT ddraw_stream_create(IUnknown *outer, void **out) object->format.width = 100; object->format.height = 100;
+ hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, + &IID_IMemAllocator, (void **)&object->private_allocator); + if (!SUCCEEDED(hr)) + { + free(object); + return hr; + }; + InitializeCriticalSection(&object->cs); InitializeConditionVariable(&object->update_queued_cv); list_init(&object->update_queue); diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index f043ed1eb7e..8f8bebf2c32 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -8512,8 +8512,17 @@ static void test_ddrawstream_mem_allocator(void) {
mem_allocator = NULL; hr = IMemInputPin_GetAllocator(mem_input, &mem_allocator); - todo_wine ok(hr == S_OK, "Got hr %#lx.\n", hr); - todo_wine ok (mem_allocator == ddraw_allocator, "Expected GetAllocator to return ddraw allocator.\n"); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + if (mem_allocator) + IMemAllocator_Release(mem_allocator); + + hr = IDirectDrawMediaStream_QueryInterface(ddraw_stream, &IID_IMemAllocator, (void**)&mem_allocator); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + + hr = IMemAllocator_GetProperties(mem_allocator, &props); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + if (mem_allocator) { check_interface(mem_allocator, &IID_IDirectDrawMediaStream, TRUE); @@ -8537,8 +8546,8 @@ static void test_ddrawstream_mem_allocator(void) { mem_allocator = NULL; hr = IMemInputPin_GetAllocator(mem_input, &mem_allocator); ok(hr == S_OK, "Got hr %#lx.\n", hr); - todo_wine ok (mem_allocator == ddraw_allocator, "Expected GetAllocator to return ddraw allocator.\n"); - todo_wine check_interface(mem_allocator, &IID_IDirectDrawMediaStream, TRUE); + ok (mem_allocator == ddraw_allocator, "Expected GetAllocator to return ddraw allocator.\n"); + check_interface(mem_allocator, &IID_IDirectDrawMediaStream, TRUE); IMemAllocator_Release(mem_allocator);
IMemAllocator_Release(new_allocator);