diff --git a/src/call/call_audio_history.h b/src/call/call_audio_history.h index e2719e2a6..1f35d9974 100644 --- a/src/call/call_audio_history.h +++ b/src/call/call_audio_history.h @@ -21,6 +21,7 @@ struct call_history_rx { struct call_history_tx { uint64_t at_ms, queued_bytes, inflight_bytes, transport_bytes; uint64_t peer_id, tx_epoch, wire_tx_bytes; /* Текущий путь звонка: разность счётчиков только при одинаковых peer/epoch. */ + double wire_bytes_per_sec; /* Среднее за последние <=1с; -1 — нет пары измерений одного пути. */ }; struct call_audio_history { uint64_t now_ms; diff --git a/src/call/call_history_store.h b/src/call/call_history_store.h index 9070ef9f8..1dc1be1a3 100644 --- a/src/call/call_history_store.h +++ b/src/call/call_history_store.h @@ -59,5 +59,14 @@ public: const auto& p = tx[(txNext + CALL_HISTORY_POINTS - txUsed + i) % CALL_HISTORY_POINTS]; if (p.at_ms <= now && now - p.at_ms < CALL_HISTORY_MS) out.tx[out.tx_count++] = p; } + for (unsigned i = 0; i < out.tx_count; ++i) { + auto& p = out.tx[i]; unsigned first = i; p.wire_bytes_per_sec = -1; + while (first && p.peer_id && out.tx[first - 1].peer_id == p.peer_id && out.tx[first - 1].tx_epoch == p.tx_epoch + && p.at_ms - out.tx[first - 1].at_ms <= 1000 && out.tx[first].at_ms - out.tx[first - 1].at_ms <= 150) + --first; + const auto& previous = out.tx[first]; + if (first < i && p.at_ms > previous.at_ms && p.wire_tx_bytes >= previous.wire_tx_bytes) + p.wire_bytes_per_sec = (p.wire_tx_bytes - previous.wire_tx_bytes) * 1000.0 / (p.at_ms - previous.at_ms); + } } };