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"
12 class QtCamGStreamerMessageListener;
17 class QtCamDevicePrivate {
19 QtCamDevicePrivate() :
22 wrapperVideoSource(0),
32 GstElement *createAndAddElement(const QString& elementName, const char *prop, const char *name) {
33 GstElement *elem = gst_element_factory_make(elementName.toAscii(), name);
35 qWarning() << "Failed to create" << elementName;
39 g_object_set(cameraBin, prop, elem, NULL);
44 void createAndAddVideoSource() {
45 GstElement *src, *wrapper;
46 QString wrapperSrc = conf->wrapperVideoSource();
47 QString prop = conf->wrapperVideoSourceProperty();
49 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
50 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
52 qCritical() << "Failed to create wrapper source" << wrapperSrc;
57 src = gst_element_factory_make(conf->videoSource().toAscii(),
60 qCritical() << "Failed to create video source";
62 gst_object_unref(wrapper);
68 g_object_set(wrapper, prop.toAscii(), src, NULL);
69 g_object_set(cameraBin, "camera-source", wrapper, NULL);
73 wrapperVideoSource = wrapper;
75 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
77 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
80 QString dev = id.toString();
81 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
82 dev.toAscii().data(), NULL);
86 bool setViewfinderSink() {
88 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
91 gst_object_unref(sink);
95 sink = viewfinder->sinkElement();
97 qCritical() << "Failed to create GStreamer sink element";
101 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
106 void _d_error(const QString& message, int code, const QString& debug) {
109 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
110 Q_ARG(int, code), Q_ARG(QString, debug));
114 QMetaObject::invokeMethod(q_ptr, "stopped");
119 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
122 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
123 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
129 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
132 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
133 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
137 void setAudioCaptureCaps() {
138 QString captureCaps = conf->audioCaptureCaps();
139 if (!captureCaps.isEmpty()) {
140 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
142 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
143 gst_caps_unref(caps);
148 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
152 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
153 Q_ARG(bool, d->q_ptr->isIdle()));
161 GstElement *cameraBin;
162 GstElement *videoSource;
163 GstElement *wrapperVideoSource;
165 QtCamImageMode *image;
166 QtCamVideoMode *video;
169 QtCamViewfinder *viewfinder;
171 QtCamGStreamerMessageListener *listener;
175 #endif /* QT_CAM_DEVICE_P_H */