| Index: webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
|
| diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
|
| index 8166b90adc2ee1be67e86a8d6bc1815f8ec4acfd..58b85db95f78afc37b8492506feda3e809dcf485 100644
|
| --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
|
| +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
|
| @@ -44,6 +44,7 @@ import org.webrtc.voiceengine.WebRtcAudioUtils;
|
|
|
| import java.io.File;
|
| import java.io.IOException;
|
| +import java.nio.ByteBuffer;
|
| import java.util.Collections;
|
| import java.util.EnumSet;
|
| import java.util.LinkedList;
|
| @@ -132,6 +133,30 @@ public class PeerConnectionClient {
|
| // enableAudio is set to true if audio should be sent.
|
| private boolean enableAudio;
|
| private AudioTrack localAudioTrack;
|
| + private DataChannel dataChannel;
|
| + private boolean dataChannelEnabled;
|
| +
|
| + /**
|
| + * Peer connection parameters.
|
| + */
|
| + public static class DataChannelParameters {
|
| + public final boolean ordered;
|
| + public final int maxRetransmitTimeMs;
|
| + public final int maxRetransmits;
|
| + public final String protocol;
|
| + public final boolean negotiated;
|
| + public final int id;
|
| +
|
| + public DataChannelParameters(boolean ordered, int maxRetransmitTimeMs, int maxRetransmits,
|
| + String protocol, boolean negotiated, int id) {
|
| + this.ordered = ordered;
|
| + this.maxRetransmitTimeMs = maxRetransmitTimeMs;
|
| + this.maxRetransmits = maxRetransmits;
|
| + this.protocol = protocol;
|
| + this.negotiated = negotiated;
|
| + this.id = id;
|
| + }
|
| + }
|
|
|
| /**
|
| * Peer connection parameters.
|
| @@ -155,12 +180,25 @@ public class PeerConnectionClient {
|
| public final boolean disableBuiltInAGC;
|
| public final boolean disableBuiltInNS;
|
| public final boolean enableLevelControl;
|
| + private final DataChannelParameters dataChannelParameters;
|
|
|
| public PeerConnectionParameters(boolean videoCallEnabled, boolean loopback, boolean tracing,
|
| int videoWidth, int videoHeight, int videoFps, int videoMaxBitrate, String videoCodec,
|
| boolean videoCodecHwAcceleration, int audioStartBitrate, String audioCodec,
|
| boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, boolean disableBuiltInAEC,
|
| boolean disableBuiltInAGC, boolean disableBuiltInNS, boolean enableLevelControl) {
|
| + this(videoCallEnabled, loopback, tracing, videoWidth, videoHeight, videoFps, videoMaxBitrate,
|
| + videoCodec, videoCodecHwAcceleration, audioStartBitrate, audioCodec, noAudioProcessing,
|
| + aecDump, useOpenSLES, disableBuiltInAEC, disableBuiltInAGC, disableBuiltInNS,
|
| + enableLevelControl, null);
|
| + }
|
| +
|
| + public PeerConnectionParameters(boolean videoCallEnabled, boolean loopback, boolean tracing,
|
| + int videoWidth, int videoHeight, int videoFps, int videoMaxBitrate, String videoCodec,
|
| + boolean videoCodecHwAcceleration, int audioStartBitrate, String audioCodec,
|
| + boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES, boolean disableBuiltInAEC,
|
| + boolean disableBuiltInAGC, boolean disableBuiltInNS, boolean enableLevelControl,
|
| + DataChannelParameters dataChannelParameters) {
|
| this.videoCallEnabled = videoCallEnabled;
|
| this.loopback = loopback;
|
| this.tracing = tracing;
|
| @@ -179,6 +217,7 @@ public class PeerConnectionClient {
|
| this.disableBuiltInAGC = disableBuiltInAGC;
|
| this.disableBuiltInNS = disableBuiltInNS;
|
| this.enableLevelControl = enableLevelControl;
|
| + this.dataChannelParameters = dataChannelParameters;
|
| }
|
| }
|
|
|
| @@ -249,6 +288,7 @@ public class PeerConnectionClient {
|
| this.peerConnectionParameters = peerConnectionParameters;
|
| this.events = events;
|
| videoCallEnabled = peerConnectionParameters.videoCallEnabled;
|
| + dataChannelEnabled = peerConnectionParameters.dataChannelParameters != null;
|
| // Reset variables to initial states.
|
| this.context = null;
|
| factory = null;
|
| @@ -493,6 +533,17 @@ public class PeerConnectionClient {
|
| rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
|
|
|
| peerConnection = factory.createPeerConnection(rtcConfig, pcConstraints, pcObserver);
|
| +
|
| + if (dataChannelEnabled) {
|
| + DataChannel.Init init = new DataChannel.Init();
|
| + init.ordered = peerConnectionParameters.dataChannelParameters.ordered;
|
| + init.negotiated = peerConnectionParameters.dataChannelParameters.negotiated;
|
| + init.maxRetransmits = peerConnectionParameters.dataChannelParameters.maxRetransmits;
|
| + init.maxRetransmitTimeMs = peerConnectionParameters.dataChannelParameters.maxRetransmitTimeMs;
|
| + init.id = peerConnectionParameters.dataChannelParameters.id;
|
| + init.protocol = peerConnectionParameters.dataChannelParameters.protocol;
|
| + dataChannel = peerConnection.createDataChannel("ApprtcDemo data", init);
|
| + }
|
| isInitiator = false;
|
|
|
| // Set default WebRTC tracing and INFO libjingle logging.
|
| @@ -533,6 +584,10 @@ public class PeerConnectionClient {
|
| }
|
| Log.d(TAG, "Closing peer connection.");
|
| statsTimer.cancel();
|
| + if (dataChannel != null) {
|
| + dataChannel.dispose();
|
| + dataChannel = null;
|
| + }
|
| if (peerConnection != null) {
|
| peerConnection.dispose();
|
| peerConnection = null;
|
| @@ -1084,7 +1139,34 @@ public class PeerConnectionClient {
|
|
|
| @Override
|
| public void onDataChannel(final DataChannel dc) {
|
| - reportError("AppRTC doesn't use data channels, but got: " + dc.label() + " anyway!");
|
| + Log.d(TAG, "New Data channel " + dc.label());
|
| +
|
| + if (!dataChannelEnabled)
|
| + return;
|
| +
|
| + dc.registerObserver(new DataChannel.Observer() {
|
| + public void onBufferedAmountChange(long previousAmount) {
|
| + Log.d(TAG, "Data channel buffered amount changed: " + dc.label() + ": " + dc.state());
|
| + }
|
| +
|
| + @Override
|
| + public void onStateChange() {
|
| + Log.d(TAG, "Data channel state changed: " + dc.label() + ": " + dc.state());
|
| + }
|
| +
|
| + @Override
|
| + public void onMessage(final DataChannel.Buffer buffer) {
|
| + if (buffer.binary) {
|
| + Log.d(TAG, "Received binary msg over " + dc);
|
| + return;
|
| + }
|
| + ByteBuffer data = buffer.data;
|
| + final byte[] bytes = new byte[data.capacity()];
|
| + data.get(bytes);
|
| + String strData = new String(bytes);
|
| + Log.d(TAG, "Got msg: " + strData + " over " + dc);
|
| + }
|
| + });
|
| }
|
|
|
| @Override
|
|
|