Signed-off-by: Gijs Vermeulen gijsvrm@gmail.com --- dlls/amstream/ddrawstream.c | 35 ++++++++++++++++++---------------- dlls/amstream/tests/amstream.c | 12 ++++++------ 2 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c index ca6a910f3f..f1b6d37d08 100644 --- a/dlls/amstream/ddrawstream.c +++ b/dlls/amstream/ddrawstream.c @@ -39,7 +39,7 @@ struct ddraw_stream IMultiMediaStream* parent; MSPID purpose_id; STREAM_TYPE stream_type; - IDirectDraw7 *ddraw; + IDirectDraw *ddraw; CRITICAL_SECTION cs; IMediaStreamFilter *filter;
@@ -107,17 +107,17 @@ static ULONG WINAPI ddraw_IAMMediaStream_AddRef(IAMMediaStream *iface)
static ULONG WINAPI ddraw_IAMMediaStream_Release(IAMMediaStream *iface) { - struct ddraw_stream *This = impl_from_IAMMediaStream(iface); - ULONG ref = InterlockedDecrement(&This->ref); + struct ddraw_stream *stream = impl_from_IAMMediaStream(iface); + ULONG ref = InterlockedDecrement(&stream->ref);
- TRACE("(%p/%p)->(): new ref = %u\n", iface, This, ref); + TRACE("%p decreasing refcount to %u.\n", stream, ref);
if (!ref) { - DeleteCriticalSection(&This->cs); - if (This->ddraw) - IDirectDraw7_Release(This->ddraw); - HeapFree(GetProcessHeap(), 0, This); + DeleteCriticalSection(&stream->cs); + if (stream->ddraw) + IDirectDraw_Release(stream->ddraw); + HeapFree(GetProcessHeap(), 0, stream); }
return ref; @@ -214,8 +214,8 @@ static HRESULT WINAPI ddraw_IAMMediaStream_Initialize(IAMMediaStream *iface, IUn stream->stream_type = stream_type;
if (source_object - && FAILED(hr = IUnknown_QueryInterface(source_object, &IID_IDirectDraw7, (void **)&stream->ddraw))) - FIXME("Stream object doesn't implement IDirectDraw7 interface, hr %#x.\n", hr); + && FAILED(hr = IUnknown_QueryInterface(source_object, &IID_IDirectDraw, (void **)&stream->ddraw))) + FIXME("Stream object doesn't implement IDirectDraw interface, hr %#x.\n", hr);
return S_OK; } @@ -373,23 +373,26 @@ static HRESULT WINAPI ddraw_IDirectDrawMediaStream_SetFormat(IDirectDrawMediaStr static HRESULT WINAPI ddraw_IDirectDrawMediaStream_GetDirectDraw(IDirectDrawMediaStream *iface, IDirectDraw **ddraw) { - struct ddraw_stream *This = impl_from_IDirectDrawMediaStream(iface); + struct ddraw_stream *stream = impl_from_IDirectDrawMediaStream(iface);
- TRACE("(%p)->(%p)\n", iface, ddraw); + TRACE("stream %p, ddraw %p.\n", stream, ddraw);
if (!ddraw) return E_POINTER;
*ddraw = NULL; - if (!This->ddraw) + if (!stream->ddraw) { - HRESULT hr = DirectDrawCreateEx(NULL, (void**)&This->ddraw, &IID_IDirectDraw7, NULL); + HRESULT hr = DirectDrawCreate(NULL, &stream->ddraw, NULL); if (FAILED(hr)) return hr; - IDirectDraw7_SetCooperativeLevel(This->ddraw, NULL, DDSCL_NORMAL); + IDirectDraw_SetCooperativeLevel(stream->ddraw, NULL, DDSCL_NORMAL); }
- return IDirectDraw7_QueryInterface(This->ddraw, &IID_IDirectDraw, (void**)ddraw); + IDirectDraw_AddRef(stream->ddraw); + *ddraw = stream->ddraw; + + return S_OK; }
static HRESULT WINAPI ddraw_IDirectDrawMediaStream_SetDirectDraw(IDirectDrawMediaStream *iface, diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 03c8660a42..5aedfa4680 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -4776,7 +4776,7 @@ static void test_ddrawstream_getsetdirectdraw(void)
hr = IAMMultiMediaStream_AddMediaStream(mmstream, (IUnknown *)ddraw7, &MSPID_PrimaryVideo, 0, &stream); ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine EXPECT_REF(ddraw, 2); + EXPECT_REF(ddraw, 2);
hr = IMediaStream_QueryInterface(stream, &IID_IDirectDrawMediaStream, (void **)&ddraw_stream); ok(hr == S_OK, "Got hr %#x.\n", hr); @@ -4787,19 +4787,19 @@ static void test_ddrawstream_getsetdirectdraw(void) hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw2); ok(hr == S_OK, "Got hr %#x.\n", hr); ok(ddraw2 == ddraw, "Expected ddraw %p, got %p.\n", ddraw, ddraw2); - todo_wine EXPECT_REF(ddraw, 3); + EXPECT_REF(ddraw, 3);
hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw3); ok(hr == S_OK, "Got hr %#x.\n", hr); ok(ddraw3 == ddraw2, "Expected ddraw %p, got %p.\n", ddraw2, ddraw3); - todo_wine EXPECT_REF(ddraw, 4); + EXPECT_REF(ddraw, 4); IDirectDraw_Release(ddraw3); - todo_wine EXPECT_REF(ddraw, 3); + EXPECT_REF(ddraw, 3);
/* The current ddraw is released when SetDirectDraw() is called. */ hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, NULL); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - EXPECT_REF(ddraw, 2); + todo_wine EXPECT_REF(ddraw, 2);
hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw3); ok(hr == S_OK, "Got hr %#x.\n", hr); @@ -4808,7 +4808,7 @@ static void test_ddrawstream_getsetdirectdraw(void)
hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw2); todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine EXPECT_REF(ddraw, 3); + EXPECT_REF(ddraw, 3);
if (hr == S_OK) {
Signed-off-by: Gijs Vermeulen gijsvrm@gmail.com --- dlls/amstream/ddrawstream.c | 35 +++++++++++-- dlls/amstream/tests/amstream.c | 95 ++++++++++++++++------------------ 2 files changed, 78 insertions(+), 52 deletions(-)
diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c index f1b6d37d08..229b5ced05 100644 --- a/dlls/amstream/ddrawstream.c +++ b/dlls/amstream/ddrawstream.c @@ -35,6 +35,7 @@ struct ddraw_stream IMemInputPin IMemInputPin_iface; IPin IPin_iface; LONG ref; + LONG sample_refs;
IMultiMediaStream* parent; MSPID purpose_id; @@ -396,11 +397,35 @@ static HRESULT WINAPI ddraw_IDirectDrawMediaStream_GetDirectDraw(IDirectDrawMedi }
static HRESULT WINAPI ddraw_IDirectDrawMediaStream_SetDirectDraw(IDirectDrawMediaStream *iface, - IDirectDraw *pDirectDraw) + IDirectDraw *ddraw) { - FIXME("(%p)->(%p) stub!\n", iface, pDirectDraw); + struct ddraw_stream *stream = impl_from_IDirectDrawMediaStream(iface);
- return E_NOTIMPL; + TRACE("stream %p, ddraw %p.\n", stream, ddraw); + + EnterCriticalSection(&stream->cs); + + if (stream->sample_refs) + { + HRESULT hr = (stream->ddraw == ddraw) ? S_OK : MS_E_SAMPLEALLOC; + LeaveCriticalSection(&stream->cs); + return hr; + } + + if (stream->ddraw) + IDirectDraw_Release(stream->ddraw); + + if (ddraw) + { + IDirectDraw_AddRef(ddraw); + stream->ddraw = ddraw; + } + else + stream->ddraw = NULL; + + LeaveCriticalSection(&stream->cs); + + return S_OK; }
static HRESULT WINAPI ddraw_IDirectDrawMediaStream_CreateSample(IDirectDrawMediaStream *iface, @@ -951,6 +976,7 @@ HRESULT ddraw_stream_create(IUnknown *outer, void **out) object->IMemInputPin_iface.lpVtbl = &ddraw_meminput_vtbl; object->IPin_iface.lpVtbl = &ddraw_sink_vtbl; object->ref = 1; + object->sample_refs = 0;
InitializeCriticalSection(&object->cs);
@@ -1013,6 +1039,8 @@ static ULONG WINAPI ddraw_sample_Release(IDirectDrawStreamSample *iface)
TRACE("(%p)->(): new ref = %u\n", iface, ref);
+ InterlockedDecrement(&sample->parent->sample_refs); + if (!ref) { if (sample->surface) @@ -1130,6 +1158,7 @@ static HRESULT ddrawstreamsample_create(struct ddraw_stream *parent, IDirectDraw object->IDirectDrawStreamSample_iface.lpVtbl = &DirectDrawStreamSample_Vtbl; object->ref = 1; object->parent = parent; + InterlockedIncrement(&parent->sample_refs);
if (surface) { diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 5aedfa4680..3578ecc6cd 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -4798,8 +4798,8 @@ static void test_ddrawstream_getsetdirectdraw(void)
/* The current ddraw is released when SetDirectDraw() is called. */ hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, NULL); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine EXPECT_REF(ddraw, 2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + EXPECT_REF(ddraw, 2);
hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw3); ok(hr == S_OK, "Got hr %#x.\n", hr); @@ -4807,65 +4807,62 @@ static void test_ddrawstream_getsetdirectdraw(void) if (ddraw3) IDirectDraw_Release(ddraw3);
hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw2); - todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(hr == S_OK, "Got hr %#x.\n", hr); EXPECT_REF(ddraw, 3);
- if (hr == S_OK) - { - hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw3); - ok(hr == S_OK, "Got hr %#x.\n", hr); - ok(ddraw3 == ddraw2, "Expected ddraw %p, got %p.\n", ddraw2, ddraw3); - EXPECT_REF(ddraw, 4); - IDirectDraw_Release(ddraw3); - EXPECT_REF(ddraw, 3); + hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw3); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ddraw3 == ddraw2, "Expected ddraw %p, got %p.\n", ddraw2, ddraw3); + EXPECT_REF(ddraw, 4); + IDirectDraw_Release(ddraw3); + EXPECT_REF(ddraw, 3);
- hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, &sample); - ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, &sample); + ok(hr == S_OK, "Got hr %#x.\n", hr);
- /* SetDirectDraw() doesn't take an extra reference to the ddraw object - * if there are samples extant. */ - hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw2); - ok(hr == S_OK, "Got hr %#x.\n", hr); - EXPECT_REF(ddraw, 3); + /* SetDirectDraw() doesn't take an extra reference to the ddraw object + * if there are samples extant. */ + hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + EXPECT_REF(ddraw, 3);
- hr = DirectDrawCreate(NULL, &ddraw3, NULL); - ok(hr == S_OK, "Got hr %#x.\n", hr); - hr = IDirectDraw_SetCooperativeLevel(ddraw3, GetDesktopWindow(), DDSCL_NORMAL); - ok(hr == DD_OK, "Got hr %#x.\n", hr); - EXPECT_REF(ddraw3, 1); + hr = DirectDrawCreate(NULL, &ddraw3, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + hr = IDirectDraw_SetCooperativeLevel(ddraw3, GetDesktopWindow(), DDSCL_NORMAL); + ok(hr == DD_OK, "Got hr %#x.\n", hr); + EXPECT_REF(ddraw3, 1);
- hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw3); - ok(hr == MS_E_SAMPLEALLOC, "Got hr %#x.\n", hr); + hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw3); + ok(hr == MS_E_SAMPLEALLOC, "Got hr %#x.\n", hr);
- hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw4); - ok(hr == S_OK, "Got hr %#x.\n", hr); - ok(ddraw4 == ddraw2, "Expected ddraw %p, got %p.\n", ddraw2, ddraw4); - EXPECT_REF(ddraw, 4); - IDirectDraw_Release(ddraw4); - EXPECT_REF(ddraw, 3); + hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw4); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ddraw4 == ddraw2, "Expected ddraw %p, got %p.\n", ddraw2, ddraw4); + EXPECT_REF(ddraw, 4); + IDirectDraw_Release(ddraw4); + EXPECT_REF(ddraw, 3);
- ref = IDirectDrawStreamSample_Release(sample); - ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IDirectDrawStreamSample_Release(sample); + ok(!ref, "Got outstanding refcount %d.\n", ref);
- hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw3); - ok(hr == S_OK, "Got hr %#x.\n", hr); - EXPECT_REF(ddraw, 2); - EXPECT_REF(ddraw3, 2); + hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw3); + ok(hr == S_OK, "Got hr %#x.\n", hr); + EXPECT_REF(ddraw, 2); + EXPECT_REF(ddraw3, 2);
- hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw4); - ok(hr == S_OK, "Got hr %#x.\n", hr); - ok(ddraw4 == ddraw3, "Expected ddraw %p, got %p.\n", ddraw3, ddraw4); - EXPECT_REF(ddraw3, 3); - IDirectDraw_Release(ddraw4); - EXPECT_REF(ddraw3, 2); + hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw4); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(ddraw4 == ddraw3, "Expected ddraw %p, got %p.\n", ddraw3, ddraw4); + EXPECT_REF(ddraw3, 3); + IDirectDraw_Release(ddraw4); + EXPECT_REF(ddraw3, 2);
- hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, NULL); - ok(hr == S_OK, "Got hr %#x.\n", hr); - EXPECT_REF(ddraw3, 1); + hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + EXPECT_REF(ddraw3, 1);
- ref = IDirectDraw_Release(ddraw3); - ok(!ref, "Got outstanding refcount %d.\n", ref); - } + ref = IDirectDraw_Release(ddraw3); + ok(!ref, "Got outstanding refcount %d.\n", ref);
EXPECT_REF(stream, 3); IDirectDrawMediaStream_Release(ddraw_stream);
This doesn't look safe regarding sample_refs update. It's tested for != 0 within critical section, but is updated separately.
Signed-off-by: Gijs Vermeulen gijsvrm@gmail.com --- dlls/amstream/ddrawstream.c | 14 +++++++++----- dlls/amstream/tests/amstream.c | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c index 229b5ced05..14ae73c094 100644 --- a/dlls/amstream/ddrawstream.c +++ b/dlls/amstream/ddrawstream.c @@ -218,6 +218,13 @@ static HRESULT WINAPI ddraw_IAMMediaStream_Initialize(IAMMediaStream *iface, IUn && FAILED(hr = IUnknown_QueryInterface(source_object, &IID_IDirectDraw, (void **)&stream->ddraw))) FIXME("Stream object doesn't implement IDirectDraw interface, hr %#x.\n", hr);
+ if (!source_object) + { + if (FAILED(hr = DirectDrawCreate(NULL, &stream->ddraw, NULL))) + return hr; + IDirectDraw_SetCooperativeLevel(stream->ddraw, NULL, DDSCL_NORMAL); + } + return S_OK; }
@@ -381,13 +388,10 @@ static HRESULT WINAPI ddraw_IDirectDrawMediaStream_GetDirectDraw(IDirectDrawMedi if (!ddraw) return E_POINTER;
- *ddraw = NULL; if (!stream->ddraw) { - HRESULT hr = DirectDrawCreate(NULL, &stream->ddraw, NULL); - if (FAILED(hr)) - return hr; - IDirectDraw_SetCooperativeLevel(stream->ddraw, NULL, DDSCL_NORMAL); + *ddraw = NULL; + return S_OK; }
IDirectDraw_AddRef(stream->ddraw); diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 3578ecc6cd..363c92fcca 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -4803,8 +4803,7 @@ static void test_ddrawstream_getsetdirectdraw(void)
hr = IDirectDrawMediaStream_GetDirectDraw(ddraw_stream, &ddraw3); ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine ok(ddraw3 == NULL, "Expected NULL, got %p.\n", ddraw3); - if (ddraw3) IDirectDraw_Release(ddraw3); + ok(ddraw3 == NULL, "Expected NULL, got %p.\n", ddraw3);
hr = IDirectDrawMediaStream_SetDirectDraw(ddraw_stream, ddraw2); ok(hr == S_OK, "Got hr %#x.\n", hr);