Skip to content
forked from openfresh/gosrt

Go SRT library with the net package like API.

License

Notifications You must be signed in to change notification settings

ZloyDyadka/gosrt

Repository files navigation

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 option SRT C API option
maxbw SRTO_MAXBW
pbkeylen SRTO_PBKEYLEN
passphrase SRTO_PASSPHRASE
mss SRTO_MSS
fc SRTO_FC
sndbuf SRTO_SNDBUF
rcvbuf SRTO_RCVBUF
ipttl SRTO_IPTTL
iptos SRTO_IPTOS
inputbw SRTO_INPUTBW
oheadbw SRTO_OHEADBW
latency SRTO_LATENCY
tsbpddelay SRTO_TSBPDDELAY
tlpktdrop SRTO_TLPKTDROP
snddropdelay SRTO_SNDDROPDELAY
nakreport SRTO_NAKREPORT
conntimeo SRTO_CONNTIMEO
lossmaxttl SRTO_LOSSMAXTTL
rcvlatency SRTO_RCVLATENCY
peerlatency SRTO_PEERLATENCY
minversion SRTO_MINVERSION
streamid SRTO_STREAMID
smoother SRTO_SMOOTHER
messageapi SRTO_MESSAGEAPI
payloadsize SRTO_PAYLOADSIZE
transtype SRTO_TRANSTYPE
kmrefreshrate SRTO_KMREFRESHRATE
kmpreannounce SRTO_KMPREANNOUNCE

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 install ffmpeg --with-srt --with-fontconfig --with-freetype
  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

About

Go SRT library with the net package like API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.1%
  • Other 0.9%