Added QtCamCapability (base class for capabilities) and implemented flash, zoom and...
authorMohammed Sameer <msameer@foolab.org>
Fri, 31 Aug 2012 18:35:35 +0000 (21:35 +0300)
committerMohammed Sameer <msameer@foolab.org>
Thu, 6 Sep 2012 16:10:10 +0000 (19:10 +0300)
lib/lib.pro
lib/qtcamcapability.cpp [new file with mode: 0644]
lib/qtcamcapability.h [new file with mode: 0644]
lib/qtcamdevice.h
lib/qtcamdevice_p.h
lib/qtcamflash.cpp [new file with mode: 0644]
lib/qtcamflash.h [new file with mode: 0644]
lib/qtcamscene.cpp [new file with mode: 0644]
lib/qtcamscene.h [new file with mode: 0644]
lib/qtcamzoom.cpp [new file with mode: 0644]
lib/qtcamzoom.h [new file with mode: 0644]

index ea2340f..9606ccf 100644 (file)
@@ -14,15 +14,19 @@ HEADERS += qtcamconfig.h qtcamera.h qtcamscanner.h qtcamdevice.h qtcamviewfinder
            qtcammode.h qtcamgstreamermessagehandler.h qtcamgstreamermessagelistener.h \
            qtcamgraphicsviewfinder.h qtcamviewfinderrenderer.h \
            qtcamviewfinderrenderergeneric.h qtcamimagesettings.h qtcamvideosettings.h \
-           qtcamimagemode.h qtcamvideomode.h qtcammetadata.h
+           qtcamimagemode.h qtcamvideomode.h qtcammetadata.h qtcamcapability.h \
+           qtcamzoom.h qtcamflash.h qtcamscene.h
 
 SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamviewfinder.cpp \
            qtcammode.cpp qtcamgstreamermessagehandler.cpp qtcamgstreamermessagelistener.cpp \
            qtcamgraphicsviewfinder.cpp qtcamviewfinderrenderer.cpp \
            qtcamviewfinderrenderergeneric.cpp qtcamimagesettings.cpp qtcamvideosettings.cpp \
-           qtcamimagemode.cpp qtcamvideomode.cpp qtcammetadata.cpp
+           qtcamimagemode.cpp qtcamvideomode.cpp qtcammetadata.cpp qtcamcapability.cpp \
+           qtcamzoom.cpp qtcamflash.cpp qtcamscene.cpp
 
