| # Copyright 2017 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("ffmpeg_generated.gni") |
| import("ffmpeg_options.gni") |
| |
| # Path to configuration files. |
| # |
| # Placing this file in //build/secondary/third_party/ffmpeg causes it to be mirrored in |
| # //third_party/ffmpeg, where the build system expects it to be. The mirroring that achieves |
| # that doesn't work for config files, however. As a result, we have to be specific about where |
| # the config file can be found by the compiler. |
| # |
| # If at some point we are able to integrate this repo at //third_party/ffmpeg, this assignment |
| # must be restored to its previous value, namely: |
| # |
| # ffmpeg_config_root = "config/$ffmpeg_profile/$current_cpu" |
| # |
| ffmpeg_config_root = "//build/secondary/third_party/ffmpeg/config/$ffmpeg_profile/$current_cpu" |
| |
| has_yasm_deps = ffmpeg_yasm_sources != [] && current_cpu == "x64" |
| if (has_yasm_deps) { |
| import("//third_party/yasm/yasm_assemble.gni") |
| yasm_assemble("ffmpeg_yasm") { |
| sources = [] |
| foreach(source, ffmpeg_yasm_sources) { |
| sources += [ "src/" + source ] |
| } |
| |
| # Ensure the architecture defines go in the command line before the -P |
| # file below, so don't use defines. |
| yasm_flags = [] |
| if (current_cpu == "x86") { |
| yasm_flags += [ "-DARCH_X86_32" ] |
| } else if (current_cpu == "x64") { |
| yasm_flags += [ "-DARCH_X86_64" ] |
| } |
| |
| inputs = [ |
| # Sets visibility hidden for cglobal functions. Explicitly included |
| # to avoid overlooking changes to this file in incremental builds. |
| "src/libavutil/x86/x86inc.asm", |
| ] |
| |
| defines = [ "PIC" ] |
| include_dirs = [ |
| ffmpeg_config_root, |
| "src/libavcodec/x86", |
| "src/libavutil/x86", |
| "src", |
| ] |
| |
| # Disable warnings, prevents log spam for things we won't fix. |
| yasm_flags += [ |
| "-w", |
| "-P", |
| rebase_path("$ffmpeg_config_root/config.asm", root_build_dir), |
| ] |
| |
| if (is_mac) { |
| # Necessary to ensure symbols end up with a _ prefix; added by |
| # yasm_assemble.gni for Windows, but not Mac. |
| defines += [ "PREFIX" ] |
| } |
| } |
| } |
| |
| config("ffmpeg_dependent_config") { |
| include_dirs = [ |
| ffmpeg_config_root, |
| "src", |
| ] |
| } |
| |
| # gn orders flags on a target before flags from configs. The default config |
| # adds -Wall, and these flags have to be after -Wall -- so they need to come |
| # from a config and can't be on the target directly. |
| config("ffmpegsumo_warnings") { |
| cflags = [ |
| "-Wno-absolute-value", |
| |
| # ffmpeg uses its own deprecated functions. |
| "-Wno-deprecated-declarations", |
| |
| # ffmpeg doesn't care about pointer constness. |
| "-Wno-incompatible-pointer-types", |
| |
| # ffmpeg doesn't follow usual parentheses conventions. |
| "-Wno-logical-op-parentheses", |
| |
| # ffmpeg doesn't care about pointer signedness. |
| "-Wno-parentheses", |
| |
| # ffmpeg doesn't care about pointer signedness. |
| "-Wno-pointer-sign", |
| |
| # ffmpeg doesn't believe in exhaustive switch statements. |
| "-Wno-switch", |
| |
| # matroskadec.c has a "failed:" label that's only used if some |
| # CONFIG_ flags we don't set are set. |
| "-Wno-unused-label", |
| |
| # ffmpeg has a lot of unused variables. |
| "-Wno-unused-variable", |
| |
| # This fires on `av_assert0(!"valid element size")` in utils.c |
| "-Wno-string-conversion", |
| |
| # This fires on `pos_min` and `pos_max` in |
| # autorename_libavformat_utils.c |
| "-Wno-sometimes-uninitialized", |
| |
| # ffmpeg contains static functions in header files, which lead |
| # to unused function warnings. There are a few legit unused |
| # functions too. |
| "-Wno-unused-function", |
| |
| # vp3data.h's vp31_inter_dequant stores '128' in an int8_t array. |
| "-Wno-constant-conversion", |
| |
| "-Wno-string-plus-int", |
| |
| # ffmpeg compares ints and floats. |
| "-Wno-implicit-int-float-conversion", |
| "-Wno-implicit-int-conversion", |
| "-Wno-implicit-float-conversion", |
| "-Wno-float-conversion", |
| "-Wno-shorten-64-to-32", |
| "-Wno-unused-but-set-variable", |
| |
| # fmmpeg may have questionable indentation. We should come back later |
| # to confirm if this indentation is expected. |
| "-Wno-misleading-indentation", |
| |
| "-Wno-extra-semi", |
| ] |
| } |
| |
| config("ffmpeg_warnings") { |
| cflags = [ |
| "-Wno-sign-compare", |
| "-Wno-missing-field-initializers", |
| "-Wno-pointer-bool-conversion", |
| "-Wno-implicit-fallthrough", |
| "-Wno-implicit-int-float-conversion", |
| "-Wno-implicit-int-conversion", |
| "-Wno-implicit-float-conversion", |
| "-Wno-float-conversion", |
| "-Wno-shorten-64-to-32", |
| "-Wno-string-plus-int", |
| "-Wno-unused-but-set-variable", |
| "-Wno-misleading-indentation", |
| ] |
| } |
| |
| shared_library("ffmpeg") { |
| sources = [] |
| foreach(source, ffmpeg_c_sources + ffmpeg_gas_sources) { |
| sources += [ "src/" + source ] |
| } |
| sources += [ |
| "$ffmpeg_config_root/config.h", |
| "$ffmpeg_config_root/libavutil/avconfig.h", |
| ] |
| public_configs = [ ":ffmpeg_dependent_config" ] |
| defines = [ |
| "HAVE_AV_CONFIG_H", |
| "_POSIX_C_SOURCE=200112", |
| "_XOPEN_SOURCE=600", |
| "PIC", |
| |
| # Disable deprecated features that generate spammy warnings. |
| "FF_API_CONVERGENCE_DURATION=0", |
| |
| # Upstream libavcodec/utils.c still uses the deprecated |
| # av_dup_packet(), avcodec_encode_{audio,video}2(), and |
| # libavformat/utils.c still accesses the deprecated AVStream.codec, |
| # causing deprecation warnings. |
| # The normal fix for such things is to disable the features like setting |
| # "FF_API_AVPACKET_OLD_API=0", but the upstream code does not yet compile |
| # with it disabled (in the case of av_dup_packet()), and has no FF_API* |
| # gate for avcodec_encode_{audio,video}2() or AVStream.codec. In the |
| # meantime, we directly disable those warnings locally in the C files. |
| ] |
| |
| # So we can append below and assume they're defined. |
| cflags = [] |
| ldflags = [] |
| libs = [] |
| deps = [ "//third_party/opus" ] |
| |
| configs += [ |
| ":ffmpeg_warnings", |
| ":ffmpegsumo_warnings", |
| ] |
| |
| # Since we are not often debugging FFmpeg, and performance is unacceptable |
| # without optimization, we always optimize for speed. |
| # |
| # In addition to the above reasons, /Od optimization won't remove symbols |
| # that are under "if (0)" style sections. Which lead to link time errors |
| # when for example it tries to link an ARM symbol on X86. |
| configs -= [ "//build/config:default_optimize" ] |
| configs += [ "//build/config:optimize_speed" ] |
| |
| # Make all symbols visible. |
| configs -= [ "//build/config:symbol_visibility_hidden" ] |
| |
| cflags += [ |
| # ffmpeg uses its own deprecated functions. |
| "-Wno-deprecated-declarations", |
| "-Wno-deprecated-non-prototype", |
| "-Wno-strict-prototypes", |
| ] |
| |
| defines += [ |
| "_ISOC99_SOURCE", |
| "_LARGEFILE_SOURCE", |
| ] |
| |
| cflags += [ |
| "-std=c99", |
| "-pthread", |
| "-fno-math-errno", |
| "-fno-signed-zeros", |
| "-fno-tree-vectorize", |
| "-fomit-frame-pointer", |
| ] |
| ldflags = [ |
| # Avoid PIC relocation errors from assembly code. |
| "-Wl,-Bsymbolic", |
| "-L", |
| rebase_path(target_gen_dir, root_build_dir), |
| ] |
| |
| if (has_yasm_deps) { |
| deps += [ ":ffmpeg_yasm" ] |
| } |
| |
| # TODO(46940): UBSan has found an instance of undefined behavior in this target. |
| # Disable UBSan for this target temporarily until it is migrated into CI/CQ. |
| configs += [ "//build/config:temporarily_disable_ubsan_do_not_use" ] |
| } |
| |
| group("ffmpeg_variants") { |
| deps = [] |
| _variants = select_variant |
| if (select_variant != []) { |
| _variants += [ "novariant" ] |
| } |
| foreach(variant, _variants) { |
| deps += [ ":ffmpeg(${toolchain_variant.base}-${variant}-shared)" ] |
| } |
| } |