1 Star 1 Fork 0

raininfall/RTSP

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
response_test.go 4.03 KB
一键复制 编辑 原始数据 按行查看 历史
Songrq 提交于 2019-08-23 04:10 . v0.0.1
package rtsp_test
import (
"bufio"
"bytes"
"testing"
"gitee.com/raininfall/rtsp"
"github.com/stretchr/testify/assert"
)
func TestReadResponseCommon(t *testing.T) {
assert := assert.New(t)
type Case struct {
input string
output rtsp.Response
}
cases := []Case{{
"RTSP/1.0 401 Unauthorized\r\n" +
"CSeq: 2\r\n" +
`WWW-Authenticate: Digest realm="Login to 4E05209PAG7F31D", nonce="84eb201f4b604187875aa575c6c99234"` + "\r\n" +
"\r\n",
rtsp.Response{
ProtoMajor: 1,
ProtoMinor: 0,
StatusCode: rtsp.StatusUnauthorized,
CSeq: 2,
Header: map[string][]string{
"CSeq": []string{"2"},
"WWW-Authenticate": []string{`Digest realm="Login to 4E05209PAG7F31D", nonce="84eb201f4b604187875aa575c6c99234"`},
},
}}, {
"RTSP/1.0 200 OK\r\n" +
"CSeq: 3\r\n" +
"Public: OPTIONS, DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, TEARDOWN, SET_PARAMETER, GET_PARAMETER\r\n" +
"Server: Rtsp Server/3.0\r\n" +
"\r\n",
rtsp.Response{
ProtoMajor: 1,
ProtoMinor: 0,
StatusCode: rtsp.StatusOK,
CSeq: 3,
Header: map[string][]string{
"CSeq": []string{"3"},
"Server": []string{"Rtsp Server/3.0"},
"Public": []string{"OPTIONS, DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, TEARDOWN, SET_PARAMETER, GET_PARAMETER"},
},
}}, {
"RTSP/1.0 200 OK\r\n" +
"CSeq: 4\r\n" +
"Cache-Control: must-revalidate\r\n" +
"Content-Base: rtsp://30.26.53.93:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif/\r\n" +
"Content-Length: 599\r\n" +
"Content-Type: application/sdp\r\n" +
"X-Accept-Dynamic-Rate: 1\r\n" +
"\r\n" +
"v=0\r\n" +
"o=- 2263020117 2263020117 IN IP4 0.0.0.0\r\n" +
"s=Media Server\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"t=0 0\r\n" +
"a=control:*\r\n" +
"a=packetization-supported:DH\r\n" +
"a=rtppayload-supported:DH\r\n" +
"a=range:npt=now-\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=control:trackID=0\r\n" +
"a=framerate:25.000000\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=fmtp:96 packetization-mode=1;profile-level-id=64002A;sprop-parameter-sets=Z2QAKq2EAQwgCGEAQwgCGEAQwgCEO1A8ARPyzcBAQFAAAD6AAAw1CEAA,aO48sAA=\r\n" +
"a=recvonly\r\n" +
"m=audio 0 RTP/AVP 8\r\n" +
"a=control:trackID=1\r\n" +
"a=rtpmap:8 PCMA/16000\r\n" +
"a=recvonly\r\n" +
"m=application 0 RTP/AVP 107\r\n" +
"a=control:trackID=4\r\n" +
"a=rtpmap:107 vnd.onvif.metadata/90000\r\n" +
"a=recvonly\r\n",
rtsp.Response{
ProtoMajor: 1,
ProtoMinor: 0,
StatusCode: rtsp.StatusOK,
CSeq: 4,
Header: map[string][]string{
"CSeq": []string{"4"},
"X-Accept-Dynamic-Rate": []string{"1"},
"Content-Base": []string{"rtsp://30.26.53.93:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif/"},
"Cache-Control": []string{"must-revalidate"},
"Content-Length": []string{"599"},
"Content-Type": []string{"application/sdp"},
},
Body: []byte(
"v=0\r\n" +
"o=- 2263020117 2263020117 IN IP4 0.0.0.0\r\n" +
"s=Media Server\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"t=0 0\r\n" +
"a=control:*\r\n" +
"a=packetization-supported:DH\r\n" +
"a=rtppayload-supported:DH\r\n" +
"a=range:npt=now-\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=control:trackID=0\r\n" +
"a=framerate:25.000000\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=fmtp:96 packetization-mode=1;profile-level-id=64002A;sprop-parameter-sets=Z2QAKq2EAQwgCGEAQwgCGEAQwgCEO1A8ARPyzcBAQFAAAD6AAAw1CEAA,aO48sAA=\r\n" +
"a=recvonly\r\n" +
"m=audio 0 RTP/AVP 8\r\n" +
"a=control:trackID=1\r\n" +
"a=rtpmap:8 PCMA/16000\r\n" +
"a=recvonly\r\n" +
"m=application 0 RTP/AVP 107\r\n" +
"a=control:trackID=4\r\n" +
"a=rtpmap:107 vnd.onvif.metadata/90000\r\n" +
"a=recvonly\r\n"),
},
}}
for _, c := range cases {
reader := bufio.NewReader(bytes.NewReader([]byte(c.input)))
response, err := rtsp.ReadResponse(reader)
assert.Nil(err)
assert.Equal(&c.output, response)
assert.Equal(c.input, string(response.Bytes()))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/raininfall/rtsp.git
git@gitee.com:raininfall/rtsp.git
raininfall
rtsp
RTSP
master

搜索帮助