Added QtCamAutoFocus
authorMohammed Sameer <msameer@foolab.org>
Wed, 31 Oct 2012 00:14:50 +0000 (02:14 +0200)
committerMohammed Sameer <msameer@foolab.org>
Wed, 31 Oct 2012 00:14:50 +0000 (02:14 +0200)
lib/lib.pro
lib/qtcamautofocus.cpp [new file with mode: 0644]
lib/qtcamautofocus.h [new file with mode: 0644]
lib/qtcamautofocus_p.h [new file with mode: 0644]
lib/qtcamcaf.h
lib/qtcamdevice.h

index e78b764..87fcf44 100644 (file)
@@ -18,7 +18,7 @@ HEADERS += qtcamconfig.h qtcamera.h qtcamscanner.h qtcamdevice.h qtcamviewfinder
            qtcamzoom.h qtcamflash.h qtcamscene.h qtcamevcomp.h qtcamvideotorch.h \
            qtcamwhitebalance.h qtcamcolortone.h qtcamflickerreduction.h \
            qtcamnoisereduction.h qtcamiso.h qtcamaperture.h qtcamexposure.h \
-           qtcammute.h qtcamnotifications.h qtcamfocus.h qtcamcaf.h
+           qtcammute.h qtcamnotifications.h qtcamfocus.h qtcamcaf.h qtcamautofocus.h
 
 SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamviewfinder.cpp \
            qtcammode.cpp qtcamgstreamermessagehandler.cpp qtcamgstreamermessagelistener.cpp \
@@ -28,9 +28,9 @@ SOURCES += qtcamconfig.cpp qtcamera.cpp qtcamscanner.cpp qtcamdevice.cpp qtcamvi
            qtcamzoom.cpp qtcamflash.cpp qtcamscene.cpp qtcamevcomp.cpp qtcamvideotorch.cpp \
            qtcamwhitebalance.cpp qtcamcolortone.cpp qtcamflickerreduction.cpp \
            qtcamnoisereduction.cpp qtcamiso.cpp qtcamaperture.cpp qtcamexposure.cpp \
-           qtcammute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamcaf.cpp
+           qtcammute.cpp qtcamnotifications.cpp qtcamfocus.cpp qtcamcaf.cpp qtcamautofocus.cpp
 
-HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamcaf_p.h
+HEADERS += qtcammode_p.h qtcamdevice_p.h qtcamcapability_p.h qtcamcaf_p.h qtcamautofocus_p.h
 
 LIBS += -lgstphotography-0.10
 
