QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RecordingPlan.cc
Go to the documentation of this file.
1#include "RecordingPlan.h"
2
3#include <algorithm>
4
5#include <QtCore/QFileInfo>
6
8 std::chrono::milliseconds maxPartDuration)
9 : _file(file)
10 , _format(format)
11 , _maxPartDuration(maxPartDuration)
12{}
13
14QString RecordingPlan::insertBeforeExtension(const QString& file, const QString& tag)
15{
16 const qsizetype dot = file.lastIndexOf(u'.');
17 const qsizetype separator = std::max(file.lastIndexOf(u'/'), file.lastIndexOf(u'\\'));
18 return (dot > separator) ? (file.left(dot) + tag + file.mid(dot)) : (file + tag);
19}
20
21QString RecordingPlan::partFile(const QString& file, int part)
22{
23 return (part <= 1) ? file : insertBeforeExtension(file, QStringLiteral("_part%1").arg(part));
24}
25
26bool RecordingPlan::onFileOpened(const QString& file, Clock::time_point now)
27{
28 if (file != currentFile()) {
29 return false;
30 }
31 _opened = true;
32 _openFile = file;
33 _partStartedAt = now;
34 if (!_startedAt) {
35 _startedAt = now;
36 }
37 return true;
38}
39
40void RecordingPlan::onFileClosed(const QString& file)
41{
42 if (file == _openFile) {
43 _closedBytes += QFileInfo(file).size();
44 _openFile.clear();
45 }
46}
47
48bool RecordingPlan::partDue(Clock::time_point now) const
49{
50 return _opened && ((now - _partStartedAt) >= _maxPartDuration);
51}
52
54{
55 if (_opened) {
56 ++_part;
57 _opened = false;
58 }
59}
60
61qint64 RecordingPlan::recordingMs(Clock::time_point now) const
62{
63 return _startedAt ? std::chrono::duration_cast<std::chrono::milliseconds>(now - *_startedAt).count() : -1;
64}
65
67{
68 return _closedBytes + (_openFile.isEmpty() ? 0 : QFileInfo(_openFile).size());
69}
static QString partFile(const QString &file, int part)
"<base>_part<part>.<ext>" for file "<base>.<ext>"; file itself for part 1.
bool onFileOpened(const QString &file, Clock::time_point now=Clock::now())
file got its first frame at now. False, changing nothing, unless it is the current part's file.
RecordingPlan(const QString &file, VideoReceiver::FileFormat format, std::chrono::milliseconds maxPartDuration=kMaxPartDuration)
qint64 recordingMs(Clock::time_point now=Clock::now()) const
For VideoStreamStats::recordingMs: since the first part got its first frame; -1 before.
bool partDue(Clock::time_point now=Clock::now()) const
The current part has recorded for its maximum duration by now.
QString currentFile() const
The file the current part records to.
static QString insertBeforeExtension(const QString &file, const QString &tag)
"<base><tag>.<ext>" for file "<base>.<ext>", and "<file><tag>" for one without an extension.
qint64 bytesWritten() const
For VideoStreamStats::recordingBytes: what the parts' files held when they closed,...
VideoReceiver::FileFormat format() const
int part() const
void onFileClosed(const QString &file)
file is closed. Counts for the one that opened last only: a file of an earlier recording can close la...
FileFormat
Values are persisted by VideoSettings::recordingFormat.