package defpackage;

import androidx.media3.common.ParserException;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/* JADX INFO: renamed from: ˏᵡʾ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1881 implements InterfaceC4291 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C5151 f7443;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public long f7444;

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public long f7445;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final boolean f7446;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public long f7447;

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public boolean f7448;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public int f7449;

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public int f7450;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public int f7451;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public long f7452;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C4545 f7453;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public C2494 f7454;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public C0986 f7455;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final ᵱᵻᵧᵷ f7456;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public C0986[] f7457;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public InterfaceC4550 f7458;

    public C1881(int i, ᵱᵻᵧᵷ r3) {
        this.f7456 = r3;
        this.f7446 = (i & 1) == 0;
        this.f7453 = new C4545(12);
        this.f7443 = new C5151();
        this.f7458 = new ᵖˊʨ(2);
        this.f7457 = new C0986[0];
        this.f7447 = -1L;
        this.f7445 = -1L;
        this.f7451 = -1;
        this.f7444 = -9223372036854775807L;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo1252(long j, long j2) {
        this.f7452 = -1L;
        this.f7455 = null;
        for (C0986 c0986 : this.f7457) {
            if (c0986.f4331 == 0) {
                c0986.f4333 = 0;
            } else {
                c0986.f4333 = c0986.f4323[AbstractC0956.m3271(c0986.f4325, j, true)];
            }
        }
        if (j != 0) {
            this.f7449 = 6;
        } else if (this.f7457.length == 0) {
            this.f7449 = 0;
        } else {
            this.f7449 = 3;
        }
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public final InterfaceC4291 mo1254() {
        return this;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵨᵣ */
    public final boolean mo1255(InterfaceC5206 interfaceC5206) {
        C4545 c4545 = this.f7453;
        interfaceC5206.mo4701(c4545.f17284, 0, 12);
        c4545.m9624(0);
        if (c4545.m9618() != 1179011410) {
            return false;
        }
        c4545.m9609(4);
        return c4545.m9618() == 541677121;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final void mo1256() {
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵵᵽ */
    public final void mo1257(InterfaceC4550 interfaceC4550) {
        this.f7449 = 0;
        if (this.f7446) {
            interfaceC4550 = new C0764(interfaceC4550, (InterfaceC1471) this.f7456);
        }
        this.f7458 = interfaceC4550;
        this.f7452 = -1L;
    }

    /* JADX WARN: Removed duplicated region for block: B:178:0x03a4  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0107  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x0110  */
    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵷᵺʾᵖ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int mo1258(InterfaceC5206 interfaceC5206, C2669 c2669) throws ParserException {
        boolean z;
        int i;
        C0986 c0986;
        long j;
        int i2;
        C0986 c09862;
        int i3 = 0;
        if (this.f7452 != -1) {
            long position = interfaceC5206.getPosition();
            long j2 = this.f7452;
            if (j2 < position || j2 > 262144 + position) {
                c2669.f10317 = j2;
                z = true;
            } else {
                interfaceC5206.mo4700((int) (j2 - position));
                z = false;
            }
        } else {
            z = false;
        }
        this.f7452 = -1L;
        if (z) {
            return 1;
        }
        int i4 = this.f7449;
        int i5 = 4;
        C0986 c09863 = null;
        C5151 c5151 = this.f7443;
        int i6 = 2;
        C4545 c4545 = this.f7453;
        switch (i4) {
            case 0:
                if (!mo1255(interfaceC5206)) {
                    throw ParserException.m357("AVI Header List not found", null);
                }
                interfaceC5206.mo4700(12);
                this.f7449 = 1;
                return 0;
            case 1:
                interfaceC5206.readFully(c4545.f17284, 0, 12);
                c4545.m9624(0);
                c5151.getClass();
                c5151.f19366 = c4545.m9618();
                c5151.f19364 = c4545.m9618();
                c5151.f19365 = 0;
                if (c5151.f19366 != 1414744396) {
                    throw ParserException.m357("LIST expected, found: " + c5151.f19366, null);
                }
                int iM9618 = c4545.m9618();
                c5151.f19365 = iM9618;
                if (iM9618 == 1819436136) {
                    this.f7451 = c5151.f19364;
                    this.f7449 = 2;
                    return 0;
                }
                throw ParserException.m357("hdrl expected, found: " + c5151.f19365, null);
            case 2:
                int i7 = this.f7451 - 4;
                C4545 c45452 = new C4545(i7);
                interfaceC5206.readFully(c45452.f17284, 0, i7);
                C5117 c5117M10619 = C5117.m10619(1819436136, c45452);
                int i8 = c5117M10619.f19270;
                if (i8 != 1819436136) {
                    throw ParserException.m357("Unexpected header list type " + i8, null);
                }
                C2494 c2494 = (C2494) c5117M10619.m10620(C2494.class);
                if (c2494 == null) {
                    throw ParserException.m357("AviHeader not found", null);
                }
                this.f7454 = c2494;
                this.f7444 = ((long) c2494.f9683) * ((long) c2494.f9684);
                ArrayList arrayList = new ArrayList();
                C2822 c2822ListIterator = c5117M10619.f19271.listIterator(0);
                int i9 = 0;
                while (c2822ListIterator.hasNext()) {
                    InterfaceC4834 interfaceC4834 = (InterfaceC4834) c2822ListIterator.next();
                    if (interfaceC4834.mo1562() == 1819440243) {
                        C5117 c5117 = (C5117) interfaceC4834;
                        int i10 = i9 + 1;
                        C4016 c4016 = (C4016) c5117.m10620(C4016.class);
                        C1797 c1797 = (C1797) c5117.m10620(C1797.class);
                        if (c4016 == null) {
                            ˋˀᵧ.ʿٴˇ("Missing Stream Header");
                        } else if (c1797 == null) {
                            ˋˀᵧ.ʿٴˇ("Missing Stream Format");
                        } else {
                            long j3 = c4016.f15440;
                            long j4 = ((long) c4016.f15436) * 1000000;
                            i = i10;
                            long j5 = c4016.f15437;
                            String str = AbstractC0956.f4222;
                            long jM3218 = AbstractC0956.m3218(j3, j4, j5, RoundingMode.DOWN);
                            C5286 c5286 = c1797.f7182;
                            C4753 c4753M10878 = c5286.m10878();
                            c4753M10878.f18121 = Integer.toString(i9);
                            int i11 = c4016.f15438;
                            if (i11 != 0) {
                                c4753M10878.f18116 = i11;
                            }
                            C0311 c0311 = (C0311) c5117.m10620(C0311.class);
                            if (c0311 != null) {
                                c4753M10878.f18089 = c0311.f2004;
                            }
                            int iM9141 = AbstractC4208.m9141(c5286.f19987);
                            if (iM9141 == 1 || iM9141 == i6) {
                                InterfaceC5226 interfaceC5226Mo2743 = this.f7458.mo2743(i9, iM9141);
                                interfaceC5226Mo2743.mo1742(new C5286(c4753M10878));
                                interfaceC5226Mo2743.mo1743(jM3218);
                                this.f7444 = Math.max(this.f7444, jM3218);
                                c0986 = new C0986(i9, c4016, interfaceC5226Mo2743);
                            } else {
                                c0986 = null;
                            }
                            if (c0986 != null) {
                                arrayList.add(c0986);
                            }
                            i9 = i;
                        }
                        i = i10;
                        c0986 = null;
                        if (c0986 != null) {
                        }
                        i9 = i;
                    }
                    i3 = 0;
                    i6 = 2;
                }
                int i12 = i3;
                this.f7457 = (C0986[]) arrayList.toArray(new C0986[i12]);
                this.f7458.mo2740();
                this.f7449 = 3;
                return i12;
            case 3:
                if (this.f7447 != -1) {
                    long position2 = interfaceC5206.getPosition();
                    long j6 = this.f7447;
                    if (position2 != j6) {
                        this.f7452 = j6;
                        return 0;
                    }
                }
                interfaceC5206.mo4701(c4545.f17284, 0, 12);
                interfaceC5206.mo4698();
                c4545.m9624(0);
                c5151.getClass();
                c5151.f19366 = c4545.m9618();
                c5151.f19364 = c4545.m9618();
                c5151.f19365 = 0;
                int iM96182 = c4545.m9618();
                int i13 = c5151.f19366;
                if (i13 == 1179011410) {
                    interfaceC5206.mo4700(12);
                    return 0;
                }
                if (i13 != 1414744396 || iM96182 != 1769369453) {
                    this.f7452 = interfaceC5206.getPosition() + ((long) c5151.f19364) + 8;
                    return 0;
                }
                long position3 = interfaceC5206.getPosition();
                this.f7447 = position3;
                this.f7445 = position3 + ((long) c5151.f19364) + 8;
                if (!this.f7448) {
                    C2494 c24942 = this.f7454;
                    c24942.getClass();
                    if ((c24942.f9682 & 16) == 16) {
                        this.f7449 = 4;
                        this.f7452 = this.f7445;
                        return 0;
                    }
                    this.f7458.mo2739(new C3782(this.f7444));
                    this.f7448 = true;
                }
                this.f7452 = interfaceC5206.getPosition() + 12;
                this.f7449 = 6;
                return 0;
            case 4:
                interfaceC5206.readFully(c4545.f17284, 0, 8);
                c4545.m9624(0);
                int iM96183 = c4545.m9618();
                int iM96184 = c4545.m9618();
                if (iM96183 != 829973609) {
                    this.f7452 = interfaceC5206.getPosition() + ((long) iM96184);
                    return 0;
                }
                this.f7449 = 5;
                this.f7450 = iM96184;
                return 0;
            case 5:
                C4545 c45453 = new C4545(this.f7450);
                interfaceC5206.readFully(c45453.f17284, 0, this.f7450);
                if (c45453.m9623() < 16) {
                    j = 0;
                } else {
                    int i14 = c45453.f17282;
                    c45453.m9609(8);
                    long jM9618 = c45453.m9618();
                    long j7 = this.f7447;
                    j = jM9618 > j7 ? 0L : j7 + 8;
                    c45453.m9624(i14);
                }
                while (c45453.m9623() >= 16) {
                    int iM96185 = c45453.m9618();
                    int iM96186 = c45453.m9618();
                    long jM96182 = ((long) c45453.m9618()) + j;
                    c45453.m9609(i5);
                    C0986[] c0986Arr = this.f7457;
                    int length = c0986Arr.length;
                    int i15 = 0;
                    while (true) {
                        if (i15 < length) {
                            c09862 = c0986Arr[i15];
                            if (c09862.f4324 != iM96185 && c09862.f4332 != iM96185) {
                                i15++;
                            }
                        } else {
                            c09862 = null;
                        }
                    }
                    if (c09862 != null) {
                        boolean z2 = (iM96186 & 16) == 16;
                        if (c09862.f4327 == -1) {
                            c09862.f4327 = jM96182;
                        }
                        if (z2) {
                            if (c09862.f4331 == c09862.f4323.length) {
                                long[] jArr = c09862.f4325;
                                c09862.f4325 = Arrays.copyOf(jArr, (jArr.length * 3) / 2);
                                int[] iArr = c09862.f4323;
                                c09862.f4323 = Arrays.copyOf(iArr, (iArr.length * 3) / 2);
                            }
                            long[] jArr2 = c09862.f4325;
                            int i16 = c09862.f4331;
                            jArr2[i16] = jM96182;
                            c09862.f4323[i16] = c09862.f4328;
                            c09862.f4331 = i16 + 1;
                        }
                        c09862.f4328++;
                    }
                    i5 = 4;
                }
                for (C0986 c09864 : this.f7457) {
                    c09864.f4325 = Arrays.copyOf(c09864.f4325, c09864.f4331);
                    c09864.f4323 = Arrays.copyOf(c09864.f4323, c09864.f4331);
                    if ((c09864.f4324 & 1651965952) == 1651965952 && c09864.f4329.f15441 != 0 && (i2 = c09864.f4331) > 0) {
                        c09864.f4334 = i2;
                    }
                }
                this.f7448 = true;
                int length2 = this.f7457.length;
                InterfaceC4550 interfaceC4550 = this.f7458;
                long j8 = this.f7444;
                if (length2 == 0) {
                    interfaceC4550.mo2739(new C3782(j8));
                } else {
                    interfaceC4550.mo2739(new C3782(this, j8, 0));
                }
                this.f7449 = 6;
                this.f7452 = this.f7447;
                return 0;
            case C5224.STRING_SET_FIELD_NUMBER /* 6 */:
                if (interfaceC5206.getPosition() >= this.f7445) {
                    return -1;
                }
                C0986 c09865 = this.f7455;
                if (c09865 != null) {
                    int i17 = c09865.f4322;
                    int iMo1744 = i17 - c09865.f4321.mo1744(interfaceC5206, i17, false);
                    c09865.f4322 = iMo1744;
                    boolean z3 = iMo1744 == 0;
                    if (z3) {
                        if (c09865.f4330 > 0) {
                            InterfaceC5226 interfaceC5226 = c09865.f4321;
                            int i18 = c09865.f4333;
                            interfaceC5226.mo1741((c09865.f4326 * ((long) i18)) / ((long) c09865.f4334), Arrays.binarySearch(c09865.f4323, i18) >= 0 ? 1 : 0, c09865.f4330, 0, null);
                        }
                        c09865.f4333++;
                    }
                    if (z3) {
                        this.f7455 = null;
                    }
                    return 0;
                }
                if ((interfaceC5206.getPosition() & 1) == 1) {
                    interfaceC5206.mo4700(1);
                }
                interfaceC5206.mo4701(c4545.f17284, 0, 12);
                c4545.m9624(0);
                int iM96187 = c4545.m9618();
                if (iM96187 == 1414744396) {
                    c4545.m9624(8);
                    interfaceC5206.mo4700(c4545.m9618() == 1769369453 ? 12 : 8);
                    interfaceC5206.mo4698();
                    return 0;
                }
                int iM96188 = c4545.m9618();
                if (iM96187 == 1263424842) {
                    this.f7452 = interfaceC5206.getPosition() + ((long) iM96188) + 8;
                    return 0;
                }
                interfaceC5206.mo4700(8);
                interfaceC5206.mo4698();
                for (C0986 c09866 : this.f7457) {
                    if (c09866.f4324 == iM96187 || c09866.f4332 == iM96187) {
                        c09863 = c09866;
                        if (c09863 != null) {
                            this.f7452 = interfaceC5206.getPosition() + ((long) iM96188);
                            return 0;
                        }
                        c09863.f4330 = iM96188;
                        c09863.f4322 = iM96188;
                        this.f7455 = c09863;
                        return 0;
                    }
                }
                if (c09863 != null) {
                }
                break;
            default:
                throw new AssertionError();
        }
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final List mo1259() {
        C2822 c2822 = AbstractC4509.f17159;
        return C2598.f10048;
    }
}
