go tool pprof 参数 ‘-base‘ 和 ‘-diff_base‘ 之间的区别

go tool pprof 工具是用于分析由 runtime/pprof包 或 net/http/pprof包产生的profile数据,完整的帮助文档在 https://github.com/google/pprof/blob/main/doc/README.mdpprof 工具支持的参数很多,可以用命令 go tool pprof --help来查看全部参数列表,今天主要来说下 -base-diff_base 这两个参数, 因为文档对这两个参数的描述比较晦涩,难以理解这两个参数之间的区别。

    -diff_base source     Source of base profile for comparison
    -base source          Source of base profile for profile subtraction

pprof can subtract one profile from another, provided the profiles are of compatible types (i.e. two heap profiles). pprof has two options which can be used to specify the filename or URL for a profile to be subtracted from the source profile:
 
-diff_base= profile: useful for comparing two profiles. Percentages in the output are relative to the total of samples in the diff base profile.
 
-base= profile: useful for subtracting a cumulative profile, like a golang block profile, from another cumulative profile collected from the same program at a later time. When comparing cumulative profiles collected on the same program, percentages in the output are relative to the difference between the total for the source profile and the total for the base profile.
 
The -normalize flag can be used when a base profile is specified with either the -diff_base or the -base option. This flag scales the source profile so that the total of samples in the source profile is equal to the total of samples in the base profile prior to subtracting the base profile from the source profile. Useful for determining the relative differences between profiles, for example, which profile has a larger percentage of CPU time used in a particular function.
 
When using the -diff_base option, some report entries may have negative values. If the merged profile is output as a protocol buffer, all samples in the diff base profile will have a label with the key “pprof::base” and a value of “true”. If pprof is then used to look at the merged profile, it will behave as if separate source and base profiles were passed in.
 
When using the -base option to subtract one cumulative profile from another collected on the same program at a later time, percentages will be relative to the difference between the total for the source profile and the total for the base profile, and all values will be positive. In the general case, some report entries may have negative values and percentages will be relative to the total of the absolute value of all samples when aggregated at the address level.

这两个参数都是用于多个profile文件之间的对比,文档中关于这两个参数的描述翻译过来:

比较profile文件

pprof 工具可以从一个profile文件中减去另一个profile文件,前提是这两个profile文件类型是兼容的(比如两个都是heap profile文件)。pprof有两个选项,用于指定需要减去的这个profile文件的文件名或URL:
 
-diff_base=profile:用于比较两个profile文件。计算出的百分比是基于diff_base 参数指定的这个profile文件中的采样指标之和。
 
-base=profile:用于累计指标类型的profile文件(比如golang的block profile),适用于将同一个程序后采集的profile文件减去先采集的profile文件的场景。当对比在同一个程序上收集的累计指标类型的profile文件时,展示的百分比是基于当前采集的profile文件中的采样指标之和与之前采集的profile文件中采样指标之和之间的差值
 
当用-diff_base-base参数指定基准profile文件时,可以加上-normalize 选项,加上该选项后,在计算当前profile文件与基准profile文件的采样和差值之前,会把当前profile文件的采样数据全部乘以一个固定的百分比(用基准profile采样和除以当前profile采样和得到),使得当前profile的采样数据之和与基准profile采样和相等。通常用于确定两个profile文件之间的相对差异,例如,用于比较哪个profile在特定函数中消耗的CPU时间占比更高。
 
当使用-diff_base选项时,某些指标可能会存在负值。如果合并后的profile文件以protocol buffer 格式输出,则基准profile文件中的所有采样都会加上pprof::base的Label,Label的值为“true”。如果随后使用pprof工具来查看合并之后的profile文件,那么它的表现和同时传入合并前的原始profile文件和基准profile文件保持一致。
 
当使用-base选项从同一个程序上后收集的一个累计指标类型的profile文件中减去一个之前收集的同类型的profile文件时,百分比将相对于后收集的profile文件的采样指标总和与先收集的profile文件的采样指标总和之间的差值,并且所有值都将为正数(因为累计指标是随着时间在不断增长的,后采集的值不会比先采集的值要小)。一般来说,有些指标可能会存在负值,这时当在地址级别进行聚合时,百分比将相对于所有采样指标的绝对值之和。

总结下来就是,两个参数都是用于计算当前 profile文件减去基准profile文件所获得的差值,用这个差值生成一个新的profile文件,区别在于计算这个新生成的profile文件每个采样指标的占比时,-base 是基于基准profile文件的指标和(所以百分比可能大于100%),而 -diff_base 则是基于差值profile文件的指标和(也就是这个新生成的profile文件本身的指标和,所以每个采样的指标占比不会超过100%)。

比如我这里由同一个程序前后生成了两个profile文件: profile001.pb.gzprofile002.pb.gz,现在分别用 -base-diff_base 参数生成一个差集profile:

$ pprof -proto -output gen_by_base_opt.pb.gz -base profile001.pb.gz profile002.pb.gz
Generating report in gen_by_base_opt.pb.gz
$ pprof -proto -output gen_by_diff_base_opt.pb.gz -diff_base profile001.pb.gz profile002.pb.gz
Generating report in gen_by_diff_base_opt.pb.gz
$ ll
total 48
-rw-r--r--  1 zy  staff  2839  5 18 19:42 gen_by_base_opt.pb.gz
-rw-r--r--  1 zy  staff  4772  5 18 19:42 gen_by_diff_base_opt.pb.gz
-rw-r--r--  1 zy  staff  3092  5 17 16:43 profile001.pb.gz
-rw-r--r--  1 zy  staff  4504  5 17 16:59 profile002.pb.gz

分别计算出这两个差集的指标和:

package main

import (
	"fmt"
	"github.com/google/pprof/profile"
	"log"
	"os"
)

