Skip to content

Commit 835e9cc

Browse files
committed
Expose processors on the BG Blur and BG Replacement providers
1 parent 3577e48 commit 835e9cc

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Added
1313

1414
- Refactor `toggleContentShare` function to allow specifying a `MediaStream` to share. This can be used to share non-screen share content.
15+
- Expose the background blur processor and background replacement processor from their respective providers - `BackgroundBlurProvider` and `BackgroundReplacementProvider`.
1516

1617
### Removed
1718

src/providers/BackgroundBlurProvider/docs/BackgroundBlurProvider.stories.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ before calling `createBackgroundBlurDevice`. Calling `createBackgroundBlurDevice
3535
`DefaultVideoTransformDevice` with `createBackgroundBlurDevice` in order to destroy the processors running previously. Once you call `DefaultVideoTransformDevice.stop`, you should discard the old `DefaultVideoTransformDevice`.
3636
For more information, refer to [Video Processing APIs](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/10_Video_Processor.md#stopping-videotransformdevice).
3737

38+
You can access the current `backgroundBlurProcessor` applied to the video device that is generated when you call `createBackgroundBlurDevice`. You can apply observer notifications to the processor. Refer to [the guide for adding observer notifications to a BackgroundBlurProcessor](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/15_Background_Filter_Video_Processor.md#observer-notifications)
39+
3840
One thing to note is that calling `meetingManager.startVideoInputDevice()` with a `Device` type while the current selected video input device is a `VideoTransformDevice`
3941
will automatically stop any video processor that was previously running. Lastly, make sure to construct a new `DefaultVideoTransformDevice` using `createBackgroundBlurDevice`.
4042
if the Props of the provider were changed.

src/providers/BackgroundBlurProvider/docs/useBackgroundBlur.stories.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ before calling `createBackgroundBlurDevice`. Calling `createBackgroundBlurDevice
1818
`DefaultVideoTransformDevice` with new video processors. For more information, refer to [Video Processing APIs](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/10_Video_Processor.md#stopping-videotransformdevice).
1919
Lastly, make sure to construct a new `DefaultVideoTransformDevice` using `createBackgroundBlurDevice` and use it as input if the `Props` of the provider were changed.
2020

21+
You can access the current `backgroundBlurProcessor` applied to the video device that is generated when you call `createBackgroundBlurDevice`. You can apply observer notifications to the processor. Refer to [the guide for adding observer notifications to a BackgroundBlurProcessor](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/15_Background_Filter_Video_Processor.md#observer-notifications)
22+
2123
Background blur related logs can be found in the browser developer tools when the `BackgroundBlurProvider` is used within the app component tree.
2224

2325
## Return Value

src/providers/BackgroundBlurProvider/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Device,
1212
LogLevel,
1313
NoOpVideoFrameProcessor,
14-
VideoFrameProcessor,
1514
} from 'amazon-chime-sdk-js';
1615
import React, {
1716
createContext,
@@ -40,6 +39,7 @@ interface BackgroundBlurProviderState {
4039
device: Device
4140
) => Promise<DefaultVideoTransformDevice>;
4241
isBackgroundBlurSupported: boolean | undefined;
42+
backgroundBlurProcessor: BackgroundBlurProcessor | undefined
4343
}
4444

4545
const BackgroundBlurProviderContext = createContext<
@@ -51,7 +51,7 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
5151
const [isBackgroundBlurSupported, setIsBackgroundBlurSupported] = useState<
5252
boolean | undefined
5353
>(undefined);
54-
const [processor, setProcessor] = useState<VideoFrameProcessor | undefined>();
54+
const [backgroundBlurProcessor, setBackgroundBlurProcessor] = useState<BackgroundBlurProcessor | undefined>();
5555

5656
const blurSpec = useMemoCompare(
5757
spec,
@@ -93,7 +93,7 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
9393
logger.info(
9494
'Specs or options were changed. Destroying and re-initializing background blur processor.'
9595
);
96-
processor?.destroy();
96+
backgroundBlurProcessor?.destroy();
9797
};
9898
}, [blurOptions, blurSpec]);
9999

