GithubHelp home page GithubHelp logo

mixer / gosrt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openfresh/gosrt

1.0 1.0 1.0 194 KB

Go SRT library with the net package like API.

License: MIT License

Go 99.10% C++ 0.29% C 0.12% Dockerfile 0.50%

gosrt's Introduction

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
transtype SRTO_TRANSTYPE
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
tsbpdmode SRTO_TSBPDMODE
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
congestion SRTO_CONGESTION
messageapi SRTO_MESSAGEAPI
payloadsize SRTO_PAYLOADSIZE
kmrefreshrate SRTO_KMREFRESHRATE
kmpreannounce SRTO_KMPREANNOUNCE
enforcedencryption SRTO_ENFORCEDENCRYPTION
peeridletimeo SRTO_PEERIDLETIMEO
packetfilter SRTO_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=user,t=file,m=publish,r=results.csv&passphrase=verylongpassword'

gosrt's People

Contributors

thmatuza avatar mauricioabreu avatar

Stargazers

Thomas Lekanger avatar

Watchers

James Cloos avatar

Forkers

hayson

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.