• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2021 Seungha Yang <seungha@centricular.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "gstmfplatloader.h"
25 #include "gstmfconfig.h"
26 #include <gmodule.h>
27 
28 /* *INDENT-OFF* */
29 G_BEGIN_DECLS
30 
31 GST_DEBUG_CATEGORY_EXTERN (gst_mf_debug);
32 #define GST_CAT_DEFAULT gst_mf_debug
33 
34 G_END_DECLS
35 
36 #define LOAD_SYMBOL(name,func) G_STMT_START { \
37   if (!g_module_symbol (module, G_STRINGIFY (name), (gpointer *) &vtable->func)) { \
38     GST_WARNING ("Failed to load '%s', %s", G_STRINGIFY (name), g_module_error()); \
39     goto out; \
40   } \
41 } G_STMT_END;
42 
43 typedef struct _GstMFPlatVTable
44 {
45   gboolean loaded;
46 
47   HRESULT (__stdcall * GstMFTEnum2) (GUID guidCategory,
48                                      UINT32 Flags,
49                                      const MFT_REGISTER_TYPE_INFO * pInputType,
50                                      const MFT_REGISTER_TYPE_INFO * pOutputType,
51                                      IMFAttributes * pAttributes,
52                                      IMFActivate *** pppMFTActivate,
53                                      UINT32 * pnumMFTActivate);
54 
55   HRESULT (__stdcall * GstMFCreateDXGIDeviceManager) (UINT * resetToken,
56                                                       IMFDXGIDeviceManager ** ppDeviceManager);
57 
58   HRESULT (__stdcall * GstMFCreateVideoSampleAllocatorEx) (REFIID riid,
59                                                            void** ppSampleAllocator);
60 } GstMFPlatVTable;
61 /* *INDENT-ON* */
62 
63 static GstMFPlatVTable gst_mf_plat_vtable = { 0, };
64 
65 static gboolean
load_library_once(void)66 load_library_once (void)
67 {
68   static gsize load_once = 0;
69   if (g_once_init_enter (&load_once)) {
70 #if GST_MF_HAVE_D3D11
71     GModule *module;
72     GstMFPlatVTable *vtable = &gst_mf_plat_vtable;
73 
74     module = g_module_open ("mfplat.dll", G_MODULE_BIND_LAZY);
75     if (!module)
76       goto out;
77 
78     LOAD_SYMBOL (MFTEnum2, GstMFTEnum2);
79     LOAD_SYMBOL (MFCreateDXGIDeviceManager, GstMFCreateDXGIDeviceManager);
80     LOAD_SYMBOL (MFCreateVideoSampleAllocatorEx,
81         GstMFCreateVideoSampleAllocatorEx);
82 
83     vtable->loaded = TRUE;
84 #endif
85 
86   out:
87     g_once_init_leave (&load_once, 1);
88   }
89 
90   return gst_mf_plat_vtable.loaded;
91 }
92 
93 gboolean
gst_mf_plat_load_library(void)94 gst_mf_plat_load_library (void)
95 {
96   return load_library_once ();
97 }
98 
99 HRESULT __stdcall
GstMFTEnum2(GUID guidCategory,UINT32 Flags,const MFT_REGISTER_TYPE_INFO * pInputType,const MFT_REGISTER_TYPE_INFO * pOutputType,IMFAttributes * pAttributes,IMFActivate *** pppMFTActivate,UINT32 * pnumMFTActivate)100 GstMFTEnum2 (GUID guidCategory, UINT32 Flags,
101     const MFT_REGISTER_TYPE_INFO * pInputType,
102     const MFT_REGISTER_TYPE_INFO * pOutputType,
103     IMFAttributes * pAttributes, IMFActivate *** pppMFTActivate,
104     UINT32 * pnumMFTActivate)
105 {
106   g_assert (gst_mf_plat_vtable.GstMFTEnum2 != NULL);
107 
108   return gst_mf_plat_vtable.GstMFTEnum2 (guidCategory, Flags, pInputType,
109       pOutputType, pAttributes, pppMFTActivate, pnumMFTActivate);
110 }
111 
112 HRESULT __stdcall
GstMFCreateDXGIDeviceManager(UINT * resetToken,IMFDXGIDeviceManager ** ppDeviceManager)113 GstMFCreateDXGIDeviceManager (UINT * resetToken,
114     IMFDXGIDeviceManager ** ppDeviceManager)
115 {
116   g_assert (gst_mf_plat_vtable.GstMFCreateDXGIDeviceManager != NULL);
117 
118   return gst_mf_plat_vtable.GstMFCreateDXGIDeviceManager (resetToken,
119       ppDeviceManager);
120 }
121 
122 HRESULT __stdcall
GstMFCreateVideoSampleAllocatorEx(REFIID riid,void ** ppSampleAllocator)123 GstMFCreateVideoSampleAllocatorEx (REFIID riid, void **ppSampleAllocator)
124 {
125   g_assert (gst_mf_plat_vtable.GstMFCreateVideoSampleAllocatorEx != NULL);
126 
127   return gst_mf_plat_vtable.GstMFCreateVideoSampleAllocatorEx (riid,
128       ppSampleAllocator);
129 }
130