Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/evr/Makefile.in | 3 +- dlls/evr/evr.spec | 2 +- dlls/evr/sample.c | 199 +++++++++++++++++++++++++++++++++++++++++++ dlls/evr/tests/evr.c | 19 +++++ include/evr.idl | 1 + include/mfidl.idl | 57 +++++++++++++ 6 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 dlls/evr/sample.c
diff --git a/dlls/evr/Makefile.in b/dlls/evr/Makefile.in index daaf9cc872a..c8178297dab 100644 --- a/dlls/evr/Makefile.in +++ b/dlls/evr/Makefile.in @@ -9,6 +9,7 @@ C_SRCS = \ evr.c \ main.c \ mixer.c \ - presenter.c + presenter.c \ + sample.c
IDL_SRCS = evr_classes.idl diff --git a/dlls/evr/evr.spec b/dlls/evr/evr.spec index 73cbf05b461..aa839295658 100644 --- a/dlls/evr/evr.spec +++ b/dlls/evr/evr.spec @@ -18,7 +18,7 @@ @ stub MFCreateVideoOTA @ stub MFCreateVideoPresenter2 @ stdcall MFCreateVideoPresenter(ptr ptr ptr ptr) -@ stub MFCreateVideoSampleAllocator +@ stdcall MFCreateVideoSampleAllocator(ptr ptr) @ stdcall MFCreateVideoSampleFromSurface(ptr ptr) @ stub MFGetPlaneSize @ stub MFGetStrideForBitmapInfoHeader diff --git a/dlls/evr/sample.c b/dlls/evr/sample.c new file mode 100644 index 00000000000..f371d920762 --- /dev/null +++ b/dlls/evr/sample.c @@ -0,0 +1,199 @@ +/* + * Copyright 2020 Nikolay Sivov + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define COBJMACROS + +#include "evr.h" + +#include "wine/debug.h" +#include "wine/heap.h" + +WINE_DEFAULT_DEBUG_CHANNEL(evr); + +struct sample_allocator +{ + IMFVideoSampleAllocator IMFVideoSampleAllocator_iface; + IMFVideoSampleAllocatorCallback IMFVideoSampleAllocatorCallback_iface; + LONG refcount; +}; + +static struct sample_allocator *impl_from_IMFVideoSampleAllocator(IMFVideoSampleAllocator *iface) +{ + return CONTAINING_RECORD(iface, struct sample_allocator, IMFVideoSampleAllocator_iface); +} + +static struct sample_allocator *impl_from_IMFVideoSampleAllocatorCallback(IMFVideoSampleAllocatorCallback *iface) +{ + return CONTAINING_RECORD(iface, struct sample_allocator, IMFVideoSampleAllocatorCallback_iface); +} + +static HRESULT WINAPI sample_allocator_QueryInterface(IMFVideoSampleAllocator *iface, REFIID riid, void **obj) +{ + struct sample_allocator *allocator = impl_from_IMFVideoSampleAllocator(iface); + + TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj); + + if (IsEqualIID(riid, &IID_IMFVideoSampleAllocator) || + IsEqualIID(riid, &IID_IUnknown)) + { + *obj = &allocator->IMFVideoSampleAllocator_iface; + } + else if (IsEqualIID(riid, &IID_IMFVideoSampleAllocatorCallback)) + { + *obj = &allocator->IMFVideoSampleAllocatorCallback_iface; + } + else + { + WARN("Unsupported interface %s.\n", debugstr_guid(riid)); + *obj = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown *)*obj); + return S_OK; +} + +static ULONG WINAPI sample_allocator_AddRef(IMFVideoSampleAllocator *iface) +{ + struct sample_allocator *allocator = impl_from_IMFVideoSampleAllocator(iface); + ULONG refcount = InterlockedIncrement(&allocator->refcount); + + TRACE("%p, refcount %u.\n", iface, refcount); + + return refcount; +} + +static ULONG WINAPI sample_allocator_Release(IMFVideoSampleAllocator *iface) +{ + struct sample_allocator *allocator = impl_from_IMFVideoSampleAllocator(iface); + ULONG refcount = InterlockedDecrement(&allocator->refcount); + + TRACE("%p, refcount %u.\n", iface, refcount); + + if (!refcount) + { + heap_free(allocator); + } + + return refcount; +} + +static HRESULT WINAPI sample_allocator_SetDirectXManager(IMFVideoSampleAllocator *iface, + IUnknown *manager) +{ + FIXME("%p, %p.\n", iface, manager); + + return E_NOTIMPL; +} + +static HRESULT WINAPI sample_allocator_UninitializeSampleAllocator(IMFVideoSampleAllocator *iface) +{ + FIXME("%p.\n", iface); + + return E_NOTIMPL; +} + +static HRESULT WINAPI sample_allocator_InitializeSampleAllocator(IMFVideoSampleAllocator *iface, + DWORD sample_count, IMFMediaType *media_type) +{ + FIXME("%p, %u, %p.\n", iface, sample_count, media_type); + + return E_NOTIMPL; +} + +static HRESULT WINAPI sample_allocator_AllocateSample(IMFVideoSampleAllocator *iface, IMFSample **sample) +{ + FIXME("%p, %p.\n", iface, sample); + + return E_NOTIMPL; +} + +static const IMFVideoSampleAllocatorVtbl sample_allocator_vtbl = +{ + sample_allocator_QueryInterface, + sample_allocator_AddRef, + sample_allocator_Release, + sample_allocator_SetDirectXManager, + sample_allocator_UninitializeSampleAllocator, + sample_allocator_InitializeSampleAllocator, + sample_allocator_AllocateSample, +}; + +static HRESULT WINAPI sample_allocator_callback_QueryInterface(IMFVideoSampleAllocatorCallback *iface, + REFIID riid, void **obj) +{ + struct sample_allocator *allocator = impl_from_IMFVideoSampleAllocatorCallback(iface); + return IMFVideoSampleAllocator_QueryInterface(&allocator->IMFVideoSampleAllocator_iface, riid, obj); +} + +static ULONG WINAPI sample_allocator_callback_AddRef(IMFVideoSampleAllocatorCallback *iface) +{ + struct sample_allocator *allocator = impl_from_IMFVideoSampleAllocatorCallback(iface); + return IMFVideoSampleAllocator_AddRef(&allocator->IMFVideoSampleAllocator_iface); +} + +static ULONG WINAPI sample_allocator_callback_Release(IMFVideoSampleAllocatorCallback *iface) +{ + struct sample_allocator *allocator = impl_from_IMFVideoSampleAllocatorCallback(iface); + return IMFVideoSampleAllocator_Release(&allocator->IMFVideoSampleAllocator_iface); +} + +static HRESULT WINAPI sample_allocator_callback_SetCallback(IMFVideoSampleAllocatorCallback *iface, + IMFVideoSampleAllocatorNotify *callback) +{ + FIXME("%p, %p.\n", iface, callback); + + return E_NOTIMPL; +} + +static HRESULT WINAPI sample_allocator_callback_GetFreeSampleCount(IMFVideoSampleAllocatorCallback *iface, + LONG *count) +{ + FIXME("%p, %p.\n", iface, count); + + return E_NOTIMPL; +} + +static const IMFVideoSampleAllocatorCallbackVtbl sample_allocator_callback_vtbl = +{ + sample_allocator_callback_QueryInterface, + sample_allocator_callback_AddRef, + sample_allocator_callback_Release, + sample_allocator_callback_SetCallback, + sample_allocator_callback_GetFreeSampleCount, +}; + +HRESULT WINAPI MFCreateVideoSampleAllocator(REFIID riid, void **obj) +{ + struct sample_allocator *object; + HRESULT hr; + + TRACE("%s, %p.\n", debugstr_guid(riid), obj); + + if (!(object = heap_alloc_zero(sizeof(*object)))) + return E_OUTOFMEMORY; + + object->IMFVideoSampleAllocator_iface.lpVtbl = &sample_allocator_vtbl; + object->IMFVideoSampleAllocatorCallback_iface.lpVtbl = &sample_allocator_callback_vtbl; + object->refcount = 1; + + hr = IMFVideoSampleAllocator_QueryInterface(&object->IMFVideoSampleAllocator_iface, riid, obj); + IMFVideoSampleAllocator_Release(&object->IMFVideoSampleAllocator_iface); + + return hr; +} diff --git a/dlls/evr/tests/evr.c b/dlls/evr/tests/evr.c index b9f86eb2529..5773fedd226 100644 --- a/dlls/evr/tests/evr.c +++ b/dlls/evr/tests/evr.c @@ -962,6 +962,24 @@ static void test_MFCreateVideoMixerAndPresenter(void) IUnknown_Release(presenter); }
+static void test_MFCreateVideoSampleAllocator(void) +{ + IUnknown *unk; + HRESULT hr; + + hr = MFCreateVideoSampleAllocator(&IID_IUnknown, (void **)&unk); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IUnknown_Release(unk); + + hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator, (void **)&unk); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IUnknown_Release(unk); + + hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocatorCallback, (void **)&unk); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IUnknown_Release(unk); +} + START_TEST(evr) { CoInitialize(NULL); @@ -978,6 +996,7 @@ START_TEST(evr) test_surface_sample(); test_default_presenter(); test_MFCreateVideoMixerAndPresenter(); + test_MFCreateVideoSampleAllocator();
CoUninitialize(); } diff --git a/include/evr.idl b/include/evr.idl index 8628e111a31..6369a39b2f3 100644 --- a/include/evr.idl +++ b/include/evr.idl @@ -303,4 +303,5 @@ cpp_quote("HRESULT WINAPI MFCreateVideoMixer(IUnknown *owner, REFIID riid_device cpp_quote("HRESULT WINAPI MFCreateVideoMixerAndPresenter(IUnknown *mixer_outer, IUnknown *presenter_outer, ") cpp_quote(" REFIID riid_mixer, void **mixer, REFIID riid_presenter, void **presenter);") cpp_quote("HRESULT WINAPI MFCreateVideoPresenter(IUnknown *owner, REFIID riid_device, REFIID riid, void **obj);") +cpp_quote("HRESULT WINAPI MFCreateVideoSampleAllocator(REFIID riid, void **allocator);") cpp_quote("HRESULT WINAPI MFCreateVideoSampleFromSurface(IUnknown *surface, IMFSample **sample);") diff --git a/include/mfidl.idl b/include/mfidl.idl index 35419756b5c..1f5fc06dd1e 100644 --- a/include/mfidl.idl +++ b/include/mfidl.idl @@ -1040,6 +1040,63 @@ interface IMFAudioPolicy : IUnknown HRESULT GetIconPath([out] LPWSTR *path); }
+[ + object, + uuid(86cbc910-e533-4751-8e3b-f19b5b806a03), + local +] +interface IMFVideoSampleAllocator : IUnknown +{ + HRESULT SetDirectXManager( + [in, unique] IUnknown *manager + ); + HRESULT UninitializeSampleAllocator(); + HRESULT InitializeSampleAllocator( + [in] DWORD sample_count, + [in] IMFMediaType *media_type + ); + + HRESULT AllocateSample( + [out] IMFSample **sample + ); +} + +[ + object, + uuid(a792cdbe-c374-4e89-8335-278e7b9956a4), + local +] +interface IMFVideoSampleAllocatorNotify : IUnknown +{ + HRESULT NotifyRelease(); +} + +[ + object, + uuid(3978aa1a-6d5b-4b7f-a340-90899189ae34), + local +] +interface IMFVideoSampleAllocatorNotifyEx : IMFVideoSampleAllocatorNotify +{ + HRESULT NotifyPrune(IMFSample *sample); +} + +[ + object, + uuid(992388b4-3372-4f67-8b6f-c84c071f4751), + local +] +interface IMFVideoSampleAllocatorCallback : IUnknown +{ + HRESULT SetCallback( + [in, unique] IMFVideoSampleAllocatorNotify *callback + ); + + HRESULT GetFreeSampleCount( + [out] LONG *count + ); +} + enum { MF_ACTIVATE_CUSTOM_MIXER_ALLOWFAIL = 0x00000001,
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/evr/tests/evr.c | 127 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 123 insertions(+), 4 deletions(-)
diff --git a/dlls/evr/tests/evr.c b/dlls/evr/tests/evr.c index 5773fedd226..db9b3a80e04 100644 --- a/dlls/evr/tests/evr.c +++ b/dlls/evr/tests/evr.c @@ -623,6 +623,7 @@ todo_wine static void test_surface_sample(void) { IDirect3DSurface9 *backbuffer = NULL; + IMFDesiredSample *desired_sample; IMFMediaBuffer *buffer, *buffer2; IDirect3DSwapChain9 *swapchain; IDirect3DDevice9 *device; @@ -662,9 +663,20 @@ todo_wine ok(hr == S_OK, "Unexpected hr %#x.\n", hr); IUnknown_Release(unk);
- hr = IMFSample_QueryInterface(sample, &IID_IMFDesiredSample, (void **)&unk); + hr = IMFSample_QueryInterface(sample, &IID_IMFDesiredSample, (void **)&desired_sample); ok(hr == S_OK, "Unexpected hr %#x.\n", hr); - IUnknown_Release(unk); + + hr = IMFSample_GetCount(sample, &count); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!count, "Unexpected attribute count %u.\n", count); + + IMFDesiredSample_SetDesiredSampleTimeAndDuration(desired_sample, 123, 456); + + hr = IMFSample_GetCount(sample, &count); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!count, "Unexpected attribute count %u.\n", count); + + IMFDesiredSample_Release(desired_sample);
hr = IMFSample_GetCount(sample, &count); ok(hr == S_OK, "Failed to get attribute count, hr %#x.\n", hr); @@ -964,16 +976,123 @@ static void test_MFCreateVideoMixerAndPresenter(void)
static void test_MFCreateVideoSampleAllocator(void) { + IMFVideoSampleAllocatorCallback *allocator_cb; + IMFVideoSampleAllocator *allocator; + IMFVideoMediaType *video_type; + IMFSample *sample, *sample2; + IDirect3DSurface9 *surface; + IMFMediaType *media_type; + IMFMediaBuffer *buffer; + IMFGetService *gs; IUnknown *unk; HRESULT hr; + LONG count;
hr = MFCreateVideoSampleAllocator(&IID_IUnknown, (void **)&unk); ok(hr == S_OK, "Unexpected hr %#x.\n", hr); IUnknown_Release(unk);
- hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator, (void **)&unk); + hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocator, (void **)&allocator); ok(hr == S_OK, "Unexpected hr %#x.\n", hr); - IUnknown_Release(unk); + + hr = IMFVideoSampleAllocator_QueryInterface(allocator, &IID_IMFVideoSampleAllocatorCallback, (void **)&allocator_cb); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + count = 10; + hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(!count, "Unexpected count %d.\n", count); +} + hr = IMFVideoSampleAllocator_UninitializeSampleAllocator(allocator); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample); +todo_wine + ok(hr == MF_E_NOT_INITIALIZED, "Unexpected hr %#x.\n", hr); + + hr = MFCreateMediaType(&media_type); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + /* It expects IMFVideoMediaType. */ + hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, media_type); +todo_wine + ok(hr == E_NOINTERFACE, "Unexpected hr %#x.\n", hr); + + hr = MFCreateVideoMediaTypeFromSubtype(&MFVideoFormat_RGB32, &video_type); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 2, (IMFMediaType *)video_type); +todo_wine + ok(hr == MF_E_INVALIDMEDIATYPE, "Unexpected hr %#x.\n", hr); + + /* Frame size is required. */ + hr = IMFVideoMediaType_SetUINT64(video_type, &MF_MT_FRAME_SIZE, (UINT64) 320 << 32 | 240); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 0, (IMFMediaType *)video_type); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(count == 1, "Unexpected count %d.\n", count); +} + sample = NULL; + hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (SUCCEEDED(hr)) + ok(get_refcount(sample) == 3, "Unexpected refcount %u.\n", get_refcount(sample)); + + hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample2); +todo_wine + ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#x.\n", hr); + + /* Reinitialize with active sample. */ + hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 4, (IMFMediaType *)video_type); +todo_wine + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + if (sample) + ok(get_refcount(sample) == 3, "Unexpected refcount %u.\n", get_refcount(sample)); + + hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count); +todo_wine { + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + ok(count == 4, "Unexpected count %d.\n", count); +} + if (sample) + { + hr = IMFSample_QueryInterface(sample, &IID_IMFDesiredSample, (void **)&unk); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IUnknown_Release(unk); + + hr = IMFSample_QueryInterface(sample, &IID_IMFTrackedSample, (void **)&unk); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + IUnknown_Release(unk); + + hr = IMFSample_GetBufferByIndex(sample, 0, &buffer); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + hr = IMFMediaBuffer_QueryInterface(buffer, &IID_IMFGetService, (void **)&gs); + ok(hr == S_OK, "Unexpected hr %#x.\n", hr); + + /* Device manager wasn't set, sample get regular memory buffers. */ + hr = IMFGetService_GetService(gs, &MR_BUFFER_SERVICE, &IID_IDirect3DSurface9, (void **)&surface); + ok(hr == E_NOTIMPL, "Unexpected hr %#x.\n", hr); + + IMFMediaBuffer_Release(buffer); + + IMFGetService_Release(gs); + IMFSample_Release(sample); + } + + IMFVideoSampleAllocatorCallback_Release(allocator_cb); + + IMFMediaType_Release(media_type); + + IMFVideoSampleAllocator_Release(allocator);
hr = MFCreateVideoSampleAllocator(&IID_IMFVideoSampleAllocatorCallback, (void **)&unk); ok(hr == S_OK, "Unexpected hr %#x.\n", hr);