qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
cameradevice.h
Go to the documentation of this file.
1 /*
2  Copyright © 2015-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox 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
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 #pragma once
22 
23 #include "videomode.h"
24 #include <QHash>
25 #include <QMutex>
26 #include <QString>
27 #include <QVector>
28 #include <atomic>
29 
30 struct AVFormatContext;
31 struct AVInputFormat;
32 struct AVDeviceInfoList;
33 struct AVDictionary;
34 
36 {
37 public:
38  static CameraDevice* open(QString devName, VideoMode mode = VideoMode());
39  void open();
40  bool close();
41 
42  static QVector<QPair<QString, QString>> getDeviceList();
43 
44  static QVector<VideoMode> getVideoModes(QString devName);
45  static QString getPixelFormatString(uint32_t pixel_format);
46  static bool betterPixelFormat(uint32_t a, uint32_t b);
47 
48  static QString getDefaultDeviceName();
49 
50  static bool isScreen(const QString& devName);
51 
52 private:
53  CameraDevice(const QString& devName, AVFormatContext* context);
54  static CameraDevice* open(QString devName, AVDictionary** options);
55  static bool getDefaultInputFormat();
56  static QVector<QPair<QString, QString>> getRawDeviceListGeneric();
57  static QVector<VideoMode> getScreenModes();
58 
59 public:
60  const QString devName;
61  AVFormatContext* context;
62 
63 private:
64  std::atomic_int refcount;
66  static QMutex openDeviceLock, iformatLock;
67 };
CameraDevice::open
void open()
Opens the device again. Never fails.
Definition: cameradevice.cpp:249
videomode.h
CameraDevice::getDeviceList
static QVector< QPair< QString, QString > > getDeviceList()
Get device list with desciption.
Definition: cameradevice.cpp:343
CameraDevice::refcount
std::atomic_int refcount
Number of times the device was opened.
Definition: cameradevice.h:64
CameraDevice::getRawDeviceListGeneric
static QVector< QPair< QString, QString > > getRawDeviceListGeneric()
Get raw device list.
Definition: cameradevice.cpp:278
CameraDevice::getScreenModes
static QVector< VideoMode > getScreenModes()
Get list of resolutions and position of screens.
Definition: cameradevice.cpp:428
CameraDevice::getVideoModes
static QVector< VideoMode > getVideoModes(QString devName)
Get the list of video modes for a device.
Definition: cameradevice.cpp:451
CameraDevice::betterPixelFormat
static bool betterPixelFormat(uint32_t a, uint32_t b)
Compare two pixel formats.
Definition: cameradevice.cpp:498
CameraDevice::getDefaultInputFormat
static bool getDefaultInputFormat()
Sets CameraDevice::iformat to default.
Definition: cameradevice.cpp:511
QHash< QString, CameraDevice * >
CameraDevice::context
AVFormatContext * context
Context of the open device, must always be valid.
Definition: cameradevice.h:61
CameraDevice::iformatLock
static QMutex iformatLock
Definition: cameradevice.h:66
CameraDevice::openDeviceLock
static QMutex openDeviceLock
Definition: cameradevice.h:66
VideoMode
Describes a video mode supported by a device.
Definition: videomode.h:25
CameraDevice::close
bool close()
Closes the device. Never fails.
Definition: cameradevice.cpp:260
CameraDevice::devName
const QString devName
Short name of the device.
Definition: cameradevice.h:60
CameraDevice
Definition: cameradevice.h:35
CameraDevice::getPixelFormatString
static QString getPixelFormatString(uint32_t pixel_format)
Get the name of the pixel format of a video mode.
Definition: cameradevice.cpp:482
CameraDevice::CameraDevice
CameraDevice(const QString &devName, AVFormatContext *context)
Definition: cameradevice.cpp:80
CameraDevice::isScreen
static bool isScreen(const QString &devName)
Checks if a device name specifies a display.
Definition: cameradevice.cpp:419
CameraDevice::getDefaultDeviceName
static QString getDefaultDeviceName()
Get the default device name.
Definition: cameradevice.cpp:396
CameraDevice::openDevices
static QHash< QString, CameraDevice * > openDevices
Definition: cameradevice.h:65