srt-live-transmit
The srt-live-transmit
tool is a universal data transport tool, which’s intention is to transport data between SRT and other medium.
At the same time it is just a sample application to show some of the powerful features of SRT. We encourage you to use SRT library itself integrated into your products.
The srt-live-transmit
can be both used as a universal SRT-to-something-else flipper, as well as a testing tool for SRT.
The general usage is the following:
srt-live-transmit <input-uri> <output-uri> [options]
The following medium types are handled by srt-live-transmit
:
stdin
and stdout
standard streamsAny medium can be used with any direction, although some of them may have special direction-dependent cases.
Mind that the URI has a standard syntax:
scheme://HOST:PORT/PATH?PARAM1=VALUE1&PARAM2=VALUE2&...
The first parameter is introduced with a ?
and all following can be appended with an &
character.
If you specify only the path (no :// specified), then the scheme
defaults to file. The path can be also specified as relative this
way. Note also that empty host (scheme://:PORT
) defaults to 0.0.0.0,
and an empty port (when there’s no :PORT
part) defaults to port number 0.
Special options for particular medium may be specified in PARAM items. All options are medium-specific, although there may happen some options common for multiple media types.
Note also that the HOST part is always tried to be resolved as a name, if its form is not directly the IPv4 address.
First we need to start up the srt-live-transmit
app, listening for unicast UDP TS input on port 1234 and making SRT available on port 4201. Note, these are randomly chosen ports. We also open the app in verbose mode for debugging:
srt-live-transmit udp://:1234 srt://:4201 -v
Now we need to generate a UDP stream. ffmpeg can be used to generate bars and tone as follows, doing a simple unicast push to our listening srt-live-transmit
application:
ffmpeg -f lavfi -re -i smptebars=duration=300:size=1280x720:rate=30 -f lavfi -re -i sine=frequency=1000:duration=60:sample_rate=44100 -pix_fmt yuv420p -c:v libx264 -b:v 1000k -g 30 -keyint_min 120 -profile:v baseline -preset veryfast -f mpegts "udp://127.0.0.1:1234?pkt_size=1316"
You should see the stream connect in srt-live-transmit
.
Now you can test in VLC (make sure you’re using the latest version!) - just go to file -> open network stream and enter
srt://127.0.0.1:4201
and you should see bars and tone right away.
If you’re having trouble, make sure this works, then add complexity one step at a time (multicast, push vs listen, etc.).
Transmission mediums are specified as the standard URI format:
SCHEME://HOST:PORT?PARAM1=VALUE1&PARAM2=VALUE2&...
The applications supports the following schemes:
file
- for file or standard input and outputudp
- UDP output (unicast and multicast)srt
- SRT connectionNote that this application doesn’t support file as a medium, but this can be handled by other applications from this project.
NB! File mode, except file://con
, is not supported in the srt-file-transmit
tool!
The general syntax is: file:///global/path/to/the/file
. No parameters in the URL are extracted. There’s one (non-standard!) special case, though:
file://con
That is, con is used as a HOST part of the URI. If you use this URI for <input-uri>, then the data will be read from the standard input. If <output-uri>, the data will be send to the standard output. Be careful with options being specified together with having standard output as output URI - some of them are not allowed as the extra output controlled by options might interfere with the data output.
UDP can only be used in listening mode for input, and in calling mode for output. Multicast Streaming is also possible, whithout any special declaration. Just use an IP address from the multicast range. The specification and meaning of the fields in the URI depend on the mode.
The PORT part is always mandatory and it designates either the port number for the target host or the port number to be bound to read from.
For sending to unicast:
udp://TARGET:PORT?parameters...
The HOST part (here: TARGET) is mandatory and designates the target host
The iptos parameter designates the Type-Of-Service (TOS) field for
outgoing packets via IP_TOS
socket option.
The ttl parameter will set time-to-live value for outgoing packets via
IP_TTL
socket options.
For receiving from unicast:
udp://LOCALADDR:PORT?parameters...
INADDR_ANY
).For multicast the scheme is:
udp://GROUPADDR:PORT?parameters...
@
character is handled in this case, but it’s not
necessary, as the IGMP addresses are recognized by their mask.For sending to a multicast group:
The iptos parameter designates the Type-Of-Service (TOS) field for
outgoing packets via IP_TOS
socket option.
The ttl parameter will set time-to-live value for outgoing packets via
IP_MULTICAST_TTL
socket options.
The adapter parameter can be used to specify the adapter to be set
through IP_MULTICAST_IF
option to override the default device used for
sending
For receiving from a multicast group:
The adapter parameter can be used to specify the adapter through which the given multicast group can be reached (it’s used to bind the socket)
The source parameter enforces the use of IP_ADD_SOURCE_MEMBERSHIP
instead of IP_ADD_MEMBERSHIP
and the value is set to imr_sourceaddr
field.
Explanations for the symbols and terms used above can be found in POSIX
manual pages, like ip(7)
and on Microsoft docs pages under IPPROTO_IP
.
Most important about SRT is that it can be either input or output and in both these cases it can work in listener, caller and rendezvous mode. SRT also handles several parameters special way, in addition to standard SRT options that can be set through the parameters.
SRT can be connected using one of three connection modes:
caller: the “agent” (this application) sends the connection request to the peer, which must be listener, and this way it initiates the connection.
listener: the “agent” waits to be contacted by any peer caller. Note that a listener can accept multiple callers, but srt-live-transmit does not use this ability; after the first connection, it no longer accepts new connections.
rendezvous: A one-to-one only connection where both parties are equivalent and both connect to one another simultaneously. Whoever happened to start first (or succeeded to punch through the firewall) is meant to have initiated the connection.
This mode can be specified explicitly using the mode parameter. When it’s not specified, then it is “deduced” the following way:
srt://:1234
- the port is specified (1234), but host is empty. This assumes listener mode.srt://remote.host.com:1234
- both host and port are specified. This assumes caller mode.When the mode
parameter is specified explicitly, then the interpretation of the host
part is the following:
For caller, it’s always the destination host address. If this is empty, it is resolved to 0.0.0.0, which usually should mean connecting to the local host
For listener, it defines the IP address of the local device on which the socket should listen, e.g.:
srt://10.10.10.100:5001?mode=listener
An alternative method to specify this IP address is the adapter
parameter:
srt://:5001?adapter=10.10.10.100
The rendezvous mode is not deduced and it has to be specified explicitly. Note also special cases of the host and port parts specified in the URI:
Some parameters handled for SRT medium are specific, all others are socket options. The following parameters are handled special way by srt-live-transmit:
SRTO_RCVSYN
for input medium or SRTO_SNDSYN
for output mediumSRTO_RCVTIMEO
for input medium or SRTO_SNDTIMEO
for output mediumAll other parameters are SRT socket options. Here are some most characteristic options:
For the complete list of options, please refer to the SRT header file srt.h
and search for SRT_SOCKOPT
enum type. Please note that the set of available options may be version dependent. All options are available under the lowercase name of the option without the SRTO_
prefix. For example, SRTO_PASSPHRASE
can be set using
a passphrase parameter. The mapping table srt_options
can be found in common/socketoptions.hpp
file.
Important thing about the options (which holds true also for options for TCP and UDP, even though it’s not described anywhere explicitly) is that there are two categories of options:
srt_accept()
.You don’t have to worry about that actually - the application is aware of this and it sets these options at appropriate time.
Note also that blocking option has no practical use for users.
Normally the non-blocking mode is used only when you have an event-driven application that needs a common
signal bar for multiple event sources, or you prefer fibers to threads, when working with multiple SRT sockets in one application. The srt-live-transmit application isn’t defined this way. This makes that the practical result of non-blocking mode here is that it uses polling on exactly one socket with infinite timeout. Every reading and writing operation will then return always without blocking, but when they report the “again” situation the application will stall on srt_epoll_wait()
call. This option then exists for the testing purposes, as well as educational, to serve as an example of how your application should use the non-blocking mode.
The following options are available in the application. Note that some may affect specifically only selected type of medium.
Options usually have values and they are set using colon: for example, -t:60. Alternatively you can also separate them by a space, but this space must be part of the parameter and not extracted by a shell (using “ “ quotes or backslash).
stderr
.Before starting any test with srt-live-transmit
please make sure your video source works properly. For example: if you use VLC as a test player, send a UDP stream directly to it before routing it through srt-live-transmit
.
For any MPEG-TS UDP based source make sure it has packet sizes of 1316 bytes. When using ffmpeg
like in the “Example for Smoke Testing” section above set the pkt_size=1316
parameter in case your input is a continuous data stream like from a file, camera or data-generator.
When leaving the LAN for testing, please keep an eye on statistics and make sure your round-trip-time (RTT) is not drifting. It’s recommended to set the latency 3 to 4 times higher than RTT. Especially on wireless links such as WLAN, Line-of-Sight Radio (LOS) and mobile links such as LTE/4G or 5G the RTT can vary a lot.
If you perform tests on the public Internet, consider checking your firewall rules. The SRT listener must be reachable on the chosen UDP port. Same applies to routers using NAT. Please set a port forwarding rule with protocol UDP to the local IP address of the SRT listener.
The direction of initiating the stream doesn’t need to be the same as the stream direction. The sender of a stream can be a SRT listener or SRT caller as long as the receiving end uses the opposite mode. Typically you use the SRT listener on the end, which is easier to configure in terms of firewall/router setup. It also makes sense to leave the Sender in listener mode when trying to connect from various end points with possibly unknown IP addresses.