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_DEVICE_P_H
24 #define QT_CAM_DEVICE_P_H
28 #include "qtcamconfig.h"
29 #include "qtcamviewfinder.h"
30 #include "qtcamdevice.h"
31 #include "qtcammode.h"
32 #include "qtcamanalysisbin.h"
34 class QtCamGStreamerMessageListener;
39 class QtCamDevicePrivate {
41 QtCamDevicePrivate() :
44 wrapperVideoSource(0),
55 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
56 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
58 qWarning() << "Failed to create" << elementName;
62 g_object_set(cameraBin, prop, elem, NULL);
67 void createAndAddVideoSource() {
68 // TODO: rework this function
69 GstElement *src, *wrapper;
70 QString wrapperSrc = conf->wrapperVideoSource();
71 QString prop = conf->wrapperVideoSourceProperty();
73 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
74 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
76 qCritical() << "Failed to create wrapper source" << wrapperSrc;
81 src = gst_element_factory_make(conf->videoSource().toAscii(),
84 qCritical() << "Failed to create video source";
86 gst_object_unref(wrapper);
92 g_object_set(wrapper, prop.toAscii(), src, NULL);
93 g_object_set(cameraBin, "camera-source", wrapper, NULL);
97 wrapperVideoSource = wrapper;
99 if (!id.isValid() || id.isNull()) {
103 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
104 int dev = id.toInt();
105 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
108 QString dev = id.toString();
109 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
110 dev.toAscii().data(), NULL);
114 bool setViewfinderSink() {
116 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
119 gst_object_unref(sink);
123 sink = viewfinder->sinkElement();
125 qCritical() << "Failed to create GStreamer sink element";
129 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
134 void _d_error(const QString& message, int code, const QString& debug) {
137 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
138 Q_ARG(int, code), Q_ARG(QString, debug));
141 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
146 QMetaObject::invokeMethod(q_ptr, "stopped");
151 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
154 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
155 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
161 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
164 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
165 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
169 void setAudioCaptureCaps() {
170 QString captureCaps = conf->audioCaptureCaps();
171 if (!captureCaps.isEmpty()) {
172 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
174 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
175 gst_caps_unref(caps);
180 void addViewfinderFilters() {
181 addElements("viewfinder-filter", conf->viewfinderFilters());
184 bool isWrapperReady() {
185 if (!wrapperVideoSource) {
189 gboolean ready = FALSE;
190 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
192 return ready == TRUE;
195 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
196 QtCamDevicePrivate *d) {
204 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
207 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
211 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
212 Q_ARG(bool, d->q_ptr->isIdle()));
215 void addElements(const char *prop, const QStringList& elements) {
216 QList<GstElement *> list;
218 if (elements.isEmpty()) {
222 foreach (const QString& element, elements) {
223 GstElement *elem = gst_element_factory_make(element.toUtf8().constData(), NULL);
225 qWarning() << "Failed to create element" << element;
232 if (list.isEmpty()) {
236 GstElement *bin = qt_cam_analysis_bin_create(list, prop);
238 qWarning() << "Failed to create bin for" << prop;
242 g_object_set(cameraBin, prop, bin, NULL);
246 void resetCapabilities() {
247 g_object_set(cameraBin, "zoom", 1.0, NULL);
248 g_object_set(videoSource, "flash-mode", 0, NULL);
250 // TODO: should scene mode be manual or automatic ?
251 g_object_set(videoSource, "scene-mode", 0, NULL);
260 GstElement *cameraBin;
261 GstElement *videoSource;
262 GstElement *wrapperVideoSource;
264 QtCamImageMode *image;
265 QtCamVideoMode *video;
268 QtCamViewfinder *viewfinder;
270 QtCamGStreamerMessageListener *listener;
272 QtCamNotifications *notifications;
275 #endif /* QT_CAM_DEVICE_P_H */