QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
UVCStreamMonitor.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <QtCore/QList>
6#include <QtCore/QMetaObject>
7#include <QtCore/QObject>
8#include <QtCore/QPointer>
9#include <QtCore/QSize>
10#include <QtCore/QTimer>
11#include <QtMultimedia/QVideoFrameFormat>
12#include <QtQmlIntegration/QtQmlIntegration>
13
14#include "VideoStreamStats.h"
16
17class QCamera;
18class QVideoFrame;
19class QVideoSink;
20
27class UVCStreamMonitor : public QObject
28{
29 Q_OBJECT
30 QML_ELEMENT
31 QML_UNCREATABLE("")
32
33 Q_PROPERTY(VideoStreamStats stats READ stats NOTIFY statsChanged FINAL)
34 Q_PROPERTY(QSize videoSize READ videoSize NOTIFY statsChanged FINAL)
35 Q_PROPERTY(double cameraFrameRate READ cameraFrameRate NOTIFY statsChanged FINAL)
36
38 friend class VideoManagerTest;
39
40public:
42 explicit UVCStreamMonitor(QObject* parent = nullptr, VideoStreamStatsMeter::Clock clock = {});
43
45 void attach(QCamera* camera, QVideoSink* videoSink);
47 void detach();
48
49 VideoStreamStats stats() const { return _stats; }
50
51 QSize videoSize() const { return _videoSize; }
52
54 double cameraFrameRate() const { return _cameraFrameRate; }
55
56signals:
58
59private:
61 struct FrameCounters
62 {
63 quint64 frames = 0;
64 QSize size;
65 QVideoFrameFormat::PixelFormat pixelFormat = QVideoFrameFormat::Format_Invalid;
66 double streamFrameRate = 0.0;
67 bool gpu = false;
68 };
69
70 void _onVideoFrame(const QVideoFrame& frame);
71 void _sample();
73 void _restart();
74 void _disconnect();
75 void _publish(const VideoStreamStats& stats, QSize videoSize, double cameraFrameRate);
76
79 QTimer _sampleTimer;
80 QPointer<QVideoSink> _videoSink;
81 QList<QMetaObject::Connection> _connections;
82
83 FrameCounters _frameCounters;
84
85 std::optional<qint64> _streamingSinceMs;
86 VideoStreamStats _stats;
87 QSize _videoSize;
88 double _cameraFrameRate = 0.0;
89};
double cameraFrameRate() const
The frame rate the camera was set up for; 0 while unknown.
QSize videoSize() const
void detach()
Stops measuring.
void attach(QCamera *camera, QVideoSink *videoSink)
Measures the frames videoSink receives from camera (optional), in place of any other sink attached.
friend class UVCStreamMonitorTest
friend class VideoManagerTest
UVCStreamMonitor(QObject *parent=nullptr, VideoStreamStatsMeter::Clock clock={})
clock defaults to the steady clock.
VideoStreamStats stats() const
std::function< qint64()> Clock
Monotonic milliseconds.