-
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
base: master
Are you sure you want to change the base?
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!
const VIDEO_CODECS = [ CodecMimeType.AV1, CodecMimeType.H264, CodecMimeType.VP8, CodecMimeType.VP9 ]; | ||
|
||
/** | ||
* Handles track related operations on TraceablePeerConnection when browser is | ||
* running in unified plan mode. | ||
* Handles all the utility functions for the TraceablePeerConnection class, like calculating the encoding parameters, |
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.
Moving things out of TPC but to a single place doesn't really move the needle much, does it? It's still one entity with too much in it. Granted, TPC will be slimmer.
Is this a stepping stone for a further split in more narrow focused parts? I really like what you did with the quality controllers!
*/ | ||
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.
} | ||
|
||
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?
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?
const { codec } = mLine.rtp.find(rtp => rtp.payload === Number(payload)); | ||
|
||
if (codec) { | ||
return Object.values(CodecMimeType).find(value => value === codec.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 we don't find it?
} | ||
}); | ||
|
||
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.
@@ -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.
|
||
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.
// 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?
Move all utility functions to TPCUtils that include
Move all functions that call RTCPeerConnection APIs directly back to TPC.