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

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // @flow
  2. import { load } from '@tensorflow-models/body-pix';
  3. import * as tfc from '@tensorflow/tfjs-core';
  4. import JitsiStreamBlurEffect from './JitsiStreamBlurEffect';
  5. /**
  6. * This promise represents the loading of the BodyPix model that is used
  7. * to extract person segmentation. A multiplier of 0.25 is used to for
  8. * improved performance on a larger range of CPUs.
  9. */
  10. const bpModelPromise = load(0.25);
  11. /**
  12. * Configure the Tensor Flow model to use the webgl backend which is the
  13. * most powerful backend for the browser.
  14. */
  15. const webGlBackend = 'webgl';
  16. /**
  17. * Creates a new instance of JitsiStreamBlurEffect.
  18. *
  19. * @returns {Promise<JitsiStreamBlurEffect>}
  20. */
  21. export function createBlurEffect() {
  22. if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
  23. return Promise.reject(new Error('JitsiStreamBlurEffect not supported!'));
  24. }
  25. const setBackendPromise = new Promise((resolve, reject) => {
  26. if (tfc.getBackend() === webGlBackend) {
  27. resolve();
  28. return;
  29. }
  30. return tfc.setBackend(webGlBackend)
  31. .then(resolve, reject);
  32. });
  33. return setBackendPromise
  34. .then(() => bpModelPromise)
  35. .then(bpmodel => new JitsiStreamBlurEffect(bpmodel));
  36. }