mirror of https://github.com/EasyDarwin/EasyDarwin
parent
1516f1dfe1
commit
31a0b346b0
|
@ -380,42 +380,60 @@ func (session *Session) handleRequest(req *Request) {
|
||||||
// a=control:streamid=1
|
// a=control:streamid=1
|
||||||
// 例2:
|
// 例2:
|
||||||
// a=control:rtsp://192.168.1.64/trackID=1
|
// a=control:rtsp://192.168.1.64/trackID=1
|
||||||
|
// 例3:
|
||||||
|
// a=control:?ctype=video
|
||||||
setupUrl, err := url.Parse(req.URL)
|
setupUrl, err := url.Parse(req.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.StatusCode = 500
|
res.StatusCode = 500
|
||||||
res.Status = "Invalid URL"
|
res.Status = "Invalid URL"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setupPath := setupUrl.Path
|
if setupUrl.Port() == "" {
|
||||||
setupPath = setupPath[strings.LastIndex(setupPath, "/")+1:]
|
setupUrl.Host = fmt.Sprintf("%s:554", setupUrl.Host)
|
||||||
|
|
||||||
vURL, err := url.Parse(session.VControl)
|
|
||||||
if err != nil {
|
|
||||||
res.StatusCode = 500
|
|
||||||
res.Status = "Invalid VControl"
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
vPath := vURL.Path
|
setupPath := setupUrl.String()
|
||||||
vPath = vPath[strings.LastIndex(vPath, "/")+1:]
|
//setupPath = setupPath[strings.LastIndex(setupPath, "/")+1:]
|
||||||
|
vPath := ""
|
||||||
aURL, err := url.Parse(session.AControl)
|
if strings.Index(strings.ToLower(session.VControl), "rtsp://") == 0 {
|
||||||
if err != nil {
|
vControlUrl, err := url.Parse(req.URL)
|
||||||
res.StatusCode = 500
|
if err != nil {
|
||||||
res.Status = "Invalid AControl"
|
res.StatusCode = 500
|
||||||
return
|
res.Status = "Invalid VControl"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if vControlUrl.Port() == "" {
|
||||||
|
vControlUrl.Host = fmt.Sprintf("%s:554", vControlUrl.Host)
|
||||||
|
}
|
||||||
|
vPath = vControlUrl.String()
|
||||||
|
} else {
|
||||||
|
vPath = session.VControl
|
||||||
|
}
|
||||||
|
|
||||||
|
aPath := ""
|
||||||
|
if strings.Index(strings.ToLower(session.AControl), "rtsp://") == 0 {
|
||||||
|
aControlUrl, err := url.Parse(req.URL)
|
||||||
|
if err != nil {
|
||||||
|
res.StatusCode = 500
|
||||||
|
res.Status = "Invalid AControl"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if aControlUrl.Port() == "" {
|
||||||
|
aControlUrl.Host = fmt.Sprintf("%s:554", aControlUrl.Host)
|
||||||
|
}
|
||||||
|
aPath = aControlUrl.String()
|
||||||
|
} else {
|
||||||
|
aPath = session.AControl
|
||||||
}
|
}
|
||||||
aPath := aURL.Path
|
|
||||||
aPath = aPath[strings.LastIndex(aPath, "/")+1:]
|
|
||||||
|
|
||||||
mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?")
|
mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?")
|
||||||
mudp := regexp.MustCompile("client_port=(\\d+)(-(\\d+))?")
|
mudp := regexp.MustCompile("client_port=(\\d+)(-(\\d+))?")
|
||||||
|
|
||||||
if tcpMatchs := mtcp.FindStringSubmatch(ts); tcpMatchs != nil {
|
if tcpMatchs := mtcp.FindStringSubmatch(ts); tcpMatchs != nil {
|
||||||
session.TransType = TRANS_TYPE_TCP
|
session.TransType = TRANS_TYPE_TCP
|
||||||
if setupPath == aPath {
|
if setupPath == aPath || strings.LastIndex(setupPath, aPath) == len(setupPath)-len(aPath) {
|
||||||
session.aRTPChannel, _ = strconv.Atoi(tcpMatchs[1])
|
session.aRTPChannel, _ = strconv.Atoi(tcpMatchs[1])
|
||||||
session.aRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3])
|
session.aRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3])
|
||||||
} else if setupPath == vPath {
|
} else if setupPath == vPath || strings.LastIndex(setupPath, vPath) == len(setupPath)-len(vPath) {
|
||||||
session.vRTPChannel, _ = strconv.Atoi(tcpMatchs[1])
|
session.vRTPChannel, _ = strconv.Atoi(tcpMatchs[1])
|
||||||
session.vRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3])
|
session.vRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3])
|
||||||
}
|
}
|
||||||
|
@ -435,7 +453,7 @@ func (session *Session) handleRequest(req *Request) {
|
||||||
Session: session,
|
Session: session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if setupPath == aPath {
|
if setupPath == aPath || strings.LastIndex(setupPath, aPath) == len(setupPath)-len(aPath) {
|
||||||
session.UDPClient.APort, _ = strconv.Atoi(udpMatchs[1])
|
session.UDPClient.APort, _ = strconv.Atoi(udpMatchs[1])
|
||||||
session.UDPClient.AControlPort, _ = strconv.Atoi(udpMatchs[3])
|
session.UDPClient.AControlPort, _ = strconv.Atoi(udpMatchs[3])
|
||||||
if err := session.UDPClient.SetupAudio(); err != nil {
|
if err := session.UDPClient.SetupAudio(); err != nil {
|
||||||
|
@ -462,7 +480,7 @@ func (session *Session) handleRequest(req *Request) {
|
||||||
tss = append(tss, tail...)
|
tss = append(tss, tail...)
|
||||||
ts = strings.Join(tss, ";")
|
ts = strings.Join(tss, ";")
|
||||||
}
|
}
|
||||||
} else if setupPath == vPath {
|
} else if setupPath == vPath || strings.LastIndex(setupPath, vPath) == len(setupPath)-len(vPath) {
|
||||||
session.UDPClient.VPort, _ = strconv.Atoi(udpMatchs[1])
|
session.UDPClient.VPort, _ = strconv.Atoi(udpMatchs[1])
|
||||||
session.UDPClient.VControlPort, _ = strconv.Atoi(udpMatchs[3])
|
session.UDPClient.VControlPort, _ = strconv.Atoi(udpMatchs[3])
|
||||||
if err := session.UDPClient.SetupVideo(); err != nil {
|
if err := session.UDPClient.SetupVideo(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue