Add "close()" method to MP Web Tasks
PiperOrigin-RevId: 527726737
This commit is contained in:
parent
b7e46ec528
commit
5e41d47f3a
|
@ -256,6 +256,11 @@ export abstract class TaskRunner {
|
|||
|
||||
this.baseOptions.setAcceleration(acceleration);
|
||||
}
|
||||
|
||||
/** Closes and cleans up the resources held by this task. */
|
||||
close(): void {
|
||||
this.graphRunner.closeGraph();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ export function createSpyWasmModule(): SpyWasmModule {
|
|||
'_setAutoRenderToScreen', 'stringToNewUTF8', '_attachProtoListener',
|
||||
'_attachProtoVectorListener', '_free', '_waitUntilIdle',
|
||||
'_addStringToInputStream', '_registerModelResourcesGraphService',
|
||||
'_configureAudio', '_malloc', '_addProtoToInputStream', '_getGraphConfig'
|
||||
'_configureAudio', '_malloc', '_addProtoToInputStream', '_getGraphConfig',
|
||||
'_closeGraph'
|
||||
]);
|
||||
spyWasmModule._getGraphConfig.and.callFake(() => {
|
||||
(spyWasmModule.simpleListeners![CALCULATOR_GRAPH_CONFIG_LISTENER_NAME] as
|
||||
|
|
|
@ -63,6 +63,7 @@ export declare interface WasmModule {
|
|||
_bindTextureToCanvas: () => boolean;
|
||||
_changeBinaryGraph: (size: number, dataPtr: number) => void;
|
||||
_changeTextGraph: (size: number, dataPtr: number) => void;
|
||||
_closeGraph: () => void;
|
||||
_free: (ptr: number) => void;
|
||||
_malloc: (size: number) => number;
|
||||
_processFrame: (width: number, height: number, timestamp: number) => void;
|
||||
|
@ -1148,6 +1149,16 @@ export class GraphRunner {
|
|||
finishProcessing(): void {
|
||||
this.wasmModule._waitUntilIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the input streams and all calculators for this graph and frees up
|
||||
* any C++ resources. The graph will not be usable once closed.
|
||||
*/
|
||||
closeGraph(): void {
|
||||
this.wasmModule._closeGraph();
|
||||
this.wasmModule.simpleListeners = undefined;
|
||||
this.wasmModule.emptyPacketListeners = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Quick private helper to run the given script safely
|
||||
|
|
Loading…
Reference in New Issue
Block a user