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

fix(video-quality) Reset scale factor and bitrates for VP9 K-SVC. #2539

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions modules/RTC/TraceablePeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2299,13 +2299,24 @@ TraceablePeerConnection.prototype._updateVideoSenderEncodings = function(frameHe

// Calculate the encodings active state based on the resolution requested by the bridge.
const codec = this.getConfiguredVideoCodec();
const bitrates = this.tpcUtils.calculateEncodingsBitrates(localVideoTrack, codec, frameHeight);
const activeState = this.tpcUtils.calculateEncodingsActiveState(localVideoTrack, codec, frameHeight);
const scaleFactors = this.tpcUtils.calculateEncodingsScaleFactor(localVideoTrack, codec, frameHeight);
let bitrates = this.tpcUtils.calculateEncodingsBitrates(localVideoTrack, codec, frameHeight);
const scalabilityModes = this.tpcUtils.calculateEncodingsScalabilityMode(localVideoTrack, codec, frameHeight);
let scaleFactors = this.tpcUtils.calculateEncodingsScaleFactor(localVideoTrack, codec, frameHeight);
const sourceName = localVideoTrack.getSourceName();
let needsUpdate = false;

// Do not configure 'scaleResolutionDownBy' and 'maxBitrate' for encoders running in VP9 legacy K-SVC mode since
// the browser sends only the lowest resolution layer when those are configured. Those fields need to be reset in
// case they were set when the endpoint was encoding video using the other codecs before switching over to VP9
// K-SVC codec.
if (codec === CodecMimeType.VP9
&& this.isSpatialScalabilityOn()
&& !this.tpcUtils.codecSettings[codec].scalabilityModeEnabled) {
scaleFactors = scaleFactors.map(() => undefined);
bitrates = bitrates.map(() => undefined);
}

for (const idx in parameters.encodings) {
if (parameters.encodings.hasOwnProperty(idx)) {
const {
Expand All @@ -2324,20 +2335,13 @@ TraceablePeerConnection.prototype._updateVideoSenderEncodings = function(frameHe
// encodings.
browser.isFirefox() && (parameters.encodings[idx].degradationPreference = preference);

// Do not configure 'scaleResolutionDownBy' and 'maxBitrate' for encoders running in legacy K-SVC mode
// since the browser sends only the lowest resolution layer when those are configured.
if (codec !== CodecMimeType.VP9
|| !this.isSpatialScalabilityOn()
|| (browser.supportsScalabilityModeAPI()
&& this.tpcUtils.codecSettings[codec].scalabilityModeEnabled)) {
if (scaleResolutionDownBy !== scaleFactors[idx]) {
parameters.encodings[idx].scaleResolutionDownBy = scaleFactors[idx];
needsUpdate = true;
}
if (maxBitrate !== bitrates[idx]) {
parameters.encodings[idx].maxBitrate = bitrates[idx];
needsUpdate = true;
}
if (scaleResolutionDownBy !== scaleFactors[idx]) {
parameters.encodings[idx].scaleResolutionDownBy = scaleFactors[idx];
needsUpdate = true;
}
if (maxBitrate !== bitrates[idx]) {
parameters.encodings[idx].maxBitrate = bitrates[idx];
needsUpdate = true;
}

// Configure scalability mode when its supported and enabled.
Expand Down