package com.google.android.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;
import p138.p176.p177.p190.p238.AbstractC4092;
import p138.p176.p177.p190.p238.C4098;

/* JADX INFO: loaded from: classes.dex */
public final class UdpDataSource extends AbstractC4092 {

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final int f2004;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final byte[] f2005;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final DatagramPacket f2006;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public Uri f2007;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public DatagramSocket f2008;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public MulticastSocket f2009;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public InetAddress f2010;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public InetSocketAddress f2011;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public boolean f2012;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public int f2013;

    public static final class UdpDataSourceException extends IOException {
        public UdpDataSourceException(IOException iOException) {
            super(iOException);
        }
    }

    public UdpDataSource() {
        super(true);
        this.f2004 = 8000;
        this.f2005 = new byte[2000];
        this.f2006 = new DatagramPacket(this.f2005, 0, 2000);
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    public void close() {
        this.f2007 = null;
        MulticastSocket multicastSocket = this.f2009;
        if (multicastSocket != null) {
            try {
                multicastSocket.leaveGroup(this.f2010);
            } catch (IOException unused) {
            }
            this.f2009 = null;
        }
        DatagramSocket datagramSocket = this.f2008;
        if (datagramSocket != null) {
            datagramSocket.close();
            this.f2008 = null;
        }
        this.f2010 = null;
        this.f2011 = null;
        this.f2013 = 0;
        if (this.f2012) {
            this.f2012 = false;
            m6581();
        }
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ֏ */
    public int mo1282(byte[] bArr, int i, int i2) throws UdpDataSourceException {
        if (i2 == 0) {
            return 0;
        }
        if (this.f2013 == 0) {
            try {
                this.f2008.receive(this.f2006);
                int length = this.f2006.getLength();
                this.f2013 = length;
                m6579(length);
            } catch (IOException e) {
                throw new UdpDataSourceException(e);
            }
        }
        int length2 = this.f2006.getLength();
        int i3 = this.f2013;
        int iMin = Math.min(i3, i2);
        System.arraycopy(this.f2005, length2 - i3, bArr, i, iMin);
        this.f2013 -= iMin;
        return iMin;
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ֏ */
    public long mo1283(C4098 c4098) throws UdpDataSourceException {
        Uri uri = c4098.f13076;
        this.f2007 = uri;
        String host = uri.getHost();
        int port = this.f2007.getPort();
        m6580(c4098);
        try {
            this.f2010 = InetAddress.getByName(host);
            this.f2011 = new InetSocketAddress(this.f2010, port);
            if (this.f2010.isMulticastAddress()) {
                MulticastSocket multicastSocket = new MulticastSocket(this.f2011);
                this.f2009 = multicastSocket;
                multicastSocket.joinGroup(this.f2010);
                this.f2008 = this.f2009;
            } else {
                this.f2008 = new DatagramSocket(this.f2011);
            }
            try {
                this.f2008.setSoTimeout(this.f2004);
                this.f2012 = true;
                m6582(c4098);
                return -1L;
            } catch (SocketException e) {
                throw new UdpDataSourceException(e);
            }
        } catch (IOException e2) {
            throw new UdpDataSourceException(e2);
        }
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ؠ */
    public Uri mo1284() {
        return this.f2007;
    }
}
