~phablet-team/qtubuntu-camera/video-bitrate

« back to all changes in this revision

Viewing changes to src/aalcameraservice.cpp

  • Committer: Florian Boucault
  • Author(s): Florian Boucault
  • Date: 2015-12-08 15:38:49 UTC
  • mfrom: (161.1.3 unloaded_when_inactive)
  • Revision ID: florian_boucault-20151208153849-mqk1yb7b4owntivq
Fixed QCamera::LoadedState so that it only disables the viewfinder but keeps the camera stack loaded.
Automatically set the state to QCamera::UnloadedState when the application becomes inactive. Restore
state when application becomes active again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include <hybris/camera/camera_compatibility_layer.h>
34
34
 
 
35
#include <QtGui/QGuiApplication>
35
36
#include <QDebug>
36
37
#include <cmath>
37
38
 
40
41
AalCameraService::AalCameraService(QObject *parent):
41
42
    QMediaService(parent),
42
43
    m_androidControl(0),
43
 
    m_androidListener(0)
 
44
    m_androidListener(0),
 
45
    m_restoreStateWhenApplicationActive(false)
44
46
{
45
47
    m_service = this;
46
48
 
58
60
    m_videoOutput = new AalVideoRendererControl(this);
59
61
    m_viewfinderControl = new AalViewfinderSettingsControl(this);
60
62
    m_exposureControl = new AalCameraExposureControl(this);
 
63
 
 
64
    QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance());
 
65
    connect(application, &QGuiApplication::applicationStateChanged,
 
66
            this, &AalCameraService::onApplicationStateChanged);
61
67
}
62
68
 
63
69
AalCameraService::~AalCameraService()
205
211
    }
206
212
}
207
213
 
 
214
bool AalCameraService::isPreviewStarted() const
 
215
{
 
216
    if (m_videoOutput) {
 
217
        return m_videoOutput->isPreviewStarted();
 
218
    } else {
 
219
        return false;
 
220
    }
 
221
}
 
222
 
208
223
bool AalCameraService::isCameraActive() const
209
224
{
210
225
    return m_cameraControl->state() == QCamera::ActiveState;
256
271
        ready = false;
257
272
    if (m_focusControl->isFocusBusy())
258
273
        ready = false;
259
 
    if (!m_videoOutput->isViewfinderRunning())
 
274
    if (!isPreviewStarted())
260
275
        ready = false;
261
276
 
262
277
    m_imageCaptureControl->setReady(ready);
263
278
}
264
279
 
 
280
void AalCameraService::onApplicationStateChanged()
 
281
{
 
282
    QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance());
 
283
    Qt::ApplicationState applicationState = application->applicationState();
 
284
    if (applicationState == Qt::ApplicationActive) {
 
285
        if (m_restoreStateWhenApplicationActive) {
 
286
            m_cameraControl->setState(m_cameraStateWhenApplicationActive);
 
287
        }
 
288
    } else {
 
289
        m_cameraStateWhenApplicationActive = m_cameraControl->state();
 
290
        m_restoreStateWhenApplicationActive = true;
 
291
        m_cameraControl->setState(QCamera::UnloadedState);
 
292
    }
 
293
}
 
294
 
265
295
/*!
266
296
 * \brief AalCameraService::initControls initialize all the controls for a newly
267
297
 * connected camera