ConnClient: new methods DialRead and DialPublish

This commit is contained in:
aler9
2020-10-04 16:15:11 +02:00
parent a36d16b015
commit 973464ed1d
7 changed files with 216 additions and 281 deletions

View File

@@ -4,54 +4,21 @@ package main
import (
"fmt"
"net/url"
"github.com/aler9/gortsplib"
)
// This example shows how to create a RTSP client, connect to a server, list
// and read tracks with the TCP protocol.
// This example shows how to create a RTSP client, connect to a server and
// read all tracks with the TCP protocol.
func main() {
// parse url
u, err := url.Parse("rtsp://localhost:8554/mystream")
if err != nil {
panic(err)
}
// connect to the server
conn, err := gortsplib.NewConnClient(gortsplib.ConnClientConf{Host: u.Host})
// connect to the server and start reading all tracks
conn, _, err := gortsplib.DialRead("rtsp://localhost:8554/mystream", gortsplib.StreamProtocolTCP)
if err != nil {
panic(err)
}
defer conn.Close()
// get allowed commands
_, err = conn.Options(u)
if err != nil {
panic(err)
}
// list tracks published on the path
tracks, _, err := conn.Describe(u)
if err != nil {
panic(err)
}
// setup tracks with TCP
for _, track := range tracks {
_, err := conn.SetupTCP(u, gortsplib.SetupModePlay, track)
if err != nil {
panic(err)
}
}
// start reading
_, err = conn.Play(u)
if err != nil {
panic(err)
}
for {
// read frames
frame, err := conn.ReadFrameTCP()