diff --git a/go.mod b/go.mod index b359ce5f..49b7750a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bluenviron/gortsplib/v4 go 1.20 require ( - github.com/bluenviron/mediacommon v1.12.1 + github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029 github.com/google/uuid v1.6.0 github.com/pion/rtcp v1.2.14 github.com/pion/rtp v1.8.7-0.20240429002300-bc5124c9d0d0 diff --git a/go.sum b/go.sum index 1ce20701..f547dc24 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c= github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI= -github.com/bluenviron/mediacommon v1.12.1 h1:sgDJaKV6OXrPCSO0KPp9zi/pwNWtKHenn5/dvjtY+Tg= -github.com/bluenviron/mediacommon v1.12.1/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec= +github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029 h1:s9PNLf98P0uRiBqvY6qKrO1pssPZVCVhs17aSNfXuLY= +github.com/bluenviron/mediacommon v1.12.2-0.20240801134301-b013c7a52029/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/pkg/auth/sender_test.go b/pkg/auth/sender_test.go index 70299e26..b04d5e8b 100644 --- a/pkg/auth/sender_test.go +++ b/pkg/auth/sender_test.go @@ -104,6 +104,12 @@ func FuzzSender(f *testing.F) { } f.Fuzz(func(_ *testing.T, a string) { - NewSender(base.HeaderValue{a}, "myuser", "mypass") //nolint:errcheck + se, err := NewSender(base.HeaderValue{a}, "myuser", "mypass") + if err == nil { + se.AddAuthorization(&base.Request{ + Method: base.Setup, + URL: mustParseURL("rtsp://myhost/mypath?key=val/trackID=3"), + }) + } }) } diff --git a/pkg/base/body_test.go b/pkg/base/body_test.go index 284fb5df..8446c5ab 100644 --- a/pkg/base/body_test.go +++ b/pkg/base/body_test.go @@ -49,10 +49,13 @@ func FuzzBodyUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, a string, b []byte) { var p body - p.unmarshal( //nolint:errcheck + err := p.unmarshal( Header{ "Content-Length": HeaderValue{a}, }, bufio.NewReader(bytes.NewReader(b))) + if err == nil { + p.marshal() + } }) } diff --git a/pkg/base/header_test.go b/pkg/base/header_test.go index af1cf0bf..91844439 100644 --- a/pkg/base/header_test.go +++ b/pkg/base/header_test.go @@ -138,6 +138,9 @@ func FuzzHeaderUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b []byte) { var h Header - h.unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck + err := h.unmarshal(bufio.NewReader(bytes.NewBuffer(b))) + if err == nil { + h.marshal() + } }) } diff --git a/pkg/base/interleaved_frame_test.go b/pkg/base/interleaved_frame_test.go index 41b5b862..61a4abef 100644 --- a/pkg/base/interleaved_frame_test.go +++ b/pkg/base/interleaved_frame_test.go @@ -60,6 +60,9 @@ func FuzzInterleavedFrameUnmarshal(f *testing.F) { } f.Fuzz(func(_ *testing.T, b []byte) { var f InterleavedFrame - f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck + err := f.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) + if err == nil { + f.Marshal() //nolint:errcheck + } }) } diff --git a/pkg/base/request_test.go b/pkg/base/request_test.go index 4d57a539..ea96e17d 100644 --- a/pkg/base/request_test.go +++ b/pkg/base/request_test.go @@ -188,6 +188,9 @@ func FuzzRequestUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b []byte) { var req Request - req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck + err := req.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) + if err == nil { + req.Marshal() //nolint:errcheck + } }) } diff --git a/pkg/base/response_test.go b/pkg/base/response_test.go index c57e4514..5853d836 100644 --- a/pkg/base/response_test.go +++ b/pkg/base/response_test.go @@ -162,6 +162,9 @@ func FuzzResponseUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b []byte) { var res Response - res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) //nolint:errcheck + err := res.Unmarshal(bufio.NewReader(bytes.NewBuffer(b))) + if err == nil { + res.Marshal() //nolint:errcheck + } }) } diff --git a/pkg/description/session_test.go b/pkg/description/session_test.go index 3774ea88..b9cf6b3a 100644 --- a/pkg/description/session_test.go +++ b/pkg/description/session_test.go @@ -837,7 +837,7 @@ func TestSessionFindFormat(t *testing.T) { require.Equal(t, tr, forma) } -func FuzzSessionUnmarshalErrors(f *testing.F) { +func FuzzSessionUnmarshal(f *testing.F) { for _, ca := range casesSession { f.Add(ca.in) } @@ -898,11 +898,9 @@ func FuzzSessionUnmarshalErrors(f *testing.F) { f.Fuzz(func(_ *testing.T, enc string) { var sd sdp.SessionDescription err := sd.Unmarshal([]byte(enc)) - if err != nil { - return + if err == nil { + var desc Session + desc.Unmarshal(&sd) //nolint:errcheck } - - var desc Session - desc.Unmarshal(&sd) //nolint:errcheck }) } diff --git a/pkg/description/testdata/fuzz/FuzzSessionUnmarshalErrors/b0432aab46b15405 b/pkg/description/testdata/fuzz/FuzzSessionUnmarshal/b0432aab46b15405 similarity index 100% rename from pkg/description/testdata/fuzz/FuzzSessionUnmarshalErrors/b0432aab46b15405 rename to pkg/description/testdata/fuzz/FuzzSessionUnmarshal/b0432aab46b15405 diff --git a/pkg/description/testdata/fuzz/FuzzSessionUnmarshalErrors/fb7e5db5b68fa760 b/pkg/description/testdata/fuzz/FuzzSessionUnmarshal/fb7e5db5b68fa760 similarity index 100% rename from pkg/description/testdata/fuzz/FuzzSessionUnmarshalErrors/fb7e5db5b68fa760 rename to pkg/description/testdata/fuzz/FuzzSessionUnmarshal/fb7e5db5b68fa760 diff --git a/pkg/format/av1_test.go b/pkg/format/av1_test.go index dc648bdc..e8e34ef4 100644 --- a/pkg/format/av1_test.go +++ b/pkg/format/av1_test.go @@ -58,6 +58,10 @@ func FuzzUnmarshalAV1(f *testing.F) { ma["tier"] = f } - Unmarshal("video", 96, "AV1/90000", ma) //nolint:errcheck + fo, err := Unmarshal("video", 96, "AV1/90000", ma) + if err == nil { + fo.(*AV1).RTPMap() + fo.(*AV1).FMTP() + } }) } diff --git a/pkg/format/h264_test.go b/pkg/format/h264_test.go index e52c2746..f49f8e67 100644 --- a/pkg/format/h264_test.go +++ b/pkg/format/h264_test.go @@ -80,6 +80,10 @@ func FuzzUnmarshalH264(f *testing.F) { ma["packetization-mode"] = d } - Unmarshal("video", 96, "H264/90000", ma) //nolint:errcheck + fo, err := Unmarshal("video", 96, "H264/90000", ma) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/h265_test.go b/pkg/format/h265_test.go index d00f3409..a4051f0b 100644 --- a/pkg/format/h265_test.go +++ b/pkg/format/h265_test.go @@ -97,6 +97,10 @@ func FuzzUnmarshalH265(f *testing.F) { ma["sprop-max-don-diff"] = d } - Unmarshal("video", 96, "H265/90000", ma) //nolint:errcheck + fo, err := Unmarshal("video", 96, "H265/90000", ma) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/lpcm_test.go b/pkg/format/lpcm_test.go index 4cfa7c70..e2662f56 100644 --- a/pkg/format/lpcm_test.go +++ b/pkg/format/lpcm_test.go @@ -44,6 +44,10 @@ func TestLPCMDecEncoder(t *testing.T) { func FuzzUnmarshalLPCM(f *testing.F) { f.Fuzz(func(_ *testing.T, a string) { - Unmarshal("audio", 96, "L16/"+a, nil) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "L16/"+a, nil) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/mpeg4_audio.go b/pkg/format/mpeg4_audio.go index 90988a34..629d9312 100644 --- a/pkg/format/mpeg4_audio.go +++ b/pkg/format/mpeg4_audio.go @@ -174,6 +174,9 @@ func (f *MPEG4Audio) ClockRate() int { if !f.LATM { return f.Config.SampleRate } + if f.CPresent { + return 16000 + } return f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig.SampleRate } @@ -199,6 +202,10 @@ func (f *MPEG4Audio) RTPMap() string { "/" + strconv.FormatInt(int64(channelCount), 10) } + if f.CPresent { + return "MP4A-LATM/16000/1" + } + aoc := f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig sampleRate := aoc.SampleRate @@ -251,15 +258,8 @@ func (f *MPEG4Audio) FMTP() map[string]string { return fmtp } - enc, err := f.StreamMuxConfig.Marshal() - if err != nil { - return nil - } - fmtp := map[string]string{ "profile-level-id": strconv.FormatInt(int64(f.ProfileLevelID), 10), - "config": hex.EncodeToString(enc), - "object": strconv.FormatInt(int64(f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig.Type), 10), } if f.Bitrate != nil { @@ -270,6 +270,14 @@ func (f *MPEG4Audio) FMTP() map[string]string { fmtp["cpresent"] = "1" } else { fmtp["cpresent"] = "0" + + enc, err := f.StreamMuxConfig.Marshal() + if err != nil { + return nil + } + + fmtp["config"] = hex.EncodeToString(enc) + fmtp["object"] = strconv.FormatInt(int64(f.StreamMuxConfig.Programs[0].Layers[0].AudioSpecificConfig.Type), 10) } if f.SBREnabled != nil { diff --git a/pkg/format/mpeg4_audio_test.go b/pkg/format/mpeg4_audio_test.go index a1976bfe..d6d20d6b 100644 --- a/pkg/format/mpeg4_audio_test.go +++ b/pkg/format/mpeg4_audio_test.go @@ -222,8 +222,10 @@ func FuzzUnmarshalMPEG4AudioLATM(f *testing.F) { ma["sbr-enabled"] = l } - fo, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", ma) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "MP4A-LATM/48000/2", ma) if err == nil { + fo.(*MPEG4Audio).RTPMap() + fo.(*MPEG4Audio).FMTP() fo.(*MPEG4Audio).GetConfig() } }) diff --git a/pkg/format/mpeg4_video_test.go b/pkg/format/mpeg4_video_test.go index 0151111e..083c7ecb 100644 --- a/pkg/format/mpeg4_video_test.go +++ b/pkg/format/mpeg4_video_test.go @@ -56,6 +56,10 @@ func FuzzUnmarshalMPEG4Video(f *testing.F) { ma["config"] = d } - Unmarshal("audio", 96, "MP4V-ES/90000", ma) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "MP4V-ES/90000", ma) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/opus_test.go b/pkg/format/opus_test.go index 0700659a..740fe716 100644 --- a/pkg/format/opus_test.go +++ b/pkg/format/opus_test.go @@ -39,7 +39,11 @@ func FuzzUnmarshalOpus(f *testing.F) { f.Add("48000/a") f.Fuzz(func(_ *testing.T, a string) { - Unmarshal("audio", 96, "Opus/"+a, nil) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "Opus/"+a, nil) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } @@ -47,6 +51,10 @@ func FuzzUnmarshalOpusMulti(f *testing.F) { f.Add("48000/a") f.Fuzz(func(_ *testing.T, a string) { - Unmarshal("audio", 96, "multiopus/"+a, nil) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "multiopus/"+a, nil) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/testdata/fuzz/FuzzUnmarshalMPEG4AudioLATM/f0052bccde74165b b/pkg/format/testdata/fuzz/FuzzUnmarshalMPEG4AudioLATM/f0052bccde74165b new file mode 100644 index 00000000..416d6456 --- /dev/null +++ b/pkg/format/testdata/fuzz/FuzzUnmarshalMPEG4AudioLATM/f0052bccde74165b @@ -0,0 +1,13 @@ +go test fuzz v1 +bool(false) +string("0") +bool(true) +string("0") +bool(true) +string("0") +bool(true) +string("70102010") +bool(true) +string("0") +bool(true) +string("0") diff --git a/pkg/format/vorbis_test.go b/pkg/format/vorbis_test.go index a39af37f..592f1668 100644 --- a/pkg/format/vorbis_test.go +++ b/pkg/format/vorbis_test.go @@ -21,8 +21,12 @@ func TestVorbisAttributes(t *testing.T) { func FuzzUnmarshalVorbis(f *testing.F) { f.Fuzz(func(_ *testing.T, a, b string) { - Unmarshal("audio", 96, "Vorbis/"+a, map[string]string{ //nolint:errcheck + fo, err := Unmarshal("audio", 96, "Vorbis/"+a, map[string]string{ "configuration": b, }) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/vp8_test.go b/pkg/format/vp8_test.go index 54aa1ef6..3219f571 100644 --- a/pkg/format/vp8_test.go +++ b/pkg/format/vp8_test.go @@ -52,6 +52,10 @@ func FuzzUnmarshalVP8(f *testing.F) { ma["max-fs"] = d } - Unmarshal("audio", 96, "VP8/90000", ma) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "VP8/90000", ma) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/format/vp9_test.go b/pkg/format/vp9_test.go index 9ebc21e1..b8cd82ba 100644 --- a/pkg/format/vp9_test.go +++ b/pkg/format/vp9_test.go @@ -58,6 +58,10 @@ func FuzzUnmarshalVP9(f *testing.F) { ma["profile-id"] = f } - Unmarshal("audio", 96, "VP9/90000", ma) //nolint:errcheck + fo, err := Unmarshal("audio", 96, "VP9/90000", ma) + if err == nil { + fo.RTPMap() + fo.FMTP() + } }) } diff --git a/pkg/headers/authenticate_test.go b/pkg/headers/authenticate_test.go index 22041749..010b4cf3 100644 --- a/pkg/headers/authenticate_test.go +++ b/pkg/headers/authenticate_test.go @@ -134,7 +134,10 @@ func FuzzAuthenticateUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b string) { var h Authenticate - h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck + err := h.Unmarshal(base.HeaderValue{b}) + if err == nil { + h.Marshal() + } }) } diff --git a/pkg/headers/authorization_test.go b/pkg/headers/authorization_test.go index 9ba6696e..c4d6ec24 100644 --- a/pkg/headers/authorization_test.go +++ b/pkg/headers/authorization_test.go @@ -130,7 +130,10 @@ func FuzzAuthorizationUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b string) { var h Authorization - h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck + err := h.Unmarshal(base.HeaderValue{b}) + if err == nil { + h.Marshal() + } }) } diff --git a/pkg/headers/range_test.go b/pkg/headers/range_test.go index 96f08374..48460a70 100644 --- a/pkg/headers/range_test.go +++ b/pkg/headers/range_test.go @@ -151,7 +151,10 @@ func FuzzRangeUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b string) { var h Range - h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck + err := h.Unmarshal(base.HeaderValue{b}) + if err == nil { + h.Marshal() + } }) } diff --git a/pkg/headers/rtpinfo_test.go b/pkg/headers/rtpinfo_test.go index d7de73d1..9ce8abb2 100644 --- a/pkg/headers/rtpinfo_test.go +++ b/pkg/headers/rtpinfo_test.go @@ -158,7 +158,10 @@ func FuzzRTPInfoUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b string) { var h RTPInfo - h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck + err := h.Unmarshal(base.HeaderValue{b}) + if err == nil { + h.Marshal() + } }) } diff --git a/pkg/headers/session_test.go b/pkg/headers/session_test.go index 3bc0e46d..bb340f6a 100644 --- a/pkg/headers/session_test.go +++ b/pkg/headers/session_test.go @@ -71,7 +71,10 @@ func FuzzSessionUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b string) { var h Session - h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck + err := h.Unmarshal(base.HeaderValue{b}) + if err == nil { + h.Marshal() + } }) } diff --git a/pkg/headers/transport_test.go b/pkg/headers/transport_test.go index a0cc3705..e12b7fb0 100644 --- a/pkg/headers/transport_test.go +++ b/pkg/headers/transport_test.go @@ -256,7 +256,10 @@ func FuzzTransportsUnmarshal(f *testing.F) { f.Fuzz(func(_ *testing.T, b string) { var h Transports - h.Unmarshal(base.HeaderValue{b}) //nolint:errcheck + err := h.Unmarshal(base.HeaderValue{b}) + if err == nil { + h.Marshal() + } }) } diff --git a/pkg/sdp/sdp_test.go b/pkg/sdp/sdp_test.go index 655f7825..c092294b 100644 --- a/pkg/sdp/sdp_test.go +++ b/pkg/sdp/sdp_test.go @@ -3070,7 +3070,10 @@ func FuzzUnmarshal(f *testing.F) { } f.Fuzz(func(_ *testing.T, b string) { - desc := SessionDescription{} - desc.Unmarshal([]byte(b)) //nolint:errcheck + var desc SessionDescription + err := desc.Unmarshal([]byte(b)) + if err == nil { + desc.Marshal() //nolint:errcheck + } }) }