webrtc用clang编译支持h264,支持msvc调用库

webrtc遇到困扰:

  • 如果msvc编译,ffmpeg编译失败,需要替换ffmpeg库。
  • 如果用clang编译,vs或qt调用dll又存在崩溃。
    经过反复尝试找到解决方法:

一、编译

1、编译参数

复制代码
//我得环境配置
set DEPOT_TOOLS_UPDATE=0
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_VERSION=2022
set GYP_MSVS_OVERRIDE_PATH =C:\Program Files (x86)\Microsoft Visual Studio 14.0
set GYP_GENERATORS=msvs-ninja,ninja

//x86 release
gn gen out\x86_release_clang --ide=vs2022 --args="use_rtti=true is_debug=false target_cpu=\"x86\" is_component_ffmpeg=true ffmpeg_branding=\"Chrome\" proprietary_codecs=true  rtc_use_h264=true  gtest_enable_absl_printers=false libyuv_include_tests=false  rtc_enable_protobuf=false treat_warnings_as_errors=false use_custom_libcxx=false"

//x86 debug
gn gen out\x86_debug_clang --ide=vs2022 --args="use_rtti=true is_debug=true target_cpu=\"x86\" is_component_ffmpeg=true ffmpeg_branding=\"Chrome\" proprietary_codecs=true  rtc_use_h264=true  gtest_enable_absl_printers=false libyuv_include_tests=false  rtc_enable_protobuf=false treat_warnings_as_errors=false enable_iterator_debugging=true use_custom_libcxx=false rtc_enable_avx2=false"

生成sln后,在vs内编译。

生成jsoncpp,进入到生成目录内

复制代码
lib *.obj /out:jsoncpp.lib

2、编译webrtc,生成libwebrtc库。

2、使用

vs2022 创建dll,举例测试apm:

选llvm,c++17标准

多线程MTD

预处理器这一大堆是比较麻烦的,怎么办?

找到 src\out\x86_debug_clang\obj\pc 下面的peer_connection.vcxproj,用记事本打开,复制

复制代码
<PreprocessorDefinitions>USE_AURA=1;_HAS_NODISCARD;_CRT_NONSTDC_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;CR_CLANG_REVISION=&quot;llvmorg-18-init-4631-gd50b56d1-1&quot;;_HAS_EXCEPTIONS=0;__STD_C;_CRT_RAND_S;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_DEPRECATE;_ATL_NO_OPENGL;_WINDOWS;CERT_CHAIN_PARA_HAS_EXTRA_FIELDS;PSAPI_VERSION=2;WIN32;_SECURE_ATL;WINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP;WIN32_LEAN_AND_MEAN;NOMINMAX;_UNICODE;UNICODE;NTDDI_VERSION=NTDDI_WIN10_NI;_WIN32_WINNT=0x0A00;WINVER=0x0A00;_DEBUG;DYNAMIC_ANNOTATIONS_ENABLED=1;WEBRTC_ENABLE_PROTOBUF=0;WEBRTC_STRICT_FIELD_TRIALS=0;WEBRTC_INCLUDE_INTERNAL_AUDIO_DEVICE;RTC_ENABLE_VP9;RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY;WEBRTC_HAVE_SCTP;WEBRTC_USE_H264;WEBRTC_LIBRARY_IMPL;RTC_ENABLE_WIN_WGC;WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=1;WEBRTC_WIN;ABSL_ALLOCATOR_NOTHROW=1;_ENABLE_EXTENDED_ALIGNED_STORAGE;LIBYUV_DISABLE_NEON;%(PreprocessorDefinitions)</PreprocessorDefinitions>

这个是连接器输入,

  • 比较重要的对clang的附加选项限制

    这个找到 src\out\x86_debug_clang\obj\pc 下面的peer_connection.vcxproj

    复制代码
        <AdditionalOptions>-Wimplicit-fallthrough -Wextra-semi -Wunreachable-code-aggressive -Wthread-safety -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -Wloop-analysis -Wno-unneeded-internal-declaration -Wno-nonportable-include-path -Wenum-compare-conditional -Wno-ignored-pragma-optimize -Wno-deprecated-builtins -Wno-bitfield-constant-conversion -Wno-deprecated-this-capture -Wshadow -fno-delete-null-pointer-checks -fno-ident -fcolor-diagnostics -fmerge-all-constants -fcrash-diagnostics-dir=../../tools/clang/crashreports -mllvm -instcombine-lower-dbg-declare=0 /clang:-ffp-contract=off -fcomplete-member-pointers /Gy /FS /bigobj /utf-8 /Zc:twoPhase -ffile-reproducible /Zc:sizedDealloc- /D__WRL_ENABLE_FUNCTION_STATICS__ -fmsc-version=1934 -m32 -msse3 /Brepro -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -ffile-compilation-dir=. -no-canonical-prefixes /std:c11 -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare /std:c++17 -Wno-trigraphs -ftrivial-auto-var-init=pattern /Ob0 /GF /Z7 -gno-codeview-command-line -gcodeview-ghash -Xclang -fuse-ctor-homing /guard:cf,nochecks -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wexit-time-destructors -Wglobal-constructors -Wno-shadow -Wctad-maybe-unsupported -Wc++11-narrowing -Wundef -Wunused-lambda-capture %(AdditionalOptions)</AdditionalOptions>

在这里面封装好的库,就可以在msvc里调用了。

如果还有问题,可能是llvm的版本有问题,需要在dll工程的同目录下创建Directory.build.props 文件,记事本打开编辑

复制代码
<Project>
  <PropertyGroup>
    <LLVMInstallDir>G:\webrtc20230919\src\third_party\llvm-build\Release+Asserts</LLVMInstallDir>
    <LLVMToolsVersion>18</LLVMToolsVersion>
  </PropertyGroup>
</Project>

这里是指定llvm应用版本,制定的和webrtc用同一个。

相关推荐
2501_915374356 天前
WebRTC与RTMP
webrtc
_pengliang6 天前
WebRTC 双向视频通话
音视频·webrtc
~央千澈~6 天前
优雅草蜻蜓R实时音视频会议系统云原生私有化部署方案深度解析-优雅草卓伊凡|贝贝|clam|麻子|夜辰
webrtc·实时音视频
~央千澈~9 天前
优雅草蜻蜓T语音会议系统私有化部署方案与RTC技术深度解析-优雅草卓伊凡|clam
webrtc·实时音视频·rtc
old-six-programmer10 天前
NAT 类型及 P2P 穿透
服务器·网络协议·webrtc·p2p·nat
大胡子大叔11 天前
webrtc-streamer视频流播放(rstp协议h264笔记)
笔记·webrtc·rtsp·webrtc-streamer
_可乐无糖11 天前
AWS WebRTC: 判断viewer端拉流是否稳定的算法
linux·服务器·webrtc·aws
却道天凉_好个秋11 天前
WebRTC(十三):信令服务器
webrtc
却道天凉_好个秋21 天前
WebRTC(七):媒体能力协商
webrtc
GetcharZp25 天前
告别“只闻其名”!一文带你深入浅出 WebRTC,并用 Go 搭建你的第一个实时应用
后端·webrtc