The reconnect policy both receivers share: the phase a stream is in, when a failed one connects again, and when it gives up. More...
#include <StreamSupervisor.h>
Classes | |
| struct | FailureOutcome |
Public Types | |
| enum class | Phase : uint8_t { Idle , Connecting , Streaming , Reconnecting , Halted } |
| enum class | Failure : uint8_t { Transient , Permanent } |
| Whether another session could fare better than the one that failed. More... | |
| enum class | AutoReconnectChange : uint8_t { None , Halted , Resumable } |
Signals | |
| void | stateChanged (VideoReceiver::State state) |
| void | reconnectDue () |
| A failure's backoff has passed, or reconnectNow() cut it short: the receiver starts the next session. | |
Public Member Functions | |
| StreamSupervisor (QObject *parent=nullptr, ExponentialBackoff backoff=kDefaultBackoff) | |
| Phase | phase () const |
| VideoReceiver::State | state () const |
| bool | halted () const |
| bool | reconnectPending () const |
| A failure's backoff is running; reconnectDue() ends it. | |
| const QString & | lastFailure () const |
| The failure the stream halted or reconnects after. | |
| int | reconnectAttempts () const |
| Failures backed off from since the backoff last started over. | |
| int | reconnects () const |
| For VideoStreamStats::reconnects: sessions that streamed since startOver(), less the first. | |
| std::chrono::milliseconds | uptime () const |
| For VideoStreamStats::uptimeMs: since the current session started streaming; zero while it isn't. | |
| void | startOver () |
| void | stop () |
| The stream isn't wanted (anymore): Idle, without a reconnect. | |
| void | sessionStarted () |
| A new session runs. | |
| void | sessionStreaming () |
| The session delivers. The first call per session counts it as streamed. | |
| FailureOutcome | sessionFailed (const QString &message, Failure failure, bool autoReconnect) |
| AutoReconnectChange | autoReconnectChanged (bool autoReconnect) |
The config's autoReconnect became autoReconnect. | |
| void | reconnectNow () |
Static Public Attributes | |
| static constexpr ExponentialBackoff | kDefaultBackoff {std::chrono::seconds(1), 2, std::chrono::seconds(30)} |
The reconnect policy both receivers share: the phase a stream is in, when a failed one connects again, and when it gives up.
The receiver runs the sessions (a GStreamer pipeline, a QMediaPlayer) and tells the supervisor what becomes of them; the supervisor reports the VideoReceiver::State that follows and signals reconnectDue() once a backoff has passed. A failure reconnects after 1 s, doubling up to 30 s, unless it is permanent or autoReconnect is off: then the stream halts until startOver(). A session that streamed had recovered, so the backoff starts over after it fails.
Threading: the receiver's thread.
Definition at line 23 of file StreamSupervisor.h.
|
strong |
| Enumerator | |
|---|---|
| None | |
| Halted | Turned off while a reconnect was pending: the stream halted. |
| Resumable | Turned on while halted after a failure that wasn't permanent: the halt is lifted. |
Definition at line 51 of file StreamSupervisor.h.
|
strong |
Whether another session could fare better than the one that failed.
| Enumerator | |
|---|---|
| Transient | It may, so reconnecting is worth it. |
| Permanent | It can't: an unsupported stream, a missing plugin. |
Definition at line 38 of file StreamSupervisor.h.
|
strong |
| Enumerator | |
|---|---|
| Idle | Not streaming and not about to: not asked to, or before the first session. |
| Connecting | A session runs, without data yet. |
| Streaming | The session delivers. |
| Reconnecting | After a failure, until the session that replaces it starts. |
| Halted | Given up after a failure, until startOver() or autoReconnect resumes it. |
Definition at line 28 of file StreamSupervisor.h.
|
explicit |
Definition at line 5 of file StreamSupervisor.cc.
References reconnectDue().
| StreamSupervisor::AutoReconnectChange StreamSupervisor::autoReconnectChanged | ( | bool | autoReconnect | ) |
|
inline |
Definition at line 68 of file StreamSupervisor.h.
References Halted.
|
inline |
The failure the stream halted or reconnects after.
Definition at line 74 of file StreamSupervisor.h.
|
inline |
Definition at line 64 of file StreamSupervisor.h.
Referenced by reconnectDue().
|
inline |
Failures backed off from since the backoff last started over.
Definition at line 77 of file StreamSupervisor.h.
|
signal |
A failure's backoff has passed, or reconnectNow() cut it short: the receiver starts the next session.
Referenced by GstReceiverWorker::GstReceiverWorker(), reconnectNow(), and StreamSupervisor().
| void StreamSupervisor::reconnectNow | ( | ) |
The stream's source may be back: a reconnect waiting out its backoff is due now, and the backoff starts over. Nothing without one.
Definition at line 116 of file StreamSupervisor.cc.
References reconnectDue().
|
inline |
A failure's backoff is running; reconnectDue() ends it.
Definition at line 71 of file StreamSupervisor.h.
| int StreamSupervisor::reconnects | ( | ) | const |
For VideoStreamStats::reconnects: sessions that streamed since startOver(), less the first.
Definition at line 32 of file StreamSupervisor.cc.
| StreamSupervisor::FailureOutcome StreamSupervisor::sessionFailed | ( | const QString & | message, |
| Failure | failure, | ||
| bool | autoReconnect ) |
The session failed, or failed to start, and the receiver ended it. Reconnects after the backoff, unless failure is permanent or not autoReconnect: then halts.
Definition at line 78 of file StreamSupervisor.cc.
References Halted, Permanent, and Reconnecting.
| void StreamSupervisor::sessionStarted | ( | ) |
| void StreamSupervisor::sessionStreaming | ( | ) |
The session delivers. The first call per session counts it as streamed.
Definition at line 68 of file StreamSupervisor.cc.
References Streaming.
| void StreamSupervisor::startOver | ( | ) |
A user start or restart, or a new stream: the backoff and the reconnect count start over, a pending reconnect is dropped and a halt lifted. A running session keeps its phase.
Definition at line 42 of file StreamSupervisor.cc.
| VideoReceiver::State StreamSupervisor::state | ( | ) | const |
Definition at line 16 of file StreamSupervisor.cc.
References Connecting, VideoReceiver::Connecting, Halted, Idle, Reconnecting, VideoReceiver::Reconnecting, VideoReceiver::Stopped, Streaming, and VideoReceiver::Streaming.
Referenced by stateChanged().
|
signal |
References state().
Referenced by GstReceiverWorker::GstReceiverWorker(), and QtMultimediaVideoReceiver::QtMultimediaVideoReceiver().
| void StreamSupervisor::stop | ( | ) |
The stream isn't wanted (anymore): Idle, without a reconnect.
Definition at line 53 of file StreamSupervisor.cc.
References Idle.
| std::chrono::milliseconds StreamSupervisor::uptime | ( | ) | const |
For VideoStreamStats::uptimeMs: since the current session started streaming; zero while it isn't.
Definition at line 37 of file StreamSupervisor.cc.
|
staticconstexpr |
The cap bounds worst-case recovery after a long RF outage and stays below a typical RTSP server keepalive (60 s).
Definition at line 60 of file StreamSupervisor.h.