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;
37 class QtCamPropertySetter;
38 class QtCamAnalysisBin;
40 class QtCamDevicePrivate {
42 QtCamDevicePrivate() :
45 wrapperVideoSource(0),
53 viewfinderFilters(0) {
57 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
58 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
60 qWarning() << "Failed to create" << elementName;
64 g_object_set(cameraBin, prop, elem, NULL);
69 void createAndAddVideoSourceAndWrapper() {
70 videoSource = gst_element_factory_make(conf->videoSource().toUtf8().constData(),
72 wrapperVideoSource = gst_element_factory_make(conf->wrapperVideoSource().toUtf8().constData(),
73 "QCameraWrapperVideoSrc");
75 if (wrapperVideoSource && videoSource) {
76 g_object_set(wrapperVideoSource, conf->wrapperVideoSourceProperty().toUtf8().constData(),
78 g_object_set(cameraBin, "camera-source", wrapperVideoSource, NULL);
80 else if (wrapperVideoSource) {
81 qWarning() << "Failed to create video source";
82 g_object_set(cameraBin, "camera-source", wrapperVideoSource, NULL);
84 else if (videoSource) {
85 qWarning() << "Failed to create wrapper source";
86 g_object_set(cameraBin, "camera-source", videoSource, NULL);
89 qWarning() << "Failed to create both video and wrapper sources";
93 void createAndAddVideoSource() {
94 videoSource = gst_element_factory_make(conf->videoSource().toUtf8().constData(),
97 qCritical() << "Failed to create video source";
100 g_object_set(cameraBin, "camera-source", videoSource, NULL);
104 void setDevicePoperty() {
106 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
107 int dev = id.toInt();
108 g_object_set(videoSource, conf->deviceScannerProperty().toAscii().constData(), dev, NULL);
111 QString dev = id.toString();
112 g_object_set(videoSource, conf->deviceScannerProperty().toAscii().constData(),
113 dev.toAscii().constData(), NULL);
118 bool setViewfinderSink() {
119 GstElement *sink = 0;
120 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
123 gst_object_unref(sink);
127 sink = viewfinder->sinkElement();
129 qCritical() << "Failed to create GStreamer sink element";
133 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
138 void _d_error(const QString& message, int code, const QString& debug) {
141 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
142 Q_ARG(int, code), Q_ARG(QString, debug));
145 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
150 QMetaObject::invokeMethod(q_ptr, "stopped");
155 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
158 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
159 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
165 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
168 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
169 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
173 void setAudioCaptureCaps() {
174 QString captureCaps = conf->audioCaptureCaps();
175 if (!captureCaps.isEmpty()) {
176 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
178 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
179 gst_caps_unref(caps);
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()));
220 GstElement *cameraBin;
221 GstElement *videoSource;
222 GstElement *wrapperVideoSource;
224 QtCamImageMode *image;
225 QtCamVideoMode *video;
228 QtCamViewfinder *viewfinder;
230 QtCamGStreamerMessageListener *listener;
232 QtCamNotifications *notifications;
233 QtCamPropertySetter *propertySetter;
234 QtCamAnalysisBin *viewfinderFilters;
237 #endif /* QT_CAM_DEVICE_P_H */