折腾了不少时间,才成功部署webrtc win10的单步调试环境,记录此文章帮助理解记忆,也备着再次需要用到。
一,环境准备工作
参考链接:
https://chromium.googlesource.com/chromium/src/+/master/docs/windows_build_instructions.md
https://github.com/open-webrtc-toolkit/owt-client-native
1.1,设置代理,
set http_proxy=http://127.0.0.1:7078
set https_proxy=http://127.0.0.1:7078
netsh winhttp set proxy proxy-server="http=127.0.0.1:7078"
git config --global user.name "yourname"
git config --global user.email "youremail"
git config --global core.autocrlf false
git config --global core.filemode false
//编辑并保存 d:\git\boto.cfg
[Boto]
proxy = 127.0.0.1
proxy_port = 7078
https_validate_certificate = True
1.2,下载安装 depot_tools
https://storage.googleapis.com/chrome-infra/depot_tools.zip
添加环境变量:
Control Panel → System and Security → System → Search for “Edit environment variables for your account”
DEPOT_TOOLS_WIN_TOOLCHAIN 0
NO_AUTH_BOTO_CONFIG d:\git\Boto.cfg
Path 添加:d:\git\depot_tools,并移动到最前面
// 确认depot_tools在最前面
C:\>where python
C:\git\depot_tools\python.bat
C:\Users\fang\AppData\Local\Microsoft\WindowsApps\python.exe
//更新gclient
gclient.bat
Note: 使用Power shell遇到问题;再次以管理员启动CMD 命令行,下载成功
1.3,安装visusl studio 2019
$ PATH_TO_INSTALLER.EXE ^
--add Microsoft.VisualStudio.Workload.NativeDesktop ^
--add Microsoft.VisualStudio.Component.VC.ATLMFC ^
--includeRecommended
NOTE: 经测试visual studio 2022也能编译调试本文的所以项目代码。推荐使用 visul studio 2022。需要将本文所有的2019变量替换成2022;
1.4,安装Windows 10 SDK 10.0.20348.0
Windows 10 SDK 需要安装有SDK Debugging Tools;
Control Panel → Programs → Programs and Features → Select the “Windows Software Development Kit” → Change → Change → Check “Debugging Tools For Windows” → Change. Or, you can download the standalone SDK installer and use it to install the Debugging Tools.
1.5, 下载编译OpenSSL 1.1.1k or higher
1.5.1 安装perl
https://strawberryperl.com/download/5.32.1.1/strawberry-perl-5.32.1.1-64bit.msi
1.5.2 安装NASM
https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-installer-x64.exe
1.5.3 下载编译 openssl
https://www.openssl.org/source/openssl-1.1.1o.tar.gz
打开vs 命令窗口; (开始菜单=> x64 Native Tools Command Prompt for VS 2019),截图如下
//生成配置
perl Configure VC-WIN64A no-asm --prefix=d:\git\libs\openssl1.1.1\x64
//使用nmake进行编译、安装,依次执行以下命令
nmake
nmake install
参考链接:Window下Openssl 编译过程_clzdl的博客-CSDN博客_windows编译openssl
添加环境变量:
OPENSSL_HOME D:\git\libs\openssl1.1.1\x64\bin
OPENSSL_ROOT_DIR D:\git\libs\openssl1.1.1\x64
1.6,下载安装 Intel Media SDK for Windows, version 2020 R1 or higher.
https://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/17861/MSDK2021R1.exe
1.7,配置环境变量
添加环境变量:
GYP_GENERATORS msvs-ninja,ninja
GYP_MSVS_VERSION 2019
GYP_MSVS_OVERRIDE_PATH C:\Program Files\Microsoft Visual Studio\2019\Community
NOTE: 有些环境变量,在第2步就需要用到
二,下载编译owt-client-native
2.1, 下载源码
Create a file named .gclient in the directory above the src dir, with these contents:
solutions = [
{
"managed": False,
"name": "src",
"url": "https://github.com/open-webrtc-toolkit/owt-client-native.git",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
},
]
target_os = []
gclient sync --no-history
NOTE: 使用PowerShell下载失败,换成cmd再次下载成
2.3.2,编译
修改脚本,生成visual studio .sln文件;
diff --git a/scripts/build-win.py b/scripts/build-win.py
- ret = subprocess.call(['gn.bat', 'gen', getoutputpath(arch, scheme), '--args=%s' % flattened_args],
+ ret = subprocess.call(['gn.bat', 'gen', getoutputpath(arch, scheme), '--args=%s ' % flattened_args,'--ide=vs'],
编译(有msdk):
python build-win.py --gn_gen --sdk --arch x64 --scheme debug --ssl_root C:\libs\openssl1.1.1\x64 --msdk_root C:\IntelSWTools\IntelMediaSDK2021R1\SoftwareDevelopmentKit --output_path C:\git\webrtc\src\out\liball
编译成功的输出文件:
C:\git\webrtc\src\out\liball\libs\owt-debug.lib
三,下载编译CS_WebRTC_Client_SDK_Windows.v5.0
3.1,下载地址
https://registrationcenter-download.intel.com/akdlm/irc_nas/18070/Intel_CS_WebRTC.v5.0.zip
解压出CS_WebRTC_Client_SDK_Windows.v5.0.zip, 这是OWT 的MFC sample client.
3.2, 编译socket.io-client-cpp
目录:C:\git\CS_WebRTC_Client_SDK_Windows.v5.0\samples\ConfSampleMFC\ConfSampleMFC\deps
//设置 OPENSSL 目录
set OPENSSL_HOME=D:\lib\OpenSSL-Win64\bin
set OPENSSL_ROOT_DIR=D:\lib\OpenSSL-Win64
//设置Proxy
set http_proxy=http://127.0.0.1:7078
set https_proxy=http://127.0.0.1:7078
netsh winhttp set proxy proxy-server="http=127.0.0.1:7078"
//下载socket.io-client-cpp
git clone --recurse-submodules https://github.com/socketio/socket.io-client-cpp.git
//编译
cmake ./
会在这里产生vs2019版本的 sln
Note: sioclient和sioclient_tls项目,运行库需要设置成MT/MTd, 才能与后面MFC的示例一致。
注意不要直接打开。而是要在开始菜单,找到vs2019的图标,右键,"更多"-> "以管理员身份运行" (否则会在INSTALL时报错 setlocal,没有管理员权限就不能在C盘创建文件夹)
然后再选这个sln,选择,release x64 ,在项目管理器里先生成 ALL_BUILD 再 INSTAL
头文件目录:socket.io-client-cpp\src;lib目录:socket.io-client-cpp\Debug\sioclient.lib
3.3, boost 下载编译
测试发现,OWT原有的Index of main/release/1.67.0/source,使用vs 2019总是编译不出来,换成vs2017才编译成功;
vs2019可以编译:Index of main/release/1.79.0/source,需要测试确认OWT是否兼容不同boost版本;
//生成配置
cd C:\git\OWT_Client_Windows\samples\ConfSampleMFC\ConfSampleMFC\deps\boost_1_79_0
bootstrap.bat --with-libraries=date_time,system,random,regex
//执行编译
b2 --build-dir=build/x64 --build_type=complete --stagedir=./stage --with-date_time --with-system --with-random --with-regex address-model=64 threading=multi toolset=msvc-14.1 link=static architecture=x86 runtime-link=static stage
// lib输出目录:deps\boost_1_79_0\stage\lib, 头文件目录:deps\boost_1_79_0\
3.4,复制依赖库到deps目录
3.5, 为项目配置目录,编译ConfSampleMFC.sln
调整包含目录和库目录,为实际目录; ConfSampleMFC就可以编译出来了。
遇到问题1:
1>------ 已启动生成: 项目: ConfSampleMFC, 配置: Debug x64 ------
1>owt-debug.lib(videorendererd3d11.obj) : error LNK2019: 无法解析的外部符号 DCompositionCreateDevice2,函数 "private: bool __cdecl owt::base::WebrtcVideoRendererD3D11Impl::InitMPO(int,int)" (?InitMPO@WebrtcVideoRendererD3D11Impl@base@owt@@AEAA_NHH@Z) 中引用了该符号
1>owt-debug.lib(videorendererd3d11.obj) : error LNK2019: 无法解析的外部符号 DCompositionCreateSurfaceHandle,函数 "private: bool __cdecl owt::base::WebrtcVideoRendererD3D11Impl::InitMPO(int,int)" (?InitMPO@WebrtcVideoRendererD3D11Impl@base@owt@@AEAA_NHH@Z) 中引用了该符号
1>D:\git\owt-native\src\out\debug-x64\x64\Debug\ConfSampleMFC.exe : fatal error LNK1120: 2 个无法解析的外部命令
1>已完成生成项目“ConfSampleMFC.vcxproj”的操作 - 失败。
========== “生成”: 0 成功,1 失败,0 更新,0 已跳过 ==========
解决方法:
需要添加一个lib: dcomp.lib, 见下图
遇到问题2:
解决办法:拷贝对应的DLL到.vcxproj目录
Note: 在VS2019可以按下图设置运行目录,找到DLL;发现vs 2022设置无效,只能拷贝DLL到项目目录
四,安装运行OWT server
参考链接:GitHub - winlinvip/owt-docker: Docker for https://github.com/open-webrtc-toolkit/owt-server
4.1安装docker
4.2运行 owt docker
//查看主机的IP
ipconfig
IPv4 地址 . . . . . . . . . . . . : 192.168.1.102
//需要将本机的实际IP,传给docker,客户端才能连接到此IP
set HostIP=192.168.1.102
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --privileged --env DOCKER_HOST=%HostIP% -v d:\\git\\owt-server:/tmp/git/owt-server -p 4000:4000 -p 8080:8080 -p 3000-3004:3000-3004 -p 3300:3300 -p 27017:27017 -p 5672:5672 -p 15672:15672 -p 12345:12345 -p 60000-60050:60000-60050/udp -it openvisualcloud/xeon-ubuntu1804-service-owt-dev /bin/bash
root@daa99f8bf2d6:/home# echo $DOCKER_HOST
192.168.1.102
root@daa99f8bf2d6:/home# apt update
root@daa99f8bf2d6:/home# apt install vim
Note:使用power shell 设置环境变量失败,需要使用cmd
4.3 修改owt以适应docker 运行环境
root@daa99f8bf2d6:/home#vi owt/webrtc_agent/agent.toml
- network_interfaces = [] # default: []
+ network_interfaces = [{name="eth0",replaced_ip_address="$DOCKER_HOST"}] # default: []
keystorePath = "./cert/certificate.pfx"
#note, this won't work with all versions of libnice. With 0 all the available ports are used
# The webrtc port range
- maxport = 0 #default: 0
- minport = 0 #default: 0
+ maxport = 60050 #default: 0
+ minport = 60000 #default: 0
root@daa99f8bf2d6:/home# vi owt/portal/portal.toml
[portal]
keystorePath = "./cert/certificate.pfx"
hostname = "" #default: ""
- ip_address = "" #default: ""
+ ip_address = "$DOCKER_HOST" #default: ""
4.4 运行owt server
root@daa99f8bf2d6:/home# ./launch.sh
第一次需要先访问信令(Portal):
https://192.168.1.102:8080/socket.io/?EIO=3&transport=polling&t=N2UmsIn
使用chrome浏览器,测试OWT演示页面:
https://192.168.1.102:3004
五,混合单步调试ConfSampleMFC、OWT native和 WebRTC
5.1, 打开 all.sln
用visual studio 2019,打开第二步输出的all.sln
5.2, 添加ConfSampleMFC.vcxproj
右键点击“解决方案”,添加->现有项,选择ConfSampleMFC.vcxproj
5.3, 编译 ConfSampleMFC.vcxproj
设置ConfSampleMFC.vcxproj为启动项,可以断点调试ConfSampleMFC、OWT native和WebRTC内源码;
NOTE: 在visual studio 2019编译all.sln, 遇到38个错误,最后不要使用VS来编译(使用python build-win.py编译成功);还是能正常调试ConfSampleMFC.vcxproj