msdkenc: Use va pool on linux and system pool for windows
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / msdk / meson.build
1 msdk_sources = [
2   'gstmsdk.c',
3   'gstmsdkbufferpool.c',
4   'gstmsdkcontext.c',
5   'gstmsdkcontextutil.c',
6   'gstmsdkdec.c',
7   'gstmsdkdecproputil.c',
8   'gstmsdkenc.c',
9   'gstmsdkh264dec.c',
10   'gstmsdkh264enc.c',
11   'gstmsdkh265dec.c',
12   'gstmsdkh265enc.c',
13   'gstmsdkmjpegdec.c',
14   'gstmsdkmjpegenc.c',
15   'gstmsdkmpeg2dec.c',
16   'gstmsdkmpeg2enc.c',
17   'gstmsdksystemmemory.c',
18   'gstmsdkvc1dec.c',
19   'gstmsdkvideomemory.c',
20   'gstmsdkvp8dec.c',
21   'gstmsdkvpp.c',
22   'gstmsdkvpputil.c',
23   'msdk-enums.c',
24   'msdk.c',
25 ]
26
27 have_msdk = false
28 msdk_dep = []
29 use_msdk = false
30 use_onevpl = false
31 onevpl_extra_args = []
32
33 msdk_option = get_option('msdk')
34 if msdk_option.disabled()
35   subdir_done()
36 endif
37
38 if host_machine.system() == 'windows'
39   msdk_sources += ['msdk_d3d.c', 'gstmsdkallocator_d3d.c' ]
40 else
41   if not gstva_dep.found()
42     if msdk_option.enabled()
43       error('The msdk plugin was enabled explicity, but required va dependencies were not found.')
44     endif
45     subdir_done()
46   endif
47   msdk_sources += ['msdk_libva.c', 'gstmsdkallocator_libva.c']
48 endif
49
50 mfx_api = get_option('mfx_api')
51
52 if mfx_api != 'oneVPL'
53   mfx_dep = dependency('libmfx', version: ['>= 1.0', '<= 1.99'], required: false)
54
55   if mfx_dep.found()
56     mfx_incdir = mfx_dep.get_variable('includedir')
57     mfx_inc = []
58     use_msdk = true
59   else
60     # Old versions of MediaSDK don't provide a pkg-config file
61     mfx_root = run_command(python3, '-c', 'import os; print(os.environ.get("INTELMEDIASDKROOT", os.environ.get("MFX_HOME", "")))', check: false).stdout().strip()
62
63     if mfx_root != ''
64       mfx_libdir = [mfx_root + '/lib/lin_x64', mfx_root + '/lib/x64', mfx_root + '/lib64', mfx_root + '/lib']
65       if host_machine.system() == 'windows'
66         if host_machine.cpu_family() == 'x86'
67           mfx_libdir = [mfx_root + '/lib/win32']
68         else
69           mfx_libdir = [mfx_root + '/lib/x64']
70         endif
71       endif
72       mfx_incdir = join_paths([mfx_root, 'include'])
73       mfx_lib = cxx.find_library('mfx', dirs: mfx_libdir, required: msdk_option)
74       mfx_inc = include_directories(mfx_incdir)
75       mfx_dep = declare_dependency(include_directories: mfx_inc, dependencies: mfx_lib)
76       use_msdk = true
77     endif
78   endif
79 endif
80
81 if not use_msdk and mfx_api != 'MSDK'
82   mfx_dep = dependency('vpl', version: '>= 2.2', required: false)
83
84   if mfx_dep.found()
85     mfx_incdir = mfx_dep.get_variable('includedir')
86     mfx_inc = []
87     use_onevpl = true
88   endif
89 endif
90
91 if not use_msdk and not use_onevpl
92   if msdk_option.enabled()
93     error('msdk plugin enabled but the Intel Media SDK or the oneVPL SDK not found: consider setting PKG_CONFIG_PATH, INTELMEDIASDKROOT or MFX_HOME')
94   else
95     subdir_done()
96   endif
97 endif
98
99 # Check oneVPL firstly
100 if use_onevpl
101   onevpl_extra_args += ['-DONEVPL_EXPERIMENTAL']
102   mfx_incdir = join_paths([mfx_incdir, 'vpl'])
103   mfx_inc = include_directories(mfx_incdir)
104 elif cxx.has_header('mfx/mfxdefs.h', args: '-I' + mfx_incdir)
105   mfx_incdir = join_paths([mfx_incdir, 'mfx'])
106   mfx_inc = include_directories(mfx_incdir)
107 endif
108
109 if use_onevpl or cxx.has_header('mfxvp9.h', args: '-I' + mfx_incdir)
110   msdk_sources += [ 'gstmsdkvp9dec.c' ]
111   cdata.set('USE_MSDK_VP9_DEC', 1)
112 endif
113
114 # Usually MFX_VERSION 1026+ is required to support raw VP9 stream, however Fedora 30 has MFX_VERSION==1026
115 # but without support for raw VP9 stream, so mfxExtVP9Param is checked as well.
116 # See https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/988#note_408093
117 mfx_ver126_check_code = '''
118 #include <mfxdefs.h>
119 #include <mfxstructures.h>
120 #if MFX_VERSION < 1026
121 #error "The current version of mfx doesn't support raw vp9 stream"
122 #endif
123 mfxExtVP9Param ext;
124 '''
125
126 have_mfx_ver126 = cc.compiles(mfx_ver126_check_code,
127                 include_directories : [configinc, mfx_inc])
128
129 if have_mfx_ver126
130   msdk_sources += [ 'gstmsdkvp9enc.c' ]
131   cdata.set('USE_MSDK_VP9_ENC', 1)
132 endif
133
134 mfx_ver134_check_code = '''
135 #include <mfxdefs.h>
136 #if MFX_VERSION < 1034
137 #error "The current version of mfx doesn't support AV1 decoding"
138 #endif
139 '''
140
141 have_mfx_ver134 = cc.compiles(mfx_ver134_check_code,
142                 include_directories : [configinc, mfx_inc])
143
144 if have_mfx_ver134
145   msdk_sources += [ 'gstmsdkav1dec.c' ]
146   cdata.set('USE_MSDK_AV1_DEC', 1)
147 endif
148
149 mfx_ver205_check_code = '''
150 #include <mfxdefs.h>
151 #if MFX_VERSION < 2005
152 #error "The current verison of mfx doesn't support AV1 encoding"
153 #endif
154 '''
155
156 have_mfx_ver205 = cc.compiles(mfx_ver205_check_code,
157                 include_directories: [configinc, mfx_inc])
158
159 if use_onevpl and have_mfx_ver205
160   msdk_sources += [ 'gstmsdkav1enc.c' ]
161   cdata.set10('USE_MSDK_AV1_ENC', 1)
162 endif
163
164 if host_machine.system() == 'windows'
165   if cc.get_id() != 'msvc' and msdk_option.enabled()
166     error('msdk plugin can only be built with MSVC')
167   endif
168   legacy_stdio_dep = cc.find_library('legacy_stdio_definitions', required: get_option('msdk'))
169   d3d11_dep = cc.find_library('d3d11', required: get_option('msdk'))
170   msdk_deps = declare_dependency(dependencies: [d3d11_dep, legacy_stdio_dep])
171   msdk_deps_found = d3d11_dep.found() and legacy_stdio_dep.found() and cc.get_id() == 'msvc'
172 else
173   libdl_dep = cc.find_library('dl', required: get_option('msdk'))
174   libgudev_dep = dependency('gudev-1.0', required: get_option('msdk'))
175   libdrm_dep = dependency('libdrm', required: get_option('msdk'))
176   msdk_deps = declare_dependency(dependencies: [gstva_dep, libdl_dep, libgudev_dep, libdrm_dep])
177   msdk_deps_found = gstva_dep.found() and libdl_dep.found() and libgudev_dep.found() and libdrm_dep.found()
178 endif
179
180 if msdk_deps_found
181   if host_machine.system() != 'windows'
182     driverdir = libva_dep.get_variable('driverdir', default_value: '')
183     if driverdir == ''
184       driverdir = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
185     endif
186     cdata.set_quoted('VA_DRIVERS_PATH', '@0@'.format(driverdir))
187   endif
188
189   gstmsdktag = library('gstmsdk',
190     msdk_sources,
191     c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'] + onevpl_extra_args,
192     include_directories : [configinc, mfx_inc],
193     dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstallocators_dep, gstcodecparsers_dep, mfx_dep, msdk_deps],
194     install : true,
195     install_dir : plugins_install_dir,
196   )
197   plugins += [gstmsdktag]
198   have_msdk = true
199 endif