add pause play
This commit is contained in:
parent
f315cc0c5e
commit
64bb2d145a
@ -46,6 +46,7 @@ const (
|
|||||||
DESCRIBE = "DESCRIBE"
|
DESCRIBE = "DESCRIBE"
|
||||||
OPTIONS = "OPTIONS"
|
OPTIONS = "OPTIONS"
|
||||||
PLAY = "PLAY"
|
PLAY = "PLAY"
|
||||||
|
PAUSE = "PAUSE"
|
||||||
SETUP = "SETUP"
|
SETUP = "SETUP"
|
||||||
TEARDOWN = "TEARDOWN"
|
TEARDOWN = "TEARDOWN"
|
||||||
)
|
)
|
||||||
@ -271,7 +272,7 @@ func (client *RTSPClient) startStream() {
|
|||||||
client.Println("RTSP Client RTP SetDeadline", err)
|
client.Println("RTSP Client RTP SetDeadline", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if int(time.Now().Sub(timer).Seconds()) > 25 {
|
if int(time.Since(timer).Seconds()) > 25 {
|
||||||
err := client.request(OPTIONS, map[string]string{"Require": "implicit-play"}, client.control, false, true)
|
err := client.request(OPTIONS, map[string]string{"Require": "implicit-play"}, client.control, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Println("RTSP Client RTP keep-alive", err)
|
client.Println("RTSP Client RTP keep-alive", err)
|
||||||
@ -335,7 +336,7 @@ func (client *RTSPClient) startStream() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
responseTmp = append(responseTmp, oneb...)
|
responseTmp = append(responseTmp, oneb...)
|
||||||
if (len(responseTmp) > 4 && bytes.Compare(responseTmp[len(responseTmp)-4:], []byte("\r\n\r\n")) == 0) || len(responseTmp) > 768 {
|
if (len(responseTmp) > 4 && bytes.Equal(responseTmp[len(responseTmp)-4:], []byte("\r\n\r\n"))) || len(responseTmp) > 768 {
|
||||||
if strings.Contains(string(responseTmp), "Content-Length:") {
|
if strings.Contains(string(responseTmp), "Content-Length:") {
|
||||||
si, err := strconv.Atoi(stringInBetween(string(responseTmp), "Content-Length: ", "\r\n"))
|
si, err := strconv.Atoi(stringInBetween(string(responseTmp), "Content-Length: ", "\r\n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -371,15 +372,13 @@ func (client *RTSPClient) request(method string, customHeaders map[string]string
|
|||||||
if client.clientDigest {
|
if client.clientDigest {
|
||||||
builder.WriteString(fmt.Sprintf("Authorization: %s\r\n", client.createDigest(method, uri)))
|
builder.WriteString(fmt.Sprintf("Authorization: %s\r\n", client.createDigest(method, uri)))
|
||||||
}
|
}
|
||||||
if customHeaders != nil {
|
for k, v := range customHeaders {
|
||||||
for k, v := range customHeaders {
|
builder.WriteString(fmt.Sprintf("%s: %s\r\n", k, v))
|
||||||
builder.WriteString(fmt.Sprintf("%s: %s\r\n", k, v))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for k, v := range client.headers {
|
for k, v := range client.headers {
|
||||||
builder.WriteString(fmt.Sprintf("%s: %s\r\n", k, v))
|
builder.WriteString(fmt.Sprintf("%s: %s\r\n", k, v))
|
||||||
}
|
}
|
||||||
builder.WriteString(fmt.Sprintf("\r\n"))
|
builder.WriteString("\r\n")
|
||||||
client.Println(builder.String())
|
client.Println(builder.String())
|
||||||
s := builder.String()
|
s := builder.String()
|
||||||
_, err = client.connRW.WriteString(s)
|
_, err = client.connRW.WriteString(s)
|
||||||
@ -505,6 +504,14 @@ func (client *RTSPClient) request(method string, customHeaders map[string]string
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *RTSPClient) Pause() error {
|
||||||
|
return client.request(PAUSE, nil, client.pURL.String(), false, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (client *RTSPClient) Play(customHeaders map[string]string) error {
|
||||||
|
return client.request(PLAY, customHeaders, client.pURL.String(), false, true)
|
||||||
|
}
|
||||||
|
|
||||||
func (client *RTSPClient) Close() {
|
func (client *RTSPClient) Close() {
|
||||||
if client.conn != nil {
|
if client.conn != nil {
|
||||||
client.conn.SetDeadline(time.Now().Add(time.Second))
|
client.conn.SetDeadline(time.Now().Add(time.Second))
|
||||||
@ -561,7 +568,7 @@ func (client *RTSPClient) CodecUpdateSPS(val []byte) {
|
|||||||
if client.videoCodec != av.H264 && client.videoCodec != av.H265 {
|
if client.videoCodec != av.H264 && client.videoCodec != av.H265 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Compare(val, client.sps) == 0 {
|
if bytes.Equal(val, client.sps) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.sps = val
|
client.sps = val
|
||||||
@ -601,7 +608,7 @@ func (client *RTSPClient) CodecUpdatePPS(val []byte) {
|
|||||||
if client.videoCodec != av.H264 && client.videoCodec != av.H265 {
|
if client.videoCodec != av.H264 && client.videoCodec != av.H265 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Compare(val, client.pps) == 0 {
|
if bytes.Equal(val, client.pps) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.pps = val
|
client.pps = val
|
||||||
@ -641,7 +648,7 @@ func (client *RTSPClient) CodecUpdateVPS(val []byte) {
|
|||||||
if client.videoCodec != av.H265 {
|
if client.videoCodec != av.H265 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bytes.Compare(val, client.vps) == 0 {
|
if bytes.Equal(val, client.vps) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
client.vps = val
|
client.vps = val
|
||||||
|
Loading…
Reference in New Issue
Block a user