You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Quickstart - Add RAW media access to your app (Android)
3
3
titleSuffix: An Azure Communication Services quickstart
4
4
description: In this quickstart, you'll learn how to add raw media access calling capabilities to your app using Azure Communication Services.
5
-
author: LaithRodan
5
+
author: Yassir Bisteni
6
6
7
-
ms.author: larodan
8
-
ms.date: 11/18/2021
7
+
ms.author: yassirb
8
+
ms.date: 04/19/2022
9
9
ms.topic: quickstart
10
10
ms.service: azure-communication-services
11
11
ms.subservice: calling
@@ -18,32 +18,20 @@ ms.custom: mode-other
18
18
19
19
In this quickstart, you'll learn how implement raw media access using the Azure Communication Services Calling SDK for Android.
20
20
21
-
## Outbound virtual video device
22
-
23
21
The Azure Communication Services Calling SDK offers APIs allowing apps to generate their own video frames to send to remote participants.
24
22
25
23
This quick start builds upon [QuickStart: Add 1:1 video calling to your app](./get-started-with-video-calling.md?pivots=platform-android) for Android.
26
24
27
25
28
-
## Overview
29
-
30
-
Once an outbound virtual video device is created, use DeviceManager to make a new virtual video device that behaves just like any other webcam connected to your computer or mobile phone.
26
+
## Virtual Video Stream Overview
31
27
32
28
Since the app will be generating the video frames, the app must inform the Azure Communication Services Calling SDK about the video formats the app is capable of generating. This is required to allow the Azure Communication Services Calling SDK to pick the best video format configuration given the network conditions at any giving time.
33
29
34
30
The app must register a delegate to get notified about when it should start or stop producing video frames. The delegate event will inform the app which video format is more appropriate for the current network conditions.
35
31
36
-
The following is an overview of the steps required to create an outbound virtual video device.
37
-
38
-
1. Create a `VirtualDeviceIdentification` with basic identification information for the new outbound virtual video device.
deviceId.setName("My First Virtual Video Device");
44
-
```
32
+
The following is an overview of the steps required to create a virtual video stream.
45
33
46
-
2.Create an array of `VideoFormat` with the video formats supported by the app. It is fine to have only one video format supported, but at least one of the provided video formats must be of the `MediaFrameKind::VideoSoftware` type. When multiple formats are provided, the order of the format in the list does not influence or prioritize which one will be used. The selected format is based on external factors like network bandwidth.
34
+
1. Create an array of `VideoFormat` with the video formats supported by the app. It is fine to have only one video format supported, but at least one of the provided video formats must be of the `VideoFrameKind::VideoSoftware` type. When multiple formats are provided, the order of the format in the list does not influence or prioritize which one will be used. The selected format is based on external factors like network bandwidth.
4.Make sure the `OutboundVirtualVideoDeviceOptions::OnFlowChanged` delegate is defined. This delegate will inform its listener about events requiring the app to start or stop producing video frames. Inthis quick start, `m_mediaFrameSender` is used as trigger to let the app know when it's time to start generating frames. Feel free to use any mechanism in your app as a trigger.
57
+
3.Subscribe to `OutgoingVirtualVideoStreamOptions::addOnOutgoingVideoStreamStateChangedListener` delegate. This delegate will inform the state of the current stream, its important that you do not send framesif the state is no equal to `OutgoingVideoStreamState.STARTED`.
5.Use `DeviceManager::CreateOutboundVirtualVideoDevice` to create an outbound virtual video device. The returning `OutboundVirtualVideoDevice` should be kept alive as long as the app needs to keep acting as a virtual video device. It is ok to register multiple outbound virtual video devices per app.
68
+
4.Make sure the `OutgoingVirtualVideoStreamOptions::addOnVideoFrameSenderChangedListener` delegate is defined. This delegate will inform its listener about events requiring the app to start or stop producing video frames. Inthis quick start, `mediaFrameSender` is used as trigger to let the app know when it's time to start generating frames. Feel free to use any mechanism in your app as a trigger.
virtualVideoStream = new VirtualVideoStream(options);
116
85
```
117
86
118
-
7.Ina non-UI thread or loop in the app, cast the `MediaFrameSender` to the appropriate type defined by the `MediaFrameKind` property of `VideoFormat`.For example, cast it to `SoftwareBasedVideoFrame` and then call the `send` method according to the number of planes defined by the MediaFormat.
87
+
7. Once outgoingVideoStreamState is equal to `OutgoingVideoStreamState.STARTED` create and instance of `FrameGenerator` class this will start a non-UI thread and will send frames, call `FrameGenerator.SetVideoFrameSender` each time we get an updated `VideoFrameSender` on the previous delegate, cast the `VideoFrameSender` to the appropriate type defined by the `VideoFrameKind` property of `VideoFormat`. For example, cast it to `SoftwareBasedVideoFrameSender` and then call the `send` method according to the number of planes defined by the MediaFormat.
119
88
After that, create the ByteBuffer backing the video frame if needed. Then, update the content of the video frame. Finally, send the video frame to other participants with the `sendFrame` API.
120
89
121
90
```java
122
-
java.nio.ByteBuffer plane1 =null;
123
-
Random rand =newRandom();
124
-
byte greyValue =0;
125
-
126
-
// ...
127
-
java.nio.ByteBuffer plane1 =null;
128
-
Random rand =newRandom();
129
-
130
-
while (m_outboundVirtualVideoDevice !=null) {
131
-
while (m_mediaFrameSender !=null) {
132
-
if (m_mediaFrameSender.getMediaFrameKind() ==MediaFrameKind.VIDEO_SOFTWARE) {
// Feel free to use a better synchronization mechanism.
170
-
Thread.sleep(100);
153
+
private void StartFrameIterator()
154
+
{
155
+
frameIteratorThread = new Thread(this::FrameIterator);
156
+
frameIteratorThread.start();
157
+
}
158
+
159
+
public void StopFrameIterator()
160
+
{
161
+
try
162
+
{
163
+
if (frameIteratorThread != null)
164
+
{
165
+
stopFrameIterator = true;
166
+
frameIteratorThread.join();
167
+
frameIteratorThread = null;
168
+
stopFrameIterator = false;
169
+
}
170
+
}
171
+
catch (InterruptedException ex)
172
+
{
173
+
ex.getMessage();
174
+
}
175
+
}
176
+
177
+
@Override
178
+
public void SetVideoFrameSender(VideoFrameSender videoFramSender) {
179
+
180
+
StopFrameIterator();
181
+
this.videoFrameSender = videoFramSender;
182
+
StartFrameIterator();
183
+
}
171
184
}
172
185
```
186
+
187
+
## Screen Share Video Stream Overview
188
+
189
+
Repeat steps `1 to 4` from the previous VirtualVideoStream tutorial.
190
+
191
+
Since the Android system generates the frames, you have to implement your own foreground service to capture the frames and send them through using our API
192
+
193
+
The following is an overview of the steps required to create a screen share video stream.
194
+
195
+
1. Add this permission to your `Manifest.xml` file inside your Android project
screenShareVideoStream = new ScreenShareVideoStream(options);
207
+
```
208
+
209
+
3. Request needed permissions for screen capture on Android, once this method is called Android will call automatically `onActivityResult` containing the request code we have sent and the result of the operation, expect `Activity.RESULT_OK` if the permission has been provided by the user if so attach the screenShareVideoStream to the call and start your own foreground service to capture the frames.
0 commit comments