qTox
Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
|
This class is a wrapper to share a camera's captured video frames. More...
#include <camerasource.h>
Public Slots | |
void | setupDevice (const QString &deviceName, const VideoMode &mode) |
Change the device and mode. More... | |
Signals | |
void | deviceOpened () |
void | openFailed () |
![]() | |
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... | |
![]() | |
VideoSource () | |
virtual | ~VideoSource ()=default |
Static Public Member Functions | |
static CameraSource & | getInstance () |
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... | |
CameraDevice * | device |
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 CameraSource * | instance {nullptr} |
Additional Inherited Members | |
![]() | |
using | IDType = std::uint_fast64_t |
using | AtomicIDType = std::atomic_uint_fast64_t |
![]() | |
const IDType | id |
ID of this VideoSource. More... | |
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.
|
private |
|
private |
|
privateslot |
Closes the video device and stops streaming.
Definition at line 376 of file camerasource.cpp.
|
static |
|
signal |
|
static |
Returns the singleton instance.
Definition at line 128 of file camerasource.cpp.
bool CameraSource::isNone | ( | ) | const |
Definition at line 193 of file camerasource.cpp.
|
privateslot |
Opens the video device and starts streaming.
Definition at line 260 of file camerasource.cpp.
|
signal |
void CameraSource::setupDefault | ( | ) |
Setup default device.
Definition at line 145 of file camerasource.cpp.
|
slot |
Change the device and mode.
Definition at line 162 of file camerasource.cpp.
|
private |
Blocking. Decodes video stream and emits new frames.
Definition at line 409 of file camerasource.cpp.
|
overridevirtual |
If subscribe sucessfully opens the source, it will start emitting frameAvailable signals.
Implements VideoSource.
Definition at line 238 of file camerasource.cpp.
|
overridevirtual |
Stop emitting frameAvailable signals, and free associated resources if necessary.
Implements VideoSource.
Definition at line 246 of file camerasource.cpp.
|
private |
Definition at line 79 of file camerasource.h.
|
private |
Codec context of the camera's selected video stream.
Definition at line 71 of file camerasource.h.
|
private |
Codec context of the camera's selected video stream.
Definition at line 73 of file camerasource.h.
|
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.
|
private |
Definition at line 76 of file camerasource.h.
|
private |
Short name of the device for CameraDevice's open(QString)
Definition at line 68 of file camerasource.h.
|
private |
Definition at line 66 of file camerasource.h.
|
staticprivate |
Definition at line 82 of file camerasource.h.
|
private |
What mode we tried to open the device in, all zeros means default mode.
Definition at line 70 of file camerasource.h.
|
private |
Future of the streaming thread.
Definition at line 65 of file camerasource.h.
|
private |
Definition at line 77 of file camerasource.h.
|
private |
Remember how many times we subscribed for RAII.
Definition at line 80 of file camerasource.h.
|
private |
A camera can have multiple streams, this is the one we're decoding.
Definition at line 74 of file camerasource.h.