Preserve bitrate bounds on format changes and discard late desktop pictures

This commit is contained in:
evgeny committed 2026-10-14 23:19:18 +02:00
1 parent 047927a7a5
commit 5f16c79559
2 files changed
+12 -4

No files matched your search

+7 -2
View File
@@ -179,10 +179,13 @@ void CallVideoEngine::transmit() {
if (lastKey >= 0 && pts - lastKey < 1000000) { idle(); continue; }
call_video_format next{format.generation + 1, (uint16_t)width, (uint16_t)height, 30, 0, (uint8_t)codec, 0, 4000000, 0};
bool opened = false;
uint32_t minimum = state.minimum_bps ? state.minimum_bps : 300000;
uint32_t maximum = state.maximum_bps ? state.maximum_bps : 4000000;
uint32_t initialRate = std::max(minimum, std::min(maximum, encoder.bitrate() ? encoder.bitrate() : 1000000));
for (int candidate = 2; candidate >= 1; --candidate) {
if ((codec && codec != candidate) || (excluded & (1u << candidate))) continue;
next.codec = candidate; next.level = next.profile = 0;
if (call_video_choose(&caps, &state.peer, &next) > 0 && encoder.open(next, 1000000)) { opened = true; break; }
if (call_video_choose(&caps, &state.peer, &next) > 0 && encoder.open(next, initialRate)) { opened = true; break; }
}
if (!opened) {
m->report(tr("Selected video mode is unavailable to the peer"));
@@ -240,7 +243,9 @@ void CallVideoEngine::receive() {
sourceEpoch = clock.source_epoch;
QImage selected;
while (!pictures.empty() && pictures.front().pts <= clock.pts_us) {
if (pictures.front().pts > lastShown) { selected = pictures.front().image; lastShown = pictures.front().pts; }
if (pictures.front().pts > lastShown && pictures.front().pts >= clock.pts_us - 500000) {
selected = pictures.front().image; lastShown = pictures.front().pts;
}
pictures.pop_front();
}
if (!selected.isNull()) { std::lock_guard<std::mutex> guard(m->lock); m->shown = selected; ++m->shownSerial; ++shown; }