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

This class is a wrapper to share a camera's captured video frames. More...

#include <camerasource.h>

Inheritance diagram for CameraSource:
Inheritance graph
Collaboration diagram for CameraSource:
Collaboration graph

Public Slots

void setupDevice (const QString &deviceName, const VideoMode &mode)
 Change the device and mode. More...
 

Signals

void deviceOpened ()
 
void openFailed ()
 
- Signals inherited from VideoSource
void frameAvailable (std::shared_ptr< VideoFrame > frame)
 Emitted when new frame available to use. More...
 
void sourceStopped ()
 Emitted when the source is stopped for an indefinite amount of time, but might restart sending frames again later. More...
 

Public Member Functions

void setupDefault ()
 Setup default device. More...
 
bool isNone () const
 
void subscribe () override
 If subscribe sucessfully opens the source, it will start emitting frameAvailable signals. More...
 
void unsubscribe () override
 Stop emitting frameAvailable signals, and free associated resources if necessary. More...
 
- Public Member Functions inherited from VideoSource
 VideoSource ()
 
virtual ~VideoSource ()=default
 

Static Public Member Functions

static CameraSourcegetInstance ()
 Returns the singleton instance. More...
 
static void destroyInstance ()
 

Private Slots

void openDevice ()
 Opens the video device and starts streaming. More...
 
void closeDevice ()
 Closes the video device and stops streaming. More...
 

Private Member Functions

 CameraSource ()
 
 ~CameraSource ()
 
void stream ()
 Blocking. Decodes video stream and emits new frames. More...
 

Private Attributes

QFuture< void > streamFuture
 Future of the streaming thread. More...
 
QThread * deviceThread
 
QString deviceName
 Short name of the device for CameraDevice's open(QString) More...
 
CameraDevicedevice
 Non-owning pointer to an open CameraDevice, or nullptr. Not atomic, synced with memfences when becomes null. More...
 
VideoMode mode
 What mode we tried to open the device in, all zeros means default mode. More...
 
AVCodecContext * cctx
 Codec context of the camera's selected video stream. More...
 
AVCodecContext * cctxOrig
 Codec context of the camera's selected video stream. More...
 
int videoStreamIndex
 A camera can have multiple streams, this is the one we're decoding. More...
 
QReadWriteLock deviceMutex
 
QReadWriteLock streamMutex
 
std::atomic_bool _isNone
 
std::atomic_int subscriptions
 Remember how many times we subscribed for RAII. More...
 

Static Private Attributes

static CameraSourceinstance {nullptr}
 

Additional Inherited Members

- Public Types inherited from VideoSource
using IDType = std::uint_fast64_t
 
using AtomicIDType = std::atomic_uint_fast64_t
 
- Public Attributes inherited from VideoSource
const IDType id
 ID of this VideoSource. More...
 

Detailed Description

This class is a wrapper to share a camera's captured video frames.

It allows objects to suscribe and unsuscribe to the stream, starting the camera and streaming new video frames only when needed. This is a singleton, since we can only capture from one camera at the same time without thread-safety issues. The source is lazy in the sense that it will only keep the video device open as long as there are subscribers, the source can be open but the device closed if there are zero subscribers.

Definition at line 34 of file camerasource.h.

Constructor & Destructor Documentation

◆ CameraSource()

CameraSource::CameraSource ( )
private

Definition at line 95 of file camerasource.cpp.

Here is the caller graph for this function:

◆ ~CameraSource()

CameraSource::~CameraSource ( )
private

Definition at line 198 of file camerasource.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ closeDevice

void CameraSource::closeDevice ( )
privateslot

Closes the video device and stops streaming.

Note
Callers must own the biglock.

Definition at line 376 of file camerasource.cpp.

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

◆ destroyInstance()

void CameraSource::destroyInstance ( )
static

Definition at line 135 of file camerasource.cpp.

Here is the caller graph for this function:

