ToolX 1.11.1 [e3f477f]
A GUI debug tool chain for diagnosing GVA systems
Loading...
Searching...
No Matches
hls_player.h
Go to the documentation of this file.
1//
2// Copyright (c) 2026, Astute Systems PTY LTD
3//
4// This file is part of the VivoeX project developed by Astute Systems.
5//
6// License. See the LICENSE file in the project root for full license details.
7//
12
13#ifndef STREAMS_HLS_PLAYER_H
14#define STREAMS_HLS_PLAYER_H
15
16#include <QAudioSink>
17#include <QByteArray>
18#include <QDialog>
19#include <QGraphicsPixmapItem>
20#include <QGraphicsScene>
21#include <QGraphicsView>
22#include <QIODevice>
23#include <QImage>
24#include <QLabel>
25#include <QObject>
26#include <QPixmap>
27#include <QPointer>
28#include <QStatusBar>
29#include <QString>
30#include <QTimer>
31
32#include <atomic>
33#include <thread>
34
42class HlsPlayer : public QObject
43{
44 Q_OBJECT
45
46public:
52 explicit HlsPlayer(QWidget *parent = nullptr);
53
57 ~HlsPlayer() final;
58
59 HlsPlayer(const HlsPlayer &) = delete;
60 HlsPlayer &operator=(const HlsPlayer &) = delete;
61 HlsPlayer(HlsPlayer &&) = delete;
62 HlsPlayer &operator=(HlsPlayer &&) = delete;
63
64public slots:
71 void play(const QString name, const QString url);
72
76 void stop();
77
78signals:
84 void stateChanged(const QString &state);
85
91 void frameReceived(const QImage &image);
92
98 void workerState(const QString &state);
99
108 void audioReceived(const QByteArray &pcm, int sample_rate, int channels);
109
110protected:
112 bool eventFilter(QObject *obj, QEvent *event) override;
113
114private slots:
116 void showFrame(const QImage &image);
118 void sessionState(const QString &state);
120 void noFrame();
122 void playAudio(const QByteArray &pcm, int sample_rate, int channels);
123
124private:
126 void receiveLoop(const std::string &url);
128 void setLabelColour(const QString &colour);
129
131 QPointer<QDialog> m_dialog;
133 QGraphicsScene *m_scene = nullptr;
135 QGraphicsView *m_view = nullptr;
137 QGraphicsPixmapItem *m_pixmap_item = nullptr;
139 QPixmap m_pixmap;
141 QLabel *m_stream_label = nullptr;
143 QLabel *m_format_label = nullptr;
145 QLabel *m_frame_label = nullptr;
149 std::thread m_thread;
151 std::atomic<bool> m_stop{ false };
153 quint64 m_frame_count = 0;
155 QAudioSink *m_audio_sink = nullptr;
157 QIODevice *m_audio_io = nullptr;
166};
167
168#endif // STREAMS_HLS_PLAYER_H
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).
int m_audio_rate
Sample rate of the open audio output in Hz.
Definition hls_player.h:159
void play(const QString name, const QString url)
Open the playlist in the background and start playing.
Definition hls_player.cpp:121
QAudioSink * m_audio_sink
The audio output, created when the first audio arrives.
Definition hls_player.h:155
void receiveLoop(const std::string &url)
Receive the stream until stop is requested, runs on the worker thread.
Definition hls_player.cpp:142
void workerState(const QString &state)
The worker thread changed state (delivered queued to the GUI thread).
HlsPlayer(QWidget *parent=nullptr)
Construct a new HLS player and show the window.
Definition hls_player.cpp:58
void noFrame()
Blank the display when no frames are arriving.
Definition hls_player.cpp:291
void showFrame(const QImage &image)
Show a received frame.
Definition hls_player.cpp:215
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.
Definition hls_player.cpp:234
QGraphicsPixmapItem * m_pixmap_item
The pixmap item, kept to avoid flicker.
Definition hls_player.h:137
void sessionState(const QString &state)
Update the status bar and report the new state.
Definition hls_player.cpp:279
bool eventFilter(QObject *obj, QEvent *event) override
Event filter to keep the image fitted to the dialog on resize.
Definition hls_player.cpp:302
QLabel * m_frame_label
Frame counter label.
Definition hls_player.h:145
QGraphicsView * m_view
The view.
Definition hls_player.h:135
void frameReceived(const QImage &image)
A frame was decoded on the worker thread (delivered queued to the GUI thread).
QLabel * m_stream_label
Stream address label (without credentials or query).
Definition hls_player.h:141
QLabel * m_format_label
Resolution label.
Definition hls_player.h:143
~HlsPlayer() final
Stop the stream and close the window.
Definition hls_player.cpp:108
void stop()
Stop the stream, close the window and destroy this object.
Definition hls_player.cpp:134
std::thread m_thread
The receive thread.
Definition hls_player.h:149
QString m_audio_info
Audio description shown in the status bar, empty without audio.
Definition hls_player.h:163
QString m_video_info
Video resolution description shown in the status bar.
Definition hls_player.h:165
QPixmap m_pixmap
The displayed image.
Definition hls_player.h:139
QPointer< QDialog > m_dialog
The player dialog.
Definition hls_player.h:131
quint64 m_frame_count
Frames received.
Definition hls_player.h:153
std::atomic< bool > m_stop
Set to ask the receive thread to finish.
Definition hls_player.h:151
QIODevice * m_audio_io
The audio output device, owned by the sink. Null if audio cannot be played.
Definition hls_player.h:157
int m_audio_channels
Channel count of the open audio output.
Definition hls_player.h:161
void setLabelColour(const QString &colour)
Set the colour of the stream label.
Definition hls_player.cpp:297
QGraphicsScene * m_scene
The scene.
Definition hls_player.h:133
void stateChanged(const QString &state)
The state of the stream changed.
QTimer m_blank_timer
No-frame blanking timer.
Definition hls_player.h:147