Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

[RTC-32] Fetch actual bitrate of a variant #21

Merged
merged 11 commits into from
Mar 23, 2023

Conversation

LVala
Copy link
Contributor

@LVala LVala commented Jan 23, 2023

No description provided.

@LVala LVala requested a review from mickel8 January 23, 2023 11:54
@LVala LVala self-assigned this Jan 23, 2023
tsconfig.json Outdated
@@ -9,7 +9,8 @@
"moduleResolution": "node",
"outDir": "dist/",
"strict": true,
"target": "es2018"
"target": "es2018",
"lib": ["dom", "es6", "es2019"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added that to be able to use Object.fromEntries()

Copy link
Contributor

@mickel8 mickel8 Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.fromEntries was added in ECMAScript 2019. Do we need to include dom and es6 (ECMAScript 2015) too?

Copy link
Contributor Author

@LVala LVala Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SO question misled me a bit (the "nothing imports es6" part) but looking at Typescript source it seems that es2019 also import previous libs so it is not necessary. DOM on the other hand contains all of the browser api definitions and without it Typescript throws errors on MediaStream type etc.

@@ -894,6 +897,7 @@ export class MembraneWebRTC {
if (parameters.encodings.length === 0) {
parameters.encodings = [{}];
} else {
// TODO: sent MediaEvent with updated variant bitrates
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending TrackVariantBitrates MediaEvent here would be quite troublesome (need to split the bandwidth before sending bitrates for each of the tracks), so I decided to leave it to the bigger refactor that we mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acctually, would it be hard to address this issue in this PR?

Copy link
Contributor Author

@LVala LVala Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I did, but I would't call the code clean, the ambiguity of how track variant bandwidth is kept (sometimes as an aggregated value, sometimes bitrate per variant) and that the function responsible for splitting bitrate is very deep on the call stack make it hard to do it nicely without bigger refactor (which, as far as I understand, we don't want to do in this PR).

@@ -934,6 +938,14 @@ export class MembraneWebRTC {
delete encoding.maxBitrate;
} else {
encoding.maxBitrate = bandwidth * 1024;
let mediaEvent = generateCustomEvent({
type: "setTrackVariantBitrates",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would favor trackVariantBitrates. It will fit more into our convention

maxBandwidth instanceof Map
? Object.fromEntries(maxBandwidth)
: maxBandwidth,
mid: trackIdToMid ? trackIdToMid.get(trackId!) : null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should allow for sending null here. Server won't be able to handle it so we should assert that trackIdtoMid is always present and contains trackId.

tsconfig.json Outdated
@@ -9,7 +9,8 @@
"moduleResolution": "node",
"outDir": "dist/",
"strict": true,
"target": "es2018"
"target": "es2018",
"lib": ["dom", "es6", "es2019"]
Copy link
Contributor

@mickel8 mickel8 Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.fromEntries was added in ECMAScript 2019. Do we need to include dom and es6 (ECMAScript 2015) too?

@@ -894,6 +897,7 @@ export class MembraneWebRTC {
if (parameters.encodings.length === 0) {
parameters.encodings = [{}];
} else {
// TODO: sent MediaEvent with updated variant bitrates
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acctually, would it be hard to address this issue in this PR?

@LVala LVala force-pushed the fetch-bitrate-of-simulcast-variant branch from acae0e5 to ed3079e Compare January 24, 2023 20:12
@LVala LVala requested a review from mickel8 January 24, 2023 20:29
@LVala LVala changed the title [RTC-10] Fetch actual bitrate of a variant [RTC-32] Fetch actual bitrate of a variant Jan 25, 2023
@daniel-jodlos daniel-jodlos self-requested a review February 23, 2023 15:08
@daniel-jodlos
Copy link
Contributor

I'm removing my review request, until the backwards compatibility is resolved in the other Pull Request

@daniel-jodlos daniel-jodlos removed their request for review March 14, 2023 09:43
@LVala LVala requested a review from daniel-jodlos March 20, 2023 11:14
@LVala
Copy link
Contributor Author

LVala commented Mar 20, 2023

Adjusted to match latest commit in this RTC Engine PR. Not the cleanest (passing media event object down 3 functions), but I believe that otherwise it would require greater refactor and I'm not sure if that's what we want to do now.

Copy link
Contributor

@daniel-jodlos daniel-jodlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, but I think one aspect of it has been missed

if (mediaEvent)
mediaEvent.data.data.variantBitrates[encoding.rid!] =
encoding.maxBitrate;
} else delete encoding.maxBitrate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case will not be adequately handled on the server. I think what will happen is that the encoding will be missing from the media event and the server will still consider the previous limit valid, which is not true because the limit has been removed, so we're back to Chrome's default limit for the variant.

Maybe we should just force the limit values to be set for all present variants in the Media Event? 🤔 This way we won't have to hard code the default Chrome limits in the RTC Engine except for backward compatibility reasons. This approach may also be better when you consider other clients, which may have different default limits.

@LVala LVala requested a review from daniel-jodlos March 22, 2023 16:06
@LVala
Copy link
Contributor Author

LVala commented Mar 22, 2023

I changed the media event to always contain all of the variant bitrates. Also, I'm not very sure about the default audio bitrate as I couldn't find anything about it in chromium source in a reasonable time.

@LVala LVala merged commit 707e9b5 into master Mar 23, 2023
@LVala LVala deleted the fetch-bitrate-of-simulcast-variant branch March 23, 2023 09:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants