Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewCNAMESourceDescription helper method #111

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions compound_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions fuzz.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build gofuzz
// +build gofuzz

package rtcp
Expand Down
14 changes: 1 addition & 13 deletions packet_stringifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
14 changes: 1 addition & 13 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
Expand Down
13 changes: 13 additions & 0 deletions source_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
/*
Expand Down
22 changes: 2 additions & 20 deletions source_description_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down