summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation/camera/avfcamerasession.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/avfoundation/camera/avfcamerasession.mm')
-rw-r--r--src/plugins/avfoundation/camera/avfcamerasession.mm120
1 files changed, 95 insertions, 25 deletions
diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm
index d0bb0e51a..6e4803f30 100644
--- a/src/plugins/avfoundation/camera/avfcamerasession.mm
+++ b/src/plugins/avfoundation/camera/avfcamerasession.mm
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -43,9 +35,13 @@
#include "avfcamerasession.h"
#include "avfcameraservice.h"
#include "avfcameracontrol.h"
-#include "avfvideorenderercontrol.h"
-#include "avfvideodevicecontrol.h"
+#include "avfcamerarenderercontrol.h"
+#include "avfcameradevicecontrol.h"
#include "avfaudioinputselectorcontrol.h"
+#include "avfmediavideoprobecontrol.h"
+#include "avfcameraviewfindersettingscontrol.h"
+#include "avfimageencodercontrol.h"
+#include "avfcamerautility.h"
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
@@ -147,6 +143,7 @@ AVFCameraSession::AVFCameraSession(AVFCameraService *service, QObject *parent)
, m_state(QCamera::UnloadedState)
, m_active(false)
, m_videoInput(nil)
+ , m_defaultCodec(0)
{
m_captureSession = [[AVCaptureSession alloc] init];
m_observer = [[AVFCameraSessionObserver alloc] initWithCameraSession:this];
@@ -247,7 +244,7 @@ void AVFCameraSession::updateCameraDevices()
#endif
}
-void AVFCameraSession::setVideoOutput(AVFVideoRendererControl *output)
+void AVFCameraSession::setVideoOutput(AVFCameraRendererControl *output)
{
m_videoOutput = output;
if (output)
@@ -288,6 +285,10 @@ void AVFCameraSession::setState(QCamera::State newState)
Q_EMIT readyToConfigureConnections();
[m_captureSession commitConfiguration];
[m_captureSession startRunning];
+ m_defaultCodec = 0;
+ defaultCodec();
+ applyImageEncoderSettings();
+ applyViewfinderSettings();
}
if (oldState == QCamera::ActiveState) {
@@ -354,4 +355,73 @@ void AVFCameraSession::attachVideoInputDevice()
}
}
+void AVFCameraSession::applyImageEncoderSettings()
+{
+ if (AVFImageEncoderControl *control = m_service->imageEncoderControl())
+ control->applySettings();
+}
+
+void AVFCameraSession::applyViewfinderSettings()
+{
+ if (AVFCameraViewfinderSettingsControl2 *vfControl = m_service->viewfinderSettingsControl2()) {
+ QCameraViewfinderSettings vfSettings(vfControl->requestedSettings());
+ if (AVFImageEncoderControl *imControl = m_service->imageEncoderControl()) {
+ const QSize imageResolution(imControl->imageSettings().resolution());
+ if (!imageResolution.isNull() && imageResolution.isValid()) {
+ vfSettings.setResolution(imageResolution);
+ vfControl->setViewfinderSettings(vfSettings);
+ return;
+ }
+ }
+
+ if (!vfSettings.isNull())
+ vfControl->applySettings();
+ }
+}
+
+void AVFCameraSession::addProbe(AVFMediaVideoProbeControl *probe)
+{
+ m_videoProbesMutex.lock();
+ if (probe)
+ m_videoProbes << probe;
+ m_videoProbesMutex.unlock();
+}
+
+void AVFCameraSession::removeProbe(AVFMediaVideoProbeControl *probe)
+{
+ m_videoProbesMutex.lock();
+ m_videoProbes.remove(probe);
+ m_videoProbesMutex.unlock();
+}
+
+FourCharCode AVFCameraSession::defaultCodec()
+{
+ if (!m_defaultCodec) {
+#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_7, __IPHONE_7_0)
+ if (QSysInfo::MacintoshVersion >= qt_OS_limit(QSysInfo::MV_10_7, QSysInfo::MV_IOS_7_0)) {
+ if (AVCaptureDevice *device = videoCaptureDevice()) {
+ AVCaptureDeviceFormat *format = device.activeFormat;
+ if (!format || !format.formatDescription)
+ return m_defaultCodec;
+ m_defaultCodec = CMVideoFormatDescriptionGetCodecType(format.formatDescription);
+ }
+ }
+#else
+ // TODO: extract media subtype.
+#endif
+ }
+ return m_defaultCodec;
+}
+
+void AVFCameraSession::onCameraFrameFetched(const QVideoFrame &frame)
+{
+ m_videoProbesMutex.lock();
+ QSet<AVFMediaVideoProbeControl *>::const_iterator i = m_videoProbes.constBegin();
+ while (i != m_videoProbes.constEnd()) {
+ (*i)->newFrameProbed(frame);
+ ++i;
+ }
+ m_videoProbesMutex.unlock();
+}
+
#include "moc_avfcamerasession.cpp"