package b1;

import C3.G;
import C3.W;
import L4.h;
import N1.C0207h;
import T0.j;
import T0.m;
import T0.n;
import T0.o;
import T0.q;
import i1.C1049a;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.List;
import n1.C1259k;
import org.xmlpull.v1.XmlPullParserException;
import q1.InterfaceC1454k;
import u0.C1578n;
import u0.D;
import u0.E;
import u0.F;
import x0.AbstractC1709a;

/* JADX INFO: renamed from: b1.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0529a implements m {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public o f9167b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f9168c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f9169d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f9170e;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public C1049a f9172g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public j f9173h;
    public C0207h i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public C1259k f9174j;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final x0.o f9166a = new x0.o(6);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public long f9171f = -1;

    @Override // T0.m
    public final void a() {
        C1259k c1259k = this.f9174j;
        if (c1259k != null) {
            c1259k.getClass();
        }
    }

    public final void b() {
        o oVar = this.f9167b;
        oVar.getClass();
        oVar.h();
        this.f9167b.v(new q(-9223372036854775807L));
        this.f9168c = 6;
    }

    @Override // T0.m
    public final m c() {
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x0108  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x0190  */
    @Override // T0.m
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int e(n nVar, h hVar) throws F, EOFException, InterruptedIOException {
        String strO;
        C0207h c0207hA;
        W w4;
        int i;
        C1049a c1049a;
        long j8;
        long j9;
        byte b8 = -1;
        int i5 = this.f9168c;
        long j10 = -1;
        x0.o oVar = this.f9166a;
        if (i5 == 0) {
            oVar.C(2);
            ((j) nVar).c(oVar.f18539a, 0, 2, false);
            int iZ = oVar.z();
            this.f9169d = iZ;
            if (iZ == 65498) {
                if (this.f9171f != -1) {
                    this.f9168c = 4;
                    return 0;
                }
                b();
                return 0;
            }
            if ((iZ < 65488 || iZ > 65497) && iZ != 65281) {
                this.f9168c = 1;
            }
        } else {
            if (i5 == 1) {
                oVar.C(2);
                ((j) nVar).c(oVar.f18539a, 0, 2, false);
                this.f9170e = oVar.z() - 2;
                this.f9168c = 2;
                return 0;
            }
            if (i5 != 2) {
                if (i5 != 4) {
                    if (i5 != 5) {
                        if (i5 == 6) {
                            return -1;
                        }
                        throw new IllegalStateException();
                    }
                    if (this.i == null || nVar != this.f9173h) {
                        j jVar = (j) nVar;
                        this.f9173h = jVar;
                        this.i = new C0207h(jVar, this.f9171f);
                    }
                    C1259k c1259k = this.f9174j;
                    c1259k.getClass();
                    int iE = c1259k.e(this.i, hVar);
                    if (iE == 1) {
                        hVar.f4006a += this.f9171f;
                    }
                    return iE;
                }
                long j11 = ((j) nVar).f6428t;
                long j12 = this.f9171f;
                if (j11 != j12) {
                    hVar.f4006a = j12;
                    return 1;
                }
                j jVar2 = (j) nVar;
                if (!jVar2.f(oVar.f18539a, 0, 1, true)) {
                    b();
                    return 0;
                }
                jVar2.f6430v = 0;
                if (this.f9174j == null) {
                    this.f9174j = new C1259k(InterfaceC1454k.f16220p, 8);
                }
                C0207h c0207h = new C0207h(jVar2, this.f9171f);
                this.i = c0207h;
                if (!this.f9174j.f(c0207h)) {
                    b();
                    return 0;
                }
                C1259k c1259k2 = this.f9174j;
                long j13 = this.f9171f;
                o oVar2 = this.f9167b;
                oVar2.getClass();
                c1259k2.l(new C0207h(3, j13, oVar2));
                C1049a c1049a2 = this.f9172g;
                c1049a2.getClass();
                o oVar3 = this.f9167b;
                oVar3.getClass();
                T0.F fJ = oVar3.j(1024, 4);
                C1578n c1578n = new C1578n();
                c1578n.f17319l = E.m("image/jpeg");
                c1578n.f17318k = new D(c1049a2);
                I1.a.w(c1578n, fJ);
                this.f9168c = 5;
                return 0;
            }
            if (this.f9169d == 65505) {
                x0.o oVar4 = new x0.o(this.f9170e);
                ((j) nVar).c(oVar4.f18539a, 0, this.f9170e, false);
                if (this.f9172g == null && "http://ns.adobe.com/xap/1.0/".equals(oVar4.o()) && (strO = oVar4.o()) != null) {
                    long j14 = ((j) nVar).f6427s;
                    if (j14 == -1) {
                        c1049a = null;
                        this.f9172g = c1049a;
                        if (c1049a != null) {
                            this.f9171f = c1049a.f13486d;
                        }
                    } else {
                        try {
                            c0207hA = AbstractC0532d.a(strO);
                        } catch (NumberFormatException | XmlPullParserException | F unused) {
                            AbstractC1709a.B("MotionPhotoXmpParser", "Ignoring unexpected XMP metadata");
                            c0207hA = null;
                        }
                        if (c0207hA != null && (i = (w4 = (W) c0207hA.f4548s).f1227t) >= 2) {
                            int i8 = i - 1;
                            boolean z8 = false;
                            long j15 = -1;
                            long j16 = -1;
                            long j17 = -1;
                            long j18 = -1;
                            while (i8 >= 0) {
                                C0530b c0530b = (C0530b) w4.get(i8);
                                byte b9 = b8;
                                boolean zEquals = "video/mp4".equals(c0530b.f9175a) | z8;
                                if (i8 == 0) {
                                    j8 = j10;
                                    j14 -= c0530b.f9177c;
                                    j9 = 0;
                                } else {
                                    j8 = j10;
                                    j9 = j14 - c0530b.f9176b;
                                }
                                long j19 = j14;
                                j14 = j9;
                                if (!zEquals || j14 == j19) {
                                    z8 = zEquals;
                                } else {
                                    j18 = j19 - j14;
                                    z8 = false;
                                    j17 = j14;
                                }
                                if (i8 == 0) {
                                    j16 = j19;
                                    j15 = j14;
                                }
                                i8--;
                                b8 = b9;
                                j10 = j8;
                            }
                            long j20 = j10;
                            if (j17 != j20 && j18 != j20 && j15 != j20 && j16 != j20) {
                                c1049a = new C1049a(j15, j16, c0207hA.f4547r, j17, j18);
                            }
                            this.f9172g = c1049a;
                            if (c1049a != null) {
                            }
                        }
                    }
                }
            } else {
                ((j) nVar).b(this.f9170e);
            }
            this.f9168c = 0;
        }
        return 0;
    }

    @Override // T0.m
    public final boolean f(n nVar) throws EOFException, InterruptedIOException {
        j jVar = (j) nVar;
        x0.o oVar = this.f9166a;
        oVar.C(2);
        jVar.f(oVar.f18539a, 0, 2, false);
        if (oVar.z() == 65496) {
            oVar.C(2);
            jVar.f(oVar.f18539a, 0, 2, false);
            int iZ = oVar.z();
            this.f9169d = iZ;
            if (iZ == 65504) {
                oVar.C(2);
                jVar.f(oVar.f18539a, 0, 2, false);
                jVar.h(oVar.z() - 2, false);
                oVar.C(2);
                jVar.f(oVar.f18539a, 0, 2, false);
                this.f9169d = oVar.z();
            }
            if (this.f9169d == 65505) {
                jVar.h(2, false);
                oVar.C(6);
                jVar.f(oVar.f18539a, 0, 6, false);
                if (oVar.v() == 1165519206 && oVar.z() == 0) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override // T0.m
    public final void i(long j8, long j9) {
        if (j8 == 0) {
            this.f9168c = 0;
            this.f9174j = null;
        } else if (this.f9168c == 5) {
            C1259k c1259k = this.f9174j;
            c1259k.getClass();
            c1259k.i(j8, j9);
        }
    }

    @Override // T0.m
    public final void l(o oVar) {
        this.f9167b = oVar;
    }

    @Override // T0.m
    public final List m() {
        C3.E e8 = G.f1197r;
        return W.f1225u;
    }
}
