#include <linux/videodev2.h>
QGstreamerVideoInputDeviceControl::QGstreamerVideoInputDeviceControl(QObject *parent)
- :QVideoDeviceSelectorControl(parent), m_selectedDevice(0)
+ :QVideoDeviceSelectorControl(parent), m_source(0), m_selectedDevice(0)
{
update();
}
+QGstreamerVideoInputDeviceControl::QGstreamerVideoInputDeviceControl(GstElement *source, QObject *parent)
+ :QVideoDeviceSelectorControl(parent), m_source(source), m_selectedDevice(0)
+{
+ if (m_source)
+ gst_object_ref(GST_OBJECT(m_source));
+
+ update();
+}
+
QGstreamerVideoInputDeviceControl::~QGstreamerVideoInputDeviceControl()
{
+ if (m_source)
+ gst_object_unref(GST_OBJECT(m_source));
}
int QGstreamerVideoInputDeviceControl::deviceCount() const
m_names.clear();
m_descriptions.clear();
-#ifdef Q_WS_MAEMO_6
- m_names << QLatin1String("primary") << QLatin1String("secondary");
- m_descriptions << tr("Main camera") << tr("Front camera");
-#else
+ // subdevsrc and the like have a camera-device property that takes an enumeration
+ // identifying a primary or secondary camera, so return identifiers that map to those
+ // instead of a list of actual devices.
+ if (m_source && g_object_class_find_property(G_OBJECT_GET_CLASS(m_source), "camera-device")) {
+ m_names << QLatin1String("primary") << QLatin1String("secondary");
+ m_descriptions << tr("Main camera") << tr("Front camera");
+ return;
+ }
+
QDir devDir("/dev");
devDir.setFilter(QDir::System);
}
::close(fd);
}
-#endif
}
m_captureDestinationControl = new CameraBinCaptureDestination(this);
m_captureBufferFormatControl = new CameraBinCaptureBufferFormat(this);
+ QByteArray envFlags = qgetenv("QT_GSTREAMER_CAMERABIN_FLAGS");
+ if (!envFlags.isEmpty())
+ g_object_set(G_OBJECT(m_camerabin), "flags", envFlags.toInt(), NULL);
+
//post image preview in RGB format
g_object_set(G_OBJECT(m_camerabin), POST_PREVIEWS_PROPERTY, TRUE, NULL);
return GST_PHOTOGRAPHY(m_camerabin);
}
- if (!m_videoSrc) {
- m_videoSrc = buildCameraSource();
-
- if (m_videoSrc)
- g_object_set(m_camerabin, CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL);
- else
- g_object_get(m_camerabin, CAMERA_SOURCE_PROPERTY, &m_videoSrc, NULL);
-
- m_videoInputHasChanged = false;
- }
+ GstElement * const source = buildCameraSource();
- if (m_videoSrc && GST_IS_PHOTOGRAPHY(m_videoSrc))
- return GST_PHOTOGRAPHY(m_videoSrc);
+ if (source && GST_IS_PHOTOGRAPHY(source))
+ return GST_PHOTOGRAPHY(source);
return 0;
}
*/
bool CameraBinSession::setupCameraBin()
{
- if (m_videoInputHasChanged) {
- m_videoSrc = buildCameraSource();
-
- if (m_videoSrc)
- g_object_set(m_camerabin, CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL);
- else
- g_object_get(m_camerabin, CAMERA_SOURCE_PROPERTY, &m_videoSrc, NULL);
-
- m_videoInputHasChanged = false;
- }
-
+ if (!buildCameraSource())
+ return false;
if (m_viewfinderHasChanged) {
if (m_viewfinderElement)
#if CAMERABIN_DEBUG
qDebug() << Q_FUNC_INFO;
#endif
+ if (!m_videoInputHasChanged)
+ return m_videoSrc;
+ m_videoInputHasChanged = false;
+
GstElement *videoSrc = 0;
+ g_object_get(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, &videoSrc, NULL);
- QList<QByteArray> candidates;
- candidates << "subdevsrc" << "wrappercamerabinsrc";
- QByteArray sourceElementName;
+ // If the QT_GSTREAMER_CAMERABIN_SRC environment variable has been set use the source
+ // it recommends.
+ const QByteArray envCandidate = qgetenv("QT_GSTREAMER_CAMERABIN_SRC");
+ if (!m_videoSrc && !envCandidate.isEmpty()) {
+ m_videoSrc = gst_element_factory_make(envCandidate.constData(), "camera_source");
+ }
+
+ // If gstreamer has set a default source use it.
+ if (!m_videoSrc)
+ m_videoSrc = videoSrc;
- foreach (sourceElementName, candidates) {
- videoSrc = gst_element_factory_make(sourceElementName.constData(), "camera_source");
- if (videoSrc)
- break;
+ // If there's no better guidance try the names of some known camera source elements.
+ if (!m_videoSrc) {
+ const QList<QByteArray> candidates = QList<QByteArray>()
+ << "subdevsrc"
+ << "wrappercamerabinsrc";
+
+ foreach (const QByteArray &sourceElementName, candidates) {
+ m_videoSrc = gst_element_factory_make(sourceElementName.constData(), "camera_source");
+ if (m_videoSrc)
+ break;
+ }
}
- if (videoSrc && !m_inputDevice.isEmpty()) {
+ if (m_videoSrc && !m_inputDevice.isEmpty()) {
#if CAMERABIN_DEBUG
qDebug() << "set camera device" << m_inputDevice;
#endif
- if (sourceElementName == "subdevsrc") {
- if (m_inputDevice == QLatin1String("secondary"))
- g_object_set(G_OBJECT(videoSrc), "camera-device", 1, NULL);
- else
- g_object_set(G_OBJECT(videoSrc), "camera-device", 0, NULL);
- } else if (sourceElementName == "wrappercamerabinsrc") {
+
+ if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSrc), "video-source")) {
GstElement *src = 0;
if (m_videoInputFactory)
if (src) {
g_object_set(G_OBJECT(src), "device", m_inputDevice.toUtf8().constData(), NULL);
- g_object_set(G_OBJECT(videoSrc), "video-source", src, NULL);
+ g_object_set(G_OBJECT(m_videoSrc), "video-source", src, NULL);
+ }
+ } else if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSrc), "camera-device")) {
+ if (m_inputDevice == QLatin1String("secondary")) {
+ g_object_set(G_OBJECT(m_videoSrc), "camera-device", 1, NULL);
+ } else {
+ g_object_set(G_OBJECT(m_videoSrc), "camera-device", 0, NULL);
}
}
}
- return videoSrc;
+ if (m_videoSrc != videoSrc)
+ g_object_set(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL);
+
+ return m_videoSrc;
}
void CameraBinSession::captureImage(int requestId, const QString &fileName)
m_viewfinderInterface->stopRenderer();
gst_element_set_state(m_camerabin, GST_STATE_NULL);
- m_videoSrc = buildCameraSource();
- g_object_set(m_camerabin, CAMERA_SOURCE_PROPERTY, m_videoSrc, NULL);
- m_videoInputHasChanged = false;
+ buildCameraSource();
}
#ifdef USE_READY_STATE_ON_LOADED
gst_element_set_state(m_camerabin, GST_STATE_READY);