QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
StreamSupervisor Class Reference

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>

Inheritance diagram for StreamSupervisor:
Collaboration diagram for StreamSupervisor:

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)}

Detailed Description

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.

Member Enumeration Documentation

◆ AutoReconnectChange

enum class StreamSupervisor::AutoReconnectChange : uint8_t
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.

◆ Failure

enum class StreamSupervisor::Failure : uint8_t
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.

◆ Phase

enum class StreamSupervisor::Phase : uint8_t
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.

Constructor & Destructor Documentation

◆ StreamSupervisor()

StreamSupervisor::StreamSupervisor ( QObject * parent = nullptr,
ExponentialBackoff backoff = kDefaultBackoff )
explicit

Definition at line 5 of file StreamSupervisor.cc.

References reconnectDue().

Member Function Documentation

◆ autoReconnectChanged()

StreamSupervisor::AutoReconnectChange StreamSupervisor::autoReconnectChanged ( bool autoReconnect)

The config's autoReconnect became autoReconnect.

Definition at line 101 of file StreamSupervisor.cc.

References Halted, Idle, None, and Resumable.

◆ halted()

bool StreamSupervisor::halted ( ) const
inline

Definition at line 68 of file StreamSupervisor.h.

References Halted.

◆ lastFailure()

const QString & StreamSupervisor::lastFailure ( ) const
inline

The failure the stream halted or reconnects after.

Definition at line 74 of file StreamSupervisor.h.

◆ phase()

Phase StreamSupervisor::phase ( ) const
inline

Definition at line 64 of file StreamSupervisor.h.

Referenced by reconnectDue().

◆ reconnectAttempts()

int StreamSupervisor::reconnectAttempts ( ) const
inline

Failures backed off from since the backoff last started over.

Definition at line 77 of file StreamSupervisor.h.

◆ reconnectDue

void StreamSupervisor::reconnectDue ( )
signal

A failure's backoff has passed, or reconnectNow() cut it short: the receiver starts the next session.

References Idle, and phase().

Referenced by GstReceiverWorker::GstReceiverWorker(), reconnectNow(), and StreamSupervisor().

◆ reconnectNow()

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().

◆ reconnectPending()

bool StreamSupervisor::reconnectPending ( ) const
inline

A failure's backoff is running; reconnectDue() ends it.

Definition at line 71 of file StreamSupervisor.h.

◆ reconnects()

int StreamSupervisor::reconnects ( ) const

For VideoStreamStats::reconnects: sessions that streamed since startOver(), less the first.

Definition at line 32 of file StreamSupervisor.cc.

◆ sessionFailed()

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.

◆ sessionStarted()

void StreamSupervisor::sessionStarted ( )

A new session runs.

Definition at line 61 of file StreamSupervisor.cc.

References Connecting.

◆ sessionStreaming()

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.

◆ startOver()

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.

References Halted, and Idle.

◆ state()

◆ stateChanged

void StreamSupervisor::stateChanged ( VideoReceiver::State state)
signal

◆ stop()

void StreamSupervisor::stop ( )

The stream isn't wanted (anymore): Idle, without a reconnect.

Definition at line 53 of file StreamSupervisor.cc.

References Idle.

◆ uptime()

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.

Member Data Documentation

◆ kDefaultBackoff

ExponentialBackoff StreamSupervisor::kDefaultBackoff {std::chrono::seconds(1), 2, std::chrono::seconds(30)}
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.


The documentation for this class was generated from the following files: