소스 검색

ref(large-video): permanently enable canvas based background (#3084)

* ref(large-video): permanently enable canvas based background

* squash: leave flag for disabling background
master
virtuacoplenny 6 년 전
부모
커밋
4ab8d98cd1

+ 7
- 11
interface_config.js 파일 보기

@@ -5,6 +5,12 @@ var interfaceConfig = {
5 5
     // methods allowing to use variables both in css and js.
6 6
     DEFAULT_BACKGROUND: '#474747',
7 7
 
8
+    /**
9
+     * Whether or not the blurred video background for large video should be
10
+     * displayed on browsers that can support it.
11
+     */
12
+    DISABLE_VIDEO_BACKGROUND: false,
13
+
8 14
     INITIAL_TOOLBAR_TIMEOUT: 20000,
9 15
     TOOLBAR_TIMEOUT: 4000,
10 16
     TOOLBAR_ALWAYS_VISIBLE: false,
@@ -142,17 +148,7 @@ var interfaceConfig = {
142 148
      *
143 149
      * @type {boolean}
144 150
      */
145
-    VIDEO_QUALITY_LABEL_DISABLED: false,
146
-
147
-    /**
148
-     * Temporary feature flag to debug performance with the large video
149
-     * background blur. On initial implementation, blur was always enabled so a
150
-     * falsy value here will be used to keep blur enabled, as will the value
151
-     * "video", and will render the blur over a video element. The value
152
-     * "canvas" will display the blur over a canvas element, while the value
153
-     * "off" will prevent the background from rendering.
154
-     */
155
-    _BACKGROUND_BLUR: 'canvas'
151
+    VIDEO_QUALITY_LABEL_DISABLED: false
156 152
 
157 153
     /**
158 154
      * Specify custom URL for downloading android mobile app.

+ 5
- 10
modules/UI/videolayout/VideoContainer.js 파일 보기

@@ -7,8 +7,7 @@ import ReactDOM from 'react-dom';
7 7
 import { browser } from '../../../react/features/base/lib-jitsi-meet';
8 8
 import {
9 9
     ORIENTATION,
10
-    LargeVideoBackground,
11
-    LargeVideoBackgroundCanvas
10
+    LargeVideoBackground
12 11
 } from '../../../react/features/large-video';
13 12
 /* eslint-enable no-unused-vars */
14 13
 
@@ -689,21 +688,17 @@ export class VideoContainer extends LargeContainer {
689 688
      */
690 689
     _updateBackground() {
691 690
         // Do not the background display on browsers that might experience
692
-        // performance issues from the presence of the background.
693
-        if (interfaceConfig._BACKGROUND_BLUR === 'off'
691
+        // performance issues from the presence of the background or if
692
+        // explicitly disabled.
693
+        if (interfaceConfig.DISABLE_VIDEO_BACKGROUND
694 694
                 || browser.isFirefox()
695 695
                 || browser.isSafariWithWebrtc()
696 696
                 || browser.isTemasysPluginUsed()) {
697 697
             return;
698 698
         }
699 699
 
700
-        // eslint-disable-next-line no-unused-vars
701
-        const Background = interfaceConfig._BACKGROUND_BLUR === 'canvas'
702
-            ? LargeVideoBackgroundCanvas
703
-            : LargeVideoBackground;
704
-
705 700
         ReactDOM.render(
706
-            <Background
701
+            <LargeVideoBackground
707 702
                 hidden = { this._hideBackground }
708 703
                 mirror = {
709 704
                     this.stream

+ 190
- 59
react/features/large-video/components/LargeVideoBackground.web.js 파일 보기

@@ -1,7 +1,6 @@
1
-import PropTypes from 'prop-types';
2
-import React, { Component } from 'react';
1
+// @flow
3 2
 
4
-import { Video } from '../../base/media';
3
+import React, { Component } from 'react';
5 4
 
6 5
 /**
7 6
  * Constants to describe the dimensions of the video. Landscape videos
@@ -23,66 +22,125 @@ export const ORIENTATION = {
23 22
  * @private
24 23
  * @type {Object}
25 24
  */
26
-export const ORIENTATION_TO_CLASS = {
25
+const ORIENTATION_TO_CLASS = {
27 26
     [ORIENTATION.LANDSCAPE]: 'fit-full-width',
28 27
     [ORIENTATION.PORTRAIT]: 'fit-full-height'
29 28
 };
30 29
 
30
+/**
31
+ * The type of the React {@code Component} props of
32
+ * {@link LargeVideoBackgroundCanvas}.
33
+ */
34
+type Props = {
35
+
36
+    /**
37
+     * Additional CSS class names to add to the root of the component.
38
+     */
39
+    className: String,
40
+
41
+    /**
42
+     * Whether or not the background should have its visibility hidden.
43
+     */
44
+    hidden: boolean,
45
+
46
+    /**
47
+     * Whether or not the video should display flipped horizontally, so left
48
+     * becomes right and right becomes left.
49
+     */
50
+    mirror: boolean,
51
+
52
+    /**
53
+     * Whether the component should ensure full width of the video is displayed
54
+     * (landscape) or full height (portrait).
55
+     */
56
+    orientationFit: string,
57
+
58
+    /**
59
+     * Whether or not to display a filter on the video to visually indicate a
60
+     * problem with the video being displayed.
61
+     */
62
+    showLocalProblemFilter: boolean,
63
+
64
+    /**
65
+     * Whether or not to display a filter on the video to visually indicate a
66
+     * problem with the video being displayed.
67
+     */
68
+    showRemoteProblemFilter: boolean,
69
+
70
+    /**
71
+     * The video stream to display.
72
+     */
73
+    videoElement: Object
74
+};
75
+
76
+
31 77
 /**
32 78
  * Implements a React Component which shows a video element intended to be used
33 79
  * as a background to fill the empty space of container with another video.
34 80
  *
35 81
  * @extends Component
36 82
  */
37
-export class LargeVideoBackground extends Component {
83
+export class LargeVideoBackground extends Component<Props> {
84
+    _canvasEl: Object;
85
+
86
+    _updateCanvasInterval: *;
87
+
88
+    /**
89
+     * Initializes new {@code LargeVideoBackground} instance.
90
+     *
91
+     * @param {*} props - The read-only properties with which the new instance
92
+     * is to be initialized.
93
+     */
94
+    constructor(props: Props) {
95
+        super(props);
96
+
97
+        // Bind event handlers so they are only bound once per instance.
98
+        this._setCanvasEl = this._setCanvasEl.bind(this);
99
+        this._updateCanvas = this._updateCanvas.bind(this);
100
+    }
101
+
102
+    /**
103
+     * If the canvas is not hidden, sets the initial interval to update the
104
+     * image displayed in the canvas.
105
+     *
106
+     * @inheritdoc
107
+     * @returns {void}
108
+     */
109
+    componentDidMount() {
110
+        if (this.props.videoElement && !this.props.hidden) {
111
+            this._updateCanvas();
112
+            this._setUpdateCanvasInterval();
113
+        }
114
+    }
115
+
38 116
     /**
39
-     * {@code LargeVideoBackground} component's property types.
117
+     * Starts or stops the interval to update the image displayed in the canvas.
40 118
      *
41
-     * @static
42
-     */
43
-    static propTypes = {
44
-        /**
45
-         * Additional CSS class names to add to the root of the component.
46
-         */
47
-        className: PropTypes.string,
48
-
49
-        /**
50
-         * Whether or not the background should have its visibility hidden.
51
-         */
52
-        hidden: PropTypes.bool,
53
-
54
-        /**
55
-         * Whether or not the video should display flipped horizontally, so
56
-         * left becomes right and right becomes left.
57
-         */
58
-        mirror: PropTypes.bool,
59
-
60
-        /**
61
-         * Whether the component should ensure full width of the video is
62
-         * displayed (landscape) or full height (portrait).
63
-         */
64
-        orientationFit: PropTypes.oneOf([
65
-            ORIENTATION.LANDSCAPE,
66
-            ORIENTATION.PORTRAIT
67
-        ]),
68
-
69
-        /**
70
-         * Whether or not to display a filter on the video to visually indicate
71
-         * a problem with the video being displayed.
72
-         */
73
-        showLocalProblemFilter: PropTypes.bool,
74
-
75
-        /**
76
-         * Whether or not to display a filter on the video to visually indicate
77
-         * a problem with the video being displayed.
78
-         */
79
-        showRemoteProblemFilter: PropTypes.bool,
80
-
81
-        /**
82
-         * The video stream to display.
83
-         */
84
-        videoTrack: PropTypes.object
85
-    };
119
+     * @inheritdoc
120
+     * @param {Object} nextProps - The read-only React {@code Component} props
121
+     * with which the new instance is to be initialized.
122
+     */
123
+    componentWillReceiveProps(nextProps: Props) {
124
+        if (this.props.hidden && !nextProps.hidden) {
125
+            this._clearCanvas();
126
+            this._setUpdateCanvasInterval();
127
+        }
128
+
129
+        if ((!this.props.hidden && nextProps.hidden)
130
+            || !nextProps.videoElement) {
131
+            this._clearCanvas();
132
+            this._clearUpdateCanvasInterval();
133
+        }
134
+    }
135
+
136
+    /**
137
+     * Clears the interval for updating the image displayed in the canvas.
138
+     *
139
+     * @inheritdoc
140
+     */
141
+    componentWillUnmount() {
142
+        this._clearUpdateCanvasInterval();
143
+    }
86 144
 
87 145
     /**
88 146
      * Implements React's {@link Component#render()}.
@@ -96,8 +154,7 @@ export class LargeVideoBackground extends Component {
96 154
             mirror,
97 155
             orientationFit,
98 156
             showLocalProblemFilter,
99
-            showRemoteProblemFilter,
100
-            videoTrack
157
+            showRemoteProblemFilter
101 158
         } = this.props;
102 159
         const orientationClass = orientationFit
103 160
             ? ORIENTATION_TO_CLASS[orientationFit] : '';
@@ -105,17 +162,91 @@ export class LargeVideoBackground extends Component {
105 162
             hidden ? 'invisible' : ''} ${orientationClass} ${
106 163
             showLocalProblemFilter ? 'videoProblemFilter' : ''} ${
107 164
             showRemoteProblemFilter ? 'remoteVideoProblemFilter' : ''}`;
108
-        const videoTrackModel = {
109
-            jitsiTrack: hidden ? null : videoTrack
110
-        };
111 165
 
112 166
         return (
113 167
             <div className = { classNames }>
114
-                <Video
115
-                    autoPlay = { true }
168
+                <canvas
116 169
                     id = 'largeVideoBackground'
117
-                    videoTrack = { videoTrackModel } />
170
+                    ref = { this._setCanvasEl } />
118 171
             </div>
119 172
         );
120 173
     }
174
+
175
+    /**
176
+     * Removes any image displayed on the canvas.
177
+     *
178
+     * @private
179
+     * @returns {void}
180
+     */
181
+    _clearCanvas() {
182
+        const cavnasContext = this._canvasEl.getContext('2d');
183
+
184
+        cavnasContext.clearRect(
185
+            0, 0, this._canvasEl.width, this._canvasEl.height);
186
+    }
187
+
188
+    /**
189
+     * Clears the interval for updating the image displayed in the canvas.
190
+     *
191
+     * @private
192
+     * @returns {void}
193
+     */
194
+    _clearUpdateCanvasInterval() {
195
+        clearInterval(this._updateCanvasInterval);
196
+    }
197
+
198
+    _setCanvasEl: () => void;
199
+
200
+    /**
201
+     * Sets the instance variable for the component's canvas element so it can
202
+     * be accessed directly for drawing on.
203
+     *
204
+     * @param {Object} element - The DOM element for the component's canvas.
205
+     * @private
206
+     * @returns {void}
207
+     */
208
+    _setCanvasEl(element) {
209
+        this._canvasEl = element;
210
+    }
211
+
212
+    /**
213
+     * Starts the interval for updating the image displayed in the canvas.
214
+     *
215
+     * @private
216
+     * @returns {void}
217
+     */
218
+    _setUpdateCanvasInterval() {
219
+        this._clearUpdateCanvasInterval();
220
+        this._updateCanvasInterval = setInterval(this._updateCanvas, 200);
221
+    }
222
+
223
+    _updateCanvas: () => void;
224
+
225
+    /**
226
+     * Draws the current frame of the passed in video element onto the canvas.
227
+     *
228
+     * @private
229
+     * @returns {void}
230
+     */
231
+    _updateCanvas() {
232
+        const { videoElement } = this.props;
233
+        const { videoWidth, videoHeight } = videoElement;
234
+        const {
235
+            height: canvasHeight,
236
+            width: canvasWidth
237
+        } = this._canvasEl;
238
+        const cavnasContext = this._canvasEl.getContext('2d');
239
+
240
+        if (this.props.orientationFit === ORIENTATION.LANDSCAPE) {
241
+            const heightScaledToFit = (canvasWidth / videoWidth) * videoHeight;
242
+
243
+            cavnasContext.drawImage(
244
+                videoElement, 0, 0, canvasWidth, heightScaledToFit);
245
+        } else {
246
+            const widthScaledToFit = (canvasHeight / videoHeight) * videoWidth;
247
+
248
+            cavnasContext.drawImage(
249
+                videoElement, 0, 0, widthScaledToFit, canvasHeight);
250
+        }
251
+    }
121 252
 }

+ 0
- 0
react/features/large-video/components/LargeVideoBackgroundCanvas.native.js 파일 보기


+ 0
- 229
react/features/large-video/components/LargeVideoBackgroundCanvas.web.js 파일 보기

@@ -1,229 +0,0 @@
1
-// @flow
2
-
3
-import React, { Component } from 'react';
4
-
5
-import { ORIENTATION, ORIENTATION_TO_CLASS } from './LargeVideoBackground';
6
-
7
-/**
8
- * The type of the React {@code Component} props of
9
- * {@link LargeVideoBackgroundCanvas}.
10
- */
11
-type Props = {
12
-
13
-    /**
14
-     * Additional CSS class names to add to the root of the component.
15
-     */
16
-    className: String,
17
-
18
-    /**
19
-     * Whether or not the background should have its visibility hidden.
20
-     */
21
-    hidden: boolean,
22
-
23
-    /**
24
-     * Whether or not the video should display flipped horizontally, so left
25
-     * becomes right and right becomes left.
26
-     */
27
-    mirror: boolean,
28
-
29
-    /**
30
-     * Whether the component should ensure full width of the video is displayed
31
-     * (landscape) or full height (portrait).
32
-     */
33
-    orientationFit: String,
34
-
35
-    /**
36
-     * Whether or not to display a filter on the video to visually indicate a
37
-     * problem with the video being displayed.
38
-     */
39
-    showLocalProblemFilter: boolean,
40
-
41
-    /**
42
-     * Whether or not to display a filter on the video to visually indicate a
43
-     * problem with the video being displayed.
44
-     */
45
-    showRemoteProblemFilter: boolean,
46
-
47
-    /**
48
-     * The video stream to display.
49
-     */
50
-    videoElement: Object
51
-};
52
-
53
-
54
-/**
55
- * Implements a React Component which shows a video element intended to be used
56
- * as a background to fill the empty space of container with another video.
57
- *
58
- * @extends Component
59
- */
60
-export class LargeVideoBackgroundCanvas extends Component<Props> {
61
-    _canvasEl: Object;
62
-
63
-    _updateCanvasInterval: *;
64
-
65
-    /**
66
-     * Initializes new {@code LargeVideoBackgroundCanvas} instance.
67
-     *
68
-     * @param {*} props - The read-only properties with which the new instance
69
-     * is to be initialized.
70
-     */
71
-    constructor(props: Props) {
72
-        super(props);
73
-
74
-        // Bind event handlers so they are only bound once per instance.
75
-        this._setCanvasEl = this._setCanvasEl.bind(this);
76
-        this._updateCanvas = this._updateCanvas.bind(this);
77
-    }
78
-
79
-    /**
80
-     * If the canvas is not hidden, sets the initial interval to update the
81
-     * image displayed in the canvas.
82
-     *
83
-     * @inheritdoc
84
-     * @returns {void}
85
-     */
86
-    componentDidMount() {
87
-        if (this.props.videoElement && !this.props.hidden) {
88
-            this._updateCanvas();
89
-            this._setUpdateCanvasInterval();
90
-        }
91
-    }
92
-
93
-    /**
94
-     * Starts or stops the interval to update the image displayed in the canvas.
95
-     *
96
-     * @inheritdoc
97
-     * @param {Object} nextProps - The read-only React {@code Component} props
98
-     * with which the new instance is to be initialized.
99
-     */
100
-    componentWillReceiveProps(nextProps: Props) {
101
-        if (this.props.hidden && !nextProps.hidden) {
102
-            this._clearCanvas();
103
-            this._setUpdateCanvasInterval();
104
-        }
105
-
106
-        if ((!this.props.hidden && nextProps.hidden)
107
-            || !nextProps.videoElement) {
108
-            this._clearCanvas();
109
-            this._clearUpdateCanvasInterval();
110
-        }
111
-    }
112
-
113
-    /**
114
-     * Clears the interval for updating the image displayed in the canvas.
115
-     *
116
-     * @inheritdoc
117
-     */
118
-    componentWillUnmount() {
119
-        this._clearUpdateCanvasInterval();
120
-    }
121
-
122
-    /**
123
-     * Implements React's {@link Component#render()}.
124
-     *
125
-     * @inheritdoc
126
-     * @returns {ReactElement}
127
-     */
128
-    render() {
129
-        const {
130
-            hidden,
131
-            mirror,
132
-            orientationFit,
133
-            showLocalProblemFilter,
134
-            showRemoteProblemFilter
135
-        } = this.props;
136
-        const orientationClass = orientationFit
137
-            ? ORIENTATION_TO_CLASS[orientationFit] : '';
138
-        const classNames = `large-video-background ${mirror ? 'flip-x' : ''} ${
139
-            hidden ? 'invisible' : ''} ${orientationClass} ${
140
-            showLocalProblemFilter ? 'videoProblemFilter' : ''} ${
141
-            showRemoteProblemFilter ? 'remoteVideoProblemFilter' : ''}`;
142
-
143
-        return (
144
-            <div className = { classNames }>
145
-                <canvas
146
-                    id = 'largeVideoBackground'
147
-                    ref = { this._setCanvasEl } />
148
-            </div>
149
-        );
150
-    }
151
-
152
-    /**
153
-     * Removes any image displayed on the canvas.
154
-     *
155
-     * @private
156
-     * @returns {void}
157
-     */
158
-    _clearCanvas() {
159
-        const cavnasContext = this._canvasEl.getContext('2d');
160
-
161
-        cavnasContext.clearRect(
162
-            0, 0, this._canvasEl.width, this._canvasEl.height);
163
-    }
164
-
165
-    /**
166
-     * Clears the interval for updating the image displayed in the canvas.
167
-     *
168
-     * @private
169
-     * @returns {void}
170
-     */
171
-    _clearUpdateCanvasInterval() {
172
-        clearInterval(this._updateCanvasInterval);
173
-    }
174
-
175
-    _setCanvasEl: () => void;
176
-
177
-    /**
178
-     * Sets the instance variable for the component's canvas element so it can
179
-     * be accessed directly for drawing on.
180
-     *
181
-     * @param {Object} element - The DOM element for the component's canvas.
182
-     * @private
183
-     * @returns {void}
184
-     */
185
-    _setCanvasEl(element) {
186
-        this._canvasEl = element;
187
-    }
188
-
189
-    /**
190
-     * Starts the interval for updating the image displayed in the canvas.
191
-     *
192
-     * @private
193
-     * @returns {void}
194
-     */
195
-    _setUpdateCanvasInterval() {
196
-        this._clearUpdateCanvasInterval();
197
-        this._updateCanvasInterval = setInterval(this._updateCanvas, 200);
198
-    }
199
-
200
-    _updateCanvas: () => void;
201
-
202
-    /**
203
-     * Draws the current frame of the passed in video element onto the canvas.
204
-     *
205
-     * @private
206
-     * @returns {void}
207
-     */
208
-    _updateCanvas() {
209
-        const { videoElement } = this.props;
210
-        const { videoWidth, videoHeight } = videoElement;
211
-        const {
212
-            height: canvasHeight,
213
-            width: canvasWidth
214
-        } = this._canvasEl;
215
-        const cavnasContext = this._canvasEl.getContext('2d');
216
-
217
-        if (this.props.orientationFit === ORIENTATION.LANDSCAPE) {
218
-            const heightScaledToFit = (canvasWidth / videoWidth) * videoHeight;
219
-
220
-            cavnasContext.drawImage(
221
-                videoElement, 0, 0, canvasWidth, heightScaledToFit);
222
-        } else {
223
-            const widthScaledToFit = (canvasHeight / videoHeight) * videoWidth;
224
-
225
-            cavnasContext.drawImage(
226
-                videoElement, 0, 0, widthScaledToFit, canvasHeight);
227
-        }
228
-    }
229
-}

+ 0
- 1
react/features/large-video/components/index.js 파일 보기

@@ -1,3 +1,2 @@
1 1
 export { default as LargeVideo } from './LargeVideo';
2 2
 export * from './LargeVideoBackground';
3
-export * from './LargeVideoBackgroundCanvas';

Loading…
취소
저장