LoginSignup
1
1

More than 3 years have passed since last update.

AndroidでKinesis Video Stream のWebRTC機能を試す

Posted at

(雑ですが備忘録です)

ビルド&実行

以下のGithubに沿ってCognitoの設定を行い、サンプルコードをビルドする。
https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-android

Master起動後に、別のAndroid端末でViewerを起動すると、ビデオ通話ができました。

また、Kinesis Video Streams のSignaling Channelsから、CloudWatchのログ等が確認できました。
image.png

コード上のメモ

チャネルARNの取得

mChannelArn = describeSignalingChannelResult.getChannelInfo().getChannelARN();
Channel ARN is arn:aws:kinesisvideo:ap-northeast-1:123456789:channel/demo-channel/1575874258965

ARNの末尾の 1575874258965 はUnix Time Stampぽいです

Endpoint 取得

上記のARNやロール(MasterかViwerか)を設定し、リソースエンドポイントを取得しています。

                GetSignalingChannelEndpointResult getSignalingChannelEndpointResult = awsKinesisVideoClient.getSignalingChannelEndpoint(
                        new GetSignalingChannelEndpointRequest()
                                .withChannelARN(mChannelArn)
                                .withSingleMasterChannelEndpointConfiguration(
                                        new SingleMasterChannelEndpointConfiguration()
                                                .withProtocols("WSS", "HTTPS")
                                                .withRole(role)));
{ResourceEndpointList: [{Protocol: WSS,ResourceEndpoint: wss://<id>.kinesisvideo.ap-northeast-1.amazonaws.com}, {Protocol: HTTPS,ResourceEndpoint: https://<id>.kinesisvideo.ap-northeast-1.amazonaws.com}]}

こちらで取得したHTTPSのエンドポイントを使って、AWSKinesisVideoSignalingClientのインスタンスを作成し、ICEサーバーの情報を取得しています。

ICE Server list

getIceServerConfigResult.getIceServerList()

手元で出力されたログをみたところ、2つのIPをturnを使って取得しているようでした。

{Uris: [turn:12.34.56.78:443],Username: xxx,Password: XXX,Ttl: 300}
{Uris: [turn:23.45.67.89:443],Username: yyy,Password: YYY,Ttl: 300}
WebRtcActivity.java
        PeerConnection.IceServer stun = PeerConnection
                .IceServer
                .builder(String.format("stun:stun.kinesisvideo.%s.amazonaws.com:443", mRegion))
                .createIceServer();
        peerIceServers.add(stun);

Stun サーバーについてはは、リージョンごとに固定のエンドポイントを指定しています。
上記の情報等を用いて、 PeerConnectionFactory.createPeerConnection()でピア接続を行います。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1