2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "qtcamscanner.h"
22 #include "qtcamconfig.h"
24 #include <sys/types.h>
27 #include <linux/videodev2.h>
28 #include <sys/ioctl.h>
32 class QtCamScannerPrivate {
38 QList<QPair<QString, QVariant> > devices;
41 void QtCamScannerPrivate::scanEnum() {
42 // Too bad there's no way to get the values of an enum without creating the element :(
43 GstElement *elem = gst_element_factory_make(conf->videoSource().toAscii(), NULL);
48 GParamSpec *spec = g_object_class_find_property(G_OBJECT_GET_CLASS(elem),
49 conf->deviceScannerProperty().toAscii());
51 gst_object_unref(elem);
55 if (!G_IS_PARAM_SPEC_ENUM(spec)) {
56 gst_object_unref(elem);
60 GParamSpecEnum *e = G_PARAM_SPEC_ENUM(spec);
61 // First add the default:
62 devices << qMakePair<QString, QVariant>(e->enum_class->values[e->default_value].value_name,
63 QByteArray::number(e->default_value));
65 for (int x = e->enum_class->minimum; x <= e->enum_class->maximum; x++) {
66 if (x != e->default_value) {
67 devices << qMakePair<QString, QVariant>(e->enum_class->values[x].value_name,
68 QByteArray::number(x));
72 gst_object_unref(elem);
75 void QtCamScannerPrivate::scanV4l2() {
76 QDir d("/dev/", "video?", QDir::Name | QDir::IgnoreCase, QDir::System);
78 QStringList entries = d.entryList();
80 foreach (const QString& dv, entries) {
81 QString dev = d.absoluteFilePath(dv);
82 struct v4l2_capability cap;
83 memset(&cap, 0x0, sizeof(cap));
85 int fd = open(dev.toLocal8Bit().data(), O_RDONLY);
90 if (ioctl(fd, VIDIOC_QUERYCAP, &cap) != 0) {
97 if (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
98 devices << qMakePair<QString, QVariant>((char *)cap.card, dev.toLocal8Bit());
103 QtCamScanner::QtCamScanner(QtCamConfig *conf, QObject *parent) :
104 QObject(parent), d_ptr(new QtCamScannerPrivate) {
109 QtCamScanner::~QtCamScanner() {
110 delete d_ptr; d_ptr = 0;
113 void QtCamScanner::refresh() {
114 d_ptr->devices.clear();
116 if (d_ptr->conf->deviceScannerType() == SCANNER_TYPE_ENUM) {
124 QList<QPair<QString, QVariant> > QtCamScanner::devices() const {
125 return d_ptr->devices;