1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Faster video device opening

This commit is contained in:
tux3 2015-10-24 05:19:23 +02:00
parent e1c61cd207
commit 50006a9a32
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 11 additions and 3 deletions

View File

@ -37,7 +37,7 @@ CameraSource* CameraSource::instance{nullptr};
CameraSource::CameraSource()
: deviceName{"none"}, device{nullptr}, mode(VideoMode{0,0,0}),
cctx{nullptr}, cctxOrig{nullptr}, videoStreamIndex{-1},
_isOpen{false}, subscriptions{0}
_isOpen{false}, streamBlocker{false}, subscriptions{0}
{
subscriptions = 0;
av_register_all();
@ -72,10 +72,14 @@ void CameraSource::open(const QString deviceName)
void CameraSource::open(const QString DeviceName, VideoMode Mode)
{
streamBlocker = true;
QMutexLocker l{&biglock};
if (DeviceName == deviceName && Mode == mode)
{
streamBlocker = false;
return;
}
if (subscriptions)
closeDevice();
@ -86,6 +90,8 @@ void CameraSource::open(const QString DeviceName, VideoMode Mode)
if (subscriptions && _isOpen)
openDevice();
streamBlocker = false;
}
void CameraSource::close()
@ -348,6 +354,8 @@ void CameraSource::stream()
// Give a chance to other functions to pick up the lock if needed
biglock.unlock();
while (streamBlocker)
QThread::yieldCurrentThread();
QThread::yieldCurrentThread();
}
}

View File

@ -93,6 +93,7 @@ private:
int videoStreamIndex; ///< A camera can have multiple streams, this is the one we're decoding
QMutex biglock, freelistLock; ///< True when locked. Faster than mutexes for video decoding.
std::atomic_bool _isOpen;
std::atomic_bool streamBlocker; ///< Holds the streaming thread still when true
std::atomic_int subscriptions; ///< Remember how many times we subscribed for RAII
static CameraSource* instance;

View File

@ -204,14 +204,13 @@ void AVForm::onVideoDevChanged(int index)
qWarning() << "Invalid index";
return;
}
QString dev = videoDeviceList[index].first;
Settings::getInstance().setVideoDev(dev);
bool previouslyBlocked = bodyUI->videoModescomboBox->blockSignals(true);
updateVideoModes(index);
bodyUI->videoModescomboBox->blockSignals(previouslyBlocked);
camera.open(dev);
killVideoSurface();
createVideoSurface();
if (dev == "none")
Core::getInstance()->getAv()->sendNoVideo();
}