◆ deviceOpened

void CameraSource::deviceOpened ( )
signal
Here is the caller graph for this function:

◆ getInstance()

CameraSource & CameraSource::getInstance ( )
static

Returns the singleton instance.

Definition at line 128 of file camerasource.cpp.

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

◆ isNone()

bool CameraSource::isNone ( ) const

Definition at line 193 of file camerasource.cpp.

◆ openDevice

void CameraSource::openDevice ( )
privateslot

Opens the video device and starts streaming.

Note
Callers must own the biglock.

Definition at line 260 of file camerasource.cpp.

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

◆ openFailed

void CameraSource::openFailed ( )
signal
Here is the caller graph for this function:

◆ setupDefault()

void CameraSource::setupDefault ( )

Setup default device.

Note
If a device is already open, the source will seamlessly switch to the new device.

Definition at line 145 of file camerasource.cpp.

Here is the call graph for this function:

◆ setupDevice

void CameraSource::setupDevice ( const QString &  DeviceName,
const VideoMode Mode 
)
slot

Change the device and mode.

Note
If a device is already open, the source will seamlessly switch to the new device.

Definition at line 162 of file camerasource.cpp.

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

◆ stream()

void CameraSource::stream ( )
private

Blocking. Decodes video stream and emits new frames.

Note
Designed to run in its own thread.

Definition at line 409 of file camerasource.cpp.

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

◆ subscribe()

void CameraSource::subscribe ( )
overridevirtual

If subscribe sucessfully opens the source, it will start emitting frameAvailable signals.

Implements VideoSource.

Definition at line 238 of file camerasource.cpp.

Here is the call graph for this function:

◆ unsubscribe()

void CameraSource::unsubscribe ( )
overridevirtual

Stop emitting frameAvailable signals, and free associated resources if necessary.

Implements VideoSource.

Definition at line 246 of file camerasource.cpp.

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

Member Data Documentation

◆ _isNone

std::atomic_bool CameraSource::_isNone
private

Definition at line 79 of file camerasource.h.

◆ cctx

AVCodecContext * CameraSource::cctx
private

Codec context of the camera's selected video stream.

Definition at line 71 of file camerasource.h.

◆ cctxOrig

AVCodecContext * CameraSource::cctxOrig
private

Codec context of the camera's selected video stream.

Deprecated:

Definition at line 73 of file camerasource.h.

◆ device

CameraDevice * CameraSource::device
private

Non-owning pointer to an open CameraDevice, or nullptr. Not atomic, synced with memfences when becomes null.

Definition at line 69 of file camerasource.h.

◆ deviceMutex

QReadWriteLock CameraSource::deviceMutex
private

Definition at line 76 of file camerasource.h.

◆ deviceName

QString CameraSource::deviceName
private

Short name of the device for CameraDevice's open(QString)

Definition at line 68 of file camerasource.h.

◆ deviceThread

QThread* CameraSource::deviceThread
private

Definition at line 66 of file camerasource.h.

◆ instance

CameraSource * CameraSource::instance {nullptr}
staticprivate

Definition at line 82 of file camerasource.h.

◆ mode

VideoMode CameraSource::mode
private

What mode we tried to open the device in, all zeros means default mode.

Definition at line 70 of file camerasource.h.

◆ streamFuture

QFuture< void > CameraSource::streamFuture
private

Future of the streaming thread.

Definition at line 65 of file camerasource.h.

◆ streamMutex

QReadWriteLock CameraSource::streamMutex
private

Definition at line 77 of file camerasource.h.

◆ subscriptions

std::atomic_int CameraSource::subscriptions
private

Remember how many times we subscribed for RAII.

Definition at line 80 of file camerasource.h.

◆ videoStreamIndex

int CameraSource::videoStreamIndex
private

A camera can have multiple streams, this is the one we're decoding.

Definition at line 74 of file camerasource.h.


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