[PATCH 1/2] evr: Add a stub for sample allocator.

Nikolay Sivov nsivov at codeweavers.com
Fri Jul 3 11:22:15 CDT 2020


Signed-off-by: Nikolay Sivov <nsivov at 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,
-- 
2.27.0




More information about the wine-devel mailing list