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),
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) {
136 // TODO: is it wise to ignore errors while stopping??
142 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
143 Q_ARG(int, code), Q_ARG(QString, debug));
146 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
151 QMetaObject::invokeMethod(q_ptr, "stopped");
156 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
159 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
160 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
166 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
169 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
170 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
174 void setAudioCaptureCaps() {
175 QString captureCaps = conf->audioCaptureCaps();
176 if (!captureCaps.isEmpty()) {
177 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
179 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
180 gst_caps_unref(caps);
185 bool isWrapperReady() {
186 if (!wrapperVideoSource) {
190 gboolean ready = FALSE;
191 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
193 return ready == TRUE;
196 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
197 QtCamDevicePrivate *d) {
205 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
208 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
212 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
213 Q_ARG(bool, d->q_ptr->isIdle()));
217 void resetCapabilities() {
218 g_object_set(cameraBin, "zoom", 1.0, NULL);
219 g_object_set(videoSource, "flash-mode", 0, NULL);
221 // TODO: should scene mode be manual or automatic ?
222 g_object_set(videoSource, "scene-mode", 0, NULL);
231 GstElement *cameraBin;
232 GstElement *videoSource;
233 GstElement *wrapperVideoSource;
235 QtCamImageMode *image;
236 QtCamVideoMode *video;
239 QtCamViewfinder *viewfinder;
241 QtCamGStreamerMessageListener *listener;
243 QtCamNotifications *notifications;
247 #endif /* QT_CAM_DEVICE_P_H */