ToolX 1.11.1 [e3f477f]
A GUI debug tool chain for diagnosing GVA systems
Loading...
Searching...
No Matches
srt_generator.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_SRT_GENERATOR_H
14#define STREAMS_SRT_GENERATOR_H
15
16#include <atomic>
17#include <cstdint>
18#include <memory>
19#include <mutex>
20#include <string>
21#include <thread>
22
23#include "rtp/rtp.h"
24#include "srt/srt_transmitter.h"
26#include "streams/srt_utils.h"
28
29namespace toolx::streams {
30
32enum class SrtCodec {
39 // TODO(future): kAv1. MediaX v2.0.0 can not mux AV1 into MPEG-TS, so AV1 over SRT needs
40 // MediaX support first. The Codec column shows AV1 greyed out until then.
41};
42
45{
47 std::string name = "SRT Stream";
51 uint32_t width = 1280;
53 uint32_t height = 720;
55 uint32_t framerate = 25;
59 int pattern = 0;
60};
61
70{
71public:
75 SrtGenerator() = default;
76
81
82 SrtGenerator(const SrtGenerator &) = delete;
83 SrtGenerator &operator=(const SrtGenerator &) = delete;
84 SrtGenerator(SrtGenerator &&) = delete;
85 SrtGenerator &operator=(SrtGenerator &&) = delete;
86
96 bool start(const SrtTransmitConfig &config, std::string &error);
97
101 void stop();
102
108 bool isRunning() const;
109
115 ::mediax::srt::SrtState linkState() const;
116
122 std::string lastError() const;
123
129 uint64_t bytesSent() const;
130
136 void setPattern(int pattern);
137
143 void setSessionNameOverlay(bool enabled);
144
150 void setTimeOverlay(bool enabled);
151
158 static bool codecAvailable(SrtCodec codec);
159
160private:
162 void generateThread();
164 std::shared_ptr<mediax::rtp::RtpPayloader> createEncoder(SrtCodec codec) const;
165
169 std::shared_ptr<mediax::rtp::RtpPayloader> m_encoder;
171 std::unique_ptr<::mediax::srt::SrtTransmitter> m_transmitter;
173 std::thread m_thread;
175 std::atomic<bool> m_running{ false };
177 std::atomic<int> m_pattern{ 0 };
181 mutable std::mutex m_mutex;
183 std::string m_last_error;
184};
185
186} // namespace toolx::streams
187
188#endif // STREAMS_SRT_GENERATOR_H
Burns the session name (bottom centre) and the date/time (top right) into frames.
Definition frame_overlay.h:41
bool isRunning() const
Check if the generator is running.
Definition srt_generator.cpp:188
void stop()
Stop generating frames and close the link.
Definition srt_generator.cpp:163
std::mutex m_mutex
Guards m_last_error, which is written from the transmitter's worker thread.
Definition srt_generator.h:181
std::string m_last_error
The last error reported by the link.
Definition srt_generator.h:183
void setTimeOverlay(bool enabled)
Burn the date and time into the video while running.
Definition srt_generator.cpp:232
static bool codecAvailable(SrtCodec codec)
Check if a codec can be encoded on this machine.
Definition srt_generator.cpp:36
std::atomic< bool > m_running
True while the thread should run.
Definition srt_generator.h:175
uint64_t bytesSent() const
Get the number of transport stream bytes handed to SRT.
Definition srt_generator.cpp:207
bool start(const SrtTransmitConfig &config, std::string &error)
Open the encoder and the SRT link and start generating frames.
Definition srt_generator.cpp:65
std::shared_ptr< mediax::rtp::RtpPayloader > m_encoder
The encoder, outlives the transmitter's use of it.
Definition srt_generator.h:169
~SrtGenerator()
Stop the stream.
Definition srt_generator.cpp:31
FrameOverlay m_overlay
Paints the session name and date/time overlays into the frames.
Definition srt_generator.h:179
std::shared_ptr< mediax::rtp::RtpPayloader > createEncoder(SrtCodec codec) const
Create the encoder for a codec.
Definition srt_generator.cpp:48
::mediax::srt::SrtState linkState() const
The state of the SRT connection.
Definition srt_generator.cpp:193
std::thread m_thread
The frame generation thread.
Definition srt_generator.h:173
void generateThread()
The frame generation thread.
Definition srt_generator.cpp:237
void setSessionNameOverlay(bool enabled)
Burn the session name into the video while running.
Definition srt_generator.cpp:227
void setPattern(int pattern)
Change the test pattern while running.
Definition srt_generator.cpp:215
SrtTransmitConfig m_config
The stream configuration.
Definition srt_generator.h:167
std::unique_ptr<::mediax::srt::SrtTransmitter > m_transmitter
The SRT sender.
Definition srt_generator.h:171
std::atomic< int > m_pattern
The current test pattern.
Definition srt_generator.h:177
SrtGenerator()=default
Construct a new SRT generator.
std::string lastError() const
The description of the last error reported by the link.
Definition srt_generator.cpp:201
Paints the session name and date/time overlays into raw video frames.
SrtCodec
The video codecs that can be carried over SRT.
Definition srt_generator.h:32
@ kH265
H.265 / HEVC (requires VA-API).
Definition srt_generator.h:38
@ kH264
H.264 / AVC encoded with OpenH264 (software).
Definition srt_generator.h:34
@ kH264Vaapi
H.264 / AVC encoded with VA-API (hardware).
Definition srt_generator.h:36
Helpers shared by the SRT transmit and receive tabs: connection settings, srt:// URL building,...
Session Announcement Protocol (SDP) implementation for listening to announcements of stream data....
The settings of one end of an SRT link.
Definition srt_utils.h:36
The configuration of one SRT transmit stream.
Definition srt_generator.h:45
SrtCodec codec
Video codec.
Definition srt_generator.h:57
uint32_t height
Image height in pixels.
Definition srt_generator.h:53
uint32_t framerate
Frames per second.
Definition srt_generator.h:55
SrtLinkConfig link
The SRT connection settings.
Definition srt_generator.h:49
uint32_t width
Image width in pixels.
Definition srt_generator.h:51
int pattern
Test pattern index (see testPatternNames()).
Definition srt_generator.h:59
std::string name
Session name, shown in the table.
Definition srt_generator.h:47