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 (!id.isValid() || id.isNull()) {
80 if (conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
82 g_object_set(src, conf->deviceScannerProperty().toAscii().data(), dev, NULL);
85 QString dev = id.toString();
86 g_object_set(src, conf->deviceScannerProperty().toAscii().data(),
87 dev.toAscii().data(), NULL);
91 bool setViewfinderSink() {
93 g_object_get(cameraBin, "viewfinder-sink", &sink, NULL);
96 gst_object_unref(sink);
100 sink = viewfinder->sinkElement();
102 qCritical() << "Failed to create GStreamer sink element";
106 g_object_set(cameraBin, "viewfinder-sink", sink, NULL);
111 void _d_error(const QString& message, int code, const QString& debug) {
114 QMetaObject::invokeMethod(q_ptr, "error", Q_ARG(QString, message),
115 Q_ARG(int, code), Q_ARG(QString, debug));
119 QMetaObject::invokeMethod(q_ptr, "stopped");
124 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
127 QMetaObject::invokeMethod(q_ptr, "stopping", Qt::QueuedConnection);
128 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
134 QMetaObject::invokeMethod(active, "canCaptureChanged", Qt::QueuedConnection);
137 QMetaObject::invokeMethod(q_ptr, "started", Qt::QueuedConnection);
138 QMetaObject::invokeMethod(q_ptr, "runningStateChanged", Qt::QueuedConnection,
142 void setAudioCaptureCaps() {
143 QString captureCaps = conf->audioCaptureCaps();
144 if (!captureCaps.isEmpty()) {
145 GstCaps *caps = gst_caps_from_string(captureCaps.toAscii().data());
147 g_object_set(cameraBin, "audio-capture-caps", caps, NULL);
148 gst_caps_unref(caps);
153 bool isWrapperReady() {
154 if (!wrapperVideoSource) {
158 gboolean ready = FALSE;
159 g_object_get(wrapperVideoSource, "ready-for-capture", &ready, NULL);
161 return ready == TRUE;
164 static void on_ready_for_capture_changed(GObject *obj, GParamSpec *pspec,
165 QtCamDevicePrivate *d) {
173 QMetaObject::invokeMethod(d->active, "canCaptureChanged", Qt::QueuedConnection);
176 static void on_idle_changed(GObject *obj, GParamSpec *pspec, QtCamDevicePrivate *d) {
180 QMetaObject::invokeMethod(d->q_ptr, "idleStateChanged", Qt::QueuedConnection,
181 Q_ARG(bool, d->q_ptr->isIdle()));
185 void resetCapabilities() {
186 g_object_set(cameraBin, "zoom", 1.0, NULL);
187 g_object_set(videoSource, "flash-mode", 0, NULL);
189 // TODO: should scene mode be manual or automatic ?
190 g_object_set(videoSource, "scene-mode", 0, NULL);
199 GstElement *cameraBin;
200 GstElement *videoSource;
201 GstElement *wrapperVideoSource;
203 QtCamImageMode *image;
204 QtCamVideoMode *video;
207 QtCamViewfinder *viewfinder;
209 QtCamGStreamerMessageListener *listener;
213 #endif /* QT_CAM_DEVICE_P_H */