4 * This file is part of CameraPlus.
6 * Copyright (C) 2012-2013 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;
37 class QtCamPropertySetter;
38 class QtCamAnalysisBin;
40 class QtCamDevicePrivate {
42 QtCamDevicePrivate() :
45 wrapperVideoSource(0),
54 viewfinderFilters(0) {
58 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
59 GstElement *elem = gst_element_factory_make(elementName.toLatin1(), name);
61 qWarning() << "Failed to create" << elementName;
65 g_object_set(cameraBin, prop, elem, NULL);
70 void createAndAddVideoSourceAndWrapper() {
71 videoSource = gst_element_factory_make(conf->videoSource().toUtf8().constData(),
73 wrapperVideoSource = gst_element_factory_make(conf->wrapperVideoSource().toUtf8().constData(),
74 "QCameraWrapperVideoSrc");
76 if (wrapperVideoSource && videoSource) {
77 g_object_set(wrapperVideoSource, conf->wrapperVideoSourceProperty().toUtf8().constData(),
79 g_object_set(cameraBin, "camera-source", wrapperVideoSource, NULL);
81 else if (wrapperVideoSource) {
82 qWarning() << "Failed to create video source";
83 g_object_set(cameraBin, "camera-source", wrapperVideoSource, NULL);
85 else if (videoSource) {
86 qWarning() << "Failed to create wrapper source";
87 g_object_set(cameraBin, "camera-source", videoSource, NULL);
90 qWarning() << "Failed to create both video and wrapper sources";
94 void createAndAddVideoSource() {
95 videoSource = gst_element_factory_make(conf->videoSource().toUtf8().constData(),
98 qCritical() << "Failed to create video source";
101 g_object_set(cameraBin, "camera-source", videoSource, NULL);
105 void setDevicePoperty() {
107 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
108 int dev = id.toInt();
109 g_object_set(videoSource, conf->deviceScannerProperty().toLatin1().constData(), dev, NULL);
112 QString dev = id.toString();
113 g_object_set(videoSource, conf->deviceScannerProperty().toLatin1().constData(),
114 dev.toLatin1().constData(), NULL);
119 bool setViewfinderSink() {
124 sink = viewfinder->sinkElement();
126 qCritical() << "Failed to create GStreamer sink element";
130 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
135 void _d_error(const QString& message, int code, const QString& debug) {
138 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
139 Q_ARG(int, code), Q_ARG(QString, debug));
142 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
147 QMetaObject::invokeMethod(q_ptr, "stopped");
152 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
155 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
156 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
162 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
165 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
166 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
170 void setAudioCaptureCaps() {
171 QString captureCaps = conf->audioCaptureCaps();
172 if (!captureCaps.isEmpty()) {
173 GstCaps *caps = gst_caps_from_string(captureCaps.toLatin1().data());
175 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
176 gst_caps_unref(caps);
181 bool isReadyForCapture() {
182 GstElement *src = videoSource;
183 if (wrapperVideoSource) {
184 src = wrapperVideoSource;
191 gboolean ready = FALSE;
192 g_object_get(src, "ready-for-capture", &ready, NULL);
194 return ready == TRUE;
197 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
198 QtCamDevicePrivate *d) {
206 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
209 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
213 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
214 Q_ARG(bool, d->q_ptr->isIdle()));
222 GstElement *cameraBin;
223 GstElement *videoSource;
224 GstElement *wrapperVideoSource;
227 QtCamImageMode *image;
228 QtCamVideoMode *video;
231 QtCamViewfinder *viewfinder;
233 QtCamGStreamerMessageListener *listener;
235 QtCamNotifications *notifications;
236 QtCamPropertySetter *propertySetter;
237 QtCamAnalysisBin *viewfinderFilters;
240 #endif /* QT_CAM_DEVICE_P_H */