Android: implement QCameraInfoControl.
VideoOutput will now take into account the camera sensor orientation to adjust the viewport orientation, we don't need to apply a rotation on the Android Camera anymore. Change-Id: Ia7639f0a5711ab6cc6f80b9716bc1a6f389499b4 Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
f783c48a17
commit
b2f40ef75d
@@ -22,7 +22,8 @@ SOURCES += \
|
||||
$$PWD/qandroidmediacontainercontrol.cpp \
|
||||
$$PWD/qandroidvideoencodersettingscontrol.cpp \
|
||||
$$PWD/qandroidaudioinputselectorcontrol.cpp \
|
||||
$$PWD/qandroidmediavideoprobecontrol.cpp
|
||||
$$PWD/qandroidmediavideoprobecontrol.cpp \
|
||||
$$PWD/qandroidcamerainfocontrol.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/qandroidcaptureservice.h \
|
||||
@@ -46,4 +47,5 @@ HEADERS += \
|
||||
$$PWD/qandroidmediacontainercontrol.h \
|
||||
$$PWD/qandroidvideoencodersettingscontrol.h \
|
||||
$$PWD/qandroidaudioinputselectorcontrol.h \
|
||||
$$PWD/qandroidmediavideoprobecontrol.h
|
||||
$$PWD/qandroidmediavideoprobecontrol.h \
|
||||
$$PWD/qandroidcamerainfocontrol.h
|
||||
|
||||
@@ -46,36 +46,15 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
static QPointF rotateNormalizedPoint(const QPointF &point, int rotation)
|
||||
{
|
||||
const qreal one(1.0f);
|
||||
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
default:
|
||||
return point;
|
||||
case 90:
|
||||
return QPointF(point.y(), one - point.x());
|
||||
case 180:
|
||||
return QPointF(one - point.x(), one - point.y());
|
||||
case 270:
|
||||
return QPointF(one - point.y(), point.x());
|
||||
}
|
||||
}
|
||||
|
||||
static QRect adjustedArea(const QRectF &area, int rotation)
|
||||
static QRect adjustedArea(const QRectF &area)
|
||||
{
|
||||
// Qt maps focus points in the range (0.0, 0.0) -> (1.0, 1.0)
|
||||
// Android maps focus points in the range (-1000, -1000) -> (1000, 1000)
|
||||
// Converts an area in Qt coordinates to Android coordinates
|
||||
// Applies 'rotation' in the counter-clockwise direction
|
||||
QRectF rotated(rotateNormalizedPoint(area.topLeft(), rotation),
|
||||
rotateNormalizedPoint(area.bottomRight(), rotation));
|
||||
|
||||
return QRect(-1000 + qRound(rotated.x() * 2000),
|
||||
-1000 + qRound(rotated.y() * 2000),
|
||||
qRound(rotated.width() * 2000),
|
||||
qRound(rotated.height() * 2000))
|
||||
return QRect(-1000 + qRound(area.x() * 2000),
|
||||
-1000 + qRound(area.y() * 2000),
|
||||
qRound(area.width() * 2000),
|
||||
qRound(area.height() * 2000))
|
||||
.intersected(QRect(-1000, -1000, 2000, 2000));
|
||||
}
|
||||
|
||||
@@ -263,9 +242,6 @@ void QAndroidCameraFocusControl::updateFocusZones(QCameraFocusZone::FocusZoneSta
|
||||
if (!viewportSize.isValid())
|
||||
return;
|
||||
|
||||
if (m_session->camera()->getDisplayOrientation() % 180)
|
||||
viewportSize.transpose();
|
||||
|
||||
QSizeF focusSize(50.f / viewportSize.width(), 50.f / viewportSize.height());
|
||||
float x = qBound(qreal(0),
|
||||
m_actualFocusPoint.x() - (focusSize.width() / 2),
|
||||
@@ -288,13 +264,8 @@ void QAndroidCameraFocusControl::setCameraFocusArea()
|
||||
// in FocusPointAuto mode, leave the area list empty
|
||||
// to let the driver choose the focus point.
|
||||
|
||||
for (int i = 0; i < m_focusZones.size(); ++i) {
|
||||
// The area passed to Android should be in sensor orientation.
|
||||
// What we have in m_focusZones is in viewport orientation, so revert the rotation set
|
||||
// on the viewport to get sensor coordinates.
|
||||
areas.append(adjustedArea(m_focusZones.at(i).area(),
|
||||
m_session->camera()->getDisplayOrientation()));
|
||||
}
|
||||
for (int i = 0; i < m_focusZones.size(); ++i)
|
||||
areas.append(adjustedArea(m_focusZones.at(i).area()));
|
||||
|
||||
}
|
||||
m_session->camera()->setFocusAreas(areas);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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: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 "qandroidcamerainfocontrol.h"
|
||||
|
||||
#include "qandroidcamerasession.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QCamera::Position QAndroidCameraInfoControl::position(const QString &deviceName)
|
||||
{
|
||||
const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
|
||||
for (int i = 0; i < cameras.count(); ++i) {
|
||||
const AndroidCameraInfo &info = cameras.at(i);
|
||||
if (QString::fromLatin1(info.name) == deviceName)
|
||||
return info.position;
|
||||
}
|
||||
|
||||
return QCamera::UnspecifiedPosition;
|
||||
}
|
||||
|
||||
int QAndroidCameraInfoControl::orientation(const QString &deviceName)
|
||||
{
|
||||
const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
|
||||
for (int i = 0; i < cameras.count(); ++i) {
|
||||
const AndroidCameraInfo &info = cameras.at(i);
|
||||
if (QString::fromLatin1(info.name) == deviceName)
|
||||
return info.orientation;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QCamera::Position QAndroidCameraInfoControl::cameraPosition(const QString &deviceName) const
|
||||
{
|
||||
return position(deviceName);
|
||||
}
|
||||
|
||||
int QAndroidCameraInfoControl::cameraOrientation(const QString &deviceName) const
|
||||
{
|
||||
return orientation(deviceName);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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: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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QANDROIDCAMERAINFOCONTROL_H
|
||||
#define QANDROIDCAMERAINFOCONTROL_H
|
||||
|
||||
#include <qcamerainfocontrol.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QAndroidCameraInfoControl : public QCameraInfoControl
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QCamera::Position cameraPosition(const QString &deviceName) const;
|
||||
int cameraOrientation(const QString &deviceName) const;
|
||||
|
||||
static QCamera::Position position(const QString &deviceName);
|
||||
static int orientation(const QString &deviceName);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QANDROIDCAMERAINFOCONTROL_H
|
||||
@@ -90,13 +90,13 @@ private:
|
||||
int bytesPerLine;
|
||||
};
|
||||
|
||||
Q_GLOBAL_STATIC(QList<AndroidCameraInfo>, g_availableCameras)
|
||||
|
||||
QAndroidCameraSession::QAndroidCameraSession(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_selectedCamera(0)
|
||||
, m_camera(0)
|
||||
, m_nativeOrientation(0)
|
||||
, m_previewOrientation(0)
|
||||
, m_videoOutput(0)
|
||||
, m_captureMode(QCamera::CaptureViewfinder)
|
||||
, m_state(QCamera::UnloadedState)
|
||||
@@ -175,6 +175,54 @@ void QAndroidCameraSession::setState(QCamera::State state)
|
||||
emit stateChanged(m_state);
|
||||
}
|
||||
|
||||
void QAndroidCameraSession::updateAvailableCameras()
|
||||
{
|
||||
g_availableCameras->clear();
|
||||
|
||||
const QJNIObjectPrivate cameraInfo("android/hardware/Camera$CameraInfo");
|
||||
const int numCameras = QJNIObjectPrivate::callStaticMethod<jint>("android/hardware/Camera",
|
||||
"getNumberOfCameras");
|
||||
|
||||
for (int i = 0; i < numCameras; ++i) {
|
||||
AndroidCameraInfo info;
|
||||
|
||||
QJNIObjectPrivate::callStaticMethod<void>("android/hardware/Camera",
|
||||
"getCameraInfo",
|
||||
"(ILandroid/hardware/Camera$CameraInfo;)V",
|
||||
i, cameraInfo.object());
|
||||
|
||||
JCamera::CameraFacing facing = JCamera::CameraFacing(cameraInfo.getField<jint>("facing"));
|
||||
// The orientation provided by Android is counter-clockwise, we need it clockwise
|
||||
info.orientation = (360 - cameraInfo.getField<jint>("orientation")) % 360;
|
||||
|
||||
switch (facing) {
|
||||
case JCamera::CameraFacingBack:
|
||||
info.name = QByteArray("back");
|
||||
info.description = QStringLiteral("Rear-facing camera");
|
||||
info.position = QCamera::BackFace;
|
||||
break;
|
||||
case JCamera::CameraFacingFront:
|
||||
info.name = QByteArray("front");
|
||||
info.description = QStringLiteral("Front-facing camera");
|
||||
info.position = QCamera::FrontFace;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!info.name.isNull())
|
||||
g_availableCameras->append(info);
|
||||
}
|
||||
}
|
||||
|
||||
const QList<AndroidCameraInfo> &QAndroidCameraSession::availableCameras()
|
||||
{
|
||||
if (g_availableCameras->isEmpty())
|
||||
updateAvailableCameras();
|
||||
|
||||
return *g_availableCameras;
|
||||
}
|
||||
|
||||
bool QAndroidCameraSession::open()
|
||||
{
|
||||
close();
|
||||
@@ -196,12 +244,6 @@ bool QAndroidCameraSession::open()
|
||||
|
||||
m_nativeOrientation = m_camera->getNativeOrientation();
|
||||
|
||||
// Preview orientation will always match the device natural orientation
|
||||
if (m_camera->getFacing() == JCamera::CameraFacingFront)
|
||||
m_previewOrientation = 360 - m_nativeOrientation;
|
||||
else
|
||||
m_previewOrientation = m_nativeOrientation;
|
||||
|
||||
m_status = QCamera::LoadedStatus;
|
||||
|
||||
if (m_camera->getPreviewFormat() != JCamera::NV21)
|
||||
@@ -279,16 +321,8 @@ void QAndroidCameraSession::adjustViewfinderSize(const QSize &captureSize, bool
|
||||
}
|
||||
|
||||
if (m_camera->previewSize() != viewfinderResolution) {
|
||||
if (m_videoOutput) {
|
||||
QSize size = viewfinderResolution;
|
||||
|
||||
// If the preview orientation is not the defaut one (0 or 180 degrees),
|
||||
// we have to invert the output aspect ratio.
|
||||
if (m_previewOrientation % 180)
|
||||
size.transpose();
|
||||
|
||||
m_videoOutput->setVideoSize(size);
|
||||
}
|
||||
if (m_videoOutput)
|
||||
m_videoOutput->setVideoSize(viewfinderResolution);
|
||||
|
||||
// if preview is started, we have to stop it first before changing its size
|
||||
if (m_previewStarted && restartPreview)
|
||||
@@ -312,7 +346,6 @@ void QAndroidCameraSession::startPreview()
|
||||
|
||||
applyImageSettings();
|
||||
adjustViewfinderSize(m_imageSettings.resolution());
|
||||
m_camera->setDisplayOrientation(m_previewOrientation);
|
||||
|
||||
if (m_videoOutput && m_videoOutput->isReady())
|
||||
onVideoOutputReady(true);
|
||||
|
||||
@@ -55,6 +55,14 @@ class JCamera;
|
||||
class QAndroidVideoOutput;
|
||||
class QAndroidMediaVideoProbeControl;
|
||||
|
||||
struct AndroidCameraInfo
|
||||
{
|
||||
QByteArray name;
|
||||
QString description;
|
||||
QCamera::Position position;
|
||||
int orientation;
|
||||
};
|
||||
|
||||
class QAndroidCameraSession : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -62,6 +70,8 @@ public:
|
||||
explicit QAndroidCameraSession(QObject *parent = 0);
|
||||
~QAndroidCameraSession();
|
||||
|
||||
static const QList<AndroidCameraInfo> &availableCameras();
|
||||
|
||||
void setSelectedCamera(int cameraId) { m_selectedCamera = cameraId; }
|
||||
JCamera *camera() const { return m_camera; }
|
||||
|
||||
@@ -126,6 +136,8 @@ private Q_SLOTS:
|
||||
void onCameraPreviewStopped();
|
||||
|
||||
private:
|
||||
static void updateAvailableCameras();
|
||||
|
||||
bool open();
|
||||
void close();
|
||||
|
||||
@@ -144,7 +156,6 @@ private:
|
||||
int m_selectedCamera;
|
||||
JCamera *m_camera;
|
||||
int m_nativeOrientation;
|
||||
int m_previewOrientation;
|
||||
QAndroidVideoOutput *m_videoOutput;
|
||||
|
||||
QCamera::CaptureModes m_captureMode;
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "qandroidmediarecordercontrol.h"
|
||||
#include "qandroidcapturesession.h"
|
||||
#include "qandroidcameracontrol.h"
|
||||
#include "qandroidcamerainfocontrol.h"
|
||||
#include "qandroidvideodeviceselectorcontrol.h"
|
||||
#include "qandroidaudioinputselectorcontrol.h"
|
||||
#include "qandroidcamerasession.h"
|
||||
@@ -75,6 +76,7 @@ QAndroidCaptureService::QAndroidCaptureService(const QString &service, QObject *
|
||||
if (m_service == QLatin1String(Q_MEDIASERVICE_CAMERA)) {
|
||||
m_cameraSession = new QAndroidCameraSession;
|
||||
m_cameraControl = new QAndroidCameraControl(m_cameraSession);
|
||||
m_cameraInfoControl = new QAndroidCameraInfoControl;
|
||||
m_videoInputControl = new QAndroidVideoDeviceSelectorControl(m_cameraSession);
|
||||
m_cameraZoomControl = new QAndroidCameraZoomControl(m_cameraSession);
|
||||
m_cameraExposureControl = new QAndroidCameraExposureControl(m_cameraSession);
|
||||
@@ -90,6 +92,7 @@ QAndroidCaptureService::QAndroidCaptureService(const QString &service, QObject *
|
||||
} else {
|
||||
m_cameraSession = 0;
|
||||
m_cameraControl = 0;
|
||||
m_cameraInfoControl = 0;
|
||||
m_videoInputControl = 0;
|
||||
m_cameraZoomControl = 0;
|
||||
m_cameraExposureControl = 0;
|
||||
@@ -125,6 +128,7 @@ QAndroidCaptureService::~QAndroidCaptureService()
|
||||
delete m_recorderControl;
|
||||
delete m_captureSession;
|
||||
delete m_cameraControl;
|
||||
delete m_cameraInfoControl;
|
||||
delete m_audioInputControl;
|
||||
delete m_videoInputControl;
|
||||
delete m_videoRendererControl;
|
||||
@@ -158,6 +162,9 @@ QMediaControl *QAndroidCaptureService::requestControl(const char *name)
|
||||
if (qstrcmp(name, QCameraControl_iid) == 0)
|
||||
return m_cameraControl;
|
||||
|
||||
if (qstrcmp(name, QCameraInfoControl_iid) == 0)
|
||||
return m_cameraInfoControl;
|
||||
|
||||
if (qstrcmp(name, QAudioInputSelectorControl_iid) == 0)
|
||||
return m_audioInputControl;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE
|
||||
class QAndroidMediaRecorderControl;
|
||||
class QAndroidCaptureSession;
|
||||
class QAndroidCameraControl;
|
||||
class QAndroidCameraInfoControl;
|
||||
class QAndroidVideoDeviceSelectorControl;
|
||||
class QAndroidAudioInputSelectorControl;
|
||||
class QAndroidCameraSession;
|
||||
@@ -85,6 +86,7 @@ private:
|
||||
QAndroidMediaRecorderControl *m_recorderControl;
|
||||
QAndroidCaptureSession *m_captureSession;
|
||||
QAndroidCameraControl *m_cameraControl;
|
||||
QAndroidCameraInfoControl *m_cameraInfoControl;
|
||||
QAndroidVideoDeviceSelectorControl *m_videoInputControl;
|
||||
QAndroidAudioInputSelectorControl *m_audioInputControl;
|
||||
QAndroidCameraSession *m_cameraSession;
|
||||
|
||||
@@ -46,17 +46,11 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QByteArray QAndroidVideoDeviceSelectorControl::m_defaultDevice;
|
||||
QList<QByteArray> QAndroidVideoDeviceSelectorControl::m_names;
|
||||
QStringList QAndroidVideoDeviceSelectorControl::m_descriptions;
|
||||
|
||||
QAndroidVideoDeviceSelectorControl::QAndroidVideoDeviceSelectorControl(QAndroidCameraSession *session)
|
||||
: QVideoDeviceSelectorControl(0)
|
||||
, m_selectedDevice(0)
|
||||
, m_cameraSession(session)
|
||||
{
|
||||
if (m_names.isEmpty())
|
||||
update();
|
||||
}
|
||||
|
||||
QAndroidVideoDeviceSelectorControl::~QAndroidVideoDeviceSelectorControl()
|
||||
@@ -65,17 +59,23 @@ QAndroidVideoDeviceSelectorControl::~QAndroidVideoDeviceSelectorControl()
|
||||
|
||||
int QAndroidVideoDeviceSelectorControl::deviceCount() const
|
||||
{
|
||||
return m_names.size();
|
||||
return QAndroidCameraSession::availableCameras().count();
|
||||
}
|
||||
|
||||
QString QAndroidVideoDeviceSelectorControl::deviceName(int index) const
|
||||
{
|
||||
return m_names.at(index);
|
||||
if (index < 0 || index >= QAndroidCameraSession::availableCameras().count())
|
||||
return QString();
|
||||
|
||||
return QString::fromLatin1(QAndroidCameraSession::availableCameras().at(index).name);
|
||||
}
|
||||
|
||||
QString QAndroidVideoDeviceSelectorControl::deviceDescription(int index) const
|
||||
{
|
||||
return m_descriptions.at(index);
|
||||
if (index < 0 || index >= QAndroidCameraSession::availableCameras().count())
|
||||
return QString();
|
||||
|
||||
return QAndroidCameraSession::availableCameras().at(index).description;
|
||||
}
|
||||
|
||||
int QAndroidVideoDeviceSelectorControl::defaultDevice() const
|
||||
@@ -98,65 +98,4 @@ void QAndroidVideoDeviceSelectorControl::setSelectedDevice(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidVideoDeviceSelectorControl::update()
|
||||
{
|
||||
m_defaultDevice.clear();
|
||||
m_names.clear();
|
||||
m_descriptions.clear();
|
||||
|
||||
QJNIObjectPrivate cameraInfo("android/hardware/Camera$CameraInfo");
|
||||
int numCameras = QJNIObjectPrivate::callStaticMethod<jint>("android/hardware/Camera",
|
||||
"getNumberOfCameras");
|
||||
|
||||
for (int i = 0; i < numCameras; ++i) {
|
||||
QJNIObjectPrivate::callStaticMethod<void>("android/hardware/Camera",
|
||||
"getCameraInfo",
|
||||
"(ILandroid/hardware/Camera$CameraInfo;)V",
|
||||
i, cameraInfo.object());
|
||||
|
||||
JCamera::CameraFacing facing = JCamera::CameraFacing(cameraInfo.getField<jint>("facing"));
|
||||
|
||||
switch (facing) {
|
||||
case JCamera::CameraFacingBack:
|
||||
m_names.append("back");
|
||||
m_descriptions.append(QStringLiteral("Rear-facing camera"));
|
||||
break;
|
||||
case JCamera::CameraFacingFront:
|
||||
m_names.append("front");
|
||||
m_descriptions.append(QStringLiteral("Front-facing camera"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_names.isEmpty())
|
||||
m_defaultDevice = m_names.first();
|
||||
}
|
||||
|
||||
QByteArray QAndroidVideoDeviceSelectorControl::defaultDeviceName()
|
||||
{
|
||||
if (m_names.isEmpty())
|
||||
update();
|
||||
|
||||
return m_defaultDevice;
|
||||
}
|
||||
|
||||
QList<QByteArray> QAndroidVideoDeviceSelectorControl::availableDevices()
|
||||
{
|
||||
if (m_names.isEmpty())
|
||||
update();
|
||||
|
||||
return m_names;
|
||||
}
|
||||
|
||||
QString QAndroidVideoDeviceSelectorControl::availableDeviceDescription(const QByteArray &device)
|
||||
{
|
||||
int i = m_names.indexOf(device);
|
||||
if (i != -1)
|
||||
return m_descriptions.at(i);
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -63,20 +63,10 @@ public:
|
||||
|
||||
int defaultDevice() const;
|
||||
int selectedDevice() const;
|
||||
|
||||
void setSelectedDevice(int index);
|
||||
|
||||
static QByteArray defaultDeviceName();
|
||||
static QList<QByteArray> availableDevices();
|
||||
static QString availableDeviceDescription(const QByteArray &device);
|
||||
|
||||
private:
|
||||
static void update();
|
||||
|
||||
int m_selectedDevice;
|
||||
static QByteArray m_defaultDevice;
|
||||
static QList<QByteArray> m_names;
|
||||
static QStringList m_descriptions;
|
||||
|
||||
QAndroidCameraSession *m_cameraSession;
|
||||
};
|
||||
|
||||
@@ -43,8 +43,9 @@
|
||||
|
||||
#include "qandroidmediaservice.h"
|
||||
#include "qandroidcaptureservice.h"
|
||||
#include "qandroidvideodeviceselectorcontrol.h"
|
||||
#include "qandroidaudioinputselectorcontrol.h"
|
||||
#include "qandroidcamerainfocontrol.h"
|
||||
#include "qandroidcamerasession.h"
|
||||
#include "jmediaplayer.h"
|
||||
#include "jsurfacetexture.h"
|
||||
#include "jsurfacetextureholder.h"
|
||||
@@ -98,16 +99,21 @@ QMediaServiceProviderHint::Features QAndroidMediaServicePlugin::supportedFeature
|
||||
|
||||
QByteArray QAndroidMediaServicePlugin::defaultDevice(const QByteArray &service) const
|
||||
{
|
||||
if (service == Q_MEDIASERVICE_CAMERA)
|
||||
return QAndroidVideoDeviceSelectorControl::defaultDeviceName();
|
||||
if (service == Q_MEDIASERVICE_CAMERA && !QAndroidCameraSession::availableCameras().isEmpty())
|
||||
return QAndroidCameraSession::availableCameras().first().name;
|
||||
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QList<QByteArray> QAndroidMediaServicePlugin::devices(const QByteArray &service) const
|
||||
{
|
||||
if (service == Q_MEDIASERVICE_CAMERA)
|
||||
return QAndroidVideoDeviceSelectorControl::availableDevices();
|
||||
if (service == Q_MEDIASERVICE_CAMERA) {
|
||||
QList<QByteArray> devices;
|
||||
const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
|
||||
for (int i = 0; i < cameras.count(); ++i)
|
||||
devices.append(cameras.at(i).name);
|
||||
return devices;
|
||||
}
|
||||
|
||||
if (service == Q_MEDIASERVICE_AUDIOSOURCE)
|
||||
return QAndroidAudioInputSelectorControl::availableDevices();
|
||||
@@ -117,8 +123,14 @@ QList<QByteArray> QAndroidMediaServicePlugin::devices(const QByteArray &service)
|
||||
|
||||
QString QAndroidMediaServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
|
||||
{
|
||||
if (service == Q_MEDIASERVICE_CAMERA)
|
||||
return QAndroidVideoDeviceSelectorControl::availableDeviceDescription(device);
|
||||
if (service == Q_MEDIASERVICE_CAMERA) {
|
||||
const QList<AndroidCameraInfo> &cameras = QAndroidCameraSession::availableCameras();
|
||||
for (int i = 0; i < cameras.count(); ++i) {
|
||||
const AndroidCameraInfo &info = cameras.at(i);
|
||||
if (info.name == device)
|
||||
return info.description;
|
||||
}
|
||||
}
|
||||
|
||||
if (service == Q_MEDIASERVICE_AUDIOSOURCE)
|
||||
return QAndroidAudioInputSelectorControl::availableDeviceDescription(device);
|
||||
@@ -126,6 +138,16 @@ QString QAndroidMediaServicePlugin::deviceDescription(const QByteArray &service,
|
||||
return QString();
|
||||
}
|
||||
|
||||
QCamera::Position QAndroidMediaServicePlugin::cameraPosition(const QByteArray &device) const
|
||||
{
|
||||
return QAndroidCameraInfoControl::position(device);
|
||||
}
|
||||
|
||||
int QAndroidMediaServicePlugin::cameraOrientation(const QByteArray &device) const
|
||||
{
|
||||
return QAndroidCameraInfoControl::orientation(device);
|
||||
}
|
||||
|
||||
|
||||
Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/)
|
||||
{
|
||||
|
||||
@@ -50,11 +50,13 @@ class QAndroidMediaServicePlugin
|
||||
: public QMediaServiceProviderPlugin
|
||||
, public QMediaServiceSupportedDevicesInterface
|
||||
, public QMediaServiceDefaultDeviceInterface
|
||||
, public QMediaServiceCameraInfoInterface
|
||||
, public QMediaServiceFeaturesInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
|
||||
Q_INTERFACES(QMediaServiceDefaultDeviceInterface)
|
||||
Q_INTERFACES(QMediaServiceCameraInfoInterface)
|
||||
Q_INTERFACES(QMediaServiceFeaturesInterface)
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0"
|
||||
FILE "android_mediaservice.json")
|
||||
@@ -68,9 +70,12 @@ public:
|
||||
|
||||
QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const Q_DECL_OVERRIDE;
|
||||
|
||||
QByteArray defaultDevice(const QByteArray &service) const;
|
||||
QList<QByteArray> devices(const QByteArray &service) const;
|
||||
QString deviceDescription(const QByteArray &service, const QByteArray &device);
|
||||
QByteArray defaultDevice(const QByteArray &service) const Q_DECL_OVERRIDE;
|
||||
QList<QByteArray> devices(const QByteArray &service) const Q_DECL_OVERRIDE;
|
||||
QString deviceDescription(const QByteArray &service, const QByteArray &device) Q_DECL_OVERRIDE;
|
||||
|
||||
QCamera::Position cameraPosition(const QByteArray &device) const Q_DECL_OVERRIDE;
|
||||
int cameraOrientation(const QByteArray &device) const Q_DECL_OVERRIDE;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -158,8 +158,6 @@ class JCameraWorker : public QObject, public QJNIObjectPrivate
|
||||
Q_INVOKABLE JCamera::CameraFacing getFacing();
|
||||
Q_INVOKABLE int getNativeOrientation();
|
||||
|
||||
Q_INVOKABLE void setDisplayOrientation(int degrees);
|
||||
|
||||
Q_INVOKABLE QSize getPreferredPreviewSizeForVideo();
|
||||
Q_INVOKABLE QList<QSize> getSupportedPreviewSizes();
|
||||
|
||||
@@ -231,7 +229,6 @@ class JCameraWorker : public QObject, public QJNIObjectPrivate
|
||||
|
||||
QSize m_previewSize;
|
||||
int m_rotation;
|
||||
int m_displayOrientation;
|
||||
|
||||
bool m_hasAPI14;
|
||||
|
||||
@@ -337,17 +334,6 @@ int JCamera::getNativeOrientation()
|
||||
return d->getNativeOrientation();
|
||||
}
|
||||
|
||||
int JCamera::getDisplayOrientation() const
|
||||
{
|
||||
return d->m_displayOrientation;
|
||||
}
|
||||
|
||||
void JCamera::setDisplayOrientation(int degrees)
|
||||
{
|
||||
d->m_displayOrientation = degrees;
|
||||
QMetaObject::invokeMethod(d, "setDisplayOrientation", Q_ARG(int, degrees));
|
||||
}
|
||||
|
||||
QSize JCamera::getPreferredPreviewSizeForVideo()
|
||||
{
|
||||
return d->getPreferredPreviewSizeForVideo();
|
||||
@@ -626,7 +612,6 @@ JCameraWorker::JCameraWorker(JCamera *camera, int cameraId, jobject cam, QThread
|
||||
, QJNIObjectPrivate(cam)
|
||||
, m_cameraId(cameraId)
|
||||
, m_rotation(0)
|
||||
, m_displayOrientation(0)
|
||||
, m_hasAPI14(false)
|
||||
, m_parametersMutex(QMutex::Recursive)
|
||||
{
|
||||
@@ -692,11 +677,6 @@ int JCameraWorker::getNativeOrientation()
|
||||
return m_info.getField<jint>("orientation");
|
||||
}
|
||||
|
||||
void JCameraWorker::setDisplayOrientation(int degrees)
|
||||
{
|
||||
callMethod<void>("setDisplayOrientation", "(I)V", degrees);
|
||||
}
|
||||
|
||||
QSize JCameraWorker::getPreferredPreviewSizeForVideo()
|
||||
{
|
||||
QMutexLocker parametersLocker(&m_parametersMutex);
|
||||
|
||||
@@ -88,9 +88,6 @@ public:
|
||||
CameraFacing getFacing();
|
||||
int getNativeOrientation();
|
||||
|
||||
int getDisplayOrientation() const;
|
||||
void setDisplayOrientation(int degrees);
|
||||
|
||||
QSize getPreferredPreviewSizeForVideo();
|
||||
QList<QSize> getSupportedPreviewSizes();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user