mirror of
https://github.com/aler9/gortsplib
synced 2025-10-07 16:10:59 +08:00
server: fix compatibility with rtspclientsink and query parameters (bluenviron/mediamtx#3295) (#619)
This commit is contained in:
@@ -298,13 +298,21 @@ func TestServerRecordPath(t *testing.T) {
|
|||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subpath and query",
|
"subpath and query, ffmpeg format",
|
||||||
"fff=ggg",
|
"fff=ggg",
|
||||||
"rtsp://localhost:8554/test/stream?testing=0",
|
"rtsp://localhost:8554/test/stream?testing=0",
|
||||||
"rtsp://localhost:8554/test/stream?testing=0/fff=ggg",
|
"rtsp://localhost:8554/test/stream?testing=0/fff=ggg",
|
||||||
"/test/stream",
|
"/test/stream",
|
||||||
"testing=0",
|
"testing=0",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"subpath and query, gstreamer format",
|
||||||
|
"fff=ggg",
|
||||||
|
"rtsp://localhost:8554/test/stream?testing=0",
|
||||||
|
"rtsp://localhost:8554/test/stream/fff=ggg?testing=0",
|
||||||
|
"/test/stream",
|
||||||
|
"testing=0",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"no path",
|
"no path",
|
||||||
"streamid=1",
|
"streamid=1",
|
||||||
|
@@ -56,29 +56,46 @@ func serverParseURLForPlay(u *base.URL) (string, string, string, error) {
|
|||||||
return path, query, trackID, nil
|
return path, query, trackID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordBaseURL(u *base.URL, path string, query string) *base.URL {
|
func findMediaByURL(
|
||||||
baseURL := &base.URL{
|
medias []*description.Media,
|
||||||
|
path string,
|
||||||
|
query string,
|
||||||
|
u *base.URL,
|
||||||
|
) *description.Media {
|
||||||
|
for _, media := range medias {
|
||||||
|
if strings.HasPrefix(media.Control, "rtsp://") ||
|
||||||
|
strings.HasPrefix(media.Control, "rtsps://") {
|
||||||
|
if media.Control == u.String() {
|
||||||
|
return media
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// FFmpeg format
|
||||||
|
u1 := &base.URL{
|
||||||
Scheme: u.Scheme,
|
Scheme: u.Scheme,
|
||||||
Host: u.Host,
|
Host: u.Host,
|
||||||
Path: path,
|
Path: path,
|
||||||
RawQuery: query,
|
RawQuery: query,
|
||||||
}
|
}
|
||||||
|
if query != "" {
|
||||||
if baseURL.RawQuery != "" {
|
u1.RawQuery += "/" + media.Control
|
||||||
baseURL.RawQuery += "/"
|
|
||||||
} else {
|
} else {
|
||||||
baseURL.Path += "/"
|
u1.Path += "/" + media.Control
|
||||||
}
|
}
|
||||||
|
if u1.String() == u.String() {
|
||||||
return baseURL
|
|
||||||
}
|
|
||||||
|
|
||||||
func findMediaByURL(medias []*description.Media, baseURL *base.URL, u *base.URL) *description.Media {
|
|
||||||
for _, media := range medias {
|
|
||||||
u1, err := media.URL(baseURL)
|
|
||||||
if err == nil && u1.String() == u.String() {
|
|
||||||
return media
|
return media
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GStreamer format
|
||||||
|
u2 := &base.URL{
|
||||||
|
Scheme: u.Scheme,
|
||||||
|
Host: u.Host,
|
||||||
|
Path: path + "/" + media.Control,
|
||||||
|
RawQuery: query,
|
||||||
|
}
|
||||||
|
if u2.String() == u.String() {
|
||||||
|
return media
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -775,7 +792,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
case ServerSessionStateInitial, ServerSessionStatePrePlay: // play
|
case ServerSessionStateInitial, ServerSessionStatePrePlay: // play
|
||||||
medi = findMediaByTrackID(stream.desc.Medias, trackID)
|
medi = findMediaByTrackID(stream.desc.Medias, trackID)
|
||||||
default: // record
|
default: // record
|
||||||
medi = findMediaByURL(ss.announcedDesc.Medias, recordBaseURL(req.URL, path, query), req.URL)
|
medi = findMediaByURL(ss.announcedDesc.Medias, path, query, req.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if medi == nil {
|
if medi == nil {
|
||||||
|
Reference in New Issue
Block a user