Internal change

PiperOrigin-RevId: 489345940
This commit is contained in:
MediaPipe Team
2022-11-17 17:16:25 -08:00
committed by Copybara-Service
parent ab3a5f0fbf
commit 6f3cb340e1
24 changed files with 46 additions and 54 deletions
+6 -14
View File
@@ -3,32 +3,24 @@
load("//mediapipe/framework/port:build_config.bzl", "mediapipe_ts_library")
package(default_visibility = [
":internal",
"//mediapipe/tasks:internal",
])
package_group(
name = "internal",
packages = [
"//mediapipe/app/pursuit/wasm/web_ml_cpu/typescript/...",
],
)
mediapipe_ts_library(
name = "wasm_mediapipe_lib_ts",
name = "graph_runner_ts",
srcs = [
":wasm_mediapipe_lib.ts",
":graph_runner.ts",
],
allow_unoptimized_namespaces = True,
)
mediapipe_ts_library(
name = "wasm_mediapipe_image_lib_ts",
name = "graph_runner_image_lib_ts",
srcs = [
":wasm_mediapipe_image_lib.ts",
":graph_runner_image_lib.ts",
],
allow_unoptimized_namespaces = True,
deps = [":wasm_mediapipe_lib_ts"],
deps = [":graph_runner_ts"],
)
mediapipe_ts_library(
@@ -37,5 +29,5 @@ mediapipe_ts_library(
":register_model_resources_graph_service.ts",
],
allow_unoptimized_namespaces = True,
deps = [":wasm_mediapipe_lib_ts"],
deps = [":graph_runner_ts"],
)
@@ -129,7 +129,7 @@ declare global {
declare function importScripts(...urls: Array<string|URL>): void;
/**
* Valid types of image sources which we can run our WasmMediaPipeLib over.
* Valid types of image sources which we can run our GraphRunner over.
*/
export type ImageSource =
HTMLCanvasElement|HTMLVideoElement|HTMLImageElement|ImageData|ImageBitmap;
@@ -138,7 +138,7 @@ export type ImageSource =
/** A listener that will be invoked with an absl::StatusCode and message. */
export type ErrorListener = (code: number, message: string) => void;
// Internal type of constructors used for initializing WasmMediaPipeLib and
// Internal type of constructors used for initializing GraphRunner and
// subclasses.
type WasmMediaPipeConstructor<LibType> =
(new (
@@ -151,7 +151,7 @@ type WasmMediaPipeConstructor<LibType> =
* into canvas, or else return the output WebGLTexture. Takes a WebAssembly
* Module (must be instantiated to self.Module).
*/
export class WasmMediaPipeLib {
export class GraphRunner {
// TODO: These should be protected/private, but are left exposed for
// now so that we can use proper TS mixins with this class as a base. This
// should be somewhat fixed when we create our .d.ts files.
@@ -989,7 +989,7 @@ async function runScript(scriptUrl: string) {
/**
* Global function to initialize Wasm blob and load runtime assets for a
* specialized MediaPipe library. This allows us to create a requested
* subclass inheriting from WasmMediaPipeLib.
* subclass inheriting from GraphRunner.
* @param constructorFcn The name of the class to instantiate via "new".
* @param wasmLoaderScript Url for the wasm-runner script; produced by the build
* process.
@@ -1043,12 +1043,12 @@ export async function createMediaPipeLib<LibType>(
* @return promise A promise which will resolve when initialization has
* completed successfully.
*/
export async function createWasmMediaPipeLib(
export async function createGraphRunner(
wasmLoaderScript?: string,
assetLoaderScript?: string,
glCanvas?: HTMLCanvasElement|OffscreenCanvas|null,
fileLocator?: FileLocator): Promise<WasmMediaPipeLib> {
fileLocator?: FileLocator): Promise<GraphRunner> {
return createMediaPipeLib(
WasmMediaPipeLib, wasmLoaderScript, assetLoaderScript, glCanvas,
GraphRunner, wasmLoaderScript, assetLoaderScript, glCanvas,
fileLocator);
}
@@ -1,12 +1,12 @@
import {ImageSource, WasmMediaPipeLib} from './wasm_mediapipe_lib';
import {ImageSource, GraphRunner} from './graph_runner';
/**
* We extend from a WasmMediaPipeLib constructor. This ensures our mixin has
* We extend from a GraphRunner constructor. This ensures our mixin has
* access to the wasmModule, among other things. The `any` type is required for
* mixin constructors.
*/
// tslint:disable-next-line:no-any
type LibConstructor = new (...args: any[]) => WasmMediaPipeLib;
type LibConstructor = new (...args: any[]) => GraphRunner;
/**
* Declarations for Emscripten's WebAssembly Module behavior, so TS compiler
@@ -19,10 +19,10 @@ export declare interface WasmImageModule {
}
/**
* An implementation of WasmMediaPipeLib that supports binding GPU image data as
* An implementation of GraphRunner that supports binding GPU image data as
* `mediapipe::Image` instances. We implement as a proper TS mixin, to allow for
* effective multiple inheritance. Example usage:
* `const WasmMediaPipeImageLib = SupportImage(WasmMediaPipeLib);`
* `const WasmMediaPipeImageLib = SupportImage(GraphRunner);`
*/
// tslint:disable-next-line:enforce-name-casing
export function SupportImage<TBase extends LibConstructor>(Base: TBase) {
@@ -1,12 +1,12 @@
import {WasmMediaPipeLib} from './wasm_mediapipe_lib';
import {GraphRunner} from './graph_runner';
/**
* We extend from a WasmMediaPipeLib constructor. This ensures our mixin has
* We extend from a GraphRunner constructor. This ensures our mixin has
* access to the wasmModule, among other things. The `any` type is required for
* mixin constructors.
*/
// tslint:disable-next-line:no-any
type LibConstructor = new (...args: any[]) => WasmMediaPipeLib;
type LibConstructor = new (...args: any[]) => GraphRunner;
/**
* Declarations for Emscripten's WebAssembly Module behavior, so TS compiler
@@ -17,11 +17,11 @@ export declare interface WasmModuleRegisterModelResources {
}
/**
* An implementation of WasmMediaPipeLib that supports registering model
* An implementation of GraphRunner that supports registering model
* resources to a cache, in the form of a GraphService C++-side. We implement as
* a proper TS mixin, to allow for effective multiple inheritance. Sample usage:
* `const WasmMediaPipeImageLib = SupportModelResourcesGraphService(
* WasmMediaPipeLib);`
* GraphRunner);`
*/
// tslint:disable:enforce-name-casing
export function SupportModelResourcesGraphService<TBase extends LibConstructor>(