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),
53 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
54 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
56 qWarning() << "Failed to create" << elementName;
60 g_object_set(cameraBin, prop, elem, NULL);
65 void createAndAddVideoSource() {
66 // TODO: rework this function
67 GstElement *src, *wrapper;
68 QString wrapperSrc = conf->wrapperVideoSource();
69 QString prop = conf->wrapperVideoSourceProperty();
71 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
72 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
74 qCritical() << "Failed to create wrapper source" << wrapperSrc;
79 src = gst_element_factory_make(conf->videoSource().toAscii(),
82 qCritical() << "Failed to create video source";
84 gst_object_unref(wrapper);
90 g_object_set(wrapper, prop.toAscii(), src, NULL);
91 g_object_set(cameraBin, "camera-source", wrapper, NULL);
95 wrapperVideoSource = wrapper;
97 if (!id.isValid() || id.isNull()) {
101 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
102 int dev = id.toInt();
103 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
106 QString dev = id.toString();
107 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
108 dev.toAscii().data(), NULL);
112 bool setViewfinderSink() {
114 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
117 gst_object_unref(sink);
121 sink = viewfinder->sinkElement();
123 qCritical() << "Failed to create GStreamer sink element";
127 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
132 void _d_error(const QString& message, int code, const QString& debug) {
135 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
136 Q_ARG(int, code), Q_ARG(QString, debug));
139 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
144 QMetaObject::invokeMethod(q_ptr, "stopped");
149 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
152 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
153 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
159 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
162 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
163 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
167 void setAudioCaptureCaps() {
168 QString captureCaps = conf->audioCaptureCaps();
169 if (!captureCaps.isEmpty()) {
170 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
172 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
173 gst_caps_unref(caps);
178 bool isWrapperReady() {
179 if (!wrapperVideoSource) {
183 gboolean ready = FALSE;
184 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
186 return ready == TRUE;
189 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
190 QtCamDevicePrivate *d) {
198 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
201 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
205 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
206 Q_ARG(bool, d->q_ptr->isIdle()));
210 void resetCapabilities() {
211 g_object_set(cameraBin, "zoom", 1.0, NULL);
212 g_object_set(videoSource, "flash-mode", 0, NULL);
214 // TODO: should scene mode be manual or automatic ?
215 g_object_set(videoSource, "scene-mode", 0, NULL);
224 GstElement *cameraBin;
225 GstElement *videoSource;
226 GstElement *wrapperVideoSource;
228 QtCamImageMode *image;
229 QtCamVideoMode *video;
232 QtCamViewfinder *viewfinder;
234 QtCamGStreamerMessageListener *listener;
238 #endif /* QT_CAM_DEVICE_P_H */