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"
33 class QtCamGStreamerMessageListener;
38 class QtCamDevicePrivate {
40 QtCamDevicePrivate() :
43 wrapperVideoSource(0),
54 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
55 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
57 qWarning() << "Failed to create" << elementName;
61 g_object_set(cameraBin, prop, elem, NULL);
66 void createAndAddVideoSource() {
67 // TODO: rework this function
68 GstElement *src, *wrapper;
69 QString wrapperSrc = conf->wrapperVideoSource();
70 QString prop = conf->wrapperVideoSourceProperty();
72 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
73 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
75 qCritical() << "Failed to create wrapper source" << wrapperSrc;
80 src = gst_element_factory_make(conf->videoSource().toAscii(),
83 qCritical() << "Failed to create video source";
85 gst_object_unref(wrapper);
91 g_object_set(wrapper, prop.toAscii(), src, NULL);
92 g_object_set(cameraBin, "camera-source", wrapper, NULL);
96 wrapperVideoSource = wrapper;
98 if (!id.isValid() || id.isNull()) {
102 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
103 int dev = id.toInt();
104 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
107 QString dev = id.toString();
108 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
109 dev.toAscii().data(), NULL);
113 bool setViewfinderSink() {
115 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
118 gst_object_unref(sink);
122 sink = viewfinder->sinkElement();
124 qCritical() << "Failed to create GStreamer sink element";
128 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
133 void _d_error(const QString& message, int code, const QString& debug) {
136 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
137 Q_ARG(int, code), Q_ARG(QString, debug));
140 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
145 QMetaObject::invokeMethod(q_ptr, "stopped");
150 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
153 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
154 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
160 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
163 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
164 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
168 void setAudioCaptureCaps() {
169 QString captureCaps = conf->audioCaptureCaps();
170 if (!captureCaps.isEmpty()) {
171 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
173 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
174 gst_caps_unref(caps);
179 bool isWrapperReady() {
180 if (!wrapperVideoSource) {
184 gboolean ready = FALSE;
185 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
187 return ready == TRUE;
190 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
191 QtCamDevicePrivate *d) {
199 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
202 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
206 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
207 Q_ARG(bool, d->q_ptr->isIdle()));
211 void resetCapabilities() {
212 g_object_set(cameraBin, "zoom", 1.0, NULL);
213 g_object_set(videoSource, "flash-mode", 0, NULL);
215 // TODO: should scene mode be manual or automatic ?
216 g_object_set(videoSource, "scene-mode", 0, NULL);
225 GstElement *cameraBin;
226 GstElement *videoSource;
227 GstElement *wrapperVideoSource;
229 QtCamImageMode *image;
230 QtCamVideoMode *video;
233 QtCamViewfinder *viewfinder;
235 QtCamGStreamerMessageListener *listener;
237 QtCamNotifications *notifications;
240 #endif /* QT_CAM_DEVICE_P_H */