From: Mohammed Sameer Date: Sat, 15 Dec 2012 02:41:32 +0000 (+0200) Subject: Use a message listener to detect auto focus acquisition instead of constructing QtCam... X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=4f75611d8145b7b01058a0f2fa6d59ae75c7e678;hp=895498a17049de7244e8bc6e6f8031388a1da209 Use a message listener to detect auto focus acquisition instead of constructing QtCamAutoFocus --- diff --git a/lib/qtcamnotifications.cpp b/lib/qtcamnotifications.cpp index a147ade..14a35ca 100644 --- a/lib/qtcamnotifications.cpp +++ b/lib/qtcamnotifications.cpp @@ -21,6 +21,10 @@ #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 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; } diff --git a/lib/qtcamnotifications.h b/lib/qtcamnotifications.h index 784ab61..140ccc6 100644 --- a/lib/qtcamnotifications.h +++ b/lib/qtcamnotifications.h @@ -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; }; diff --git a/lib/qtcamnotifications_p.h b/lib/qtcamnotifications_p.h index c61c535..a2422f4 100644 --- a/lib/qtcamnotifications_p.h +++ b/lib/qtcamnotifications_p.h @@ -24,10 +24,13 @@ #define QT_CAM_NOTIFICATIONS_P_H #include -#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 class QtCamNotificationsPrivate : public QObject { Q_OBJECT @@ -38,15 +41,25 @@ public: QPointer imageEnd; QPointer videoDone; + + QPointer af; + QPointer listener; - QPointer 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(); + } } } };