Signed-off-by: Gijs Vermeulen gijsvrm@gmail.com --- dlls/amstream/tests/amstream.c | 326 +++++++++++++++++++++++---------- 1 file changed, 225 insertions(+), 101 deletions(-)
diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 130f9f0e0e..17ff110f11 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -2542,106 +2542,6 @@ static void test_media_types(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
-static void test_IDirectDrawStreamSample(void) -{ - IDirectDrawMediaStream *ddraw_stream = NULL; - IDirectDrawStreamSample *sample = NULL; - IDirectDrawSurface *surface, *surface2; - IMediaStream *stream2, *stream = NULL; - DDSURFACEDESC desc = { sizeof(desc) }; - IAMMultiMediaStream *mmstream; - IDirectDrawSurface7 *surface7; - HRESULT hr; - RECT rect; - - if (!(mmstream = create_ammultimediastream())) - return; - if (!create_directdraw()) - { - IAMMultiMediaStream_Release(mmstream); - return; - } - - hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); - ok(hr == S_OK, "got 0x%08x\n", hr); - - hr = IAMMultiMediaStream_AddMediaStream(mmstream, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL); - ok(hr == S_OK, "got 0x%08x\n", hr); - - hr = IAMMultiMediaStream_GetMediaStream(mmstream, &MSPID_PrimaryVideo, &stream); - ok(hr == S_OK, "got 0x%08x\n", hr); - if (FAILED(hr)) goto error; - - hr = IMediaStream_QueryInterface(stream, &IID_IDirectDrawMediaStream, (LPVOID*)&ddraw_stream); - ok(hr == S_OK, "got 0x%08x\n", hr); - if (FAILED(hr)) goto error; - - hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, &sample); - ok(hr == S_OK, "got 0x%08x\n", hr); - - surface = NULL; - hr = IDirectDrawStreamSample_GetSurface(sample, &surface, &rect); - ok(hr == S_OK, "got 0x%08x\n", hr); - ok(surface != NULL, "got %p\n", surface); - - /* Crashes on native. */ - if (0) - { - hr = IDirectDrawStreamSample_GetMediaStream(sample, NULL); - ok(hr == E_POINTER, "Got hr %#x.\n", hr); - } - - hr = IDirectDrawStreamSample_GetMediaStream(sample, &stream2); - ok(hr == S_OK, "Got hr %#x.\n", hr); - ok(stream2 == stream, "Expected stream %p, got %p.\n", stream, stream2); - IMediaStream_Release(stream2); - - hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7); - ok(hr == S_OK, "got 0x%08x\n", hr); - IDirectDrawSurface7_Release(surface7); - - hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc); - ok(hr == S_OK, "got 0x%08x\n", hr); - ok(desc.dwWidth == 100, "width %d\n", desc.dwWidth); - ok(desc.dwHeight == 100, "height %d\n", desc.dwHeight); - ok(desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "format flags %08x\n", desc.ddpfPixelFormat.dwFlags); - ok(desc.ddpfPixelFormat.dwRGBBitCount, "dwRGBBitCount %d\n", desc.ddpfPixelFormat.dwRGBBitCount); - IDirectDrawSurface_Release(surface); - IDirectDrawStreamSample_Release(sample); - - hr = IDirectDrawSurface7_QueryInterface(pdds7, &IID_IDirectDrawSurface, (void **)&surface); - ok(hr == S_OK, "got 0x%08x\n", hr); - - EXPECT_REF(surface, 1); - hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, surface, NULL, 0, &sample); - ok(hr == S_OK, "got 0x%08x\n", hr); - EXPECT_REF(surface, 2); - - surface2 = NULL; - SetRectEmpty(&rect); - hr = IDirectDrawStreamSample_GetSurface(sample, &surface2, &rect); - ok(hr == S_OK, "got 0x%08x\n", hr); - ok(surface == surface2, "got %p\n", surface2); - ok(rect.right > 0 && rect.bottom > 0, "got %d, %d\n", rect.right, rect.bottom); - EXPECT_REF(surface, 3); - IDirectDrawSurface_Release(surface2); - - hr = IDirectDrawStreamSample_GetSurface(sample, NULL, NULL); - ok(hr == S_OK, "got 0x%08x\n", hr); - - IDirectDrawStreamSample_Release(sample); - IDirectDrawSurface_Release(surface); - -error: - if (ddraw_stream) - IDirectDrawMediaStream_Release(ddraw_stream); - if (stream) - IMediaStream_Release(stream); - - release_directdraw(); - IAMMultiMediaStream_Release(mmstream); -} - static IUnknown *create_audio_data(void) { IUnknown *audio_data = NULL; @@ -5727,6 +5627,227 @@ static void test_audiostreamsample_get_audio_data(void) ok(!ref, "Got outstanding refcount %d.\n", ref); }
+static void test_ddrawstream_create_sample(void) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IDirectDrawMediaStream *ddraw_stream; + IDirectDrawStreamSample *sample; + IDirectDrawSurface *surface; + IMediaStream *stream; + IDirectDraw *ddraw; + DDSURFACEDESC desc; + HRESULT hr; + RECT rect; + ULONG ref; + + hr = DirectDrawCreate(NULL, &ddraw, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, (IUnknown *)ddraw, &MSPID_PrimaryVideo, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaStream_QueryInterface(stream, &IID_IDirectDrawMediaStream, (void **)&ddraw_stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + /* Crashes on native. */ + if (0) + { + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + } + + SetRectEmpty(&rect); + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, &rect, 0, &sample); + todo_wine ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + + EXPECT_REF(stream, 3); + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, &sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + todo_wine EXPECT_REF(stream, 4); + IDirectDrawStreamSample_Release(sample); + EXPECT_REF(stream, 3); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + EXPECT_REF(surface, 1); + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, surface, NULL, 0, &sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + EXPECT_REF(surface, 2); + IDirectDrawStreamSample_Release(sample); + EXPECT_REF(surface, 1); + + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, surface, &rect, 0, &sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + IDirectDrawMediaStream_Release(ddraw_stream); + ref = IDirectDrawStreamSample_Release(sample); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IDirectDrawSurface_Release(surface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IDirectDraw_Release(ddraw); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + +static void test_ddrawstreamsample_get_media_stream(void) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IDirectDrawMediaStream *ddraw_stream; + IDirectDrawStreamSample *sample; + IMediaStream *stream, *stream2; + IDirectDraw *ddraw; + HRESULT hr; + ULONG ref; + + hr = DirectDrawCreate(NULL, &ddraw, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, (IUnknown *)ddraw, &MSPID_PrimaryVideo, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaStream_QueryInterface(stream, &IID_IDirectDrawMediaStream, (void **)&ddraw_stream); + 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); + + /* Crashes on native. */ + if (0) + { + hr = IDirectDrawStreamSample_GetMediaStream(sample, NULL); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + } + + todo_wine EXPECT_REF(stream, 4); + hr = IDirectDrawStreamSample_GetMediaStream(sample, &stream2); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(stream2 == stream, "Expected stream %p, got %p.\n", stream, stream2); + todo_wine EXPECT_REF(stream, 5); + IMediaStream_Release(stream2); + todo_wine EXPECT_REF(stream, 4); + + IDirectDrawMediaStream_Release(ddraw_stream); + ref = IDirectDrawStreamSample_Release(sample); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IDirectDraw_Release(ddraw); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + +static void test_ddrawstreamsample_get_surface(void) +{ + IAMMultiMediaStream *mmstream = create_ammultimediastream(); + IDirectDrawSurface *surface, *surface2; + DDSURFACEDESC desc = { sizeof(desc) }; + IDirectDrawMediaStream *ddraw_stream; + IDirectDrawStreamSample *sample; + IMediaStream *stream; + IDirectDraw *ddraw; + HRESULT hr; + RECT rect; + ULONG ref; + + hr = DirectDrawCreate(NULL, &ddraw, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IDirectDraw_SetCooperativeLevel(ddraw, GetDesktopWindow(), DDSCL_NORMAL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_Initialize(mmstream, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IAMMultiMediaStream_AddMediaStream(mmstream, (IUnknown *)ddraw, &MSPID_PrimaryVideo, 0, &stream); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IMediaStream_QueryInterface(stream, &IID_IDirectDrawMediaStream, (void **)&ddraw_stream); + 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); + + hr = IDirectDrawStreamSample_GetSurface(sample, NULL, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IDirectDrawStreamSample_GetSurface(sample, NULL, &rect); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + hr = IDirectDrawStreamSample_GetSurface(sample, &surface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(surface != NULL, "Expected non-NULL surface.\n"); + IDirectDrawSurface_Release(surface); + + surface = NULL; + hr = IDirectDrawStreamSample_GetSurface(sample, &surface, &rect); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(surface != NULL, "Expected non-NULL surface.\n"); + + hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(desc.dwWidth == 100, "Expected width 100, got %d.\n", desc.dwWidth); + ok(desc.dwHeight == 100, "Expected height 100, got %d.\n", desc.dwHeight); + ok(desc.ddpfPixelFormat.dwFlags == DDPF_RGB, "Expected format flags DDPF_RGB, got %#x.\n", desc.ddpfPixelFormat.dwFlags); + ok(desc.ddpfPixelFormat.dwRGBBitCount, "Expected non-zero RGB bit count.\n"); + IDirectDrawSurface_Release(surface); + IDirectDrawStreamSample_Release(sample); + + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + EXPECT_REF(surface, 1); + hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, surface, NULL, 0, &sample); + ok(hr == S_OK, "Got hr %#x.\n", hr); + EXPECT_REF(surface, 2); + + surface2 = NULL; + SetRectEmpty(&rect); + hr = IDirectDrawStreamSample_GetSurface(sample, &surface2, &rect); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(surface2 == surface, "Expected surface %p, got %p.\n", surface, surface2); + ok(rect.right > 0 && rect.bottom > 0, "Got rect %d, %d.\n", rect.right, rect.bottom); + EXPECT_REF(surface, 3); + IDirectDrawSurface_Release(surface2); + EXPECT_REF(surface, 2); + + IDirectDrawMediaStream_Release(ddraw_stream); + ref = IDirectDrawStreamSample_Release(sample); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IDirectDrawSurface_Release(surface); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IAMMultiMediaStream_Release(mmstream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IMediaStream_Release(stream); + ok(!ref, "Got outstanding refcount %d.\n", ref); + ref = IDirectDraw_Release(ddraw); + ok(!ref, "Got outstanding refcount %d.\n", ref); +} + START_TEST(amstream) { const WCHAR *test_avi_path; @@ -5743,7 +5864,6 @@ START_TEST(amstream) test_set_state(); test_enum_media_types(); test_media_types(); - test_IDirectDrawStreamSample();
test_avi_path = load_resource(L"test.avi");
@@ -5779,6 +5899,10 @@ START_TEST(amstream) test_ddrawstream_initialize(); test_ddrawstream_getsetdirectdraw(); test_ddrawstream_receive_connection(); + test_ddrawstream_create_sample(); + + test_ddrawstreamsample_get_media_stream(); + test_ddrawstreamsample_get_surface();
test_ammediastream_join_am_multi_media_stream(); test_ammediastream_join_filter();
Signed-off-by: Gijs Vermeulen gijsvrm@gmail.com --- dlls/amstream/ddrawstream.c | 3 +++ dlls/amstream/tests/amstream.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c index 4c94bacf52..917fcad9c9 100644 --- a/dlls/amstream/ddrawstream.c +++ b/dlls/amstream/ddrawstream.c @@ -442,6 +442,9 @@ static HRESULT WINAPI ddraw_IDirectDrawMediaStream_CreateSample(IDirectDrawMedia TRACE("stream %p, surface %p, rect %s, flags %#x, sample %p.\n", stream, surface, wine_dbgstr_rect(rect), flags, sample);
+ if (!surface && rect) + return E_INVALIDARG; + EnterCriticalSection(&stream->cs); hr = ddrawstreamsample_create(stream, surface, rect, sample); LeaveCriticalSection(&stream->cs); diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 17ff110f11..4149ff0cd6 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -5664,7 +5664,7 @@ static void test_ddrawstream_create_sample(void)
SetRectEmpty(&rect); hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, &rect, 0, &sample); - todo_wine ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr);
EXPECT_REF(stream, 3); hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, &sample);
Signed-off-by: Gijs Vermeulen gijsvrm@gmail.com --- dlls/amstream/ddrawstream.c | 3 +++ dlls/amstream/tests/amstream.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/dlls/amstream/ddrawstream.c b/dlls/amstream/ddrawstream.c index 917fcad9c9..0d3f2d0d4b 100644 --- a/dlls/amstream/ddrawstream.c +++ b/dlls/amstream/ddrawstream.c @@ -1048,6 +1048,8 @@ static ULONG WINAPI ddraw_sample_Release(IDirectDrawStreamSample *iface) --sample->parent->sample_refs; LeaveCriticalSection(&sample->parent->cs);
+ IAMMediaStream_Release(&sample->parent->IAMMediaStream_iface); + if (sample->surface) IDirectDrawSurface_Release(sample->surface); HeapFree(GetProcessHeap(), 0, sample); @@ -1163,6 +1165,7 @@ static HRESULT ddrawstreamsample_create(struct ddraw_stream *parent, IDirectDraw object->IDirectDrawStreamSample_iface.lpVtbl = &DirectDrawStreamSample_Vtbl; object->ref = 1; object->parent = parent; + IAMMediaStream_AddRef(&parent->IAMMediaStream_iface); ++parent->sample_refs;
if (surface) diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index 4149ff0cd6..e01e3e0cf9 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -5669,7 +5669,7 @@ static void test_ddrawstream_create_sample(void) EXPECT_REF(stream, 3); hr = IDirectDrawMediaStream_CreateSample(ddraw_stream, NULL, NULL, 0, &sample); ok(hr == S_OK, "Got hr %#x.\n", hr); - todo_wine EXPECT_REF(stream, 4); + EXPECT_REF(stream, 4); IDirectDrawStreamSample_Release(sample); EXPECT_REF(stream, 3);
@@ -5738,13 +5738,13 @@ static void test_ddrawstreamsample_get_media_stream(void) ok(hr == E_POINTER, "Got hr %#x.\n", hr); }
- todo_wine EXPECT_REF(stream, 4); + EXPECT_REF(stream, 4); hr = IDirectDrawStreamSample_GetMediaStream(sample, &stream2); ok(hr == S_OK, "Got hr %#x.\n", hr); ok(stream2 == stream, "Expected stream %p, got %p.\n", stream, stream2); - todo_wine EXPECT_REF(stream, 5); + EXPECT_REF(stream, 5); IMediaStream_Release(stream2); - todo_wine EXPECT_REF(stream, 4); + EXPECT_REF(stream, 4);
IDirectDrawMediaStream_Release(ddraw_stream); ref = IDirectDrawStreamSample_Release(sample);