Skip to content

Commit

Permalink
added example to use SRT Access Control
Browse files Browse the repository at this point in the history
  • Loading branch information
thmatuza committed Apr 3, 2020
1 parent 5dc68b3 commit e3c7fb6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
69 changes: 36 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,47 @@ 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 |
| strictenc | SRTO_STRICTENC |
| 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
```sh
$ brew install ffmpeg --with-srt --with-fontconfig --with-freetype
$ brew tap homebrew-ffmpeg/ffmpeg
$ brew install homebrew-ffmpeg/ffmpeg/ffmpeg --with-srt
```

2. Run ffplay
Expand All @@ -100,5 +103,5 @@ $ docker-compose up
$ 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
-acodec aac -f mpegts 'srt://127.0.0.1:5000?streamid=#!::u=johnny,t=file,m=publish,r=results.csv'
```
26 changes: 26 additions & 0 deletions examples/livetransmit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ func main() {
log.Fatal(err)
}
fmt.Printf("accepted: %s\n", conn.RemoteAddr())
sc := conn.(*srt.SRTConn)
if sc == nil {
fmt.Printf("conn is not srtConn: %s\n", conn.RemoteAddr())
} else {
username := ""
streamID, err := sc.StreamID()
if err != nil {
log.Fatal(err)
}
if strings.HasPrefix(streamID, "#!::") {
items := strings.Split(streamID[4:], ",")
for i := range items {
kv := strings.Split(items[i], "=")
if len(kv) == 2 && kv[0] == "u" {
username = kv[1]
}
}
if username == "" {
fmt.Println("USER NOT FOUND")
}
} else {
// By default the whole streamid is username
username = streamID
}
fmt.Printf("username is %s\n", username)
}
target := ""
if i < len(targets) {
target = targets[i]
Expand Down

0 comments on commit e3c7fb6

Please sign in to comment.