Skip to content

Commit

Permalink
Merge pull request #345 from mcottontensor/frontend_quality
Browse files Browse the repository at this point in the history
Adding the compatibility quality min/max
  • Loading branch information
mcottontensor authored Dec 3, 2024
2 parents 26f6d91 + 21dc67d commit cc0a217
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 34 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/healthcheck-libs-with-public-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,33 @@ jobs:
with:
fetch-depth: 5 # This should be enough history to contain the commit that triggered the PR

- name: Check commit message for push event
- name: Grab PR body
if: github.event_name == 'pull_request'
env:
COMMIT: ${{ github.event.head_commit.message }}
if: github.event_name == 'push'
PR_BODY: ${{ github.event.pull_request.body }}
run: |
echo "Commit message: ${{ env.COMMIT }}"
echo "COMMIT=${{ env.COMMIT }}" >> $GITHUB_ENV
echo "BODY_CHECK<<EOF" >> $GITHUB_ENV
echo "$PR_BODY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Check commit message for pull request event
if: github.event_name == 'pull_request'
- name: Grab commit message for push event
if: github.event_name == 'push'
env:
COMMIT: ${{ github.event.head_commit.message }}
run: |
# Get the latest commit SHA for the pull request
COMMIT_SHA="${{ github.event.pull_request.head.sha }}"
echo "Fetching commit message for PR commit: $COMMIT_SHA"
COMMIT_MESSAGE=$(git log -1 --pretty=%B "$COMMIT_SHA")
echo "Commit message: $COMMIT_MESSAGE"
echo "COMMIT=$COMMIT_MESSAGE" >> $GITHUB_ENV
echo "BODY_CHECK<<EOF" >> $GITHUB_ENV
echo "$COMMIT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Check commit message for bypass
- name: Check if the body to check contains the bypass tag
id: checkbypass
run: |
echo "$COMMIT"
if echo "$COMMIT" | grep -q "#bypass-publish-check"; then
if echo "$BODY_CHECK" | grep -q "#bypass-publish-check"; then
echo "bypass=true" >> $GITHUB_OUTPUT
echo "bypass=true"
else
echo "bypass=false" >> $GITHUB_OUTPUT
echo "bypass=false"
echo "bypass=flase"
fi
build-using-public-deps:
Expand Down
64 changes: 64 additions & 0 deletions Frontend/library/src/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class NumericParameters {
static AFKCountdownSecs = 'AFKCountdown' as const;
static MinQP = 'MinQP' as const;
static MaxQP = 'MaxQP' as const;
static MinQuality = 'MinQuality' as const;
static MaxQuality = 'MaxQuality' as const;
static CompatQualityMin = 'CompatQualityMin' as const;
static CompatQualityMax = 'CompatQualityMax' as const;
static WebRTCFPS = 'WebRTCFPS' as const;
static WebRTCMinBitrate = 'WebRTCMinBitrate' as const;
static WebRTCMaxBitrate = 'WebRTCMaxBitrate' as const;
Expand Down Expand Up @@ -622,6 +626,66 @@ export class Config {
)
);

this.numericParameters.set(
NumericParameters.MinQuality,
new SettingNumber(
NumericParameters.MinQuality,
'Min Quality',
'The lower bound for the quality factor of the encoder. 0 = Worst quality, 100 = Best quality.',
0 /*min*/,
100 /*max*/,
settings && Object.prototype.hasOwnProperty.call(settings, NumericParameters.MinQuality)
? settings[NumericParameters.MinQuality]
: 0 /*value*/,
useUrlParams
)
);

this.numericParameters.set(
NumericParameters.MaxQuality,
new SettingNumber(
NumericParameters.MaxQuality,
'Max Quality',
'The upper bound for the quality factor of the encoder. 0 = Worst quality, 100 = Best quality.',
0 /*min*/,
100 /*max*/,
settings && Object.prototype.hasOwnProperty.call(settings, NumericParameters.MaxQuality)
? settings[NumericParameters.MaxQuality]
: 100 /*value*/,
useUrlParams
)
);

this.numericParameters.set(
NumericParameters.CompatQualityMin,
new SettingNumber(
NumericParameters.CompatQualityMin,
'Min Quality',
'The lower bound for encoding quality. 0 = Worst, 100 = Best.',
0 /*min*/,
100 /*max*/,
settings && Object.prototype.hasOwnProperty.call(settings, NumericParameters.CompatQualityMin)
? settings[NumericParameters.CompatQualityMin]
: 0 /*value*/,
useUrlParams
)
);

