Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jallamsetty1
Copy link
Member

@jallamsetty1 jallamsetty1 commented Nov 18, 2024

Move all utility functions to TPCUtils that include

  1. munging the SDP.
  2. getting current codecs
  3. getting expected transceiver direction.
  4. getting expected settings for video encodings.

Move all functions that call RTCPeerConnection APIs directly back to TPC.

Copy link
Member

@saghul saghul left a 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,
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Member

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;
Copy link
Member

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();
Copy link
Member

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());
Copy link
Member

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({
Copy link
Member

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, { });
Copy link
Member

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) {
Copy link
Member

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();
Copy link
Member

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);
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants