chore(calling): log outbound audio bytes and per-source mic levels
- Stats line shows audio bytes sent and each audio media source's level - call-e2e: guest audio falls back to inbound stats energy, reports guest playback elements and receive stats Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -2340,11 +2340,11 @@ async fn drive(
2340
2340
timeline.record(
2341
2341
"stats",
2342
2342
format!(
2343
"in packets={} bytes={} level={:.3} rms={decoded_rms:.3} tone={ratio:.2} out packets={} mic={:.3} erle={:.1} dtls={} video in packets={} decoded={} {}x{} out packets={} encoded={} {}x{} mixer reports {} (rtt {:.0} ms){}",
2343
"in packets={} bytes={} level={:.3} rms={decoded_rms:.3} tone={ratio:.2} out packets={} mic={:.3} erle={:.1} dtls={} video in packets={} decoded={} {}x{} out packets={} encoded={} {}x{} mixer reports {} (rtt {:.0} ms) out bytes={} sources={:?}{}",
2344
2344
snapshot.inbound_packets, snapshot.inbound_bytes, snapshot.audio_level, snapshot.outbound_packets, snapshot.local_level, snapshot.echo_return_loss_enhancement, snapshot.dtls_state,
2345
2345
snapshot.video.inbound_packets, snapshot.video.inbound_frames_decoded, snapshot.video.inbound_width, snapshot.video.inbound_height,
2346
2346
snapshot.video.outbound_packets, snapshot.video.outbound_frames_encoded, snapshot.video.outbound_width, snapshot.video.outbound_height,
2347
snapshot.video.remote_reports, snapshot.video.remote_round_trip_ms,
2347
snapshot.video.remote_reports, snapshot.video.remote_round_trip_ms, snapshot.outbound_bytes, snapshot.source_levels,
2348
2348
snapshot.share_receive.as_ref().filter(|_| snapshot.share_inbound_packets > 0).map(ShareReceive::summary).unwrap_or_default()
2349
2349
),
2350
2350
);
@@ -3409,6 +3409,8 @@ struct StatsSnapshot {
3409
3409
inbound_packets: u64,
3410
3410
inbound_bytes: u64,
3411
3411
outbound_packets: u64,
3412
outbound_bytes: u64,
3413
source_levels: Vec<String>,
3412
3414
audio_level: f64,
3413
3415
local_level: f64,
3414
3416
echo_return_loss_enhancement: f64,
@@ -3462,10 +3464,12 @@ async fn collect_stats(peer: &PeerConnection, share_mids: &[String]) -> StatsSna
3462
3464
}
3463
3465
RtcStats::MediaSource(source) if source.source.kind == "audio" => {
3464
3466
snapshot.local_level = snapshot.local_level.max(source.audio.audio_level);
3467
snapshot.source_levels.push(format!("{}={:.3}", source.source.track_identifier, source.audio.audio_level));
3465
3468
snapshot.echo_return_loss_enhancement = source.audio.echo_return_loss_enhancement;
3466
3469
}
3467
3470
RtcStats::OutboundRtp(outbound) if outbound.stream.kind == "audio" => {
3468
3471
snapshot.outbound_packets += outbound.sent.packets_sent;
3472
snapshot.outbound_bytes += outbound.sent.bytes_sent;
3469
3473
}
3470
3474
RtcStats::InboundRtp(inbound) if inbound.stream.kind == "video" => {
3471
3475
snapshot.video.inbound_packets += inbound.received.packets_received;
@@ -2340,11 +2340,11 @@ async fn drive(2340
timeline.record(2340
timeline.record(2341
"stats",2341
"stats",2342
format!(2342
format!(2343
"in packets={} bytes={} level={:.3} rms={decoded_rms:.3} tone={ratio:.2} out packets={} mic={:.3} erle={:.1} dtls={} video in packets={} decoded={} {}x{} out packets={} encoded={} {}x{} mixer reports {} (rtt {:.0} ms){}",2343
"in packets={} bytes={} level={:.3} rms={decoded_rms:.3} tone={ratio:.2} out packets={} mic={:.3} erle={:.1} dtls={} video in packets={} decoded={} {}x{} out packets={} encoded={} {}x{} mixer reports {} (rtt {:.0} ms) out bytes={} sources={:?}{}",2344
snapshot.inbound_packets, snapshot.inbound_bytes, snapshot.audio_level, snapshot.outbound_packets, snapshot.local_level, snapshot.echo_return_loss_enhancement, snapshot.dtls_state,2344
snapshot.inbound_packets, snapshot.inbound_bytes, snapshot.audio_level, snapshot.outbound_packets, snapshot.local_level, snapshot.echo_return_loss_enhancement, snapshot.dtls_state,2345
snapshot.video.inbound_packets, snapshot.video.inbound_frames_decoded, snapshot.video.inbound_width, snapshot.video.inbound_height,2345
snapshot.video.inbound_packets, snapshot.video.inbound_frames_decoded, snapshot.video.inbound_width, snapshot.video.inbound_height,2346
snapshot.video.outbound_packets, snapshot.video.outbound_frames_encoded, snapshot.video.outbound_width, snapshot.video.outbound_height,2346
snapshot.video.outbound_packets, snapshot.video.outbound_frames_encoded, snapshot.video.outbound_width, snapshot.video.outbound_height,2347
snapshot.video.remote_reports, snapshot.video.remote_round_trip_ms,2347
snapshot.video.remote_reports, snapshot.video.remote_round_trip_ms, snapshot.outbound_bytes, snapshot.source_levels,2348
snapshot.share_receive.as_ref().filter(|_| snapshot.share_inbound_packets > 0).map(ShareReceive::summary).unwrap_or_default()2348
snapshot.share_receive.as_ref().filter(|_| snapshot.share_inbound_packets > 0).map(ShareReceive::summary).unwrap_or_default()2349
),2349
),2350
);2350
);@@ -3409,6 +3409,8 @@ struct StatsSnapshot {3409
inbound_packets: u64,3409
inbound_packets: u64,3410
inbound_bytes: u64,3410
inbound_bytes: u64,3411
outbound_packets: u64,3411
outbound_packets: u64,3412
outbound_bytes: u64,3413
source_levels: Vec<String>,3412
audio_level: f64,3414
audio_level: f64,3413
local_level: f64,3415
local_level: f64,3414
echo_return_loss_enhancement: f64,3416
echo_return_loss_enhancement: f64,@@ -3462,10 +3464,12 @@ async fn collect_stats(peer: &PeerConnection, share_mids: &[String]) -> StatsSna3462
}3464
}3463
RtcStats::MediaSource(source) if source.source.kind == "audio" => {3465
RtcStats::MediaSource(source) if source.source.kind == "audio" => {3464
snapshot.local_level = snapshot.local_level.max(source.audio.audio_level);3466
snapshot.local_level = snapshot.local_level.max(source.audio.audio_level);3467
snapshot.source_levels.push(format!("{}={:.3}", source.source.track_identifier, source.audio.audio_level));3465
snapshot.echo_return_loss_enhancement = source.audio.echo_return_loss_enhancement;3468
snapshot.echo_return_loss_enhancement = source.audio.echo_return_loss_enhancement;3466
}3469
}3467
RtcStats::OutboundRtp(outbound) if outbound.stream.kind == "audio" => {3470
RtcStats::OutboundRtp(outbound) if outbound.stream.kind == "audio" => {3468
snapshot.outbound_packets += outbound.sent.packets_sent;3471
snapshot.outbound_packets += outbound.sent.packets_sent;3472
snapshot.outbound_bytes += outbound.sent.bytes_sent;3469
}3473
}3470
RtcStats::InboundRtp(inbound) if inbound.stream.kind == "video" => {3474
RtcStats::InboundRtp(inbound) if inbound.stream.kind == "video" => {3471
snapshot.video.inbound_packets += inbound.received.packets_received;3475
snapshot.video.inbound_packets += inbound.received.packets_received;@@ -102,7 +102,16 @@ const REMOTE_AUDIO_TAP = `(() => {
102
102
}, 500);
103
103
})();`;
104
104
105
const INBOUND_AUDIO = `({ ...window.__remoteAudio })`;
105
const INBOUND_AUDIO = `(async () => {
106
let energy = 0, duration = 0;
107
for (const peer of window.__pcs || []) {
108
if (peer.connectionState === 'closed') continue;
109
(await peer.getStats()).forEach((entry) => {
110
if (entry.type === 'inbound-rtp' && entry.kind === 'audio') { energy += entry.totalAudioEnergy || 0; duration += entry.totalSamplesDuration || 0; }
111
});
112
}
113
return { ...window.__remoteAudio, energy, duration };
114
})()`;
106
115
107
116
const GUEST_SENDING = `(async () => {
108
117
let energy = 0, duration = 0, packets = 0;
@@ -183,6 +192,9 @@ class GuestTab {
183
192
await this.browser.send('Input.dispatchMouseEvent', { type, x: 5, y: 5, button: 'left', clickCount: 1 }, this.sessionId).catch(() => {});
184
193
}
185
194
}
195
async playbackState() {
196
return this.evaluate(`[...document.querySelectorAll('audio, video')].map((element) => ({ tag: element.tagName, paused: element.paused, muted: element.muted, volume: element.volume, tracks: element.srcObject ? element.srcObject.getTracks().map((track) => track.kind + ':' + track.readyState + ':' + (track.muted ? 'muted' : 'live')) : [] }))`).catch((error) => error.message);
197
}
186
198
async typeName() {
187
199
const focused = await this.evaluate(`(() => {
188
200
const input = document.querySelector('input[placeholder*="name" i]');
@@ -209,7 +221,9 @@ async function sampleWeb(tab, seconds) {
209
221
await delay(WINDOW_MS);
210
222
const current = await tab.evaluate(INBOUND_AUDIO);
211
223
const count = current.count - previous.count;
212
levels.push(count > 0 ? Math.sqrt((current.sum - previous.sum) / count) : 0);
224
const duration = current.duration - previous.duration;
225
if (count > 0) levels.push(Math.sqrt((current.sum - previous.sum) / count));
226
else levels.push(duration > 0 ? Math.sqrt((current.energy - previous.energy) / duration) : 0);
213
227
previous = current;
214
228
}
215
229
return levels;
@@ -377,6 +391,8 @@ try {
377
391
sampleWeb(tab, MEASURE_SECONDS),
378
392
]);
379
393
report.guestSending = await tab.evaluate(GUEST_SENDING).catch((error) => error.message);
394
report.guestPlayback = await tab.playbackState();
395
report.guestReceiving = await tab.evaluate(PEER_STATS).then((stats) => ({ peers: stats.peers, audioIn: stats.audioIn })).catch((error) => error.message);
380
396
report.appToWeb = judge(webLevels, WEB_THRESHOLD);
381
397
report.webToApp = judge(JSON.parse(recorded).rms, APP_THRESHOLD);
382
398
report.webLevels = webLevels.map((level) => Number(level.toFixed(4)));
@@ -397,5 +413,5 @@ const scenariosPass = Object.values(report.scenarios ?? {}).every((entry) => ent
397
413
report.pass = Boolean(report.appToWeb?.pass && report.webToApp?.pass && scenariosPass);
398
414
writeFileSync(workDir + '/report.json', JSON.stringify(report, null, 2));
399
415
const scenarioSummary = Object.fromEntries(Object.entries(report.scenarios ?? {}).map(([name, entry]) => [name, entry.pass ? 'pass' : `FAIL ${entry.error ?? ''}`.trim()]));
400
console.log(JSON.stringify({ pass: report.pass, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));
416
console.log(JSON.stringify({ pass: report.pass, guestPlayback: report.guestPlayback, guestReceiving: report.guestReceiving, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));
401
417
process.exit(report.pass ? 0 : 1);
@@ -102,7 +102,16 @@ const REMOTE_AUDIO_TAP = `(() => {102
}, 500);102
}, 500);103
})();`;103
})();`;104
104
105
const INBOUND_AUDIO = `({ ...window.__remoteAudio })`;105
const INBOUND_AUDIO = `(async () => {106
let energy = 0, duration = 0;107
for (const peer of window.__pcs || []) {108
if (peer.connectionState === 'closed') continue;109
(await peer.getStats()).forEach((entry) => {110
if (entry.type === 'inbound-rtp' && entry.kind === 'audio') { energy += entry.totalAudioEnergy || 0; duration += entry.totalSamplesDuration || 0; }111
});112
}113
return { ...window.__remoteAudio, energy, duration };114
})()`;106
115
107
const GUEST_SENDING = `(async () => {116
const GUEST_SENDING = `(async () => {108
let energy = 0, duration = 0, packets = 0;117
let energy = 0, duration = 0, packets = 0;@@ -183,6 +192,9 @@ class GuestTab {183
await this.browser.send('Input.dispatchMouseEvent', { type, x: 5, y: 5, button: 'left', clickCount: 1 }, this.sessionId).catch(() => {});192
await this.browser.send('Input.dispatchMouseEvent', { type, x: 5, y: 5, button: 'left', clickCount: 1 }, this.sessionId).catch(() => {});184
}193
}185
}194
}195
async playbackState() {196
return this.evaluate(`[...document.querySelectorAll('audio, video')].map((element) => ({ tag: element.tagName, paused: element.paused, muted: element.muted, volume: element.volume, tracks: element.srcObject ? element.srcObject.getTracks().map((track) => track.kind + ':' + track.readyState + ':' + (track.muted ? 'muted' : 'live')) : [] }))`).catch((error) => error.message);197
}186
async typeName() {198
async typeName() {187
const focused = await this.evaluate(`(() => {199
const focused = await this.evaluate(`(() => {188
const input = document.querySelector('input[placeholder*="name" i]');200
const input = document.querySelector('input[placeholder*="name" i]');@@ -209,7 +221,9 @@ async function sampleWeb(tab, seconds) {209
await delay(WINDOW_MS);221
await delay(WINDOW_MS);210
const current = await tab.evaluate(INBOUND_AUDIO);222
const current = await tab.evaluate(INBOUND_AUDIO);211
const count = current.count - previous.count;223
const count = current.count - previous.count;212
levels.push(count > 0 ? Math.sqrt((current.sum - previous.sum) / count) : 0);224
const duration = current.duration - previous.duration;225
if (count > 0) levels.push(Math.sqrt((current.sum - previous.sum) / count));226
else levels.push(duration > 0 ? Math.sqrt((current.energy - previous.energy) / duration) : 0);213
previous = current;227
previous = current;214
}228
}215
return levels;229
return levels;@@ -377,6 +391,8 @@ try {377
sampleWeb(tab, MEASURE_SECONDS),391
sampleWeb(tab, MEASURE_SECONDS),378
]);392
]);379
report.guestSending = await tab.evaluate(GUEST_SENDING).catch((error) => error.message);393
report.guestSending = await tab.evaluate(GUEST_SENDING).catch((error) => error.message);394
report.guestPlayback = await tab.playbackState();395
report.guestReceiving = await tab.evaluate(PEER_STATS).then((stats) => ({ peers: stats.peers, audioIn: stats.audioIn })).catch((error) => error.message);380
report.appToWeb = judge(webLevels, WEB_THRESHOLD);396
report.appToWeb = judge(webLevels, WEB_THRESHOLD);381
report.webToApp = judge(JSON.parse(recorded).rms, APP_THRESHOLD);397
report.webToApp = judge(JSON.parse(recorded).rms, APP_THRESHOLD);382
report.webLevels = webLevels.map((level) => Number(level.toFixed(4)));398
report.webLevels = webLevels.map((level) => Number(level.toFixed(4)));@@ -397,5 +413,5 @@ const scenariosPass = Object.values(report.scenarios ?? {}).every((entry) => ent397
report.pass = Boolean(report.appToWeb?.pass && report.webToApp?.pass && scenariosPass);413
report.pass = Boolean(report.appToWeb?.pass && report.webToApp?.pass && scenariosPass);398
writeFileSync(workDir + '/report.json', JSON.stringify(report, null, 2));414
writeFileSync(workDir + '/report.json', JSON.stringify(report, null, 2));399
const scenarioSummary = Object.fromEntries(Object.entries(report.scenarios ?? {}).map(([name, entry]) => [name, entry.pass ? 'pass' : `FAIL ${entry.error ?? ''}`.trim()]));415
const scenarioSummary = Object.fromEntries(Object.entries(report.scenarios ?? {}).map(([name, entry]) => [name, entry.pass ? 'pass' : `FAIL ${entry.error ?? ''}`.trim()]));400
console.log(JSON.stringify({ pass: report.pass, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));416
console.log(JSON.stringify({ pass: report.pass, guestPlayback: report.guestPlayback, guestReceiving: report.guestReceiving, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));401
process.exit(report.pass ? 0 : 1);417
process.exit(report.pass ? 0 : 1);