qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CameraDevice Class Reference

#include <cameradevice.h>

Collaboration diagram for CameraDevice:
Collaboration graph

Public Member Functions

void open ()
 Opens the device again. Never fails. More...
 
bool close ()
 Closes the device. Never fails. More...
 

Static Public Member Functions

static CameraDeviceopen (QString devName, VideoMode mode=VideoMode())
 Opens a device. More...
 
static QVector< QPair< QString, QString > > getDeviceList ()
 Get device list with desciption. More...
 
static QVector< VideoModegetVideoModes (QString devName)
 Get the list of video modes for a device. More...
 
static QString getPixelFormatString (uint32_t pixel_format)
 Get the name of the pixel format of a video mode. More...
 
static bool betterPixelFormat (uint32_t a, uint32_t b)
 Compare two pixel formats. More...
 
static QString getDefaultDeviceName ()
 Get the default device name. More...
 
static bool isScreen (const QString &devName)
 Checks if a device name specifies a display. More...
 

Public Attributes

const QString devName
 Short name of the device. More...
 
AVFormatContext * context
 Context of the open device, must always be valid. More...
 

Private Member Functions

 CameraDevice (const QString &devName, AVFormatContext *context)
 

Static Private Member Functions

static CameraDeviceopen (QString devName, AVDictionary **options)
 
static bool getDefaultInputFormat ()
 Sets CameraDevice::iformat to default. More...
 
static QVector< QPair< QString, QString > > getRawDeviceListGeneric ()
 Get raw device list. More...
 
static QVector< VideoModegetScreenModes ()
 Get list of resolutions and position of screens. More...
 

Private Attributes

std::atomic_int refcount
 Number of times the device was opened. More...
 

Static Private Attributes

static QHash< QString, CameraDevice * > openDevices
 
static QMutex openDeviceLock
 
static QMutex iformatLock
 

Detailed Description

Maintains an FFmpeg context for open camera devices, takes care of sharing the context accross users and closing the camera device when not in use. The device can be opened recursively, and must then be closed recursively

Definition at line 35 of file cameradevice.h.

Constructor & Destructor Documentation

◆ CameraDevice()

CameraDevice::CameraDevice ( const QString &  devName,
AVFormatContext *  context 
)
private

Definition at line 80 of file cameradevice.cpp.

Member Function Documentation

◆ betterPixelFormat()

bool CameraDevice::betterPixelFormat ( uint32_t  a,
uint32_t  b 
)
static

Compare two pixel formats.

Parameters
aFirst pixel format to compare.
bSecond pixel format to compare.
Returns
True if we prefer format a to b, false otherwise (such as if there's no preference).

Definition at line 498 of file cameradevice.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

bool CameraDevice::close ( )

Closes the device. Never fails.

Note
If returns true, "this" becomes invalid.
Returns
True, if device finally deleted (closed last reference), false otherwise (if other references exist).

Definition at line 260 of file cameradevice.cpp.

Here is the caller graph for this function:

◆ getDefaultDeviceName()

QString CameraDevice::getDefaultDeviceName ( )
static

Get the default device name.

Returns
The short name of the default device This is either the device in the settings or the system default.

Definition at line 396 of file cameradevice.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDefaultInputFormat()

bool CameraDevice::getDefaultInputFormat ( )
staticprivate

Sets CameraDevice::iformat to default.

Returns
True if success, false if failure.

Definition at line 511 of file cameradevice.cpp.

Here is the caller graph for this function:

◆ getDeviceList()

QVector< QPair< QString, QString > > CameraDevice::getDeviceList ( )
static

Get device list with desciption.

Returns
A list of device names and descriptions. The names are the first part of the pair and can be passed to open(QString).

Definition at line 343 of file cameradevice.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPixelFormatString()

QString CameraDevice::getPixelFormatString ( uint32_t  pixel_format)
static

Get the name of the pixel format of a video mode.

Parameters
pixel_formatPixel format to get the name from.
Returns
Name of the pixel format.

Definition at line 482 of file cameradevice.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRawDeviceListGeneric()

QVector< QPair< QString, QString > > CameraDevice::getRawDeviceListGeneric ( )
staticprivate

Get raw device list.

Note
Uses avdevice_list_devices
Returns
Raw device list

Definition at line 278 of file cameradevice.cpp.

Here is the call graph for this function:

◆ getScreenModes()

QVector< VideoMode > CameraDevice::getScreenModes ( )
staticprivate

Get list of resolutions and position of screens.

Returns
Vector of avaliable screen modes with offset

Definition at line 428 of file cameradevice.cpp.

◆ getVideoModes()

QVector< VideoMode > CameraDevice::getVideoModes ( QString  devName)
static

Get the list of video modes for a device.

Parameters
devNameDevice name to get nodes from.
Returns
Vector of available modes for the device.

Definition at line 451 of file cameradevice.cpp.

Here is the caller graph for this function:

◆ isScreen()

bool CameraDevice::isScreen ( const QString &  devName)
static

Checks if a device name specifies a display.

Parameters
devNameDevice name to check.
Returns
True, if device is screen, false otherwise.

Definition at line 419 of file cameradevice.cpp.

Here is the caller graph for this function:

◆ open() [1/3]

void CameraDevice::open ( )

Opens the device again. Never fails.

Definition at line 249 of file cameradevice.cpp.

Here is the caller graph for this function:

◆ open() [2/3]

CameraDevice * CameraDevice::open ( QString  devName,
AVDictionary **  options 
)
staticprivate

Definition at line 87 of file cameradevice.cpp.

◆ open() [3/3]

CameraDevice * CameraDevice::open ( QString  devName,
VideoMode  mode = VideoMode() 
)
static

Opens a device.

Opens a device, creating a new one if needed If the device is alreay open in another mode, the mode will be ignored and the existing device is used If the mode does not exist, a new device can't be opened.

Parameters
devNameDevice name to open.
modeMode of device to open.
Returns
CameraDevice if the device could be opened, nullptr otherwise.

Definition at line 152 of file cameradevice.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ context

AVFormatContext * CameraDevice::context

Context of the open device, must always be valid.

Definition at line 61 of file cameradevice.h.

◆ devName

const QString CameraDevice::devName

Short name of the device.

Definition at line 60 of file cameradevice.h.

◆ iformatLock

QMutex CameraDevice::iformatLock
staticprivate

Definition at line 66 of file cameradevice.h.

◆ openDeviceLock

QMutex CameraDevice::openDeviceLock
staticprivate

Definition at line 66 of file cameradevice.h.

◆ openDevices

QHash< QString, CameraDevice * > CameraDevice::openDevices
staticprivate

Definition at line 65 of file cameradevice.h.

◆ refcount

std::atomic_int CameraDevice::refcount
private

Number of times the device was opened.

Definition at line 64 of file cameradevice.h.


The documentation for this class was generated from the following files: