forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-tcp.go
60 lines (47 loc) · 986 Bytes
/
client-tcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// +build ignore
package main
import (
"fmt"
"net/url"
"github.com/aler9/gortsplib"
)
func main() {
u, err := url.Parse("rtsp://user:[email protected]/mystream")
if err != nil {
panic(err)
}
conn, err := gortsplib.NewConnClient(gortsplib.ConnClientConf{Host: u.Host})
if err != nil {
panic(err)
}
defer conn.Close()
_, err = conn.Options(u)
if err != nil {
panic(err)
}
tracks, _, err := conn.Describe(u)
if err != nil {
panic(err)
}
for _, track := range tracks {
_, err := conn.SetupTcp(u, track)
if err != nil {
panic(err)
}
}
_, err = conn.Play(u)
if err != nil {
panic(err)
}
frame := &gortsplib.InterleavedFrame{Content: make([]byte, 0, 512*1024)}
for {
frame.Content = frame.Content[:cap(frame.Content)]
err := conn.ReadFrame(frame)
if err != nil {
fmt.Println("connection is closed (%s)", err)
break
}
fmt.Printf("packet from track %d, type %v: %v\n",
frame.TrackId, frame.StreamType, frame.Content)
}
}