Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(virtual background): Add virtual background flow. #8750

Merged
merged 2 commits into from
Mar 12, 2021

Conversation

tudor-phd
Copy link
Contributor

No description provided.

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't wait for this to land! Great work so far! Left some comments, PTAL.

lang/main.json Outdated
@@ -809,8 +812,8 @@
"tileViewToggle": "Toggle tile view",
"toggleCamera": "Toggle camera",
"videomute": "Start / Stop camera",
"startvideoblur": "Blur my background",
"stopvideoblur": "Disable background blur"
"startvideoblur": "Enable background",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the keys to match please.

lang/main.json Outdated
"startvideoblur": "Blur my background",
"stopvideoblur": "Disable background blur"
"startvideoblur": "Enable background",
"stopvideoblur": "Change background"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we just need a single entry now? The user will be able to choose between a background, blur or nothing, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case 1: The user has already set a background => Text will be: "Change background"
Case 2: The user has no background set, or has pressed the None button => Text will be: "Enable background"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need 2. "Enable background" sounds very weird. I'd go with a si gel entry with something like "Select background"


return Promise.resolve();
return getBlurEffect()
.then(blurEffectInstance =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this an async function and remove the .then "ladder" here :-)

return getBlurEffect()
.then(blurEffectInstance =>
jitsiTrack
.setEffect(enabled ? blurEffectInstance : undefined)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are creating an effect object just to discard it when disabling, let's avoid that.

@@ -36,7 +36,7 @@ type Props = AbstractButtonProps & {
*/
class VideoBlurButton extends AbstractButton<Props, *> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the button and the feature itself to match the new behavior. This does now a lot more than blur!


const addImageBackground = image => {
dispatch(setVirtualBackground(image, true));
dispatch(toggleBlurEffect(true));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a new name for this, since it now turns on the virtual background, not just blur.

tooltip: 'Image 1',
name: 'background-1.jpg',
id: 1,
src: '../../../../images/virtual-background/background-1.jpg'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to use images/foo because the static assets will be part of the CDN anyway.

position = { 'top' }>
<div
className = 'virtual-background-none'
// eslint-disable-next-line react/jsx-no-bind
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this at the top of the file and remove it for the entire file.

We may need to rethink if having it enabled is a good idea going forward, but that's outside the scope of this PR.

src = { image.src } />
</Tooltip>
))}
<div className = 'virtual-video-preview'>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a real preview? Looks like the effect is being applied to the actual track anyway not to a different one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be discussed...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the preview.

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, PTAL! Nothing major, mostly related to consistency / naming.

