Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
perf: Optimize open/close device
Browse files Browse the repository at this point in the history
Because while device thread wait for a freeing 'streamMutex', in another
thread someone can subscribe or unsubscribe => it will require useless
pair (close + open) or (open + close)
  • Loading branch information
Diadlo committed Jul 5, 2017
1 parent d86912e commit d704f5d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/video/camerasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,21 @@ void CameraSource::setupDevice(const QString& DeviceName, const VideoMode& Mode)
return;
}

if (subscriptions)
if (subscriptions) {
// To force close, ignoring optimization
int subs = subscriptions;
subscriptions = 0;
closeDevice();
subscriptions = subs;
}

deviceName = DeviceName;
mode = Mode;
_isNone = (deviceName == "none");

if (subscriptions && !_isNone)
if (subscriptions && !_isNone) {
openDevice();
}
}

bool CameraSource::isNone() const
Expand Down Expand Up @@ -253,6 +259,10 @@ void CameraSource::openDevice()
}

QWriteLocker locker{&streamMutex};
if (subscriptions == 0) {
return;
}

qDebug() << "Opening device " << deviceName;

if (device) {
Expand Down Expand Up @@ -365,6 +375,10 @@ void CameraSource::closeDevice()
}

QWriteLocker locker{&streamMutex};
if (subscriptions != 0) {
return;
}

qDebug() << "Closing device " << deviceName;

// Free all remaining VideoFrame
Expand Down

0 comments on commit d704f5d

Please sign in to comment.