Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java

Issue 2464243002: Add Datachannel support to Android AppRTCMobile (Closed)
Patch Set: modify authors Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6052a4d8e3155e7fb7f1a621f447d4b7ee9ae77e 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,31 @@ 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 +181,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, useCamera2, 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 +218,7 @@ public class PeerConnectionClient {
this.disableBuiltInAGC = disableBuiltInAGC;
this.disableBuiltInNS = disableBuiltInNS;
this.enableLevelControl = enableLevelControl;
+ this.dataChannelParameters = dataChannelParameters;
}
}
@@ -249,6 +289,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 +534,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 +585,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;
@@ -549,6 +605,7 @@ public class PeerConnectionClient {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
+ videoCapturerStopped = true;
sakal 2016/11/09 11:45:03 This is probably correct but please do not add unr
hekra01 2016/11/10 02:32:20 Done.
videoCapturer.dispose();
videoCapturer = null;
}
@@ -1084,7 +1141,43 @@ 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());
sakal 2016/11/09 11:45:03 nit: Don't make new all caps
hekra01 2016/11/10 02:32:20 Done.
+
+ if (!dataChannelEnabled)
+ return;
+
+ dc.registerObserver(new DataChannel.Observer() {
+ public void onBufferedAmountChange(long var1){
sakal 2016/11/09 11:45:03 nit: var1 is not a very descriptive name here. May
hekra01 2016/11/10 02:32:20 Naming fixed No spam.Callback doeas not seem calle
+ 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);
+ Runnable command = new Runnable() {
+ @Override
+ public void run() {
+ // Get DC message as String.
+ String strData = new String(bytes);
+ Log.d(TAG, "Got msg: " + strData + " over " + dc);
sakal 2016/11/09 11:45:03 Maybe we should show the message in a toast?
hekra01 2016/11/10 02:32:20 DataChannel use cases would be to enable chat/file
+ }
+ };
+ executor.execute(command);
sakal 2016/11/09 11:45:03 Why does this have to be posted?
hekra01 2016/11/10 02:32:20 Done because of comments in the PeerConnectionClie
sakal 2016/11/10 08:31:42 But you are not making any peerconnection API call
hekra01 2016/11/10 14:16:53 Correct. Removed the post
+ }
+ });
}
@Override

Powered by Google App Engine
This is Rietveld 408576698