*/
export function toggleBlurEffect(enabled: boolean) {
return function(dispatch: (Object) => Object, getState: () => any) {
* Signals the local participant is switching between blurred or non blurred video.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reword this so it better matches what it does now.

try {
if (enabled) {
await jitsiTrack.setEffect(await getBlurEffect(virtualBackground));
dispatch(blurEnabled());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename.


try {
if (enabled) {
await jitsiTrack.setEffect(await getBlurEffect(virtualBackground));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename.

@@ -28,31 +28,28 @@ type Props = AbstractButtonProps & {
* The redux {@code dispatch} function.
*/
dispatch: Function

};

/**
* An abstract implementation of a button that toggles the video blur effect.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update.

@@ -7,16 +7,17 @@ let filterSupport;
/**
* Returns promise that resolves with the blur effect instance.
*
* @param {Object} virtualBackground - The virtual object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe the object.

</div>
</Tooltip>
<Tooltip
content = { 'Enable Blur' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, translate.

@@ -38,6 +39,12 @@ export default class JitsiStreamBlurEffect {
* @param {Object} options - Segmentation dimensions.
*/
constructor(model: Object, options: Object) {
this._options = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this class too, it now does more than blur.

@@ -57,5 +58,7 @@ export async function createBlurEffect() {

const options = wasmCheck.feature.simd ? segmentationDimensions.model144 : segmentationDimensions.model96;

options.virtualBackground = virtualBackground;

return new JitsiStreamBlurEffect(tflite, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this class.

/**
* The JitsiLocalTrack to display.
*/
videoTrack: ?Object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

/**
* Initial state.
*/
const DEFAULT_STATE = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these are falsey when undefined, you don't need to define them explicitly, do you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't define them -> I get this console error: "The initial state may not be undefined."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this do it?

ReducerRegistry.register('features/virtual-background', (state = {}, action) => {

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did another round, PTAL!

@@ -14,8 +14,8 @@ import logger from './logger';
export default function loadEffects(store: Object): Promise<any> {
const state = store.getState();

const blurPromise = state['features/blur'].blurEnabled
? getBlurEffect()
const blurPromise = state['features/virtual-backgrounds'].backgroundEnabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backgroundPromose? also adjust the log line please

model96: {
height: 96,
width: 160,
virtualBackground: {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a new object then instead of augmenting this one. Like so:

    const options = {
       ...(wasmCheck.feature.simd ? segmentationDimensions.model144 : segmentationDimensions.model96),
       virtualBackground
   };

   return new JitsiStreamBackgroundEffect(tflite, options);

/**
* Initial state.
*/
const DEFAULT_STATE = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this do it?

ReducerRegistry.register('features/virtual-background', (state = {}, action) => {

@@ -92,10 +89,9 @@ function _mapStateToProps(state): Object {
const tracks = state['features/base/tracks'];

return {
_isVideoBlurred: Boolean(state['features/blur'].blurEnabled),
_isVideoBlurred: Boolean(state['features/virtual-backgrounds'].backgroundEnabled),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_isBackgroundEnabled

const ns = getJitsiMeetGlobalNS();

if (ns.effects && ns.effects.createBlurEffect) {
return ns.effects.createBlurEffect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createVirtualBackgroundEffect



ReducerRegistry.register('features/virtual-backgrounds', (state = {}, action) => {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the extra newline

import { BACKGROUND_ENABLED, BACKGROUND_DISABLED } from './actionTypes';


ReducerRegistry.register('features/virtual-backgrounds', (state = {}, action) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some docs please

ReducerRegistry.register('features/virtual-backgrounds', (state = {}, action) => {

switch (action.type) {
case BACKGROUND_ENABLED: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not part of the virtual-background (no S) feature? Please put all of this in that one feature, why would we want 2, with such similar names even?

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there! PTAL.

@@ -0,0 +1,3 @@
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M16.6666 1.66667H3.33329C2.41282 1.66667 1.66663 2.41286 1.66663 3.33334V16.6667C1.66663 17.5871 2.41282 18.3333 3.33329 18.3333H3.63257H8.56767H9.14753H15.6942H16.6666C17.5871 18.3333 18.3333 17.5871 18.3333 16.6667V3.33334C18.3333 2.41286 17.5871 1.66667 16.6666 1.66667ZM7.57977 12.3005L9.3687 14.893L12.0223 8.76728C12.2052 8.34496 12.6959 8.15091 13.1182 8.33385C13.2964 8.41106 13.4421 8.54811 13.53 8.72131L16.6666 14.9002V3.33334H3.33329V16.4665L6.208 12.3005C6.4694 11.9217 6.98838 11.8265 7.36718 12.0879C7.45035 12.1453 7.52238 12.2174 7.57977 12.3005ZM7.49996 10C6.11925 10 4.99996 8.88072 4.99996 7.5C4.99996 6.11929 6.11925 5.00001 7.49996 5.00001C8.88067 5.00001 9.99996 6.11929 9.99996 7.5C9.99996 8.88072 8.88067 10 7.49996 10ZM8.33329 7.5C8.33329 7.96024 7.9602 8.33334 7.49996 8.33334C7.03972 8.33334 6.66663 7.96024 6.66663 7.5C6.66663 7.03977 7.03972 6.66667 7.49996 6.66667C7.9602 6.66667 8.33329 7.03977 8.33329 7.5ZM12.8466 11.0572L15.6942 16.6667H10.4167L12.8466 11.0572ZM6.89389 14.2411L8.56767 16.6667H5.2201L6.89389 14.2411Z" fill="white"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the fill="white"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not solved.

this._shouldShowButton('videobackgroundblur')
&& <VideoBlurButton
key = 'videobackgroundblur'
this._shouldShowButton('select-background')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some backwards compatibility check here. It should still work with the old button name.

@@ -2,35 +2,37 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename this folder from blur to virtual-background too.

@@ -1,3 +1,5 @@
export * from './actions';
export * from './components';
export * from './functions';

import './reducer';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import the reducer in the app's reducers.web.js, not here.

case BACKGROUND_ENABLED: {
return {
...state,
backgroundEnabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when the action is created this is called backgroundEffectEnabled, so this is broken.

* is enabled.
*
* {
* type: BACKGROUND_ENABLED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the parameter.

@saghul saghul force-pushed the virtual-background-feature branch from cae762b to 334a240 Compare March 12, 2021 13:17
@saghul saghul force-pushed the virtual-background-feature branch from 334a240 to 21f9122 Compare March 12, 2021 13:18
@saghul saghul merged commit 31ace26 into jitsi:master Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants