@stream-io/video-filters-web 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { TFLite } from '../tflite';
2
2
  import { SegmentationParams } from '../segmentation';
3
- export declare function buildResizingStage(gl: WebGL2RenderingContext, vertexShader: WebGLShader, positionBuffer: WebGLBuffer, texCoordBuffer: WebGLBuffer, tflite: TFLite, segmentationConfig: SegmentationParams): {
3
+ export declare function buildResizingStage(gl: WebGL2RenderingContext, vertexShader: WebGLShader, positionBuffer: WebGLBuffer, texCoordBuffer: WebGLBuffer, tflite: TFLite, segmentationConfig: SegmentationParams, onError?: (error: any) => void): {
4
4
  render: () => void;
5
5
  cleanUp: () => void;
6
6
  };
@@ -1,7 +1,7 @@
1
1
  import { TFLite } from '../tflite';
2
2
  import { BackgroundBlurLevel, BackgroundFilter } from '../createRenderer';
3
3
  import { SegmentationParams } from '../segmentation';
4
- export declare function buildWebGL2Pipeline(videoSource: HTMLVideoElement, backgroundImage: HTMLImageElement | undefined, blurLevel: BackgroundBlurLevel | undefined, backgroundFilter: BackgroundFilter, canvas: HTMLCanvasElement, tflite: TFLite, segmentationConfig: SegmentationParams): {
4
+ export declare function buildWebGL2Pipeline(videoSource: HTMLVideoElement, backgroundImage: HTMLImageElement | undefined, blurLevel: BackgroundBlurLevel | undefined, backgroundFilter: BackgroundFilter, canvas: HTMLCanvasElement, tflite: TFLite, segmentationConfig: SegmentationParams, onError?: (error: any) => void): {
5
5
  render: () => void;
6
6
  updatePostProcessingConfig: () => void;
7
7
  cleanUp: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stream-io/video-filters-web",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "packageManager": "yarn@3.5.0",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "module": "./dist/index.es.js",
@@ -111,8 +111,10 @@ async function getBufferSubDataAsync(
111
111
  dstOffset?: number,
112
112
  length?: number,
113
113
  ) {
114
- const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0)!;
114
+ const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
115
115
  gl.flush();
116
+ if (!sync) return;
117
+
116
118
  const res = await clientWaitAsync(gl, sync);
117
119
  gl.deleteSync(sync);
118
120
 
@@ -15,6 +15,7 @@ export function buildResizingStage(
15
15
  texCoordBuffer: WebGLBuffer,
16
16
  tflite: TFLite,
17
17
  segmentationConfig: SegmentationParams,
18
+ onError?: (error: any) => void,
18
19
  ) {
19
20
  const fragmentShaderSource = glsl`#version 300 es
20
21
 
@@ -81,7 +82,9 @@ export function buildResizingStage(
81
82
  gl.RGBA,
82
83
  gl.UNSIGNED_BYTE,
83
84
  outputPixels,
84
- );
85
+ ).catch((error: any) => {
86
+ onError?.(error);
87
+ });
85
88
 
86
89
  for (let i = 0; i < outputPixelCount; i++) {
87
90
  const tfliteIndex = tfliteInputMemoryOffset + i * 3;
@@ -22,6 +22,7 @@ export function buildWebGL2Pipeline(
22
22
  canvas: HTMLCanvasElement,
23
23
  tflite: TFLite,
24
24
  segmentationConfig: SegmentationParams,
25
+ onError?: (error: any) => void,
25
26
  ) {
26
27
  const gl = canvas.getContext('webgl2')!;
27
28
  if (!gl) throw new Error('WebGL2 is not supported');
@@ -95,6 +96,7 @@ export function buildWebGL2Pipeline(
95
96
  texCoordBuffer,
96
97
  tflite,
97
98
  segmentationConfig,
99
+ onError,
98
100
  );
99
101
  const loadSegmentationStage = buildSoftmaxStage(
100
102
  gl,