Bound video encoder commands and verify generation-safe feedback

This commit is contained in:
evgeny committed 2026-10-14 20:53:53 +02:00
1 parent 23bd954b79
commit ed848f94eb
2 files changed
+33 -4

No files matched your search

+13 -2
View File
@@ -24,7 +24,7 @@ struct call_video_transport {
int have_peer, need_key;
struct call_video_rate rate;
struct route_tx_meter production;
uint64_t rate_generation, rate_request, produced_id, route_local_epoch, route_peer_epoch;
uint64_t rate_generation, rate_request, produced_id, route_local_epoch, route_peer_epoch, rate_requested_us;
uint32_t applied_bps, maximum_bps;
int rate_pending, admit;
};
@@ -80,6 +80,12 @@ static void update_rate(struct call_video_transport *v) {
if (!v->rate_generation || !v->applied_bps) return;
struct call_session *s = v->session;
uint64_t now = get_time_us();
if (v->rate_pending && now - v->rate_requested_us > 2000000) {
v->rate_pending = 0; v->applied_bps = 0; v->admit = 0;
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "video encoder command timeout call=%llu generation=%llu request=%llu",
(unsigned long long)s->call_id, (unsigned long long)v->rate_generation, (unsigned long long)v->rate_request);
return;
}
struct ETCP_ROUTER_TX_STATS net = {0};
int found = etcp_router_tx_stats(s->ctx->inst, s->group_id, s->peer_node_id, ETCP_RT_ID_CALL_VIDEO, now, &net) == 0;
if (found && (net.local_epoch != v->route_local_epoch || net.peer_epoch != v->route_peer_epoch)) {
@@ -109,7 +115,7 @@ static void update_rate(struct call_video_transport *v) {
if (call_video_rate_step(&v->rate, &sample, &result)) { v->admit = 0; return; }
v->admit = result.admit;
if (result.target_bps != v->applied_bps && v->ops.bitrate) {
v->rate_pending = 1; ++v->rate_request;
v->rate_pending = 1; ++v->rate_request; v->rate_requested_us = now;
v->ops.bitrate(v->arg, v->rate_generation, v->rate_request, result.target_bps);
}
}
@@ -204,6 +210,11 @@ int call_video_send_frame(struct UTUN_INSTANCE *inst, const struct call_video_fr
if (!v->admit) { v->need_key = 1; return 0; }
}
if (v->data) { v->need_key = 1; return 0; }
struct ETCP_ROUTER_TX_STATS net;
if (etcp_router_tx_stats(inst, s->group_id, s->peer_node_id, ETCP_RT_ID_CALL_VIDEO, get_time_us(), &net) == 0) {
uint64_t debt = media_bytes(net.queued_bytes + net.inflight_bytes, (uint64_t)net.queued_packets + net.inflight_packets);
if (debt + f->size > CALL_VIDEO_MAX_FRAME) { v->need_key = 1; return 0; }
}
int changed = !call_video_same_format(&f->format, &v->tx.format);
if (f->format.generation < v->tx.format.generation || (changed && f->format.generation == v->tx.format.generation)) {
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "video TX format changed without new generation"); return -1;