-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
139 lines (111 loc) · 2.57 KB
/
client.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package rtsp
import (
"strconv"
goPool "github.com/panjf2000/gnet/pkg/pool/goroutine"
"github.com/sirupsen/logrus"
)
type Client struct {
state State
cseqCounter int
pool *goPool.Pool
Url string
Write WriteHandler
}
func NewClient(write WriteHandler) *Client {
return &Client{
state: EmptyState,
cseqCounter: 0,
pool: goPool.Default(),
Write: write,
}
}
func (c *Client) SetUrl(url string) {
c.Url = url
}
func (c *Client) State() State {
return c.state
}
func (c *Client) decodeRtpRtcp(buf []byte) (int, error) {
return 0, nil
}
func (c *Client) Feed(buf []byte) (int, error) {
if len(buf) == 0 {
logrus.Warningf("rtsp feed empty data")
return 0, nil
}
var err error
var endOffset int
if buf[0] != '$' {
_, endOffset, err = UnmarshalResponse(buf)
if err != nil {
return endOffset, err
}
// err = c.responseProcess(resp)
// if err != nil {
// return endOffset, err
// }
} else {
endOffset, err = c.decodeRtpRtcp(buf)
if err != nil {
return endOffset, err
}
}
return endOffset, nil
}
func (c *Client) nextCSeq() string {
c.cseqCounter++
return strconv.Itoa(c.cseqCounter)
}
func (c *Client) NewRequest(method string) *Request {
req := &Request{
method: method,
url: "*",
version: "RTSP/1.0",
lines: HeaderLines{
"CSeq": c.nextCSeq(),
},
}
return req
}
func (c *Client) NewOptionsRequest() *OptionsRequest {
req := c.NewRequest("OPTIONS").Option()
return req
}
func (c *Client) NewDescribeRequest(sdp string) *DescribeRequest {
req := c.NewRequest("DESCRIBE").Describe()
req.SetSdp(sdp)
return req
}
func (c *Client) NewAnnounceRequest() *AnnounceRequest {
req := c.NewRequest("ANNOUNCE").Announce()
return req
}
func (c *Client) NewSetupRequest(trackId int, transport *Transport) *SetupRequest {
req := c.NewRequest("SETUP").Setup()
req.SetTransport(transport)
return req
}
func (c *Client) NewPlayRequest() *PlayRequest {
req := c.NewRequest("PLAY").Play()
return req
}
func (c *Client) NewPauseRequest() *PauseRequest {
req := c.NewRequest("PAUSE").Pause()
return req
}
func (c *Client) NewTeardownRequest() *TeardownRequest {
req := c.NewRequest("TEARDOWN").Teardown()
return req
}
func (c *Client) NewGetParameterRequest() *GetParameterRequest {
req := c.NewRequest("GET_PARAMETER").GetParameter()
return req
}
func (c *Client) NewSetParameterRequest() *SetParameterRequest {
req := c.NewRequest("SET_PARAMETER").SetParameter()
return req
}
func (c *Client) NewRecordRequest() *RecordRequest {
req := c.NewRequest("RECORD").Record()
return req
}