summaryrefslogtreecommitdiffstats
path: root/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp')
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp116
1 files changed, 48 insertions, 68 deletions
diff --git a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
index 3decd6070..bfb0c4935 100644
--- a/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinserviceplugin.cpp
@@ -55,12 +55,25 @@
QT_BEGIN_NAMESPACE
+template <typename T, int N> static int lengthOf(const T(&)[N]) { return N; }
+
+CameraBinServicePlugin::CameraBinServicePlugin()
+ : m_sourceFactory(0)
+{
+}
+
+CameraBinServicePlugin::~CameraBinServicePlugin()
+{
+ if (m_sourceFactory)
+ gst_object_unref(GST_OBJECT(m_sourceFactory));
+}
+
QMediaService* CameraBinServicePlugin::create(const QString &key)
{
QGstUtils::initializeGst();
if (key == QLatin1String(Q_MEDIASERVICE_CAMERA))
- return new CameraBinService(key);
+ return new CameraBinService(sourceFactory());
qWarning() << "Gstreamer camerabin service plugin: unsupported key:" << key;
return 0;
@@ -82,40 +95,24 @@ QMediaServiceProviderHint::Features CameraBinServicePlugin::supportedFeatures(
QByteArray CameraBinServicePlugin::defaultDevice(const QByteArray &service) const
{
- if (service == Q_MEDIASERVICE_CAMERA) {
- if (m_cameraDevices.isEmpty())
- updateDevices();
-
- return m_defaultCameraDevice;
- }
-
- return QByteArray();
+ return service == Q_MEDIASERVICE_CAMERA
+ ? QGstUtils::enumerateCameras(sourceFactory()).value(0).name.toUtf8()
+ : QByteArray();
}
QList<QByteArray> CameraBinServicePlugin::devices(const QByteArray &service) const
{
- if (service == Q_MEDIASERVICE_CAMERA) {
- if (m_cameraDevices.isEmpty())
- updateDevices();
- return m_cameraDevices;
- }
-
- return QList<QByteArray>();
+ return service == Q_MEDIASERVICE_CAMERA
+ ? QGstUtils::cameraDevices(m_sourceFactory)
+ : QList<QByteArray>();
}
-QString CameraBinServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
+QString CameraBinServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &deviceName)
{
- if (service == Q_MEDIASERVICE_CAMERA) {
- if (m_cameraDevices.isEmpty())
- updateDevices();
-
- for (int i=0; i<m_cameraDevices.count(); i++)
- if (m_cameraDevices[i] == device)
- return m_cameraDescriptions[i];
- }
-
- return QString();
+ return service == Q_MEDIASERVICE_CAMERA
+ ? QGstUtils::cameraDescription(deviceName, m_sourceFactory)
+ : QString();
}
QVariant CameraBinServicePlugin::deviceProperty(const QByteArray &service, const QByteArray &device, const QByteArray &property)
@@ -126,53 +123,36 @@ QVariant CameraBinServicePlugin::deviceProperty(const QByteArray &service, const
return QVariant();
}
-void CameraBinServicePlugin::updateDevices() const
+QCamera::Position CameraBinServicePlugin::cameraPosition(const QByteArray &deviceName) const
{
- m_defaultCameraDevice.clear();
- m_cameraDevices.clear();
- m_cameraDescriptions.clear();
-
- QDir devDir("/dev");
- devDir.setFilter(QDir::System);
-
- QFileInfoList entries = devDir.entryInfoList(QStringList() << "video*");
-
- foreach (const QFileInfo &entryInfo, entries) {
- int fd = qt_safe_open(entryInfo.filePath().toLatin1().constData(), O_RDWR );
- if (fd == -1)
- continue;
-
- bool isCamera = false;
-
- v4l2_input input;
- memset(&input, 0, sizeof(input));
- for (; ::ioctl(fd, VIDIOC_ENUMINPUT, &input) >= 0; ++input.index) {
- if (input.type == V4L2_INPUT_TYPE_CAMERA || input.type == 0) {
- isCamera = ::ioctl(fd, VIDIOC_S_INPUT, input.index) != 0;
- break;
- }
- }
-
- if (isCamera) {
- // find out its driver "name"
- QString name;
- struct v4l2_capability vcap;
- memset(&vcap, 0, sizeof(struct v4l2_capability));
+ return QGstUtils::cameraPosition(deviceName, m_sourceFactory);
+}
- if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) != 0)
- name = entryInfo.fileName();
- else
- name = QString((const char*)vcap.card);
- //qDebug() << "found camera: " << name;
+int CameraBinServicePlugin::cameraOrientation(const QByteArray &deviceName) const
+{
+ return QGstUtils::cameraOrientation(deviceName, m_sourceFactory);
+}
- m_cameraDevices.append(entryInfo.filePath().toLocal8Bit());
- m_cameraDescriptions.append(name);
+GstElementFactory *CameraBinServicePlugin::sourceFactory() const
+{
+ if (!m_sourceFactory) {
+ GstElementFactory *factory = 0;
+ const QByteArray envCandidate = qgetenv("QT_GSTREAMER_CAMERABIN_SRC");
+ if (!envCandidate.isEmpty())
+ factory = gst_element_factory_find(envCandidate.constData());
+
+ static const char *candidates[] = { "subdevsrc", "wrappercamerabinsrc" };
+ for (int i = 0; !factory && i < lengthOf(candidates); ++i)
+ factory = gst_element_factory_find(candidates[i]);
+
+ if (factory) {
+ m_sourceFactory = GST_ELEMENT_FACTORY(gst_plugin_feature_load(
+ GST_PLUGIN_FEATURE(factory)));
+ gst_object_unref((GST_OBJECT(factory)));
}
- qt_safe_close(fd);
}
- if (!m_cameraDevices.isEmpty())
- m_defaultCameraDevice = m_cameraDevices.first();
+ return m_sourceFactory;
}
QT_END_NAMESPACE