将 x264 纳入 webrtc 的编译系统

本文详细介绍了如何将x264编译系统纳入WebRTC,包括前提条件、编译环境(macOS 10.15 Catalina,WebRTC m84版本),操作步骤涉及下载x264源码、编写GN脚本、配置文件编译以及文件重命名。通过这些步骤,可以在WebRTC项目中启用H264编解码支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将 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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值