将 x264 纳入 webrtc 的编译系统
Author: Vinton.Liu
Date: 2020-11-05
1. 前提
下载好的 webrtc 代码已经能正常编译。
2. 编译环境
- macos: 10.15 Catalina
- webrtc: m84 (branch-heads/4147)
3. 操作步骤
3.1 下载代码
下载地址:VideoLan X264.
将代码解压缩到 webrtc 的 third_party 目录内,最终目录结构为:
<m84 path>/third_party/x264
3.2 编写 GN 脚本
参考 x264 的 Makefile 编写 Gn 脚本,需要注意的是需要考虑 Bitdepth = 8 及 Bitdepth = 10的编译。
个人经过各平台编译调试,总结出以下脚本:
- BUILD.gn
# Copyright 2014 The Chromium 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("x264_options.gni")
import("x264_srcs.gni")
import("//build/config/arm.gni")
import("//build/config/android/config.gni")
import("//build/config/sanitizers/sanitizers.gni")
# Path to platform configuration files.
platform_config_root =
"config/$os_config/$x264_arch"
# print("x264 platform_config_root: $platform_config_root")
has_nasm_deps =
x264_srcs_mmx_x86_assembly != [] &&
(current_cpu == "x86" || current_cpu == "x64") && os_config != "linux-noasm"
config("x264_config") {
include_dirs = [
platform_config_root,
".",
"common",
"encoder",
]
defines = []
cflags = [ ]
if (is_posix && is_android) {
defines += [
"_GNU_SOURCE",
]
}
if (current_cpu == "arm") {
include_dirs += [ "common/arm" ]
cflags += [
"-mfpu=neon",
"-Wno-incompatible-pointer-types",
"-fno-tree-vectorize"
]
if (is_android) {
cflags += [
"-fomit-frame-pointer",
]
}
} else if (current_cpu == "arm64") {
include_dirs += [ "common/aarch64" ]
# configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
} else if (current_cpu == "x64") {
include_dirs += [ "common/x86" ]
if (is_win) {
include_dirs += [ "extras" ]
}
} else if (current_cpu == "x86") {
include_dirs += [ "common/x86" ]
if (is_win) {
include_dirs += [ "extras" ]
}
}
if (!is_win) {
cflags_c = [
"-ffast-math",
"-std=gnu99",
"-fPIC",
]
}
if (is_android) {
defines += [ "WEBRTC_ANDROID" ]
} else if (is_ios) {
defines += [ "WEBRTC_IOS", "PREFIX" ]
} else if (is_win) {
defines += [ "WEBRTC_WIN", "HAVE_STRING_H" ]
} else {
defines += [ "WEBRTC_MAC", "HAVE_MMX=1"]
}
if ((is_android) && is_clang) {
# TODO(hans) Enable integrated-as (crbug.com/124610).
asmflags = [ "-fno-integrated-as" ]
if (is_android) {
rebased_android_toolchain_root = rebase_path(android_toolchain_root, root_build_dir)
# Else /usr/bin/as gets picked up.
asmflags += [ "-B${rebased_android_toolchain_root}/bin" ]
}
}
}
# 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("x264_warnings") {
if (is_clang) {
cflags = [
"-Wno-conversion",
"-Wno-parentheses-equality",
"-Wno-unused-function",
"-Wno-sign-compare",
"-Wno-unreachable-code"
]
if (is_android) {
cflags += [
"-Wno-implicit-f