Internal change

PiperOrigin-RevId: 518747623
This commit is contained in:
Sebastian Schmidt
2023-03-22 20:44:34 -07:00
committed by Copybara-Service
parent 37111e8fa5
commit 1a7be8a4c1
8 changed files with 123 additions and 4 deletions
@@ -36,6 +36,17 @@ export type EmptyPacketListener = (timestamp: number) => void;
export type VectorListener<T> = (data: T, done: boolean, timestamp: number) =>
void;
/**
* A listener that receives the CalculatorGraphConfig in binary encoding.
*/
export type CalculatorGraphConfigListener = (graphConfig: Uint8Array) => void;
/**
* The name of the internal listener that we use to obtain the calculator graph
* config. Intended for internal usage. Exported for testing only.
*/
export const CALCULATOR_GRAPH_CONFIG_LISTENER_NAME = '__graph_config__';
/**
* Declarations for Emscripten's WebAssembly Module behavior, so TS compiler
* doesn't break our JS/C++ bridge.
@@ -124,6 +135,10 @@ export declare interface WasmModule {
_configureAudio: (channels: number, samples: number, sampleRate: number,
streamNamePtr: number, headerNamePtr: number) => void;
// Get the graph configuration and invoke the listener configured under
// streamNamePtr
_getGraphConfig: (streamNamePtr: number, makeDeepCopy?: boolean) => void;
// TODO: Refactor to just use a few numbers (perhaps refactor away
// from gl_graph_runner_internal.cc entirely to use something a little more
// streamlined; new version is _processFrame above).
@@ -437,6 +452,29 @@ export class GraphRunner {
this.wasmModule._free(heapSpace);
}
/**
* Invokes the callback with the current calculator configuration (in binary
* format).
*
* Consumers must deserialize the binary representation themselves as this
* avoids addding a direct dependency on the Protobuf JSPB target in the graph
* library.
*/
getCalculatorGraphConfig(
callback: CalculatorGraphConfigListener, makeDeepCopy?: boolean): void {
const listener = CALCULATOR_GRAPH_CONFIG_LISTENER_NAME;
// Create a short-lived listener to receive the binary encoded proto
this.setListener(listener, (data: Uint8Array) => {
callback(data);
});
this.wrapStringPtr(listener, (outputStreamNamePtr: number) => {
this.wasmModule._getGraphConfig(outputStreamNamePtr, makeDeepCopy);
});
delete this.wasmModule.simpleListeners![listener];
}
/**
* Ensures existence of the simple listeners table and registers the callback.
* Intended for internal usage.