package defpackage;

import android.graphics.SurfaceTexture;
import android.media.MediaFormat;
import android.opengl.GLES20;
import android.opengl.Matrix;
import androidx.media3.common.util.GlUtil$GlException;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: renamed from: ˁᵕ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0716 implements InterfaceC0819, InterfaceC4690 {

    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    public volatile int f3255;

    /* JADX INFO: renamed from: ˈᵲᵢ, reason: contains not printable characters */
    public final float[] f3256;

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public byte[] f3257;

    /* JADX INFO: renamed from: ˌᵨʠᵫ, reason: contains not printable characters */
    public final float[] f3259;

    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    public SurfaceTexture f3260;

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public int f3263;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public final C0764 f3264;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public final C0760 f3265;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final C0760 f3266;

    /* JADX INFO: renamed from: ᵸˆˁ, reason: contains not printable characters */
    public int f3267;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public final AtomicBoolean f3258 = new AtomicBoolean();

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final AtomicBoolean f3262 = new AtomicBoolean(true);

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public final C0133 f3261 = new C0133();

    public C0716() {
        C0764 c0764 = new C0764();
        c0764.f3428 = new float[16];
        c0764.f3427 = new float[16];
        c0764.f3429 = new C0760();
        this.f3264 = c0764;
        this.f3265 = new C0760();
        this.f3266 = new C0760();
        this.f3256 = new float[16];
        this.f3259 = new float[16];
        this.f3255 = 0;
        this.f3263 = -1;
    }

    @Override // defpackage.InterfaceC4690
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final void mo2564() {
        this.f3265.m2723();
        C0764 c0764 = this.f3264;
        ((C0760) c0764.f3429).m2723();
        c0764.f3426 = false;
        this.f3262.set(true);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m2565(float[] fArr) {
        Object objM2714;
        GLES20.glClear(16384);
        try {
            ᵺᵘ.ˊᵫᵗ();
        } catch (GlUtil$GlException e) {
            ˋˀᵧ.ˋˈ("Failed to draw a frame", e);
        }
        if (this.f3258.compareAndSet(true, false)) {
            SurfaceTexture surfaceTexture = this.f3260;
            surfaceTexture.getClass();
            surfaceTexture.updateTexImage();
            try {
                ᵺᵘ.ˊᵫᵗ();
            } catch (GlUtil$GlException e2) {
                ˋˀᵧ.ˋˈ("Failed to draw a frame", e2);
            }
            if (this.f3262.compareAndSet(true, false)) {
                Matrix.setIdentityM(this.f3256, 0);
            }
            long timestamp = this.f3260.getTimestamp();
            C0760 c0760 = this.f3265;
            synchronized (c0760) {
                objM2714 = c0760.m2714(false, timestamp);
            }
            Long l = (Long) objM2714;
            if (l != null) {
                C0764 c0764 = this.f3264;
                float[] fArr2 = this.f3256;
                float[] fArr3 = (float[]) ((C0760) c0764.f3429).m2728(l.longValue());
                if (fArr3 != null) {
                    float[] fArr4 = (float[]) c0764.f3427;
                    float f = fArr3[0];
                    float f2 = -fArr3[1];
                    float f3 = -fArr3[2];
                    float length = Matrix.length(f, f2, f3);
                    if (length != 0.0f) {
                        Matrix.setRotateM(fArr4, 0, (float) Math.toDegrees(length), f / length, f2 / length, f3 / length);
                    } else {
                        Matrix.setIdentityM(fArr4, 0);
                    }
                    if (!c0764.f3426) {
                        C0764.m2738((float[]) c0764.f3428, (float[]) c0764.f3427);
                        c0764.f3426 = true;
                    }
                    Matrix.multiplyMM(fArr2, 0, (float[]) c0764.f3428, 0, (float[]) c0764.f3427, 0);
                }
            }
            C2109 c2109 = (C2109) this.f3266.m2728(timestamp);
            if (c2109 != null) {
                C0133 c0133 = this.f3261;
                c0133.getClass();
                if (C0133.m1242(c2109)) {
                    c0133.f1467 = c2109.f8397;
                    c0133.f1468 = new C0760(c2109.f8398.f9730[0]);
                    if (!c2109.f8399) {
                        new C0760(c2109.f8396.f9730[0]);
                    }
                }
            }
        }
        Matrix.multiplyMM(this.f3259, 0, fArr, 0, this.f3256, 0);
        C0133 c01332 = this.f3261;
        int i = this.f3267;
        float[] fArr5 = this.f3259;
        C0760 c07602 = (C0760) c01332.f1468;
        if (c07602 == null) {
            return;
        }
        int i2 = c01332.f1467;
        GLES20.glUniformMatrix3fv(c01332.f1465, 1, false, i2 == 1 ? C0133.f1460 : i2 == 2 ? C0133.f1461 : C0133.f1462, 0);
        GLES20.glUniformMatrix4fv(c01332.f1463, 1, false, fArr5, 0);
        GLES20.glActiveTexture(33984);
        GLES20.glBindTexture(36197, i);
        GLES20.glUniform1i(c01332.f1470, 0);
        try {
            ᵺᵘ.ˊᵫᵗ();
        } catch (GlUtil$GlException e3) {
            ˋˀᵧ.ˋˈ("Failed to bind uniforms", e3);
        }
        GLES20.glVertexAttribPointer(c01332.f1469, 3, 5126, false, 12, (Buffer) c07602.f3418);
        try {
            ᵺᵘ.ˊᵫᵗ();
        } catch (GlUtil$GlException e4) {
            ˋˀᵧ.ˋˈ("Failed to load position data", e4);
        }
        GLES20.glVertexAttribPointer(c01332.f1466, 2, 5126, false, 8, (Buffer) c07602.f3420);
        try {
            ᵺᵘ.ˊᵫᵗ();
        } catch (GlUtil$GlException e5) {
            ˋˀᵧ.ˋˈ("Failed to load texture data", e5);
        }
        GLES20.glDrawArrays(c07602.f3419, 0, c07602.f3417);
        try {
            ᵺᵘ.ˊᵫᵗ();
        } catch (GlUtil$GlException e6) {
            ˋˀᵧ.ˋˈ("Failed to render", e6);
        }
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final SurfaceTexture m2566() {
        try {
            GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            ᵺᵘ.ˊᵫᵗ();
            this.f3261.m1243();
            ᵺᵘ.ˊᵫᵗ();
            int[] iArr = new int[1];
            GLES20.glGenTextures(1, iArr, 0);
            ᵺᵘ.ˊᵫᵗ();
            int i = iArr[0];
            ᵺᵘ.ʽˈˋ(36197, i);
            this.f3267 = i;
        } catch (GlUtil$GlException e) {
            ˋˀᵧ.ˋˈ("Failed to initialize the renderer", e);
        }
        SurfaceTexture surfaceTexture = new SurfaceTexture(this.f3267);
        this.f3260 = surfaceTexture;
        surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { // from class: ᵧʡᵖˊ
            @Override // android.graphics.SurfaceTexture.OnFrameAvailableListener
            public final void onFrameAvailable(SurfaceTexture surfaceTexture2) {
                this.f13753.f3258.set(true);
            }
        });
        return this.f3260;
    }

    @Override // defpackage.InterfaceC4690
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final void mo2567(long j, float[] fArr) {
        ((C0760) this.f3264.f3429).m2710(j, fArr);
    }

    @Override // defpackage.InterfaceC0819
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void mo2568(long j, long j2, C5286 c5286, MediaFormat mediaFormat) {
        int i;
        ArrayList arrayList;
        int iM9614;
        this.f3265.m2710(j2, Long.valueOf(j));
        byte[] bArr = c5286.f19974;
        int i2 = c5286.f19998;
        byte[] bArr2 = this.f3257;
        int i3 = this.f3263;
        this.f3257 = bArr;
        if (i2 == -1) {
            i2 = this.f3255;
        }
        this.f3263 = i2;
        if (i3 == i2 && Arrays.equals(bArr2, this.f3257)) {
            return;
        }
        byte[] bArr3 = this.f3257;
        C2109 c2109 = null;
        if (bArr3 != null) {
            int i4 = this.f3263;
            C4545 c4545 = new C4545(bArr3);
            try {
                c4545.m9609(4);
                iM9614 = c4545.m9614();
                c4545.m9624(0);
            } catch (ArrayIndexOutOfBoundsException unused) {
            }
            if (iM9614 == 1886547818) {
                c4545.m9609(8);
                int i5 = c4545.f17282;
                int i6 = c4545.f17283;
                while (i5 < i6) {
                    int iM96142 = c4545.m9614() + i5;
                    if (iM96142 > i5 && iM96142 <= i6) {
                        int iM96143 = c4545.m9614();
                        if (iM96143 != 2037673328 && iM96143 != 1836279920) {
                            c4545.m9624(iM96142);
                            i5 = iM96142;
                        }
                        c4545.m9612(iM96142);
                        arrayList = ˀᵳˎᵹ.ᵜᵪʾ(c4545);
                        break;
                    }
                    break;
                }
                arrayList = null;
            } else {
                arrayList = ˀᵳˎᵹ.ᵜᵪʾ(c4545);
            }
            if (arrayList != null) {
                int size = arrayList.size();
                if (size == 1) {
                    C2519 c2519 = (C2519) arrayList.get(0);
                    c2109 = new C2109(c2519, c2519, i4);
                } else if (size == 2) {
                    c2109 = new C2109((C2519) arrayList.get(0), (C2519) arrayList.get(1), i4);
                }
            }
        }
        if (c2109 == null || !C0133.m1242(c2109)) {
            int i7 = this.f3263;
            float radians = (float) Math.toRadians(180.0d);
            float radians2 = (float) Math.toRadians(360.0d);
            float f = radians / 36.0f;
            float f2 = radians2 / 72.0f;
            float[] fArr = new float[15984];
            float[] fArr2 = new float[10656];
            int i8 = 0;
            int i9 = 0;
            for (int i10 = 0; i10 < 36; i10 = i) {
                float f3 = radians / 2.0f;
                float f4 = (i10 * f) - f3;
                i = i10 + 1;
                float f5 = (i * f) - f3;
                int i11 = 0;
                while (i11 < 73) {
                    int i12 = i;
                    int i13 = 0;
                    int i14 = 2;
                    while (i13 < i14) {
                        float f6 = radians;
                        float f7 = i11 * f2;
                        float f8 = radians2;
                        double d = (f7 + 3.1415927f) - (radians2 / 2.0f);
                        double d2 = i13 == 0 ? f4 : f5;
                        fArr[i8] = -((float) (Math.cos(d2) * Math.sin(d) * 50.0d));
                        fArr[i8 + 1] = (float) (Math.sin(d2) * 50.0d);
                        int i15 = i8 + 3;
                        float f9 = f;
                        fArr[i8 + 2] = (float) (Math.cos(d2) * Math.cos(d) * 50.0d);
                        fArr2[i9] = f7 / f8;
                        int i16 = i9 + 2;
                        fArr2[i9 + 1] = ((i10 + i13) * f9) / f6;
                        if ((i11 == 0 && i13 == 0) || (i11 == 72 && i13 == 1)) {
                            System.arraycopy(fArr, i8, fArr, i15, 3);
                            i8 += 6;
                            i14 = 2;
                            System.arraycopy(fArr2, i9, fArr2, i16, 2);
                            i9 += 4;
                        } else {
                            i14 = 2;
                            i8 = i15;
                            i9 = i16;
                        }
                        i13++;
                        radians = f6;
                        f = f9;
                        radians2 = f8;
                    }
                    i11++;
                    i = i12;
                }
            }
            C2519 c25192 = new C2519(new C0760(0, fArr, fArr2, 1));
            c2109 = new C2109(c25192, c25192, i7);
        }
        this.f3266.m2710(j2, c2109);
    }
}
