meson: wasapi2,mediafoundation: Work around Windows SDK header issue
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / mediafoundation / meson.build
1 mf_sources = [
2   'plugin.c',
3   'gstmfutils.cpp',
4   'gstmftransform.cpp',
5   'gstmfvideoenc.cpp',
6   'gstmfh264enc.cpp',
7   'gstmfh265enc.cpp',
8   'gstmfvp9enc.cpp',
9   'gstmfvideosrc.c',
10   'gstmfsourceobject.c',
11   'gstmfdevice.c',
12   'gstmfaudioenc.cpp',
13   'gstmfaacenc.cpp',
14   'gstmfmp3enc.cpp',
15   'gstmfvideobuffer.cpp',
16   'gstmfplatloader.c',
17 ]
18
19 mf_desktop_sources = [
20   'gstmfsourcereader.cpp',
21   'gstwin32devicewatcher.cpp',
22 ]
23
24 mf_app_sources = [
25   'gstmfcapturewinrt.cpp',
26   'mediacapturewrapper.cpp',
27 ]
28
29 mf_header_deps = [
30   'mfidl.h',
31   'mfapi.h',
32   'mfreadwrite.h',
33   'mferror.h',
34   'strmif.h',
35   'mfobjects.h',
36   'codecapi.h',
37 ]
38
39 winapi_desktop = false
40 winapi_app = false
41 have_capture_engine = false
42 have_mf_d3d11 = false
43 mf_lib_deps = []
44 mf_config = configuration_data()
45 extra_c_args = ['-DCOBJMACROS']
46 extra_cpp_args = []
47
48 mf_option = get_option('mediafoundation')
49 if host_system != 'windows' or mf_option.disabled()
50   subdir_done()
51 endif
52
53 if cc.get_id() != 'msvc'
54   if mf_option.enabled()
55     error('mediafoundation plugin can only be built with MSVC')
56   endif
57   subdir_done()
58 endif
59
60 mf_lib = cc.find_library('mf', required : mf_option)
61 mfplat_lib = cc.find_library('mfplat', required : mf_option)
62 mfreadwrite_lib = cc.find_library('mfreadwrite', required : mf_option)
63 mfuuid_lib = cc.find_library('mfuuid', required : mf_option)
64 strmiids_lib = cc.find_library('strmiids', required : mf_option)
65 ole32_dep = cc.find_library('ole32', required : mf_option)
66 runtimeobject_lib = cc.find_library('runtimeobject', required : false)
67
68 have_mf_lib = mf_lib.found() and mfplat_lib.found() and mfreadwrite_lib.found() and mfuuid_lib.found() and strmiids_lib.found() and ole32_dep.found()
69 if not have_mf_lib
70   if mf_option.enabled()
71     error('The mediafoundation plugin was enabled explicitly, but required libraries were not found.')
72   endif
73   subdir_done()
74 endif
75
76 mf_lib_deps += [mf_lib, mfplat_lib, mfreadwrite_lib, mfuuid_lib, strmiids_lib, ole32_dep]
77
78 have_mf_header = true
79 foreach h: mf_header_deps
80   if have_mf_header
81     have_mf_header = cc.has_header(h)
82   endif
83 endforeach
84
85 if not have_mf_header
86   if mf_option.enabled()
87     error('The mediafoundation plugin was enabled explicitly, but required headers were not found.')
88   endif
89   subdir_done()
90 endif
91
92 winapi_desktop = cxx.compiles('''#include <winapifamily.h>
93     #include <wrl.h>
94     #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
95     #error "not win32"
96     #endif''',
97     dependencies: mf_lib_deps,
98     name: 'building for Win32')
99
100 if runtimeobject_lib.found()
101   winapi_app = cxx.compiles('''#include <winapifamily.h>
102       #include <windows.applicationmodel.core.h>
103       #include <wrl.h>
104       #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
105       #error "not winrt"
106       #endif
107       #ifndef WINVER
108       #error "unknown minimum supported OS version"
109       #endif
110       #if (WINVER < 0x0A00)
111       #error "Windows 10 API is not guaranteed"
112       #endif''',
113       dependencies: [mf_lib_deps, runtimeobject_lib],
114       name: 'building for WinRT')
115 endif
116
117 if not winapi_desktop and not winapi_app
118   error('Neither Desktop partition nor App partition')
119 endif
120
121 if winapi_app
122   if not gstwinrt_dep.found()
123     if mf_option.enabled()
124       error('The mediafoundation plugin was enabled explicitly, but GstWinRt library is unavailable')
125     else
126       subdir_done()
127     endif
128   endif
129
130   mf_sources += mf_app_sources
131   mf_lib_deps += [runtimeobject_lib, gstwinrt_dep]
132 endif
133
134 if winapi_desktop
135   mf_sources += mf_desktop_sources
136   # We need d3d11_4.h header for querying "ExtendedNV12SharedTextureSupported"
137   # Since MFTEnum2 is desktop only we don't support d3d11 interop for UWP build
138   # And because MFTEnum2 is Windows 10 API, we will load MFTEnum2 symbol
139   # by using g_module_open() so that keep supporting old OS versions
140   if gstd3d11_dep.found() and cc.has_header('d3d11_4.h') and cc.has_header('d3d10.h')
141     have_mf_d3d11 = true
142     mf_lib_deps += [gstd3d11_dep, gmodule_dep]
143     extra_c_args += ['-DGST_USE_UNSTABLE_API']
144     extra_cpp_args += ['-DGST_USE_UNSTABLE_API']
145     message ('Enable D3D11 interop for MediaFoundation plugin')
146   endif
147 endif
148
149 mf_config.set10('GST_MF_WINAPI_APP', winapi_app)
150 mf_config.set10('GST_MF_WINAPI_DESKTOP', winapi_desktop)
151 mf_config.set10('GST_MF_HAVE_D3D11', have_mf_d3d11)
152
153 configure_file(
154   output: 'gstmfconfig.h',
155   configuration: mf_config,
156 )
157
158 # Work around for Windows SDK header issue
159 # https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=msvc-160#windows-header-issues
160 extra_cpp_args += cxx.get_supported_arguments(['/Zc:twoPhase-'])
161
162 gstmediafoundation = library('gstmediafoundation',
163   mf_sources,
164   c_args : gst_plugins_bad_args + extra_c_args,
165   cpp_args : gst_plugins_bad_args + extra_cpp_args,
166   include_directories : [configinc],
167   dependencies : [gstbase_dep, gstvideo_dep, gstaudio_dep, gstpbutils_dep] + mf_lib_deps,
168   install : true,
169   install_dir : plugins_install_dir,
170 )
171 pkgconfig.generate(gstmediafoundation, install_dir : plugins_pkgconfig_install_dir)
172 plugins += [gstmediafoundation]