Skip to content

Commit

Permalink
server: use relative control attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Sep 15, 2024
1 parent c682ff5 commit 987da37
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 169 deletions.
2 changes: 1 addition & 1 deletion client_media.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (cm *clientMedia) allocateUDPListeners(
}

var err error
cm.udpRTPListener, cm.udpRTCPListener, err = clientAllocateUDPListenerPair(cm.c)
cm.udpRTPListener, cm.udpRTCPListener, err = allocateUDPListenerPair(cm.c)
return err
}

Expand Down
6 changes: 5 additions & 1 deletion client_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func TestClientRecordSerial(t *testing.T) {
err = desc.Unmarshal(req.Body)
require.NoError(t, err2)

var desc2 description.Session
err = desc2.Unmarshal(&desc)
require.NoError(t, err2)

err2 = conn.WriteResponse(&base.Response{
StatusCode: base.StatusOK,
})
Expand All @@ -194,7 +198,7 @@ func TestClientRecordSerial(t *testing.T) {
require.NoError(t, err2)
require.Equal(t, base.Setup, req.Method)
require.Equal(t, mustParseURL(
scheme+"://localhost:8554/teststream/"+relativeControlAttribute(desc.MediaDescriptions[0])), req.URL)
scheme+"://localhost:8554/teststream/"+desc2.Medias[0].Control), req.URL)

var inTH headers.Transport
err2 = inTH.Unmarshal(req.Header["Transport"])
Expand Down
2 changes: 1 addition & 1 deletion client_udp_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func randInRange(max int) (int, error) {
return int(n.Int64()), nil
}

func clientAllocateUDPListenerPair(c *Client) (*clientUDPListener, *clientUDPListener, error) {
func allocateUDPListenerPair(c *Client) (*clientUDPListener, *clientUDPListener, error) {
// choose two consecutive ports in range 65535-10000
// RTP port must be even and RTCP port odd
for {
Expand Down
2 changes: 2 additions & 0 deletions pkg/base/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
)

// PathSplitQuery splits a path from a query.
//
// Deprecated: not useful anymore.
func PathSplitQuery(pathAndQuery string) (string, string) {
i := strings.Index(pathAndQuery, "?")
if i >= 0 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/base/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (u *URL) CloneWithoutCredentials() *URL {
}

// RTSPPathAndQuery returns the path and query of a RTSP URL.
//
// Deprecated: not useful anymore.
func (u *URL) RTSPPathAndQuery() (string, bool) {
var pathAndQuery string
if u.RawPath != "" {
Expand Down
25 changes: 5 additions & 20 deletions server_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func getSessionID(header base.Header) string {
return ""
}

func serverSideDescription(d *description.Session, contentBase *base.URL) *description.Session {
func serverSideDescription(d *description.Session) *description.Session {
out := &description.Session{
Title: d.Title,
FECGroups: d.FECGroups,
Medias: make([]*description.Media, len(d.Medias)),
}

for i, medi := range d.Medias {
mc := &description.Media{
out.Medias[i] = &description.Media{
Type: medi.Type,
ID: medi.ID,
IsBackChannel: medi.IsBackChannel,
Expand All @@ -41,15 +41,6 @@ func serverSideDescription(d *description.Session, contentBase *base.URL) *descr
Control: "trackID=" + strconv.FormatInt(int64(i), 10),
Formats: medi.Formats,
}

// always use the absolute URL of the track as control attribute, in order
// to fix compatibility between GStreamer and URLs with queries.
// (when a relative control is used, GStreamer puts it between path and query,
// instead of appending it to the URL).
u, _ := mc.URL(contentBase)
mc.Control = u.String()

out.Medias[i] = mc
}

return out
Expand Down Expand Up @@ -215,16 +206,10 @@ func (sc *ServerConn) handleRequestInner(req *base.Request) (*base.Response, err

var path string
var query string

switch req.Method {
case base.Describe, base.GetParameter, base.SetParameter:
pathAndQuery, ok := req.URL.RTSPPathAndQuery()
if !ok {
return &base.Response{
StatusCode: base.StatusBadRequest,
}, liberrors.ErrServerInvalidPath{}
}

path, query = base.PathSplitQuery(pathAndQuery)
path, query = getPathAndQuery(req.URL, false)
}

switch req.Method {
Expand Down Expand Up @@ -295,7 +280,7 @@ func (sc *ServerConn) handleRequestInner(req *base.Request) (*base.Response, err
}

if stream != nil {
byts, _ := serverSideDescription(stream.desc, req.URL).Marshal(multicast)
byts, _ := serverSideDescription(stream.desc).Marshal(multicast)
res.Body = byts
}
}
Expand Down
2 changes: 1 addition & 1 deletion server_multicast_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (h *serverMulticastWriter) initialize() error {
return err
}

rtpl, rtcpl, err := serverAllocateUDPListenerMulticastPair(
rtpl, rtcpl, err := allocateUDPListenerMulticastPair(
h.s.ListenPacket,
h.s.WriteTimeout,
h.s.MulticastRTPPort,
Expand Down
Loading

0 comments on commit 987da37

Please sign in to comment.