Use transceiver's codec in getCodecs

Issue:
------
A transceiver's codecs can be modified using `SetCodecPreferences`.
When retrieving codecs from the transceiver after changing codec
preferences of the transceiver (for example changing the SDPFmtpLine),
the filter function was using codec from the media engine. Thus,
the change from `SetCodecPreferences` is lost.

Fix:
----
- When a match is found (either exact or partial), use the codec from
the transceiver instead of media engine.
- Based on feedback, add checks to ensure that PayloadType is not
set incorrectly (i. e. set with a default of 0). If it is set to 0,
use the PayloadType from the media engine, i. e. negotiated value.

Testing:
--------
- Modify SDPFmtpLine of a codec of a transceiver using
`SetCodecPreferences` method of `RTPTransceiver`.
- Invoke `GetParamters` of `RTPREceiver` and ensure that `Codecs`
has the SDPFmtpLine modification. Before this change the change
was not reflected in the returned `Codecs`.
- Check that SDP has payload from codec set via SetCodecPreferences
This commit is contained in:
boks1971
2021-10-09 11:32:22 +05:30
committed by David Zhao
parent 5d0ea98f08
commit b1a08a7e0d
2 changed files with 5 additions and 2 deletions

View File

@@ -69,7 +69,10 @@ func (t *RTPTransceiver) getCodecs() []RTPCodecParameters {
filteredCodecs := []RTPCodecParameters{}
for _, codec := range t.codecs {
if c, matchType := codecParametersFuzzySearch(codec, mediaEngineCodecs); matchType != codecMatchNone {
filteredCodecs = append(filteredCodecs, c)
if codec.PayloadType == 0 {
codec.PayloadType = c.PayloadType
}
filteredCodecs = append(filteredCodecs, codec)
}
}

View File

@@ -124,7 +124,7 @@ func Test_RTPTransceiver_SetCodecPreferences_PayloadType(t *testing.T) {
assert.NoError(t, err)
// VP8 with proper PayloadType
assert.NotEqual(t, -1, strings.Index(answer.SDP, "a=rtpmap:96 VP8/90000"))
assert.NotEqual(t, -1, strings.Index(answer.SDP, "a=rtpmap:51 VP8/90000"))
// testCodec is ignored since offerer doesn't support
assert.Equal(t, -1, strings.Index(answer.SDP, "testCodec"))