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 GstElement *src, *wrapper;
47 QString wrapperSrc = conf->wrapperVideoSource();
48 QString prop = conf->wrapperVideoSourceProperty();
50 if (!prop.isEmpty() && !wrapperSrc.isEmpty()) {
51 wrapper = gst_element_factory_make(wrapperSrc.toAscii(), "QCameraWrapperVideoSrc");
53 qCritical() << "Failed to create wrapper source" << wrapperSrc;
58 src = gst_element_factory_make(conf->videoSource().toAscii(),
61 qCritical() << "Failed to create video source";
63 gst_object_unref(wrapper);
69 g_object_set(wrapper, prop.toAscii(), src, NULL);
70 g_object_set(cameraBin, "camera-source", wrapper, NULL);
74 wrapperVideoSource = wrapper;
76 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
78 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
81 QString dev = id.toString();
82 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
83 dev.toAscii().data(), NULL);
87 bool setViewfinderSink() {
89 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
92 gst_object_unref(sink);
96 sink = viewfinder->sinkElement();
98 qCritical() << "Failed to create GStreamer sink element";
102 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
107 void _d_error(const QString& message, int code, const QString& debug) {
110 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
111 Q_ARG(int, code), Q_ARG(QString, debug));
115 QMetaObject::invokeMethod(q_ptr, "stopped");
120 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
123 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
124 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
130 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
133 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
134 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
138 void setAudioCaptureCaps() {
139 QString captureCaps = conf->audioCaptureCaps();
140 if (!captureCaps.isEmpty()) {
141 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
143 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
144 gst_caps_unref(caps);
149 bool isWrapperReady() {
150 if (!wrapperVideoSource) {
154 gboolean ready = FALSE;
155 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
157 return ready == TRUE;
160 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
161 QtCamDevicePrivate *d) {
169 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
172 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
176 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
177 Q_ARG(bool, d->q_ptr->isIdle()));
185 GstElement *cameraBin;
186 GstElement *videoSource;
187 GstElement *wrapperVideoSource;
189 QtCamImageMode *image;
190 QtCamVideoMode *video;
193 QtCamViewfinder *viewfinder;
195 QtCamGStreamerMessageListener *listener;
199 #endif /* QT_CAM_DEVICE_P_H */