v2: InstanceV2CompatImpl matches 13.0.0's options and mute, and works with unchanged 8.0.0 clients

14.0.0 parity with 13.0.0:
- network_sctp_t1_init_ms / _t1_cookie_ms / _max_backoff_ms and
  network_signaling_nosctp are read as InstanceV2Impl reads them. Under nosctp
  a 14.0.0 <-> 13.0.0 call never connected (SCTP INITs to a peer without SCTP).
- Mute stops the audio send stream (the sender's encodings[0].active), as
  13.0.0 does and GroupInstanceReferenceImpl was fixed to on 2026-09-15; a
  disabled track alone kept sending zeroed Opus. The state is re-applied after
  every negotiation step: a rollback restores the encodings saved at the first
  SetLocalDescription onto the re-sent offer's new SSRC, which left a callee
  that unmuted between its first offer and a glare silent for the call.

Legacy versions: the signaling framing now follows descriptor.version, as
InstanceV2Impl's does - 7.0.0 encryptRawPacket without gzip; 8.0.0/9.0.0
EncryptedConnection's reliable messages without gzip; both without SCTP; any
other version, 14.0.0 included, keeps 13.0.0's (unlike InstanceV2Impl's map,
whose default is V2). network_kcp_experiment moves any version to V3, as there.
Before this an 8.0.0 client rejected every packet. Messages, channel protocol
and glare rules are 8.0.0's already; its parser is unchanged since it shipped.

Two defects then kept compat+8.0.0 below 8.0.0+8.0.0, both fixed under V2 only:
- EncryptedConnection arms its resend timer only from a packet sent while an
  earlier message is unacknowledged. InstanceV2Impl answers synchronously,
  before the ack packet that arms it; CompatImpl answers from the
  PeerConnection's callbacks, after it, so a lost answer was never resent. A
  service packet after each V2 message now arms the timer.
- An offer sent right behind an answer crossed the 8.0.0 callee's pending
  offer, which it then drops for good. As caller CompatImpl holds its offers
  1 s after each answer (kPostAnswerOfferHoldMs).