-HEADERS += qtcammode_p.h qtcamdevice_p.h
+HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h
+
+LIBS += -lgstphotography-0.10
 
 isEqual(MEEGO_EDITION, harmattan) {
 SOURCES += qtcamviewfinderrenderermeego.cpp
diff --git a/lib/qtcamcapability.cpp b/lib/qtcamcapability.cpp
new file mode 100644 (file)
index 0000000..2972560
--- /dev/null
@@ -0,0 +1,45 @@
+#include "qtcamcapability.h"
+#include "qtcamdevice.h"
+#include "qtcamdevice_p.h"
+#include "qtcamcapability_p.h"
+
+#ifndef GST_USE_UNSTABLE_API
+#define GST_USE_UNSTABLE_API
+#endif
+#include <gst/interfaces/photography.h>
+
+QtCamCapability::Capabilities QtCamCapability::capabilities(QtCamDevice *dev) {
+  if (!dev || !dev->d_ptr || !dev->d_ptr->videoSource) {
+    return QtCamCapability::Capabilities(0);
+  }
+
+  if (!GST_IS_PHOTOGRAPHY(dev->d_ptr->videoSource)) {
+    return QtCamCapability::Capabilities(0);
+  }
+
+  GstPhotography *photo = GST_PHOTOGRAPHY(dev->d_ptr->videoSource);
+  return QtCamCapability::Capabilities(gst_photography_get_capabilities(photo));
+}
+
+QtCamCapability::QtCamCapability(QtCamCapabilityPrivate *d, QObject *parent) :
+  QObject(parent), d_ptr(d) {
+  d_ptr->bin = d_ptr->dev->d_ptr->cameraBin;
+  d_ptr->src = d_ptr->dev->d_ptr->videoSource;
+  d_ptr->q_ptr = this;
+
+  if (!d_ptr->prop.isEmpty()) {
+    d_ptr->startMonitoring();
+  }
+}
+
+QtCamCapability::~QtCamCapability() {
+  if (!d_ptr->prop.isEmpty()) {
+    d_ptr->stopMonitoring();
+  }
+
+  delete d_ptr; d_ptr = 0;
+}
+
+bool QtCamCapability::isSupported() {
+  return QtCamCapability::capabilities(d_ptr->dev).testFlag(d_ptr->cap);
+}
diff --git a/lib/qtcamcapability.h b/lib/qtcamcapability.h
new file mode 100644 (file)
index 0000000..d22f5da
--- /dev/null
@@ -0,0 +1,49 @@
+// -*- c++ -*-
+
+#ifndef QT_CAM_CAPABILITY_H
+#define QT_CAM_CAPABILITY_H
+
+#include <QObject>
+
+class QtCamDevice;
+class QtCamCapabilityPrivate;
+
+class QtCamCapability : public QObject {
+  Q_OBJECT
+  Q_FLAGS(Capability Capabilities)
+
+public:
+  typedef enum {
+    EvComp = (1 << 0),
+    IsoSpeed = (1 << 1),
+    WbMode = (1 << 2),
+    ColourTone = (1 << 3),
+    Scene = (1 << 4),
+    Flash = (1 << 5),
+    Zoom = (1 << 6),
+    Focus = (1 << 7),
+    Aperture = (1 << 8),
+    Eposure = (1 << 9),
+    Shake = (1 << 10),
+    NoiseReduction = (1 << 11)
+  } Capability;
+
+  Q_DECLARE_FLAGS(Capabilities, Capability)
+
+  static Capabilities capabilities(QtCamDevice *dev);
+
+  QtCamCapability(QtCamCapabilityPrivate *d, QObject *parent = 0);
+  virtual ~QtCamCapability();
+
+  bool isSupported();
+
+signals:
+  void valueChanged();
+  void minimumValueChanged();
+  void maximumValueChanged();
+
+protected:
+  QtCamCapabilityPrivate *d_ptr;
+};
+
+#endif /* QT_CAM_CAPABILITY_H */
index 1b6d229..20b153c 100644 (file)
@@ -14,6 +14,7 @@ class QtCamImageMode;
 class QtCamMode;
 class QtCamGStreamerMessageListener;
 class QtCamMetaData;
+class QtCamCapability;
 
 class QtCamDevice : public QObject {
   Q_OBJECT
@@ -55,6 +56,8 @@ private:
   Q_PRIVATE_SLOT(d_ptr, void _d_stopping())
 
   friend class QtCamMetaData;
+  friend class QtCamCapability;
+
   QtCamDevicePrivate *d_ptr;
 };
 
index fd4bf96..0bb979f 100644 (file)
@@ -184,6 +184,9 @@ public:
   void resetCapabilities() {
     g_object_set(cameraBin, "zoom", 1.0, NULL);
     g_object_set(videoSource, "flash-mode", 0, NULL);
+
+    // TODO: should scene mode be manual or automatic ?
+    g_object_set(videoSource, "scene-mode", 0, NULL);
   }
 
   QString name;
diff --git a/lib/qtcamflash.cpp b/lib/qtcamflash.cpp
new file mode 100644 (file)
index 0000000..c83ff54
--- /dev/null
@@ -0,0 +1,33 @@
+#include "qtcamflash.h"
+#include "qtcamcapability_p.h"
+
+QtCamFlash::QtCamFlash(QtCamDevice *dev, QObject *parent) :
+  QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Flash, "flash-mode"), parent) {
+
+}
+
+QtCamFlash::~QtCamFlash() {
+
+}
+
+QtCamFlash::FlashMode QtCamFlash::value() {
+  int val = 0;
+  if (!d_ptr->intValue(&val)) {
+    return QtCamFlash::Auto;
+  }
+
+  switch (val) {
+  case QtCamFlash::On:
+  case QtCamFlash::Off:
+  case QtCamFlash::FillIn:
+  case QtCamFlash::RedEye:
+    return (QtCamFlash::FlashMode)val;
+
+  default:
+    return QtCamFlash::Auto;
+  }
+}
+
+bool QtCamFlash::setValue(const QtCamFlash::FlashMode& mode) {
+  return d_ptr->setIntValue(mode);
+}
diff --git a/lib/qtcamflash.h b/lib/qtcamflash.h
new file mode 100644 (file)
index 0000000..100eea3
--- /dev/null
@@ -0,0 +1,27 @@
+// -*- c++ -*-
+
+#ifndef QT_CAM_FLASH_H
+#define QT_CAM_FLASH_H
+
+#include "qtcamcapability.h"
+
+class QtCamFlash : public QtCamCapability {
+  Q_OBJECT
+
+public:
+  typedef enum {
+    Auto = 0,
+    Off = 1,
+    On = 2,
+    FillIn = 3,
+    RedEye = 4
+  } FlashMode;
+
+  QtCamFlash(QtCamDevice *dev, QObject *parent = 0);
+  ~QtCamFlash();
+
+  FlashMode value();
+  bool setValue(const FlashMode& mode);
+};
+
+#endif /* QT_CAM_FLASH_H */
diff --git a/lib/qtcamscene.cpp b/lib/qtcamscene.cpp
new file mode 100644 (file)
index 0000000..333697c
--- /dev/null
@@ -0,0 +1,35 @@
+#include "qtcamscene.h"
+#include "qtcamcapability_p.h"
+
+QtCamScene::QtCamScene(QtCamDevice *dev, QObject *parent) :
+  QtCamCapability(new QtCamCapabilityPrivate(dev, QtCamCapability::Scene, "scene-mode"), parent) {
+
+}
+
+QtCamScene::~QtCamScene() {
+
+}
+
+QtCamScene::SceneMode QtCamScene::value() {
+  int val = 0;
+  if (!d_ptr->intValue(&val)) {
+    return QtCamScene::Auto;
+  }
+
+  switch (val) {
+  case QtCamScene::Manual:
+  case QtCamScene::Closeup:
+  case QtCamScene::Portrait:
+  case QtCamScene::Landscape:
+  case QtCamScene::Sport:
+  case QtCamScene::Night:
+    return (QtCamScene::SceneMode)val;
+
+  default:
+    return QtCamScene::Auto;
+  }
+}
+
+bool QtCamScene::setValue(const QtCamScene::SceneMode& mode) {
+  return d_ptr->setIntValue(mode);
+}
diff --git a/lib/qtcamscene.h b/lib/qtcamscene.h
new file mode 100644 (file)
index 0000000..92f2b72
--- /dev/null
@@ -0,0 +1,29 @@
+// -*- c++ -*-
+
+#ifndef QT_CAM_SCENE_H
+#define QT_CAM_SCENE_H
+
+#include "qtcamcapability.h"
+
+class QtCamScene : public QtCamCapability {
+  Q_OBJECT
+
+public:
+  typedef enum {
+    Manual = 0,
+    Closeup = 1,
+    Portrait = 2,
+    Landscape = 3,
+    Sport = 4,
+    Night = 5,
+    Auto = 6
+  } SceneMode;
+
+  QtCamScene(QtCamDevice *dev, QObject *parent = 0);
+  ~QtCamScene();
+
+  SceneMode value();
+  bool setValue(const SceneMode& mode);
+};
+
+#endif /* QT_CAM_SCENE_H */
diff --git a/lib/qtcamzoom.cpp b/lib/qtcamzoom.cpp
new file mode 100644 (file)
index 0000000..5bf0d8a
--- /dev/null
@@ -0,0 +1,107 @@
+#include "qtcamzoom.h"
+#include "qtcamcapability_p.h"
+#include "qtcamdevice_p.h"
+
+class QtCamZoomPrivate : public QtCamCapabilityPrivate {
+public:
+  QtCamZoomPrivate(QtCamDevice *d, QtCamZoom *q) :
+    QtCamCapabilityPrivate(d, QtCamCapability::Zoom), q_ptr(q), binHandler(0) {
+
+  }
+
+  ~QtCamZoomPrivate() {
+    if (binHandler) {
+      g_signal_handler_disconnect(bin, binHandler);
+    }
+  }
+
+  void init() {
+    if (bin) {
+      binHandler = g_signal_connect(bin, "notify", G_CALLBACK(camera_bin_notify), this);
+    }
+  }
+
+  static void camera_bin_notify(GObject *gobject, GParamSpec *pspec, QtCamZoomPrivate *d) {
+    Q_UNUSED(gobject);
+
+    QLatin1String name(pspec->name);
+    if (name == QLatin1String("max-zoom")) {
+      QMetaObject::invokeMethod(d->q_ptr, "maximumValueChanged", Qt::QueuedConnection);
+    }
+    else if (name == QLatin1String("zoom")) {
+      QMetaObject::invokeMethod(d->q_ptr, "valueChanged", Qt::QueuedConnection);
+    }
+  }
+
+  qreal zoom() {
+    if (!bin) {
+      return 1.0;
+    }
+
+    gfloat v = 1.0;
+
+    g_object_get(bin, "zoom", &v, NULL);
+
+    return v;
+  }
+
+  qreal maxZoom() {
+    if (!bin) {
+      return 1.0;
+    }
+
+    gfloat v = 1.0;
+
+    g_object_get(bin, "max-zoom", &v, NULL);
+
+    return v;
+  }
+
+  bool setZoom(qreal zoom) {
+    if (!bin) {
+      return false;
+    }
+
+    if (qFuzzyCompare(QtCamZoomPrivate::zoom(), zoom)) {
+       return false;
+      }
+
+    g_object_set(bin, "zoom", zoom, NULL);
+
+    return true;
+  }
+
+  QtCamZoom *q_ptr;
+  gulong binHandler;
+};
+
+QtCamZoom::QtCamZoom(QtCamDevice *dev, QObject *parent) :
+  QtCamCapability(new QtCamZoomPrivate(dev, this), parent) {
+
+  ((QtCamZoomPrivate *) d_ptr)->init();
+}
+
+QtCamZoom::~QtCamZoom() {
+
+}
+
+qreal QtCamZoom::value() {
+  return ((QtCamZoomPrivate *) d_ptr)->zoom();
+}
+
+bool QtCamZoom::setValue(qreal zoom) {
+  if (((QtCamZoomPrivate *) d_ptr)->setZoom(zoom)) {
+    emit valueChanged();
+    return true;
+  }
+
+  return false;
+}
+
+qreal QtCamZoom::minimumValue() {
+  return 1.0;
+}
+
+qreal QtCamZoom::maximumValue() {
+  return ((QtCamZoomPrivate *) d_ptr)->maxZoom();
+}
diff --git a/lib/qtcamzoom.h b/lib/qtcamzoom.h
new file mode 100644 (file)
index 0000000..0961a3a
--- /dev/null
@@ -0,0 +1,18 @@
+// -*- c++ -*-
+
+#include "qtcamcapability.h"
+
+class QtCamZoomPrivate;
+
+class QtCamZoom : public QtCamCapability {
+  Q_OBJECT
+
+public:
+  QtCamZoom(QtCamDevice *dev, QObject *parent = 0);
+  ~QtCamZoom();
+
+  qreal value();
+  bool setValue(qreal zoom);
+  qreal minimumValue();
+  qreal maximumValue();
+};