Adds a public function for creating TaskRunner instances.

PiperOrigin-RevId: 493109736
This commit is contained in:
MediaPipe Team 2022-12-05 14:14:13 -08:00 committed by Copybara-Service
parent 4f8eaee20f
commit 69b27b246a

View File

@ -32,19 +32,13 @@ const GraphRunnerImageLibType =
/** An implementation of the GraphRunner that supports image operations */
export class GraphRunnerImageLib extends GraphRunnerImageLibType {}
/** Base class for all MediaPipe Tasks. */
export abstract class TaskRunner<O extends TaskRunnerOptions> {
protected abstract baseOptions: BaseOptionsProto;
protected graphRunner: GraphRunnerImageLib;
private processingErrors: Error[] = [];
/**
* Creates a new instance of a Mediapipe Task. Determines if SIMD is
* supported and loads the relevant WASM binary.
* @return A fully instantiated instance of `T`.
*/
protected static async createInstance<T extends TaskRunner<O>,
O extends TaskRunnerOptions>(
export async function
createTaskRunner<T extends TaskRunner<O>, O extends TaskRunnerOptions>(
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
fileset: WasmFileset, options: O): Promise<T> {
const fileLocator: FileLocator = {
@ -66,6 +60,24 @@ export abstract class TaskRunner<O extends TaskRunnerOptions> {
return instance;
}
/** Base class for all MediaPipe Tasks. */
export abstract class TaskRunner<O extends TaskRunnerOptions> {
protected abstract baseOptions: BaseOptionsProto;
protected graphRunner: GraphRunnerImageLib;
private processingErrors: Error[] = [];
/**
* Creates a new instance of a Mediapipe Task. Determines if SIMD is
* supported and loads the relevant WASM binary.
* @return A fully instantiated instance of `T`.
*/
protected static async createInstance<T extends TaskRunner<O>,
O extends TaskRunnerOptions>(
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
fileset: WasmFileset, options: O): Promise<T> {
return createTaskRunner(type, initializeCanvas, fileset, options);
}
constructor(
wasmModule: WasmModule,
glCanvas?: HTMLCanvasElement|OffscreenCanvas|null) {