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),
56 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
57 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
59 qWarning() << "Failed to create" << elementName;
63 g_object_set(cameraBin, prop, elem, NULL);
68 void createAndAddVideoSourceAndWrapper() {
69 videoSource = gst_element_factory_make(conf->videoSource().toUtf8().constData(),
71 wrapperVideoSource = gst_element_factory_make(conf->wrapperVideoSource().toUtf8().constData(),
72 "QCameraWrapperVideoSrc");
74 if (wrapperVideoSource && videoSource) {
75 g_object_set(wrapperVideoSource, conf->wrapperVideoSourceProperty().toUtf8().constData(),
77 g_object_set(cameraBin, "camera-source", wrapperVideoSource, NULL);
79 else if (wrapperVideoSource) {
80 qWarning() << "Failed to create video source";
81 g_object_set(cameraBin, "camera-source", wrapperVideoSource, NULL);
83 else if (videoSource) {
84 qWarning() << "Failed to create wrapper source";
85 g_object_set(cameraBin, "camera-source", videoSource, NULL);
88 qWarning() << "Failed to create both video and wrapper sources";
92 void createAndAddVideoSource() {
93 videoSource = gst_element_factory_make(conf->videoSource().toUtf8().constData(),
96 qCritical() << "Failed to create video source";
99 g_object_set(cameraBin, "camera-source", videoSource, NULL);
103 bool setViewfinderSink() {
105 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
108 gst_object_unref(sink);
112 sink = viewfinder->sinkElement();
114 qCritical() << "Failed to create GStreamer sink element";
118 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
123 void _d_error(const QString& message, int code, const QString& debug) {
126 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
127 Q_ARG(int, code), Q_ARG(QString, debug));
130 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
135 QMetaObject::invokeMethod(q_ptr, "stopped");
140 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
143 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
144 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
150 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
153 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
154 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
158 void setAudioCaptureCaps() {
159 QString captureCaps = conf->audioCaptureCaps();
160 if (!captureCaps.isEmpty()) {
161 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
163 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
164 gst_caps_unref(caps);
169 bool isWrapperReady() {
170 if (!wrapperVideoSource) {
174 gboolean ready = FALSE;
175 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
177 return ready == TRUE;
180 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
181 QtCamDevicePrivate *d) {
189 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
192 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
196 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
197 Q_ARG(bool, d->q_ptr->isIdle()));
205 GstElement *cameraBin;
206 GstElement *videoSource;
207 GstElement *wrapperVideoSource;
209 QtCamImageMode *image;
210 QtCamVideoMode *video;
213 QtCamViewfinder *viewfinder;
215 QtCamGStreamerMessageListener *listener;
217 QtCamNotifications *notifications;
218 QtCamPropertySetter *propertySetter;
219 QtCamAnalysisBin *viewfinderFilters;
222 #endif /* QT_CAM_DEVICE_P_H */