ToolX 1.11.1 [e3f477f]
A GUI debug tool chain for diagnosing GVA systems
Loading...
Searching...
No Matches
HlsPlayer Class Reference

Downloads an HLS stream and displays the video in a window, playing any audio. More...

#include <hls_player.h>

Inheritance diagram for HlsPlayer:
Inheritance graph
Collaboration diagram for HlsPlayer:
Collaboration graph

Public Slots

void play (const QString name, const QString url)
 Open the playlist in the background and start playing.
void stop ()
 Stop the stream, close the window and destroy this object.

Signals

void stateChanged (const QString &state)
 The state of the stream changed.
void frameReceived (const QImage &image)
 A frame was decoded on the worker thread (delivered queued to the GUI thread).
void workerState (const QString &state)
 The worker thread changed state (delivered queued to the GUI thread).
void audioReceived (const QByteArray &pcm, int sample_rate, int channels)
 A block of decoded audio arrived on the worker thread (delivered queued to the GUI thread).

Public Member Functions

 HlsPlayer (QWidget *parent=nullptr)
 Construct a new HLS player and show the window.
 ~HlsPlayer () final
 Stop the stream and close the window.
 HlsPlayer (const HlsPlayer &)=delete
HlsPlayer & operator= (const HlsPlayer &)=delete
 HlsPlayer (HlsPlayer &&)=delete
HlsPlayer & operator= (HlsPlayer &&)=delete

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event) override
 Event filter to keep the image fitted to the dialog on resize.

Private Slots

void showFrame (const QImage &image)
 Show a received frame.
void sessionState (const QString &state)
 Update the status bar and report the new state.
void noFrame ()
 Blank the display when no frames are arriving.
void playAudio (const QByteArray &pcm, int sample_rate, int channels)
 Play a block of decoded audio, (re)opening the audio output when the format changes.

Private Member Functions

void receiveLoop (const std::string &url)
 Receive the stream until stop is requested, runs on the worker thread.
void setLabelColour (const QString &colour)
 Set the colour of the stream label.

Private Attributes

QPointer< QDialog > m_dialog
 The player dialog.
QGraphicsScene * m_scene = nullptr
 The scene.
QGraphicsView * m_view = nullptr
 The view.
QGraphicsPixmapItem * m_pixmap_item = nullptr
 The pixmap item, kept to avoid flicker.
QPixmap m_pixmap
 The displayed image.
QLabel * m_stream_label = nullptr
 Stream address label (without credentials or query).
QLabel * m_format_label = nullptr
 Resolution label.
QLabel * m_frame_label = nullptr
 Frame counter label.
QTimer m_blank_timer
 No-frame blanking timer.
std::thread m_thread
 The receive thread.
std::atomic< bool > m_stop { false }
 Set to ask the receive thread to finish.
quint64 m_frame_count = 0
 Frames received.
QAudioSink * m_audio_sink = nullptr
 The audio output, created when the first audio arrives.
QIODevice * m_audio_io = nullptr
 The audio output device, owned by the sink. Null if audio cannot be played.
int m_audio_rate = 0
 Sample rate of the open audio output in Hz.
int m_audio_channels = 0
 Channel count of the open audio output.
QString m_audio_info
 Audio description shown in the status bar, empty without audio.
QString m_video_info
 Video resolution description shown in the status bar.

Detailed Description

Downloads an HLS stream and displays the video in a window, playing any audio.

The stream is received on a worker thread using mediax::hls::HlsDepayloader. Audio is decoded to PCM by MediaX and played on the default audio output. The stream stops and the object is destroyed when the window is closed or stop() is called.

Constructor & Destructor Documentation

◆ HlsPlayer()

HlsPlayer::HlsPlayer ( QWidget * parent = nullptr)
explicit

Construct a new HLS player and show the window.

Parameters
parentthe parent widget (the player closes when the parent closes)

Member Function Documentation

◆ audioReceived

void HlsPlayer::audioReceived ( const QByteArray & pcm,
int sample_rate,
int channels )
signal

A block of decoded audio arrived on the worker thread (delivered queued to the GUI thread).

Parameters
pcminterleaved signed 16 bit samples in host byte order
sample_ratesample rate in Hz
channelsnumber of interleaved channels

◆ frameReceived

void HlsPlayer::frameReceived ( const QImage & image)
signal

A frame was decoded on the worker thread (delivered queued to the GUI thread).

Parameters
imagethe decoded frame

◆ play

void HlsPlayer::play ( const QString name,
const QString url )
slot

Open the playlist in the background and start playing.

Parameters
namethe stream name shown in the window title
urlthe playlist URL, http(s)://host/path/stream.m3u8

◆ stateChanged

void HlsPlayer::stateChanged ( const QString & state)
signal

The state of the stream changed.

Parameters
statea short description, e.g. "Playing" or "Failed: HTTP error"

◆ workerState

void HlsPlayer::workerState ( const QString & state)
signal

The worker thread changed state (delivered queued to the GUI thread).

Parameters
statea short description, e.g. "Playing" or "Failed: HTTP error"

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