AVFoundation: re-apply viewfinder settings on mode changes.

Since the active viewfinder resolution can be overridden by the image
and video capture resolutions, we need to re-evaluate the viewfinder
settings whenever the capture mode changes.

Change-Id: Ibdb7a070585cf67ebb2fcfb95ccbdd105f5f41cf
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
This commit is contained in:
Yoann Lopes
2016-03-10 11:47:24 +01:00
committed by Yoann Lopes
parent c6a8c2c846
commit af5e0d0485
5 changed files with 28 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -47,6 +47,7 @@ AVFCameraControl::AVFCameraControl(AVFCameraService *service, QObject *parent)
{
Q_UNUSED(service);
connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(updateStatus()));
connect(this, &AVFCameraControl::captureModeChanged, m_session, &AVFCameraSession::onCaptureModeChanged);
}
AVFCameraControl::~AVFCameraControl()

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -93,6 +93,8 @@ public Q_SLOTS:
void processSessionStarted();
void processSessionStopped();
void onCaptureModeChanged(QCamera::CaptureModes mode);
void onCameraFrameFetched(const QVideoFrame &frame);
Q_SIGNALS:

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -286,8 +286,8 @@ void AVFCameraSession::setState(QCamera::State newState)
m_defaultCodec = 0;
defaultCodec();
bool activeFormatSet = applyImageEncoderSettings();
activeFormatSet |= applyViewfinderSettings();
bool activeFormatSet = applyImageEncoderSettings()
| applyViewfinderSettings();
[m_captureSession commitConfiguration];
@@ -338,6 +338,17 @@ void AVFCameraSession::processSessionStopped()
}
}
void AVFCameraSession::onCaptureModeChanged(QCamera::CaptureModes mode)
{
Q_UNUSED(mode)
const QCamera::State s = state();
if (s == QCamera::LoadedState || s == QCamera::ActiveState) {
applyImageEncoderSettings();
applyViewfinderSettings();
}
}
void AVFCameraSession::attachVideoInputDevice()
{
//Attach video input device:
@@ -381,11 +392,12 @@ bool AVFCameraSession::applyImageEncoderSettings()
bool AVFCameraSession::applyViewfinderSettings()
{
if (AVFCameraViewfinderSettingsControl2 *vfControl = m_service->viewfinderSettingsControl2()) {
QCamera::CaptureModes currentMode = m_service->cameraControl()->captureMode();
QCameraViewfinderSettings vfSettings(vfControl->requestedSettings());
// Viewfinder and image capture solutions must be the same, if an image capture
// resolution is set, it takes precedence over the viewfinder resolution.
if (AVFImageEncoderControl *imControl = m_service->imageEncoderControl()) {
const QSize imageResolution(imControl->requestedSettings().resolution());
if (currentMode.testFlag(QCamera::CaptureStillImage)) {
const QSize imageResolution(m_service->imageEncoderControl()->requestedSettings().resolution());
if (!imageResolution.isNull() && imageResolution.isValid())
vfSettings.setResolution(imageResolution);
}

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -67,6 +67,7 @@ AVFImageCaptureControl::AVFImageCaptureControl(AVFCameraService *service, QObjec
connect(m_cameraControl, SIGNAL(statusChanged(QCamera::Status)), SLOT(updateReadyStatus()));
connect(m_session, SIGNAL(readyToConfigureConnections()), SLOT(updateCaptureConnection()));
connect(m_cameraControl, SIGNAL(captureModeChanged(QCamera::CaptureModes)), SLOT(updateCaptureConnection()));
connect(m_session, &AVFCameraSession::newViewfinderFrame,
this, &AVFImageCaptureControl::onNewViewfinderFrame,

View File

@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
@@ -38,6 +38,7 @@
#include "avfcamerasession.h"
#include "avfcameraservice.h"
#include "avfcameradebug.h"
#include "avfcameracontrol.h"
#include <QtMultimedia/qmediaencodersettings.h>
@@ -182,7 +183,8 @@ bool AVFImageEncoderControl::applySettings()
AVFCameraSession *session = m_service->session();
if (!session || (session->state() != QCamera::ActiveState
&& session->state() != QCamera::LoadedState)) {
&& session->state() != QCamera::LoadedState)
|| !m_service->cameraControl()->captureMode().testFlag(QCamera::CaptureStillImage)) {
return false;
}