From 762ff94f67a58df6c7c6315268ea64a2d2151f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludger=20Kr=C3=A4mer?= Date: Tue, 9 Sep 2014 13:46:20 +0200 Subject: implement QVideoProbe for iOS camera This commit allows to use QVideoProbe for QCamera on iOS. The logic for the implementation is taken from the Android plugin. [ChangeLog][Platform Specific Changes][iOS] QVideoProbe support is implemented for QCamera on iOS Change-Id: I1db50defa8518287c4f1f3cc6602881702a95849 Reviewed-by: Yoann Lopes --- .../avfoundation/camera/avfcameraservice.mm | 14 +++++ src/plugins/avfoundation/camera/avfcamerasession.h | 10 ++++ .../avfoundation/camera/avfcamerasession.mm | 27 ++++++++++ .../camera/avfmediavideoprobecontrol.h | 54 +++++++++++++++++++ .../camera/avfmediavideoprobecontrol.mm | 63 ++++++++++++++++++++++ .../avfoundation/camera/avfvideorenderercontrol.mm | 2 + src/plugins/avfoundation/camera/camera.pro | 6 ++- 7 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h create mode 100644 src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm (limited to 'src') diff --git a/src/plugins/avfoundation/camera/avfcameraservice.mm b/src/plugins/avfoundation/camera/avfcameraservice.mm index 25111c5cc..20792000a 100644 --- a/src/plugins/avfoundation/camera/avfcameraservice.mm +++ b/src/plugins/avfoundation/camera/avfcameraservice.mm @@ -54,6 +54,7 @@ #include "avfvideorenderercontrol.h" #include "avfmediarecordercontrol.h" #include "avfimagecapturecontrol.h" +#include "avfmediavideoprobecontrol.h" #include #include @@ -119,6 +120,12 @@ QMediaControl *AVFCameraService::requestControl(const char *name) if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0) return m_imageCaptureControl; + if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) { + AVFMediaVideoProbeControl *videoProbe = 0; + videoProbe = new AVFMediaVideoProbeControl(this); + m_session->addProbe(videoProbe); + return videoProbe; + } if (!m_videoOutput) { if (qstrcmp(name, QVideoRendererControl_iid) == 0) m_videoOutput = new AVFVideoRendererControl(this); @@ -139,6 +146,13 @@ void AVFCameraService::releaseControl(QMediaControl *control) m_session->setVideoOutput(0); delete control; } + AVFMediaVideoProbeControl *videoProbe = qobject_cast(control); + if (videoProbe) { + m_session->removeProbe(videoProbe); + delete videoProbe; + return; + } + } #include "moc_avfcameraservice.cpp" diff --git a/src/plugins/avfoundation/camera/avfcamerasession.h b/src/plugins/avfoundation/camera/avfcamerasession.h index 75ca3f4ce..ec0c746c4 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.h +++ b/src/plugins/avfoundation/camera/avfcamerasession.h @@ -36,6 +36,7 @@ #include #include +#include #import @@ -46,6 +47,7 @@ QT_BEGIN_NAMESPACE class AVFCameraControl; class AVFCameraService; class AVFVideoRendererControl; +class AVFMediaVideoProbeControl; struct AVFCameraInfo { @@ -76,6 +78,9 @@ public: QCamera::State requestedState() const { return m_state; } bool isActive() const { return m_active; } + void addProbe(AVFMediaVideoProbeControl *probe); + void removeProbe(AVFMediaVideoProbeControl *probe); + public Q_SLOTS: void setState(QCamera::State state); @@ -83,6 +88,7 @@ public Q_SLOTS: void processSessionStarted(); void processSessionStopped(); + void onCameraFrameFetched(const QVideoFrame &frame); Q_SIGNALS: void readyToConfigureConnections(); void stateChanged(QCamera::State newState); @@ -107,6 +113,10 @@ private: AVCaptureDeviceInput *m_videoInput; AVCaptureDeviceInput *m_audioInput; AVFCameraSessionObserver *m_observer; + + QSet m_videoProbes; + QMutex m_videoProbesMutex; + }; QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfcamerasession.mm b/src/plugins/avfoundation/camera/avfcamerasession.mm index a72ef5041..3c58c25d6 100644 --- a/src/plugins/avfoundation/camera/avfcamerasession.mm +++ b/src/plugins/avfoundation/camera/avfcamerasession.mm @@ -46,6 +46,7 @@ #include "avfvideorenderercontrol.h" #include "avfvideodevicecontrol.h" #include "avfaudioinputselectorcontrol.h" +#include "avfmediavideoprobecontrol.h" #include #include @@ -371,4 +372,30 @@ void AVFCameraSession::attachInputDevices() } } +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(); +} + +void AVFCameraSession::onCameraFrameFetched(const QVideoFrame &frame) +{ + m_videoProbesMutex.lock(); + QSet::const_iterator i = m_videoProbes.constBegin(); + while (i != m_videoProbes.constEnd()) { + (*i)->newFrameProbed(frame); + ++i; + } + m_videoProbesMutex.unlock(); +} + #include "moc_avfcamerasession.cpp" diff --git a/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h b/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h new file mode 100644 index 000000000..c42b7f7d2 --- /dev/null +++ b/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $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. +** +** 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 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 +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef AVFMEDIAVIDEOPROBECONTROL_H +#define AVFMEDIAVIDEOPROBECONTROL_H + +#include + +QT_BEGIN_NAMESPACE + +class AVFMediaVideoProbeControl : public QMediaVideoProbeControl +{ + Q_OBJECT +public: + explicit AVFMediaVideoProbeControl(QObject *parent = 0); + ~AVFMediaVideoProbeControl(); + + void newFrameProbed(const QVideoFrame& frame); + +}; + +QT_END_NAMESPACE + +#endif // AVFMEDIAVIDEOPROBECONTROL_H diff --git a/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm b/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm new file mode 100644 index 000000000..b4853b61b --- /dev/null +++ b/src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Integrated Computer Solutions, Inc +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt 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$ +** +****************************************************************************/ + +#include "avfmediavideoprobecontrol.h" +#include + +QT_BEGIN_NAMESPACE + +AVFMediaVideoProbeControl::AVFMediaVideoProbeControl(QObject *parent) : + QMediaVideoProbeControl(parent) +{ +} + +AVFMediaVideoProbeControl::~AVFMediaVideoProbeControl() +{ + +} + +void AVFMediaVideoProbeControl::newFrameProbed(const QVideoFrame &frame) +{ + Q_EMIT videoFrameProbed(frame); +} + +QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm b/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm index 1a2054452..369ed473e 100644 --- a/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm +++ b/src/plugins/avfoundation/camera/avfvideorenderercontrol.mm @@ -240,6 +240,8 @@ void AVFVideoRendererControl::syncHandleViewfinderFrame(const QVideoFrame &frame m_lastViewfinderFrame.unmap(); m_lastViewfinderFrame = QVideoFrame(mirrored); } + if (m_cameraSession && m_lastViewfinderFrame.isValid()) + m_cameraSession->onCameraFrameFetched(m_lastViewfinderFrame); } void AVFVideoRendererControl::handleViewfinderFrame() diff --git a/src/plugins/avfoundation/camera/camera.pro b/src/plugins/avfoundation/camera/camera.pro index 1dac45f86..2cd3d56a5 100644 --- a/src/plugins/avfoundation/camera/camera.pro +++ b/src/plugins/avfoundation/camera/camera.pro @@ -34,7 +34,8 @@ HEADERS += \ avfstoragelocation.h \ avfvideodevicecontrol.h \ avfaudioinputselectorcontrol.h \ - avfcamerainfocontrol.h + avfcamerainfocontrol.h \ + avfmediavideoprobecontrol.h OBJECTIVE_SOURCES += \ avfcameraserviceplugin.mm \ @@ -48,5 +49,6 @@ OBJECTIVE_SOURCES += \ avfstoragelocation.mm \ avfvideodevicecontrol.mm \ avfaudioinputselectorcontrol.mm \ - avfcamerainfocontrol.mm + avfcamerainfocontrol.mm \ + avfmediavideoprobecontrol.mm -- cgit v1.2.3