Checked and not ported: 11.0.0's DTLS-role backstop (SignalingTranslator pins
setup by role both ways), its AddTrack one-round negotiation ("Do not
implement" here), dev/android's screencast reorder and audioLevelsUpdated.

tools/cli: --version/--version2 "compat:<version>" runs CompatImpl under that
version; --mute-participants/--unmute-after work in p2p, in one schedule with
the camera attachments; p2p reports audio heard and first video per side
(ToneRenderer, FakeVideoSink first-frame time), read before teardown;
run-parity-tests.sh + parity_report.py compare compat+V with V+V.

Measured against today's InstanceV2Impl under 8.0.0 (not a 2022 binary):
no failure without signaling loss in either role; at 30% loss with cameras
mid-call the callee's video is lost in 33/64 with CompatImpl as caller vs
32/64 for 8<->8 (44/64 without the hold), 1/64 as callee. As caller it
connects and gets first media 0.06-0.16 s later at p50 (three PeerConnection
operations to answer). 14.0.0 regression matrix 40/40, nosctp and mtproto
both ways.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
isaacandClaude Opus 5.5 committed 2026-10-27 21:40:42 +04:00
1 parent ea0f24e32f
commit c839645dd1
7 files changed
+533 -74

No files matched your search

+12
View File
@@ -191,6 +191,9 @@ For group-churn: success = all churn cycles complete without crash/hang AND base
- `--reflector-list addr,addr,...` — comma-separated list, one picked at random
- `--version VER` — caller tgcalls protocol version (default: `13.0.0`)
- `--version2 VER` — callee tgcalls protocol version (default: same as `--version`). Enables cross-version interop testing.
Either may be `compat:<version>` (2026-10-27): `InstanceV2CompatImpl` constructed under that call
version, which the version registry cannot give (it maps 7.0.0–13.0.0 to `InstanceV2Impl`), so
`--version compat:8.0.0 --version2 8.0.0` is CompatImpl against an unchanged 8.0.0 peer.
- `--wasm-core PATH` — CLI-only override: run the caller's pump core from a module file instead of the version-derived default (`NONE` forces native). Mainly for variant modules; version `19.0.0` already uses the module embedded in the binary. Exists only because the CLI target defines `TGCALLS_ALLOW_EXTERNAL_WASM_CORE` — the app has no such loader.
- `--wasm-core2 PATH` — same for the callee (defaults to `--wasm-core`; `NONE` forces native)
- `--custom-params JSON` — sets the caller's engine `customParameters` as a JSON object (merged
@@ -274,6 +277,15 @@ For group-churn: success = all churn cycles complete without crash/hang AND base
and the same late unmute with NO prior renegotiation
(`--participants 1 --reference-participants 1 --mute-participants 0 --unmute-after 8`) also passes
either way — which is what pins the cause to the renegotiation rather than to the lateness.
- `--mute-participants` / `--unmute-after` in p2p/reflector mode (2026-10-27): index 0 is the
caller, 1 the callee; the side is muted right after creation and, with `--unmute-after N` (N below
`--duration`), unmuted at N s, which also writes a `tgcalls_cli: unmuting the muted side(s)` line
into the `--log-file`. Nothing is validated; read the log: a muted side's `AudioSendStream::Start`
and `First audio RTP packet sent to pacer` must come after that line. The unmute shares one
schedule with the camera attachments (`--video-late`, `--video-late-caller-ms` /
`--video-late-callee-ms`), which is how a glare is made to roll a muted side's first offer back
(13.0.0 → 14.0.0 with `--delay 0-1200`, caller camera swept over 1000–4000 ms). Added for `InstanceV2CompatImpl`'s mute,
which used to keep the send stream running (see `submodules/TgVoipWebrtc/CLAUDE.md`).
- Every group run also prints `Audio levels heard: X/Y pairs` (every peer must report a real level
for every unmuted sender — a participant who is audible but never reaches the level reports is
the "never shown as speaking" defect) and `Unsignaled audio: N stream(s) (must be 0)` (the engine
+212 -41
View File
@@ -76,6 +76,32 @@
namespace tgcalls {
namespace {
// How signaling is framed on the wire, chosen by the call version exactly as
// InstanceV2Impl chooses it: the peer may be a client of any age that runs
// InstanceV2Impl under the same version, and cannot be changed.
// V1 (7.0.0): encryptRawPacket, no compression, no SCTP.
// V2 (8.0.0, 9.0.0): EncryptedConnection's own reliable messages (seq, acks,
// resends), no compression, no SCTP. 9.0.0 was V3 until 2023-04.
// V3 (12.0.0, 13.0.0, and 14.0.0, this engine's own): gzip, encryptRawPacket,
// over SCTP unless the server sets network_signaling_nosctp.
// Unlike InstanceV2Impl's map, an unknown version is V3, not V2: 14.0.0 must
// keep the framing it has always had.
enum class SignalingProtocolVersion {
V1,
V2,
V3
};
SignalingProtocolVersion signalingProtocolVersion(std::string const &version) {
if (version == "7.0.0") {
return SignalingProtocolVersion::V1;
} else if (version == "8.0.0" || version == "9.0.0") {
return SignalingProtocolVersion::V2;
} else {
return SignalingProtocolVersion::V3;
}
}
static VideoCaptureInterfaceObject *GetVideoCaptureAssumingSameThread(VideoCaptureInterface *videoCapture) {
return videoCapture
? static_cast<VideoCaptureInterfaceImpl*>(videoCapture)->object()->getSyncAssumingSameThread()
@@ -361,6 +387,13 @@ public:
}
}
_signalingProtocolVersion = signalingProtocolVersion(descriptor.version);
// As InstanceV2Impl: the server can move any version to V3, and the peer
// gets the same custom parameters.
if (getCustomParameterBool(_customParameters, "network_kcp_experiment")) {
_signalingProtocolVersion = SignalingProtocolVersion::V3;
}
webrtc::field_trial::InitFieldTrialsFromString(
"WebRTC-DataChannel-Dcsctp/Enabled/"
"WebRTC-Audio-iOS-Holding/Enabled/"
@@ -393,24 +426,58 @@ public:
RTC_DCHECK(_threads->getMediaThread()->IsCurrent());
// Always use SCTP signaling connection (V3 protocol)
_signalingConnection = std::make_unique<SignalingSctpConnection>(
_threads,
[threads = _threads, weak](const std::vector<uint8_t> &data) {
threads->getMediaThread()->PostTask([weak, data] {
const auto strong = weak.lock();
if (!strong) {
return;
}
// Carried as InstanceV2Impl carries it: V3 over SCTP with the server's
// timer overrides, or bare when the server sets network_signaling_nosctp
// (both ends get the same custom parameters, and a 13.0.0 peer under
// nosctp never answers an SCTP INIT); V1 and V2 always bare.
if (_signalingProtocolVersion == SignalingProtocolVersion::V3 && !getCustomParameterBool(_customParameters, "network_signaling_nosctp")) {
SignalingSctpConnection::Options sctpOptions;
if (int v = getCustomParameterInt(_customParameters, "network_sctp_t1_init_ms")) {
sctpOptions.t1InitTimeoutMs = v;
}
if (int v = getCustomParameterInt(_customParameters, "network_sctp_t1_cookie_ms")) {
sctpOptions.t1CookieTimeoutMs = v;
}
if (int v = getCustomParameterInt(_customParameters, "network_sctp_max_backoff_ms")) {
sctpOptions.maxBackoffMs = v;
}
strong->onSignalingData(data);
});
},
[signalingDataEmitted = _signalingDataEmitted](const std::vector<uint8_t> &data) {
signalingDataEmitted(data);
},
_encryptionKey.isOutgoing
);
_signalingConnection = std::make_unique<SignalingSctpConnection>(
_threads,
[threads = _threads, weak](const std::vector<uint8_t> &data) {
threads->getMediaThread()->PostTask([weak, data] {
const auto strong = weak.lock();
if (!strong) {
return;
}
strong->onSignalingData(data);
});
},
[signalingDataEmitted = _signalingDataEmitted](const std::vector<uint8_t> &data) {
signalingDataEmitted(data);
},
_encryptionKey.isOutgoing,
sctpOptions
);
}
if (!_signalingConnection) {
_signalingConnection = std::make_unique<ExternalSignalingConnection>(
[threads = _threads, weak](const std::vector<uint8_t> &data) {
threads->getMediaThread()->PostTask([weak, data] {
const auto strong = weak.lock();
if (!strong) {
return;
}
strong->onSignalingData(data);
});
},
[signalingDataEmitted = _signalingDataEmitted](const std::vector<uint8_t> &data) {
signalingDataEmitted(data);
}
);
}
_signalingConnection->start();
@@ -741,7 +808,7 @@ public:
parameters.encodings[0].max_bitrate_bps = 32 * 1024;
_outgoingAudioTransceiver->sender()->SetParameters(parameters);
_outgoingAudioTrack->set_enabled(true);
applyOutgoingAudioMuteState();
}
}
@@ -800,19 +867,49 @@ public:
RTC_LOG(LS_INFO) << "sendSignalingMessage: " << std::string(data.begin(), data.end());
if (_signalingConnection && _signalingEncryptedConnection) {
// Always V3 protocol: gzip + encryptRawPacket
std::vector<uint8_t> packetData;
if (const auto compressedData = gzipData(data)) {
packetData = std::move(compressedData.value());
} else {
RTC_LOG(LS_ERROR) << "Could not gzip signaling message";
return;
}
switch (_signalingProtocolVersion) {
case SignalingProtocolVersion::V1:
case SignalingProtocolVersion::V3: {
std::vector<uint8_t> packetData;
if (_signalingProtocolVersion == SignalingProtocolVersion::V3) {
if (const auto compressedData = gzipData(data)) {
packetData = std::move(compressedData.value());
} else {
RTC_LOG(LS_ERROR) << "Could not gzip signaling message";
return;
}
} else {
packetData = data;
}
if (const auto message = _signalingEncryptedConnection->encryptRawPacket(rtc::CopyOnWriteBuffer(packetData.data(), packetData.size()))) {
_signalingConnection->send(std::vector<uint8_t>(message.value().data(), message.value().data() + message.value().size()));
} else {
RTC_LOG(LS_ERROR) << "Could not encrypt signaling message";
if (const auto message = _signalingEncryptedConnection->encryptRawPacket(rtc::CopyOnWriteBuffer(packetData.data(), packetData.size()))) {
_signalingConnection->send(std::vector<uint8_t>(message.value().data(), message.value().data() + message.value().size()));
} else {
RTC_LOG(LS_ERROR) << "Could not encrypt signaling message";
}
break;
}
case SignalingProtocolVersion::V2: {
// Acknowledged and resent by EncryptedConnection itself (no
// SCTP here); acks and resends leave through
// sendPendingSignalingServiceData.
rtc::CopyOnWriteBuffer message;
message.AppendData(data.data(), data.size());
commitSendSignalingMessage(_signalingEncryptedConnection->prepareForSendingRawMessage(message, true));
// EncryptedConnection arms its resend timer only from a packet
// sent while an earlier message still waits for its ack, so a
// message sent with nothing queued has no timer: if its packet
// is lost, it goes again only when something else is sent.
// InstanceV2Impl never meets this, because it answers
// synchronously, ahead of the ack packet for the offer it
// answers, and that packet arms the timer. Our answers come
// later, from the PeerConnection's callbacks, after the ack:
// a lost answer stayed lost for the rest of the call. A service
// packet now arms the timer (and resends nothing yet).
commitSendSignalingMessage(_signalingEncryptedConnection->prepareForSendingService(0));
break;
}
}
} else {
RTC_LOG(LS_ERROR) << "sendSignalingMessage encryption not available";
@@ -1077,11 +1174,17 @@ public:
// After every SetLocalDescription/SetRemoteDescription: remote messages first,
// then any offer of our own.
void onNegotiationStepCompleted() {
// A rollback restores the audio sender's encodings as they were at its
// first SetLocalDescription, and the next one applies them to a new SSRC
// (the re-sent offer), whatever the mute state is now: a callee unmuted
// between its first offer and a glare stayed silent for the call.
applyOutgoingAudioMuteState();
processPendingRemoteNegotiation();
flushPendingRenegotiation();
}
void scheduleCallerOfferHoldRelease() {
// Ends an offer hold: flushPendingRenegotiation re-checks it after `delayMs`.
void scheduleOfferHoldRelease(int64_t delayMs) {
const auto weak = std::weak_ptr<InstanceV2CompatImplInternal>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask([weak]() {
const auto strong = weak.lock();
@@ -1092,7 +1195,7 @@ public:
return;
}
strong->flushPendingRenegotiation();
}, webrtc::TimeDelta::Millis(kCallerOfferHoldMs + 1));
}, webrtc::TimeDelta::Millis(delayMs));
}
void requestRenegotiation() {
@@ -1145,6 +1248,18 @@ public:
if (_encryptionKey.isOutgoing && !_hasAppliedRemoteOffer && _firstRemoteAnswerTimestamp != 0 && rtc::TimeMillis() < _firstRemoteAnswerTimestamp + kCallerOfferHoldMs) {
return;
}
// Likewise right after every answer of ours, under 8.0.0's framing. A
// 13.0.0-protocol callee keeps its own changes (a camera turned on, say)
// while its offer waits for our answer, and offers them the moment that
// answer lands; an offer of ours sent right behind the answer crosses it,
// and the callee drops its offer for good. Its offer reaches us one round
// trip after our answer (0.2-0.3 s in the CLI), so a short hold lets it in
// first. 8.0.0 resends a lost message only after 3-5 s, so changes pile up
// behind a lost answer of ours and this is common there; InstanceV2Impl
// offers at once and its caller loses the callee's change the same way.
if (_encryptionKey.isOutgoing && _signalingProtocolVersion == SignalingProtocolVersion::V2 && _lastAnswerSentTimestamp != 0 && rtc::TimeMillis() < _lastAnswerSentTimestamp + kPostAnswerOfferHoldMs) {
return;
}
bool needsOffer = _pendingRenegotiation;
// Bounded: a description that keeps failing would otherwise make this an
@@ -1188,6 +1303,8 @@ public:
message.data = _signalingTranslator.makeOffer(description);
} else {
message.data = _signalingTranslator.makeAnswer(description);
_lastAnswerSentTimestamp = rtc::TimeMillis();
scheduleOfferHoldRelease(kPostAnswerOfferHoldMs + 1);
}
sendSignalingMessage(message);
}
@@ -1208,11 +1325,28 @@ public:
void onSignalingData(const std::vector<uint8_t> &data) {
if (_signalingEncryptedConnection) {
// Always V3 protocol: decryptRawPacket
if (const auto message = _signalingEncryptedConnection->decryptRawPacket(rtc::CopyOnWriteBuffer(data.data(), data.size()))) {
processSignalingMessage(message.value());
} else {
RTC_LOG(LS_ERROR) << "receiveSignalingData could not decrypt signaling data";
switch (_signalingProtocolVersion) {
case SignalingProtocolVersion::V1:
case SignalingProtocolVersion::V3: {
if (const auto message = _signalingEncryptedConnection->decryptRawPacket(rtc::CopyOnWriteBuffer(data.data(), data.size()))) {
processSignalingMessage(message.value());
} else {
RTC_LOG(LS_ERROR) << "receiveSignalingData could not decrypt signaling data";
}
break;
}
case SignalingProtocolVersion::V2: {
// One packet carries the message it was sent for plus any
// earlier ones still unacknowledged, in order.
if (const auto packet = _signalingEncryptedConnection->handleIncomingRawPacket((const char *)data.data(), data.size())) {
processSignalingMessage(packet.value().main.message);
for (const auto &additional : packet.value().additional) {
processSignalingMessage(additional.message);
}
}
break;
}
}
} else {
RTC_LOG(LS_ERROR) << "receiveSignalingData encryption not available";
@@ -1398,7 +1532,7 @@ public:
strong->_consecutiveNegotiationFailures = 0;
if (strong->_firstRemoteAnswerTimestamp == 0) {
strong->_firstRemoteAnswerTimestamp = rtc::TimeMillis();
strong->scheduleCallerOfferHoldRelease();
strong->scheduleOfferHoldRelease(kCallerOfferHoldMs + 1);
}
}
} else if (!isOffer) {
@@ -1697,14 +1831,48 @@ public:
if (_isMicrophoneMuted != muteMicrophone) {
_isMicrophoneMuted = muteMicrophone;
if (_outgoingAudioTrack) {
_outgoingAudioTrack->set_enabled(!_isMicrophoneMuted);
}
applyOutgoingAudioMuteState();
sendMediaState();
}
}
// Mute stops the outgoing audio stream, as 13.0.0's does (its
// OutgoingAudioChannel::setIsMuted disables the channel and its send stream).
// A disabled track alone only reaches ChannelSend::SetInputMute, which zeroes
// the samples but keeps encoding and sending a full Opus stream. What starts
// and stops the AudioSendStream is the sender's encodings[0].active
// (WebRtcAudioSendStream::UpdateSendState), with no renegotiation; before the
// first negotiation it lands in the sender's init parameters, so a call that
// starts muted never starts the stream. The same fix GroupInstanceReferenceImpl
// got on 2026-09-15, without its ADM microphone mute, which 13.0.0's 1:1 path
// does not apply either.
void applyOutgoingAudioMuteState() {
const bool isSending = !_isMicrophoneMuted;
if (_outgoingAudioTrack) {
_outgoingAudioTrack->set_enabled(isSending);
}
if (!_outgoingAudioTransceiver) {
return;
}
auto sender = _outgoingAudioTransceiver->sender();
webrtc::RtpParameters parameters = sender->GetParameters();
if (parameters.encodings.empty()) {
RTC_LOG(LS_WARNING) << "InstanceV2CompatImpl: outgoing audio sender has no encodings, cannot apply the mute state";
return;
}
if (parameters.encodings[0].active == isSending) {
return;
}
parameters.encodings[0].active = isSending;
const auto error = sender->SetParameters(parameters);
if (error.ok()) {
RTC_LOG(LS_INFO) << "InstanceV2CompatImpl: outgoing audio active=" << isSending;
} else {
RTC_LOG(LS_WARNING) << "InstanceV2CompatImpl: failed to set outgoing audio active=" << isSending << ": " << error.message();
}
}
void connectIncomingVideoSink(webrtc::scoped_refptr<webrtc::RtpTransceiverInterface> transceiver) {
if (!_currentStrongSink) {
return;
@@ -1901,6 +2069,7 @@ private:
std::function<webrtc::scoped_refptr<WrappedAudioDeviceModule>(webrtc::TaskQueueFactory*)> _createWrappedAudioDeviceModule;
FilePath _statsLogPath;
SignalingProtocolVersion _signalingProtocolVersion = SignalingProtocolVersion::V3;
std::unique_ptr<SignalingConnection> _signalingConnection;
std::unique_ptr<EncryptedConnection> _signalingEncryptedConnection;
@@ -1941,6 +2110,8 @@ private:
bool _hasAppliedRemoteOffer = false;
int64_t _firstRemoteAnswerTimestamp = 0;
static constexpr int64_t kCallerOfferHoldMs = 10000;
int64_t _lastAnswerSentTimestamp = 0;
static constexpr int64_t kPostAnswerOfferHoldMs = 1000;
bool _isPerformingConfiguration = false;
bool _useMtProto = false;
+5 -3
View File
@@ -6,7 +6,8 @@ In-process test harness for tgcalls. See the root `CLAUDE.md` for build instruct
| Version | Implementation | Notes |
|---|---|---|
| `14.0.0` | `InstanceV2CompatImpl` | WebRTC PeerConnection speaking V2Impl's channel protocol; interoperates with 7.0.0–13.0.0 and itself (rewritten 2026-10-11, see `submodules/TgVoipWebrtc/CLAUDE.md`) |
| `14.0.0` | `InstanceV2CompatImpl` | WebRTC PeerConnection speaking V2Impl's channel protocol (rewritten 2026-10-11, see `submodules/TgVoipWebrtc/CLAUDE.md`) |
| `compat:<version>` | `InstanceV2CompatImpl` | CompatImpl constructed under that call version, e.g. `compat:8.0.0` against an unchanged `8.0.0` peer: the registry maps 7.0.0–13.0.0 to `InstanceV2Impl`, as the app does |
| `13.0.0` (default) | `InstanceV2Impl` | Also: 7.0.0, 8.0.0, 9.0.0, 12.0.0 |
| `11.0.0` | `InstanceV2ReferenceImpl` | Also: 10.0.0. Uses WebRTC PeerConnection |
| `5.0.0` | `InstanceImpl` (v1) | Also: 2.7.7. Legacy |
@@ -16,9 +17,10 @@ In-process test harness for tgcalls. See the root `CLAUDE.md` for build instruct
- Signaling bridged via `SignalingBridge` with configurable drop rate and delay
- Group participant logs (`/tmp/tgcalls_group_p<id>_<pid>.log`) are written at stop and unlinked after validation; set `TGCALLS_CLI_KEEP_LOGS=1` to keep them (added 2026-09-17).
- `--video` in p2p/reflector mode attaches a `tgcalls::VideoCaptureInterface::Create(threads, ...)` to BOTH descriptors (`descriptor.videoCapture`, the iOS join-time path: camera already on when the call is created). Added 2026-09-17 to reproduce the 18/19 start-glare renegotiation loop; a healthy video call shows 2 `Calling SetLocalDescription` in the `--log-file` for 11.0.0 (one per side since the 2026-10-12 one-round negotiation; 4 for 18/19), no `SetLocalDescription failed`, one `Creating data channel`. Combine with `--delay 100-300` for field-like signaling latency.
- `run-parity-tests.sh` (2026-10-27): `InstanceV2CompatImpl` under a legacy version against `InstanceV2Impl` under the same version, "no worse than V ↔ V" as numbers. Eight scenarios (delay, mid-call cameras, mute, 30% signaling loss) × three pairings (V-V, CompatImpl caller, CompatImpl callee), 528 calls, ~6 min; `parity_report.py` prints failure counts with a one-sided Fisher p where CompatImpl is worse, and p50/p90 of connection and first audio/video per side. Default version 8.0.0.
- `--video-late-caller-ms N` / `--video-late-callee-ms N` attach that side's capture N ms after the instances are created (the other side gets none unless it has its own value): the Android app's shape, where the camera reaches the engine while the first offer is in flight. `run-negotiation-tests.sh` (2026-10-12) uses them with `network_reference_immediate_capture_renegotiation` to reproduce the late-camera DTLS failure and pins the one-round negotiation (see the tgcalls `CLAUDE.md`).
- `--video-late` attaches the same captures mid-call via `setVideoCapture` (callee at 3 s, caller at 5 s). With either flag both instances get a `FakeVideoSink` (`setIncomingVideoOutput`) and the summary prints the decoded frames each side received; `remoteMediaStateUpdated` is counted per side. Both are informational, not pass criteria.
- `FakeAudioDeviceModule` with `SineRecorder` (440Hz tone) and `NoOpRenderer` (audio discarded; validation via BWE)
- `FakeAudioDeviceModule` with `SineRecorder` (440Hz tone, amplitude 3000) and, since 2026-10-27, `ToneRenderer`, which counts the 10 ms playout frames whose peak reaches 1000 — the peer's tone; silence and loss concealment stay far below — and when the first played. The summary prints `Audio heard: caller N frames (first at Ts), callee …` (-1 = nothing heard); with `--video*` also `Video first frame: caller at Ts, callee at Ts`. Informational, like the video counts; the exit code still rests on connection + BWE. With both sides muted the counts are 0, which is how the renderer was validated (a first version read past the buffer and "heard" ~500 frames regardless: the fake ADM's `num_samples` is already the interleaved total).
- `FakeInterface` platform implementation (pure C++, no iOS/ObjC deps)
- Stats log validation: both caller and callee write `config.statsLogPath` with bitrate records; non-empty log with at least one non-zero BWE value is a success condition
- On failure, full tgcalls internal logs (caller + callee) are dumped to stdout via `config.logPath`
@@ -40,7 +42,7 @@ In-process test harness for tgcalls. See the root `CLAUDE.md` for build instruct
- Video validation: `FakeVideoSink` (implements `rtc::VideoSinkInterface<VideoFrame>`) counts decoded frames per remote endpoint; success requires every participant to receive ≥1 frame from every other
- Video signaling flow: SFU broadcasts `ActiveVideoSsrcs` over data channel → `dataChannelMessageReceived` callback fires in the app → app calls `setRequestedVideoChannels` → CustomImpl creates `IncomingVideoChannel` / ReferenceImpl adds recvonly video transceiver → both send `ReceiverVideoConstraints` → SFU sends `SenderVideoConstraints` + proactive PLI → sender produces keyframe → receiver decodes. `requestVideoFromEndpoints()` (group_participant.cpp) is the single request path: it accumulates the FULL requested set in `ParticipantState::requestedVideoChannels` and resends all of it on every call, because both engines treat the list as the complete set and drop endpoints missing from it. With `--early-video-request` the same helper runs right after `emitJoinPayload` for every already-joined participant (SSRCs via `GoSfu_QueryVideoSsrcs`), reproducing the real app's order — request before join response, before the data channel — which the `ActiveVideoSsrcs`-driven path never exercises (the broadcast fires 500 ms after the data channel is up)
- `dataChannelMessageReceived` callback: added to `GroupInstanceDescriptor`, forwards all incoming Colibri data channel messages to the application. Used by the CLI test tool to react to `ActiveVideoSsrcs` and dynamically set up video channels — mirrors the real Telegram app's reactive flow
- `FakeAudioDeviceModule` with `SineRecorder` (440Hz tone) and `NoOpRenderer` — same as P2P mode
- `FakeAudioDeviceModule` with `SineRecorder` (440Hz tone) and `NoOpRenderer` (audio discarded; levels come from `audioLevelsUpdated`)
- `FakeInterface` (`tgcalls/platform/fake/FakeInterface.cpp`) wraps the builtin video encoder/decoder factories so `GetSupportedFormats()` comes back in the iOS platform order — two H264 entries (packetization-mode 1, the constrained-baseline one kept), VP8, VP9 profile 0. PeerConnection assigns dynamic payload types by walking that list (96, 98, 100, ... with RTX at +1), so the ORDER decides which codec sits on which number; the raw builtin host order lists five H264 profiles and lands one on PT 104 by coincidence, which is exactly the number the group-call convention uses for H264 and hid a ReferenceImpl bug for the device (where PT 104 was H265). `--builtin-codec-order` restores the raw order for comparison
- `churnVideoSinks()` (group_participant.cpp, `--video-sink-churn`) replaces every participant's incoming sinks via `addIncomingVideoOutput` and releases the old ones, mirroring the app recreating tile views on quality changes; the engine must only ever hold weak references (a raw sink pointer left on the track crashes on the next frame)
- `dropAllVideoRequests()` / `rerequestAllVideo()` (group_participant.cpp, `--video-rerequest`): after frames flow, every participant's SFU egress gets a 150 ms delay (`GoSfu_SetNetworkParams`), then five rounds of `setRequestedVideoChannels({})` followed a second later by the full accumulated set again, sinks kept throughout. Validation requires every sink's frame count to grow past the value recorded at the last drop ("Video after re-request: N/M stalled", must be 0). The delay is load-bearing: on the in-process SFU the streams stop before the renegotiation lands, whereas on a real network the packets forwarded before the SFU read the empty `ReceiverVideoConstraints` are still arriving while the receive streams are torn down; that in-flight packet is what used to create a default receive stream on the abandoned transceiver's channel and freeze the tile on re-request. The window is sub-millisecond at the harness's packet rates, so the reproduction needs `--reference-participants 6` (both unfixed runs failed 1/30; three participants passed by luck).
+9 -1
View File
@@ -2,11 +2,14 @@
#include "api/video/video_frame.h"
#include "api/video/video_sink_interface.h"
#include <atomic>
#include <chrono>
class FakeVideoSink : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
public:
void OnFrame(const webrtc::VideoFrame& frame) override {
frameCount_.fetch_add(1, std::memory_order_relaxed);
if (frameCount_.fetch_add(1, std::memory_order_relaxed) == 0) {
firstFrameTime_.store(std::chrono::steady_clock::now().time_since_epoch().count(), std::memory_order_relaxed);
}
int w = frame.width();
int h = frame.height();
lastWidth_.store(w, std::memory_order_relaxed);
@@ -17,8 +20,13 @@ public:
int frameCount() const {
return frameCount_.load(std::memory_order_relaxed);
}
// steady_clock time of the first frame (time_since_epoch ticks), 0 before it.
int64_t firstFrameTime() const {
return firstFrameTime_.load(std::memory_order_relaxed);
}
private:
std::atomic<int> frameCount_{0};
std::atomic<int64_t> firstFrameTime_{0};
std::atomic<int> lastWidth_{0};
std::atomic<int> lastHeight_{0};
};
+128 -29
View File
@@ -37,6 +37,7 @@
#include "modules/audio_device/include/audio_device.h"
#include "api/task_queue/task_queue_factory.h"
#include "rtc_base/logging.h"
// Stub: AudioDeviceModule::Create is referenced by InstanceV2Impl as a fallback
// but never called when createAudioDeviceModule is provided in the Descriptor.
@@ -158,6 +159,38 @@ public:
bool Render(const tgcalls::AudioFrame&) override { return true; }
};
// ---------------------------------------------------------------------------
// ToneRenderer - what one p2p side hears: the 10 ms playout frames that carry
// the peer's tone (peak at or above kAudibleThreshold; the tone is sent at
// 3000, silence and packet-loss concealment play out far below) and when the
// first of them played.
// ---------------------------------------------------------------------------
class ToneRenderer : public tgcalls::FakeAudioDeviceModule::Renderer {
public:
bool Render(const tgcalls::AudioFrame &frame) override {
int peak = 0;
// num_samples is the interleaved total (AudioTransport's nSamplesOut).
for (size_t i = 0; i < frame.num_samples; ++i) {
peak = std::max(peak, std::abs((int)frame.audio_samples[i]));
}
if (peak >= kAudibleThreshold) {
if (audibleFrames_.fetch_add(1, std::memory_order_relaxed) == 0) {
firstAudibleAt_.store(elapsed(), std::memory_order_relaxed);
}
}
return true;
}
int audibleFrames() const { return audibleFrames_.load(std::memory_order_relaxed); }
// Seconds since start, -1 if nothing was heard.
double firstAudibleAt() const { return firstAudibleAt_.load(std::memory_order_relaxed); }
private:
static constexpr int kAudibleThreshold = 1000;
std::atomic<int> audibleFrames_{0};
std::atomic<double> firstAudibleAt_{-1.0};
};
// ---------------------------------------------------------------------------
// SignalingBridge
// ---------------------------------------------------------------------------
@@ -221,6 +254,18 @@ struct CallState {
// Merges the optional --custom-params JSON object with the wasm_core_path entry the CLI
// synthesises, so a test can set engine custom parameters without losing --wasm-core.
// --version / --version2 "compat:<version>": InstanceV2CompatImpl under that call
// version, which the registry cannot give (it maps 7.0.0-13.0.0 to InstanceV2Impl,
// as the app does). This is CompatImpl against an unchanged peer of that version.
static std::unique_ptr<tgcalls::Instance> createInstance(std::string const &version, tgcalls::Descriptor &&descriptor) {
const std::string compatPrefix = "compat:";
if (version.rfind(compatPrefix, 0) == 0) {
descriptor.version = version.substr(compatPrefix.size());
return std::make_unique<tgcalls::InstanceV2CompatImpl>(std::move(descriptor));
}
return tgcalls::Meta::Create(version, std::move(descriptor));
}
static std::string buildCustomParameters(std::string const &wasmCorePath, std::string const &extraJson) {
json11::Json::object params;
@@ -501,9 +546,9 @@ int main(int argc, char* argv[]) {
// Audio components
auto callerRecorder = std::make_shared<SineRecorder>();
auto callerRenderer = std::make_shared<NoOpRenderer>();
auto callerRenderer = std::make_shared<ToneRenderer>();
auto calleeRecorder = std::make_shared<SineRecorder>();
auto calleeRenderer = std::make_shared<NoOpRenderer>();
auto calleeRenderer = std::make_shared<ToneRenderer>();
// Stats log paths (per-process to avoid collisions in parallel runs)
std::string callerStatsPath = "/tmp/tgcalls_cli_caller_" + std::to_string(getpid()) + ".json";
@@ -629,7 +674,7 @@ int main(int argc, char* argv[]) {
// Create instances
auto callerInstance = std::shared_ptr<tgcalls::Instance>(
tgcalls::Meta::Create(version, std::move(callerDesc)).release());
createInstance(version, std::move(callerDesc)).release());
if (!callerInstance) {
fprintf(stderr, "Error: unknown version '%s'\n", version.c_str());
return 1;
@@ -637,7 +682,7 @@ int main(int argc, char* argv[]) {
logMsg("Caller", "created (version %s)", version.c_str());
auto calleeInstance = std::shared_ptr<tgcalls::Instance>(
tgcalls::Meta::Create(version2, std::move(calleeDesc)).release());
createInstance(version2, std::move(calleeDesc)).release());
if (!calleeInstance) {
fprintf(stderr, "Error: unknown callee version '%s'\n", version2.c_str());
return 1;
@@ -656,13 +701,35 @@ int main(int argc, char* argv[]) {
calleeInstance->setIncomingVideoOutput(calleeVideoSink);
}
// --mute-participants in p2p/reflector: 0 is the caller, 1 the callee, muted
// right after creation (a call that starts muted). Read the --log-file: a muted
// side's AudioSendStream must not run until the "unmuting" marker.
const bool muteCaller = mutedParticipants.count(0) > 0;
const bool muteCallee = mutedParticipants.count(1) > 0;
if (muteCaller) {
callerInstance->setMuteMicrophone(true);
}
if (muteCallee) {
calleeInstance->setMuteMicrophone(true);
}
logMsg("Main", "sleeping for %d seconds...", duration);
if (videoLateMs) {
// The camera reaches the engine a fixed time after start, on each side
// that asked for it, in time order.
std::vector<std::pair<int, bool>> events; // (ms, isCaller)
if (videoLateCallerMs >= 0) events.push_back({videoLateCallerMs, true});
if (videoLateCalleeMs >= 0) events.push_back({videoLateCalleeMs, false});
const bool unmuteMidCall = (muteCaller || muteCallee) && unmuteAfterSeconds > 0 && unmuteAfterSeconds < duration;
// --video-late: the camera switched on mid-call, the app's setVideoCapture
// path, the callee first, so the callee has to offer its own new channel.
const bool videoLateFixed = videoLate && !videoLateMs && duration > 5;
if (videoLateMs || videoLateFixed || unmuteMidCall) {
// Mid-call events in time order: a side's camera reaching the engine a
// fixed time after start, and the unmute.
enum class Event { CallerCamera, CalleeCamera, Unmute };
std::vector<std::pair<int, Event>> events; // (ms, event)
if (videoLateCallerMs >= 0) events.push_back({videoLateCallerMs, Event::CallerCamera});
if (videoLateCalleeMs >= 0) events.push_back({videoLateCalleeMs, Event::CalleeCamera});
if (videoLateFixed) {
events.push_back({3000, Event::CalleeCamera});
events.push_back({5000, Event::CallerCamera});
}
if (unmuteMidCall) events.push_back({unmuteAfterSeconds * 1000, Event::Unmute});
std::sort(events.begin(), events.end());
int elapsedMs = 0;
for (const auto &event : events) {
@@ -670,31 +737,51 @@ int main(int argc, char* argv[]) {
std::this_thread::sleep_for(std::chrono::milliseconds(event.first - elapsedMs));
elapsedMs = event.first;
}
logMsg("Main", "attaching the %s's video capture at %d ms", event.second ? "caller" : "callee", event.first);
if (event.second) {
callerInstance->setVideoCapture(callerVideoCapture);
} else {
calleeInstance->setVideoCapture(calleeVideoCapture);
switch (event.second) {
case Event::CallerCamera:
logMsg("Main", "attaching the caller's video capture at %d ms", event.first);
callerInstance->setVideoCapture(callerVideoCapture);
break;
case Event::CalleeCamera:
logMsg("Main", "attaching the callee's video capture at %d ms", event.first);
calleeInstance->setVideoCapture(calleeVideoCapture);
break;
case Event::Unmute:
logMsg("Main", "unmuting at %d ms", event.first);
RTC_LOG(LS_INFO) << "tgcalls_cli: unmuting the muted side(s)";
if (muteCaller) {
callerInstance->setMuteMicrophone(false);
}
if (muteCallee) {
calleeInstance->setMuteMicrophone(false);
}
break;
}
}
int remainingMs = duration * 1000 - elapsedMs;
if (remainingMs > 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(remainingMs));
}
} else if (videoLate && duration > 5) {
// The camera switched on mid-call, the app's setVideoCapture path: the
// callee first, so the callee has to offer its own new channel.
std::this_thread::sleep_for(std::chrono::seconds(3));
logMsg("Main", "attaching the callee's video capture");
calleeInstance->setVideoCapture(calleeVideoCapture);
std::this_thread::sleep_for(std::chrono::seconds(2));
logMsg("Main", "attaching the caller's video capture");
callerInstance->setVideoCapture(callerVideoCapture);
std::this_thread::sleep_for(std::chrono::seconds(duration - 5));
} else {
std::this_thread::sleep_for(std::chrono::seconds(duration));
}
// What the call delivered, read before teardown: on a loaded host a teardown can
// stall for minutes while media still flows, and that must not count.
const int callerAudibleFrames = callerRenderer->audibleFrames();
const int calleeAudibleFrames = calleeRenderer->audibleFrames();
const double callerFirstAudibleAt = callerRenderer->firstAudibleAt();
const double calleeFirstAudibleAt = calleeRenderer->firstAudibleAt();
const int callerVideoFrames = callerVideoSink->frameCount();
const int calleeVideoFrames = calleeVideoSink->frameCount();
const int64_t callerFirstFrameTime = callerVideoSink->firstFrameTime();
const int64_t calleeFirstFrameTime = calleeVideoSink->firstFrameTime();
double establishedAt = -1.0;
{
std::lock_guard<std::mutex> lock(callState->mutex);
establishedAt = callState->establishedAt;
}
// Stop both instances
logMsg("Main", "stopping instances...");
@@ -770,7 +857,7 @@ int main(int argc, char* argv[]) {
{
std::lock_guard<std::mutex> lock(callState->mutex);
bool established = (callState->establishedAt >= 0);
bool established = (establishedAt >= 0);
printf("\n=== Call Summary ===\n");
printf("Duration: %ds\n", duration);
@@ -785,8 +872,8 @@ int main(int argc, char* argv[]) {
}
printf("Caller state: %s\n", stateName(callState->callerState));
printf("Callee state: %s\n", stateName(callState->calleeState));
if (callState->establishedAt >= 0) {
printf("Call established: yes (at %.3fs)\n", callState->establishedAt);
if (established) {
printf("Call established: yes (at %.3fs)\n", establishedAt);
} else {
printf("Call established: no\n");
}
@@ -797,9 +884,21 @@ int main(int argc, char* argv[]) {
printf("BWE non-zero: %s\n", bweNonZero ? "yes" : "no");
printf("Remote media state: caller=%d callee=%d updates\n",
callState->callerRemoteMediaStates, callState->calleeRemoteMediaStates);
// What each side heard of the other's tone, and when it first did.
printf("Audio heard: caller %d frames (first at %.3fs), callee %d frames (first at %.3fs)\n",
callerAudibleFrames, callerFirstAudibleAt, calleeAudibleFrames, calleeFirstAudibleAt);
if (callerVideoCapture) {
printf("Video frames: caller received %d, callee received %d\n",
callerVideoSink->frameCount(), calleeVideoSink->frameCount());
callerVideoFrames, calleeVideoFrames);
const auto firstFrameAt = [](int64_t time) -> double {
if (time == 0) {
return -1.0;
}
const auto start = gStartTime.time_since_epoch().count();
return std::chrono::duration<double>(std::chrono::steady_clock::duration(time - start)).count();
};
printf("Video first frame: caller at %.3fs, callee at %.3fs\n",
firstFrameAt(callerFirstFrameTime), firstFrameAt(calleeFirstFrameTime));
}
bool statsCollected = (callerStats.bitrateRecords > 0 && calleeStats.bitrateRecords > 0);
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env python3
"""Summarises run-parity-tests.sh output: per scenario and pairing, how many calls failed
each check, a one-sided Fisher p wherever a CompatImpl pairing failed more often than the
baseline, and p50/p90 of the connection time and of each side's first audio and video."""
import glob
import math
import os
import re
import sys
from collections import defaultdict
PAIRINGS = ('V-V', 'cV-V', 'V-cV')
def parse(path):
text = open(path, errors='replace').read()
r = {}
m = re.search(r'^Call established:\s+yes \(at ([0-9.]+)s\)', text, re.M)
r['setup'] = float(m.group(1)) if m else None
m = re.search(r'^Audio heard:\s+caller (\d+) frames \(first at (-?[0-9.]+)s\), '
r'callee (\d+) frames \(first at (-?[0-9.]+)s\)', text, re.M)
if m:
r['audio caller'], r['audio callee'] = int(m.group(1)), int(m.group(3))
r['first audio caller'] = float(m.group(2)) if float(m.group(2)) >= 0 else None
r['first audio callee'] = float(m.group(4)) if float(m.group(4)) >= 0 else None
m = re.search(r'^Video frames:\s+caller received (\d+), callee received (\d+)', text, re.M)
if m:
r['video caller'], r['video callee'] = int(m.group(1)), int(m.group(2))
m = re.search(r'^Video first frame: caller at (-?[0-9.]+)s, callee at (-?[0-9.]+)s', text, re.M)
if m:
r['first video caller'] = float(m.group(1)) if float(m.group(1)) >= 0 else None
r['first video callee'] = float(m.group(2)) if float(m.group(2)) >= 0 else None
return r
CHECKS = {
'not connected': lambda r: r['setup'] is None,
'caller hears nothing': lambda r: r.get('audio caller', 0) == 0,
'callee hears nothing': lambda r: r.get('audio callee', 0) == 0,
'caller gets no video': lambda r: 'video caller' in r and r['video caller'] == 0,
'callee gets no video': lambda r: 'video callee' in r and r['video callee'] == 0,
}
def fisher_worse(bad_base, n_base, bad, n):
"""P(at least `bad` failures among the n CompatImpl calls | both margins)."""
total_bad = bad_base + bad
total = n_base + n
return sum(math.comb(n, k) * math.comb(n_base, total_bad - k) / math.comb(total, total_bad)
for k in range(bad, min(n, total_bad) + 1) if total_bad - k <= n_base)
def quantile(values, q):
values = sorted(v for v in values if v is not None)
if not values:
return None
return values[min(len(values) - 1, max(0, math.ceil(q * len(values)) - 1))]
def timing(rs, key):
p50, p90 = quantile([r.get(key) for r in rs], .5), quantile([r.get(key) for r in rs], .9)
return '-' if p50 is None else f'{p50:.2f}/{p90:.2f}'
runs = defaultdict(list)
for path in glob.glob(os.path.join(sys.argv[1], '*.out')):
scenario, pairing, _ = os.path.basename(path)[:-4].rsplit('.', 2)
runs[(scenario, pairing)].append(parse(path))
for scenario in sorted({s for s, _ in runs}):
print(f'== {scenario}')
base = runs.get((scenario, 'V-V'), [])
for pairing in PAIRINGS:
rs = runs.get((scenario, pairing), [])
if not rs:
continue
cells = []
for name, failed in CHECKS.items():
if name.endswith('video') and not any('video caller' in r for r in rs):
continue
bad = sum(1 for r in rs if failed(r))
cell = f'{name} {bad}'
if pairing != 'V-V' and base:
bad_base = sum(1 for r in base if failed(r))
if bad * len(base) > bad_base * len(rs):
cell += f' (p={fisher_worse(bad_base, len(base), bad, len(rs)):.2f})'
cells.append(cell)
print(f' {pairing:5} n={len(rs):2} | ' + ' | '.join(cells))
line = f' p50/p90 s: connected {timing(rs, "setup")}'
line += f' | caller hears {timing(rs, "first audio caller")} | callee hears {timing(rs, "first audio callee")}'
if any('video caller' in r for r in rs):
line += f' | caller sees {timing(rs, "first video caller")} | callee sees {timing(rs, "first video callee")}'
print(line)
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env zsh
# Parity of InstanceV2CompatImpl under a legacy call version against InstanceV2Impl under the
# same version: is compat+V no worse than V+V? Every scenario runs for three pairings on the
# in-process p2p harness:
# V-V the baseline, InstanceV2Impl on both ends
# cV-V CompatImpl as the caller (--version compat:V)
# V-cV CompatImpl as the callee (--version2 compat:V)
# and parity_report.py prints, per scenario and pairing, the failure counts (no connection,
# a side that hears nothing of the other's tone, a side that gets no video) with a one-sided
# Fisher p wherever a CompatImpl pairing is worse than the baseline, and p50/p90 of the
# connection time and of each side's first audio and first video.
#
# ./submodules/TgVoipWebrtc/tgcalls/tools/cli/run-parity-tests.sh [-v VERSION] [-j PARALLEL] [-o DIR] [-l] [CLI] [SCENARIO...]
#
# -l keeps each call's engine log next to its summary (DIR/<scenario>.<pairing>.<n>.log), which
# is what a failure has to be traced from. VERSION defaults to 8.0.0, PARALLEL to 16: every call
# encodes and decodes on both sides, and an oversubscribed host delays CompatImpl's answers (two
# posted tasks) more than InstanceV2Impl's (synchronous), which biases exactly what is measured.
# CLI defaults to the bazel-bin binary. With no SCENARIO all run (528 calls, ~10 min at -j 16):
# audio-delay, video-delay, videolate-delay 100-300 ms signaling delay, 16 runs each
# mute-caller, mute-callee muted at start, unmuted at 4 s, 8 runs each
# audio-loss30, video-loss30 30% signaling loss, 32 runs each
# videolate-loss30 30% loss, cameras at 3 s (callee) / 5 s (caller),
# 48 runs: the glare stress case
# At these sample sizes a rate difference shows direction, not equivalence.
set -u
VERSION=8.0.0
PAR=16
LOGS=0
OUT="${TMPDIR:-/tmp}/tgcalls-parity-$$"
while getopts "v:j:o:l" opt; do
case $opt in
v) VERSION=$OPTARG ;;
j) PAR=$OPTARG ;;
o) OUT=$OPTARG ;;
l) LOGS=1 ;;
*) exit 2 ;;
esac
done
shift $((OPTIND - 1))
CLI="${1:-./bazel-bin/submodules/TgVoipWebrtc/tgcalls/tools/cli/tgcalls_cli}"
(( $# > 0 )) && shift
if [ ! -x "$CLI" ]; then echo "no CLI at $CLI"; exit 2; fi
CLI=${CLI:A}
mkdir -p "$OUT/jobs"
rm -f "$OUT"/jobs/*.sh(N)
typeset -A ARGS RUNS
ARGS[audio-delay]="--duration 10 --delay 100-300"; RUNS[audio-delay]=16
ARGS[video-delay]="--duration 10 --video --delay 100-300"; RUNS[video-delay]=16
ARGS[videolate-delay]="--duration 12 --video-late --delay 100-300"; RUNS[videolate-delay]=16
ARGS[mute-caller]="--duration 10 --mute-participants 0 --unmute-after 4 --delay 100-300"; RUNS[mute-caller]=8
ARGS[mute-callee]="--duration 10 --mute-participants 1 --unmute-after 4 --delay 100-300"; RUNS[mute-callee]=8
ARGS[audio-loss30]="--duration 20 --drop-rate 0.3 --delay 50-200"; RUNS[audio-loss30]=32
ARGS[video-loss30]="--duration 20 --video --drop-rate 0.3 --delay 50-200"; RUNS[video-loss30]=32
ARGS[videolate-loss30]="--duration 30 --video-late --drop-rate 0.3 --delay 50-200"; RUNS[videolate-loss30]=48
scenarios=("$@")
(( ${#scenarios} == 0 )) && scenarios=(${(k)ARGS})
for sc in $scenarios; do
if [ -z "${ARGS[$sc]:-}" ]; then echo "unknown scenario $sc"; exit 2; fi
for pair in "V-V $VERSION $VERSION" "cV-V compat:$VERSION $VERSION" "V-cV $VERSION compat:$VERSION"; do
set -- ${=pair}
for r in $(seq 1 ${RUNS[$sc]}); do
log=""
(( LOGS )) && log="--log-file '$OUT/$sc.$1.$r.log'"
echo "'$CLI' --mode p2p --version $2 --version2 $3 ${ARGS[$sc]} $log --quiet > '$OUT/$sc.$1.$r.out' 2>/dev/null" > "$OUT/jobs/$sc.$1.$r.sh"
done
done
done
echo "running $(ls "$OUT"/jobs/*.sh | wc -l | tr -d ' ') calls, $PAR at a time, into $OUT"
# Shuffled so every pairing sees the same load.
ls "$OUT"/jobs/*.sh | sort -R | xargs -P "$PAR" -n 1 zsh
python3 -I "${0:A:h}/parity_report.py" "$OUT"