openvidu-browser: input options for Virtual Background

pull/713/head
pabloFuente 2022-04-06 13:39:54 +02:00
parent 841db74c75
commit e9cdb7b131
3 changed files with 74 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import { Publisher } from './Publisher';
import { Session } from './Session'; import { Session } from './Session';
import { StreamManager } from './StreamManager'; import { StreamManager } from './StreamManager';
import { Subscriber } from './Subscriber'; import { Subscriber } from './Subscriber';
import { VirtualBackgroundOptions } from '../OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions';
import { InboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/InboundStreamOptions'; import { InboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/InboundStreamOptions';
import { OutboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/OutboundStreamOptions'; import { OutboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/OutboundStreamOptions';
import { WebRtcPeer, WebRtcPeerSendonly, WebRtcPeerRecvonly, WebRtcPeerSendrecv, WebRtcPeerConfiguration } from '../OpenViduInternal/WebRtcPeer/WebRtcPeer'; import { WebRtcPeer, WebRtcPeerSendonly, WebRtcPeerRecvonly, WebRtcPeerSendrecv, WebRtcPeerConfiguration } from '../OpenViduInternal/WebRtcPeer/WebRtcPeer';
@ -378,11 +379,10 @@ export class Stream {
inputResolution: '160x96', inputResolution: '160x96',
outputFramerate: 30 outputFramerate: 30
}); });
const response: { video: HTMLVideoElement, canvas: HTMLCanvasElement } = await VB.backgroundBlur({
maskRadius: 0.1, const optionsVB = options as VirtualBackgroundOptions;
backgroundCoverage: 0.6,
lightWrapping: 0.3 const response: { video: HTMLVideoElement, canvas: HTMLCanvasElement } = await VB.backgroundBlur(optionsVB);
});
this.virtualBackgroundSinkElements = { VB, ...response }; this.virtualBackgroundSinkElements = { VB, ...response };
videoClone.style.display = 'none'; videoClone.style.display = 'none';

View File

@ -0,0 +1,28 @@
/*
* (C) Copyright 2017-2022 OpenVidu (https://openvidu.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import { VirtualBackgroundOptions } from './VirtualBackgroundOptions';
/**
* See [[Stream.applyFilter]]
*/
export interface VirtualBackgroundImageOptions extends VirtualBackgroundOptions {
/**
* URL to the image asset to be used as background
*/
url: string;
}

View File

@ -0,0 +1,41 @@
/*
* (C) Copyright 2017-2022 OpenVidu (https://openvidu.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* See [[Stream.applyFilter]]
*/
export interface VirtualBackgroundOptions {
/**
* Radius of the effect. Higher values mean less defined edges but a smoother transition between the person's mask and
* the background. Number between [0, 1] with 2 decimals
*/
maskRadius?: number;
/**
* Amplitude of the space between the person's mask and the background. Higher values mean the effect will be applied
* more tightly to the person's mask, but this may cause loss of pixel information of the person. Lower values mean the
* effect will be applied further from the person's mask, granting a full view of the person but at the cost of the accuracy
* of the person's mask. Number between [0, 1] with 2 decimals
*/
backgroundCoverage?: number;
/**
* Blends the background with the person's mask with a light effect. Higher values mean a more aggressive light blending
* Number between [0, 1] with 2 decimals
*/
lightWrapping?: number;
}