From 88e1244e9f59c50685b47f1f1107ee1f56e304c3 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Tue, 1 Feb 2022 19:43:59 +0100 Subject: [PATCH] improve coverage --- track_generic.go | 1 + track_generic_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/track_generic.go b/track_generic.go index 97c3d560..781f7716 100644 --- a/track_generic.go +++ b/track_generic.go @@ -16,6 +16,7 @@ func trackGenericGetClockRate(md *psdp.MediaDescription) (int, error) { } // get clock rate from payload type + // https://en.wikipedia.org/wiki/RTP_payload_formats switch md.MediaName.Formats[0] { case "0", "1", "2", "3", "4", "5", "7", "8", "9", "12", "13", "15", "18": return 8000, nil diff --git a/track_generic_test.go b/track_generic_test.go index eb33aaab..fd699e0e 100644 --- a/track_generic_test.go +++ b/track_generic_test.go @@ -82,3 +82,73 @@ func TestTrackGenericNewFromMediaDescription(t *testing.T) { }) } } + +func TestTrackGenericNewFromMediaDescriptionErrors(t *testing.T) { + for _, ca := range []struct { + name string + md *psdp.MediaDescription + err string + }{ + { + "no formats", + &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "audio", + Protos: []string{"RTP", "AVP"}, + Formats: []string{}, + }, + }, + "unable to get clock rate: no formats provided", + }, + { + "no rtpmap", + &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "video", + Protos: []string{"RTP", "AVP"}, + Formats: []string{"90"}, + }, + }, + "unable to get clock rate: attribute 'rtpmap' not found", + }, + { + "invalid rtpmap 1", + &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "video", + Protos: []string{"RTP", "AVP"}, + Formats: []string{"96"}, + }, + Attributes: []psdp.Attribute{ + { + Key: "rtpmap", + Value: "96", + }, + }, + }, + "unable to get clock rate: invalid rtpmap (96)", + }, + { + "invalid rtpmap 2", + &psdp.MediaDescription{ + MediaName: psdp.MediaName{ + Media: "video", + Protos: []string{"RTP", "AVP"}, + Formats: []string{"96"}, + }, + Attributes: []psdp.Attribute{ + { + Key: "rtpmap", + Value: "96 mpeg4-generic", + }, + }, + }, + "unable to get clock rate: invalid rtpmap (96 mpeg4-generic)", + }, + } { + t.Run(ca.name, func(t *testing.T) { + _, err := newTrackGenericFromMediaDescription(ca.md) + require.EqualError(t, err, ca.err) + }) + } +}