Skip to content

Commit

Permalink
Avoid use of regex to create RED worker code
Browse files Browse the repository at this point in the history
Now, the RED worker code will all come bundled together in a single blob that only needs to be passed to the worker, which will avoid the use of parsing the stringified RED class code via regex since it is possible that the stringified RED class code may come in a different format as expected by the regex. This issue was originally found in #2771.
  • Loading branch information
dinmin-amzn committed Oct 5, 2023
1 parent 12418f3 commit 3a863b8
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 133 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

### Fixed
- Removed use of regex to create redundant audio worker code to avoid errors where the regex match fails and leads to failure to start the AudioVideoController

## [3.18.1] - 2023-09-29

Expand Down
64 changes: 32 additions & 32 deletions docs/classes/defaulttransceivercontroller.html

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions docs/classes/simulcastcontentsharetransceivercontroller.html

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions docs/classes/simulcasttransceivercontroller.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions docs/classes/videoonlytransceivercontroller.html

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/redundantaudioencoder/RedundantAudioEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1480,3 +1480,15 @@ namespace RedundantAudioEncoder {
windowSize: number;
}
}

/* istanbul ignore next */
/**
* This function is only meant to be called within the RED worker to initialize and start RED functionality.
*/
function startRedWorker(): void {
RedundantAudioEncoder.shouldLogDebug = true;
RedundantAudioEncoder.shouldReportStats = true;
RedundantAudioEncoder.initializeWorker();
}

export const redWorkerCode = `${RedundantAudioEncoder.toString()}(${startRedWorker})();`;
19 changes: 4 additions & 15 deletions src/transceivercontroller/DefaultTransceiverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import BrowserBehavior from '../browserbehavior/BrowserBehavior';
import ClientMetricReport from '../clientmetricreport/ClientMetricReport';
import RedundantAudioRecoveryMetricReport from '../clientmetricreport/RedundantAudioRecoveryMetricReport';
import Logger from '../logger/Logger';
import LogLevel from '../logger/LogLevel';
import RedundantAudioEncoder from '../redundantaudioencoder/RedundantAudioEncoder';
import RedundantAudioEncoder, {
redWorkerCode,
} from '../redundantaudioencoder/RedundantAudioEncoder';
import RedundantAudioRecoveryMetricsObserver from '../redundantaudiorecoverymetricsobserver/RedundantAudioRecoveryMetricsObserver';
import AsyncScheduler from '../scheduler/AsyncScheduler';
import VideoStreamIdSet from '../videostreamidset/VideoStreamIdSet';
Expand Down Expand Up @@ -493,20 +494,8 @@ export default class DefaultTransceiverController
);
}

// Stringify the `RedundantAudioEncoder` class code and get the new name of the `RedundantAudioEncoder` class since
// its name is changed in the browser.
const redWorkerCode = RedundantAudioEncoder.toString();
const redClassName = redWorkerCode.match(/class\s*(\w+)\s*\{/)[1];

const blobParts: BlobPart[] = [redWorkerCode];
if (this.logger.getLogLevel() === LogLevel.DEBUG) {
blobParts.push(`${redClassName}.shouldLogDebug=1;`);
}
blobParts.push(`${redClassName}.shouldReportStats=1;`);
blobParts.push(`${redClassName}.initializeWorker();`);

this.audioRedWorkerURL = URL.createObjectURL(
new Blob(blobParts, {
new Blob([redWorkerCode], {
type: 'application/javascript',
})
);
Expand Down

0 comments on commit 3a863b8

Please sign in to comment.