创建RtcEventLog 数据捕获RtcEventLog接口。通过该接口可以实时捕获进出webrtc的RTP报文头数据、音视频配置参数、webrtc的探测数据
默认是的RtcEventLog是空的,如果要记录打印关于rtp报文的配置要在gn gen脚本执行的时候 开启 rtc_enable_protobuf 这里详见 src/build.gn脚本的364行可知:
if (rtc_enable_protobuf) {
defines += [ "ENABLE_RTC_EVENT_LOG" ]
deps += [ "logging:rtc_event_log_proto" ]
}
在代码工程里是:logging tc_event_log tc_event_log.cc
// RtcEventLog member functions.
std::unique_ptr<RtcEventLog> RtcEventLog::Create(EncodingType encoding_type) {
#ifdef ENABLE_RTC_EVENT_LOG
// TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|.
constexpr int kMaxLogCount = 5;
int count = 1 + std::atomic_fetch_add(&rtc_event_log_count, 1);
if (count > kMaxLogCount) {
RTC_LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. "
<< count - 1 << " logs open already.";
std::atomic_fetch_sub(&rtc_event_log_count, 1);
return CreateNull();
}
auto encoder = CreateEncoder(encoding_type);
return rtc::MakeUnique<RtcEventLogImpl>(std::move(encoder));
#else
return CreateNull();
#endif // ENABLE_RTC_EVENT_LOG
}
std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() {
return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
}
}
- 1)数据存储接口及实现文件
rtc_event_log.cc
rtc_event_log.h
rtc_event_log.proto
rtc_event_log_factory.cc
rtc_event_log_factory.h
rtc_event_log_factory_interface.h
rtc_event_log.proto为数据存储格式接口,我们可以根据项目需要,在rtc_event_log.proto里面增加本项目私有接口。
- 2)数据解析工具实现文件
rtc_event_log2rtp_dump.cc
rtc_event_log2stats.cc
rtc_event_log2text.cc
rtc_event_log_parser.cc
rtc_event_log_parser.h
使用内部调试工具,开启rtc_enable_protobuf=true rtc_include_tests=true后,生成一个rtc_event_log2rtp_dump.exe文件。可以将捕获数据中的RTP报文头信息打印出来。
要想生成rtc_event_log2stats.exe/rtc_event_log2text需要修改/src/webrtc/BUILD.gn和/src/webrtc/logging/BUILD.gn两处Makefile文件。修改方式参考生成rtc_event_log2rtp_dump.exe,未实际用过。
工具使用:
1、rtc_event_log2rtp_dump.exe
工具可以将捕获的dump文件中的RTP数据提取出来,但是提取后的数据还是以protobuf存储
命令行:rtc_event_log2rtp_dump test.rtp output.rtp
//output.rtp 就是程序启动以后抓取出来的文件
// test.rtp 是转成protobuf存储
2、rtp_analyze.exe
该工具可以将以protobuf格式存储的RTP数据,打印成文本格式。
命令行是: rtp_analyze test.txt test/rtp
解析结果:

这个和wireshark抓包的内容是一样的,包含 时间戳 包大小 ssrc