package defpackage;

import android.net.Uri;
import androidx.media3.datasource.UdpDataSource$UdpDataSourceException;
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.SocketTimeoutException;

/* renamed from: ˈᵫʕᵢ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1093 extends AbstractC1628 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final DatagramPacket f4704;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public MulticastSocket f4705;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public DatagramSocket f4706;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public Uri f4707;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final byte[] f4708;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final int f4709;

    /* renamed from: ᵧـˌᵎ, reason: contains not printable characters */
    public boolean f4710;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public InetAddress f4711;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public int f4712;

    public C1093() {
        this(8000);
    }

    public C1093(int i) {
        super(true);
        this.f4709 = i;
        byte[] bArr = new byte[2000];
        this.f4708 = bArr;
        this.f4704 = new DatagramPacket(bArr, 0, 2000);
    }

    @Override // defpackage.InterfaceC2569
    public final void close() throws IOException {
        this.f4707 = null;
        MulticastSocket multicastSocket = this.f4705;
        if (multicastSocket != null) {
            try {
                InetAddress inetAddress = this.f4711;
                inetAddress.getClass();
                multicastSocket.leaveGroup(inetAddress);
            } catch (IOException unused) {
            }
            this.f4705 = null;
        }
        DatagramSocket datagramSocket = this.f4706;
        if (datagramSocket != null) {
            datagramSocket.close();
            this.f4706 = null;
        }
        this.f4711 = null;
        this.f4712 = 0;
        if (this.f4710) {
            this.f4710 = false;
            m4667();
        }
    }

    @Override // defpackage.InterfaceC1463
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        if (i2 == 0) {
            return 0;
        }
        int i3 = this.f4712;
        DatagramPacket datagramPacket = this.f4704;
        if (i3 == 0) {
            try {
                DatagramSocket datagramSocket = this.f4706;
                datagramSocket.getClass();
                datagramSocket.receive(datagramPacket);
                int length = datagramPacket.getLength();
                this.f4712 = length;
                m4668(length);
            } catch (SocketTimeoutException e) {
                throw new UdpDataSource$UdpDataSourceException(2002, e);
            } catch (IOException e2) {
                throw new UdpDataSource$UdpDataSourceException(2001, e2);
            }
        }
        int length2 = datagramPacket.getLength();
        int i4 = this.f4712;
        int iMin = Math.min(i4, i2);
        System.arraycopy(this.f4708, length2 - i4, bArr, i, iMin);
        this.f4712 -= iMin;
        return iMin;
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ˏˋٴ */
    public final long mo1165(C4179 c4179) {
        Uri uri = c4179.f15620;
        this.f4707 = uri;
        String host = uri.getHost();
        host.getClass();
        int port = this.f4707.getPort();
        m4666();
        try {
            this.f4711 = InetAddress.getByName(host);
            InetSocketAddress inetSocketAddress = new InetSocketAddress(this.f4711, port);
            if (this.f4711.isMulticastAddress()) {
                MulticastSocket multicastSocket = new MulticastSocket(inetSocketAddress);
                this.f4705 = multicastSocket;
                multicastSocket.joinGroup(this.f4711);
                this.f4706 = this.f4705;
            } else {
                this.f4706 = new DatagramSocket(inetSocketAddress);
            }
            this.f4706.setSoTimeout(this.f4709);
            this.f4710 = true;
            m4669(c4179);
            return -1L;
        } catch (IOException e) {
            throw new UdpDataSource$UdpDataSourceException(2001, e);
        } catch (SecurityException e2) {
            throw new UdpDataSource$UdpDataSourceException(2006, e2);
        }
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ᵿʗᵝʽ */
    public final Uri mo1166() {
        return this.f4707;
    }
}
