Categorygithub.com/bledogit/gosrt
repository
0.2.0
Repository: https://github.com/bledogit/gosrt.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Build Status GoDoc license

gosrt

This is a SRT library for Go. This is based on the SRT C library.

This library is internally binding SRT C API, but it exposes Go net package like API so that Go programmers can easy to integrate SRT into their application.

Examples

This is a simple example that receive SRT packets from port 5000 and forwards them to localhost port 5001.

l, _ := srt.Listen("srt", ":5000")
defer l.Close()
for {
    conn, _ := l.Accept()
    go func(sc net.Conn) {
        defer sc.Close()
        tc, _ := srt.Dial("srt", "127.0.0.1:5001")
        for {
            b := make([]byte, 1316)
            n, _ := sc.Read(b)
            tc.Write(b[:n])
        }
    }(conn)
}

SRT Socket Options

There are several SRT socket options. You can configure those options with a context.

For example, following code creates a context with options payloadsize to 1316 and latency to 400, then listen and dial with the options.

ctx := srt.WithOptions(context.Background(), srt.Options("payloadsize", "1316", "latency", "400"))

l, err := srt.ListenContext(ctx, "srt", ":5000")

var d srt.Dialer
tc, err := d.DialContext(ctx, "srt", "127.0.0.1:5001")

Following table show how gosrt option corresponds to SRT C API options.

gosrt optionSRT C API option
transtypeSRTO_TRANSTYPE
maxbwSRTO_MAXBW
pbkeylenSRTO_PBKEYLEN
passphraseSRTO_PASSPHRASE
mssSRTO_MSS
fcSRTO_FC
sndbufSRTO_SNDBUF
rcvbufSRTO_RCVBUF
ipttlSRTO_IPTTL
iptosSRTO_IPTOS
inputbwSRTO_INPUTBW
oheadbwSRTO_OHEADBW
latencySRTO_LATENCY
tsbpdmodeSRTO_TSBPDMODE
tlpktdropSRTO_TLPKTDROP
snddropdelaySRTO_SNDDROPDELAY
nakreportSRTO_NAKREPORT
conntimeoSRTO_CONNTIMEO
lossmaxttlSRTO_LOSSMAXTTL
rcvlatencySRTO_RCVLATENCY
peerlatencySRTO_PEERLATENCY
minversionSRTO_MINVERSION
streamidSRTO_STREAMID
congestionSRTO_CONGESTION
messageapiSRTO_MESSAGEAPI
payloadsizeSRTO_PAYLOADSIZE
kmrefreshrateSRTO_KMREFRESHRATE
kmpreannounceSRTO_KMPREANNOUNCE
enforcedencryptionSRTO_ENFORCEDENCRYPTION
peeridletimeoSRTO_PEERIDLETIMEO
packetfilterSRTO_PACKETFILTER

Run the Example app with Docker

The example app receives SRT packets and sends them to the target address specified in .env file. In the following steps, you can send a test stream from ffmpeg to the gosrt example app, and ffplay play it.

  1. Install ffmpeg with srt support
$ brew tap homebrew-ffmpeg/ffmpeg
$ brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-srt
  1. Run ffplay
$ ffplay -probesize 32000 -sync ext 'srt://0.0.0.0:5001?mode=listener'
  1. Run gosrt Example app
$ cp .env.sample .env
$ docker-compose up
  1. Run ffmpeg
$ ffmpeg -re -f lavfi -i testsrc=size=1280x720:rate=30 -f lavfi -i sine \
-vf drawtext="text='%{localtime\:%X}':fontsize=20:fontcolor=white:x=7:y=7" \
-vcodec libx264 -vb 2000k -preset ultrafast -x264-params keyint=60 \
-acodec aac -f mpegts 'srt://127.0.0.1:5000?streamid=#!::u=johnny,t=file,m=publish,r=results.csv'