Retain video mailbox tails and pause raw input under backpressure
This commit is contained in:
1 parent
4ae5a9007b
commit
4b683528fd
3 files changed
+51
-17
No files matched your search
@@ -191,6 +191,10 @@ void CallVideoEngine::transmit() {
|
||||
int64_t reportAt = nowUs(), encodeMax = 0, inputAgeMax = 0;
|
||||
uint64_t captureBase = 0;
|
||||
unsigned encodedCount = 0, keyCount = 0, sendBusy = 0, expired = 0;
|
||||
QList<LiveEncodedFrame> pendingOutputs;
|
||||
call_video_frame pendingPackets[CALL_VIDEO_PORT_TX_FRAMES]{};
|
||||
unsigned pendingCount = 0;
|
||||
uint64_t pendingRevision = 0;
|
||||
uint64_t wakeSerial = 0;
|
||||
auto idle = [this, &wakeSerial] {
|
||||
std::unique_lock<std::mutex> guard(m->lock);
|
||||
@@ -208,6 +212,18 @@ void CallVideoEngine::transmit() {
|
||||
clockCorrection = m->clockCorrection; image = m->capturedImage; wakeSerial = m->wakeSerial;
|
||||
}
|
||||
int64_t now = nowUs();
|
||||
if (pendingCount) {
|
||||
if (!enabled || revision != pendingRevision) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CALL, "video TX cancelled by mode change call=%llu frames=%u",
|
||||
(unsigned long long)m->id, pendingCount);
|
||||
pendingCount = 0; pendingOutputs.clear(); forceKey = true;
|
||||
} else {
|
||||
int sent = call_video_port_send(pendingPackets, pendingCount);
|
||||
if (!sent) { ++sendBusy; idle(); continue; }
|
||||
if (sent < 0) { forceKey = true; m->report(tr("Video transport rejected encoded frames")); }
|
||||
pendingCount = 0; pendingOutputs.clear();
|
||||
}
|
||||
}
|
||||
if (now - reportAt >= 1000000) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG,
|
||||
"video capture flow call=%llu interval_us=%lld captured=%llu encoded=%u keys=%u send_busy=%u "
|
||||
@@ -258,6 +274,7 @@ void CallVideoEngine::transmit() {
|
||||
call_video_port_applied(m->id, format.generation, request, 0);
|
||||
}
|
||||
#ifdef HAVE_STREAM_CAPTURE
|
||||
if (!state.can_encode) { idle(); continue; }
|
||||
if (image.isNull() || nowUs() - pts > CallCameraMaxFrameAgeUs) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CALL, "video TX skips old capture age_us=%lld", (long long)(nowUs() - pts));
|
||||
lastPts = pts; ++expired; continue;
|
||||
@@ -279,8 +296,9 @@ void CallVideoEngine::transmit() {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "GPU output batch exceeds mailbox frames=%lld", (long long)outputs.size());
|
||||
forceKey = true; continue;
|
||||
}
|
||||
call_video_frame packets[CALL_VIDEO_PORT_TX_FRAMES]{}; unsigned count = 0;
|
||||
for (const auto& output : outputs) {
|
||||
pendingOutputs = std::move(outputs); pendingRevision = revision;
|
||||
auto* packets = pendingPackets; unsigned count = 0;
|
||||
for (const auto& output : pendingOutputs) {
|
||||
++encodedCount; if (output.key) ++keyCount;
|
||||
auto& packet = packets[count++];
|
||||
packet.call_id = m->id; packet.frame_id = ++frameId; packet.pts_us = output.pts; packet.format = format;
|
||||
@@ -288,15 +306,15 @@ void CallVideoEngine::transmit() {
|
||||
packet.flags = output.key ? CALL_VIDEO_KEY : 0;
|
||||
}
|
||||
{ std::lock_guard<std::mutex> guard(m->lock);
|
||||
if (!m->running || !m->enabled || m->revision != revision || nowUs() - packets[0].pts_us > CallCameraMaxFrameAgeUs) {
|
||||
if (!m->running || !m->enabled || m->revision != revision) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CALL, "video TX discards obsolete batch revision=%llu/%llu enabled=%d age_us=%lld frames=%u",
|
||||
(unsigned long long)revision, (unsigned long long)m->revision, m->enabled,
|
||||
(long long)(nowUs() - packets[0].pts_us), count);
|
||||
expired += count; forceKey = true; continue;
|
||||
expired += count; forceKey = true; pendingOutputs.clear(); continue;
|
||||
}
|
||||
forceKey = call_video_port_send(packets, count) != 1; }
|
||||
pendingCount = count; forceKey = false; }
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
const auto& output = outputs[i];
|
||||
const auto& output = pendingOutputs[i];
|
||||
// Одинаковое окно исходного PTS на всех этапах: примерно один кадр в секунду, без трассы каждого кадра.
|
||||
if (output.pts % 1000000 < 34000)
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_CALL,
|
||||
|
||||
Reference in new issue
Block a user