@@ -117,7 +117,7 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
117117
// the assets are not fetched successfully.
118118
if (createdProcessor instanceof NoOpVideoFrameProcessor) {
119119
logger.warn('Initialized NoOpVideoFrameProcessor');
120-
setProcessor(undefined);
120+
setBackgroundBlurProcessor(undefined);
121121
setIsBackgroundBlurSupported(false);
122122
return undefined;
123123
} else {
@@ -126,15 +126,15 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
126126
createdProcessor
127127
)}`
128128
);
129-
setProcessor(createdProcessor);
129+
setBackgroundBlurProcessor(createdProcessor);
130130
setIsBackgroundBlurSupported(true);
131131
return createdProcessor;
132132
}
133133
} catch (error) {
134134
logger.error(
135135
`Error creating a background blur video frame processor device ${error}`
136136
);
137-
setProcessor(undefined);
137+
setBackgroundBlurProcessor(undefined);
138138
setIsBackgroundBlurSupported(false);
139139
return undefined;
140140
}
@@ -175,6 +175,7 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
175175
const value: BackgroundBlurProviderState = {
176176
createBackgroundBlurDevice,
177177
isBackgroundBlurSupported,
178+
backgroundBlurProcessor,
178179
};
179180

180181
return (

src/providers/BackgroundReplacementProvider/docs/BackgroundReplacementProvider.stories.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ before calling `createBackgroundReplacementDevice`. Calling `createBackgroundRep
3535
`DefaultVideoTransformDevice` with `createBackgroundReplacementDevice` in order to destroy the processors running previously. Once you call `DefaultVideoTransformDevice.stop`, you should discard the old `DefaultVideoTransformDevice`.
3636
For more information, refer to [Video Processing APIs](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/10_Video_Processor.md#stopping-videotransformdevice).
3737

38+
You can access the current `backgroundReplacementProcessor` applied to the video device that is generated when you call `createBackgroundBlurDevice`. You can apply observer notifications to the processor. Refer to [the guide for adding observer notifications to a BackgroundReplacementProcessor](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/15_Background_Filter_Video_Processor.md#observer-notifications)
39+
3840
One thing to note is that calling `meetingManager.startVideoInputDevice()` with a `Device` type while the current selected video input device is a `VideoTransformDevice`
3941
will automatically stop any processors running within a `DefaultVideoTransformDevice` that was previously running. Lastly, make sure to construct a new `DefaultVideoTransformDevice` using `createBackgroundReplacementDevice`.
4042
if the Props of the provider were changed.

src/providers/BackgroundReplacementProvider/docs/useBackgroundReplacement.stories.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ before calling `createBackgroundReplacementDevice`. Calling `createBackgroundRep
1818
`DefaultVideoTransformDevice` with new video processors. For more information, refer to [Video Processing APIs](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/10_Video_Processor.md#stopping-videotransformdevice);
1919
Lastly, make sure to construct a new `DefaultVideoTransformDevice` using `createBackgroundReplacementDevice` and use it as input if the `Props` of the provider were changed.
2020

21+
You can access the current `backgroundReplacementProcessor` applied to the video device that is generated when you call `createBackgroundBlurDevice`. You can apply observer notifications to the processor. Refer to [the guide for adding observer notifications to a BackgroundReplacementProcessor](https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/15_Background_Filter_Video_Processor.md#observer-notifications)
22+
2123
Background replacement related logs can be found in the browser developer tools when the `BackgroundReplacementProvider` is used within the app component tree.
2224

2325
## Return Value

src/providers/BackgroundReplacementProvider/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Device,
1212
LogLevel,
1313
NoOpVideoFrameProcessor,
14-
VideoFrameProcessor,
1514
} from 'amazon-chime-sdk-js';
1615
import React, {
1716
createContext,
@@ -40,6 +39,7 @@ interface BackgroundReplacementProviderState {
4039
device: Device
4140
) => Promise<DefaultVideoTransformDevice>;
4241
isBackgroundReplacementSupported: boolean | undefined;
42+
backgroundReplacementProcessor: BackgroundReplacementProcessor | undefined;
4343
}
4444

4545
const BackgroundReplacementProviderContext = createContext<
@@ -56,7 +56,7 @@ const BackgroundReplacementProvider: FC<Props> = ({
5656
isBackgroundReplacementSupported,
5757
setIsBackgroundReplacementSupported,
5858
] = useState<boolean | undefined>(undefined);
59-
const [processor, setProcessor] = useState<VideoFrameProcessor | undefined>(
59+
const [backgroundReplacementProcessor, setBackgroundReplacementProcessor] = useState<BackgroundReplacementProcessor | undefined>(
6060
undefined
6161
);
6262

@@ -100,7 +100,7 @@ const BackgroundReplacementProvider: FC<Props> = ({
100100
logger.info(
101101
'Specs or options were changed. Destroying and re-initializing background replacement processor.'
102102
);
103-
processor?.destroy();
103+
backgroundReplacementProcessor?.destroy();
104104
};
105105
}, [replacementSpec, replacementOptions]);
106106

@@ -125,7 +125,7 @@ const BackgroundReplacementProvider: FC<Props> = ({
125125
// the assets are not fetched successfully.
126126
if (createdProcessor instanceof NoOpVideoFrameProcessor) {
127127
logger.warn('Initialized NoOpVideoFrameProcessor');
128-
setProcessor(undefined);
128+
setBackgroundReplacementProcessor(undefined);
129129
setIsBackgroundReplacementSupported(false);
130130
return undefined;
131131
} else {
@@ -134,15 +134,15 @@ const BackgroundReplacementProvider: FC<Props> = ({
134134
createdProcessor
135135
)}`
136136
);
137-
setProcessor(createdProcessor);
137+
setBackgroundReplacementProcessor(createdProcessor);
138138
setIsBackgroundReplacementSupported(true);
139139
return createdProcessor;
140140
}
141141
} catch (error) {
142142
logger.error(
143143
`Error creating a background replacement video frame processor device. ${error}`
144144
);
145-
setProcessor(undefined);
145+
setBackgroundReplacementProcessor(undefined);
146146
setIsBackgroundReplacementSupported(false);
147147
return undefined;
148148
}
@@ -183,6 +183,7 @@ const BackgroundReplacementProvider: FC<Props> = ({
183183
const value: BackgroundReplacementProviderState = {
184184
createBackgroundReplacementDevice,
185185
isBackgroundReplacementSupported,
186+
backgroundReplacementProcessor
186187
};
187188

188189
return (

0 commit comments

Comments
 (0)