From 139445eb49c3f3500a1105fa7803b8f35b2bf5a2 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 22 Jun 2015 22:39:41 +0300 Subject: [PATCH] amstream: Implement IDirectDrawStreamSample_GetSurface(). --- dlls/amstream/mediastream.c | 58 +++++++++++++++--- dlls/amstream/tests/amstream.c | 106 ++++++++++++++++++++++++++++++++- 2 files changed, 154 insertions(+), 10 deletions(-) diff --git a/dlls/amstream/mediastream.c b/dlls/amstream/mediastream.c index b457d1f946b..f51d4ddb200 100644 --- a/dlls/amstream/mediastream.c +++ b/dlls/amstream/mediastream.c @@ -31,7 +31,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(amstream); -static HRESULT ddrawstreamsample_create(IDirectDrawMediaStream *parent, IDirectDrawStreamSample **ddraw_stream_sample); +static HRESULT ddrawstreamsample_create(IDirectDrawMediaStream *parent, IDirectDrawSurface *surface, + const RECT *rect, IDirectDrawStreamSample **ddraw_stream_sample); static HRESULT audiostreamsample_create(IAudioMediaStream *parent, IAudioData *audio_data, IAudioStreamSample **audio_stream_sample); typedef struct { @@ -388,12 +389,12 @@ static HRESULT WINAPI DirectDrawMediaStreamImpl_IDirectDrawMediaStream_SetDirect } static HRESULT WINAPI DirectDrawMediaStreamImpl_IDirectDrawMediaStream_CreateSample(IDirectDrawMediaStream *iface, - IDirectDrawSurface *pSurface, const RECT *pRect, DWORD dwFlags, + IDirectDrawSurface *surface, const RECT *rect, DWORD dwFlags, IDirectDrawStreamSample **ppSample) { - TRACE("(%p)->(%p,%p,%x,%p)\n", iface, pSurface, pRect, dwFlags, ppSample); + TRACE("(%p)->(%p,%s,%x,%p)\n", iface, surface, wine_dbgstr_rect(rect), dwFlags, ppSample); - return ddrawstreamsample_create(iface, ppSample); + return ddrawstreamsample_create(iface, surface, rect, ppSample); } static HRESULT WINAPI DirectDrawMediaStreamImpl_IDirectDrawMediaStream_GetTimePerFrame(IDirectDrawMediaStream *iface, @@ -854,6 +855,8 @@ typedef struct { IDirectDrawStreamSample IDirectDrawStreamSample_iface; LONG ref; IMediaStream *parent; + IDirectDrawSurface *surface; + RECT rect; } IDirectDrawStreamSampleImpl; static inline IDirectDrawStreamSampleImpl *impl_from_IDirectDrawStreamSample(IDirectDrawStreamSample *iface) @@ -900,7 +903,11 @@ static ULONG WINAPI IDirectDrawStreamSampleImpl_Release(IDirectDrawStreamSample TRACE("(%p)->(): new ref = %u\n", iface, ref); if (!ref) + { + if (This->surface) + IDirectDrawSurface_Release(This->surface); HeapFree(GetProcessHeap(), 0, This); + } return ref; } @@ -948,9 +955,21 @@ static HRESULT WINAPI IDirectDrawStreamSampleImpl_CompletionStatus(IDirectDrawSt static HRESULT WINAPI IDirectDrawStreamSampleImpl_GetSurface(IDirectDrawStreamSample *iface, IDirectDrawSurface **ddraw_surface, RECT *rect) { - FIXME("(%p)->(%p,%p): stub\n", iface, ddraw_surface, rect); + IDirectDrawStreamSampleImpl *This = impl_from_IDirectDrawStreamSample(iface); - return E_NOTIMPL; + TRACE("(%p)->(%p,%p)\n", iface, ddraw_surface, rect); + + if (ddraw_surface) + { + *ddraw_surface = This->surface; + if (*ddraw_surface) + IDirectDrawSurface_AddRef(*ddraw_surface); + } + + if (rect) + *rect = This->rect; + + return S_OK; } static HRESULT WINAPI IDirectDrawStreamSampleImpl_SetRect(IDirectDrawStreamSample *iface, const RECT *rect) @@ -977,19 +996,42 @@ static const struct IDirectDrawStreamSampleVtbl DirectDrawStreamSample_Vtbl = IDirectDrawStreamSampleImpl_SetRect }; -static HRESULT ddrawstreamsample_create(IDirectDrawMediaStream *parent, IDirectDrawStreamSample **ddraw_stream_sample) +static HRESULT ddrawstreamsample_create(IDirectDrawMediaStream *parent, IDirectDrawSurface *surface, + const RECT *rect, IDirectDrawStreamSample **ddraw_stream_sample) { IDirectDrawStreamSampleImpl *object; + HRESULT hr; TRACE("(%p)\n", ddraw_stream_sample); - object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawStreamSampleImpl)); + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) return E_OUTOFMEMORY; object->IDirectDrawStreamSample_iface.lpVtbl = &DirectDrawStreamSample_Vtbl; object->ref = 1; object->parent = (IMediaStream*)parent; + if (surface) + { + object->surface = surface; + IDirectDrawSurface_AddRef(surface); + } + else + FIXME("create ddraw surface\n"); + + if (rect) + object->rect = *rect; + else if (object->surface) + { + DDSURFACEDESC desc = { sizeof(desc) }; + hr = IDirectDrawSurface_GetSurfaceDesc(object->surface, &desc); + if (hr == S_OK) + { + object->rect.left = object->rect.top = 0; + object->rect.right = desc.dwWidth; + object->rect.bottom = desc.dwHeight; + } + } *ddraw_stream_sample = (IDirectDrawStreamSample*)&object->IDirectDrawStreamSample_iface; diff --git a/dlls/amstream/tests/amstream.c b/dlls/amstream/tests/amstream.c index f2f572357ee..a8986a6bb47 100644 --- a/dlls/amstream/tests/amstream.c +++ b/dlls/amstream/tests/amstream.c @@ -26,6 +26,14 @@ #include "amstream.h" #include "vfwmsgs.h" +#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__) +static void _expect_ref(IUnknown* obj, ULONG ref, int line) +{ + ULONG rc = IUnknown_AddRef(obj); + IUnknown_Release(obj); + ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1); +} + static const WCHAR filenameW[] = {'t','e','s','t','.','a','v','i',0}; static IDirectDraw7* pdd7; @@ -119,6 +127,8 @@ static void test_renderfile(void) IMediaStream *pvidstream = NULL; IDirectDrawMediaStream *pddstream = NULL; IDirectDrawStreamSample *pddsample = NULL; + IDirectDrawSurface *surface; + RECT rect; if (!(pams = create_ammultimediastream())) return; @@ -151,9 +161,23 @@ static void test_renderfile(void) hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample); ok(hr == S_OK, "IDirectDrawMediaStream_CreateSample returned: %x\n", hr); + surface = NULL; + hr = IDirectDrawStreamSample_GetSurface(pddsample, &surface, &rect); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(surface == NULL, "got %p\n", surface); + IDirectDrawStreamSample_Release(pddsample); + + hr = IDirectDrawSurface7_QueryInterface(pdds7, &IID_IDirectDrawSurface, (void**)&surface); + ok(hr == S_OK, "got 0x%08x\n", hr); + + EXPECT_REF(surface, 1); + hr = IDirectDrawMediaStream_CreateSample(pddstream, surface, NULL, 0, &pddsample); + ok(hr == S_OK, "IDirectDrawMediaStream_CreateSample returned: %x\n", hr); + EXPECT_REF(surface, 2); + IDirectDrawStreamSample_Release(pddsample); + IDirectDrawSurface_Release(surface); + error: - if (pddsample) - IDirectDrawStreamSample_Release(pddsample); if (pddstream) IDirectDrawMediaStream_Release(pddstream); if (pvidstream) @@ -426,6 +450,83 @@ static void test_media_streams(void) IAMMultiMediaStream_Release(pams); } +static void test_IDirectDrawStreamSample(void) +{ + IAMMultiMediaStream *pams; + HRESULT hr; + IMediaStream *pvidstream = NULL; + IDirectDrawMediaStream *pddstream = NULL; + IDirectDrawStreamSample *pddsample = NULL; + IDirectDrawSurface *surface, *surface2; + RECT rect; + + if (!(pams = create_ammultimediastream())) + return; + if (!create_directdraw()) + { + IAMMultiMediaStream_Release(pams); + return; + } + + hr = IAMMultiMediaStream_Initialize(pams, STREAMTYPE_READ, 0, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IAMMultiMediaStream_AddMediaStream(pams, (IUnknown*)pdd7, &MSPID_PrimaryVideo, 0, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IAMMultiMediaStream_GetMediaStream(pams, &MSPID_PrimaryVideo, &pvidstream); + ok(hr == S_OK, "got 0x%08x\n", hr); + if (FAILED(hr)) goto error; + + hr = IMediaStream_QueryInterface(pvidstream, &IID_IDirectDrawMediaStream, (LPVOID*)&pddstream); + ok(hr == S_OK, "got 0x%08x\n", hr); + if (FAILED(hr)) goto error; + + hr = IDirectDrawMediaStream_CreateSample(pddstream, NULL, NULL, 0, &pddsample); + ok(hr == S_OK, "got 0x%08x\n", hr); + + surface = NULL; + hr = IDirectDrawStreamSample_GetSurface(pddsample, &surface, &rect); + ok(hr == S_OK, "got 0x%08x\n", hr); +todo_wine + ok(surface != NULL, "got %p\n", surface); +if (surface) + IDirectDrawSurface_Release(surface); + IDirectDrawStreamSample_Release(pddsample); + + hr = IDirectDrawSurface7_QueryInterface(pdds7, &IID_IDirectDrawSurface, (void**)&surface); + ok(hr == S_OK, "got 0x%08x\n", hr); + + EXPECT_REF(surface, 1); + hr = IDirectDrawMediaStream_CreateSample(pddstream, surface, NULL, 0, &pddsample); + ok(hr == S_OK, "got 0x%08x\n", hr); + EXPECT_REF(surface, 2); + + surface2 = NULL; + memset(&rect, 0, sizeof(rect)); + hr = IDirectDrawStreamSample_GetSurface(pddsample, &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(pddsample, NULL, NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + IDirectDrawStreamSample_Release(pddsample); + IDirectDrawSurface_Release(surface); + +error: + if (pddstream) + IDirectDrawMediaStream_Release(pddstream); + if (pvidstream) + IMediaStream_Release(pvidstream); + + release_directdraw(); + IAMMultiMediaStream_Release(pams); +} + START_TEST(amstream) { HANDLE file; @@ -433,6 +534,7 @@ START_TEST(amstream) CoInitializeEx(NULL, COINIT_MULTITHREADED); test_media_streams(); + test_IDirectDrawStreamSample(); file = CreateFileW(filenameW, 0, 0, NULL, OPEN_EXISTING, 0, NULL); if (file != INVALID_HANDLE_VALUE)