package defpackage;

import android.graphics.Bitmap;
import android.os.Trace;
import androidx.media3.exoplayer.ExoPlaybackException;
import androidx.media3.exoplayer.image.ImageDecoderException;
import androidx.media3.exoplayer.image.ImageOutput;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;

/* JADX INFO: renamed from: ᵔˊᵴ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2242 extends AbstractC0799 {

    /* JADX INFO: renamed from: ʽᵡᵢᵾ, reason: contains not printable characters */
    public final ArrayDeque f8877;

    /* JADX INFO: renamed from: ʿᵿʽᵞ, reason: contains not printable characters */
    public C1183 f8878;

    /* JADX INFO: renamed from: ˀᵗ, reason: contains not printable characters */
    public int f8879;

    /* JADX INFO: renamed from: ˁʢᵛ, reason: contains not printable characters */
    public long f8880;

    /* JADX INFO: renamed from: ˁᵺˈ, reason: contains not printable characters */
    public boolean f8881;

    /* JADX INFO: renamed from: ˈⁱᵡ, reason: contains not printable characters */
    public boolean f8882;

    /* JADX INFO: renamed from: ˉˆᵗ, reason: contains not printable characters */
    public Bitmap f8883;

    /* JADX INFO: renamed from: ˊˌˊ, reason: contains not printable characters */
    public long f8884;

    /* JADX INFO: renamed from: ˋʿᐧ, reason: contains not printable characters */
    public C0961 f8885;

    /* JADX INFO: renamed from: ˋᵯᵩ, reason: contains not printable characters */
    public C5019 f8886;

    /* JADX INFO: renamed from: ˏᵩʨ, reason: contains not printable characters */
    public int f8887;

    /* JADX INFO: renamed from: ːᵝٴᵶ, reason: contains not printable characters */
    public int f8888;

    /* JADX INFO: renamed from: ˑʢ, reason: contains not printable characters */
    public final C3008 f8889;

    /* JADX INFO: renamed from: ᵗᵭ, reason: contains not printable characters */
    public boolean f8890;

    /* JADX INFO: renamed from: ᵛˀˊ, reason: contains not printable characters */
    public C5286 f8891;

    /* JADX INFO: renamed from: ᵜᵤ, reason: contains not printable characters */
    public C5019 f8892;

    /* JADX INFO: renamed from: ᵞᵛᵘ, reason: contains not printable characters */
    public C0060 f8893;

    /* JADX INFO: renamed from: ᵡᵶ, reason: contains not printable characters */
    public C3008 f8894;

    /* JADX INFO: renamed from: ᵡᵶᵬʤ, reason: contains not printable characters */
    public ImageOutput f8895;

    /* JADX INFO: renamed from: ᵨˈʼﹶ, reason: contains not printable characters */
    public boolean f8896;

    /* JADX INFO: renamed from: ᵵᵬᵽ, reason: contains not printable characters */
    public final C2926 f8897;

    public C2242(C2926 c2926) {
        super(4);
        this.f8897 = c2926;
        this.f8895 = ImageOutput.f646;
        this.f8889 = new C3008(0, 0);
        this.f8893 = C0060.f1239;
        this.f8877 = new ArrayDeque();
        this.f8880 = -9223372036854775807L;
        this.f8884 = -9223372036854775807L;
        this.f8879 = 0;
        this.f8887 = 1;
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x002f  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x007e  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x010d  */
    /* JADX INFO: renamed from: ʿٴˇ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m5843(long j) {
        boolean z;
        C5286 c5286;
        int i;
        if (!this.f8881 || this.f8886 == null) {
            ˊˊᵞᵽ r0 = this.f3590;
            r0.ᵻˈᵦʼ();
            C1183 c1183 = this.f8878;
            if (c1183 != null && this.f8879 != 3 && !this.f8882) {
                if (this.f8894 == null) {
                    C3008 c3008 = (C3008) c1183.mo2936();
                    this.f8894 = c3008;
                    if (c3008 != null) {
                        int i2 = this.f8879;
                        C3008 c30082 = this.f8894;
                        if (i2 == 2) {
                            c30082.getClass();
                            this.f8894.f9866 = 4;
                            C1183 c11832 = this.f8878;
                            c11832.getClass();
                            c11832.mo2938(this.f8894);
                            this.f8894 = null;
                            this.f8879 = 3;
                            return false;
                        }
                        int iM2893 = m2893(r0, c30082, 0);
                        if (iM2893 == -5) {
                            C5286 c52862 = (C5286) r0.ᵔᵖᵹᵫ;
                            c52862.getClass();
                            this.f8891 = c52862;
                            this.f8890 = true;
                            this.f8879 = 2;
                            return true;
                        }
                        if (iM2893 == -4) {
                            this.f8894.m7092();
                            ByteBuffer byteBuffer = this.f8894.f11582;
                            if (byteBuffer == null || byteBuffer.remaining() <= 0) {
                                C3008 c30083 = this.f8894;
                                c30083.getClass();
                                z = c30083.m6278(4);
                            }
                            if (z) {
                                C3008 c30084 = this.f8894;
                                c30084.getClass();
                                c30084.f11580 = this.f8891;
                                C1183 c11833 = this.f8878;
                                c11833.getClass();
                                C3008 c30085 = this.f8894;
                                c30085.getClass();
                                c11833.mo2938(c30085);
                                this.f8888 = 0;
                            }
                            C3008 c30086 = this.f8894;
                            c30086.getClass();
                            if (c30086.m6278(4)) {
                                this.f8881 = true;
                            } else {
                                int i3 = this.f8888;
                                long j2 = c30086.f11577;
                                C5019 c5019 = new C5019();
                                c5019.f19020 = i3;
                                c5019.f19018 = j2;
                                this.f8892 = c5019;
                                this.f8888 = i3 + 1;
                                if (this.f8881) {
                                    this.f8886 = this.f8892;
                                    this.f8892 = null;
                                } else {
                                    boolean z2 = j2 - 30000 <= j && j <= 30000 + j2;
                                    C5019 c50192 = this.f8886;
                                    boolean z3 = c50192 != null && c50192.f19018 <= j && j < j2;
                                    C5286 c52863 = this.f8891;
                                    c52863.getClass();
                                    this.f8881 = z2 || z3 || (c52863.f19993 == -1 || (i = (c5286 = this.f8891).f19977) == -1 || i3 == (i * c5286.f19993) - 1);
                                    if (!z3 || z2) {
                                    }
                                }
                            }
                            C3008 c30087 = this.f8894;
                            c30087.getClass();
                            if (c30087.m6278(4)) {
                                this.f8882 = true;
                                this.f8894 = null;
                                return false;
                            }
                            long j3 = this.f8880;
                            C3008 c30088 = this.f8894;
                            c30088.getClass();
                            this.f8880 = Math.max(j3, c30088.f11577);
                            if (z) {
                                this.f8894 = null;
                            } else {
                                C3008 c30089 = this.f8894;
                                c30089.getClass();
                                c30089.mo7091();
                            }
                            return !this.f8881;
                        }
                        if (iM2893 != -3) {
                            ᵷᵝˎ.ᵱʡˏ();
                            return false;
                        }
                    }
                }
            }
        }
        return false;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˈᵲᵢ */
    public final int mo376(C5286 c5286) {
        this.f8897.getClass();
        return C2926.m6987(c5286);
    }

    /* JADX INFO: renamed from: ˉᵵᵜ, reason: contains not printable characters */
    public final void m5844() {
        this.f8894 = null;
        this.f8879 = 0;
        this.f8880 = -9223372036854775807L;
        C1183 c1183 = this.f8878;
        if (c1183 != null) {
            c1183.mo364();
            this.f8878 = null;
        }
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˊᵙᵾᵲ */
    public final void mo2891() {
        m5844();
        this.f8887 = Math.min(this.f8887, 1);
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0023, code lost:
    
        if (r2 >= r6) goto L15;
     */
    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˊᵨᵧ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void mo380(C5286[] c5286Arr, long j, long j2, C4100 c4100) {
        if (this.f8893.f1240 != -9223372036854775807L) {
            ArrayDeque arrayDeque = this.f8877;
            if (arrayDeque.isEmpty()) {
                long j3 = this.f8880;
                if (j3 != -9223372036854775807L) {
                    long j4 = this.f8884;
                    if (j4 != -9223372036854775807L) {
                    }
                }
            }
            arrayDeque.add(new C0060(this.f8880, j2));
            return;
        }
        this.f8893 = new C0060(-9223372036854775807L, j2);
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ˋˈ */
    public final void mo383() {
        this.f8891 = null;
        this.f8893 = C0060.f1239;
        this.f8877.clear();
        m5844();
        this.f8895.mo409();
    }

    @Override // defpackage.AbstractC0799, defpackage.InterfaceC1896
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public final void mo386(int i, Object obj) {
        if (i != 15) {
            if (i != 23) {
                return;
            }
            this.f8885 = (C0961) obj;
        } else {
            ImageOutput imageOutput = obj instanceof ImageOutput ? (ImageOutput) obj : null;
            if (imageOutput == null) {
                imageOutput = ImageOutput.f646;
            }
            this.f8895 = imageOutput;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:45:0x008a  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00d9  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00db  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00e0  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00ed  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00f7  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x0144  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x015d  */
    /* JADX INFO: renamed from: ˑˊᵲ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m5845(long j) throws ExoPlaybackException {
        boolean z;
        C5019 c5019;
        boolean z2;
        int i;
        C0961 c0961;
        Bitmap bitmapCreateBitmap;
        Bitmap bitmap = this.f8883;
        if ((bitmap == null || this.f8886 != null) && (this.f8887 != 0 || this.f3588 == 2)) {
            ArrayDeque arrayDeque = this.f8877;
            if (bitmap == null) {
                this.f8878.getClass();
                C1420 c1420 = (C1420) this.f8878.mo2937();
                if (c1420 != null) {
                    if (!c1420.m6278(4)) {
                        ᵻᵪ.ᵱʡˏ(c1420.f5840, "Non-EOS buffer came back from the decoder without bitmap.");
                        this.f8883 = c1420.f5840;
                        c1420.mo359();
                        if (this.f8881 && this.f8883 != null && this.f8886 != null) {
                            this.f8891.getClass();
                            C5286 c5286 = this.f8891;
                            int i2 = c5286.f19993;
                            int i3 = c5286.f19977;
                            z = ((i2 == 1 && i3 == 1) || i2 == -1 || i3 == -1) ? false : true;
                            c5019 = this.f8886;
                            if (((Bitmap) c5019.f19019) == null) {
                                if (z) {
                                    int i4 = c5019.f19020;
                                    this.f8883.getClass();
                                    int width = this.f8883.getWidth();
                                    C5286 c52862 = this.f8891;
                                    c52862.getClass();
                                    int i5 = width / c52862.f19993;
                                    int height = this.f8883.getHeight();
                                    C5286 c52863 = this.f8891;
                                    c52863.getClass();
                                    int i6 = height / c52863.f19977;
                                    int i7 = this.f8891.f19993;
                                    bitmapCreateBitmap = Bitmap.createBitmap(this.f8883, (i4 % i7) * i5, (i4 / i7) * i6, i5, i6);
                                } else {
                                    bitmapCreateBitmap = this.f8883;
                                    bitmapCreateBitmap.getClass();
                                }
                                c5019.f19019 = bitmapCreateBitmap;
                            }
                            Bitmap bitmap2 = (Bitmap) this.f8886.f19019;
                            bitmap2.getClass();
                            long j2 = this.f8886.f19018;
                            long j3 = j2 - j;
                            z2 = this.f3588 == 2;
                            i = this.f8887;
                            if (i != 0) {
                                if (i == 1) {
                                    z2 = true;
                                } else {
                                    if (i != 3) {
                                        ᵷᵝˎ.ᵱʡˏ();
                                        return false;
                                    }
                                    z2 = false;
                                }
                            }
                            if (!z2 || j3 < 30000) {
                                c0961 = this.f8885;
                                if (c0961 != null) {
                                    long j4 = this.f8893.f1240;
                                    this.f8891.getClass();
                                    C1760 c1760 = c0961.f4237;
                                    if (c1760.f7052) {
                                        c1760.f7032.m7174(37).m3635();
                                    }
                                }
                                this.f8895.onImageAvailable(j2 - this.f8893.f1240, bitmap2);
                                C5019 c50192 = this.f8886;
                                c50192.getClass();
                                long j5 = c50192.f19018;
                                this.f8884 = j5;
                                while (!arrayDeque.isEmpty() && j5 >= ((C0060) arrayDeque.peek()).f1241) {
                                    this.f8893 = (C0060) arrayDeque.removeFirst();
                                }
                                this.f8887 = 3;
                                if (z) {
                                    C5019 c50193 = this.f8886;
                                    c50193.getClass();
                                    int i8 = c50193.f19020;
                                    C5286 c52864 = this.f8891;
                                    c52864.getClass();
                                    int i9 = c52864.f19977;
                                    C5286 c52865 = this.f8891;
                                    c52865.getClass();
                                    if (i8 == (i9 * c52865.f19993) - 1) {
                                        this.f8883 = null;
                                    }
                                }
                                this.f8886 = this.f8892;
                                this.f8892 = null;
                                return true;
                            }
                        }
                    } else {
                        if (this.f8879 == 3) {
                            m5844();
                            this.f8891.getClass();
                            m5846();
                            return false;
                        }
                        c1420.mo359();
                        if (arrayDeque.isEmpty()) {
                            this.f8896 = true;
                            return false;
                        }
                    }
                }
            } else if (this.f8881) {
                this.f8891.getClass();
                C5286 c52866 = this.f8891;
                int i22 = c52866.f19993;
                int i32 = c52866.f19977;
                if (i22 == 1) {
                    c5019 = this.f8886;
                    if (((Bitmap) c5019.f19019) == null) {
                    }
                    Bitmap bitmap22 = (Bitmap) this.f8886.f19019;
                    bitmap22.getClass();
                    long j22 = this.f8886.f19018;
                    long j32 = j22 - j;
                    if (this.f3588 == 2) {
                    }
                    i = this.f8887;
                    if (i != 0) {
                    }
                    if (!z2) {
                    }
                    c0961 = this.f8885;
                    if (c0961 != null) {
                    }
                    this.f8895.onImageAvailable(j22 - this.f8893.f1240, bitmap22);
                    C5019 c501922 = this.f8886;
                    c501922.getClass();
                    long j52 = c501922.f19018;
                    this.f8884 = j52;
                    while (!arrayDeque.isEmpty()) {
                    }
                    this.f8887 = 3;
                    if (z) {
                    }
                    this.f8886 = this.f8892;
                    this.f8892 = null;
                    return true;
                }
                c5019 = this.f8886;
                if (((Bitmap) c5019.f19019) == null) {
                }
                Bitmap bitmap222 = (Bitmap) this.f8886.f19019;
                bitmap222.getClass();
                long j222 = this.f8886.f19018;
                long j322 = j222 - j;
                if (this.f3588 == 2) {
                }
                i = this.f8887;
                if (i != 0) {
                }
                if (!z2) {
                }
                c0961 = this.f8885;
                if (c0961 != null) {
                }
                this.f8895.onImageAvailable(j222 - this.f8893.f1240, bitmap222);
                C5019 c5019222 = this.f8886;
                c5019222.getClass();
                long j522 = c5019222.f19018;
                this.f8884 = j522;
                while (!arrayDeque.isEmpty()) {
                    this.f8893 = (C0060) arrayDeque.removeFirst();
                }
                this.f8887 = 3;
                if (z) {
                }
                this.f8886 = this.f8892;
                this.f8892 = null;
                return true;
            }
        }
        return false;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵔᵖᵹᵫ */
    public final void mo388(long j, long j2) throws ExoPlaybackException {
        if (this.f8896) {
            return;
        }
        if (this.f8891 == null) {
            ˊˊᵞᵽ r6 = this.f3590;
            r6.ᵻˈᵦʼ();
            C3008 c3008 = this.f8889;
            c3008.mo7091();
            int iM2893 = m2893(r6, c3008, 2);
            if (iM2893 != -5) {
                if (iM2893 == -4) {
                    ᵻᵪ.ˌᴵ(c3008.m6278(4));
                    this.f8882 = true;
                    this.f8896 = true;
                    return;
                }
                return;
            }
            C5286 c5286 = (C5286) r6.ᵔᵖᵹᵫ;
            c5286.getClass();
            this.f8891 = c5286;
            this.f8890 = true;
        }
        if (this.f8878 == null) {
            m5846();
        }
        try {
            Trace.beginSection("drainAndFeedDecoder");
            while (m5845(j)) {
            }
            while (m5843(j)) {
            }
            Trace.endSection();
        } catch (ImageDecoderException e) {
            throw m2900(e, null, false, 4003);
        }
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵝᵶ */
    public final boolean mo389() {
        int i = this.f8887;
        if (i != 3) {
            return i == 0 && this.f8881;
        }
        return true;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵟᵹᵙ */
    public final void mo390(long j, boolean z, boolean z2) {
        this.f8887 = Math.min(this.f8887, 1);
        this.f8896 = false;
        this.f8882 = false;
        this.f8883 = null;
        this.f8886 = null;
        this.f8892 = null;
        this.f8881 = false;
        this.f8894 = null;
        C1183 c1183 = this.f8878;
        if (c1183 != null) {
            c1183.flush();
        }
        this.f8877.clear();
    }

    /* JADX INFO: renamed from: ᵠˏˏ, reason: contains not printable characters */
    public final void m5846() throws ExoPlaybackException {
        if (this.f8890) {
            C5286 c5286 = this.f8891;
            c5286.getClass();
            C2926 c2926 = this.f8897;
            c2926.getClass();
            int iM6987 = C2926.m6987(c5286);
            if (iM6987 != AbstractC2704.m6526(4, 0, 0, 0) && iM6987 != AbstractC2704.m6526(3, 0, 0, 0)) {
                throw m2900(new ImageDecoderException("Provided decoder factory can't create decoder for format."), this.f8891, false, 4005);
            }
            C1183 c1183 = this.f8878;
            if (c1183 != null) {
                c1183.mo364();
            }
            this.f8878 = new C1183(c2926.f11267);
            this.f8890 = false;
        }
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵪᵹᵥᵻ */
    public final void mo392(boolean z, boolean z2) {
        this.f8887 = z2 ? 1 : 0;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵮᵣᵗˈ */
    public final boolean mo393() {
        return this.f8896;
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵱʡˏ */
    public final void mo2897() {
        m5844();
    }

    @Override // defpackage.AbstractC0799
    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public final String mo394() {
        return "ImageRenderer";
    }
}
