98570e5baa16a60dd8013f5dce449fcf56039f82
[platform/upstream/gstreamer.git] / 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 if host_machine.system() == 'windows'
28   msdk_sources += ['msdk_d3d.c', 'gstmsdkallocator_d3d.c' ]
29 else
30   msdk_sources += ['msdk_libva.c', 'gstmsdkallocator_libva.c']
31 endif
32
33 have_msdk = false
34 msdk_dep = []
35
36 msdk_option = get_option('msdk')
37 if msdk_option.disabled()
38   subdir_done()
39 endif
40
41 mfx_dep = dependency('libmfx', required: false)
42 if mfx_dep.found()
43   mfx_incdir = mfx_dep.get_pkgconfig_variable('includedir')
44   mfx_inc = []
45 else
46   # Old versions of MediaSDK don't provide a pkg-config file
47   mfx_root = run_command(python3, '-c', 'import os; print(os.environ.get("INTELMEDIASDKROOT", os.environ.get("MFX_HOME", "")))').stdout().strip()
48
49   if mfx_root != ''
50     mfx_libdir = [mfx_root + '/lib/lin_x64', mfx_root + '/lib/x64', mfx_root + '/lib64', mfx_root + '/lib']
51     if host_machine.system() == 'windows'
52       if host_machine.cpu_family() == 'x86'
53         mfx_libdir = [mfx_root + '/lib/win32']
54       else
55         mfx_libdir = [mfx_root + '/lib/x64']
56       endif
57     endif
58     mfx_incdir = join_paths([mfx_root, 'include'])
59     mfx_lib = cxx.find_library('mfx', dirs: mfx_libdir, required: msdk_option)
60     mfx_inc = include_directories(mfx_incdir)
61     mfx_dep = declare_dependency(include_directories: mfx_inc, dependencies: mfx_lib)
62   elif msdk_option.enabled()
63     error('msdk plugin enabled but Intel Media SDK not found: consider setting PKG_CONFIG_PATH, INTELMEDIASDKROOT or MFX_HOME')
64   else
65     subdir_done()
66   endif
67 endif
68
69 # Old versions of MediaSDK don't have the 'mfx' directory prefix
70 if cxx.has_header('mfx/mfxdefs.h', args: '-I' + mfx_incdir)
71   mfx_incdir = join_paths([mfx_incdir, 'mfx'])
72   mfx_inc = include_directories(mfx_incdir)
73 endif
74
75 if cxx.has_header('mfxvp9.h', args: '-I' + mfx_incdir)
76   msdk_sources += [ 'gstmsdkvp9dec.c' ]
77   cdata.set10('USE_MSDK_VP9_DEC', 1)
78 endif
79
80 # Usually MFX_VERSION 1026+ is required to support raw VP9 stream, however Fedora 30 has MFX_VERSION==1026
81 # but without support for raw VP9 stream, so mfxExtVP9Param is checked as well.
82 # See https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/988#note_408093
83 mfx_ver126_check_code = '''
84 #include <mfxdefs.h>
85 #include <mfxstructures.h>
86 #if MFX_VERSION < 1026
87 #error "The current version of mfx doesn't support raw vp9 stream"
88 #endif
89 mfxExtVP9Param ext;
90 '''
91
92 have_mfx_ver126 = cc.compiles(mfx_ver126_check_code,
93                 include_directories : [configinc, mfx_inc])
94
95 if have_mfx_ver126
96   msdk_sources += [ 'gstmsdkvp9enc.c' ]
97   cdata.set10('USE_MSDK_VP9_ENC', 1)
98 endif
99
100 mfx_ver134_check_code = '''
101 #include <mfxdefs.h>
102 #if MFX_VERSION < 1034
103 #error "The current version of mfx doesn't support AV1 decoding"
104 #endif
105 '''
106
107 have_mfx_ver134 = cc.compiles(mfx_ver134_check_code,
108                 include_directories : [configinc, mfx_inc])
109
110 if have_mfx_ver134
111   msdk_sources += [ 'gstmsdkav1dec.c' ]
112   cdata.set10('USE_MSDK_AV1_DEC', 1)
113 endif
114
115 if host_machine.system() == 'windows'
116   if cc.get_id() != 'msvc' and msdk_option.enabled()
117     error('msdk plugin can only be built with MSVC')
118   endif
119   legacy_stdio_dep = cc.find_library('legacy_stdio_definitions', required: get_option('msdk'))
120   d3d11_dep = cc.find_library('d3d11', required: get_option('msdk'))
121   msdk_deps = declare_dependency(dependencies: [d3d11_dep, legacy_stdio_dep])
122   msdk_deps_found = d3d11_dep.found() and legacy_stdio_dep.found() and cc.get_id() == 'msvc'
123 else
124   libva_dep = dependency('libva-drm', required: get_option('msdk'))
125   libdl_dep = cc.find_library('dl', required: get_option('msdk'))
126   libgudev_dep = dependency('gudev-1.0', required: get_option('msdk'))
127   libdrm_dep = dependency('libdrm', required: get_option('msdk'))
128   msdk_deps = declare_dependency(dependencies: [libva_dep, libdl_dep, libgudev_dep, libdrm_dep])
129   msdk_deps_found = libva_dep.found() and libdl_dep.found() and libgudev_dep.found() and libdrm_dep.found()
130 endif
131
132 if msdk_deps_found
133   gstmsdktag = library('gstmsdk',
134     msdk_sources,
135     c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
136     include_directories : [configinc, mfx_inc],
137     dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstallocators_dep, gstcodecparsers_dep, mfx_dep, msdk_deps],
138     install : true,
139     install_dir : plugins_install_dir,
140   )
141   pkgconfig.generate(gstmsdktag, install_dir : plugins_pkgconfig_install_dir)
142   plugins += [gstmsdktag]
143   have_msdk = true
144 endif