Chromium Code Reviews| 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 a26c86d0391181b50a27085e544d20f173967e70..28ed428e688c885635c453ce0ffc897c62d8430f 100644 |
| --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java |
| +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java |
| @@ -16,6 +16,7 @@ import android.os.ParcelFileDescriptor; |
| import android.util.Log; |
| import java.io.File; |
| import java.io.IOException; |
| +import java.nio.ByteBuffer; |
| import java.util.Collections; |
| import java.util.EnumSet; |
| import java.util.LinkedList; |
| @@ -126,6 +127,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. |
| @@ -149,12 +174,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; |
| @@ -173,6 +211,7 @@ public class PeerConnectionClient { |
| this.disableBuiltInAGC = disableBuiltInAGC; |
| this.disableBuiltInNS = disableBuiltInNS; |
| this.enableLevelControl = enableLevelControl; |
| + this.dataChannelParameters = dataChannelParameters; |
| } |
| } |
| @@ -243,6 +282,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; |
| @@ -484,6 +524,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. |
| @@ -524,6 +575,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; |
| @@ -540,7 +595,6 @@ public class PeerConnectionClient { |
| } catch (InterruptedException e) { |
| throw new RuntimeException(e); |
| } |
| - videoCapturerStopped = true; |
|
magjed_webrtc
2016/11/17 10:51:05
Don't remove this.
|
| videoCapturer.dispose(); |
| videoCapturer = null; |
| } |
| @@ -1076,7 +1130,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 |