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