winrt: Unload camera when application is suspended.
Camera needs to be unloaded when going to suspend. Otherwise resume from suspend will hang and application will be terminated. Change-Id: Idc8bd47e56c99ebd53a1a4632338cf977317a495 Task-Id: QTBUG-48569 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com>
This commit is contained in:
@@ -43,8 +43,8 @@
|
|||||||
#include "qwinrtcameralockscontrol.h"
|
#include "qwinrtcameralockscontrol.h"
|
||||||
|
|
||||||
#include <QtCore/qfunctions_winrt.h>
|
#include <QtCore/qfunctions_winrt.h>
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
#include <QtCore/QPointer>
|
#include <QtCore/QPointer>
|
||||||
|
#include <QtGui/QGuiApplication>
|
||||||
|
|
||||||
#include <mfapi.h>
|
#include <mfapi.h>
|
||||||
#include <mferror.h>
|
#include <mferror.h>
|
||||||
@@ -547,6 +547,11 @@ QWinRTCameraControl::QWinRTCameraControl(QObject *parent)
|
|||||||
d->imageEncoderControl = new QWinRTImageEncoderControl(this);
|
d->imageEncoderControl = new QWinRTImageEncoderControl(this);
|
||||||
d->cameraFocusControl = new QWinRTCameraFocusControl(this);
|
d->cameraFocusControl = new QWinRTCameraFocusControl(this);
|
||||||
d->cameraLocksControl = new QWinRTCameraLocksControl(this);
|
d->cameraLocksControl = new QWinRTCameraLocksControl(this);
|
||||||
|
|
||||||
|
if (qGuiApp) {
|
||||||
|
connect(qGuiApp, &QGuiApplication::applicationStateChanged,
|
||||||
|
this, &QWinRTCameraControl::onApplicationStateChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QWinRTCameraControl::~QWinRTCameraControl()
|
QWinRTCameraControl::~QWinRTCameraControl()
|
||||||
@@ -778,6 +783,25 @@ void QWinRTCameraControl::onBufferRequested()
|
|||||||
d->mediaSink->RequestSample();
|
d->mediaSink->RequestSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QWinRTCameraControl::onApplicationStateChanged(Qt::ApplicationState state)
|
||||||
|
{
|
||||||
|
Q_D(QWinRTCameraControl);
|
||||||
|
static QCamera::State savedState = d->state;
|
||||||
|
switch (state) {
|
||||||
|
case Qt::ApplicationInactive:
|
||||||
|
if (d->state != QCamera::UnloadedState) {
|
||||||
|
savedState = d->state;
|
||||||
|
setState(QCamera::UnloadedState);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Qt::ApplicationActive:
|
||||||
|
setState(QCamera::State(savedState));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HRESULT QWinRTCameraControl::initialize()
|
HRESULT QWinRTCameraControl::initialize()
|
||||||
{
|
{
|
||||||
Q_D(QWinRTCameraControl);
|
Q_D(QWinRTCameraControl);
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onBufferRequested();
|
void onBufferRequested();
|
||||||
|
void onApplicationStateChanged(Qt::ApplicationState state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HRESULT enumerateDevices();
|
HRESULT enumerateDevices();
|
||||||
|
|||||||
Reference in New Issue
Block a user