|
本帖最后由 ancientcc 于 2017-7-16 14:48 编辑
为什么要把openh264链入Visual Studio
openh264功能丰富,这里只链入webrtc需要的模块:Windows上的H264编码。webrtc框架处理H264时,iOS、Android都是用硬编码、硬解码,因而不须要openh264,至于Windows平台是openh264编码,ffmpeg解码。
openh264代码量大,既然只要H264编码,那就要做到只编译这一部分源码。
webrtc中的openh264
相比于openh264官方是供的源码包,webrtc源包码中包括了google特有的*.gn编译。通过看*.gn相关文件就能知道怎么编写*.sln了。
只须要编码模块,openh264.def移除WelsCreateSVCDecoder、WelsDestroySVCDecoder。
Visual Studio中yasm的命令行- yasm -Xvc -DX86_32 -DPREFIX -g cv8 -f win32 -I"." -I"$(SolutionDir)../../codec/common/x86" "%(FullPath)" -o $(IntDir)sample_sc.obj
- -DPREFIX:让输出函数的函数名有“_”前缀。
复制代码 asm中实现的输出函数(global修饰)一旦不加“_”,外面的C代码就无法调用这函数,链接时时会出未定义符号错,这里提供个快速判断asm生成的obj是否带“_”的方法。更多这方面细节参数“把ffmpeg链入Visual Studio”。
我是按以下逻辑得出要定义“PREFIX”。以要输出WelsCPUIdVerify为例,它是在cpuid.asm实现,以下是定义语句。
- <openh264>/codec/common/x86/cpuid.asm
- WELS_EXTERN WelsCPUIdVerify
- <openh264>/codec/common/x86/asm_inc.asm
- %macro WELS_EXTERN 1
- ALIGN 16, nop
- %ifdef PREFIX
- global _%1
- %define %1 _%1
- %else
- global %1
- %endif
- %1:
- %endmacro
复制代码 按WELS_EXTERN定义,只有定义了“PREFIX”才会增加向函数增加“_”。但让我感到奇怪,BUILD.gn中对x86是不定义PREFIX!
- <openh264>/BUILD.gn
- yasm_assemble("openh264_common_yasm") {
- include_dirs = openh264_common_include_dirs
- sources = openh264_common_sources_asm_x86
- if (target_cpu == "x86") {
- defines = [ "X86_32" ]
- } else { # x64
- if (is_mac) {
- defines = [
- "PREFIX",
- "UNIX64",
- ]
- } else if (is_win) {
- defines = [ "WIN64" ]
- } else if (is_linux) {
- defines = [ "UNIX64" ]
- }
- }
- }
复制代码 只有iOS、Mac OS X才定义“PREFIX”。——但不定义“PREFIX”会出链接时不能找到函数错误。 |
|