-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fix addCodec to return error if payload type exists in codecs list #3016
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3016 +/- ##
==========================================
+ Coverage 78.47% 78.52% +0.05%
==========================================
Files 89 89
Lines 11037 11038 +1
==========================================
+ Hits 8661 8668 +7
+ Misses 1890 1885 -5
+ Partials 486 485 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
While this PR fixes the issue of duplicate payload type codec entry on RegisterCodec, There is still one issue that this PR doesn't cover. What if we have some registered codecs and the client sends the codecs with different payload types and one of the payload types the client is using clashes with our registered codecs, in that case, the client's codec won't be added to the negotiated codecs list. That's an issue because the server will now be missing that codec. The flow -
This PR will make the media engine discard the opus codec. However, the issue remains even without this PR,
Again the client-given codec won't be added and most probably the browser will use |
@itzmanish Thank you so much, Will you be able to fix the lint issues (commit and code?).
For your use cause (SFU) you will need to manage separate payload type mappings for the send and receive directions in certain cases, as outlined in rfc3264
Worth mentioning rfc3551
|
Maybe need to re-trigger the commit linter to run. I have updated the PR title and last commit message to pass, but it's not getting triggered for newer commits. @JoeTurki could you please re-trigger the gh action for lint metadata? |
This line. let's say, the server is an offerer and generates SDP with PT 96, mime video/VP8 and PT 97, mime video/VP9. Could it be possible for the client to generate and answer SDP with PT 96, mime video/VP9 and PT 97, mime video/VP8? If yes, according to how we update negotiatedCodecs, it won't get updated. |
@@ -573,9 +577,9 @@ func (m *MediaEngine) updateHeaderExtension(id int, extension string, typ RTPCod | |||
func (m *MediaEngine) pushCodecs(codecs []RTPCodecParameters, typ RTPCodecType) { | |||
for _, codec := range codecs { | |||
if typ == RTPCodecTypeAudio { | |||
m.negotiatedAudioCodecs = m.addCodec(m.negotiatedAudioCodecs, codec) | |||
m.negotiatedAudioCodecs, _ = m.addCodec(m.negotiatedAudioCodecs, codec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider handling this error explicitly? If someone mistakenly changes matchRemoteCodec.
I think it might be better to scope the logic of your PR to specific cases, such as only handling it only for videoCodecs and audioCodecs (calls originating from RegisterCodec). This would make sure we’re not inadvertently affecting unrelated handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider handling this error explicitly?
Honestly, we don't have to handle the error here, because push codec only happens on either partial or full match. If it's a full match, the codec won't be pushed anyway, and if it's partial I don't think it will be possible for the client to send two different codecs with the same payload type on SDP. So error handling doesn't matter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true, but my comment was more about if someone updates matchRemoteCodec
in the future, or any side effects. Maybe we only introduce this change only to the public API RegisterCodec
or what do you think?
I don't think it will be possible for the client to send two different codecs with the same payload type on SDP.
I think we should return an error but I think we should do that in another PR.
I'm not entirely sure about this PR, maybe we should wait for someone with better understanding of the codebase, But I agree that RegisterCodec
should return an error for dynamic PT reuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we only introduce this change only to the public API RegisterCodec or what do you think?
For my use case only doing this and having publically accessible GetCodecsByKind is fine (separate PR). It's just currently the least possible change path where without doing another loop to find if the payload type already exists or not, we can achieve the error returning in case the codec is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should return an error but I think we should do that in another PR.
Is there any possible scenario you can think of, where the client sends two different codecs with the same payload type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just currently the least possible change path where without doing another loop to find if the payload type already exists or not, we can achieve the error returning in case the codec is available.
You can just pass a Boolean (unique) to addCodec and conditionally return an error if it's true or refactor it to two functions one for internals, and one for matchedcodecs. Or any other option, The implementation doesn't matter, we can fix the code later; What matters is the behavior.
Is there any possible scenario you can think of, where the client sends two different codecs with the same payload type?
Yes, A misconfigured client, You found this "bug" because Chrome returned an error when you re-used the PT for different codecs. And I think we should return an error, to make sure we don't have an unexpected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, A misconfigured client, You found this "bug" because Chrome returned an error when you re-used the PT for different codecs. And I think we should return an error, to make sure we don't have an unexpected behavior.
I totally agree. I can make those changes in the same PR or wait for @Sean-Der's input. It makes sense to handle this error on updateFromRemoteDescription
.
PR title doesn't affect it, You'll need to reword your old commits, but since we only allow for one commit per PR it's better if you squash your commits into a single one and fix the lint issues :) Thanks :) |
Is this what you mean? Line 98 in feeeebf
|
yes. I get it now. The negotiated codecs list always respects the answer's codec preferences. Thanks :) |
Description
This PR adds changes to return an error if the codec already exists on the codecs list. This way now the implementing party should take care of duplicate codecs addition if the payload type is the same.
Reference issue
Fixes #3015