-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
ref(TPC) Move all the utility functions to TPCUtils. #2599
Conversation
be70784
to
aac1deb
Compare
aac1deb
to
7de84c8
Compare
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.
Left some comments!
modules/RTC/TPCUtils.js
Outdated
*/ | ||
export class TPCUtils { | ||
/** | ||
* Creates a new instance for a given TraceablePeerConnection | ||
* | ||
* @param peerconnection - the tpc instance for which we have utility functions. | ||
*/ | ||
constructor(peerconnection) { | ||
constructor(peerconnection, options) { |
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.
Make options default to {}
, it will help you later.
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.
Also document it above.
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.
Yep, makes sense! Will modify it.
modules/RTC/TPCUtils.js
Outdated
} | ||
|
||
const sdp = this.pc.remoteDescription?.sdp; | ||
const defaultCodec = CodecMimeType.VP8; |
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.
Constant outside of here?
modules/RTC/TPCUtils.js
Outdated
if (this.pc.usesCodecSelectionAPI() && rtpSender) { | ||
const { codecs } = rtpSender.getParameters(); | ||
|
||
return codecs[0].mimeType.split('/')[1].toLowerCase(); |
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.
Is there a chance the codec list is empty?
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.
No, it shouldn't be unless there is a bug in the browser. Will add a check for that.
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.
👍
modules/RTC/TPCUtils.js
Outdated
} | ||
}); | ||
|
||
return new RTCSessionDescription({ |
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.
Ditto.
modules/RTC/TPCUtils.spec.js
Outdated
@@ -35,7 +35,7 @@ describe('TPCUtils', () => { | |||
|
|||
it('sort ssrcs associated with all FID ssrc-groups', () => { | |||
const pc = new MockPeerConnection(); | |||
const tpcUtils = new TPCUtils(pc); | |||
const tpcUtils = new TPCUtils(pc, { }); |
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.
If you use a default, we don't need to pass the weird empty object.
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.
You can remove this one now.
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.
Looks like I missed this one, I removed it from all other places.
|
||
try { | ||
transceiver = this.peerconnection.addTransceiver(mediaStreamTrack, transceiverInit); | ||
} catch (error) { |
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.
Suggestion: make this function async so you don't need to do this, execptions will reject the promsie already.
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 just moved the code around and tried not to make any additional changes. This one however is simple enough that I don't mind doing it.
// peerconnection on chrome in unified-plan. It is ok to ignore and not report the error here since the | ||
// action that triggers 'addTrack' (like unmute) will also configure the encodings and set bitrates after that. | ||
if (!parameters?.encodings?.length) { | ||
return Promise.resolve(); |
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.
Ditto, why not make it async?
let mungedDescription = description; | ||
|
||
this.trace('RTCSessionDescription::preTransform', dumpSDP(description)); | ||
mungedDescription = this.tpcUtils.mungeOpus(description); |
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.
Each of these operations re-parses the SDP. Since we are refactoring, doesn't it make sense to parse it in this functiom, and pass the transform object along, so each of the tpcUtils functions can apply transformations, and then after all of them, re-generate the SDP?
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.
Yep makes sense.
I attempted all transformations in one utils function and that made it look rather unwieldy. Also some of the transormations will be gone soon so I thought its easier to just remove indivdual transformations then.
I see the benefit in passing just the transform object along though, will update it.
…g an instance of RTCSessionDescription. The constructor for RTCSessionDescription has been deprecated - https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription/RTCSessionDescription.
modules/RTC/TPCUtils.js
Outdated
* @param desc A session description object (with 'type' and 'sdp' fields) | ||
* @return A session description object with its sdp field modified to contain an inject ssrc-group for simulcast. | ||
*/ | ||
injectSsrcGroupForUnifiedSimulcast(desc) { |
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.
Why does this have "unified" in the name now?
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.
Forgot to rename the method, will do. Thanks for pointing it out.
modules/RTC/TPCUtils.js
Outdated
@@ -574,6 +575,57 @@ export class TPCUtils { | |||
} ]; | |||
} | |||
|
|||
/** | |||
* Injects a 'SIM' ssrc-group line for simulcast into the given session description object to make Jicofo happy. | |||
* This is needed only for Firefox since it does not generate it when simulcast is enabled. |
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.
We call this regardless of the browser, is it really only required for FF?
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, this is only needed for Firefox now since it doesn't produce a SIM group but we also need to verify it on other browsers just in case as this would break the functionality otherwise. This code adds the SIM group only if its missing from the SDP.
* @returns {Array} | ||
*/ | ||
getConfiguredVideoCodecs(description) { | ||
const currentSdp = description?.sdp ?? this.pc.localDescription?.sdp; | ||
getConfiguredVideoCodecs(sdp) { |
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 suggest you break this function into 2:
getConfiguredVideoCodecs(sdp) {
}
_getConfiguredVideoCodecsImpl(parsedSdp) {
}
With the former calling the latter, after parsing the SDP.
This will allow you to call the 2nd one in the munge code and doing it all in 1 pass!
modules/RTC/TPCUtils.spec.js
Outdated
@@ -35,7 +35,7 @@ describe('TPCUtils', () => { | |||
|
|||
it('sort ssrcs associated with all FID ssrc-groups', () => { | |||
const pc = new MockPeerConnection(); | |||
const tpcUtils = new TPCUtils(pc); | |||
const tpcUtils = new TPCUtils(pc, { }); |
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.
You can remove this one now.
*/ | ||
TraceablePeerConnection.prototype._mungeDescription = function(description) { | ||
this.trace('RTCSessionDescription::preTransform', dumpSDP(description)); | ||
let mungedSdp = transform.parse(description.sdp); |
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.
Why are we not using SdpTransformWrap 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.
There is no added benefit of using SdpTransformWrap here since util functions operate on the parsedSDP directly. The helper functions that SdpTransformWrap provides are all related to SSRCs and only used by RTXModifier class.
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.
🚀
Pl next time use squash-merge, you can keep the individual commit messages if you want, but this was 1 logical change. |
Move all utility functions to TPCUtils that include
Move all functions that call RTCPeerConnection APIs directly back to TPC.