func sumProfile(file string) map[string]int64 {
	f, err := os.Open(file)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	pprof, err := profile.Parse(f)
	if err != nil {
		log.Fatal(err)
	}
	sums := make(map[string]int64, len(pprof.SampleType))

	for _, sample := range pprof.Sample {
		for i, v := range sample.Value {
			sums[pprof.SampleType[i].Type] += v
		}
	}
	return sums
}

func main() {
	var sum map[string]int64

	sum = sumProfile("./profile001.pb.gz")
	fmt.Println("sum of profile001.pb.gz: ")

	keys := make([]string, 0, len(sum))
	for k := range sum {
		keys = append(keys, k)
	}

	for _, k := range keys {
		fmt.Println(k, " --> ", sum[k])
	}
	fmt.Println()

	sum = sumProfile("./profile002.pb.gz")
	fmt.Println("sum of profile002.pb.gz: ")
	for _, k := range keys {
		fmt.Println(k, " --> ", sum[k])
	}
	fmt.Println()

	sum = sumProfile("./gen_by_base_opt.pb.gz")
	fmt.Println("sum of gen_by_base_opt.pb.gz: ")
	for _, k := range keys {
		fmt.Println(k, " --> ", sum[k])
	}
	fmt.Println()

	sum = sumProfile("./gen_by_diff_base_opt.pb.gz")
	fmt.Println("sum of gen_by_diff_base_opt.pb.gz: ")
	for _, k := range keys {
		fmt.Println(k, " --> ", sum[k])
	}
	fmt.Println()
}


执行结果:

sum of profile001.pb.gz: 
alloc_objects  -->  26137
alloc_space  -->  31409035
inuse_objects  -->  3914
inuse_space  -->  3148768

sum of profile002.pb.gz: 
alloc_space  -->  98663649
inuse_objects  -->  9397
inuse_space  -->  4771620
alloc_objects  -->  51635

sum of gen_by_base_opt.pb.gz: 
alloc_objects  -->  25498
alloc_space  -->  67254614
inuse_objects  -->  5483
inuse_space  -->  1622852

sum of gen_by_diff_base_opt.pb.gz: 
alloc_objects  -->  25498
alloc_space  -->  67254614
inuse_objects  -->  5483
inuse_space  -->  1622852

可以看出,gen_by_base_opt.pb.gzgen_by_diff_base_opt.pb.gz 的各项指标和等于 profile002.pb.gz 值减去 profile001.pb.gz

通过 pprof 工具来查看生成的差集profile:

$ pprof -http=: -base=profile001.pb.gz profile002.pb.gz
Serving web UI on http://localhost:57739

在这里插入图片描述

$ pprof -http=: -diff_base=profile001.pb.gz profile002.pb.gz
Serving web UI on http://localhost:57845

在这里插入图片描述
对比两幅火焰图可以看出两幅图除了百分比之外基本没有差别,并且从右上角可以看出这里展示的是 alloc_space指标数据,而 64.14MB 正好就是我们上面生成的profile文件gen_by_base_opt.pb.gzgen_by_diff_base_opt.pb.gzalloc_space指标和(67254614 / 1024 / 1024 = 64.13899803161621)。

而百分比之所以不同,是因为计算百分比的基数不同,-base 是以计算出的差集本身作为基准值计算百分比,而-diff_base则是以指定的base profile,也就是这里的 profile001.pb.gz 指标值作为基准进行计算 ( 67254614 / 31409035 = 2.141250566914902)。

