fix(webrtc): fix GStreamer WHEP interop (#4720)

## Summary

This PR fixes GStreamer interoperability issues during WebRTC/WHEP
negotiation with ZLMediaServer.

GStreamer could fail to establish the connection for two separate
reasons:

1. ZLMediaServer generated a non-compliant ICE `ufrag`. The generated
value contained `_`, which is not a valid ICE character, so GStreamer
rejected the SDP.
2. ZLMediaServer did not correctly handle `bundle-only` offers and could
answer an accepted bundled m-line with `port=0`, which caused the later
WHEP negotiation to fail.

## Changes

- Generate ICE `ufrag` values using ICE-compliant characters only.
- Preserve and handle `a=bundle-only` correctly during SDP parsing and
answer generation.
- Return `port=9` instead of `port=0` for accepted bundled m-lines.
- Add regression coverage for `bundle-only` SDP handling.
- URL-encode `delete_webrtc` query parameters in the returned `Location`
header so ICE-safe identifiers remain round-trippable over HTTP.

## Validation

- Built with WebRTC and SCTP enabled.
- Added regression test: `test_webrtc_regression`
- Verified:
  - ICE-safe identifier round-trip through `delete_webrtc`
  - `bundle-only` SDP answer generation
This commit is contained in:
Miau Lightouch
2026-04-21 11:37:08 +08:00
committed by GitHub
parent 56f2cfba7c
commit a9e0e1a81e
6 changed files with 165 additions and 27 deletions

View File

@@ -137,7 +137,12 @@ static std::string getServerPrefix() {
// 拷贝tcp端口 [AUTO-TRANSLATED:23191878]
// Copy tcp port
memcpy(buf + 6, &(reinterpret_cast<sockaddr_in *>(&addr)->sin_port), 2);
auto ret = encodeBase64(string(buf, 8)) + '_';
// RFC 5245 §15.4: ice-char = ALPHA / DIGIT / "+" / "/"
auto ret = encodeBase64(string(buf, 8));
// Remove base64 '=' padding (not a valid ice-char)
ret.erase(std::remove(ret.begin(), ret.end(), '='), ret.end());
// Use '/' separator instead of '_' (not a valid ice-char)
ret += '/';
InfoL << "MediaServer(" << host << ":" << udp_port << ":" << tcp_port << ") prefix: " << ret;
return ret;
}