Browse Source

perf: Optimize open/close device

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)
pull/4495/head
Diadlo 8 years ago
parent
commit
d704f5d21d
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 18
      src/video/camerasource.cpp

18
src/video/camerasource.cpp

@ -168,15 +168,21 @@ void CameraSource::setupDevice(const QString& DeviceName, const VideoMode& Mode) @@ -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
@ -253,6 +259,10 @@ void CameraSource::openDevice() @@ -253,6 +259,10 @@ void CameraSource::openDevice()
}
QWriteLocker locker{&streamMutex};
if (subscriptions == 0) {
return;
}
qDebug() << "Opening device " << deviceName;
if (device) {
@ -365,6 +375,10 @@ void CameraSource::closeDevice() @@ -365,6 +375,10 @@ void CameraSource::closeDevice()
}
QWriteLocker locker{&streamMutex};
if (subscriptions != 0) {
return;
}
qDebug() << "Closing device " << deviceName;
// Free all remaining VideoFrame

Loading…
Cancel
Save