1 /* Webcamoid, webcam capture application.
2  * Copyright (C) 2016  Gonzalo Exequiel Pedone
3  *
4  * Webcamoid is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Webcamoid is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Web-Site: http://webcamoid.github.io/
18  */
19 
20 #ifndef CAPTURELIBUVC_H
21 #define CAPTURELIBUVC_H
22 
23 #include "capture.h"
24 
25 /* libuvc requires RW permissions for opening capturing devices, so you must
26  * create the following .rules file:
27  *
28  * /etc/udev/rules.d/99-uvc.rules
29  *
30  * Then, for each webcam add the following line:
31  *
32  * SUBSYSTEMS=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", MODE="0666"
33  *
34  * Replace XXXX and YYYY for the 4 hexadecimal characters corresponding to the
35  * vendor and product ID of your webcams. Read more at:
36  *
37  * http://wiki.ros.org/libuvc_camera#Usage
38  */
39 
40 class CaptureLibUVCPrivate;
41 
42 class CaptureLibUVC: public Capture
43 {
44     Q_OBJECT
45 
46     public:
47         enum IoMethod
48         {
49             IoMethodUnknown = -1,
50             IoMethodReadWrite,
51             IoMethodMemoryMap,
52             IoMethodUserPointer
53         };
54 
55         CaptureLibUVC(QObject *parent=nullptr);
56         ~CaptureLibUVC();
57 
58         Q_INVOKABLE QStringList webcams() const;
59         Q_INVOKABLE QString device() const;
60         Q_INVOKABLE QList<int> streams();
61         Q_INVOKABLE QList<int> listTracks(const QString &mimeType);
62         Q_INVOKABLE QString ioMethod() const;
63         Q_INVOKABLE int nBuffers() const;
64         Q_INVOKABLE QString description(const QString &webcam) const;
65         Q_INVOKABLE QVariantList caps(const QString &webcam) const;
66         Q_INVOKABLE QString capsDescription(const AkCaps &caps) const;
67         Q_INVOKABLE QVariantList imageControls() const;
68         Q_INVOKABLE bool setImageControls(const QVariantMap &imageControls);
69         Q_INVOKABLE bool resetImageControls();
70         Q_INVOKABLE QVariantList cameraControls() const;
71         Q_INVOKABLE bool setCameraControls(const QVariantMap &cameraControls);
72         Q_INVOKABLE bool resetCameraControls();
73         Q_INVOKABLE AkPacket readFrame();
74         Q_INVOKABLE QString uvcId(quint16 vendorId, quint16 productId) const;
75 
76     private:
77         CaptureLibUVCPrivate *d;
78 
79     public slots:
80         bool init();
81         void uninit();
82         void setDevice(const QString &device);
83         void setStreams(const QList<int> &streams);
84         void setIoMethod(const QString &ioMethod);
85         void setNBuffers(int nBuffers);
86         void resetDevice();
87         void resetStreams();
88         void resetIoMethod();
89         void resetNBuffers();
90         void reset();
91 };
92 
93 #endif // CAPTURELIBUVC_H
94