Collect call audio buffer history independently of visible diagnostics

This commit is contained in:
evgeny committed 2026-10-30 21:11:18 +01:00
1 parent c6c4b72487
commit f3d3c9d920
2 files changed
+21

No files matched your search

+16
View File
@@ -4,9 +4,11 @@
#include "call_timeline.h"
#include "call_delay.h"
#include "call_playout_policy.h"
#include "call_history_store.h"
#include <chrono>
#include "../../lib/debug_config.h"
#include "../../lib/mem.h"
#include "../../lib/u_async.h"
#include <algorithm>
#include <cmath>
@@ -36,6 +38,7 @@ struct call_jitter {
call_jitter_window packet_window; // Длительность пачек за то же окно, не второй сетевой запас.
int packet_frames = 0;
call_playout_policy policy;
CallHistoryStore history; // Общая для desktop/Android, сбор не зависит от открытого графика.
bool stable_playback = false; // Снимок состояния worker для сетевой оценки, под mtx.
int64_t last_pull_received_ms = -1; // До какого сетевого измерения worker действительно дошёл.
call_jitter_range range = {0, 0, CALL_JITTER_STARTUP_MS}; /* опубликованный снимок под mtx */
@@ -172,6 +175,8 @@ int call_jitter_pull(struct call_jitter* j, int16_t* out, int max_samples) {
int required = reserve * 48 + std::max(max_samples, packet_ms * 48);
if (depth_samples < required) {
std::lock_guard<std::mutex> lock(j->mtx);
j->history.receive(get_time_us() / 1000, (int)depth, reserve, j->tempo_x100,
j->playback_started ? max_samples : 0, j->playback_started ? max_samples : 0);
j->diagnostics.depth_ms = (int)depth; j->diagnostics.reserve_ms = reserve;
j->diagnostics.tempo_x100 = j->tempo_x100; j->diagnostics.waiting = 1;
j->diagnostics.pcm_samples = 0;
@@ -194,6 +199,7 @@ int call_jitter_pull(struct call_jitter* j, int16_t* out, int max_samples) {
j->timeline.read((unsigned)n);
j->processing_ms = (int)std::lround(state.pending / 48); j->tempo_x100 = (int)std::lround(state.tempo * 100);
j->stable_playback = n == max_samples;
j->history.receive(get_time_us() / 1000, (int)depth, reserve, j->tempo_x100, max_samples, max_samples - n);
if (n < max_samples) {
j->underruns++;
j->policy.recover(j->arrival_window.last_received_ms, j->arrival_window.max_reserve);
@@ -234,6 +240,16 @@ void call_jitter_get_diagnostics(struct call_jitter* j, struct call_jitter_diagn
}
}
void call_jitter_get_history(struct call_jitter* j, uint64_t now_ms, struct call_audio_history* out) {
std::lock_guard<std::mutex> lock(j->mtx);
j->history.snapshot(now_ms, *out);
}
void call_jitter_record_tx(struct call_jitter* j, const struct call_history_tx* snapshot) {
std::lock_guard<std::mutex> lock(j->mtx);
j->history.transmit(*snapshot);
}
void call_jitter_silence(struct call_jitter* j, unsigned samples) {
if (!j) return;
std::lock_guard<std::mutex> lock(j->mtx);
+5
View File
@@ -3,6 +3,7 @@
#include <stdint.h>
#include "call_clock.h"
#include "call_audio_history.h"
#ifdef __cplusplus
extern "C" {
@@ -38,6 +39,10 @@ struct call_jitter_diagnostics {
/* j/out обязательны. reset_events!=0 обнуляет только decode_errors, budget_hits и resumed.
* Логировать после выхода из mutex голосового стека; dropped/underruns этим чтением не сбрасываются. */
void call_jitter_get_diagnostics(struct call_jitter*, struct call_jitter_diagnostics*, int reset_events);
/* UI: копия истории под mutex; now_ms на шкале get_time_us()/1000. out обязателен. */
void call_jitter_get_history(struct call_jitter*, uint64_t now_ms, struct call_audio_history* out);
/* uasync: сохранить общий снимок очередей отправки, без заимствования живых очередей. */
void call_jitter_record_tx(struct call_jitter*, const struct call_history_tx* snapshot);
/* decode обязателен; arg заимствован до destroy, max_reserve_ms=500..2000. NULL при ошибке. */
struct call_jitter* call_jitter_create(call_jitter_decode_fn decode, void* arg, int max_reserve_ms);
/* Освободить объект; NULL допустим. */