package x;

import b0.D;
import b0.l;
import b0.t;
import com.mstar.android.tv.TvLanguage;
import java.io.EOFException;
import n.x;
import n.z;
import v.f;
import v.g;
import v.i;
import v.j;
import v.m;
import v.o;

/* JADX INFO: renamed from: x.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0734c implements v.e {

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private static final int f6743m = D.u("Xing");

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private static final int f6744n = D.u("Info");

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private static final int f6745o = D.u("VBRI");

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final /* synthetic */ int f6746p = 0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final long f6747b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private g f6750e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private o f6751f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f6752g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private i f6753h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private a f6754i;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private long f6756k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private int f6757l;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final t f6748c = new t(4);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final l f6749d = new l();

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private long f6755j = -1;

    /* JADX INFO: renamed from: x.c$a */
    interface a extends m {
        long d(long j2);

        long h();
    }

    public C0734c(long j2) {
        this.f6747b = j2;
    }

    private boolean b(f fVar) {
        fVar.g();
        if (!fVar.b(this.f6748c.f3092a, 0, 4, true)) {
            return false;
        }
        this.f6748c.B(0);
        int iH = this.f6748c.h();
        if ((iH & (-128000)) == ((-128000) & this.f6752g) && l.a(iH) != -1) {
            l.b(iH, this.f6749d);
            return true;
        }
        this.f6752g = 0;
        fVar.h(1);
        return i(fVar);
    }

    private int c(f fVar) {
        if (this.f6757l == 0) {
            if (!b(fVar)) {
                return -1;
            }
            if (this.f6755j == -1) {
                this.f6755j = this.f6754i.d(fVar.j());
                if (this.f6747b != -1) {
                    this.f6755j += this.f6747b - this.f6754i.d(0L);
                }
            }
            this.f6757l = this.f6749d.f3026c;
        }
        int iD = this.f6751f.d(fVar, this.f6757l, true);
        if (iD == -1) {
            return -1;
        }
        int i2 = this.f6757l - iD;
        this.f6757l = i2;
        if (i2 > 0) {
            return 0;
        }
        long j2 = this.f6755j;
        long j3 = this.f6756k * 1000000;
        l lVar = this.f6749d;
        this.f6751f.e(j2 + (j3 / ((long) lVar.f3027d)), 1, lVar.f3026c, 0, null);
        this.f6756k += (long) this.f6749d.f3030g;
        this.f6757l = 0;
        return 0;
    }

    private void d(f fVar) {
        int iH;
        t tVar = new t(this.f6749d.f3026c);
        fVar.i(tVar.f3092a, 0, this.f6749d.f3026c);
        long j2 = fVar.j();
        long jF = fVar.f();
        l lVar = this.f6749d;
        int i2 = 21;
        if ((lVar.f3024a & 1) != 0) {
            if (lVar.f3028e != 1) {
                i2 = 36;
            }
        } else if (lVar.f3028e == 1) {
            i2 = 13;
        }
        if (tVar.d() >= i2 + 4) {
            tVar.B(i2);
            iH = tVar.h();
        } else {
            iH = 0;
        }
        if (iH == f6743m || iH == f6744n) {
            C0736e c0736eA = C0736e.a(this.f6749d, tVar, j2, jF);
            this.f6754i = c0736eA;
            if (c0736eA != null && this.f6753h == null) {
                fVar.g();
                fVar.d(i2 + TvLanguage.CREOLESANDPIDGINSFRENCH);
                fVar.i(this.f6748c.f3092a, 0, 3);
                this.f6748c.B(0);
                this.f6753h = i.b(this.f6748c.t());
            }
            fVar.h(this.f6749d.f3026c);
        } else if (tVar.d() >= 40) {
            tVar.B(36);
            if (tVar.h() == f6745o) {
                this.f6754i = C0735d.a(this.f6749d, tVar, j2, jF);
                fVar.h(this.f6749d.f3026c);
            }
        }
        if (this.f6754i == null) {
            fVar.g();
            fVar.i(this.f6748c.f3092a, 0, 4);
            this.f6748c.B(0);
            l.b(this.f6748c.h(), this.f6749d);
            this.f6754i = new C0732a(fVar.j(), this.f6749d.f3029f, jF);
        }
    }

    private boolean h(f fVar, boolean z2) throws z {
        int iC;
        int i2;
        int iA;
        fVar.g();
        if (fVar.j() == 0) {
            this.f6753h = AbstractC0733b.e(fVar);
            iC = (int) fVar.c();
            if (!z2) {
                fVar.h(iC);
            }
            i2 = 0;
        } else {
            iC = 0;
            i2 = 0;
        }
        int i3 = i2;
        while (true) {
            int i4 = i3;
            while (true) {
                if (z2 && i2 == 4096) {
                    return false;
                }
                if (!z2 && i2 == 131072) {
                    throw new z("Searched too many bytes.");
                }
                if (!fVar.b(this.f6748c.f3092a, 0, 4, true)) {
                    return false;
                }
                this.f6748c.B(0);
                int iH = this.f6748c.h();
                if ((i3 != 0 && (iH & (-128000)) != ((-128000) & i3)) || (iA = l.a(iH)) == -1) {
                    break;
                }
                i4++;
                if (i4 == 1) {
                    l.b(iH, this.f6749d);
                    i3 = iH;
                } else if (i4 == 4) {
                    if (z2) {
                        fVar.h(iC + i2);
                    } else {
                        fVar.g();
                    }
                    this.f6752g = i3;
                    return true;
                }
                fVar.d(iA - 4);
            }
            i2++;
            if (z2) {
                fVar.g();
                fVar.d(iC + i2);
            } else {
                fVar.h(1);
            }
            i3 = 0;
        }
    }

    private boolean i(f fVar) {
        try {
            return h(fVar, false);
        } catch (EOFException unused) {
            return false;
        }
    }

    @Override // v.e
    public int a(f fVar, j jVar) {
        if (this.f6752g == 0 && !i(fVar)) {
            return -1;
        }
        if (this.f6754i == null) {
            d(fVar);
            this.f6750e.b(this.f6754i);
            String str = this.f6749d.f3025b;
            long jH = this.f6754i.h();
            l lVar = this.f6749d;
            x xVarH = x.h(null, str, -1, 4096, jH, lVar.f3028e, lVar.f3027d, null, null);
            i iVar = this.f6753h;
            if (iVar != null) {
                xVarH = xVarH.d(iVar.f6630a, iVar.f6631b);
            }
            this.f6751f.c(xVarH);
        }
        return c(fVar);
    }

    @Override // v.e
    public void e(g gVar) {
        this.f6750e = gVar;
        this.f6751f = gVar.i(0);
        gVar.m();
    }

    @Override // v.e
    public void f() {
        this.f6752g = 0;
        this.f6756k = 0L;
        this.f6755j = -1L;
        this.f6757l = 0;
    }

    @Override // v.e
    public boolean g(f fVar) {
        return h(fVar, true);
    }

    @Override // v.e
    public void release() {
    }
}
