Use a message listener to detect auto focus acquisition instead of constructing QtCam...
authorMohammed Sameer <msameer@foolab.org>
Sat, 15 Dec 2012 02:41:32 +0000 (04:41 +0200)
committerMohammed Sameer <msameer@foolab.org>
Sat, 15 Dec 2012 02:41:32 +0000 (04:41 +0200)
lib/qtcamnotifications.cpp
lib/qtcamnotifications.h
lib/qtcamnotifications_p.h

index a147ade..14a35ca 100644 (file)
 #include "qtcamnotifications.h"
 #include "qtcamnotifications_p.h"
 #include "qtcamdevice.h"
+#ifndef GST_USE_UNSTABLE_API
+#define GST_USE_UNSTABLE_API
+#endif /* GST_USE_UNSTABLE_API */
+#include <gst/interfaces/photography.h>
 
 QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
   QObject(parent), d_ptr(new QtCamNotificationsPrivate) {
@@ -32,13 +36,13 @@ QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
   d_ptr->imageStart = new QtCamGStreamerMessageHandler("photo-capture-start", this);
   d_ptr->imageEnd = new QtCamGStreamerMessageHandler("photo-capture-end", this);
   d_ptr->videoDone = new QtCamGStreamerMessageHandler("video-done", this);
-
-  d_ptr->af = new QtCamAutoFocus(dev, this);
+  d_ptr->af = new QtCamGStreamerMessageHandler(GST_PHOTOGRAPHY_AUTOFOCUS_DONE, this);
 
   if (d_ptr->listener) {
     d_ptr->listener->addSyncHandler(d_ptr->imageStart);
     d_ptr->listener->addHandler(d_ptr->imageEnd);
     d_ptr->listener->addHandler(d_ptr->videoDone);
+    d_ptr->listener->addHandler(d_ptr->af);
   }
 
   QObject::connect(d_ptr->imageStart, SIGNAL(messageSent(GstMessage *)),
@@ -50,7 +54,8 @@ QtCamNotifications::QtCamNotifications(QtCamDevice *dev, QObject *parent) :
   QObject::connect(d_ptr->videoDone, SIGNAL(messageSent(GstMessage *)),
                   this, SIGNAL(videoRecordingEnded()), Qt::DirectConnection);
 
-  QObject::connect(d_ptr->af, SIGNAL(statusChanged()), this, SLOT(autoFocusStatusChanged()));
+  QObject::connect(d_ptr->af, SIGNAL(messageSent(GstMessage *)),
+                  this, SLOT(autoFocusStatusChanged(GstMessage *)));
 }
 
 QtCamNotifications::~QtCamNotifications() {
@@ -58,12 +63,13 @@ QtCamNotifications::~QtCamNotifications() {
     d_ptr->listener->removeSyncHandler(d_ptr->imageStart);
     d_ptr->listener->removeHandler(d_ptr->imageEnd);
     d_ptr->listener->removeHandler(d_ptr->videoDone);
+    d_ptr->listener->removeHandler(d_ptr->af);
   }
 
   delete d_ptr->imageStart.data();
   delete d_ptr->imageEnd.data();
-
-  delete d_ptr->af;
+  delete d_ptr->videoDone.data();
+  delete d_ptr->af.data();
 
   delete d_ptr; d_ptr = 0;
 }
index 784ab61..140ccc6 100644 (file)
@@ -49,7 +49,7 @@ signals:
   void autoFocusAcquired();
 
 private:
-  Q_PRIVATE_SLOT(d_ptr, void autoFocusStatusChanged());
+  Q_PRIVATE_SLOT(d_ptr, void autoFocusStatusChanged(GstMessage *));
 
   QtCamNotificationsPrivate *d_ptr;
 };
index c61c535..a2422f4 100644 (file)
 #define QT_CAM_NOTIFICATIONS_P_H
 
 #include <QPointer>
-#include "qtcamautofocus.h"
 #include "qtcamgstreamermessagehandler.h"
 #include "qtcamgstreamermessagelistener.h"
 #include "qtcamnotifications.h"
+#ifndef GST_USE_UNSTABLE_API
+#define GST_USE_UNSTABLE_API
+#endif /* GST_USE_UNSTABLE_API */
+#include <gst/interfaces/photography.h>
 
 class QtCamNotificationsPrivate : public QObject {
   Q_OBJECT
@@ -38,15 +41,25 @@ public:
   QPointer<QtCamGStreamerMessageHandler> imageEnd;
 
   QPointer<QtCamGStreamerMessageHandler> videoDone;
+
+  QPointer<QtCamGStreamerMessageHandler> af;
+
   QPointer<QtCamGStreamerMessageListener> listener;
-  QPointer<QtCamAutoFocus> af;
 
   QtCamNotifications *q_ptr;
 
 public slots:
-  void autoFocusStatusChanged() {
-    if (af->status() == QtCamAutoFocus::Success) {
-      emit q_ptr->autoFocusAcquired();
+  void autoFocusStatusChanged(GstMessage *message) {
+    if (!message || !gst_message_get_structure(message)) {
+      return;
+    }
+
+    const GstStructure *s = gst_message_get_structure(message);
+    int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
+    if (gst_structure_get_int(s, "status", &st)) {
+      if (st == GST_PHOTOGRAPHY_FOCUS_STATUS_SUCCESS) {
+       emit q_ptr->autoFocusAcquired();
+      }
     }
   }
 };