Remove obsolete audio batch delay controller

This commit is contained in:
evgeny committed 2026-10-30 19:21:46 +01:00
1 parent a3bacc9844
commit 7c48567716
3 files changed
+5 -121

No files matched your search

-54
View File
@@ -1,5 +1,4 @@
#include "call_audio_batch.h"
#include "../routing_layer/etcp_router.h"
#include "../../lib/debug_config.h"
#include <string.h>
@@ -50,56 +49,3 @@ int call_audio_batch_parse(const uint8_t *wire, size_t length, struct call_audio
invalid:
DEBUG_WARN(DEBUG_CATEGORY_CALL, "audio batch RX malformed bytes=%zu", length); return -1;
}
void call_audio_batch_init(struct call_audio_batch_control *c, uint64_t now) {
if (!c) { DEBUG_ERROR(DEBUG_CATEGORY_CALL, "audio batch reset without state"); return; }
*c = (struct call_audio_batch_control){.target = 4, .hold_us = 60000, .last_us = now};
}
int call_audio_batch_step(struct call_audio_batch_control *c, uint64_t now, const struct ETCP_ROUTER_TX_STATS *net) {
if (!c || !c->target || now < c->last_us || (net && net->last_ack_us > now)) {
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "audio batch invalid control sample time=%llu", (unsigned long long)now); return -1;
}
unsigned previous = c->target;
if ((!net && (c->local_epoch || c->peer_epoch || c->feedback_received))
|| (net && (net->local_epoch != c->local_epoch || net->peer_epoch != c->peer_epoch))) {
call_audio_batch_init(c, now);
if (net) { c->local_epoch = net->local_epoch; c->peer_epoch = net->peer_epoch; }
DEBUG_DEBUG(DEBUG_CATEGORY_CALL, "audio batch reset router epoch=%llx/%llx previous=%u",
(unsigned long long)c->local_epoch, (unsigned long long)c->peer_epoch, previous);
}
c->last_us = now;
c->delay_us = net ? net->delivery_rtt_us : 0;
if (net && net->queued_age_us > c->delay_us) c->delay_us = net->queued_age_us;
if (net && net->inflight_age_us > c->delay_us) c->delay_us = net->inflight_age_us;
uint64_t interval = net && net->delivery_rtt_us > 250000 ? net->delivery_rtt_us * 2 : 500000;
uint64_t fresh_us = interval > 2000000 ? interval : 2000000;
int measured = net && net->ready && !net->no_route && !net->receive_busy && !net->probing
&& net->acked_packets && now - net->last_ack_us <= fresh_us;
if (measured) c->feedback_received = 1;
int usable = measured && net->window.valid;
const char *reason = "hold";
if (!usable) { c->high = c->low = 0; reason = "unavailable"; }
else if (c->delay_us > 100000) {
c->low = 0;
if (!c->high) { c->high = 1; c->high_since_us = now; }
if (c->target < CALL_AUDIO_BATCH_MAX && now >= c->next_change_us && now - c->high_since_us >= 200000) {
c->target++; c->next_change_us = now + interval; reason = "enqueue_ack_delay";
}
} else if (c->delay_us < 40000 && !net->queued_packets) {
c->high = 0;
if (!c->low) { c->low = 1; c->low_since_us = now; }
if (c->target > 1 && now >= c->next_change_us && now - c->low_since_us >= 2000000) {
c->target--; c->next_change_us = now + interval; c->low_since_us = now; reason = "recovered";
}
} else c->high = c->low = 0;
/* Даже при медленном снижении target быстрый канал сразу перестаёт ждать накопления. */
unsigned budget = c->delay_us > 40000 ? (unsigned)((c->delay_us - 40000) / 4 > 40000 ? 40000 : (c->delay_us - 40000) / 4) : 0;
unsigned target_wait = (c->target - 1) * 20000;
int starting = !c->feedback_received && (!net || (!net->no_route && !net->receive_busy && !net->probing));
c->hold_us = measured ? (target_wait < budget ? target_wait : budget) : (starting ? 60000 : 0);
if (c->target != previous) DEBUG_INFO(DEBUG_CATEGORY_CALL,
"audio batch target=%u->%u reason=%s delay_us=%llu router_rtt_us=%llu queued_us=%llu flight_us=%llu hold_us=%u",
previous, c->target, reason, (unsigned long long)c->delay_us, (unsigned long long)(net ? net->delivery_rtt_us : 0),
(unsigned long long)(net ? net->queued_age_us : 0), (unsigned long long)(net ? net->inflight_age_us : 0), c->hold_us);
return 0;
}
+2 -16
View File
@@ -1,6 +1,5 @@
/* Упаковка Opus и регулятор пачек звонка. Только uasync; wire views заимствуют входной буфер.
* Контроллер использует полный Router enqueue->ACK, не вычитает базовый RTT.
* Владелец снимает статистику каждые 50мс, ограничивает ожидание пачки hold_us и отменяет свои таймеры. */
/* Упаковка Opus звонка: 1..10 кадров, не более 1024 байт. Wire views заимствуют входной буфер.
* call.c собирает доступные кадры по готовности Router, без отдельного ожидания наполнения. */
#ifndef CALL_AUDIO_BATCH_H
#define CALL_AUDIO_BATCH_H
#include "call_proto.h"
@@ -8,7 +7,6 @@
#ifdef __cplusplus
extern "C" {
#endif
struct ETCP_ROUTER_TX_STATS;
struct call_audio_frame_view {
struct call_pkt_audio_frame header; /* Исходные seq/PTS/length; payload не копируется. */
const uint8_t *opus; /* Не менее length байт до конца encode/потребления view. */
@@ -17,22 +15,10 @@ struct call_audio_batch_view {
struct call_pkt_media header; /* Общие поля; count определяет число frames. */
struct call_audio_frame_view frames[CALL_AUDIO_BATCH_MAX];
};
struct call_audio_batch_control {
uint64_t local_epoch, peer_epoch, last_us, high_since_us, low_since_us, next_change_us;
uint64_t delay_us; /* max полного RTT и возраста Router-очередей; собственное накопление сюда не входит. */
unsigned target, hold_us; /* 1..10 кадров; старт4/60000мкс, после измерения 0..40000мкс. */
int feedback_received; /* Есть первый пригодный ACK в текущей Router epoch. */
int high, low;
};
/* Encode/parse: 0/-1. Проверяют весь пакет до изменения out/length/view; ошибки логируются.
* Encode не допускает перекрытие output с Opus; capacity >= вычисленного размера, максимум 1024. */
int call_audio_batch_encode(const struct call_audio_batch_view *batch, uint8_t *out, size_t capacity, size_t *length);
int call_audio_batch_parse(const uint8_t *wire, size_t length, struct call_audio_batch_view *out);
/* Начать с четырёх кадров и deadline60мс до первого измерения ACK. Reset нужен на каждый новый звонок. */
void call_audio_batch_init(struct call_audio_batch_control *control, uint64_t now_us);
/* Снимок NULL — канал пока отсутствует. Смена эпохи сбрасывает историю; 0/-1.
* BLOCKED/нет свежих ACK: рост запрещён. Значения порогов и причин смены пишет DEBUG_CATEGORY_CALL. */
int call_audio_batch_step(struct call_audio_batch_control *control, uint64_t now_us, const struct ETCP_ROUTER_TX_STATS *net);
#ifdef __cplusplus
}
#endif
+3 -51
View File
@@ -1,6 +1,5 @@
/* Wire: границы/атомарный отказ. Регулятор: полный RTT, очередь без ACK, гистерезис и смена эпохи. */
/* Wire: границы размера пачек, полный разбор и атомарный отказ. */
#include "../src/call/call_audio_batch.h"
#include "../src/routing_layer/etcp_router.h"
#include "../lib/debug_config.h"
#include <stdlib.h>
#include <string.h>
@@ -44,57 +43,10 @@ static void wire_test(void) {
CHECK(call_audio_batch_parse(wire, length, &out) == 0 && out.frames[0].header.capture_pts_us == INT64_MIN);
}
static void step(struct call_audio_batch_control *c, struct ETCP_ROUTER_TX_STATS *n, uint64_t t) {
n->last_ack_us = t; CHECK(call_audio_batch_step(c, t, n) == 0);
}
static void control_test(void) {
struct call_audio_batch_control c;
struct ETCP_ROUTER_TX_STATS n = {.local_epoch = 1, .peer_epoch = 2, .ready = 1, .acked_packets = 1,
.delivery_rtt_us = 20000, .window = {.valid = 1}};
call_audio_batch_init(&c, 0);
CHECK(c.target == 4 && c.hold_us == 60000);
CHECK(call_audio_batch_step(&c, 0, NULL) == 0 && c.target == 4 && c.hold_us == 60000);
n.ready = 0; n.acked_packets = 0; n.window.valid = 0;
step(&c, &n, 50000); CHECK(c.target == 4 && c.hold_us == 60000);
n.ready = 1; n.acked_packets = 1;
step(&c, &n, 100000); CHECK(c.target == 4 && c.hold_us == 0); // Первый ACK, не ждём окна500мс.
n.window.valid = 1;
for (unsigned t = 150000; t < 2000000; t += 50000) step(&c, &n, t);
CHECK(c.target == 4 && c.hold_us == 0);
/* Изолированная задержка не включает упаковку. */
n.delivery_rtt_us = 150000; step(&c, &n, 2000000); step(&c, &n, 2050000);
n.delivery_rtt_us = 20000; step(&c, &n, 2100000); CHECK(c.target == 4);
/* Даже без queued/inflight высокий обычный RTT включает пачки. */
n.delivery_rtt_us = 150000;
for (unsigned t = 2150000; t <= 2350000; t += 50000) step(&c, &n, t);
CHECK(c.target == 5 && c.hold_us == 27500);
for (unsigned t = 2400000; t <= 2850000; t += 50000) step(&c, &n, t);
CHECK(c.target == 6 && c.hold_us == 27500);
n.delivery_rtt_us = 300000;
for (unsigned t = 2900000; t <= 9000000; t += 50000) step(&c, &n, t);
CHECK(c.target == 10 && c.hold_us == 40000);
n.delivery_rtt_us = 10000; step(&c, &n, 9050000);
CHECK(c.target == 10 && c.hold_us == 0);
for (unsigned t = 9100000; t <= 11050000; t += 50000) step(&c, &n, t);
CHECK(c.target == 9);
n.peer_epoch = 3; step(&c, &n, 11100000); CHECK(c.target == 4);
n.inflight_age_us = 150000;
for (unsigned t = 11150000; t <= 11350000; t += 50000) step(&c, &n, t);
CHECK(c.target == 5);
n.receive_busy = 1;
for (unsigned t = 11400000; t <= 13000000; t += 50000) step(&c, &n, t);
CHECK(c.target == 5 && c.hold_us == 0);
n.receive_busy = 0; CHECK(call_audio_batch_step(&c, 20000000, &n) == 0 && c.target == 5 && c.hold_us == 0);
CHECK(call_audio_batch_step(&c, 19999999, &n) == -1);
CHECK(call_audio_batch_step(&c, 20000001, NULL) == 0 && c.target == 4 && c.hold_us == 60000);
n.inflight_age_us = 0;
for (unsigned t = 20100000; t <= 27000000; t += 50000) step(&c, &n, t);
CHECK(c.target == 1 && c.hold_us == 0);
}
int main(void) {
debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR);
wire_test(); control_test();
wire_test();
debug_set_level(DEBUG_LEVEL_INFO);
DEBUG_INFO(DEBUG_CATEGORY_CALL, "PASS audio batch: 1..10, partial/trailing/invalid wire, full RTT, hysteresis, deadline budget, epochs/stall");
DEBUG_INFO(DEBUG_CATEGORY_CALL, "PASS audio batch: 1..10, partial/trailing/invalid wire, atomic output");
return 0;
}