ToolX 1.11.1 [e3f477f]
A GUI debug tool chain for diagnosing GVA systems
Loading...
Searching...
No Matches
WebcamCapture Class Reference

Singleton webcam capture using Qt6 Multimedia. More...

#include <webcam_capture.h>

Inheritance diagram for WebcamCapture:
Inheritance graph
Collaboration diagram for WebcamCapture:
Collaboration graph

Public Member Functions

bool startCapture (int width=640, int height=480)
 Start capturing from the default camera.
void stopCapture ()
 Stop capturing.
bool getLatestFrame (uint8_t *dest, int width, int height)
 Copy the latest webcam frame into the destination buffer as RGB24, scaled to the requested dimensions.
bool isActive () const
 Check if the camera is actively capturing.

Static Public Member Functions

static WebcamCapture * instance ()
 Get the singleton instance (created on first call).

Private Slots

void onVideoFrameChanged (const QVideoFrame &frame)
 Receive a new video frame from the camera.

Private Member Functions

 WebcamCapture ()
 Private constructor (singleton).

Private Attributes

std::unique_ptr< QCamera > m_camera
 The camera device.
std::unique_ptr< QMediaCaptureSession > m_session
 The capture session.
std::unique_ptr< QVideoSink > m_sink
 The video sink.
QImage m_latestFrame
 Latest captured frame as RGB888 QImage.
std::mutex m_mutex
 Mutex protecting m_latestFrame.
bool m_active = false
 Whether capture is active.

Detailed Description

Singleton webcam capture using Qt6 Multimedia.

Only one instance is created (first user). Multiple StreamGenerators can read the latest frame concurrently via getLatestFrame().

Member Function Documentation

◆ getLatestFrame()

bool WebcamCapture::getLatestFrame ( uint8_t * dest,
int width,
int height )

Copy the latest webcam frame into the destination buffer as RGB24, scaled to the requested dimensions.

Parameters
destDestination buffer (must be at least width*height*3 bytes)
widthTarget width
heightTarget height
Returns
true if a frame was available and copied

◆ instance()

WebcamCapture * WebcamCapture::instance ( )
static

Get the singleton instance (created on first call).

Returns
WebcamCapture*

◆ isActive()

bool WebcamCapture::isActive ( ) const

Check if the camera is actively capturing.

Returns
true if active

◆ onVideoFrameChanged

void WebcamCapture::onVideoFrameChanged ( const QVideoFrame & frame)
privateslot

Receive a new video frame from the camera.

Parameters
frameThe video frame

◆ startCapture()

bool WebcamCapture::startCapture ( int width = 640,
int height = 480 )

Start capturing from the default camera.

Parameters
widthDesired capture width
heightDesired capture height
Returns
true if camera started successfully

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