Skip to content

Commit 9cd2bfe

Browse files
authored
Merge pull request #270129 from DaybreakQuip/patch-5
Update ACS Calling Video Effects
2 parents dd0e169 + 710a477 commit 9cd2bfe

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed

articles/communication-services/quickstarts/voice-video-calling/includes/video-effects/video-effects-android.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,70 @@ public void disableBackgroundBlur() {
120120
videoEffectsFeature.disableEffect(backgroundBlurEffect);
121121
}
122122
```
123+
124+
### Background replacement
125+
126+
Background Replacement is a Video Effect that allows a person's background to be replaced. In order to use Background Video Effect, you need to obtain a `VideoEffectsLocalVideoStreamFeature` feature from a valid `LocalVideoStream`.
127+
128+
To enable Background Replacement Video Effect:
129+
130+
- Create a method that obtains the `VideoEFfects` Feature subscribes to the events:
131+
132+
```java
133+
private void handleOnVideoEffectEnabled(VideoEffectEnabledEvent args) {
134+
Log.i("VideoEfects", "Effect enabled for effect " + args.getVideoEffectName());
135+
}
136+
private void handleOnVideoEffectDisabled(VideoEffectDisabledEvent args) {
137+
Log.i("VideoEfects", "Effect disabled for effect " + args.getVideoEffectName());
138+
}
139+
private void handleOnVideoEffectError(VideoEffectErrorEvent args) {
140+
Log.i("VideoEfects", "Error " + args.getCode() + ":" + args.getMessage()
141+
+ " for effect " + args.getVideoEffectName());
142+
}
143+
144+
VideoEffectsLocalVideoStreamFeature videoEffectsFeature;
145+
public void createVideoEffectsFeature() {
146+
videoEffectsFeature = currentVideoStream.feature(Features.LOCAL_VIDEO_EFFECTS);
147+
videoEffectsFeature.addOnVideoEffectEnabledListener(this::handleOnVideoEffectEnabled);
148+
videoEffectsFeature.addOnVideoEffectDisabledListener(this::handleOnVideoEffectDisabled);
149+
videoEffectsFeature.addOnVideoEffectErrorListener(this::handleOnVideoEffectError);
150+
}
151+
152+
```
153+
154+
- Create a new Background Replacement Video Effect object:
155+
156+
```java
157+
BackgroundReplacementEffect backgroundReplacementVideoEffect = new BackgroundReplacementEffect();
158+
```
159+
160+
- Set a custom background by passing in the image through a buffer.
161+
162+
```java
163+
//example of where we can get an image from, in this case, this is from assets in Android folder
164+
InputStream inputStream = getAssets().open("image.jpg");
165+
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
166+
ByteArrayOutputStream stream = new ByteArrayOutputStream();
167+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
168+
byte[] data = stream.toByteArray();
169+
ByteBuffer dataBuffer = ByteBuffer.allocateDirect(data.length);
170+
dataBuffer.put(data);
171+
dataBuffer.rewind();
172+
backgroundReplacementVideoEffect.setBuffer(dataBuffer);
173+
```
174+
175+
- Call `EnableEffect` on the `videoEffectsFeature` object:
176+
177+
```java
178+
public void enableBackgroundReplacement() {
179+
videoEffectsFeature.enableEffect(backgroundReplacementVideoEffect);
180+
}
181+
```
182+
183+
To disable Background Replacement Video Effect:
184+
185+
```java
186+
public void disableBackgroundReplacement() {
187+
videoEffectsFeature.disableEffect(backgroundReplacementVideoEffect);
188+
}
189+
```

articles/communication-services/quickstarts/voice-video-calling/includes/video-effects/video-effects-ios.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,37 @@ To disable Background Blur Video Effect:
7373
```swift
7474
localVideoEffectsFeature.disable(effect: backgroundBlurVideoEffect)
7575
```
76+
77+
### Background Replacement
78+
Background Replacement is a Video Effect that allows a person to set their own custom background. In order to use Background Replacement Effect, you need to obtain a `LocalVideoEffectsFeature` feature from a valid `LocalVideoStream`.
79+
80+
- Create a new Background Replacement Video Effect object:
81+
82+
```swift
83+
@State var backgroundReplacementVideoEffect: BackgroundReplacementEffect?
84+
```
85+
86+
- Set a custom background by passing in the image through a buffer.
87+
88+
```swift
89+
let image = UIImage(named:"image.png")
90+
guard let imageData = image?.jpegData(compressionQuality: 1.0) else {
91+
return
92+
}
93+
backgroundReplacementVideoEffect.buffer = imageData
94+
```
95+
96+
- Check if `BackgroundReplacementEffect` is supported and call `Enable` on the `videoEffectsFeature` object:
97+
98+
```swift
99+
if((localVideoEffectsFeature.isSupported(effect: backgroundReplacementVideoEffect)) != nil)
100+
{
101+
localVideoEffectsFeature.enable(effect: backgroundReplacementVideoEffect)
102+
}
103+
```
104+
105+
To disable Background Replacement Video Effect:
106+
107+
```swift
108+
localVideoEffectsFeature.disable(effect: backgroundReplacementVideoEffect)
109+
```

articles/communication-services/quickstarts/voice-video-calling/includes/video-effects/video-effects-windows.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,96 @@ private async void BackgroundBlur_Click(object sender, RoutedEventArgs e)
158158
}
159159
}
160160
```
161+
162+
### Background replacement
163+
164+
Background Replacement is a Video Effect that allows a person's background to be replaced. In order to use Background Video Effect, you need to obtain a `VideoEffectsLocalVideoStreamFeature` feature from a valid `LocalVideoStream`.
165+
166+
To enable Background Replacement Video Effect:
167+
168+
- Add the `BackgroundReplacementEffect` instance to the MainPage.
169+
170+
```C#
171+
public sealed partial class MainPage : Page
172+
{
173+
private BackgroundReplacementEffect backgroundReplacementVideoEffect = new BackgroundReplacementEffect();
174+
}
175+
```
176+
177+
- Create a method that obtains the `VideoEFfects` Feature subscribes to the events:
178+
179+
```C#
180+
private async void LocalVideoEffectsFeature_VideoEffectEnabled(object sender, VideoEffectEnabledEventArgs e)
181+
{
182+
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
183+
{
184+
BackgroundReplacement.IsChecked = true;
185+
});
186+
}
187+
188+
private async void LocalVideoEffectsFeature_VideoEffectDisabled(object sender, VideoEffectDisabledEventArgs e)
189+
{
190+
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
191+
{
192+
BackgroundReplacement.IsChecked = false;
193+
});
194+
}
195+
196+
private void LocalVideoEffectsFeature_VideoEffectError(object sender, VideoEffectErrorEventArgs e)
197+
{
198+
String effectName = args.VideoEffectName;
199+
String errorCode = args.Code;
200+
String errorMessage = args.Message;
201+
202+
Trace.WriteLine("VideoEffects VideoEffectError on effect " + effectName + "with code "
203+
+ errorCode + "and error message " + errorMessage);
204+
}
205+
```
206+
207+
- Set a custom background by passing in the image through a buffer.
208+
209+
```C#
210+
//example of getting the image from storage folder
211+
MemoryBuffer memoryBuffer = new MemoryBuffer(0);
212+
StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
213+
StorageFile file = InstallationFolder.GetFileAsync("image.jpg").GetAwaiter().GetResult();
214+
if (File.Exists(file.Path))
215+
{
216+
byte[] imageBytes = File.ReadAllBytes(file.Path);
217+
memoryBuffer = new MemoryBuffer((uint)imageBytes.Length);
218+
using (IMemoryBufferReference reference = memoryBuffer.CreateReference())
219+
{
220+
byte* dataInBytes;
221+
uint capacityInBytes;
222+
223+
(reference.As<IMemoryBufferByteAccess>()).GetBuffer(out dataInBytes, out capacityInBytes);
224+
for (int i = 0; i < imageBytes.Length; i++)
225+
{
226+
dataInBytes[i] = imageBytes[i];
227+
}
228+
}
229+
return memoryBuffer;
230+
}
231+
backgroundReplacementVideoEffect.Buffer = memoryBuffer;
232+
```
233+
234+
235+
- Enable and disable the Background Replacement effect:
236+
237+
```C#
238+
private async void BackgroundReplacement_Click(object sender, RoutedEventArgs e)
239+
{
240+
if (localVideoEffectsFeature.IsEffectSupported(backgroundReplacementVideoEffect))
241+
{
242+
var backgroundReplacementCheckbox = sender as CheckBox;
243+
if (backgroundReplacementCheckbox.IsChecked.Value)
244+
{
245+
localVideoEffectsFeature.EnableEffect(backgroundReplacementVideoEffect);
246+
}
247+
else
248+
{
249+
localVideoEffectsFeature.DisableEffect(backgroundReplacementVideoEffect);
250+
}
251+
}
252+
}
253+
```

0 commit comments

Comments
 (0)