add new examples

This commit is contained in:
aler9
2020-11-21 12:30:40 +01:00
parent b4842c2841
commit c0c2390748
7 changed files with 233 additions and 7 deletions

View File

@@ -0,0 +1,44 @@
// +build ignore
package main
import (
"fmt"
"time"
"github.com/aler9/gortsplib"
)
// This example shows how to
// * connect to a RTSP server
// * read all tracks on a path
func main() {
// Dialer allows to set additional options
dialer := gortsplib.Dialer{
// the stream protocol
StreamProtocol: gortsplib.StreamProtocolUDP,
// timeout of read operations
ReadTimeout: 10 * time.Second,
// timeout of write operations
WriteTimeout: 10 * time.Second,
// read buffer count.
// If greater than 1, allows to pass buffers to routines different than the one
// that is reading frames
ReadBufferCount: 1,
}
// connect to the server and start reading all tracks
conn, err := dialer.DialRead("rtsp://localhost:8554/mystream")
if err != nil {
panic(err)
}
defer conn.Close()
// read frames from the server
readerDone := conn.OnFrame(func(id int, typ gortsplib.StreamType, buf []byte) {
fmt.Printf("frame from track %d, type %v: %v\n", id, typ, buf)
})
<-readerDone
}