134 const QString &description)
136 const auto prevError = std::exchange(m_prevError, error);
138 if (error != QPlatformSurfaceCapture::Error::NoError
139 || prevError != QPlatformSurfaceCapture::Error::NoError) {
140 emit errorUpdated(error, description);
143 updateTimerInterval();
148 using namespace std::chrono;
150 const qreal rate = m_prevError && *m_prevError != QPlatformSurfaceCapture::Error::NoError
151 ? MinScreenCaptureFrameRate
153 const auto interval = round<nanoseconds>(nanoseconds(1s) / rate);
155 if (m_context && m_context->timer.interval() != interval)
156 m_context->timer.setInterval(interval);
161 Q_ASSERT(!isGrabbingContextInitialized());
162 qCDebug(qLcScreenCaptureGrabber) <<
"screen capture started";
164 m_context = std::make_unique<GrabbingContext>();
165 m_context->timer.setTimerType(Qt::PreciseTimer);
166 updateTimerInterval();
168 m_context->elapsedTimer.start();
170 auto doGrab = [
this]() {
171 auto measure = m_context->profiler.measure();
173 auto frame = grabFrame();
175 if (frame.isValid()) {
176 frame.setStartTime(m_context->lastFrameTime);
177 frame.setEndTime(m_context->elapsedTimer.nsecsElapsed() / 1000);
178 m_context->lastFrameTime = frame.endTime();
180 updateError(QPlatformSurfaceCapture::Error::NoError);
182 emit frameGrabbed(frame);
188 m_context->timer.callOnTimeout(&m_context->timer, doGrab);
189 m_context->timer.start();