4 * This file is part of CameraPlus.
6 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef QT_CAM_AUTO_FOCUS_P_H
24 #define QT_CAM_AUTO_FOCUS_P_H
26 #include "qtcamautofocus.h"
27 #include "qtcamgstreamermessagehandler.h"
28 #include "qtcamgstreamermessagelistener.h"
29 #include "qtcamdevice.h"
30 #include "qtcamdevice_p.h"
34 #ifndef GST_USE_UNSTABLE_API
35 #define GST_USE_UNSTABLE_API
36 #endif /* GST_USE_UNSTABLE_API */
37 #include <gst/interfaces/photography.h>
39 class QtCamAutoFocusPrivate : public QObject {
43 QtCamAutoFocusPrivate(QtCamDevice *device, QtCamAutoFocus *q, QObject *parent = 0) :
47 status(QtCamAutoFocus::None),
48 cafStatus(QtCamAutoFocus::None) {
50 handler = new QtCamGStreamerMessageHandler(GST_PHOTOGRAPHY_AUTOFOCUS_DONE, this);
52 QObject::connect(handler, SIGNAL(messageSent(GstMessage *)),
53 this, SLOT(handleMessage(GstMessage *)));
55 dev->listener()->addHandler(handler);
57 cafHandler = new QtCamGStreamerMessageHandler("caf-update", this);
59 QObject::connect(cafHandler, SIGNAL(messageSent(GstMessage *)),
60 this, SLOT(handleCafMessage(GstMessage *)));
62 dev->listener()->addHandler(cafHandler);
65 ~QtCamAutoFocusPrivate() {
66 dev->listener()->removeHandler(handler);
67 delete handler; handler = 0;
72 bool setEnabled(bool enabled) {
73 if (!dev->d_ptr->videoSource) {
77 if (!GST_IS_PHOTOGRAPHY(dev->d_ptr->videoSource)) {
81 GstPhotography *photo = GST_PHOTOGRAPHY(dev->d_ptr->videoSource);
86 gst_photography_set_autofocus(photo, enabled ? TRUE : FALSE);
91 bool setStatus(QtCamAutoFocus::Status *status, GstMessage *message) {
92 const GstStructure *s = gst_message_get_structure(message);
93 int st = GST_PHOTOGRAPHY_FOCUS_STATUS_NONE;
95 if (gst_structure_get_int(s, "status", &st)) {
97 *status = (QtCamAutoFocus::Status) st;
106 void handleMessage(GstMessage *message) {
107 if (setStatus(&status, message)) {
108 // TODO: focus-window-rows, focus-window-columns, focus-windows and the rest
109 emit q_ptr->statusChanged();
113 void handleCafMessage(GstMessage *message) {
114 if (setStatus(&cafStatus, message)) {
115 emit q_ptr->cafStatusChanged();
121 QtCamAutoFocus *q_ptr;
123 QtCamAutoFocus::Status status;
124 QtCamAutoFocus::Status cafStatus;
126 QtCamGStreamerMessageHandler *handler;
127 QtCamGStreamerMessageHandler *cafHandler;
130 #endif /* QT_CAM_AUTO_FOCUS_P_H */