ToolX 1.11.1 [e3f477f]
A GUI debug tool chain for diagnosing GVA systems
Loading...
Searching...
No Matches
webcam_capture.h
Go to the documentation of this file.
1//
2// Copyright (c) 2026, Astute Systems PTY LTD
3//
4// This file is part of the VivoeX project developed by Astute Systems.
5//
6// License. See the LICENSE file in the project root for full license details.
7//
13
14#ifndef STREAMS_WEBCAM_CAPTURE_H
15#define STREAMS_WEBCAM_CAPTURE_H
16
17#include <mutex>
18#include <QCamera>
19#include <QMediaCaptureSession>
20#include <QVideoSink>
21#include <QVideoFrame>
22#include <QImage>
23#include <QObject>
24
31class WebcamCapture : public QObject
32{
33 Q_OBJECT
34
35public:
41 static WebcamCapture *instance();
42
50 bool startCapture(int width = 640, int height = 480);
51
55 void stopCapture();
56
66 bool getLatestFrame(uint8_t *dest, int width, int height);
67
73 bool isActive() const;
74
75private slots:
81 void onVideoFrameChanged(const QVideoFrame &frame);
82
83private:
86 ~WebcamCapture() override;
87
89 std::unique_ptr<QCamera> m_camera;
91 std::unique_ptr<QMediaCaptureSession> m_session;
93 std::unique_ptr<QVideoSink> m_sink;
97 std::mutex m_mutex;
99 bool m_active = false;
100};
101
102#endif // STREAMS_WEBCAM_CAPTURE_H
bool startCapture(int width=640, int height=480)
Start capturing from the default camera.
Definition webcam_capture.cpp:38
std::unique_ptr< QCamera > m_camera
The camera device.
Definition webcam_capture.h:89
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...
Definition webcam_capture.cpp:110
bool m_active
Whether capture is active.
Definition webcam_capture.h:99
static WebcamCapture * instance()
Get the singleton instance (created on first call).
Definition webcam_capture.cpp:32
WebcamCapture()
Private constructor (singleton).
Definition webcam_capture.cpp:21
std::unique_ptr< QMediaCaptureSession > m_session
The capture session.
Definition webcam_capture.h:91
std::mutex m_mutex
Mutex protecting m_latestFrame.
Definition webcam_capture.h:97
std::unique_ptr< QVideoSink > m_sink
The video sink.
Definition webcam_capture.h:93
void stopCapture()
Stop capturing.
Definition webcam_capture.cpp:70
bool isActive() const
Check if the camera is actively capturing.
Definition webcam_capture.cpp:137
void onVideoFrameChanged(const QVideoFrame &frame)
Receive a new video frame from the camera.
Definition webcam_capture.cpp:88
QImage m_latestFrame
Latest captured frame as RGB888 QImage.
Definition webcam_capture.h:95