mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: chroma virtual background
parent
c0a525aac6
commit
a30f4dcd85
|
@ -22,6 +22,8 @@ import { Session } from './Session';
|
|||
import { StreamManager } from './StreamManager';
|
||||
import { Subscriber } from './Subscriber';
|
||||
import { VirtualBackgroundOptions } from '../OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions';
|
||||
import { VirtualBackgroundImageOptions } from '../OpenViduInternal/Interfaces/Public/VirtualBackgroundImageOptions';
|
||||
import { VirtualBackgroundChromaOptions } from '../OpenViduInternal/Interfaces/Public/VirtualBackgroundChromaOptions';
|
||||
import { InboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/InboundStreamOptions';
|
||||
import { OutboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/OutboundStreamOptions';
|
||||
import { WebRtcPeer, WebRtcPeerSendonly, WebRtcPeerRecvonly, WebRtcPeerSendrecv, WebRtcPeerConfiguration } from '../OpenViduInternal/WebRtcPeer/WebRtcPeer';
|
||||
|
@ -380,18 +382,24 @@ export class Stream {
|
|||
outputFramerate: 30
|
||||
});
|
||||
|
||||
const optionsVB = options as VirtualBackgroundOptions;
|
||||
|
||||
let response: { video: HTMLVideoElement, canvas: HTMLCanvasElement };
|
||||
switch (type) {
|
||||
case 'VB:blur': {
|
||||
const optionsVB = options as VirtualBackgroundOptions;
|
||||
response = await VB.backgroundBlur(optionsVB);
|
||||
break;
|
||||
}
|
||||
case 'VB:image': {
|
||||
const optionsVB = options as VirtualBackgroundImageOptions;
|
||||
response = await VB.backgroundImage(optionsVB);
|
||||
break;
|
||||
}
|
||||
case 'VB:chroma': {
|
||||
const optionsVB = options as VirtualBackgroundChromaOptions;
|
||||
response = await VB.backgroundChroma(optionsVB);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error('Unknown Virtual Background filter: ' + type);
|
||||
}
|
||||
|
@ -632,6 +640,11 @@ export class Stream {
|
|||
* @hidden
|
||||
*/
|
||||
disposeMediaStream(): void {
|
||||
if (!!this.filter && this.filter.type.startsWith('VB:')) {
|
||||
this.removeFilter()
|
||||
.then(() => console.debug(`Success removing Virtual Background filter for stream ${this.streamId}`))
|
||||
.catch(error => console.error(`Error removing Virtual Background filter for stream ${this.streamId}`, error));
|
||||
}
|
||||
if (this.mediaStream) {
|
||||
this.mediaStream.getAudioTracks().forEach((track) => {
|
||||
track.stop();
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* (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 { VirtualBackgroundImageOptions } from './VirtualBackgroundImageOptions';
|
||||
|
||||
/**
|
||||
* Options to apply to a Virtual Background Image filter. See [[Stream.applyFilter]]
|
||||
*/
|
||||
export interface VirtualBackgroundChromaOptions extends VirtualBackgroundImageOptions {
|
||||
/**
|
||||
* H component (Hue) range for the HSV chroma color. A pixel color must be inside this range to be replaced by the chroma filter
|
||||
*/
|
||||
chromaHRange: [number, number];
|
||||
/**
|
||||
* S component (Saturation) range for the HSV chroma color. A pixel color must be inside this range to be replaced by the chroma filter
|
||||
*/
|
||||
chromaSRange: [number, number];
|
||||
/**
|
||||
* V component (Value) range for the HSV chroma color. A pixel color must be inside this range to be replaced by the chroma filter
|
||||
*/
|
||||
chromaVRange: [number, number];
|
||||
/**
|
||||
* Whether to automatically detect the most probable chroma color or not
|
||||
*/
|
||||
chromaAuto: boolean;
|
||||
}
|
Loading…
Reference in New Issue