diff --git a/compound_packet_test.go b/compound_packet_test.go index 2076aaf..13150d3 100644 --- a/compound_packet_test.go +++ b/compound_packet_test.go @@ -54,15 +54,7 @@ func TestBadCompound(t *testing.T) { } func TestValidPacket(t *testing.T) { - cname := &SourceDescription{ - Chunks: []SourceDescriptionChunk{{ - Source: 1234, - Items: []SourceDescriptionItem{{ - Type: SDESCNAME, - Text: "cname", - }}, - }}, - } + cname := NewCNAMESourceDescription(1234, "cname") for _, test := range []struct { Name string @@ -147,15 +139,7 @@ func TestValidPacket(t *testing.T) { } func TestCNAME(t *testing.T) { - cname := &SourceDescription{ - Chunks: []SourceDescriptionChunk{{ - Source: 1234, - Items: []SourceDescriptionItem{{ - Type: SDESCNAME, - Text: "cname", - }}, - }}, - } + cname := NewCNAMESourceDescription(1234, "cname") for _, test := range []struct { Name string @@ -241,15 +225,7 @@ func TestCNAME(t *testing.T) { } func TestCompoundPacketRoundTrip(t *testing.T) { - cname := &SourceDescription{ - Chunks: []SourceDescriptionChunk{{ - Source: 1234, - Items: []SourceDescriptionItem{{ - Type: SDESCNAME, - Text: "cname", - }}, - }}, - } + cname := NewCNAMESourceDescription(1234, "cname") for _, test := range []struct { Name string diff --git a/fuzz.go b/fuzz.go index 2ea4fb1..b811822 100644 --- a/fuzz.go +++ b/fuzz.go @@ -1,3 +1,4 @@ +//go:build gofuzz // +build gofuzz package rtcp diff --git a/packet_stringifier_test.go b/packet_stringifier_test.go index 681023d..3ff17cf 100644 --- a/packet_stringifier_test.go +++ b/packet_stringifier_test.go @@ -294,19 +294,7 @@ func TestPrint(t *testing.T) { "\tProfileExtensions: []\n", }, { - &SourceDescription{ - Chunks: []SourceDescriptionChunk{ - { - Source: 0x902f9e2e, - Items: []SourceDescriptionItem{ - { - Type: SDESCNAME, - Text: "{9c00eb92-1afb-9d49-a47d-91f64eee69f5}", - }, - }, - }, - }, - }, + NewCNAMESourceDescription(0x902f9e2e, "{9c00eb92-1afb-9d49-a47d-91f64eee69f5}"), "rtcp.SourceDescription:\n" + "\tChunks:\n" + "\t\t0:\n" + diff --git a/packet_test.go b/packet_test.go index c497900..6ac48e3 100644 --- a/packet_test.go +++ b/packet_test.go @@ -91,19 +91,7 @@ func TestUnmarshal(t *testing.T) { }}, ProfileExtensions: []byte{}, }, - &SourceDescription{ - Chunks: []SourceDescriptionChunk{ - { - Source: 0x902f9e2e, - Items: []SourceDescriptionItem{ - { - Type: SDESCNAME, - Text: "{9c00eb92-1afb-9d49-a47d-91f64eee69f5}", - }, - }, - }, - }, - }, + NewCNAMESourceDescription(0x902f9e2e, "{9c00eb92-1afb-9d49-a47d-91f64eee69f5}"), &Goodbye{ Sources: []uint32{0x902f9e2e}, }, diff --git a/source_description.go b/source_description.go index d62e57a..597a044 100644 --- a/source_description.go +++ b/source_description.go @@ -61,6 +61,19 @@ type SourceDescription struct { Chunks []SourceDescriptionChunk } +// NewCNAMESourceDescription creates a new SourceDescription with a single CNAME item. +func NewCNAMESourceDescription(ssrc uint32, cname string) *SourceDescription { + return &SourceDescription{ + Chunks: []SourceDescriptionChunk{{ + Source: ssrc, + Items: []SourceDescriptionItem{{ + Type: SDESCNAME, + Text: cname, + }}, + }}, + } +} + // Marshal encodes the SourceDescription in binary func (s SourceDescription) Marshal() ([]byte, error) { /* diff --git a/source_description_test.go b/source_description_test.go index ca8d4b7..105ad20 100644 --- a/source_description_test.go +++ b/source_description_test.go @@ -138,17 +138,7 @@ func TestSourceDescriptionUnmarshal(t *testing.T) { // END + padding 0x00, 0x00, }, - Want: SourceDescription{ - Chunks: []SourceDescriptionChunk{{ - Source: 0x01020304, - Items: []SourceDescriptionItem{ - { - Type: SDESCNAME, - Text: "", - }, - }, - }}, - }, + Want: *NewCNAMESourceDescription(0x01020304, ""), }, { Name: "two items", @@ -321,15 +311,7 @@ func TestSourceDescriptionRoundTrip(t *testing.T) { }, { Name: "empty text", - Desc: SourceDescription{ - Chunks: []SourceDescriptionChunk{{ - Source: 1, - Items: []SourceDescriptionItem{{ - Type: SDESCNAME, - Text: "", - }}, - }}, - }, + Desc: *NewCNAMESourceDescription(1, ""), }, { Name: "text too long",