diff --git a/lib/qtcamautofocus.cpp b/lib/qtcamautofocus.cpp
new file mode 100644 (file)
index 0000000..b1cdf53
--- /dev/null
@@ -0,0 +1,44 @@
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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 "qtcamautofocus.h"
+#include "qtcamautofocus_p.h"
+
+QtCamAutoFocus::QtCamAutoFocus(QtCamDevice *dev, QObject *parent) :
+  QObject(parent),
+  d_ptr(new QtCamAutoFocusPrivate(dev, this, this)) {
+
+}
+
+QtCamAutoFocus::~QtCamAutoFocus() {
+  delete d_ptr; d_ptr = 0;
+}
+
+QtCamAutoFocus::Status QtCamAutoFocus::status() {
+  return d_ptr->status;
+}
+
+bool QtCamAutoFocus::start() {
+  return d_ptr->setEnabled(true);
+}
+
+bool QtCamAutoFocus::stop() {
+  return d_ptr->setEnabled(false);
+}
diff --git a/lib/qtcamautofocus.h b/lib/qtcamautofocus.h
new file mode 100644 (file)
index 0000000..e201e2d
--- /dev/null
@@ -0,0 +1,61 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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_AUTO_FOCUS_H
+#define QT_CAM_AUTO_FOCUS_H
+
+#include <QObject>
+
+class QtCamDevice;
+class QtCamAutoFocusPrivate;
+
+class QtCamAutoFocus : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(Status status READ status NOTIFY statusChanged);
+  Q_ENUMS(Status);
+
+  friend class QtCamAutoFocusPrivate;
+
+public:
+  typedef enum {
+    None = 0,
+    Running = 1,
+    Fail = 2,
+    Success = 3,
+  } Status;
+
+  QtCamAutoFocus(QtCamDevice *dev, QObject *parent = 0);
+  ~QtCamAutoFocus();
+
+  Status status();
+
+  bool start();
+  bool stop();
+
+signals:
+  void statusChanged();
+
+private:
+  QtCamAutoFocusPrivate *d_ptr;
+};
+
+#endif /* QT_CAM_AUTO_FOCUS_H */
diff --git a/lib/qtcamautofocus_p.h b/lib/qtcamautofocus_p.h
new file mode 100644 (file)
index 0000000..097305d
--- /dev/null
@@ -0,0 +1,105 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * 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_AUTO_FOCUS_P_H
+#define QT_CAM_AUTO_FOCUS_P_H
+
+#include "qtcamautofocus.h"
+#include "qtcamgstreamermessagehandler.h"
+#include "qtcamgstreamermessagelistener.h"
+#include "qtcamdevice.h"
+#include "qtcamdevice_p.h"
+
+#include <QDebug>
+
+#ifndef GST_USE_UNSTABLE_API
+#define GST_USE_UNSTABLE_API
+#endif /* GST_USE_UNSTABLE_API */
+#include <gst/interfaces/photography.h>
+
+class QtCamAutoFocusPrivate : public QObject {
+  Q_OBJECT
+
+public:
+  QtCamAutoFocusPrivate(QtCamDevice *device, QtCamAutoFocus *q, QObject *parent = 0) :
+    QObject(parent),
+    dev(device),
+    q_ptr(q),
+    status(QtCamAutoFocus::None) {
+
+    handler = new QtCamGStreamerMessageHandler(GST_PHOTOGRAPHY_AUTOFOCUS_DONE, this);
+
+    QObject::connect(handler, SIGNAL(messageSent(GstMessage *)),
+                    this, SLOT(handleMessage(GstMessage *)));
+
+    dev->listener()->addHandler(handler);
+  }
+
+  ~QtCamAutoFocusPrivate() {
+    dev->listener()->removeHandler(handler);
+    delete handler; handler = 0;
+    dev = 0;
+    q_ptr = 0;
+  }
+
+  bool setEnabled(bool enabled) {
+    if (!dev->d_ptr->videoSource) {
+      return false;
+    }
+
+    if (!GST_IS_PHOTOGRAPHY(dev->d_ptr->videoSource)) {
+      return false;
+    }
+
+    GstPhotography *photo = GST_PHOTOGRAPHY(dev->d_ptr->videoSource);
+    if (!photo) {
+      return false;
+    }
+
+    gst_photography_set_autofocus(photo, enabled ? TRUE : FALSE);
+
+    return true;
+  }
+
+public slots:
+  void handleMessage(GstMessage *message) {
+    const GstStructure *s = gst_message_get_structure(message);
+    int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
+
+    if (gst_structure_get_int(s, "status", &st)) {
+      if (status != st) {
+       status = (QtCamAutoFocus::Status) st;
+
+       // TODO: focus-window-rows, focus-window-columns, focus-windows and the rest
+       emit q_ptr->statusChanged();
+      }
+    }
+  }
+
+public:
+  QtCamDevice *dev;
+  QtCamAutoFocus *q_ptr;
+  QtCamAutoFocus::Status status;
+  QtCamGStreamerMessageHandler *handler;
+};
+
+#endif /* QT_CAM_AUTO_FOCUS_P_H */
index 10f0047..68510ed 100644 (file)
@@ -29,9 +29,7 @@ class QtCamDevice;
 class QtCamCafPrivate;
 
 class QtCamCaf : public QObject {
-
   Q_OBJECT
-
   Q_PROPERTY(Status status READ status NOTIFY statusChanged);
   Q_ENUMS(Status);
 
index 1f75d3d..0428f4d 100644 (file)
@@ -82,6 +82,7 @@ private:
   friend class QtCamCapability;
   friend class QtCamVideoTorch;
   friend class QtCamMute;
+  friend class QtCamAutoFocusPrivate;
 
   QtCamDevicePrivate *d_ptr;
 };