package x0;

import B0.V;
import android.media.MediaFormat;
import android.net.Uri;
import android.opengl.GLES20;
import android.opengl.GLU;
import android.text.TextUtils;
import android.util.Log;
import c0.ThreadFactoryC0564a;
import d5.AbstractC0844a;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.xmlpull.v1.XmlPullParser;

/* JADX INFO: renamed from: x0.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1709a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static ExecutorService f18497a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Object f18498b = new Object();

    public static void A(MediaFormat mediaFormat, List list) {
        for (int i = 0; i < list.size(); i++) {
            mediaFormat.setByteBuffer(AbstractC0844a.j("csd-", i), ByteBuffer.wrap((byte[]) list.get(i)));
        }
    }

    public static void B(String str, String str2) {
        synchronized (f18498b) {
            Log.w(str, a(str2, null));
        }
    }

    public static void C(String str, String str2, Throwable th) {
        synchronized (f18498b) {
            Log.w(str, a(str2, th));
        }
    }

    public static String a(String str, Throwable th) {
        String strReplace;
        if (th != null) {
            synchronized (f18498b) {
                Throwable cause = th;
                while (true) {
                    if (cause == null) {
                        strReplace = Log.getStackTraceString(th).trim().replace("\t", "    ");
                        break;
                    }
                    try {
                        if (cause instanceof UnknownHostException) {
                            strReplace = "UnknownHostException (no network)";
                        } else {
                            cause = cause.getCause();
                        }
                    } finally {
                    }
                }
            }
        } else {
            strReplace = null;
        }
        if (TextUtils.isEmpty(strReplace)) {
            return str;
        }
        return str + "\n  " + strReplace.replace("\n", "\n  ") + '\n';
    }

    public static void b(int i, int i5) throws f {
        GLES20.glBindTexture(i, i5);
        e();
        GLES20.glTexParameteri(i, 10240, 9729);
        e();
        GLES20.glTexParameteri(i, 10241, 9729);
        e();
        GLES20.glTexParameteri(i, 10242, 33071);
        e();
        GLES20.glTexParameteri(i, 10243, 33071);
        e();
    }

    public static void c(String str, boolean z8) {
        if (!z8) {
            throw new IllegalArgumentException(String.valueOf(str));
        }
    }

    public static void d(boolean z8) {
        if (!z8) {
            throw new IllegalArgumentException();
        }
    }

    public static void e() throws f {
        StringBuilder sb = new StringBuilder();
        boolean z8 = false;
        while (true) {
            int iGlGetError = GLES20.glGetError();
            if (iGlGetError == 0) {
                break;
            }
            if (z8) {
                sb.append('\n');
            }
            String strGluErrorString = GLU.gluErrorString(iGlGetError);
            if (strGluErrorString == null) {
                strGluErrorString = "error code: 0x" + Integer.toHexString(iGlGetError);
            }
            sb.append("glError: ");
            sb.append(strGluErrorString);
            z8 = true;
        }
        if (z8) {
            throw new f(sb.toString());
        }
    }

    public static void f(String str, boolean z8) throws f {
        if (!z8) {
            throw new f(str);
        }
    }

    public static void g(int i, int i5) {
        if (i < 0 || i >= i5) {
            throw new IndexOutOfBoundsException();
        }
    }

    public static void h(V v7) {
        v7.getClass();
    }

    public static void i(String str, boolean z8) {
        if (!z8) {
            throw new IllegalStateException(String.valueOf(str));
        }
    }

    public static void j(boolean z8) {
        if (!z8) {
            throw new IllegalStateException();
        }
    }

    public static void k(Object obj) {
        if (obj == null) {
            throw new IllegalStateException();
        }
    }

    public static void l(Object obj, String str) {
        if (obj == null) {
            throw new IllegalStateException(str);
        }
    }

    public static FloatBuffer m(float[] fArr) {
        return (FloatBuffer) ByteBuffer.allocateDirect(fArr.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer().put(fArr).flip();
    }

    public static void n(String str, String str2) {
        synchronized (f18498b) {
            Log.d(str, a(str2, null));
        }
    }

    public static void o(String str, String str2) {
        synchronized (f18498b) {
            Log.e(str, a(str2, null));
        }
    }

    public static void p(String str, String str2, Throwable th) {
        synchronized (f18498b) {
            Log.e(str, a(str2, th));
        }
    }

    public static synchronized Executor q() {
        try {
            if (f18497a == null) {
                int i = v.f18553a;
                f18497a = Executors.newSingleThreadExecutor(new ThreadFactoryC0564a(1, "ExoPlayer:BackgroundExecutor"));
            }
        } catch (Throwable th) {
            throw th;
        }
        return f18497a;
    }

    public static String r(XmlPullParser xmlPullParser, String str) {
        int attributeCount = xmlPullParser.getAttributeCount();
        for (int i = 0; i < attributeCount; i++) {
            if (xmlPullParser.getAttributeName(i).equals(str)) {
                return xmlPullParser.getAttributeValue(i);
            }
        }
        return null;
    }

    public static int[] s(String str) {
        int iIndexOf;
        int[] iArr = new int[4];
        if (TextUtils.isEmpty(str)) {
            iArr[0] = -1;
            return iArr;
        }
        int length = str.length();
        int iIndexOf2 = str.indexOf(35);
        if (iIndexOf2 != -1) {
            length = iIndexOf2;
        }
        int iIndexOf3 = str.indexOf(63);
        if (iIndexOf3 == -1 || iIndexOf3 > length) {
            iIndexOf3 = length;
        }
        int iIndexOf4 = str.indexOf(47);
        if (iIndexOf4 == -1 || iIndexOf4 > iIndexOf3) {
            iIndexOf4 = iIndexOf3;
        }
        int iIndexOf5 = str.indexOf(58);
        if (iIndexOf5 > iIndexOf4) {
            iIndexOf5 = -1;
        }
        int i = iIndexOf5 + 2;
        if (i < iIndexOf3 && str.charAt(iIndexOf5 + 1) == '/' && str.charAt(i) == '/') {
            iIndexOf = str.indexOf(47, iIndexOf5 + 3);
            if (iIndexOf == -1 || iIndexOf > iIndexOf3) {
                iIndexOf = iIndexOf3;
            }
        } else {
            iIndexOf = iIndexOf5 + 1;
        }
        iArr[0] = iIndexOf5;
        iArr[1] = iIndexOf;
        iArr[2] = iIndexOf3;
        iArr[3] = length;
        return iArr;
    }

    public static void t(String str, String str2) {
        synchronized (f18498b) {
            Log.i(str, a(str2, null));
        }
    }

    public static boolean u(XmlPullParser xmlPullParser, String str) {
        return xmlPullParser.getEventType() == 3 && xmlPullParser.getName().equals(str);
    }

    public static boolean v(XmlPullParser xmlPullParser, String str) {
        return xmlPullParser.getEventType() == 2 && xmlPullParser.getName().equals(str);
    }

    public static void w(MediaFormat mediaFormat, String str, int i) {
        if (i != -1) {
            mediaFormat.setInteger(str, i);
        }
    }

    public static String x(StringBuilder sb, int i, int i5) {
        int i8;
        int iLastIndexOf;
        if (i >= i5) {
            return sb.toString();
        }
        if (sb.charAt(i) == '/') {
            i++;
        }
        int i9 = i;
        int i10 = i9;
        while (i9 <= i5) {
            if (i9 == i5) {
                i8 = i9;
            } else if (sb.charAt(i9) == '/') {
                i8 = i9 + 1;
            } else {
                i9++;
            }
            int i11 = i10 + 1;
            if (i9 == i11 && sb.charAt(i10) == '.') {
                sb.delete(i10, i8);
                i5 -= i8 - i10;
            } else {
                if (i9 == i10 + 2 && sb.charAt(i10) == '.' && sb.charAt(i11) == '.') {
                    iLastIndexOf = sb.lastIndexOf("/", i10 - 2) + 1;
                    int i12 = iLastIndexOf > i ? iLastIndexOf : i;
                    sb.delete(i12, i8);
                    i5 -= i8 - i12;
                } else {
                    iLastIndexOf = i9 + 1;
                }
                i10 = iLastIndexOf;
            }
            i9 = i10;
        }
        return sb.toString();
    }

    public static String y(String str, String str2) {
        StringBuilder sb = new StringBuilder();
        if (str == null) {
            str = "";
        }
        if (str2 == null) {
            str2 = "";
        }
        int[] iArrS = s(str2);
        if (iArrS[0] != -1) {
            sb.append(str2);
            x(sb, iArrS[1], iArrS[2]);
            return sb.toString();
        }
        int[] iArrS2 = s(str);
        if (iArrS[3] == 0) {
            sb.append((CharSequence) str, 0, iArrS2[3]);
            sb.append(str2);
            return sb.toString();
        }
        if (iArrS[2] == 0) {
            sb.append((CharSequence) str, 0, iArrS2[2]);
            sb.append(str2);
            return sb.toString();
        }
        int i = iArrS[1];
        if (i != 0) {
            int i5 = iArrS2[0] + 1;
            sb.append((CharSequence) str, 0, i5);
            sb.append(str2);
            return x(sb, iArrS[1] + i5, i5 + iArrS[2]);
        }
        if (str2.charAt(i) == '/') {
            sb.append((CharSequence) str, 0, iArrS2[1]);
            sb.append(str2);
            int i8 = iArrS2[1];
            return x(sb, i8, iArrS[2] + i8);
        }
        int i9 = iArrS2[0] + 2;
        int i10 = iArrS2[1];
        if (i9 >= i10 || i10 != iArrS2[2]) {
            int iLastIndexOf = str.lastIndexOf(47, iArrS2[2] - 1);
            int i11 = iLastIndexOf == -1 ? iArrS2[1] : iLastIndexOf + 1;
            sb.append((CharSequence) str, 0, i11);
            sb.append(str2);
            return x(sb, iArrS2[1], i11 + iArrS[2]);
        }
        sb.append((CharSequence) str, 0, i10);
        sb.append('/');
        sb.append(str2);
        int i12 = iArrS2[1];
        return x(sb, i12, iArrS[2] + i12 + 1);
    }

    public static Uri z(String str, String str2) {
        return Uri.parse(y(str, str2));
    }
}
