diff --git a/sdk/android/api/org/webrtc/PeerConnection.java b/sdk/android/api/org/webrtc/PeerConnection.java index d530bc2c0c..d03d2a28ac 100644 --- a/sdk/android/api/org/webrtc/PeerConnection.java +++ b/sdk/android/api/org/webrtc/PeerConnection.java @@ -10,7 +10,10 @@ package org.webrtc; +import androidx.annotation.IntDef; import androidx.annotation.Nullable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -456,6 +459,15 @@ public class PeerConnection { UNIFIED_PLAN } + // Keep in sync with webrtc/p2p/base/port_allocator.h + @IntDef( + flag = true, + value = {PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS}) + @Retention(RetentionPolicy.SOURCE) + public @interface PortAllocatorFlags {} + + public static final int PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS = 0x8000; + /** Java version of PeerConnectionInterface.RTCConfiguration */ // TODO(qingsi): Resolve the naming inconsistency of fields with/without units. public static class RTCConfiguration { @@ -567,6 +579,9 @@ public class PeerConnection { */ public boolean offerExtmapAllowMixed; + /** Control port allocation, including what kinds of ports are allocated. */ + @PortAllocatorFlags public int portAllocatorFlags; + // TODO(deadbeef): Instead of duplicating the defaults here, we should do // something to pick up the defaults from C++. The Objective-C equivalent // of RTCConfiguration does that. @@ -608,6 +623,7 @@ public class PeerConnection { turnLoggingId = null; enableImplicitRollback = false; offerExtmapAllowMixed = true; + portAllocatorFlags = 0; } @CalledByNative("RTCConfiguration") @@ -816,6 +832,12 @@ public class PeerConnection { boolean getOfferExtmapAllowMixed() { return offerExtmapAllowMixed; } + + @CalledByNative("RTCConfiguration") + @PortAllocatorFlags + int getPortAllocatorFlags() { + return portAllocatorFlags; + } }; private final List localStreams = new ArrayList<>(); diff --git a/sdk/android/src/jni/pc/peer_connection.cc b/sdk/android/src/jni/pc/peer_connection.cc index e5fb11e3b4..de23e489ae 100644 --- a/sdk/android/src/jni/pc/peer_connection.cc +++ b/sdk/android/src/jni/pc/peer_connection.cc @@ -277,6 +277,9 @@ void JavaToNativeRTCConfiguration( if (!IsNull(jni, j_turn_logging_id)) { rtc_config->turn_logging_id = JavaToNativeString(jni, j_turn_logging_id); } + + rtc_config->port_allocator_config.flags = + Java_RTCConfiguration_getPortAllocatorFlags(jni, j_rtc_config); } rtc::KeyType GetRtcConfigKeyType(JNIEnv* env,