You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // @flow
  2. import * as wasmCheck from 'wasm-check';
  3. import JitsiStreamBlurEffect from './JitsiStreamBlurEffect';
  4. import createTFLiteModule from './vendor/tflite/tflite';
  5. import createTFLiteSIMDModule from './vendor/tflite/tflite-simd';
  6. const models = {
  7. '96': 'libs/segm_lite_v681.tflite',
  8. '144': 'libs/segm_full_v679.tflite'
  9. };
  10. /**
  11. * Creates a new instance of JitsiStreamBlurEffect. This loads the bodyPix model that is used to
  12. * extract person segmentation.
  13. *
  14. * @returns {Promise<JitsiStreamBlurEffect>}
  15. */
  16. export async function createBlurEffect() {
  17. if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
  18. throw new Error('JitsiStreamBlurEffect not supported!');
  19. }
  20. let tflite;
  21. if (wasmCheck.feature.simd) {
  22. tflite = await createTFLiteSIMDModule();
  23. } else {
  24. tflite = await createTFLiteModule();
  25. }
  26. const modelBufferOffset = tflite._getModelBufferMemoryOffset();
  27. const modelResponse = await fetch(
  28. models['144']
  29. );
  30. if (!modelResponse.ok) {
  31. throw new Error('Failed to download tflite model!');
  32. }
  33. const model = await modelResponse.arrayBuffer();
  34. tflite.HEAPU8.set(new Uint8Array(model), modelBufferOffset);
  35. tflite._loadModel(model.byteLength);
  36. return new JitsiStreamBlurEffect(tflite);
  37. }