瀏覽代碼

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

j8
Tudor D. Pop 3 年之前
父節點
當前提交
d72b27d46d
No account linked to committer's email address

+ 26
- 25
react/features/stream-effects/virtual-background/JitsiStreamBackgroundEffect.js 查看文件

88
 
88
 
89
         const track = this._stream.getVideoTracks()[0];
89
         const track = this._stream.getVideoTracks()[0];
90
         const { height, width } = track.getSettings() ?? track.getConstraints();
90
         const { height, width } = track.getSettings() ?? track.getConstraints();
91
+        const { backgroundType } = this._options.virtualBackground;
91
 
92
 
92
         this._outputCanvasElement.height = height;
93
         this._outputCanvasElement.height = height;
93
         this._outputCanvasElement.width = width;
94
         this._outputCanvasElement.width = width;
94
         this._outputCanvasCtx.globalCompositeOperation = 'copy';
95
         this._outputCanvasCtx.globalCompositeOperation = 'copy';
95
 
96
 
96
         // Draw segmentation mask.
97
         // Draw segmentation mask.
97
-        //
98
 
98
 
99
         // Smooth out the edges.
99
         // Smooth out the edges.
100
-        if (this._options.virtualBackground.backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE) {
100
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.IMAGE) {
101
             this._outputCanvasCtx.filter = 'blur(4px)';
101
             this._outputCanvasCtx.filter = 'blur(4px)';
102
         } else {
102
         } else {
103
             this._outputCanvasCtx.filter = 'blur(8px)';
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
         this._outputCanvasCtx.drawImage(
113
         this._outputCanvasCtx.drawImage(
107
             this._segmentationMaskCanvas,
114
             this._segmentationMaskCanvas,
108
             0,
115
             0,
114
             this._inputVideoElement.width,
121
             this._inputVideoElement.width,
115
             this._inputVideoElement.height
122
             this._inputVideoElement.height
116
         );
123
         );
124
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
125
+            this._outputCanvasCtx.restore();
126
+        }
117
         this._outputCanvasCtx.globalCompositeOperation = 'source-in';
127
         this._outputCanvasCtx.globalCompositeOperation = 'source-in';
118
         this._outputCanvasCtx.filter = 'none';
128
         this._outputCanvasCtx.filter = 'none';
119
 
129
 
120
         // Draw the foreground video.
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
         this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);
139
         this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);
140
+        if (backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
141
+            this._outputCanvasCtx.restore();
142
+        }
124
 
143
 
125
         // Draw the background.
144
         // Draw the background.
126
-        //
127
 
145
 
128
         this._outputCanvasCtx.globalCompositeOperation = 'destination-over';
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
             this._outputCanvasCtx.drawImage(
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
                 0,
152
                 0,
149
                 0,
153
                 0,
150
                 this._outputCanvasElement.width,
154
                 this._outputCanvasElement.width,
151
                 this._outputCanvasElement.height
155
                 this._outputCanvasElement.height
152
             );
156
             );
153
-
154
-            // restore the canvas
155
-            this._outputCanvasCtx.restore();
156
         } else {
157
         } else {
157
             this._outputCanvasCtx.filter = `blur(${this._options.virtualBackground.blurValue}px)`;
158
             this._outputCanvasCtx.filter = `blur(${this._options.virtualBackground.blurValue}px)`;
158
             this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);
159
             this._outputCanvasCtx.drawImage(this._inputVideoElement, 0, 0);

+ 7
- 7
react/features/virtual-background/components/VirtualBackgroundDialog.js 查看文件

188
         if (storedImages.length === backgroundsLimit) {
188
         if (storedImages.length === backgroundsLimit) {
189
             setStoredImages(storedImages.slice(1));
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
     const enableBlur = useCallback(async () => {
194
     const enableBlur = useCallback(async () => {
390
         setLoading(true);
385
         setLoading(true);
391
         await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
386
         await dispatch(toggleBackgroundEffect(options, _jitsiTrack));
392
         await setLoading(false);
387
         await setLoading(false);
388
+        if (_localFlipX && options.backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
389
+            dispatch(updateSettings({
390
+                localFlipX: !_localFlipX
391
+            }));
392
+        }
393
         dispatch(hideDialog());
393
         dispatch(hideDialog());
394
-    }, [ dispatch, options ]);
394
+    }, [ dispatch, options, _localFlipX ]);
395
 
395
 
396
     // Prevent the selection of a new virtual background if it has not been applied by default
396
     // Prevent the selection of a new virtual background if it has not been applied by default
397
     const cancelVirtualBackground = useCallback(async () => {
397
     const cancelVirtualBackground = useCallback(async () => {

+ 1
- 1
react/features/virtual-background/components/VirtualBackgroundPreview.js 查看文件

13
 import { VIRTUAL_BACKGROUND_TYPE } from '../constants';
13
 import { VIRTUAL_BACKGROUND_TYPE } from '../constants';
14
 import { localTrackStopped } from '../functions';
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
  * The type of the React {@code PureComponent} props of {@link VirtualBackgroundPreview}.
19
  * The type of the React {@code PureComponent} props of {@link VirtualBackgroundPreview}.

Loading…
取消
儲存