mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00
update docs
This commit is contained in:
66
examples/client-read-tcp.go
Normal file
66
examples/client-read-tcp.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// +build ignore
|
||||
|
||||
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.
|
||||
|
||||
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})
|
||||
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()
|
||||
if err != nil {
|
||||
fmt.Println("connection is closed (%s)", err)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("frame from track %d, type %v: %v\n",
|
||||
frame.TrackId, frame.StreamType, frame.Content)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user