Comment out resetCapabilities(). Not sure if it's needed
[harmattan/cameraplus] / lib / qtcamdevice_p.h
1 // -*- c++ -*-
2
3 #ifndef QT_CAM_DEVICE_P_H
4 #define QT_CAM_DEVICE_P_H
5
6 #include <QDebug>
7 #include <gst/gst.h>
8 #include "qtcamconfig.h"
9 #include "qtcamviewfinder.h"
10 #include "qtcamdevice.h"
11 #include "qtcammode.h"
12
13 class QtCamGStreamerMessageListener;
14 class QtCamMode;
15 class QtCamImageMode;
16 class QtCamVideoMode;
17
18 class QtCamDevicePrivate {
19 public:
20   QtCamDevicePrivate() :
21     cameraBin(0),
22     videoSource(0),
23     wrapperVideoSource(0),
24     image(0),
25     video(0),
26     active(0),
27     viewfinder(0),
28     conf(0),
29     error(false) {
30
31   }
32
33   GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
34     GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
35     if (!elem) {
36       qWarning() << "Failed to create" << elementName;
37       return 0;
38     }
39
40     g_object_set(cameraBin, prop, elem, NULL);
41
42     return elem;
43   }
44
45   void createAndAddVideoSource() {
46     GstElement *src, *wrapper;
47     QString wrapperSrc = conf->wrapperVideoSource();
48     QString prop = conf->wrapperVideoSourceProperty();
49
50     if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
51       wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
52       if (!wrapper) {
53         qCritical() << "Failed to create wrapper source" << wrapperSrc;
54         return;
55       }
56     }
57
58     src = gst_element_factory_make(conf->videoSource().toAscii(),
59                                                "QtCameraVideoSrc");
60     if (!src) {
61       qCritical() << "Failed to create video source";
62       if (wrapper) {
63         gst_object_unref(wrapper);
64       }
65       return;
66     }
67
68     if (wrapper) {
69       g_object_set(wrapper, prop.toAscii(), src, NULL);
70       g_object_set(cameraBin, "camera-source", wrapper, NULL);
71     }
72
73     videoSource = src;
74     wrapperVideoSource = wrapper;
75
76     if (!id.isValid() || id.isNull()) {
77       return;
78     }
79
80     if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
81       int dev = id.toInt();
82       g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
83     }
84     else {
85       QString dev = id.toString();
86       g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
87                    dev.toAscii().data(), NULL);
88     }
89   }
90
91   bool setViewfinderSink() {
92     GstElement *sink;
93     g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
94
95     if (sink) {
96       gst_object_unref(sink);
97       return true;
98     }
99
100     sink = viewfinder->sinkElement();
101     if (!sink) {
102       qCritical() << "Failed to create GStreamer sink element";
103       return false;
104     }
105
106     g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
107
108     return true;
109   }
110
111   void _d_error(const QString& message, int code, const QString& debug) {
112     error = true;
113
114     QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
115                               Q_ARG(int, code), Q_ARG(QString, debug));
116   }
117
118   void _d_stopped() {
119     QMetaObject::invokeMethod(q_ptr, "stopped");
120   }
121
122   void _d_stopping() {
123     if (active) {
124       QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
125     }
126
127     QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
128     QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
129                               Q_ARG(bool, false));
130   }
131
132   void _d_started() {
133     if (active) {
134       QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
135     }
136
137     QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
138     QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
139                               Q_ARG(bool, true));
140   }
141
142   void setAudioCaptureCaps() {
143     QString captureCaps = conf->audioCaptureCaps();
144     if (!captureCaps.isEmpty()) {
145       GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
146       if (caps) {
147         g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
148         gst_caps_unref(caps);
149       }
150     }
151   }
152
153   bool isWrapperReady() {
154     if (!wrapperVideoSource) {
155       return false;
156     }
157
158     gboolean ready = FALSE;
159     g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
160
161     return ready == TRUE;
162   }
163
164   static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
165                                            QtCamDevicePrivate *d)  {
166     Q_UNUSED(obj);
167     Q_UNUSED(pspec);
168
169     if (!d->active) {
170       return;
171     }
172
173     QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
174   }
175
176   static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
177     Q_UNUSED(obj);
178     Q_UNUSED(pspec);
179
180     QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
181                               Q_ARG(bool, d->q_ptr->isIdle()));
182   }
183
184 #if 0
185   void resetCapabilities() {
186     g_object_set(cameraBin, "zoom", 1.0, NULL);
187     g_object_set(videoSource, "flash-mode", 0, NULL);
188
189     // TODO: should scene mode be manual or automatic ?
190     g_object_set(videoSource, "scene-mode", 0, NULL);
191   }
192 #endif
193
194   QString name;
195   QVariant id;
196
197   QtCamDevice *q_ptr;
198
199   GstElement *cameraBin;
200   GstElement *videoSource;
201   GstElement *wrapperVideoSource;
202
203   QtCamImageMode *image;
204   QtCamVideoMode *video;
205   QtCamMode *active;
206
207   QtCamViewfinder *viewfinder;
208   QtCamConfig *conf;
209   QtCamGStreamerMessageListener *listener;
210   bool error;
211 };
212
213 #endif /* QT_CAM_DEVICE_P_H */