Add QT_GSTREAMER_CAMERABIN_VIDEOSRC environment variable.

It can be used to set which video source element should be used by
the camerabin.

Change-Id: I8d1cd8c4ba6fe5a89817699f645b0997e713aaca
Reviewed-by: Samuli Piippo <samuli.piippo@digia.com>
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
Yoann Lopes
2014-10-17 16:51:23 +02:00
parent f51ca0b97c
commit deb13f102a
3 changed files with 56 additions and 7 deletions

View File

@@ -430,13 +430,15 @@ QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *fa
QStringLiteral("primary"),
QGstreamerVideoInputDeviceControl::primaryCamera(),
0,
QCamera::BackFace
QCamera::BackFace,
QByteArray()
};
const CameraInfo secondary = {
QStringLiteral("secondary"),
QGstreamerVideoInputDeviceControl::secondaryCamera(),
0,
QCamera::FrontFace
QCamera::FrontFace,
QByteArray()
};
devices.append(primary);
@@ -498,14 +500,17 @@ QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *fa
if (isCamera) {
// find out its driver "name"
QByteArray driver;
QString name;
struct v4l2_capability vcap;
memset(&vcap, 0, sizeof(struct v4l2_capability));
if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0)
if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0) {
name = entryInfo.fileName();
else
} else {
driver = QByteArray((const char*)vcap.driver);
name = QString::fromUtf8((const char*)vcap.card);
}
//qDebug() << "found camera: " << name;
@@ -513,7 +518,8 @@ QVector<QGstUtils::CameraInfo> QGstUtils::enumerateCameras(GstElementFactory *fa
entryInfo.absoluteFilePath(),
name,
0,
QCamera::UnspecifiedPosition
QCamera::UnspecifiedPosition,
driver
};
devices.append(device);
}
@@ -561,6 +567,15 @@ int QGstUtils::cameraOrientation(const QString &device, GstElementFactory * fact
return 0;
}
QByteArray QGstUtils::cameraDriver(const QString &device, GstElementFactory *factory)
{
foreach (const CameraInfo &camera, enumerateCameras(factory)) {
if (camera.name == device)
return camera.driver;
}
return QByteArray();
}
void qt_gst_object_ref_sink(gpointer object)
{

View File

@@ -65,6 +65,7 @@ namespace QGstUtils {
QString description;
int orientation;
QCamera::Position position;
QByteArray driver;
};
QMap<QByteArray, QVariant> gstTagListToMap(const GstTagList *list);
@@ -84,6 +85,7 @@ namespace QGstUtils {
QString cameraDescription(const QString &device, GstElementFactory * factory = 0);
QCamera::Position cameraPosition(const QString &device, GstElementFactory * factory = 0);
int cameraOrientation(const QString &device, GstElementFactory * factory = 0);
QByteArray cameraDriver(const QString &device, GstElementFactory * factory = 0);
}
void qt_gst_object_ref_sink(gpointer object);

View File

@@ -412,9 +412,41 @@ GstElement *CameraBinSession::buildCameraSource()
if (g_object_class_find_property(G_OBJECT_GET_CLASS(m_videoSrc), "video-source")) {
GstElement *src = 0;
if (m_videoInputFactory)
/* QT_GSTREAMER_CAMERABIN_VIDEOSRC can be used to set the video source element.
--- Usage
QT_GSTREAMER_CAMERABIN_VIDEOSRC=[drivername=elementname[,drivername2=elementname2 ...],][elementname]
--- Examples
Always use 'somevideosrc':
QT_GSTREAMER_CAMERABIN_VIDEOSRC="somevideosrc"
Use 'somevideosrc' when the device driver is 'somedriver', otherwise use default:
QT_GSTREAMER_CAMERABIN_VIDEOSRC="somedriver=somevideosrc"
Use 'somevideosrc' when the device driver is 'somedriver', otherwise use 'somevideosrc2'
QT_GSTREAMER_CAMERABIN_VIDEOSRC="somedriver=somevideosrc,somevideosrc2"
*/
const QByteArray envVideoSource = qgetenv("QT_GSTREAMER_CAMERABIN_VIDEOSRC");
if (!envVideoSource.isEmpty()) {
QList<QByteArray> sources = envVideoSource.split(',');
foreach (const QByteArray &source, sources) {
QList<QByteArray> keyValue = source.split('=');
if (keyValue.count() == 1) {
src = gst_element_factory_make(keyValue.at(0), "camera_source");
break;
} else if (keyValue.at(0) == QGstUtils::cameraDriver(m_inputDevice, m_sourceFactory)) {
src = gst_element_factory_make(keyValue.at(1), "camera_source");
break;
}
}
} else if (m_videoInputFactory) {
src = m_videoInputFactory->buildElement();
else
}
if (!src)
src = gst_element_factory_make("v4l2src", "camera_source");
if (src) {