Skip to content

Fix missing RTX codec when using SetCodecPreferences #3051

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion rtpcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
return RTPCodecParameters{}, codecMatchNone
}

// Given a CodecParameters find the RTX CodecParameters if one exists.
// Given a CodecParameters find the RTX Payload if one exists.
func findRTXPayloadType(needle PayloadType, haystack []RTPCodecParameters) PayloadType {
aptStr := fmt.Sprintf("apt=%d", needle)
for _, c := range haystack {
Expand All @@ -155,6 +155,18 @@
return PayloadType(0)
}

// Given a CodecParameters find the RTX CodecParameters if one exists.
func findRTXPCodec(needle PayloadType, haystack []RTPCodecParameters) *RTPCodecParameters {
aptStr := fmt.Sprintf("apt=%d", needle)
for _, c := range haystack {
if aptStr == c.SDPFmtpLine {
return &c
}

Check warning on line 164 in rtpcodec.go

View check run for this annotation

Codecov / codecov/patch

rtpcodec.go#L159-L164

Added lines #L159 - L164 were not covered by tests
}

return nil

Check warning on line 167 in rtpcodec.go

View check run for this annotation

Codecov / codecov/patch

rtpcodec.go#L167

Added line #L167 was not covered by tests
}

func rtcpFeedbackIntersection(a, b []RTCPFeedback) (out []RTCPFeedback) {
for _, aFeedback := range a {
for _, bFeeback := range b {
Expand Down
11 changes: 11 additions & 0 deletions rtptransceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ func (t *RTPTransceiver) getCodecs() []RTPCodecParameters {
}
}

// check if direction is specified
if t.direction.Load() != nil {
for _, c := range filteredCodecs {
if rtxCodec := findRTXPCodec(c.PayloadType, mediaEngineCodecs); rtxCodec != nil {
if _, matchType := codecParametersFuzzySearch(*rtxCodec, filteredCodecs); matchType == codecMatchNone {
filteredCodecs = append(filteredCodecs, *rtxCodec)
}
}
}
}

return filteredCodecs
}

Expand Down
52 changes: 52 additions & 0 deletions rtptransceiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,55 @@ func Test_RTPTransceiver_SetCodecPreferences_PayloadType(t *testing.T) {

closePairNow(t, offerPC, answerPC)
}

func Test_RTPTransceiver_SDP_Codec(t *testing.T) {
tests := []struct {
Label string
setPreferences bool
}{
{
Label: "NoSetCodecPreferences",
setPreferences: false,
},
{
Label: "SetCodecPreferences",
setPreferences: true,
},
}

for _, test := range tests {
t.Run(test.Label, func(t *testing.T) {
pc, err := NewPeerConnection(Configuration{})
assert.NoError(t, err)

transceiver, err := pc.AddTransceiverFromKind(
RTPCodecTypeVideo,
RTPTransceiverInit{
Direction: RTPTransceiverDirectionRecvonly,
},
)
assert.NoError(t, err)

if test.setPreferences {
codec := RTPCodecCapability{
"video/vp8", 90000, 0, "", nil,
}

err = transceiver.SetCodecPreferences(
[]RTPCodecParameters{
{
RTPCodecCapability: codec,
},
},
)
assert.NoError(t, err)
}

offer, err := pc.CreateOffer(nil)
assert.NoError(t, err)

assert.Equal(t, true, strings.Contains(offer.SDP, "apt=96"))
assert.NoError(t, pc.Close())
})
}
}
Loading