To download the Kinesis Video Streams WebRTC SDK in Android, run the following command:
git clone https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-android.git
Follow the instructions here to set up an Amazon Cognito user pool for secure login.
Follow the instructions here to set up an Amazon Cognito identity pool.
- Import the downloaded SDK into the Android Studio integrated development environment by opening the amazon-kinesis-video-streams-webrtc-sdkandroid/build.gradle with
Open an existing Android Studio project. - You will need all the information from the above steps copied in clipboard, then paste them into this file on your local file awsconfiguration.json. Your completed awsconfiguration.json should look something like this:
{
"Version": "1.0",
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "us-west-2:01234567-89ab-cdef-0123-456789abcdef",
"Region": "us-west-2"
}
}
},
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"AppClientSecret": "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmno",
"AppClientId": "0123456789abcdefghijklmnop",
"PoolId": "us-west-2_qRsTuVwXy",
"Region": "us-west-2"
}
}
}-
Import Google WebRTC (aka libwebrtc). Choose one of the following:
a. Build libwebrtc yourself, following https://webrtc.github.io/webrtc-org/native-code/android/#getting-the-code. After it's been built, place the
.aarfile in libs.b. Acquire a pre-built binary of libwebrtc and import it.
-
Click gradle Sync and Build
-
Run the demo application in simulator or in Android device (connected through USB).
On your Android device, open AWSKinesisVideoWebRTCDemoApp and sign up with Create New Account or sign in with existing accounts.
Note: This account information is stored in your Cognito User Pool and is not your AWS Console user name/password.
Once login is successful, you will entering the following channel information to start peer to peer streaming.
- Enter a channel name: e.g.
demo-channel - Enter AWS region: e.g.
us-west-2 - Select
audioif you would like to send both audio or video data. - Optionally, when using it in
viewermode, you can enter a uniqueClient Id. Client ID is required only if multiple viewers are connected to a channel. This helps channel's master identify respective viewers.
To verify peer to peer streaming, do any of the following setup. In these setup, ensure that the signaling channel name, region, viewer ID, and the AWS account ID are the same.
- Start one Android device in
mastermode for starting a new session. Remote peer will be joining as viewer to this master. There should be only one master for any given channel. - Use another Android device to connect to the same channel name (started up in the step above as
master) inviewermode; this will connect to an existing session (channel) where a master is connected. - Verify media showing up in both Android devices.
- Run Kinesis Video Streams WebRTC embedded SDK in
mastermode on a camera device. - Start the Android device in
viewermode - you should be able to check the video (and audio if selected both in embedded SDK) showing up in the Android device from the camera. - Verify media showing up from the Embedded SDK to the Android.
- Start one Android device in
mastermode for starting a new session. - Start the web browser using the Javascript SDK and start it as
viewer. - Verify media showing up from the Android device to the browser.
The sample application demonstrates how to connect to the KVS WebRTC storage session as a master or viewer participant.
For more information about WebRTC ingestion, see https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/webrtc-ingestion.html.
Follow the instructions below to:
- Create the signaling channel: https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/ingestion-create-channel.html
- Create the stream: https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/ingestion-create-stream.html
- Link the signaling channel and stream: https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/configure-ingestion.html
- Configure the IAM role with the correct permissions: https://docs.aws.amazon.com/kinesisvideostreams-webrtc-dg/latest/devguide/ingestion-grant-permission.html
- Ensure H.264 and OPUS codec support is available on the device
Usage:
-
Master with Ingest Media: Check the "Ingest Media" option and ensure both "Send Audio" and "Send Video" are selected. The master will stream audio and video to the KVS WebRTC storage session, who forwards it to all connected viewer participants and the configured Kinesis Video stream.
-
Viewer with Ingest Media: Check the "Ingest Media" option but only select "Send Audio" (video must be deselected). Multiple viewer participants (at most three) can connect to the same channel and their optional audio will be incorporated into the Kinesis Video stream, forwarded to the master participant, and forwarded to all other viewer participants.
Note
Android emulators may not have H.264 encoding support. A pop-up error will appear if the device you're using does not have H.264 encoding support for master participants or H.264 decoding support for viewer participants.
Candidate trickling is a technique through which a caller may incrementally provide candidates to the callee after the initial offer has been dispatched; the semantics of "Trickle ICE" are defined in [RFC8838].
Trickle ICE is the default behavior within the Kinesis Video Stream WebRTC SDK for Android since it reduces the time it takes for the ICE negotiation process. However, in the case that it needs to be disabled, locate the RTCConfiguration property called ContinualGatheringPolicy and change it to GATHER_ONCE instead of GATHER_CONTINUALLY (default).
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration();
rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;This SDK has been tested with Java 11, 17 to build the Gradle dependencies and Java 8, 11, and, 17 in the compile options in build.gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
For more details about the different Java versions, please check Java versions in Android builds
This library is licensed under the Apache 2.0 License.