Open Source the remaining Web implementation files
PiperOrigin-RevId: 486701932
This commit is contained in:
committed by
Copybara-Service
parent
c02f3933d4
commit
2371051e17
@@ -0,0 +1,41 @@
|
||||
# The TypeScript graph runner used by all MediaPipe Web tasks.
|
||||
|
||||
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",
|
||||
srcs = [
|
||||
":wasm_mediapipe_lib.ts",
|
||||
],
|
||||
allow_unoptimized_namespaces = True,
|
||||
)
|
||||
|
||||
mediapipe_ts_library(
|
||||
name = "wasm_mediapipe_image_lib_ts",
|
||||
srcs = [
|
||||
":wasm_mediapipe_image_lib.ts",
|
||||
],
|
||||
allow_unoptimized_namespaces = True,
|
||||
deps = [":wasm_mediapipe_lib_ts"],
|
||||
)
|
||||
|
||||
mediapipe_ts_library(
|
||||
name = "register_model_resources_graph_service_ts",
|
||||
srcs = [
|
||||
":register_model_resources_graph_service.ts",
|
||||
],
|
||||
allow_unoptimized_namespaces = True,
|
||||
deps = [":wasm_mediapipe_lib_ts"],
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
import {WasmMediaPipeLib} from './wasm_mediapipe_lib';
|
||||
|
||||
/**
|
||||
* We extend from a WasmMediaPipeLib 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;
|
||||
|
||||
/**
|
||||
* Declarations for Emscripten's WebAssembly Module behavior, so TS compiler
|
||||
* doesn't break our JS/C++ bridge.
|
||||
*/
|
||||
export declare interface WasmModuleRegisterModelResources {
|
||||
_registerModelResourcesGraphService: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of WasmMediaPipeLib 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);`
|
||||
*/
|
||||
// tslint:disable:enforce-name-casing
|
||||
export function SupportModelResourcesGraphService<TBase extends LibConstructor>(
|
||||
Base: TBase) {
|
||||
return class extends Base {
|
||||
// tslint:enable:enforce-name-casing
|
||||
/**
|
||||
* Instructs the graph runner to use the model resource caching graph
|
||||
* service for both graph expansion/inintialization, as well as for graph
|
||||
* run.
|
||||
*/
|
||||
registerModelResourcesGraphService(): void {
|
||||
(this.wasmModule as unknown as WasmModuleRegisterModelResources)
|
||||
._registerModelResourcesGraphService();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import {ImageSource, WasmMediaPipeLib} from './wasm_mediapipe_lib';
|
||||
|
||||
/**
|
||||
* We extend from a WasmMediaPipeLib 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;
|
||||
|
||||
/**
|
||||
* Declarations for Emscripten's WebAssembly Module behavior, so TS compiler
|
||||
* doesn't break our JS/C++ bridge.
|
||||
*/
|
||||
export declare interface WasmImageModule {
|
||||
_addBoundTextureAsImageToStream:
|
||||
(streamNamePtr: number, width: number, height: number,
|
||||
timestamp: number) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* An implementation of WasmMediaPipeLib 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);`
|
||||
*/
|
||||
// tslint:disable-next-line:enforce-name-casing
|
||||
export function SupportImage<TBase extends LibConstructor>(Base: TBase) {
|
||||
return class extends Base {
|
||||
/**
|
||||
* Takes the relevant information from the HTML video or image element, and
|
||||
* passes it into the WebGL-based graph for processing on the given stream
|
||||
* at the given timestamp as a MediaPipe image. Processing will not occur
|
||||
* until a blocking call (like processVideoGl or finishProcessing) is made.
|
||||
* @param imageSource Reference to the video frame we wish to add into our
|
||||
* graph.
|
||||
* @param streamName The name of the MediaPipe graph stream to add the frame
|
||||
* to.
|
||||
* @param timestamp The timestamp of the input frame, in ms.
|
||||
*/
|
||||
addGpuBufferAsImageToStream(
|
||||
imageSource: ImageSource, streamName: string, timestamp: number): void {
|
||||
this.wrapStringPtr(streamName, (streamNamePtr: number) => {
|
||||
const [width, height] =
|
||||
this.bindTextureToStream(imageSource, streamNamePtr);
|
||||
(this.wasmModule as unknown as WasmImageModule)
|
||||
._addBoundTextureAsImageToStream(
|
||||
streamNamePtr, width, height, timestamp);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user