- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
143 lines
5.2 KiB
Java
143 lines
5.2 KiB
Java
package com.mbridge.msdk.playercommon.exoplayer2.upstream;
|
|
|
|
import android.net.Uri;
|
|
import java.io.IOException;
|
|
import java.net.DatagramPacket;
|
|
import java.net.DatagramSocket;
|
|
import java.net.InetAddress;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.MulticastSocket;
|
|
import java.net.SocketException;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public final class UdpDataSource implements DataSource {
|
|
public static final int DEAFULT_SOCKET_TIMEOUT_MILLIS = 8000;
|
|
public static final int DEFAULT_MAX_PACKET_SIZE = 2000;
|
|
private InetAddress address;
|
|
private final TransferListener<? super UdpDataSource> listener;
|
|
private MulticastSocket multicastSocket;
|
|
private boolean opened;
|
|
private final DatagramPacket packet;
|
|
private final byte[] packetBuffer;
|
|
private int packetRemaining;
|
|
private DatagramSocket socket;
|
|
private InetSocketAddress socketAddress;
|
|
private final int socketTimeoutMillis;
|
|
private Uri uri;
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final Uri getUri() {
|
|
return this.uri;
|
|
}
|
|
|
|
public static final class UdpDataSourceException extends IOException {
|
|
public UdpDataSourceException(IOException iOException) {
|
|
super(iOException);
|
|
}
|
|
}
|
|
|
|
public UdpDataSource(TransferListener<? super UdpDataSource> transferListener) {
|
|
this(transferListener, 2000);
|
|
}
|
|
|
|
public UdpDataSource(TransferListener<? super UdpDataSource> transferListener, int i) {
|
|
this(transferListener, i, 8000);
|
|
}
|
|
|
|
public UdpDataSource(TransferListener<? super UdpDataSource> transferListener, int i, int i2) {
|
|
this.listener = transferListener;
|
|
this.socketTimeoutMillis = i2;
|
|
byte[] bArr = new byte[i];
|
|
this.packetBuffer = bArr;
|
|
this.packet = new DatagramPacket(bArr, 0, i);
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final long open(DataSpec dataSpec) throws UdpDataSourceException {
|
|
Uri uri = dataSpec.uri;
|
|
this.uri = uri;
|
|
String host = uri.getHost();
|
|
int port = this.uri.getPort();
|
|
try {
|
|
this.address = InetAddress.getByName(host);
|
|
this.socketAddress = new InetSocketAddress(this.address, port);
|
|
if (this.address.isMulticastAddress()) {
|
|
MulticastSocket multicastSocket = new MulticastSocket(this.socketAddress);
|
|
this.multicastSocket = multicastSocket;
|
|
multicastSocket.joinGroup(this.address);
|
|
this.socket = this.multicastSocket;
|
|
} else {
|
|
this.socket = new DatagramSocket(this.socketAddress);
|
|
}
|
|
try {
|
|
this.socket.setSoTimeout(this.socketTimeoutMillis);
|
|
this.opened = true;
|
|
TransferListener<? super UdpDataSource> transferListener = this.listener;
|
|
if (transferListener == null) {
|
|
return -1L;
|
|
}
|
|
transferListener.onTransferStart(this, dataSpec);
|
|
return -1L;
|
|
} catch (SocketException e) {
|
|
throw new UdpDataSourceException(e);
|
|
}
|
|
} catch (IOException e2) {
|
|
throw new UdpDataSourceException(e2);
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final int read(byte[] bArr, int i, int i2) throws UdpDataSourceException {
|
|
if (i2 == 0) {
|
|
return 0;
|
|
}
|
|
if (this.packetRemaining == 0) {
|
|
try {
|
|
this.socket.receive(this.packet);
|
|
int length = this.packet.getLength();
|
|
this.packetRemaining = length;
|
|
TransferListener<? super UdpDataSource> transferListener = this.listener;
|
|
if (transferListener != null) {
|
|
transferListener.onBytesTransferred(this, length);
|
|
}
|
|
} catch (IOException e) {
|
|
throw new UdpDataSourceException(e);
|
|
}
|
|
}
|
|
int length2 = this.packet.getLength();
|
|
int i3 = this.packetRemaining;
|
|
int min = Math.min(i3, i2);
|
|
System.arraycopy(this.packetBuffer, length2 - i3, bArr, i, min);
|
|
this.packetRemaining -= min;
|
|
return min;
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.playercommon.exoplayer2.upstream.DataSource
|
|
public final void close() {
|
|
this.uri = null;
|
|
MulticastSocket multicastSocket = this.multicastSocket;
|
|
if (multicastSocket != null) {
|
|
try {
|
|
multicastSocket.leaveGroup(this.address);
|
|
} catch (IOException unused) {
|
|
}
|
|
this.multicastSocket = null;
|
|
}
|
|
DatagramSocket datagramSocket = this.socket;
|
|
if (datagramSocket != null) {
|
|
datagramSocket.close();
|
|
this.socket = null;
|
|
}
|
|
this.address = null;
|
|
this.socketAddress = null;
|
|
this.packetRemaining = 0;
|
|
if (this.opened) {
|
|
this.opened = false;
|
|
TransferListener<? super UdpDataSource> transferListener = this.listener;
|
|
if (transferListener != null) {
|
|
transferListener.onTransferEnd(this);
|
|
}
|
|
}
|
|
}
|
|
}
|