diff --git a/tools/chatgui/src/call_video_engine.cpp b/tools/chatgui/src/call_video_engine.cpp index f69675e9..469d379e 100644 --- a/tools/chatgui/src/call_video_engine.cpp +++ b/tools/chatgui/src/call_video_engine.cpp @@ -35,7 +35,8 @@ struct CallVideoEngine::Impl { uint64_t captured = 0; QImage shown; uint64_t shownSerial = 0, deliveredSerial = 0; - int64_t previewPts = -1, previewAt = 0; + int64_t previewPts = -1, previewReportAt = 0, previewMaxUs = 0; + unsigned previewFrames = 0; bool previewVisible = false; QString status; bool statusDirty = false; @@ -52,6 +53,7 @@ struct CallVideoEngine::Impl { }; CallVideoEngine::CallVideoEngine(QObject* parent) : QObject(parent), m(std::make_unique()) { m_timer.setInterval(20); + m_timer.setTimerType(Qt::PreciseTimer); connect(&m_timer, &QTimer::timeout, this, [this] { QImage image; QString status; bool changed = false, report = false; { std::lock_guard guard(m->lock); @@ -64,8 +66,8 @@ CallVideoEngine::CallVideoEngine(QObject* parent) : QObject(parent), m(std::make int64_t now = nowUs(); { std::lock_guard guard(m->lock); if (!m->enabled && m->previewVisible) { m->previewVisible = false; clear = true; } - if (m->enabled && m->raw.isValid() && m->pts != m->previewPts && now - m->previewAt >= 100000) { - preview = m->raw; m->previewPts = m->pts; m->previewAt = now; + if (m->enabled && m->raw.isValid() && m->pts != m->previewPts) { + preview = m->raw; m->previewPts = m->pts; } } if (clear) emit localImageChanged({}); if (preview.isValid()) { @@ -73,8 +75,15 @@ CallVideoEngine::CallVideoEngine(QObject* parent) : QObject(parent), m(std::make if (!local.isNull()) { m->previewVisible = true; emit localImageChanged(local.scaled(320, 240, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + ++m->previewFrames; + m->previewMaxUs = std::max(m->previewMaxUs, nowUs() - now); } else DEBUG_WARN(DEBUG_CATEGORY_CALL, "call camera preview conversion failed"); } + if (m->previewVisible && now - m->previewReportAt >= 1000000) { + DEBUG_DEBUG(DEBUG_CATEGORY_CALL, "video local preview call=%llu interval_us=%lld frames=%u update_max_us=%lld", + (unsigned long long)m->id, (long long)(now - m->previewReportAt), m->previewFrames, (long long)m->previewMaxUs); + m->previewReportAt = now; m->previewFrames = 0; m->previewMaxUs = 0; + } #endif }); } @@ -99,7 +108,8 @@ void CallVideoEngine::closeCamera() { m->capture.reset(); m->camera.reset(); m->sink.reset(); { std::lock_guard guard(m->lock); m->raw = {}; m->pts = m->backend = m->anchor = -1; } #endif - m->previewPts = -1; m->previewVisible = false; emit localImageChanged({}); + m->previewPts = -1; m->previewVisible = false; m->previewReportAt = nowUs(); m->previewFrames = 0; m->previewMaxUs = 0; + emit localImageChanged({}); } void CallVideoEngine::stop() { m->running = false; m_timer.stop(); closeCamera(); @@ -127,6 +137,10 @@ void CallVideoEngine::setVideo(bool enabled, const QByteArray& cameraId, int wid if (score < distance) { best = f; distance = score; } } if (!best.isNull()) m->camera->setCameraFormat(best); + const auto selectedFormat = m->camera->cameraFormat(); + DEBUG_INFO(DEBUG_CATEGORY_CALL, "call camera selected device=%s size=%dx%d pixel=%d fps=%.3f..%.3f", + selected.id().constData(), selectedFormat.resolution().width(), selectedFormat.resolution().height(), + selectedFormat.pixelFormat(), selectedFormat.minFrameRate(), selectedFormat.maxFrameRate()); connect(m->sink.get(), &QVideoSink::videoFrameChanged, this, [this, revision](const QVideoFrame& frame) { if (!frame.isValid() || !m->running) return; std::lock_guard guard(m->lock);