Bläddra i källkod

fix(virtual-background): Fix mirror behavior for remote participants.

j8
Tudor D. Pop 3 år sedan
förälder
incheckning
d72b27d46d
Inget konto är kopplat till bidragsgivarens mejladress

+ 26
- 25
react/features/stream-effects/virtual-background/JitsiStreamBackgroundEffect.js Visa fil

@@ -88,21 +88,28 @@ export default class JitsiStreamBackgroundEffect {
88 88
 
89 89
         const track = this._stream.getVideoTracks()[0];
90 90
         const { height, width } = track.getSettings() ?? track.getConstraints();
91
+        const { backgroundType } = this._options.virtualBackground;
91 92
 
92 93
         this._outputCanvasElement.height = height;
93 94
         this._outputCanvasElement.width = width;
94 95
         this._outputCanvasCtx.globalCompositeOperation = 'copy';
95 96
 
96 97
         // Draw segmentation mask.
97
-        //
98 98
 
99 99
         // Smooth out the edges.
100
-        if (this._options.virtualBackground.backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE) {
100
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE) {
101 101
             this._outputCanvasCtx.filter = 'blur(4px)';
102 102
         } else {
103 103
             this._outputCanvasCtx.filter = 'blur(8px)';
104 104
         }
105
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
106
+            // Save current context before applying transformations.
107
+            this._outputCanvasCtx.save();
105 108
 
109
+            // Flip the canvas and prevent mirror behaviour.
110
+            this._outputCanvasCtx.scale(-1, 1);
111
+            this._outputCanvasCtx.translate(-this._outputCanvasElement.width, 0);
112
+        }
106 113
         this._outputCanvasCtx.drawImage(
107 114
             this._segmentationMaskCanvas,
108 115
             0,
@@ -114,45 +121,39 @@ export default class JitsiStreamBackgroundEffect {
114 121
             this._inputVideoElement.width,
115 122
             this._inputVideoElement.height
116 123
         );
124
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
125
+            this._outputCanvasCtx.restore();
126
+        }
117 127
         this._outputCanvasCtx.globalCompositeOperation = 'source-in';
118 128
         this._outputCanvasCtx.filter = 'none';
119 129
 
120 130
         // Draw the foreground video.
121
-        //
131
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
132
+            // Save current context before applying transformations.
133
+            this._outputCanvasCtx.save();
122 134
 
135
+            // Flip the canvas and prevent mirror behaviour.
136
+            this._outputCanvasCtx.scale(-1, 1);
137
+            this._outputCanvasCtx.translate(-this._outputCanvasElement.width, 0);
138
+        }
123 139
         this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);
140
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
141
+            this._outputCanvasCtx.restore();
142
+        }
124 143
 
125 144
         // Draw the background.
126
-        //
127 145
 
128 146
         this._outputCanvasCtx.globalCompositeOperation = 'destination-over';
129
-        if (this._options.virtualBackground.backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE) {
147
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE
148
+            || backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
130 149
             this._outputCanvasCtx.drawImage(
131
-                this._virtualImage,
132
-                0,
133
-                0,
134
-                this._inputVideoElement.width,
135
-                this._inputVideoElement.height
136
-            );
137
-        }
138
-        if (this._options.virtualBackground.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
139
-
140
-            // save current context before applying transformations
141
-            this._outputCanvasCtx.save();
142
-
143
-            // flip the canvas and prevent mirror behaviour
144
-            this._outputCanvasCtx.scale(-1, 1);
145
-            this._outputCanvasCtx.translate(-this._outputCanvasElement.width, 0);
146
-            this._outputCanvasCtx.drawImage(
147
-                this._virtualVideo,
150
+                backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE
151
+                    ? this._virtualImage : this._virtualVideo,
148 152
                 0,
149 153
                 0,
150 154
                 this._outputCanvasElement.width,
151 155
                 this._outputCanvasElement.height
152 156
             );
153
-
154
-            // restore the canvas
155
-            this._outputCanvasCtx.restore();
156 157
         } else {
157 158
             this._outputCanvasCtx.filter = `blur(${this._options.virtualBackground.blurValue}px)`;
158 159
             this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);

+ 7
- 7
react/features/virtual-background/components/VirtualBackgroundDialog.js Visa fil

@@ -188,12 +188,7 @@ function VirtualBackground({
188 188
         if (storedImages.length === backgroundsLimit) {
189 189
             setStoredImages(storedImages.slice(1));
190 190
         }
191
-        if (!_localFlipX) {
192
-            dispatch(updateSettings({
193
-                localFlipX: !_localFlipX
194
-            }));
195
-        }
196
-    }, [ storedImages, _localFlipX ]);
191
+    }, [ storedImages ]);
197 192
 
198 193
 
199 194
     const enableBlur = useCallback(async () => {
@@ -390,8 +385,13 @@ function VirtualBackground({
390 385
         setLoading(true);
391 386
         await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
392 387
         await setLoading(false);
388
+        if (_localFlipX && options.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
389
+            dispatch(updateSettings({
390
+                localFlipX: !_localFlipX
391
+            }));
392
+        }
393 393
         dispatch(hideDialog());
394
-    }, [ dispatch, options ]);
394
+    }, [ dispatch, options, _localFlipX ]);
395 395
 
396 396
     // Prevent the selection of a new virtual background if it has not been applied by default
397 397
     const cancelVirtualBackground = useCallback(async () => {

+ 1
- 1
react/features/virtual-background/components/VirtualBackgroundPreview.js Visa fil

@@ -13,7 +13,7 @@ import { toggleBackgroundEffect } from '../actions';
13 13
 import { VIRTUAL_BACKGROUND_TYPE } from '../constants';
14 14
 import { localTrackStopped } from '../functions';
15 15
 
16
-const videoClassName = 'video-preview-video flipVideoX';
16
+const videoClassName = 'video-preview-video';
17 17
 
18 18
 /**
19 19
  * The type of the React {@code PureComponent} props of {@link VirtualBackgroundPreview}.

Laddar…
Avbryt
Spara