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",
|
||||
"rtsp://localhost:8554/test/stream?testing=0",
|
||||
"rtsp://localhost:8554/test/stream?testing=0/fff=ggg",
|
||||
"/test/stream",
|
||||
"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",
|
||||
"streamid=1",
|
||||
|
@@ -56,29 +56,46 @@ func serverParseURLForPlay(u *base.URL) (string, string, string, error) {
|
||||
return path, query, trackID, nil
|
||||
}
|
||||
|
||||
func recordBaseURL(u *base.URL, path string, query string) *base.URL {
|
||||
baseURL := &base.URL{
|
||||
func findMediaByURL(
|
||||
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,
|
||||
Host: u.Host,
|
||||
Path: path,
|
||||
RawQuery: query,
|
||||
}
|
||||
|
||||
if baseURL.RawQuery != "" {
|
||||
baseURL.RawQuery += "/"
|
||||
if query != "" {
|
||||
u1.RawQuery += "/" + media.Control
|
||||
} else {
|
||||
baseURL.Path += "/"
|
||||
u1.Path += "/" + media.Control
|
||||
}
|
||||
|
||||
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() {
|
||||
if u1.String() == u.String() {
|
||||
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
|
||||
@@ -775,7 +792,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
||||
case ServerSessionStateInitial, ServerSessionStatePrePlay: // play
|
||||
medi = findMediaByTrackID(stream.desc.Medias, trackID)
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user