package defpackage;

import androidx.media3.common.ParserException;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* JADX INFO: renamed from: ʽᵙᵕ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C0139 implements InterfaceC4291 {

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

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

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

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

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final C0154 f1495;

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

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

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

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

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

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public long f1503;

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

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C4545 f1499 = new C4545(4);

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C4545 f1489 = new C4545(9);

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final C4545 f1492 = new C4545(11);

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final C4545 f1502 = new C4545();

    public C0139() {
        C0154 c0154 = new C0154(new C0406());
        c0154.f1557 = -9223372036854775807L;
        c0154.f1556 = new long[0];
        c0154.f1558 = new long[0];
        this.f1495 = c0154;
        this.f1500 = 1;
    }

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final void mo1252(long j, long j2) {
        if (j == 0) {
            this.f1500 = 1;
            this.f1490 = false;
        } else {
            this.f1500 = 3;
        }
        this.f1498 = 0;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final C4545 m1253(InterfaceC5206 interfaceC5206) {
        int i = this.f1497;
        C4545 c4545 = this.f1502;
        byte[] bArr = c4545.f17284;
        if (i > bArr.length) {
            c4545.m9600(0, new byte[Math.max(bArr.length * 2, i)]);
        } else {
            c4545.m9624(0);
        }
        c4545.m9612(this.f1497);
        interfaceC5206.readFully(c4545.f17284, 0, this.f1497);
        return c4545;
    }

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

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final boolean mo1255(InterfaceC5206 interfaceC5206) throws EOFException, InterruptedIOException {
        C4545 c4545 = this.f1499;
        C2373 c2373 = (C2373) interfaceC5206;
        c2373.mo4708(c4545.f17284, 0, 3, false);
        c4545.m9624(0);
        if (c4545.m9628() == 4607062) {
            c2373.mo4708(c4545.f17284, 0, 2, false);
            c4545.m9624(0);
            if ((c4545.m9598() & 250) == 0) {
                c2373.mo4708(c4545.f17284, 0, 4, false);
                c4545.m9624(0);
                int iM9614 = c4545.m9614();
                c2373.f9292 = 0;
                c2373.m6055(iM9614, false);
                c2373.mo4708(c4545.f17284, 0, 4, false);
                c4545.m9624(0);
                if (c4545.m9614() == 0) {
                    return true;
                }
            }
        }
        return false;
    }

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

    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final void mo1257(InterfaceC4550 interfaceC4550) {
        this.f1504 = interfaceC4550;
    }

    /* JADX WARN: Removed duplicated region for block: B:144:0x03b0  */
    /* JADX WARN: Removed duplicated region for block: B:145:0x03b4  */
    /* JADX WARN: Removed duplicated region for block: B:184:0x03c0 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:194:0x0009 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0170  */
    /* JADX WARN: Removed duplicated region for block: B:94:0x029d  */
    /* JADX WARN: Removed duplicated region for block: B:99:0x02b2  */
    @Override // defpackage.InterfaceC4291
    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int mo1258(InterfaceC5206 interfaceC5206, C2669 c2669) throws ParserException {
        long j;
        long j2;
        int i;
        boolean z;
        boolean z2;
        int i2;
        this.f1504.getClass();
        while (true) {
            int i3 = this.f1500;
            boolean z3 = true;
            if (i3 == 1) {
                C4545 c4545 = this.f1489;
                if (!interfaceC5206.mo4710(c4545.f17284, 0, 9, true)) {
                    return -1;
                }
                c4545.m9624(0);
                c4545.m9609(4);
                int iM9626 = c4545.m9626();
                boolean z4 = (iM9626 & 4) != 0;
                boolean z5 = (iM9626 & 1) != 0;
                if (z4 && this.f1496 == null) {
                    this.f1496 = new C3756(this.f1504.mo2743(8, 1));
                }
                if (z5 && this.f1494 == null) {
                    i2 = 2;
                    this.f1494 = new C3480(this.f1504.mo2743(9, 2));
                } else {
                    i2 = 2;
                }
                this.f1504.mo2740();
                this.f1498 = c4545.m9614() - 5;
                this.f1500 = i2;
            } else if (i3 == 2) {
                interfaceC5206.mo4700(this.f1498);
                this.f1498 = 0;
                this.f1500 = 3;
            } else if (i3 == 3) {
                C4545 c45452 = this.f1492;
                if (!interfaceC5206.mo4710(c45452.f17284, 0, 11, true)) {
                    return -1;
                }
                c45452.m9624(0);
                this.f1501 = c45452.m9626();
                this.f1497 = c45452.m9628();
                this.f1493 = c45452.m9628();
                this.f1493 = (((long) (c45452.m9626() << 24)) | this.f1493) * 1000;
                c45452.m9609(3);
                this.f1500 = 4;
            } else {
                if (i3 != 4) {
                    ᵷᵝˎ.ᵱʡˏ();
                    return 0;
                }
                boolean z6 = this.f1490;
                C0154 c0154 = this.f1495;
                if (z6) {
                    j = this.f1503 + this.f1493;
                } else if (c0154.f1557 == -9223372036854775807L) {
                    j2 = 0;
                    i = this.f1501;
                    if (i == 8 || this.f1496 == null) {
                        int i4 = 4;
                        if (i != 9 && this.f1494 != null) {
                            if (!this.f1491) {
                                this.f1504.mo2739(new C3782(-9223372036854775807L));
                                this.f1491 = true;
                            }
                            C3480 c3480 = this.f1494;
                            C4545 c4545M1253 = m1253(interfaceC5206);
                            c3480.getClass();
                            int iM96262 = c4545M1253.m9626();
                            int i5 = (iM96262 >> 4) & 15;
                            int i6 = iM96262 & 15;
                            if (i6 != 7) {
                                final String strM6517 = AbstractC2704.m6517(i6, "Video format not supported: ");
                                throw new ParserException(strM6517) { // from class: androidx.media3.extractor.flv.TagPayloadReader$UnsupportedFormatException
                                };
                            }
                            c3480.f13396 = i5;
                            if (i5 != 5) {
                                C4545 c45453 = c3480.f13398;
                                InterfaceC5226 interfaceC5226 = (InterfaceC5226) ((ᵜᵪʾ) c3480).ˌᴵ;
                                C4545 c45454 = c3480.f13397;
                                int iM96263 = c4545M1253.m9626();
                                c4545M1253.m9630(3);
                                byte[] bArr = c4545M1253.f17284;
                                int i7 = c4545M1253.f17282;
                                int i8 = i7 + 1;
                                c4545M1253.f17282 = i8;
                                int i9 = ((bArr[i7] & 255) << 24) >> 8;
                                int i10 = i7 + 2;
                                c4545M1253.f17282 = i10;
                                int i11 = ((bArr[i8] & 255) << 8) | i9;
                                c4545M1253.f17282 = i7 + 3;
                                long j3 = (((long) (i11 | (bArr[i10] & 255))) * 1000) + j2;
                                if (iM96263 == 0 && !c3480.f13400) {
                                    byte[] bArr2 = new byte[c4545M1253.m9623()];
                                    C4545 c45455 = new C4545(bArr2);
                                    c4545M1253.m9627(bArr2, 0, c4545M1253.m9623());
                                    C3923 c3923M8653 = C3923.m8653(c45455);
                                    c3480.f13399 = c3923M8653.f14974;
                                    C4753 c4753 = new C4753();
                                    c4753.f18111 = AbstractC4208.m9132("video/x-flv");
                                    c4753.f18101 = AbstractC4208.m9132("video/avc");
                                    c4753.f18120 = c3923M8653.f14978;
                                    c4753.f18098 = c3923M8653.f14976;
                                    c4753.f18102 = c3923M8653.f14983;
                                    c4753.f18124 = c3923M8653.f14982;
                                    c4753.f18119 = c3923M8653.f14980;
                                    AbstractC0659.m2415(c4753, interfaceC5226);
                                    c3480.f13400 = true;
                                } else if (iM96263 == 1 && c3480.f13400) {
                                    int i12 = c3480.f13396 == 1 ? 1 : 0;
                                    if (c3480.f13401 || i12 != 0) {
                                        byte[] bArr3 = c45454.f17284;
                                        bArr3[0] = 0;
                                        bArr3[1] = 0;
                                        bArr3[2] = 0;
                                        int i13 = 4 - c3480.f13399;
                                        int i14 = 0;
                                        while (c4545M1253.m9623() > 0) {
                                            c4545M1253.m9627(c45454.f17284, i13, c3480.f13399);
                                            c45454.m9624(0);
                                            int iM9610 = c45454.m9610();
                                            c45453.m9624(0);
                                            interfaceC5226.mo1740(i4, c45453);
                                            interfaceC5226.mo1740(iM9610, c4545M1253);
                                            i14 = i14 + 4 + iM9610;
                                            i4 = 4;
                                        }
                                        ((InterfaceC5226) ((ᵜᵪʾ) c3480).ˌᴵ).mo1741(j3, i12, i14, 0, null);
                                        c3480.f13401 = true;
                                        z2 = true;
                                    }
                                    z = z2 ? false : true;
                                    z3 = true;
                                }
                                z2 = false;
                                if (z2) {
                                }
                                z3 = true;
                            }
                        } else if (i == 18 || this.f1491) {
                            interfaceC5206.mo4700(this.f1497);
                            z = false;
                            z3 = false;
                        } else {
                            C4545 c4545M12532 = m1253(interfaceC5206);
                            c0154.getClass();
                            if (c4545M12532.m9626() == 2 && "onMetaData".equals(C0154.m1299(c4545M12532)) && c4545M12532.m9623() != 0 && c4545M12532.m9626() == 8) {
                                HashMap mapM1300 = C0154.m1300(c4545M12532);
                                Object obj = mapM1300.get("duration");
                                if (obj instanceof Double) {
                                    double dDoubleValue = ((Double) obj).doubleValue();
                                    if (dDoubleValue > 0.0d) {
                                        c0154.f1557 = (long) (dDoubleValue * 1000000.0d);
                                    }
                                }
                                Object obj2 = mapM1300.get("keyframes");
                                if (obj2 instanceof Map) {
                                    Map map = (Map) obj2;
                                    Object obj3 = map.get("filepositions");
                                    Object obj4 = map.get("times");
                                    if ((obj3 instanceof List) && (obj4 instanceof List)) {
                                        List list = (List) obj3;
                                        List list2 = (List) obj4;
                                        int size = list2.size();
                                        c0154.f1556 = new long[size];
                                        c0154.f1558 = new long[size];
                                        for (int i15 = 0; i15 < size; i15++) {
                                            Object obj5 = list.get(i15);
                                            Object obj6 = list2.get(i15);
                                            if (!(obj6 instanceof Double) || !(obj5 instanceof Double)) {
                                                c0154.f1556 = new long[0];
                                                c0154.f1558 = new long[0];
                                                break;
                                            }
                                            c0154.f1556[i15] = (long) (((Double) obj6).doubleValue() * 1000000.0d);
                                            c0154.f1558[i15] = ((Double) obj5).longValue();
                                        }
                                    }
                                }
                            }
                            long j4 = c0154.f1557;
                            if (j4 != -9223372036854775807L) {
                                this.f1504.mo2739(new C2665(j4, c0154.f1558, c0154.f1556));
                                this.f1491 = true;
                            }
                        }
                        z3 = true;
                    } else {
                        if (!this.f1491) {
                            this.f1504.mo2739(new C3782(-9223372036854775807L));
                            this.f1491 = true;
                        }
                        C3756 c3756 = this.f1496;
                        C4545 c4545M12533 = m1253(interfaceC5206);
                        InterfaceC5226 interfaceC52262 = (InterfaceC5226) ((ᵜᵪʾ) c3756).ˌᴵ;
                        if (c3756.f14285) {
                            c4545M12533.m9609(1);
                        } else {
                            int iM96264 = c4545M12533.m9626();
                            int i16 = (iM96264 >> 4) & 15;
                            c3756.f14286 = i16;
                            if (i16 == 2) {
                                int i17 = C3756.f14283[(iM96264 >> 2) & 3];
                                C4753 c47532 = new C4753();
                                c47532.f18111 = AbstractC4208.m9132("video/x-flv");
                                c47532.f18101 = AbstractC4208.m9132("audio/mpeg");
                                c47532.f18090 = 1;
                                c47532.f18113 = i17;
                                AbstractC0659.m2415(c47532, interfaceC52262);
                                c3756.f14284 = true;
                            } else if (i16 == 7 || i16 == 8) {
                                String str = i16 == 7 ? "audio/g711-alaw" : "audio/g711-mlaw";
                                C4753 c47533 = new C4753();
                                c47533.f18111 = AbstractC4208.m9132("video/x-flv");
                                c47533.f18101 = AbstractC4208.m9132(str);
                                c47533.f18090 = 1;
                                c47533.f18113 = 8000;
                                AbstractC0659.m2415(c47533, interfaceC52262);
                                c3756.f14284 = true;
                            } else if (i16 != 10) {
                                final String str2 = "Audio format not supported: " + c3756.f14286;
                                throw new ParserException(str2) { // from class: androidx.media3.extractor.flv.TagPayloadReader$UnsupportedFormatException
                                };
                            }
                            c3756.f14285 = true;
                        }
                        InterfaceC5226 interfaceC52263 = (InterfaceC5226) ((ᵜᵪʾ) c3756).ˌᴵ;
                        if (c3756.f14286 == 2) {
                            int iM9623 = c4545M12533.m9623();
                            interfaceC52263.mo1740(iM9623, c4545M12533);
                            ((InterfaceC5226) ((ᵜᵪʾ) c3756).ˌᴵ).mo1741(j2, 1, iM9623, 0, null);
                        } else {
                            int iM96265 = c4545M12533.m9626();
                            if (iM96265 == 0 && !c3756.f14284) {
                                int iM96232 = c4545M12533.m9623();
                                byte[] bArr4 = new byte[iM96232];
                                c4545M12533.m9627(bArr4, 0, iM96232);
                                C1260 c1260 = ᵱˉˈ.ˑˊᵲ(new C3180(iM96232, bArr4), false);
                                C4753 c47534 = new C4753();
                                c47534.f18111 = AbstractC4208.m9132("video/x-flv");
                                c47534.f18101 = AbstractC4208.m9132("audio/mp4a-latm");
                                c47534.f18120 = c1260.f5307;
                                c47534.f18090 = c1260.f5306;
                                c47534.f18113 = c1260.f5308;
                                c47534.f18119 = Collections.singletonList(bArr4);
                                AbstractC0659.m2415(c47534, interfaceC52263);
                                c3756.f14284 = true;
                            } else if (c3756.f14286 != 10 || iM96265 == 1) {
                                int iM96233 = c4545M12533.m9623();
                                interfaceC52263.mo1740(iM96233, c4545M12533);
                                ((InterfaceC5226) ((ᵜᵪʾ) c3756).ˌᴵ).mo1741(j2, 1, iM96233, 0, null);
                            }
                            z = false;
                        }
                        z = true;
                    }
                    if (!this.f1490 && z) {
                        this.f1490 = true;
                        this.f1503 = c0154.f1557 != -9223372036854775807L ? -this.f1493 : 0L;
                    }
                    this.f1498 = 4;
                    this.f1500 = 2;
                    if (!z3) {
                        return 0;
                    }
                } else {
                    j = this.f1493;
                }
                j2 = j;
                i = this.f1501;
                if (i == 8) {
                    int i42 = 4;
                    if (i != 9) {
                        if (i == 18) {
                        }
                        interfaceC5206.mo4700(this.f1497);
                        z = false;
                        z3 = false;
                        if (!this.f1490) {
                            this.f1490 = true;
                            this.f1503 = c0154.f1557 != -9223372036854775807L ? -this.f1493 : 0L;
                        }
                        this.f1498 = 4;
                        this.f1500 = 2;
                        if (!z3) {
                        }
                    }
                }
            }
        }
    }

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