summaryrefslogtreecommitdiff
path: root/src/codec/ffmpeg/meson.build
blob: e34cc9265883478abaf61caaf81a76c2965364a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
ffmpeg_src = ['common.c', 'packet_ext.c']
ffmpeg_args = ['-DCAMU_HAVE_FFMPEG']

ffmpeg_server_src = [ffmpeg_src, 'demuxer.c', 'avio.c']
server_transcode = not get_option('sink-only')
if server_transcode
  ffmpeg_server_src += ['decoder.c', 'resampler.c', 'scaler.c', 'encoder.c']
endif
ffmpeg_server_deps = []

ffmpeg_client_src = [ffmpeg_src, 'decoder.c', 'resampler.c', 'scaler.c']
ffmpeg_client_deps = []

ffmpeg_force_fallback = get_option('wrap_mode') == 'forcefallback'
foreach dep: ['ffmpeg', 'libavutil', 'libavformat', 'libavcodec', 'libavdevice', 'libswresample', 'libswscale']
  if dep in get_option('force_fallback_for')
    ffmpeg_force_fallback = true
    break
  endif
endforeach
ffmpeg_version_option = get_option('codec-ffmpeg-version')
# Check for FFmpeg version in the environment.
if not ffmpeg_force_fallback
  libavutil_version_map = { '54': '2', '55': '3', '56': '4', '57': '5', '58': '6', '59': '7', '60': '8' }
  libavutil_version_rev = { '2': '54', '3': '55', '4': '56', '5': '57', '6': '58', '7': '59', '8': '60' }
  if ffmpeg_version_option != 'system'
    ffmpeg_version_int = ffmpeg_version_option.to_int()
    # Overriding a found dependency will error but overriding a found dependency of the wrong version is allowed.
    libavutil_version_request = ['>=' + libavutil_version_rev[(ffmpeg_version_int).to_string()] + '.0.0']
    if ffmpeg_version_int < 8
      libavutil_version_request += ['<' + libavutil_version_rev[(ffmpeg_version_int + 1).to_string()] + '.0.0']
    endif
    libavutil = dependency('libavutil', required: false, allow_fallback: false, version: libavutil_version_request)
  else
    libavutil = dependency('libavutil', required: false, allow_fallback: false)
  endif
  if libavutil.found()
    ffmpeg_version_string = run_command('sh', join_paths(meson.current_source_dir(), 'version.sh'), check: true).stdout().strip()
    if ffmpeg_version_string == '(unknown)'
      ffmpeg_version_string = libavutil_version_map[libavutil.version().split('.')[0]] + '.x'
    endif
    ffmpeg_args += ['-DFFMPEG_VERSION="' + ffmpeg_version_string + '"']
    if get_option('codec-hwaccels').length() > 0
      hwaccel_map = {
        'vulkan': '-DCAMU_HAVE_VULKAN_DECODE',
        'vaapi': '-DCAMU_HAVE_VAAPI',
        'd3d11va': '-DCAMU_HAVE_D3D11VA',
        'dxva2': '-DCAMU_HAVE_DXVA2',
        'mediacodec': '-DCAMU_HAVE_MEDIACODEC',
      }
      foreach hwaccel: get_option('codec-hwaccels')
        if hwaccel in hwaccel_map
          ffmpeg_args += hwaccel_map[hwaccel]
        endif
      endforeach
      ffmpeg_args += ['-DCAMU_TRY_HWACCEL']
    endif
  elif ffmpeg_version_option == 'system'
    error('System FFmpeg requested but not found. Add \'--force-fallback-for=ffmpeg\' or \'-Dcodec-ffmpeg-version=[8,7,6,...]\'.')
  endif
endif
# Fallback if requested or necessary.
if ffmpeg_force_fallback or not libavutil.found()
  if ffmpeg_version_option == 'system'
    ffmpeg_version_option = '8' # Default to current latest.
  endif
  subproject('ffmpeg' + ffmpeg_version_option) # Override libav dependencies.
endif

libavutil = dependency('libavutil')
libavutil_version = libavutil.version().split('.')[0].to_int()
if libavutil_version <= 54
  error('FFmpeg version 2.x and lower currently unsupported.')
elif libavutil_version <= 56
  ffmpeg_args += ['-DCAMU_OLD_FFMPEG']
endif
libavformat = dependency('libavformat')
libavcodec = dependency('libavcodec')
libavdevice = dependency('libavdevice')
libswresample = dependency('libswresample')
libswscale = dependency('libswscale')
ffmpeg_server_deps += [libavutil, libavformat, libavcodec]
if server_transcode
  ffmpeg_server_deps += [libswresample, libswscale]
endif
ffmpeg_client_deps += [libavutil, libavformat, libavcodec, libswresample, libswscale]
codec_server_deps += [declare_dependency(sources: ffmpeg_server_src, dependencies: ffmpeg_server_deps, compile_args: ffmpeg_args)]
codec_client_deps += [declare_dependency(sources: ffmpeg_client_src, dependencies: ffmpeg_client_deps, compile_args: ffmpeg_args)]