implement QVideoProbe for iOS camera
authorLudger Krämer <kraemer@dem-gmbh.de>
Tue, 9 Sep 2014 11:46:20 +0000 (13:46 +0200)
committerYoann Lopes <yoann.lopes@digia.com>
Fri, 12 Sep 2014 15:57:52 +0000 (17:57 +0200)
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 <yoann.lopes@digia.com>
src/plugins/avfoundation/camera/avfcameraservice.mm
src/plugins/avfoundation/camera/avfcamerasession.h
src/plugins/avfoundation/camera/avfcamerasession.mm
src/plugins/avfoundation/camera/avfmediavideoprobecontrol.h [new file with mode: 0644]
src/plugins/avfoundation/camera/avfmediavideoprobecontrol.mm [new file with mode: 0644]
src/plugins/avfoundation/camera/avfvideorenderercontrol.mm
src/plugins/avfoundation/camera/camera.pro

index 25111c5..2079200 100644 (file)
@@ -54,6 +54,7 @@
 #include "avfvideorenderercontrol.h"
 #include "avfmediarecordercontrol.h"
 #include "avfimagecapturecontrol.h"
+#include "avfmediavideoprobecontrol.h"
 
 #include <private/qmediaplaylistnavigator_p.h>
 #include <qmediaplaylist.h>
@@ -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<AVFMediaVideoProbeControl *>(control);
+    if (videoProbe) {
+        m_session->removeProbe(videoProbe);
+        delete videoProbe;
+        return;
+    }
+
 }
 
 #include "moc_avfcameraservice.cpp"
index 75ca3f4..ec0c746 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <QtCore/qmutex.h>
 #include <QtMultimedia/qcamera.h>
+#include <QVideoFrame>
 
 #import <AVFoundation/AVFoundation.h>
 
@@ -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<AVFMediaVideoProbeControl *> m_videoProbes;
+    QMutex m_videoProbesMutex;
+
 };
 
 QT_END_NAMESPACE
index a72ef50..3c58c25 100644 (file)
@@ -46,6 +46,7 @@
 #include "avfvideorenderercontrol.h"
 #include "avfvideodevicecontrol.h"
 #include "avfaudioinputselectorcontrol.h"
+#include "avfmediavideoprobecontrol.h"
 
 #include <CoreFoundation/CoreFoundation.h>
 #include <Foundation/Foundation.h>
@@ -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<AVFMediaVideoProbeControl *>::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 (file)
index 0000000..c42b7f7
--- /dev/null
@@ -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 <qmediavideoprobecontrol.h>
+
+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 (file)
index 0000000..b4853b6
--- /dev/null
@@ -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 <qvideoframe.h>
+
+QT_BEGIN_NAMESPACE
+
+AVFMediaVideoProbeControl::AVFMediaVideoProbeControl(QObject *parent) :
+    QMediaVideoProbeControl(parent)
+{
+}
+
+AVFMediaVideoProbeControl::~AVFMediaVideoProbeControl()
+{
+
+}
+
+void AVFMediaVideoProbeControl::newFrameProbed(const QVideoFrame &frame)
+{
+    Q_EMIT videoFrameProbed(frame);
+}
+
+QT_END_NAMESPACE
index 1a20544..369ed47 100644 (file)
@@ -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()
index 1dac45f..2cd3d56 100644 (file)
@@ -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