Commit 2492954f authored by Thiago Santini's avatar Thiago Santini

Adds mutex protection for surface access

parent 72b37013
......@@ -27,12 +27,13 @@ void UVCCameraSession::setDevice(uvc_device_t *device)
void UVCCameraSession::setSurface(QAbstractVideoSurface* surface)
{
QMutexLocker locker(&surfaceMutex);
m_surface = surface;
}
// If the following is defined, frame grabbing is performed by the callback thread
//#define BLOCKING_FRAME_GRABBING
void cb(uvc_frame_t *frame, void *ptr) { static_cast<UVCCameraSession*>(ptr)->callback(frame); }
void cb(uvc_frame_t *frame, void *ptr) { if (ptr && frame) static_cast<UVCCameraSession*>(ptr)->callback(frame); }
void UVCCameraSession::callback(uvc_frame_t *frame)
{
qreal t = frameReference.elapsed();
......@@ -40,6 +41,7 @@ void UVCCameraSession::callback(uvc_frame_t *frame)
if (!streaming)
return;
QMutexLocker locker(&surfaceMutex);
if (m_surface) {
QVideoFrame qFrame;
switch(frame->frame_format) {
......@@ -55,7 +57,7 @@ void UVCCameraSession::callback(uvc_frame_t *frame)
#ifdef BLOCKING_FRAME_GRABBING
m_surface->present( qFrame );
#else
QMetaObject::invokeMethod(this, "presentFrame", Qt::QueuedConnection, Q_ARG(QVideoFrame, qFrame), Q_ARG(const qreal, t) );
QMetaObject::invokeMethod(this, "presentFrame", Qt::QueuedConnection, Q_ARG(const QVideoFrame&, qFrame), Q_ARG(const qreal, t) );
#endif
}
}
......@@ -64,7 +66,7 @@ void UVCCameraSession::presentFrame(QVideoFrame frame, const qreal t)
{
qreal latency = frameReference.elapsed() - t;
frame.setMetaData("timestamp", t);
if (latency <= MAX_LATENCY_MS)
if (latency <= MAX_LATENCY_MS && m_surface)
m_surface->present(frame);
//else
// qWarning() << "Dropping frame (" << latency << "ms old )";
......
......@@ -61,6 +61,7 @@ private:
float bandwidthFactor;
QCamera::Status m_status;
QAbstractVideoSurface *m_surface;
QMutex surfaceMutex;
// Source (camera)
uvc_device_t *dev;
......@@ -83,6 +84,7 @@ private:
bool isPupilFieldCamera();
bool isPupilEyeCamera();
};
QT_END_NAMESPACE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment