5#include <QtQuick/QQuickItem>
24 return QStringLiteral(
"thermalVideo");
26 return QStringLiteral(
"uvcCamera");
28 return QStringLiteral(
"videoTile");
30 return QStringLiteral(
"videoContent");
39 const int degrees = streamInfo->
rotation() % 360;
40 if ((degrees % 90) != 0) {
41 qCDebug(VideoStreamControllerLog) <<
"Ignoring the stream's rotation of" << degrees <<
"degrees";
53 , _name(nameForRole(
role))
54 , _videoSettings(videoSettings)
61 _hasOwnReceiver =
true;
96 if (_role != Role::Thermal) {
104 if (!_hasOwnReceiver) {
110 _receiver->shutDown();
115 if (_hasOwnReceiver || (
receiver == _receiver)) {
119 const bool wasDecoding =
decoding();
129 if (
VideoReceiver*
const oldReceiver = std::exchange(_receiver,
nullptr)) {
130 (void) disconnect(oldReceiver,
nullptr,
this,
nullptr);
141 _receiver->setParent(
this);
142 _receiver->setName(
name());
149 _updateReconnecting();
155 qCDebug(VideoStreamControllerLog) <<
name() <<
"video size" << size;
163 _receiver->setDisplayConfig(_resolvedDisplayConfig());
164 _receiver->setRecordingEncoding(_recordingEncoding);
165 _receiver->setVideoOutput(_displaySuspended ?
nullptr : _videoOutput.data());
182 if (
stats() != oldStats) {
185 _updateReconnecting();
200 (void) disconnect(_streamInfo,
nullptr,
this,
nullptr);
205 &VideoStreamController::_onStreamInfoChanged);
206 (void) connect(_streamInfo, &QObject::destroyed,
this, &VideoStreamController::_onStreamInfoChanged);
208 _onStreamInfoChanged();
211void VideoStreamController::_onStreamInfoChanged()
214 if (
const int rotation = shownRotation(_streamInfo);
rotation != _rotation) {
215 qCDebug(VideoStreamControllerLog) <<
name() <<
"rotation" <<
rotation;
226 if (camera != _camera) {
234 if (enabled != _enabled) {
240std::optional<VideoReceiver::Config> VideoStreamController::_resolvedConfig()
const
242 if (_role == Role::Camera) {
243 if (_camera.isEmpty()) {
246 VideoReceiver::Config config;
247 config.
uri = _camera;
263 _applyPending =
true;
264 (void) QMetaObject::invokeMethod(
this, &VideoStreamController::_apply, Qt::QueuedConnection);
267void VideoStreamController::_apply()
269 _applyPending =
false;
270 const std::optional<VideoReceiver::Config> config = _resolvedConfig();
271 if (
const QString
uri = config ? config->uri : QString();
uri != _uri) {
280 const bool active = _enabled && config.has_value();
284 qCDebug(VideoStreamControllerLog) <<
name() <<
"active:" <<
active <<
"uri:" <<
uri();
289 _receiver->setConfig(*config);
290 _receiver->setActive(
true);
292 _receiver->setActive(
false);
294 _receiver->setConfig(*config);
308 _receiver->setDisplayConfig(_resolvedDisplayConfig());
309 _receiver->restart();
316 _receiver->reconnectNow();
325 _updateReconnecting();
328void VideoStreamController::_forgetDecoded()
331 _updateReconnecting();
334void VideoStreamController::_updateReconnecting()
340 qCDebug(VideoStreamControllerLog) <<
name() <<
"reconnecting" <<
reconnecting;
356 qCDebug(VideoStreamControllerLog) <<
name()
357 << ((
videoOutput == _videoOutput) ?
"re-attaching video output" :
"video output")
361 if (_receiver && !_displaySuspended) {
372 qCDebug(VideoStreamControllerLog) <<
name() <<
"video output removed" <<
videoOutput;
373 _videoOutput =
nullptr;
375 (void) QMetaObject::invokeMethod(
this, &VideoStreamController::_detachVideoOutput, Qt::QueuedConnection);
378void VideoStreamController::_detachVideoOutput()
380 if (!_videoOutput && _receiver) {
390 if (suspended == _displaySuspended) {
393 _displaySuspended = suspended;
394 qCDebug(VideoStreamControllerLog) <<
name() << (suspended ?
"display suspended" :
"display resumed");
395 if (!_receiver || !_videoOutput) {
401 _receiver->setVideoOutput(
nullptr);
403 _receiver->setVideoOutput(_videoOutput);
409 return _receiver && _receiver->active();
415 _receiver->startRecording(file, format);
422 _receiver->stopRecording();
428 return _receiver && _receiver->encodesRecordings();
433 _recordingEncoding = encoding;
435 _receiver->setRecordingEncoding(encoding);
441 return _receiver && _receiver->streaming() && _receiver->videoOutput();
446 return _receiver && _receiver->takeScreenshot(file, exif);
451 return _receiver && _receiver->decoding();
456 return _receiver && _receiver->recording();
461 const QSize size = _receiver ? _receiver->videoSize() : QSize();
462 return ((_rotation % 180) != 0) ? size.transposed() : size;
468 if (!size.isEmpty()) {
469 return static_cast<double>(size.width()) / size.height();
472 const double advertised = _streamInfo->aspectRatio();
473 return (((_rotation % 180) != 0) && (advertised > 0.0)) ? (1.0 / advertised) : advertised;
475 return (_role == Role::Primary) ? _videoSettings->aspectRatio()->rawValue().toDouble() : 1.0;
485 if (_uri.isEmpty() || (_role == Role::Camera)) {
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void rawValueChanged(const QVariant &value)
Encapsulates the contents of a VIDEO_STREAM_INFORMATION message.
static QString insertBeforeExtension(const QString &file, const QString &tag)
"<base><tag>.<ext>" for file "<base>.<ext>", and "<file><tag>" for one without an extension.
void statsChanged(const VideoStreamStats &stats)
void videoSizeChanged(QSize size)
void recordingChanged(bool recording)
void setVideoOutput(QQuickItem *videoOutput)
void stateChanged(VideoReceiver::State state)
void recordingFinished(const QString &file, const QString &error)
A recording file closed. error is empty when the file was finalized cleanly.
FileFormat
Values are persisted by VideoSettings::recordingFormat.
void recordingStarted(const QString &file)
A recording file opened: the first one after startRecording(), or the recording's next part.
void decodingChanged(bool decoding)
@ Stopped
Inactive, no URI, or given up after a failure (autoReconnect off).
void errorOccurred(const QString &message)
void setDisplaySuspended(bool suspended)
QGCVideoStreamInfo * streamInfo() const
void recordingStarted(const QString &file)
void setDisplayName(const QString &displayName)
QQuickItem * videoOutput() const
void recordingFinished(const QString &file, const QString &error)
void restart()
Reconnects now and rebuilds the receiver's display sink, so construct-only sink settings apply.
void encodesRecordingsChanged()
void setCamera(const QString &camera)
QString displayName() const
void displayNameChanged()
~VideoStreamController() override
void startRecording(const QString &file, VideoReceiver::FileFormat format)
VideoReceiver * receiver() const
QString taggedFile(const QString &file) const
file for this source: the thermal stream's name goes before the extension, "<base>....
double aspectRatio() const
bool encodesRecordings() const
bool takeScreenshot(const QString &file, const VideoScreenshot::Exif &exif={}) const
void setReceiver(VideoReceiver *receiver)
QString transport() const
void setEnabled(bool enabled)
The stream plays while it is enabled and configured().
VideoStreamResolver::Role Role
The source is shown in a tile of the video view, rather than as the main picture or with it.
void setRecordingEncoding(const VideoReceiver::RecordingEncoding &encoding)
VideoReceiver::setRecordingEncoding(), for the receiver and for each one set later.
void reconnectNow()
VideoReceiver::reconnectNow(): the stream's source is likely back, so a reconnect doesn't wait out it...
QSize videoSize() const
The size the stream is shown at: the receiver's video size, turned by rotation().
void aspectRatioChanged()
bool reconnecting() const
bool active() const
True when the receiver is active, accepting startRecording().
VideoStreamStats stats() const
The receiver's VideoReceiver::stats(); invalid without a receiver.
Q_INVOKABLE void registerVideoOutput(QQuickItem *videoOutput)
VideoStreamController(Role role, VideoSettings *videoSettings, QObject *parent=nullptr, VideoReceiver *ownReceiver=nullptr)
ownReceiver, when given, is the source's receiver for good; the source takes ownership of it.
Q_INVOKABLE void unregisterVideoOutput(QQuickItem *videoOutput)
void setRole(Role role)
Makes a stream in a tile the primary stream, or the reverse. What the source plays stays.
void recordingChanged(bool recording)
void setStreamInfo(QGCVideoStreamInfo *streamInfo)
The stream the camera advertises for this role, which takes precedence over the manual settings.
void reconnectingChanged()
void stop()
Disables the stream and stops the receiver now.
void errorOccurred(const QString &message)
bool canTakeScreenshot() const
True while the stream is streaming into a registered output.
QString redactedUrlForLogging(const QUrl &url)
Settings snapshot(VideoSettings *videoSettings)
VideoReceiver::DisplayConfig displayConfig(const Settings &settings)
The display sink settings: GPU zero-copy unless the CPU path or a software decoder is forced.
Role
What a video source, each with a VideoStreamController, is. VideoSourceRole.Primary,...
@ Primary
The stream to display: a vehicle's current camera's current one, else the one the settings configure.
@ Camera
The local camera: the one the video source setting names or, beside a stream, the one for a tile.
@ Tile
Another stream a vehicle's cameras advertise, shown in a tile.
@ Thermal
The thermal stream a vehicle's current camera advertises.
QString transportName(const QString &uri)
std::optional< VideoReceiver::Config > resolve(const Settings &settings, const QGCVideoStreamInfo *streamInfo, Role role)
How the display sink presents frames. Construct-only: a change applies when restart() rebuilds the si...