From 028ad30a80767cb7bb231be4970c4ffc5b1b22db Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Wed, 14 Aug 2013 00:42:49 +0300 Subject: [PATCH] Added QtCamQuirks to libQtCamera and Quirks to libdeclarativeQtCamera This allows us to specify any device specific quirks to workaround from the UI side. Also added N9 quirks --- data/n9/qtcamera.ini | 6 ++++ declarative/camera.cpp | 13 +++++++- declarative/camera.h | 7 +++++ declarative/cameraconfig.cpp | 2 ++ declarative/declarative.pro | 4 +-- declarative/plugin.cpp | 4 +++ declarative/quirks.cpp | 38 +++++++++++++++++++++++ declarative/quirks.h | 53 ++++++++++++++++++++++++++++++++ lib/lib.pro | 4 +-- lib/qtcamconfig.cpp | 37 ++++++++++++++++++++++ lib/qtcamconfig.h | 7 +++-- lib/qtcamquirks.cpp | 44 +++++++++++++++++++++++++++ lib/qtcamquirks.h | 59 ++++++++++++++++++++++++++++++++++++ 13 files changed, 271 insertions(+), 7 deletions(-) create mode 100644 declarative/quirks.cpp create mode 100644 declarative/quirks.h create mode 100644 lib/qtcamquirks.cpp create mode 100644 lib/qtcamquirks.h diff --git a/data/n9/qtcamera.ini b/data/n9/qtcamera.ini index 65fc889..c912b67 100644 --- a/data/n9/qtcamera.ini +++ b/data/n9/qtcamera.ini @@ -201,3 +201,9 @@ message=regions-of-interest [%General] preview-supported=true + +[quirks-0] +quirks = NoSceneModeChangeDuringRecording + +[quirks-1] +quirks = NoNightSceneMode, NoFlash, NoVideoTorch, NoAutoFocus, NoSceneModeChangeDuringRecording \ No newline at end of file diff --git a/declarative/camera.cpp b/declarative/camera.cpp index 2ce7aed..3429832 100644 --- a/declarative/camera.cpp +++ b/declarative/camera.cpp @@ -51,6 +51,7 @@ #include "videomute.h" #include "videotorch.h" #include "cameraconfig.h" +#include "quirks.h" Camera::Camera(QObject *parent) : QObject(parent), @@ -74,7 +75,8 @@ Camera::Camera(QObject *parent) : m_roi(0), m_videoMute(0), m_videoTorch(0), - m_config(new CameraConfig(this)) { + m_config(new CameraConfig(this)), + m_quirks(0) { m_config->componentComplete(); } @@ -106,6 +108,7 @@ Camera::~Camera() { delete m_roi; delete m_videoMute; delete m_videoTorch; + delete m_quirks; } int Camera::deviceCount() const { @@ -333,6 +336,10 @@ void Camera::resetCapabilities() { delete m_videoTorch; m_videoTorch = new VideoTorch(dev, this); emit videoTorchChanged(); + + delete m_quirks; + m_quirks = new Quirks(dev->config()->quirks(dev->id()), this); + emit quirksChanged(); } Zoom *Camera::zoom() const { @@ -402,3 +409,7 @@ VideoTorch *Camera::videoTorch() const { CameraConfig *Camera::cameraConfig() const { return m_config; } + +Quirks *Camera::quirks() const { + return m_quirks; +} diff --git a/declarative/camera.h b/declarative/camera.h index b533991..76ad878 100644 --- a/declarative/camera.h +++ b/declarative/camera.h @@ -48,6 +48,7 @@ class Roi; class VideoMute; class VideoTorch; class CameraConfig; +class Quirks; class Camera : public QObject { Q_OBJECT @@ -79,6 +80,8 @@ class Camera : public QObject { Q_PROPERTY(VideoMute *videoMute READ videoMute NOTIFY videoMuteChanged); Q_PROPERTY(VideoTorch *videoTorch READ videoTorch NOTIFY videoTorchChanged); + Q_PROPERTY(Quirks *quirks READ quirks NOTIFY quirksChanged); + // TODO: We need a setter here too. Q_PROPERTY(CameraConfig *cameraConfig READ cameraConfig CONSTANT); @@ -136,6 +139,8 @@ public: VideoMute *videoMute() const; VideoTorch *videoTorch() const; + Quirks *quirks() const; + CameraConfig *cameraConfig() const; signals: @@ -169,6 +174,7 @@ signals: void videoMuteChanged(); void videoTorchChanged(); void renderingEnabledChanged(); + void quirksChanged(); private: bool applyMode(); @@ -201,6 +207,7 @@ private: VideoMute *m_videoMute; VideoTorch *m_videoTorch; CameraConfig *m_config; + Quirks *m_quirks; }; #endif /* CAMERA_H */ diff --git a/declarative/cameraconfig.cpp b/declarative/cameraconfig.cpp index 1c1678a..169c34c 100644 --- a/declarative/cameraconfig.cpp +++ b/declarative/cameraconfig.cpp @@ -28,6 +28,8 @@ #include #endif +// TODO: share that with qtcamera. We now have 2 instances of QtCamConfig + CameraConfig::CameraConfig(QObject *parent) : QObject(parent), m_config(0) { diff --git a/declarative/declarative.pro b/declarative/declarative.pro index c7249f2..c83ecb5 100644 --- a/declarative/declarative.pro +++ b/declarative/declarative.pro @@ -22,7 +22,7 @@ HEADERS += plugin.h previewprovider.h camera.h mode.h imagemode.h videomode.h \ imageresolutionmodel.h videosettings.h videoresolutionmodel.h \ notificationscontainer.h sounds.h focus.h autofocus.h \ roi.h cameraconfig.h videoplayer.h viewfinder.h capability.h \ - imageresolution.h videoresolution.h + imageresolution.h videoresolution.h quirks.h SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp videomode.cpp \ zoom.cpp flash.cpp scene.cpp evcomp.cpp videotorch.cpp whitebalance.cpp \ @@ -31,7 +31,7 @@ SOURCES += plugin.cpp previewprovider.cpp camera.cpp mode.cpp imagemode.cpp vide imageresolutionmodel.cpp videosettings.cpp videoresolutionmodel.cpp \ notificationscontainer.cpp sounds.cpp focus.cpp autofocus.cpp \ roi.cpp cameraconfig.cpp videoplayer.cpp viewfinder.cpp capability.cpp \ - imageresolution.cpp videoresolution.cpp + imageresolution.cpp videoresolution.cpp quirks.cpp PLUGIN_IMPORT_PATH = QtCamera target.path = $$[QT_INSTALL_IMPORTS]/$$PLUGIN_IMPORT_PATH diff --git a/declarative/plugin.cpp b/declarative/plugin.cpp index b510a73..263328f 100644 --- a/declarative/plugin.cpp +++ b/declarative/plugin.cpp @@ -51,6 +51,7 @@ #include "capability.h" #include "imageresolution.h" #include "videoresolution.h" +#include "quirks.h" #if defined(QT4) #include #elif defined(QT5) @@ -127,6 +128,9 @@ void Plugin::registerTypes(const char *uri) { qmlRegisterType(uri, MAJOR, MINOR, "ImageResolution"); qmlRegisterType(uri, MAJOR, MINOR, "VideoResolution"); + + qmlRegisterUncreatableType(uri, MAJOR, MINOR, "Quirks", + "Quirks can be obtained from Camera"); } #if defined(QT4) diff --git a/declarative/quirks.cpp b/declarative/quirks.cpp new file mode 100644 index 0000000..4c352f7 --- /dev/null +++ b/declarative/quirks.cpp @@ -0,0 +1,38 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "quirks.h" + +Quirks::Quirks(QtCamQuirks *quirks, QObject *parent) : + QObject(parent), + m_quirks(quirks) { + +} + +Quirks::~Quirks() { + delete m_quirks; + m_quirks = 0; +} + +bool Quirks::hasQuirk(const QuirkType& type) { + return m_quirks->quirks().testFlag(QtCamQuirks::QuirkType(type)); +} diff --git a/declarative/quirks.h b/declarative/quirks.h new file mode 100644 index 0000000..2b1c641 --- /dev/null +++ b/declarative/quirks.h @@ -0,0 +1,53 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef QUIRKS_H +#define QUIRKS_H + +#include +#include "qtcamquirks.h" + +class Quirks : public QObject { + Q_OBJECT + + Q_ENUMS(QuirkType); + +public: + Quirks(QtCamQuirks *quirks, QObject *parent = 0); + ~Quirks(); + + typedef enum { + NoNightSceneMode = QtCamQuirks::NoNightSceneMode, + NoFlash = QtCamQuirks::NoFlash, + NoVideoTorch = QtCamQuirks::NoVideoTorch, + NoAutoFocus = QtCamQuirks::NoAutoFocus, + NoSceneModeChangeDuringRecording = QtCamQuirks::NoSceneModeChangeDuringRecording, + NoRedEyeFlash = QtCamQuirks::NoRedEyeFlash, + } QuirkType; + + Q_INVOKABLE bool hasQuirk(const QuirkType& type); + +private: + QtCamQuirks *m_quirks; +}; + +#endif /* QUIRKS_H */ diff --git a/lib/lib.pro b/lib/lib.pro index 3e27453..fd6b936 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -23,7 +23,7 @@ HEADERS += qtcamconfig.h qtcamera.h qtcamscanner.h qtcamdevice.h qtcamviewfinder qtcamwhitebalance.h qtcamcolortone.h qtcamflickerreduction.h \ qtcamnoisereduction.h qtcamiso.h qtcamaperture.h qtcamexposure.h \ qtcamvideomute.h qtcamnotifications.h qtcamfocus.h qtcamautofocus.h \ - qtcamanalysisbin.h qtcampropertysetter.h qtcamroi.h + qtcamanalysisbin.h qtcampropertysetter.h qtcamroi.h qtcamquirks.h SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamviewfinder.cpp \ qtcammode.cpp qtcamgstreamermessagehandler.cpp qtcamgstreamermessagelistener.cpp \ @@ -33,7 +33,7 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi qtcamwhitebalance.cpp qtcamcolortone.cpp qtcamflickerreduction.cpp \ qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \ qtcamvideomute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamautofocus.cpp \ - qtcamanalysisbin.cpp qtcampropertysetter.cpp qtcamroi.cpp + qtcamanalysisbin.cpp qtcampropertysetter.cpp qtcamroi.cpp qtcamquirks.cpp HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamautofocus_p.h \ qtcamnotifications_p.h qtcamflash_p.h qtcamroi_p.h diff --git a/lib/qtcamconfig.cpp b/lib/qtcamconfig.cpp index 1b2a1b8..41da44c 100644 --- a/lib/qtcamconfig.cpp +++ b/lib/qtcamconfig.cpp @@ -19,9 +19,13 @@ */ #include "qtcamconfig.h" +#include "qtcamimagesettings.h" +#include "qtcamvideosettings.h" +#include "qtcamquirks.h" #include #include #include +#include #define CONFIGURATION_FILE DATA_DIR"/qtcamera.ini" @@ -168,6 +172,39 @@ QtCamVideoSettings *QtCamConfig::videoSettings(const QVariant& id) { return new QtCamVideoSettings(id.toString(), suffix, profileName, profilePath, resolutions); } +QtCamQuirks *QtCamConfig::quirks(const QVariant& id) { + QString group = QString("quirks-%1").arg(id.toString()); + d_ptr->conf->beginGroup(group); + QStringList quirks = d_ptr->conf->value("quirks").toStringList(); + d_ptr->conf->endGroup(); + + QMetaObject m = QtCamQuirks::staticMetaObject; + int index = m.indexOfEnumerator("QuirkType"); + if (index == -1) { + qCritical() << "Failed to obtain QuirkType index"; + return 0; + } + + QMetaEnum e = m.enumerator(index); + + int value = 0; + + foreach (const QString& quirk, quirks) { + int val = e.keyToValue(quirk.toLatin1().constData()); + + if (val == -1) { + qWarning() << "Unknown quirk" << quirk; + } + else { + value |= val; + } + } + + QtCamQuirks::QuirkTypes types = (QtCamQuirks::QuirkTypes)value; + + return new QtCamQuirks(types); +} + QString QtCamConfig::imageEncodingProfileName() const { return d_ptr->conf->value("image/profile-name").toString(); } diff --git a/lib/qtcamconfig.h b/lib/qtcamconfig.h index cd7a493..bd1469c 100644 --- a/lib/qtcamconfig.h +++ b/lib/qtcamconfig.h @@ -24,10 +24,12 @@ #define QT_CAM_CONFIG_H #include -#include "qtcamimagesettings.h" -#include "qtcamvideosettings.h" #include +class QtCamImageSettings; +class QtCamVideoSettings; +class QtCamQuirks; + #define SCANNER_TYPE_V4L2 "v4l2" #define SCANNER_TYPE_ENUM "enum" @@ -63,6 +65,7 @@ public: QtCamImageSettings *imageSettings(const QVariant& id); QtCamVideoSettings *videoSettings(const QVariant& id); + QtCamQuirks *quirks(const QVariant& id); QString imageEncodingProfileName() const; QString imageEncodingProfilePath() const; diff --git a/lib/qtcamquirks.cpp b/lib/qtcamquirks.cpp new file mode 100644 index 0000000..93c79cb --- /dev/null +++ b/lib/qtcamquirks.cpp @@ -0,0 +1,44 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "qtcamquirks.h" +#include "qtcamconfig.h" // For DATA_DIR + +#define CONFIGURATION_FILE DATA_DIR"/qtcamera.ini" + +class QtCamQuirksPrivate { +public: + QtCamQuirks::QuirkTypes types; +}; + +QtCamQuirks::QtCamQuirks(const QuirkTypes& types, QObject *parent) : + QObject(parent), + d_ptr(new QtCamQuirksPrivate) { + + d_ptr->types = types; +} + +QtCamQuirks::~QtCamQuirks() { + delete d_ptr; d_ptr = 0; +} + +QtCamQuirks::QuirkTypes QtCamQuirks::quirks() const { + return d_ptr->types; +} diff --git a/lib/qtcamquirks.h b/lib/qtcamquirks.h new file mode 100644 index 0000000..c22ff10 --- /dev/null +++ b/lib/qtcamquirks.h @@ -0,0 +1,59 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef QT_CAM_QUIRKS_H +#define QT_CAM_QUIRKS_H + +#include + +class QtCamQuirksPrivate; +class QtCamDevice; + +class QtCamQuirks : public QObject { + Q_OBJECT + + Q_ENUMS(QuirkType); + +public: + typedef enum { + NoNightSceneMode = 0x1, + NoFlash = 0x2, + NoVideoTorch = 0x4, + NoAutoFocus = 0x8, + NoSceneModeChangeDuringRecording = 0x10, + NoRedEyeFlash = 0x20, + } QuirkType; + + Q_DECLARE_FLAGS(QuirkTypes, QuirkType); + + QtCamQuirks(const QuirkTypes& types, QObject *parent = 0); + ~QtCamQuirks(); + + QuirkTypes quirks() const; + +private: + QtCamQuirksPrivate *d_ptr; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QtCamQuirks::QuirkTypes); + +#endif /* QT_CAM_QUIRKS_H */ -- 2.25.1