From 6f7c97a7293e8acc7b6be7badef9fb39a091cc07 Mon Sep 17 00:00:00 2001 From: claincly Date: Tue, 10 Nov 2020 23:15:37 +0000 Subject: [PATCH] Add method to expose the locally opened port for UdpDataSource. PiperOrigin-RevId: 341707809 --- .../android/exoplayer2/upstream/UdpDataSource.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java index 77a2c6ffee..2da837e788 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/UdpDataSource.java @@ -45,6 +45,8 @@ public final class UdpDataSource extends BaseDataSource { /** The default socket timeout, in milliseconds. */ public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000; + public static final int UDP_PORT_UNSET = -1; + private final int socketTimeoutMillis; private final byte[] packetBuffer; private final DatagramPacket packet; @@ -169,4 +171,15 @@ public final class UdpDataSource extends BaseDataSource { transferEnded(); } } + + /** + * Returns the local port number opened for the UDP connection, or {@link #UDP_PORT_UNSET} if no + * connection is open + */ + public int getLocalPort() { + if (socket == null) { + return UDP_PORT_UNSET; + } + return socket.getLocalPort(); + } }