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

Save the redundant audio worker code during build time so that the worker code stays intact and is able to be loaded #2772

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

dinmin-amzn
Copy link
Contributor

@dinmin-amzn dinmin-amzn commented Oct 5, 2023

Issue #: #2771
Description of changes:
The redundant audio worker code string may vary based on the build system of different projects. Because of this, certain build systems will cause invalid worker code to be generated and the redundant audio worker will not be able to run. Now, the redundant audio worker code is saved at build time so that all clients can run the redundant audio worker with the same exact code, regardless of the client's build system.

This issue was originally found in #2771.

Testing:

Can these tested using a demo application? Please provide reproducible step-by-step instructions.
Reproduction steps for the original issue are mentioned in #2771. Following the same steps with this change should fix the issue.

Checklist:

  1. Have you successfully run npm run build:release locally?
    y

  2. Do you add, modify, or delete public API definitions? If yes, has that been reviewed and approved?
    n

  3. Do you change the wire protocol, e.g. the request method? If yes, has that been reviewed and approved?
    n

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dinmin-amzn dinmin-amzn requested a review from a team as a code owner October 5, 2023 01:38
@dinmin-amzn dinmin-amzn force-pushed the avoid-red-regex branch 2 times, most recently from 3a863b8 to 3b4e765 Compare October 5, 2023 01:48
hensmi-amazon
hensmi-amazon previously approved these changes Oct 5, 2023
* This function is only meant to be called within the RED worker to initialize and start RED functionality.
*/
function startRedWorker(): void {
RedundantAudioEncoder.shouldLogDebug = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be false, yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want the RED worker to be able to emit logs, so this should be true

Copy link
Contributor

Choose a reason for hiding this comment

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

Does the worker have any high frequency logs? If yes, then this will lead to a lot of messages being sent from the worker to the main thread. Probably just a quick scrub of the encoder file should be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The encoder file only has low frequency logs at the moment, so this shouldn't overload the main thread with too many messages

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just based on the Log level defined ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to configure this based on log level

@dinmin-amzn dinmin-amzn changed the title Avoid use of regex to create RED worker code Save the redundant audio worker code during build time so that the worker code stays intact and is able to be loaded Oct 6, 2023
@dinmin-amzn dinmin-amzn force-pushed the avoid-red-regex branch 2 times, most recently from 3cb7500 to fbd8292 Compare October 6, 2023 07:45
"outDir": "../build",
"rootDir": "../src"
},
"include": [
Copy link
Contributor

@ltrung ltrung Oct 6, 2023

Choose a reason for hiding this comment

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

Why do we need a separate config for just RED? Can you put a comment in the package.json explaining it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Same question. Using the existing tsconfig file I see RedundantAudioEncoder.js being generated in the build folder? Doesn't that mean we don't need this extra tsconfig file?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is because we need to convert ts -> js for this file first and put it in the source folder so when we transpile for the whole folder they can refer to this file

Copy link
Contributor Author

@dinmin-amzn dinmin-amzn Oct 6, 2023

Choose a reason for hiding this comment

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

The idea for generating and building the worker code was:

  1. Build the RedundantAudioEncoder.js file
  2. Use the RedundantAudioEncoder.js file to generate RedundantAudioEncoderWorkerCode.ts
  3. Now build everything using npm run tsc:src so that the generated RedundantAudioEncoderWorkerCode.ts file also gets built and transpiled

So yes, we don't need this extra tsconfig file, but using the normal tsconfig.json would generate all of the built files for Step 1, then the RedundantAudioEncoderWorkerCode.ts file would be generated in Step 2, and then all of the files would be re-built again in Step 3. Having the separate config for RED was just a minor build time optimization so that we wouldn't be building all of the code twice during each npm run build.

Copy link
Contributor

@pracheth pracheth left a comment

Choose a reason for hiding this comment

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

Wondering if we should make these lines INFO rather than DEBUG while we're at it?

[DEBUG] ChimeLogger - [AudioRed] Initializing RedundantAudioEncoder
[DEBUG] ChimeLogger - [AudioRed] Setting up sender RED transform
[DEBUG] ChimeLogger - [AudioRed] Setting up receiver RED transform
[DEBUG] ChimeLogger - [AudioRed] red payload type set to 63
[DEBUG] ChimeLogger - [AudioRed] opus payload type set to 111

* This file was generated with the `generate-red-worker-code.js` script.
*/

export default class RedundantAudioEncoderWorkerCode {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we rename the folder to match with the file name (..workercode)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will make this change

@dinmin-amzn
Copy link
Contributor Author

Wondering if we should make these lines INFO rather than DEBUG while we're at it?

[DEBUG] ChimeLogger - [AudioRed] Initializing RedundantAudioEncoder
[DEBUG] ChimeLogger - [AudioRed] Setting up sender RED transform
[DEBUG] ChimeLogger - [AudioRed] Setting up receiver RED transform
[DEBUG] ChimeLogger - [AudioRed] red payload type set to 63
[DEBUG] ChimeLogger - [AudioRed] opus payload type set to 111

Yes, we should make these INFO level

pracheth
pracheth previously approved these changes Oct 6, 2023
pracheth
pracheth previously approved these changes Oct 6, 2023
]
}
`;
fs.writeFileSync(`${configDir}/${redTsconfig}`, redTsconfigContent);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, let me add it

fs.writeFileSync(`${configDir}/${redTsconfig}`, redTsconfigContent);

// Transpile `RedundantAudioEncoder.ts`.
const command = 'npx tsc --build config/tsconfig.red.json';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we not depend on npx and just use the local node_module path to tsc? otherwise you would need to update READM to install it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use local tsc from node_modules in latest push

…rker code stays intact and is able to be loaded

The redundant audio worker code string may vary based on the build system of different projects. Because of this, certain build systems will cause invalid worker code to be generated and the redundant audio worker will not be able to run. Now, the redundant audio worker code is saved at build time so that all clients can run the redundant audio worker with the same exact code, regardless of the client's build system.

This issue was originally found in #2771.
@dinmin-amzn dinmin-amzn merged commit 096edac into main Oct 9, 2023
10 checks passed
@dinmin-amzn dinmin-amzn deleted the avoid-red-regex branch October 9, 2023 17:09
dinmin-amzn added a commit that referenced this pull request Oct 9, 2023
…rker code stays intact and is able to be loaded (#2772)

The redundant audio worker code string may vary based on the build system of different projects. Because of this, certain build systems will cause invalid worker code to be generated and the redundant audio worker will not be able to run. Now, the redundant audio worker code is saved at build time so that all clients can run the redundant audio worker with the same exact code, regardless of the client's build system.

This issue was originally found in #2771.
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.

4 participants