Skip to content

server: fix compatibility with rtspclientsink and query parameters (bluenviron/mediamtx#3295) #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 39 additions & 22 deletions server_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,45 @@
return path, query, trackID, nil
}

func recordBaseURL(u *base.URL, path string, query string) *base.URL {
baseURL := &base.URL{
Scheme: u.Scheme,
Host: u.Host,
Path: path,
RawQuery: query,
}

if baseURL.RawQuery != "" {
baseURL.RawQuery += "/"
} else {
baseURL.Path += "/"
}

return baseURL
}

func findMediaByURL(medias []*description.Media, baseURL *base.URL, u *base.URL) *description.Media {
func findMediaByURL(
medias []*description.Media,
path string,
query string,
u *base.URL,
) *description.Media {
for _, media := range medias {
u1, err := media.URL(baseURL)
if err == nil && u1.String() == u.String() {
return media
if strings.HasPrefix(media.Control, "rtsp://") ||
strings.HasPrefix(media.Control, "rtsps://") {
if media.Control == u.String() {
return media
}

Check warning on line 70 in server_session.go

View check run for this annotation

Codecov / codecov/patch

server_session.go#L68-L70

Added lines #L68 - L70 were not covered by tests
} else {
// FFmpeg format
u1 := &base.URL{
Scheme: u.Scheme,
Host: u.Host,
Path: path,
RawQuery: query,
}
if query != "" {
u1.RawQuery += "/" + media.Control
} else {
u1.Path += "/" + media.Control
}
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
}
}
}

Expand Down Expand Up @@ -775,7 +792,7 @@
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 {
Expand Down
Loading