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"
32 #include "qtcamanalysisbin.h"
34 class QtCamGStreamerMessageListener;
38 class QtCamPropertySetter;
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 createAndAddVideoSource() {
69 // TODO: rework this function
70 GstElement *src, *wrapper;
71 QString wrapperSrc = conf->wrapperVideoSource();
72 QString prop = conf->wrapperVideoSourceProperty();
74 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
75 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
77 qCritical() << "Failed to create wrapper source" << wrapperSrc;
82 src = gst_element_factory_make(conf->videoSource().toAscii(),
85 qCritical() << "Failed to create video source";
87 gst_object_unref(wrapper);
93 g_object_set(wrapper, prop.toAscii(), src, NULL);
94 g_object_set(cameraBin, "camera-source", wrapper, NULL);
98 wrapperVideoSource = wrapper;
100 if (!id.isValid() || id.isNull()) {
104 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
105 int dev = id.toInt();
106 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
109 QString dev = id.toString();
110 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
111 dev.toAscii().data(), NULL);
115 bool setViewfinderSink() {
117 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
120 gst_object_unref(sink);
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.toAscii().data());
175 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
176 gst_caps_unref(caps);
181 void addViewfinderFilters() {
182 addElements("viewfinder-filter", conf->viewfinderFilters());
185 bool isWrapperReady() {
186 if (!wrapperVideoSource) {
190 gboolean ready = FALSE;
191 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
193 return ready == TRUE;
196 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
197 QtCamDevicePrivate *d) {
205 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
208 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
212 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
213 Q_ARG(bool, d->q_ptr->isIdle()));
216 void addElements(const char *prop, const QStringList& elements) {
217 QList<GstElement *> list;
219 if (elements.isEmpty()) {
223 foreach (const QString& element, elements) {
224 GstElement *elem = gst_element_factory_make(element.toUtf8().constData(), NULL);
226 qWarning() << "Failed to create element" << element;
233 if (list.isEmpty()) {
237 GstElement *bin = qt_cam_analysis_bin_create(list, prop);
239 qWarning() << "Failed to create bin for" << prop;
243 g_object_set(cameraBin, prop, bin, NULL);
247 void resetCapabilities() {
248 g_object_set(cameraBin, "zoom", 1.0, NULL);
249 g_object_set(videoSource, "flash-mode", 0, NULL);
251 // TODO: should scene mode be manual or automatic ?
252 g_object_set(videoSource, "scene-mode", 0, NULL);
261 GstElement *cameraBin;
262 GstElement *videoSource;
263 GstElement *wrapperVideoSource;
265 QtCamImageMode *image;
266 QtCamVideoMode *video;
269 QtCamViewfinder *viewfinder;
271 QtCamGStreamerMessageListener *listener;
273 QtCamNotifications *notifications;
274 QtCamPropertySetter *propertySetter;
277 #endif /* QT_CAM_DEVICE_P_H */