package A;

import android.util.Log;
import android.util.Pair;
import b0.s;
import b0.t;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.util.Arrays;
import java.util.Collections;
import n.x;

/* JADX INFO: loaded from: classes.dex */
final class c extends e {

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private static final byte[] f16o = {SDKKeyboardCode.FUNCTION_KEY_BOARD_INSERT, SDKKeyboardCode.FUNCTION_KEY_BOARD_F11, SDKKeyboardCode.FUNCTION_KEY_BOARD_SEMICOLON};

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final t f18c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final v.o f19d;

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private v.o f28m;

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

    public c(v.o oVar, v.o oVar2) {
        super(oVar);
        this.f19d = oVar2;
        oVar2.c(x.k());
        this.f17b = new s(new byte[7]);
        this.f18c = new t(Arrays.copyOf(f16o, 10));
        j();
    }

    private boolean e(t tVar, byte[] bArr, int i2) {
        int iMin = Math.min(tVar.a(), i2 - this.f21f);
        tVar.e(bArr, this.f21f, iMin);
        int i3 = this.f21f + iMin;
        this.f21f = i3;
        return i3 == i2;
    }

    private void f(t tVar) {
        byte[] bArr = tVar.f3092a;
        int iC = tVar.c();
        int iD = tVar.d();
        while (iC < iD) {
            int i2 = iC + 1;
            byte b2 = bArr[iC];
            int i3 = b2 & 255;
            int i4 = this.f22g;
            if (i4 == 512 && i3 >= 240 && i3 != 255) {
                this.f23h = (b2 & 1) == 0;
                k();
                tVar.B(i2);
                return;
            }
            int i5 = i4 | i3;
            if (i5 == 329) {
                this.f22g = 768;
            } else if (i5 == 511) {
                this.f22g = 512;
            } else if (i5 == 836) {
                this.f22g = 1024;
            } else if (i5 == 1075) {
                l();
                tVar.B(i2);
                return;
            } else if (i4 != 256) {
                this.f22g = 256;
            }
            iC = i2;
        }
        tVar.B(iC);
    }

    private void g() {
        this.f17b.k(0);
        if (this.f24i) {
            this.f17b.l(10);
        } else {
            int i2 = 2;
            int iE = this.f17b.e(2) + 1;
            if (iE != 2) {
                Log.w("AdtsReader", "Detected audio object type: " + iE + ", but assuming AAC LC.");
            } else {
                i2 = iE;
            }
            int iE2 = this.f17b.e(4);
            this.f17b.l(1);
            byte[] bArrB = b0.f.b(i2, iE2, this.f17b.e(3));
            Pair pairF = b0.f.f(bArrB);
            x xVarH = x.h(null, "audio/mp4a-latm", -1, -1, -1L, ((Integer) pairF.second).intValue(), ((Integer) pairF.first).intValue(), Collections.singletonList(bArrB), null);
            this.f25j = 1024000000 / ((long) xVarH.f5841f0);
            this.f38a.c(xVarH);
            this.f24i = true;
        }
        this.f17b.l(4);
        int iE3 = this.f17b.e(13);
        int i3 = iE3 - 7;
        if (this.f23h) {
            i3 = iE3 - 9;
        }
        m(this.f38a, this.f25j, 0, i3);
    }

    private void h() {
        this.f19d.a(this.f18c, 10);
        this.f18c.B(6);
        m(this.f19d, 0L, 10, this.f18c.p() + 10);
    }

    private void i(t tVar) {
        int iMin = Math.min(tVar.a(), this.f26k - this.f21f);
        this.f28m.a(tVar, iMin);
        int i2 = this.f21f + iMin;
        this.f21f = i2;
        int i3 = this.f26k;
        if (i2 == i3) {
            this.f28m.e(this.f27l, 1, i3, 0, null);
            this.f27l += this.f29n;
            j();
        }
    }

    private void j() {
        this.f20e = 0;
        this.f21f = 0;
        this.f22g = 256;
    }

    private void k() {
        this.f20e = 2;
        this.f21f = 0;
    }

    private void l() {
        this.f20e = 1;
        this.f21f = f16o.length;
        this.f26k = 0;
        this.f18c.B(0);
    }

    private void m(v.o oVar, long j2, int i2, int i3) {
        this.f20e = 3;
        this.f21f = i2;
        this.f28m = oVar;
        this.f29n = j2;
        this.f26k = i3;
    }

    @Override // A.e
    public void a(t tVar) {
        while (tVar.a() > 0) {
            int i2 = this.f20e;
            if (i2 == 0) {
                f(tVar);
            } else if (i2 != 1) {
                if (i2 == 2) {
                    if (e(tVar, this.f17b.f3088a, this.f23h ? 7 : 5)) {
                        g();
                    }
                } else if (i2 == 3) {
                    i(tVar);
                }
            } else if (e(tVar, this.f18c.f3092a, 10)) {
                h();
            }
        }
    }

    @Override // A.e
    public void b() {
    }

    @Override // A.e
    public void c(long j2, boolean z2) {
        this.f27l = j2;
    }

    @Override // A.e
    public void d() {
        j();
    }
}
