7#include <QtCore/QElapsedTimer>
8#include <QtCore/QString>
9#include <QtCore/QTimer>
44 virtual void onRecordingFailed(
const QString& file,
const QString& error,
bool fileOpened) = 0;
80 const GstCaps* inputCaps);
89 [[nodiscard]]
bool build();
95 void setRequest(
const std::optional<Request>& request);
103 bool finalizing()
const {
return _state == State::Finalizing; }
110 void onBusError(GstMessage* message,
const GError* error,
const QString& text,
const char* debug);
125 void _start(
const Request& request);
128 void _switchAtKeyframe();
130 void _onSwitchKeyframe(quint64 hold);
132 void _releaseSwitchHold();
135 void _end(
const QString& failure = QString());
138 void _finish(
const QString& error,
bool fileClosed =
false);
141 bool _fromRecorder(GstObject* source)
const;
142 void _onFileOpened(quint64 recording);
143 void _onOverrun(quint64 recording);
146 void _onCapsChanged(quint64 recording);
148 void _checkStarted();
150 void _checkHeaderSpace();
151 void _reportOpened();
153 static GstPadProbeReturn _keyframeProbe(GstPad* pad, GstPadProbeInfo* info, gpointer data);
154 static GstPadProbeReturn _startProbe(GstPad* pad, GstPadProbeInfo* info, gpointer data);
155 static GstPadProbeReturn _capsProbe(GstPad* pad, GstPadProbeInfo* info, gpointer data);
156 static GstPadProbeReturn _switchProbe(GstPad* pad, GstPadProbeInfo* info, gpointer data);
157 static void _onQueueOverrun(
GstElement* queue, gpointer data);
159 const BranchContext _context;
161 QTimer _finalizeTimer;
167 State _state = State::Idle;
168 bool _streaming =
false;
169 std::optional<Request> _requested;
172 std::atomic<quint64> _recording = 0;
176 GStreamer::PadProbe _keyframeWatch;
179 GStreamer::PadProbe _startWatch;
181 GStreamer::PadProbe _capsWatch;
184 std::atomic<gulong> _capsHold = 0;
186 GStreamer::PadProbe _switchHold;
187 bool _switching =
false;
189 quint64 _switchHoldId = 0;
191 std::atomic<gint64> _fedAt = 0;
193 std::atomic<bool> _fileStarted =
false;
194 bool _openedReported =
false;
196 QElapsedTimer _openedFor;
struct _GstElement GstElement
virtual void onRecordingFileClosed(const QString &file, const QString &error)=0
file is closed; error is empty when it was finalized cleanly.
virtual void onRecordingNeedsNewFile(const QString &file)=0
virtual void onRecordingFileOpened(const QString &file)=0
file got its first frame.
virtual void onRecordingFailed(const QString &file, const QString &error, bool fileOpened)=0
static constexpr std::chrono::seconds kFinalizeTimeout
static constexpr std::chrono::seconds kHeaderEstimateDelay
static constexpr guint64 kQueueMaxBytes
Backlog the recording queue holds for slow storage before the recording gives up.
void completeTeardown()
Closes a file whose finalization is still outstanding by flushing the recorder, and reports it.
void onBusError(GstMessage *message, const GError *error, const QString &text, const char *debug)
RecordingBranch(const BranchContext &context, Listener &listener)
void setRequest(const std::optional< Request > &request)
GstElement * valve() const
static constexpr std::chrono::seconds kHeaderSpaceMargin
void onBusElement(GstMessage *message)
A bus ELEMENT message: the current recorder's EOS, as the pipeline forwards it, means its file is clo...
RecordingBranch & operator=(const RecordingBranch &)=delete
RecordingBranch(const RecordingBranch &)=delete
bool build()
Adds the branch's queue and closed valve behind the tee.
void onSourceStreaming()
The first frame reached the tee, so the input caps are known: a waiting request starts.
void reset()
Drops the recording, if any, without reports; the pipeline must be in NULL.
static GStreamer::GstElementPtr makeFileSink(const QString &file, VideoReceiver::FileFormat format, const GstCaps *inputCaps)
static constexpr std::chrono::seconds kStartTimeout
FileFormat
Values are persisted by VideoSettings::recordingFormat.
std::unique_ptr< GstElement, GstObjectDeleter > GstElementPtr
VideoReceiver::FileFormat format
friend bool operator==(const Request &, const Request &)=default