this.numericParameters.set(
NumericParameters.CompatQualityMax,
new SettingNumber(
NumericParameters.CompatQualityMax,
'Max Quality',
'The upper bound for encoding quality. 0 = Worst, 100 = Best.',
0 /*min*/,
100 /*max*/,
settings && Object.prototype.hasOwnProperty.call(settings, NumericParameters.CompatQualityMax)
? settings[NumericParameters.CompatQualityMax]
: 100 /*value*/,
useUrlParams
)
);

this.numericParameters.set(
NumericParameters.WebRTCFPS,
new SettingNumber(
Expand Down
2 changes: 2 additions & 0 deletions Frontend/library/src/DataChannel/InitialSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class EncoderSettings {
MaxBitrate?: number;
MinQP?: number;
MaxQP?: number;
MinQuality?: number;
MaxQuality?: number;
RateControl?: 'CBR' | 'VBR' | 'ConstQP';
FillerData?: boolean;
MultiPass?: 'DISABLED' | 'QUARTER' | 'FULL';
Expand Down
109 changes: 94 additions & 15 deletions Frontend/library/src/PixelStreaming/PixelStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,58 @@ export class PixelStreaming {
this._webRtcController.setGamePadInputEnabled(isEnabled);
});

// encoder settings
// direct qp settings
this.config._addOnNumericSettingChangedListener(NumericParameters.MinQP, (newValue: number) => {
Logger.Info('-------- Sending MinQP --------');
this._webRtcController.sendEncoderMinQP(newValue);
Logger.Info('-------------------------------------------');
const quality = Math.trunc(100 * (1 - newValue / 51));
this.config.setNumericSetting(NumericParameters.CompatQualityMax, quality);
});

this.config._addOnNumericSettingChangedListener(NumericParameters.MaxQP, (newValue: number) => {
Logger.Info('-------- Sending encoder settings --------');
Logger.Info('-------- Sending MaxQP --------');
this._webRtcController.sendEncoderMaxQP(newValue);
Logger.Info('-------------------------------------------');
const quality = Math.trunc(100 * (1 - newValue / 51));
this.config.setNumericSetting(NumericParameters.CompatQualityMin, quality);
});

// direct quality factor settings
this.config._addOnNumericSettingChangedListener(NumericParameters.MinQuality, (newValue: number) => {
Logger.Info('-------- Sending MinQuality --------');
this._webRtcController.sendEncoderMinQuality(newValue);
Logger.Info('-------------------------------------------');
this.config.setNumericSetting(NumericParameters.CompatQualityMin, newValue);
});

this.config._addOnNumericSettingChangedListener(NumericParameters.MaxQuality, (newValue: number) => {
Logger.Info('-------- Sending MaxQuality --------');
this._webRtcController.sendEncoderMaxQuality(newValue);
Logger.Info('-------------------------------------------');
this.config.setNumericSetting(NumericParameters.CompatQualityMax, newValue);
});

// new quality value that gets scaled to qp for legacy reasons
this.config._addOnNumericSettingChangedListener(
NumericParameters.CompatQualityMin,
(newValue: number) => {
newValue = 51 - (newValue / 100) * 51;
Logger.Info('-------- Sending MinQP from quality value --------');
this._webRtcController.sendEncoderMaxQP(newValue);
Logger.Info('-------------------------------------------');
}
);

this.config._addOnNumericSettingChangedListener(
NumericParameters.CompatQualityMax,
(newValue: number) => {
newValue = 51 - (newValue / 100) * 51;
Logger.Info('-------- Sending MaxQP from quality value --------');
this._webRtcController.sendEncoderMinQP(newValue);
Logger.Info('-------------------------------------------');
}
);
// WebRTC settings
this.config._addOnNumericSettingChangedListener(
NumericParameters.WebRTCMinBitrate,
Expand Down Expand Up @@ -531,20 +570,60 @@ export class PixelStreaming {
const urlParams = new IURLSearchParams(window.location.search);
Logger.Info(`using URL parameters ${useUrlParams}`);
if (settings.EncoderSettings) {
this.config.setNumericSetting(
NumericParameters.MinQP,
// If a setting is set in the URL, make sure we respect that value as opposed to what the application sends us
useUrlParams && urlParams.has(NumericParameters.MinQP)
? Number.parseFloat(urlParams.get(NumericParameters.MinQP))
: settings.EncoderSettings.MinQP
);
// here we should either get Min/MaxQP from PS1
// or Min/MaxQuality from PS2
// we only want to set one set or the other as they converge in CompatQualityMin/Max and
// we dont want to have them conflict with default values.
if (settings.EncoderSettings.MinQP) {
this.config.setNumericSetting(
NumericParameters.MinQP,
// If a setting is set in the URL, make sure we respect that value as opposed to what the application sends us
useUrlParams && urlParams.has(NumericParameters.MinQP)
? Number.parseFloat(urlParams.get(NumericParameters.MinQP))
: settings.EncoderSettings.MinQP || 0
);

this.config.setNumericSetting(
NumericParameters.MaxQP,
useUrlParams && urlParams.has(NumericParameters.MaxQP)
? Number.parseFloat(urlParams.get(NumericParameters.MaxQP))
: settings.EncoderSettings.MaxQP
);
this.config.setNumericSetting(
NumericParameters.MaxQP,
useUrlParams && urlParams.has(NumericParameters.MaxQP)
? Number.parseFloat(urlParams.get(NumericParameters.MaxQP))
: settings.EncoderSettings.MaxQP || 51
);
}

if (settings.EncoderSettings.MinQuality) {
this.config.setNumericSetting(
NumericParameters.MinQuality,
// If a setting is set in the URL, make sure we respect that value as opposed to what the application sends us
useUrlParams && urlParams.has(NumericParameters.MinQuality)
? Number.parseFloat(urlParams.get(NumericParameters.MinQuality))
: settings.EncoderSettings.MinQuality || 0
);

this.config.setNumericSetting(
NumericParameters.MaxQuality,
useUrlParams && urlParams.has(NumericParameters.MaxQuality)
? Number.parseFloat(urlParams.get(NumericParameters.MaxQuality))
: settings.EncoderSettings.MaxQuality || 100
);
}

// these two are just used to converge quality and qp and behave slightly differently since they
// shouldnt exist in EncoderSettings
if (useUrlParams) {
if (urlParams.has(NumericParameters.CompatQualityMin)) {
this.config.setNumericSetting(
NumericParameters.CompatQualityMin,
Number.parseFloat(urlParams.get(NumericParameters.CompatQualityMin))
);
}
if (urlParams.has(NumericParameters.CompatQualityMax)) {
this.config.setNumericSetting(
NumericParameters.CompatQualityMax,
Number.parseFloat(urlParams.get(NumericParameters.CompatQualityMax))
);
}
}
}
if (settings.WebRTCSettings) {
this.config.setNumericSetting(
Expand Down
38 changes: 38 additions & 0 deletions Frontend/library/src/WebRtcPlayer/WebRtcPlayerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,44 @@ export class WebRtcPlayerController {
}
}

/**
* Send the MinQuality encoder setting to the UE Instance.
* @param minQuality - The lower bound for quality when encoding
* valid values are (0-100) where:
* 0 = Worst quality.
* 100 = Best quality.
*/
sendEncoderMinQuality(minQuality: number) {
Logger.Info(`MinQuality=${minQuality}\n`);

if (minQuality != null) {
this.streamMessageController.toStreamerHandlers.get('Command')([
JSON.stringify({
'Encoder.MinQuality': minQuality
})
]);
}
}

/**
* Send the MaxQuality encoder setting to the UE Instance.
* @param maxQuality - The upper bound for quality when encoding
* valid values are (0-100) where:
* 0 = Worst quality.
* 100 = Best quality.
*/
sendEncoderMaxQuality(maxQuality: number) {
Logger.Info(`MaxQuality=${maxQuality}\n`);

if (maxQuality != null) {
this.streamMessageController.toStreamerHandlers.get('Command')([
JSON.stringify({
'Encoder.MaxQuality': maxQuality
})
]);
}
}

/**
* Send the { WebRTC.MinBitrate: SomeNumber }} command to UE to set
* the minimum bitrate that we allow WebRTC to use
Expand Down
10 changes: 8 additions & 2 deletions Frontend/ui-library/src/Config/ConfigUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ export class ConfigUI {
/* Setup all encoder related settings under this section */
const encoderSettingsSection = this.buildSectionWithHeading(settingsElem, 'Encoder');

this.addSettingNumeric(encoderSettingsSection, this.numericParametersUi.get(NumericParameters.MinQP));
this.addSettingNumeric(encoderSettingsSection, this.numericParametersUi.get(NumericParameters.MaxQP));
this.addSettingNumeric(
encoderSettingsSection,
this.numericParametersUi.get(NumericParameters.CompatQualityMin)
);
this.addSettingNumeric(
encoderSettingsSection,
this.numericParametersUi.get(NumericParameters.CompatQualityMax)
);

const preferredCodecOption = this.optionParametersUi.get(OptionParameters.PreferredCodec);
this.addSettingOption(
Expand Down

0 comments on commit cc0a217

Please sign in to comment.