From 608f149fd4938f63069d9112d866c53e55194f9e Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Fri, 25 Aug 2023 18:33:44 +0200 Subject: [PATCH] re-enable consistency checks on clock rate of tracks (#382) --- pkg/formats/format_test.go | 13 ------------- pkg/formats/generic.go | 30 ++++++++++++++---------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/pkg/formats/format_test.go b/pkg/formats/format_test.go index f6259d13..04aecb8e 100644 --- a/pkg/formats/format_test.go +++ b/pkg/formats/format_test.go @@ -890,19 +890,6 @@ var casesFormat = []struct { "custom", nil, }, - { - "application invalid rtpmap 2", - "application", - 98, - "custom/aaa", - nil, - &Generic{ - PayloadTyp: 98, - RTPMa: "custom/aaa", - }, - "custom/aaa", - nil, - }, } func TestUnmarshal(t *testing.T) { diff --git a/pkg/formats/generic.go b/pkg/formats/generic.go index 2f8bb48a..0173fd36 100644 --- a/pkg/formats/generic.go +++ b/pkg/formats/generic.go @@ -1,7 +1,6 @@ package formats import ( - "fmt" "strconv" "strings" @@ -34,21 +33,19 @@ func findClockRate(payloadType uint8, rtpMap string) (int, error) { // get clock rate from rtpmap // https://tools.ietf.org/html/rfc4566 // a=rtpmap: / [/] - if rtpMap == "" { - return 0, fmt.Errorf("attribute 'rtpmap' not found") + if rtpMap != "" { + if tmp := strings.Split(rtpMap, "/"); len(tmp) >= 2 { + v, err := strconv.ParseUint(tmp[1], 10, 31) + if err != nil { + return 0, err + } + return int(v), nil + } } - tmp := strings.Split(rtpMap, "/") - if len(tmp) != 2 && len(tmp) != 3 { - return 0, fmt.Errorf("invalid rtpmap (%v)", rtpMap) - } - - v, err := strconv.ParseUint(tmp[1], 10, 31) - if err != nil { - return 0, err - } - - return int(v), nil + // no clock rate was found. + // do not throw an error, but return zero, that disables RTCP sender and receiver reports. + return 0, nil } // Generic is a generic RTP format. @@ -63,8 +60,9 @@ type Generic struct { // Init computes the clock rate of the format. It is mandatory to call it. func (f *Generic) Init() error { - f.ClockRat, _ = findClockRate(f.PayloadTyp, f.RTPMa) - return nil + var err error + f.ClockRat, err = findClockRate(f.PayloadTyp, f.RTPMa) + return err } func (f *Generic) unmarshal(payloadType uint8, _ string, _ string, rtpmap string, fmtp map[string]string) error {