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;

/* renamed from: ˊᵤᵣ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1367 implements InterfaceC4325, InterfaceC2517 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public final float[] f5626;

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

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

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final float[] f5629;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final C3959 f5630;

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

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

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public volatile int f5635;

    /* renamed from: ᵺʙ, reason: contains not printable characters */
    public byte[] f5636;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final C4699 f5637;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final AtomicBoolean f5634 = new AtomicBoolean();

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final AtomicBoolean f5631 = new AtomicBoolean(true);

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final C1347 f5638 = new C1347();

    public C1367() {
        C4699 c4699 = new C4699();
        c4699.f17372 = new float[16];
        c4699.f17375 = new float[16];
        c4699.f17374 = new C3959();
        this.f5637 = c4699;
        this.f5632 = new C3959();
        this.f5630 = new C3959();
        this.f5626 = new float[16];
        this.f5629 = new float[16];
        this.f5635 = 0;
        this.f5633 = -1;
    }

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final SurfaceTexture m4220() {
        try {
            GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            ˉˇʨ.ˏˋٴ();
            this.f5638.m4170();
            ˉˇʨ.ˏˋٴ();
            int[] iArr = new int[1];
            GLES20.glGenTextures(1, iArr, 0);
            ˉˇʨ.ˏˋٴ();
            int i = iArr[0];
            ˉˇʨ.ᵴᵳ(36197, i);
            this.f5628 = i;
        } catch (GlUtil$GlException e) {
            ᵳʿˉ.ᵸˑ("Failed to initialize the renderer", e);
        }
        SurfaceTexture surfaceTexture = new SurfaceTexture(this.f5628);
        this.f5627 = surfaceTexture;
        surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { // from class: ˀᵚᵪᵷ
            @Override // android.graphics.SurfaceTexture.OnFrameAvailableListener
            public final void onFrameAvailable(SurfaceTexture surfaceTexture2) {
                this.f2937.f5634.set(true);
            }
        });
        return this.f5627;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m4221(float[] fArr) {
        Object objM8758;
        GLES20.glClear(16384);
        try {
            ˉˇʨ.ˏˋٴ();
        } catch (GlUtil$GlException e) {
            ᵳʿˉ.ᵸˑ("Failed to draw a frame", e);
        }
        if (this.f5634.compareAndSet(true, false)) {
            SurfaceTexture surfaceTexture = this.f5627;
            surfaceTexture.getClass();
            surfaceTexture.updateTexImage();
            try {
                ˉˇʨ.ˏˋٴ();
            } catch (GlUtil$GlException e2) {
                ᵳʿˉ.ᵸˑ("Failed to draw a frame", e2);
            }
            if (this.f5631.compareAndSet(true, false)) {
                Matrix.setIdentityM(this.f5626, 0);
            }
            long timestamp = this.f5627.getTimestamp();
            C3959 c3959 = this.f5632;
            synchronized (c3959) {
                objM8758 = c3959.m8758(false, timestamp);
            }
            Long l = (Long) objM8758;
            if (l != null) {
                C4699 c4699 = this.f5637;
                float[] fArr2 = this.f5626;
                float[] fArr3 = (float[]) ((C3959) c4699.f17374).m8756(l.longValue());
                if (fArr3 != null) {
                    float[] fArr4 = (float[]) c4699.f17375;
                    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 (!c4699.f17373) {
                        C4699.m9877((float[]) c4699.f17372, (float[]) c4699.f17375);
                        c4699.f17373 = true;
                    }
                    Matrix.multiplyMM(fArr2, 0, (float[]) c4699.f17372, 0, (float[]) c4699.f17375, 0);
                }
            }
            C1807 c1807 = (C1807) this.f5630.m8756(timestamp);
            if (c1807 != null) {
                C1347 c1347 = this.f5638;
                c1347.getClass();
                if (C1347.m4168(c1807)) {
                    c1347.f5563 = c1807.f7276;
                    c1347.f5560 = new C3959(c1807.f7277.f12305[0]);
                    if (!c1807.f7279) {
                        new C3959(c1807.f7278.f12305[0]);
                    }
                }
            }
        }
        Matrix.multiplyMM(this.f5629, 0, fArr, 0, this.f5626, 0);
        C1347 c13472 = this.f5638;
        int i = this.f5628;
        float[] fArr5 = this.f5629;
        C3959 c39592 = (C3959) c13472.f5560;
        if (c39592 == null) {
            return;
        }
        int i2 = c13472.f5563;
        GLES20.glUniformMatrix3fv(c13472.f5562, 1, false, i2 == 1 ? C1347.f5557 : i2 == 2 ? C1347.f5558 : C1347.f5556, 0);
        GLES20.glUniformMatrix4fv(c13472.f5564, 1, false, fArr5, 0);
        GLES20.glActiveTexture(33984);
        GLES20.glBindTexture(36197, i);
        GLES20.glUniform1i(c13472.f5561, 0);
        try {
            ˉˇʨ.ˏˋٴ();
        } catch (GlUtil$GlException e3) {
            ᵳʿˉ.ᵸˑ("Failed to bind uniforms", e3);
        }
        GLES20.glVertexAttribPointer(c13472.f5566, 3, 5126, false, 12, (Buffer) c39592.f14938);
        try {
            ˉˇʨ.ˏˋٴ();
        } catch (GlUtil$GlException e4) {
            ᵳʿˉ.ᵸˑ("Failed to load position data", e4);
        }
        GLES20.glVertexAttribPointer(c13472.f5559, 2, 5126, false, 8, (Buffer) c39592.f14937);
        try {
            ˉˇʨ.ˏˋٴ();
        } catch (GlUtil$GlException e5) {
            ᵳʿˉ.ᵸˑ("Failed to load texture data", e5);
        }
        GLES20.glDrawArrays(c39592.f14935, 0, c39592.f14936);
        try {
            ˉˇʨ.ˏˋٴ();
        } catch (GlUtil$GlException e6) {
            ᵳʿˉ.ᵸˑ("Failed to render", e6);
        }
    }

    @Override // defpackage.InterfaceC2517
    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void mo4222(long j, float[] fArr) {
        ((C3959) this.f5637.f17374).m8754(j, fArr);
    }

    @Override // defpackage.InterfaceC2517
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void mo4223() {
        this.f5632.m8759();
        C4699 c4699 = this.f5637;
        ((C3959) c4699.f17374).m8759();
        c4699.f17373 = false;
        this.f5631.set(true);
    }

    @Override // defpackage.InterfaceC4325
    /* renamed from: ᵻᵢﹳᵰ */
    public final void mo3132(long j, long j2, C3446 c3446, MediaFormat mediaFormat) {
        int i;
        ArrayList arrayList;
        int iM7965;
        this.f5632.m8754(j2, Long.valueOf(j));
        byte[] bArr = c3446.f12917;
        int i2 = c3446.f12910;
        byte[] bArr2 = this.f5636;
        int i3 = this.f5633;
        this.f5636 = bArr;
        if (i2 == -1) {
            i2 = this.f5635;
        }
        this.f5633 = i2;
        if (i3 == i2 && Arrays.equals(bArr2, this.f5636)) {
            return;
        }
        byte[] bArr3 = this.f5636;
        C1807 c1807 = null;
        if (bArr3 != null) {
            int i4 = this.f5633;
            C3493 c3493 = new C3493(bArr3);
            try {
                c3493.m7946(4);
                iM7965 = c3493.m7965();
                c3493.m7955(0);
            } catch (ArrayIndexOutOfBoundsException unused) {
            }
            if (iM7965 == 1886547818) {
                c3493.m7946(8);
                int i5 = c3493.f13083;
                int i6 = c3493.f13081;
                while (i5 < i6) {
                    int iM79652 = c3493.m7965() + i5;
                    if (iM79652 > i5 && iM79652 <= i6) {
                        int iM79653 = c3493.m7965();
                        if (iM79653 != 2037673328 && iM79653 != 1836279920) {
                            c3493.m7955(iM79652);
                            i5 = iM79652;
                        }
                        c3493.m7950(iM79652);
                        arrayList = ˆᴵ.ˑᵱ(c3493);
                        break;
                    }
                    break;
                }
                arrayList = null;
            } else {
                arrayList = ˆᴵ.ˑᵱ(c3493);
            }
            if (arrayList != null) {
                int size = arrayList.size();
                if (size == 1) {
                    C3275 c3275 = (C3275) arrayList.get(0);
                    c1807 = new C1807(c3275, c3275, i4);
                } else if (size == 2) {
                    c1807 = new C1807((C3275) arrayList.get(0), (C3275) arrayList.get(1), i4);
                }
            }
        }
        if (c1807 == null || !C1347.m4168(c1807)) {
            int i7 = this.f5633;
            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;
                }
            }
            C3275 c32752 = new C3275(new C3959(0, fArr, fArr2, 1));
            c1807 = new C1807(c32752, c32752, i7);
        }
        this.f5630.m8754(j2, c1807);
    }
}