1 #!/bin/bash 2 3 # variables, parent script must set it: 4 # SRS_JOBS: the build jobs. 5 # SrsArmMakeOptions: the arm make options for ubuntu12(armhf, v7cpu) 6 7 ##################################################################################### 8 ##################################################################################### 9 # prepare the depends tools and libraries 10 # DEPENDS: options.sh, only when user options parsed, the depends tools are known. 11 ##################################################################################### 12 ##################################################################################### 13 14 ##################################################################################### 15 # Check OS and CPU architectures. 16 ##################################################################################### 17 if [[ $OS_IS_UBUNTU != YES && $OS_IS_CENTOS != YES && $OS_IS_OSX != YES && $SRS_CYGWIN64 != YES ]]; then 18 if [[ $SRS_CROSS_BUILD != YES && $SRS_GENERIC_LINUX != YES ]]; then 19 echo "Your OS `uname -s` is not supported." 20 if [[ $(uname -s) == "Linux" ]]; then 21 echo "Please try --generic-linux=on for other Linux systems." 22 fi 23 exit 1 24 fi 25 fi 26 27 # The absolute path of SRS_OBJS, for prefix and PKG_CONFIG_PATH 28 SRS_DEPENDS_LIBS=$(mkdir -p $SRS_OBJS && cd $SRS_OBJS && pwd) 29 echo -n "SRS_JOBS: $SRS_JOBS, SRS_DEPENDS_LIBS: ${SRS_DEPENDS_LIBS}" 30 if [[ ! -z $OS_IS_LINUX ]]; then echo -n ", OS_IS_LINUX: $OS_IS_LINUX"; fi 31 if [[ ! -z $OS_IS_OSX ]]; then echo -n ", OS_IS_OSX: $OS_IS_OSX"; fi 32 if [[ ! -z $OS_IS_CYGWIN ]]; then echo -n ", OS_IS_CYGWIN: $OS_IS_CYGWIN"; fi 33 if [[ ! -z $OS_IS_UBUNTU ]]; then echo -n ", OS_IS_UBUNTU: $OS_IS_UBUNTU"; fi 34 if [[ ! -z $OS_IS_CENTOS ]]; then echo -n ", OS_IS_CENTOS: $OS_IS_CENTOS"; fi 35 if [[ ! -z $SRS_CROSS_BUILD ]]; then echo -n ", SRS_CROSS_BUILD: $SRS_CROSS_BUILD"; fi 36 if [[ ! -z $OS_IS_LOONGARCH64 ]]; then echo -n ", OS_IS_LOONGARCH64: $OS_IS_LOONGARCH64"; fi 37 if [[ ! -z $OS_IS_MIPS64 ]]; then echo -n ", OS_IS_MIPS64: $OS_IS_MIPS64"; fi 38 if [[ ! -z $OS_IS_LOONGSON ]]; then echo -n ", OS_IS_LOONGSON: $OS_IS_LOONGSON"; fi 39 if [[ ! -z $OS_IS_X86_64 ]]; then echo -n ", OS_IS_X86_64: $OS_IS_X86_64"; fi 40 if [[ ! -z $OS_IS_RISCV ]]; then echo -n ", OS_IS_RISCV: $OS_IS_RISCV"; fi 41 echo "" 42 43 ##################################################################################### 44 # Check dependency tools. 45 ##################################################################################### 46 if [[ $SRS_OSX == YES ]]; then 47 brew --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 48 echo "Please install brew at https://brew.sh/"; exit $ret; 49 fi 50 fi 51 # Check perl, which is depended by automake for building libopus etc. 52 perl --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 53 if [[ $OS_IS_CENTOS == YES ]]; then 54 echo "Please install perl by:" 55 echo " yum install -y perl" 56 elif [[ $OS_IS_UBUNTU == YES ]]; then 57 echo "Please install perl by:" 58 echo " apt install -y perl" 59 else 60 echo "Please install perl" 61 fi 62 exit $ret; 63 fi 64 gcc --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 65 if [[ $OS_IS_CENTOS == YES ]]; then 66 echo "Please install gcc by:" 67 echo " yum install -y gcc" 68 elif [[ $OS_IS_UBUNTU == YES ]]; then 69 echo "Please install gcc by:" 70 echo " apt install -y gcc" 71 else 72 echo "Please install gcc" 73 fi 74 exit $ret; 75 fi 76 g++ --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 77 if [[ $OS_IS_CENTOS == YES ]]; then 78 echo "Please install g++ by:" 79 echo " yum install -y gcc-c++" 80 elif [[ $OS_IS_UBUNTU == YES ]]; then 81 echo "Please install g++ by:" 82 echo " apt install -y g++" 83 else 84 echo "Please install gcc-c++" 85 fi 86 exit $ret; 87 fi 88 make --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 89 if [[ $OS_IS_CENTOS == YES ]]; then 90 echo "Please install make by:" 91 echo " yum install -y make" 92 elif [[ $OS_IS_UBUNTU == YES ]]; then 93 echo "Please install make by:" 94 echo " apt install -y make" 95 else 96 echo "Please install make" 97 fi 98 exit $ret; 99 fi 100 patch --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 101 if [[ $OS_IS_CENTOS == YES ]]; then 102 echo "Please install patch by:" 103 echo " yum install -y patch" 104 elif [[ $OS_IS_UBUNTU == YES ]]; then 105 echo "Please install patch by:" 106 echo " apt install -y patch" 107 else 108 echo "Please install patch" 109 fi 110 exit $ret; 111 fi 112 unzip -v >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 113 if [[ $OS_IS_CENTOS == YES ]]; then 114 echo "Please install unzip by:" 115 echo " yum install -y unzip" 116 elif [[ $OS_IS_UBUNTU == YES ]]; then 117 echo "Please install unzip by:" 118 echo " apt install -y unzip" 119 else 120 echo "Please install unzip" 121 fi 122 exit $ret; 123 fi 124 automake --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 125 if [[ $OS_IS_CENTOS == YES ]]; then 126 echo "Please install automake by:" 127 echo " yum install -y automake" 128 elif [[ $OS_IS_UBUNTU == YES ]]; then 129 echo "Please install automake by:" 130 echo " apt install -y automake" 131 else 132 echo "Please install automake" 133 fi 134 exit $ret; 135 fi 136 if [[ $SRS_VALGRIND == YES ]]; then 137 valgrind --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 138 echo "Please install valgrind"; exit $ret; 139 fi 140 if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then 141 echo "Please install valgrind-dev"; exit $ret; 142 fi 143 fi 144 # Check tclsh, which is depended by SRT. 145 if [[ $SRS_SRT == YES ]]; then 146 tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then 147 if [[ $OS_IS_CENTOS == YES ]]; then 148 echo "Please install tclsh by:" 149 echo " yum install -y tcl" 150 elif [[ $OS_IS_UBUNTU == YES ]]; then 151 echo "Please install tclsh by:" 152 echo " apt install -y tclsh" 153 else 154 echo "Please install tclsh" 155 fi 156 exit $ret; 157 fi 158 cmake --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 159 if [[ $OS_IS_CENTOS == YES ]]; then 160 echo "Please install cmake by:" 161 echo " yum install -y cmake" 162 elif [[ $OS_IS_UBUNTU == YES ]]; then 163 echo "Please install cmake by:" 164 echo " apt install -y cmake" 165 else 166 echo "Please install cmake" 167 fi 168 exit $ret; 169 fi 170 fi 171 pkg-config --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 172 echo "Please install pkg-config"; exit $ret; 173 fi 174 which ls >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then 175 if [[ $OS_IS_CENTOS == YES ]]; then 176 echo "Please install which by:" 177 echo " yum install -y which" 178 elif [[ $OS_IS_UBUNTU == YES ]]; then 179 echo "Please install which by:" 180 echo " apt install -y which" 181 else 182 echo "Please install which" 183 fi 184 exit $ret; 185 fi 186 187 ##################################################################################### 188 # Try to load cache if exists /usr/local/srs-cache 189 ##################################################################################### 190 # Use srs-cache from base image. See https://github.com/ossrs/dev-docker/blob/ubuntu20-cache/Dockerfile 191 # Note that the cache for cygwin is not under /usr/local, but copy to objs instead. 192 if [[ -d /usr/local/srs-cache/srs/trunk/objs && $(pwd) != "/usr/local/srs-cache/srs/trunk" && $SRS_BUILD_CACHE == YES ]]; then 193 SOURCE_DIR=$(ls -d /usr/local/srs-cache/srs/trunk/objs/Platform-SRS${SRS_MAJOR}-* 2>/dev/null|head -n 1) 194 if [[ -d $SOURCE_DIR ]]; then 195 TARGET_DIR=${SRS_OBJS}/${SRS_PLATFORM} && 196 echo "Build from cache, source=$SOURCE_DIR, target=$TARGET_DIR" && 197 rm -rf $TARGET_DIR && mkdir -p ${SRS_OBJS} && cp -R $SOURCE_DIR $TARGET_DIR && 198 du -sh /usr/local/srs-cache/srs/trunk/objs/Platform-* && 199 du -sh /usr/local/srs-cache/srs/trunk/objs/Platform-*/* && 200 du -sh objs/Platform-* && 201 ls -lh objs 202 fi 203 fi 204 205 ##################################################################################### 206 # Check for address sanitizer, see https://github.com/google/sanitizers 207 ##################################################################################### 208 if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES ]]; then 209 echo 'int main() { return 0; }' > ${SRS_OBJS}/test_sanitizer.c && 210 gcc -fsanitize=address -fno-omit-frame-pointer -g -O0 ${SRS_OBJS}/test_sanitizer.c \ 211 -o ${SRS_OBJS}/test_sanitizer 1>/dev/null 2>&1; 212 ret=$?; rm -rf ${SRS_OBJS}/test_sanitizer* 213 if [[ $ret -ne 0 ]]; then 214 echo "Please install libasan, see https://github.com/google/sanitizers"; 215 if [[ $OS_IS_CENTOS == YES ]]; then echo " sudo yum install -y libasan"; fi 216 exit $ret; 217 fi 218 fi 219 220 if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES && $SRS_SANITIZER_STATIC == NO ]]; then 221 echo 'int main() { return 0; }' > ${SRS_OBJS}/test_sanitizer.c && 222 gcc -fsanitize=address -fno-omit-frame-pointer -static-libasan -g -O0 ${SRS_OBJS}/test_sanitizer.c \ 223 -o ${SRS_OBJS}/test_sanitizer 1>/dev/null 2>&1; 224 ret=$?; rm -rf ${SRS_OBJS}/test_sanitizer* 225 if [[ $ret -eq 0 ]]; then 226 echo "link static-libasan" 227 SRS_SANITIZER_STATIC=YES 228 fi 229 fi 230 231 if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES && $SRS_SANITIZER_LOG == NO ]]; then 232 echo "#include <sanitizer/asan_interface.h>" > ${SRS_OBJS}/test_sanitizer.c && 233 echo "int main() { return 0; }" >> ${SRS_OBJS}/test_sanitizer.c && 234 gcc -fsanitize=address -fno-omit-frame-pointer -g -O0 ${SRS_OBJS}/test_sanitizer.c \ 235 -o ${SRS_OBJS}/test_sanitizer 1>/dev/null 2>&1; 236 ret=$?; rm -rf ${SRS_OBJS}/test_sanitizer* 237 if [[ $ret -eq 0 ]]; then 238 echo "libasan api found ok!"; 239 SRS_SANITIZER_LOG=YES 240 fi 241 fi 242 243 ##################################################################################### 244 # state-threads 245 ##################################################################################### 246 # check the cross build flag file, if flag changed, need to rebuild the st. 247 _ST_MAKE=linux-debug && _ST_OBJ="LINUX_`uname -r`_DBG" 248 # Always alloc on heap, @see https://github.com/ossrs/srs/issues/509#issuecomment-719931676 249 _ST_EXTRA_CFLAGS="-DMALLOC_STACK" 250 # For valgrind to detect memory issues. 251 if [[ $SRS_VALGRIND == YES ]]; then 252 _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_VALGRIND" 253 fi 254 # for osx, use darwin for st, donot use epoll. 255 if [[ $SRS_OSX == YES ]]; then 256 _ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG" 257 fi 258 # for windows/cygwin 259 if [[ $SRS_CYGWIN64 = YES ]]; then 260 _ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG" 261 fi 262 # For Ubuntu, the epoll detection might be fail. 263 if [[ $OS_IS_UBUNTU == YES ]]; then 264 _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL" 265 fi 266 # Whether enable debug stats. 267 if [[ $SRS_DEBUG_STATS == YES ]]; then 268 _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS" 269 fi 270 # Pass the global extra flags. 271 if [[ $SRS_EXTRA_FLAGS != '' ]]; then 272 _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS" 273 fi 274 # Whether link as .so 275 if [[ $SRS_SHARED_ST == YES ]]; then 276 _ST_STATIC_ONLY=no; 277 else 278 _ST_STATIC_ONLY=yes; 279 fi 280 # The final args to make st. 281 _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}" 282 _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}" 283 # Patched ST from https://github.com/ossrs/state-threads/tree/srs 284 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/libst.a ]]; then 285 rm -rf ${SRS_OBJS}/st && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/ && 286 echo "The state-threads is ok." 287 else 288 echo "Building state-threads." && 289 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/st && 290 cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/ && 291 env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} && 292 mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st && 293 cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/st.h ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/ && 294 cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/ && 295 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/ && 296 echo "The state-threads is ok." 297 fi 298 # check status 299 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi 300 301 ##################################################################################### 302 # nginx for HLS, nginx-1.5.0 303 ##################################################################################### 304 function write_nginx_html5() 305 { 306 cat<<END > ${html_file} 307 <video width="100%" autoplay controls autobuffer type="application/vnd.apple.mpegurl" 308 src="${hls_stream}"> 309 </video> 310 END 311 } 312 # create the nginx dir, for http-server if not build nginx 313 mkdir -p ${SRS_OBJS}/nginx 314 315 # the demo dir. 316 # create forward dir 317 mkdir -p ${SRS_OBJS}/nginx/html/live && 318 html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5 && 319 320 # copy players to nginx html dir. 321 rm -rf ${SRS_OBJS}/nginx/html/players && 322 cp -rf $SRS_WORKDIR/research/players ${SRS_OBJS}/nginx/html/ && 323 324 # for favicon.ico 325 rm -rf ${SRS_OBJS}/nginx/html/favicon.ico && 326 cp -f $SRS_WORKDIR/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico && 327 328 # For srs-console. 329 rm -rf ${SRS_OBJS}/nginx/html/console && 330 cp -rf $SRS_WORKDIR/research/console ${SRS_OBJS}/nginx/html/ && 331 332 # For SRS signaling. 333 rm -rf ${SRS_OBJS}/nginx/html/demos && 334 cp -rf $SRS_WORKDIR/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/ && 335 336 # For home page index.html 337 rm -rf ${SRS_OBJS}/nginx/html/index.html && 338 cp -f $SRS_WORKDIR/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html && 339 340 # nginx.html to detect whether nginx is alive 341 echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html 342 343 # check status 344 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build web pages failed, ret=$ret"; exit $ret; fi 345 346 ##################################################################################### 347 # Generate default self-sign certificate for HTTPS server, test only. 348 ##################################################################################### 349 if [[ ! -f $SRS_WORKDIR/conf/server.key || ! -f $SRS_WORKDIR/conf/server.crt ]]; then 350 openssl genrsa -out $SRS_WORKDIR/conf/server.key 2048 && 351 openssl req -new -x509 -key $SRS_WORKDIR/conf/server.key -out $SRS_WORKDIR/conf/server.crt -days 3650 \ 352 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" && 353 echo "Generate test-only self-sign certificate files" 354 fi 355 356 ##################################################################################### 357 # openssl, for rtmp complex handshake and HLS encryption. 358 ##################################################################################### 359 if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then 360 echo "Warning: Use system libssl, without compiling openssl." 361 fi 362 # @see http://www.openssl.org/news/secadv/20140407.txt 363 # Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately 364 # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS. 365 if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then 366 OPENSSL_OPTIONS="-no-shared -no-threads -DOPENSSL_NO_HEARTBEATS" 367 OPENSSL_CONFIG="./config" 368 # https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain 369 if [[ $SRS_CROSS_BUILD == YES ]]; then 370 OPENSSL_CONFIG="./Configure linux-generic32" 371 if [[ $SRS_CROSS_BUILD_ARCH == "arm" ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi 372 if [[ $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi 373 if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" ]]; then OPENSSL_CONFIG="./Configure linux-mips32"; fi 374 elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib/libssl.a ]]; then 375 # Try to use exists libraries. 376 if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then 377 (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib && 378 cp /usr/local/ssl/lib/libssl.a . && cp /usr/local/ssl/lib/libcrypto.a . && 379 mkdir -p /usr/local/ssl/lib/pkgconfig && cp -rf /usr/local/ssl/lib/pkgconfig .) 380 (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/include && 381 cp -rf /usr/local/ssl/include/openssl .) 382 fi 383 # Warning if not use the system ssl. 384 if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then 385 echo "Warning: Local openssl is on, ignore system openssl" 386 fi 387 fi 388 # Patch for loongarch mips64, disable ASM for build failed message as bellow: 389 # Error: opcode not supported on this processor: mips3 (mips3) 390 if [[ $OS_IS_MIPS64 == YES ]]; then OPENSSL_CONFIG="./Configure linux64-mips64"; fi 391 if [[ $OS_IS_LOONGSON == YES ]]; then OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-asm"; fi 392 # For RTC, we should use ASM to improve performance, not a little improving. 393 if [[ $SRS_RTC == NO || $SRS_NASM == NO ]]; then 394 OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-asm" 395 echo "Warning: NASM is off, performance is hurt" 396 fi 397 # Mac OS X can have issues (its often a neglected platform). 398 # @see https://wiki.openssl.org/index.php/Compilation_and_Installation 399 if [[ $SRS_OSX == YES ]]; then 400 export KERNEL_BITS=64; 401 fi 402 # Use 1.0 if required. 403 if [[ $SRS_SSL_1_0 == YES ]]; then 404 OPENSSL_AR="$SRS_TOOL_AR -r" # For openssl 1.0, MUST specifies the args for ar or build faild. 405 OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && 406 OPENSSL_UNZIP="tar xf ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE.tar.gz -C ${SRS_OBJS}/${SRS_PLATFORM}" 407 else 408 OPENSSL_AR="$SRS_TOOL_AR" 409 OPENSSL_CANDIDATE="openssl-1.1-fit" && 410 OPENSSL_UNZIP="cp -R ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE ${SRS_OBJS}/${SRS_PLATFORM}/" 411 fi 412 # 413 # https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options 414 # Already defined: -no-shared -no-threads -no-asm 415 # Should enable: -no-dtls -no-dtls1 -no-ssl3 416 # Might able to disable: -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers 417 # Note that we do not disable more features, because no file could be removed. 418 #OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers" 419 # 420 # cross build not specified, if exists flag, need to rebuild for no-arm platform. 421 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib/libssl.a ]]; then 422 rm -rf ${SRS_OBJS}/openssl && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl ${SRS_OBJS}/ && 423 echo "The $OPENSSL_CANDIDATE is ok." 424 else 425 echo "Building $OPENSSL_CANDIDATE." && 426 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl \ 427 ${SRS_OBJS}/openssl && 428 ${OPENSSL_UNZIP} && 429 ( 430 cd ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && 431 chmod +x ./config ./Configure && 432 ${OPENSSL_CONFIG} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/openssl $OPENSSL_OPTIONS 433 ) && 434 make -C ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" \ 435 LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && 436 make -C ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} install_sw && 437 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl ${SRS_OBJS}/ && 438 echo "The $OPENSSL_CANDIDATE is ok." 439 fi 440 # check status 441 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build $OPENSSL_CANDIDATE failed, ret=$ret"; exit $ret; fi 442 fi 443 444 ##################################################################################### 445 # srtp 446 ##################################################################################### 447 if [[ $SRS_RTC == YES && $SRS_USE_SYS_SRTP == YES ]]; then 448 echo "Warning: Use system libsrtp, without compiling srtp." 449 fi 450 if [[ $SRS_RTC == YES && $SRS_USE_SYS_SRTP == NO ]]; then 451 SRTP_OPTIONS="" 452 # To eliminate warnings, see https://stackoverflow.com/a/34208904/17679565 453 # was built for newer macOS version (11.6) than being linked (11.0) 454 if [[ $SRS_OSX == YES ]]; then 455 export MACOSX_DEPLOYMENT_TARGET=11.0 456 echo "Set MACOSX_DEPLOYMENT_TARGET to avoid warnings" 457 fi 458 # If use ASM for SRTP, we enable openssl(with ASM). 459 if [[ $SRS_SRTP_ASM == YES ]]; then 460 SRTP_OPTIONS="--enable-openssl" 461 SRTP_CONFIGURE="env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/openssl/lib/pkgconfig ./configure" 462 else 463 SRTP_OPTIONS="--disable-openssl" 464 SRTP_CONFIGURE="./configure" 465 fi 466 if [[ $SRS_CROSS_BUILD == YES ]]; then 467 SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST" 468 fi 469 if [[ $OS_IS_LOONGARCH64 == YES ]]; then 470 SRTP_OPTIONS="$SRTP_OPTIONS --build=loongarch64-unknown-linux-gnu" 471 fi 472 # Copy and patch source files, then build and install libsrtp. 473 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2/lib/libsrtp2.a ]]; then 474 rm -rf ${SRS_OBJS}/srtp2 && 475 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 ${SRS_OBJS} && 476 echo "The libsrtp-2-fit is ok." 477 else 478 echo "Building libsrtp-2-fit." 479 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 \ 480 ${SRS_OBJS}/srtp2 && 481 cp -rf ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && 482 # For cygwin64, the patch is not available, so use sed instead. 483 if [[ $SRS_CYGWIN64 == YES ]]; then 484 sed -i 's/char bit_string/static char bit_string/g' ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c 485 else 486 patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch 487 fi && 488 # Patch the cpu arch guessing for RISCV. 489 if [[ $OS_IS_RISCV == YES ]]; then 490 patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch 491 fi && 492 ( 493 cd ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit && 494 $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/srtp2 495 ) && 496 # Sometimes it might fail because autoconf failed to generate crypto/include.config.h 497 if [[ $SRS_CYGWIN64 == YES ]]; then 498 SRS_PATCH_SOURCE=${SRS_WORKDIR}/3rdparty/patches/srtp/cygwin-crypto-include-config.h 499 if [[ $SRS_SRTP_ASM == YES ]]; then 500 SRS_PATCH_SOURCE=${SRS_WORKDIR}/3rdparty/patches/srtp/cygwin-gcm-crypto-include-config.h 501 fi 502 grep -q 'HAVE_UINT64_T 1' ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/include/config.h || 503 cp -f $SRS_PATCH_SOURCE ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/include/config.h 504 fi && 505 make -C ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_JOBS} && 506 make -C ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit install && 507 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 ${SRS_OBJS}/ && 508 echo "The libsrtp-2-fit is ok." 509 fi 510 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp failed, ret=$ret"; exit $ret; fi 511 fi 512 513 ##################################################################################### 514 # libopus, for WebRTC to transcode AAC with Opus. 515 ##################################################################################### 516 # For cross build, we use opus of FFmpeg, so we don't build the libopus. 517 if [[ $SRS_RTC == YES && $SRS_USE_SYS_FFMPEG != YES && $SRS_FFMPEG_OPUS != YES ]]; then 518 # Only build static libraries if no shared FFmpeg. 519 if [[ $SRS_SHARED_FFMPEG != YES ]]; then 520 OPUS_OPTIONS="--disable-shared --disable-doc" 521 fi 522 if [[ $OS_IS_LOONGARCH64 == YES ]]; then 523 OPUS_OPTIONS="$OPUS_OPTIONS --build=loongarch64-unknown-linux-gnu" 524 fi 525 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus/lib/libopus.a ]]; then 526 rm -rf ${SRS_OBJS}/opus && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/ && 527 echo "The opus-1.3.1 is ok." 528 else 529 echo "Building opus-1.3.1." && 530 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/opus && 531 tar xf ${SRS_WORKDIR}/3rdparty/opus-1.3.1.tar.gz -C ${SRS_OBJS}/${SRS_PLATFORM} && 532 ( 533 # Opus requires automake 1.15, and fails for automake 1.16+, so we run autoreconf to fix it. 534 cd ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && autoreconf && 535 ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/opus --enable-static $OPUS_OPTIONS 536 ) && 537 make -C ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 ${SRS_JOBS} && 538 make -C ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 install && 539 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/ && 540 echo "The opus-1.3.1 is ok." 541 fi 542 if [ ! -f ${SRS_OBJS}/opus/lib/libopus.a ]; then echo "Build opus-1.3.1 failed."; exit -1; fi 543 fi 544 545 ##################################################################################### 546 # ffmpeg-fit, for WebRTC to transcode AAC with Opus. 547 ##################################################################################### 548 if [[ $SRS_FFMPEG_FIT == YES && $SRS_USE_SYS_FFMPEG == YES ]]; then 549 echo "Warning: Use system ffmpeg, without compiling ffmpeg." 550 fi 551 if [[ $SRS_FFMPEG_FIT == YES && $SRS_USE_SYS_FFMPEG == NO ]]; then 552 FFMPEG_CONFIGURE="env SRS_FFMPEG_FIT=on" 553 if [[ $SRS_FFMPEG_OPUS != YES ]]; then 554 FFMPEG_CONFIGURE="$FFMPEG_CONFIGURE PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/opus/lib/pkgconfig" 555 fi 556 FFMPEG_CONFIGURE="$FFMPEG_CONFIGURE ./configure" 557 558 # Disable all features, note that there are still some options need to be disabled. 559 FFMPEG_OPTIONS="--disable-everything" 560 # Disable all asm for FFmpeg, to compatible with ARM CPU. 561 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-asm --disable-x86asm --disable-inline-asm" 562 # Only build static libraries if no shared FFmpeg. 563 if [[ $SRS_SHARED_FFMPEG == YES ]]; then 564 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-shared" 565 fi 566 # For loongson/mips64, disable mips64r6, or build failed. 567 if [[ $OS_IS_MIPS64 == YES && $OS_IS_LOONGSON == YES ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-mips64r6"; fi 568 # For cross-build. 569 if [[ $SRS_CROSS_BUILD == YES ]]; then 570 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-cross-compile --target-os=linux --disable-pthreads" 571 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --arch=$SRS_CROSS_BUILD_ARCH"; 572 if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cpu=$SRS_CROSS_BUILD_CPU"; fi 573 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cross-prefix=$SRS_CROSS_BUILD_PREFIX" 574 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cc=${SRS_TOOL_CC} --cxx=${SRS_TOOL_CXX} --ar=${SRS_TOOL_AR} --ld=${SRS_TOOL_LD}" 575 fi 576 # For audio codec opus, use FFmpeg native one, or external libopus. 577 if [[ $SRS_FFMPEG_OPUS == YES ]]; then 578 # TODO: FIXME: Note that the audio might be corrupted, see https://github.com/ossrs/srs/issues/3140 579 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=opus --enable-encoder=opus" 580 else 581 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus" 582 fi 583 # Disable features of ffmpeg. 584 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-avdevice --disable-avformat --disable-swscale --disable-postproc --disable-avfilter --disable-network" 585 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-dwt --disable-error-resilience --disable-lsp --disable-lzo --disable-faan --disable-pixelutils" 586 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-hwaccels --disable-devices --disable-audiotoolbox --disable-videotoolbox --disable-cuvid" 587 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-d3d11va --disable-dxva2 --disable-ffnvcodec --disable-nvdec --disable-nvenc --disable-v4l2-m2m --disable-vaapi" 588 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-vdpau --disable-appkit --disable-coreimage --disable-avfoundation --disable-securetransport --disable-iconv" 589 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-lzma --disable-sdl2" 590 # Enable FFmpeg native AAC encoder and decoder. 591 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm --enable-encoder=aac" 592 # Enable FFmpeg native MP3 decoder, which depends on dct. 593 FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=mp3 --enable-dct" 594 595 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg/lib/libavcodec.a ]]; then 596 rm -rf ${SRS_OBJS}/ffmpeg && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg ${SRS_OBJS}/ && 597 echo "The ffmpeg-4-fit is ok." 598 else 599 echo "Building ffmpeg-4-fit." && 600 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg \ 601 ${SRS_OBJS}/ffmpeg && 602 cp -rf ${SRS_WORKDIR}/3rdparty/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && 603 ( 604 cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && 605 $FFMPEG_CONFIGURE --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/ffmpeg \ 606 --pkg-config=pkg-config --pkg-config-flags='--static' --extra-libs='-lpthread' --extra-libs='-lm' \ 607 ${FFMPEG_OPTIONS} 608 ) && 609 # See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/ 610 if [[ $SRS_CROSS_BUILD == YES ]]; then 611 sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 612 sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 613 sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 614 # For MIPS, which fail with: 615 # ./libavutil/libm.h:54:32: error: static declaration of 'cbrt' follows non-static declaration 616 # /root/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/include/math.h:163:13: note: previous declaration of 'cbrt' was here 617 if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" || $SRS_CROSS_BUILD_ARCH == "arm" || $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then 618 sed -i -e 's/#define HAVE_CBRT 0/#define HAVE_CBRT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 619 sed -i -e 's/#define HAVE_CBRTF 0/#define HAVE_CBRTF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 620 sed -i -e 's/#define HAVE_COPYSIGN 0/#define HAVE_COPYSIGN 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 621 sed -i -e 's/#define HAVE_ERF 0/#define HAVE_ERF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 622 sed -i -e 's/#define HAVE_HYPOT 0/#define HAVE_HYPOT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 623 sed -i -e 's/#define HAVE_RINT 0/#define HAVE_RINT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 624 sed -i -e 's/#define HAVE_LRINT 0/#define HAVE_LRINT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 625 sed -i -e 's/#define HAVE_LRINTF 0/#define HAVE_LRINTF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 626 sed -i -e 's/#define HAVE_ROUND 0/#define HAVE_ROUND 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 627 sed -i -e 's/#define HAVE_ROUNDF 0/#define HAVE_ROUNDF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 628 sed -i -e 's/#define HAVE_TRUNC 0/#define HAVE_TRUNC 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 629 sed -i -e 's/#define HAVE_TRUNCF 0/#define HAVE_TRUNCF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h && 630 echo "FFmpeg sed ok" 631 fi 632 fi && 633 make -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit ${SRS_JOBS} && 634 make -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit install && 635 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg ${SRS_OBJS}/ && 636 echo "The ffmpeg-4-fit is ok." 637 fi 638 # check status 639 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build ffmpeg-4-fit failed, ret=$ret"; exit $ret; fi 640 fi 641 642 ##################################################################################### 643 # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2. 644 ##################################################################################### 645 # Guess where is the ffmpeg. 646 SYSTEMP_FFMPEG_BIN=`which ffmpeg` 647 # Always link the ffmpeg tools if exists. 648 if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then 649 mkdir -p ${SRS_OBJS}/ffmpeg/bin && 650 cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ 651 fi 652 if [[ $SRS_FFMPEG_TOOL == YES ]]; then 653 if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then 654 cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ && 655 echo "ffmpeg-4.1 is ok."; 656 else 657 echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}" 658 echo -e "${RED} Please copy it from srs-docker${BLACK}" 659 echo -e "${RED} or download from http://ffmpeg.org/download.html${BLACK}" 660 echo -e "${RED} or disable it by --without-ffmpeg${BLACK}" 661 exit -1; 662 fi 663 fi 664 665 ##################################################################################### 666 # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119 667 ##################################################################################### 668 if [[ $SRS_SRT == YES && $SRS_USE_SYS_SRT == YES ]]; then 669 echo "Warning: Use system libsrt, without compiling srt." 670 fi 671 if [[ $SRS_SRT == YES && $SRS_USE_SYS_SRT == NO ]]; then 672 # Always disable c++11 for libsrt, because only the srt-app requres it. 673 LIBSRT_OPTIONS="--enable-apps=0 --enable-static=1 --enable-c++11=0" 674 if [[ $SRS_SHARED_SRT == YES ]]; then 675 LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=1" 676 else 677 LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0" 678 fi 679 # For windows build, over cygwin 680 if [[ $SRS_CYGWIN64 == YES ]]; then 681 LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix" 682 fi 683 # For cross-build. 684 if [[ $SRS_CROSS_BUILD == YES ]]; then 685 TOOL_GCC_REALPATH=$(realpath $(which $SRS_TOOL_CC)) 686 SRT_COMPILER_PREFIX=$(echo $TOOL_GCC_REALPATH |sed 's/-gcc.*$/-/') 687 LIBSRT_OPTIONS="$LIBSRT_OPTIONS --with-compiler-prefix=$SRT_COMPILER_PREFIX" 688 fi 689 690 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib/libsrt.a ]]; then 691 rm -rf ${SRS_OBJS}/srt && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt ${SRS_OBJS}/ && 692 echo "libsrt-1-fit is ok." 693 else 694 if [[ $SRS_USE_SYS_SSL != YES && ! -d ${SRS_OBJS}/openssl/lib/pkgconfig ]]; then 695 echo "OpenSSL pkgconfig no found, build srt-1-fit failed." 696 exit -1 697 fi 698 echo "Build srt-1-fit" && 699 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt ${SRS_OBJS}/srt && 700 cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && 701 patch -p0 -R ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit/srtcore/api.cpp ${SRS_WORKDIR}/3rdparty/patches/srt/api.cpp-01.patch && 702 ( 703 cd ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && 704 env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/openssl/lib/pkgconfig \ 705 ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/srt $LIBSRT_OPTIONS 706 ) && 707 make -C ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit ${SRS_JOBS} && 708 make -C ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit install && 709 # If exists lib64 of libsrt, copy it to lib 710 if [[ -d ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib64 ]]; then 711 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib64 ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib 712 fi && 713 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt ${SRS_OBJS}/ && 714 echo "libsrt-1-fit is ok." 715 fi 716 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi 717 fi 718 719 ##################################################################################### 720 # build utest code 721 ##################################################################################### 722 if [[ $SRS_UTEST == YES ]]; then 723 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest/googletest/include/gtest/gtest.h ]]; then 724 rm -rf ${SRS_OBJS}/gtest && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest ${SRS_OBJS}/ && 725 echo "The gtest-fit is ok." 726 else 727 echo "Build gtest-fit" && 728 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}gtest-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest ${SRS_OBJS}/gtest && 729 cp -rf ${SRS_WORKDIR}/3rdparty/gtest-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest && 730 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest ${SRS_OBJS}/ && 731 echo "The gtest-fit is ok." 732 fi 733 # check status 734 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi 735 fi 736 737 ##################################################################################### 738 # build gperf code 739 ##################################################################################### 740 if [[ $SRS_GPERF == YES ]]; then 741 if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf/bin/pprof ]]; then 742 rm -rf ${SRS_OBJS}/gperf && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf ${SRS_OBJS}/ && 743 cp -f ${SRS_OBJS}/gperf/bin/pprof ${SRS_OBJS}/ && 744 echo "The gperftools-2-fit is ok." 745 else 746 echo "Build gperftools-2-fit" && 747 rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf \ 748 ${SRS_OBJS}/gperf ${SRS_OBJS}/pprof && 749 cp -rf ${SRS_WORKDIR}/3rdparty/gperftools-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ && 750 ( 751 cd ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit && 752 ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/gperf --enable-frame-pointers 753 ) && 754 make -C ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit ${SRS_JOBS} && 755 make -C ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit install && 756 cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf ${SRS_OBJS}/ && 757 cp -f ${SRS_OBJS}/gperf/bin/pprof ${SRS_OBJS}/ && 758 echo "The gperftools-2-fit is ok." 759 fi 760 # check status 761 ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gperftools-2-fit failed, ret=$ret"; exit $ret; fi 762 fi 分析一下这个脚本都是什么功能 如果我想新增一个能编译app/srs_app_jwt.cpp的功能怎么添加,请帮我添加
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值