Add PortAllocatorFlags to JAVA API

And add PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS
which makes WebRTC allocate an unbound port.

BUG=None

Tested: Manually (not the flag, but that it doesn't break anything)
Change-Id: Iba541eb366f111e5ab7844bb3a2dc25ca0838cfe
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/347881
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42119}
This commit is contained in:
Jonas Oreland 2024-04-18 14:02:54 +02:00 committed by WebRTC LUCI CQ
parent f459fb31b9
commit 299b285696
2 changed files with 25 additions and 0 deletions

View File

@ -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<MediaStream> localStreams = new ArrayList<>();

View File

@ -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,