3 #ifndef QT_CAM_DEVICE_P_H
4 #define QT_CAM_DEVICE_P_H
8 #include "qtcamconfig.h"
9 #include "qtcamviewfinder.h"
10 #include "qtcamdevice.h"
11 #include "qtcammode.h"
13 class QtCamGStreamerMessageListener;
18 class QtCamDevicePrivate {
20 QtCamDevicePrivate() :
23 wrapperVideoSource(0),
33 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
34 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
36 qWarning() << "Failed to create" << elementName;
40 g_object_set(cameraBin, prop, elem, NULL);
45 void createAndAddVideoSource() {
46 // TODO: rework this function
47 GstElement *src, *wrapper;
48 QString wrapperSrc = conf->wrapperVideoSource();
49 QString prop = conf->wrapperVideoSourceProperty();
51 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
52 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
54 qCritical() << "Failed to create wrapper source" << wrapperSrc;
59 src = gst_element_factory_make(conf->videoSource().toAscii(),
62 qCritical() << "Failed to create video source";
64 gst_object_unref(wrapper);
70 g_object_set(wrapper, prop.toAscii(), src, NULL);
71 g_object_set(cameraBin, "camera-source", wrapper, NULL);
75 wrapperVideoSource = wrapper;
77 if (!id.isValid() || id.isNull()) {
81 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
83 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
86 QString dev = id.toString();
87 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
88 dev.toAscii().data(), NULL);
92 bool setViewfinderSink() {
94 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
97 gst_object_unref(sink);
101 sink = viewfinder->sinkElement();
103 qCritical() << "Failed to create GStreamer sink element";
107 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
112 void _d_error(const QString& message, int code, const QString& debug) {
115 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
116 Q_ARG(int, code), Q_ARG(QString, debug));
119 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
124 QMetaObject::invokeMethod(q_ptr, "stopped");
129 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
132 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
133 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
139 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
142 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
143 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
147 void setAudioCaptureCaps() {
148 QString captureCaps = conf->audioCaptureCaps();
149 if (!captureCaps.isEmpty()) {
150 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
152 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
153 gst_caps_unref(caps);
158 bool isWrapperReady() {
159 if (!wrapperVideoSource) {
163 gboolean ready = FALSE;
164 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
166 return ready == TRUE;
169 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
170 QtCamDevicePrivate *d) {
178 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
181 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
185 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
186 Q_ARG(bool, d->q_ptr->isIdle()));
190 void resetCapabilities() {
191 g_object_set(cameraBin, "zoom", 1.0, NULL);
192 g_object_set(videoSource, "flash-mode", 0, NULL);
194 // TODO: should scene mode be manual or automatic ?
195 g_object_set(videoSource, "scene-mode", 0, NULL);
204 GstElement *cameraBin;
205 GstElement *videoSource;
206 GstElement *wrapperVideoSource;
208 QtCamImageMode *image;
209 QtCamVideoMode *video;
212 QtCamViewfinder *viewfinder;
214 QtCamGStreamerMessageListener *listener;
218 #endif /* QT_CAM_DEVICE_P_H */