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),
53 viewfinderFilters(0) {
57 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
58 GstElement *elem = gst_element_factory_make(elementName.toLatin1(), 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().toLatin1().constData(), dev, NULL);
111 QString dev = id.toString();
112 g_object_set(videoSource, conf->deviceScannerProperty().toLatin1().constData(),
113 dev.toLatin1().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.toLatin1().data());
178 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
179 gst_caps_unref(caps);
184 bool isReadyForCapture() {
185 GstElement *src = videoSource;
186 if (wrapperVideoSource) {
187 src = wrapperVideoSource;
194 gboolean ready = FALSE;
195 g_object_get(src, "ready-for-capture", &ready, NULL);
197 return ready == TRUE;
200 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
201 QtCamDevicePrivate *d) {
209 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
212 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
216 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
217 Q_ARG(bool, d->q_ptr->isIdle()));
225 GstElement *cameraBin;
226 GstElement *videoSource;
227 GstElement *wrapperVideoSource;
229 QtCamImageMode *image;
230 QtCamVideoMode *video;
233 QtCamViewfinder *viewfinder;
235 QtCamGStreamerMessageListener *listener;
237 QtCamNotifications *notifications;
238 QtCamPropertySetter *propertySetter;
239 QtCamAnalysisBin *viewfinderFilters;
242 #endif /* QT_CAM_DEVICE_P_H */