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

Better freeing of CameraSource

This commit is contained in:
tux3 2015-06-26 19:04:53 +02:00
parent 89080b949e
commit 9e55c77849
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 14 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "src/persistence/profilelocker.h" #include "src/persistence/profilelocker.h"
#include "src/widget/loginscreen.h" #include "src/widget/loginscreen.h"
#include "src/widget/translator.h" #include "src/widget/translator.h"
#include "src/video/camerasource.h"
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QDateTime> #include <QDateTime>
@ -275,6 +276,7 @@ int main(int argc, char *argv[])
logFile = nullptr; logFile = nullptr;
#endif #endif
CameraSource::destroyInstance();
Nexus::destroyInstance(); Nexus::destroyInstance();
Settings::destroyInstance(); Settings::destroyInstance();
qDebug() << "Clean exit with status"<<errorcode; qDebug() << "Clean exit with status"<<errorcode;

View File

@ -51,6 +51,15 @@ CameraSource& CameraSource::getInstance()
return *instance; return *instance;
} }
void CameraSource::destroyInstance()
{
if (instance)
{
delete instance;
instance = nullptr;
}
}
void CameraSource::open() void CameraSource::open()
{ {
open(CameraDevice::getDefaultDeviceName()); open(CameraDevice::getDefaultDeviceName());
@ -293,6 +302,8 @@ void CameraSource::closeDevice()
continue; continue;
vframe->releaseFrame(); vframe->releaseFrame();
} }
freelist.clear();
freelist.squeeze();
// Free our resources and close the device // Free our resources and close the device
videoStreamIndex = -1; videoStreamIndex = -1;

View File

@ -47,6 +47,7 @@ class CameraSource : public VideoSource
Q_OBJECT Q_OBJECT
public: public:
static CameraSource& getInstance(); static CameraSource& getInstance();
static void destroyInstance();
/// Opens the source for the camera device in argument, in the settings, or the system default /// Opens the source for the camera device in argument, in the settings, or the system default
/// If a device is already open, the source will seamlessly switch to the new device /// If a device is already open, the source will seamlessly switch to the new device
void open(); void open();