You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WebRTC自定义C++应用SDP异常:网页端无法播放视频流排查

WebRTC视频流播放故障排查

提供的SDP信息

Offer SDP

v=0
o=- 7218303015490137756 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0 1
a=extmap-allow-mixed
a=msid-semantic: WMS
m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:nKYe
a=ice-pwd:6Zxgc+gxTwxd3ap5I/sOdcPu
a=ice-options:trickle
a=fingerprint:sha-256 DD:C2:BC:0F:E8:05:65:2F:20:72:82:20:04:50:5A:7F:9B:DF:60:50:73:C4:E8:5D:37:55:C4:1F:4D:3B:DC:13
a=setup:actpass
a=mid:0
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=recvonly
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:63 red/48000/2
a=fmtp:63 111/111
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:126 telephone-event/8000
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 35 36 37 38 102 103 104 105 106 107 108 109 127 125 39 40 41 42 43 44 45 46 47 48 112 113 114 115 116 117 118 49
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:nKYe
a=ice-pwd:6Zxgc+gxTwxd3ap5I/sOdcPu
a=ice-options:trickle
a=fingerprint:sha-256 DD:C2:BC:0F:E8:05:65:2F:20:72:82:20:04:50:5A:7F:9B:DF:60:50:73:C4:E8:5D:37:55:C4:1F:4D:3B:DC:13
a=setup:actpass
a=mid:1
a=extmap:14 urn:ietf:params:rtp-hdrext:toffset
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
......

应答SDP

v=0
o=- 7218303015490137756 2 IN IP4 192.168.50.119
s=-
t=0 0
a=group:BUNDLE 0 1
a=msid-semantic: WMS
a=ice-lite
m=audio 9 UDP/TLS/RTP/SAVPF 0
c=IN IP4 192.168.50.119
a=ice-ufrag:sh2j
a=ice-pwd:au6tvqpf0igutargfbzq07y4
a=ice-options:trickle
a=fingerprint:sha-256 2B:4C:BA:79:27:69:77:08:16:13:BA:5E:95:98:A6:E0:09:D0:9A:C0:19:FF:8E:27:59:F5:89:E3:80:45:77:A1
a=setup:passive
a=mid:0
a=ice-lite
a=sendonly
a=rtcp-mux
a=rtpmap:0 PCMU/8000/1
a=msid:video-mslabel video-label
a=ssrc:2 cname:video-rtp
a=ssrc:2 msid:video-mslabel video-label
a=ssrc:2 mslabel:video-mslabel
a=ssrc:2 label:video-label
a=candidate:udpcandidate 1 udp 100 192.168.50.119 6000 typ host
m=video 9 UDP/TLS/RTP/SAVPF 102
c=IN IP4 192.168.50.119
a=ice-ufrag:sh2j
a=ice-pwd:au6tvqpf0igutargfbzq07y4
a=ice-options:trickle
a=fingerprint:sha-256 2B:4C:BA:79:27:69:77:08:16:13:BA:5E:95:98:A6:E0:09:D0:9A:C0:19:FF:8E:27:59:F5:89:E3:80:45:77:A1
a=setup:passive
a=mid:1
a=ice-lite
a=sendonly
a=rtcp-mux
a=rtpmap:102 H264/90000
a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
a=msid:video-mslabel video-label
a=ssrc:1 cname:video-rtp
a=ssrc:1 msid:video-mslabel video-label
a=ssrc:1 mslabel:video-mslabel
a=ssrc:1 label:video-label
a=candidate:udpcandidate 1 udp 100 192.168.50.119 6000 typ host

问题解答

RTCP是否必需?

WebRTC规范未强制要求RTCP,但主流浏览器的WebRTC实现高度依赖RTCP的核心功能:比如接收报告确认流的有效性、SSRC同步、时钟校准、丢包统计等。缺失RTCP时,浏览器无法验证媒体流的状态,也无法完成时序同步,基本都会导致播放失败。即使不实现RTX重传,至少需要实现基础的RTCP发送/接收报告,才能让浏览器正常处理媒体流。

其他可能的故障原因

  • RTP包格式与SDP协商不匹配:确认发送的H264 RTP包负载类型是协商好的102;SDP中指定packetization-mode=1,要求发送FU-A分片格式的NALU,若发送完整NALU或错误分片,浏览器无法解析。
  • MSID标识冲突:应答SDP中音频和视频流使用了完全相同的video-mslabel video-label作为MSID,会导致浏览器混淆媒体流类型,音频和视频应分配独立的MSID。
  • RTP时间戳异常:H264的RTP时间戳基于90kHz时钟,每帧的时间戳增量需匹配帧率(比如30帧/秒时,增量应为3000)。时间戳增量错误会导致浏览器无法正确排序和渲染帧。
  • DTLS加密有效性问题:Wireshark抓包需解密DTLS流量才能确认RTP内容是否正确,若加密过程出错,看似发送的数据实际是无效密文,浏览器无法解码。
  • BUNDLE模式处理错误:已启用BUNDLE,音频和视频复用同一UDP端口6000,需确认传输层能正确区分不同mid的RTP流,避免流数据混叠。
  • 缺少关键帧:浏览器需要H264关键帧(I帧)初始化解码上下文,若初始发送的都是P帧/B帧,无法启动解码播放。
  • SDP扩展头缺失:Offer SDP声明了abs-send-time等扩展头,但应答SDP未对应支持,部分浏览器会因缺少这些优化信息而拒绝播放流。

内容的提问来源于stack exchange,提问作者jesseyWang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 10:19:53