package com.applovin.impl; import com.applovin.impl.b5; import java.util.ArrayList; import java.util.Collections; /* loaded from: classes.dex */ public final class qf extends ek { private final bh o; public qf() { super("Mp4WebvttDecoder"); this.o = new bh(); } @Override // com.applovin.impl.ek public nl a(byte[] bArr, int i, boolean z) { this.o.a(bArr, i); ArrayList arrayList = new ArrayList(); while (this.o.a() > 0) { if (this.o.a() >= 8) { int j = this.o.j(); if (this.o.j() == 1987343459) { arrayList.add(a(this.o, j - 8)); } else { this.o.g(j - 8); } } else { throw new pl("Incomplete Mp4Webvtt Top Level box header found."); } } return new rf(arrayList); } private static b5 a(bh bhVar, int i) { CharSequence charSequence = null; b5.b bVar = null; while (i > 0) { if (i >= 8) { int j = bhVar.j(); int j2 = bhVar.j(); int i2 = j - 8; String a = xp.a(bhVar.c(), bhVar.d(), i2); bhVar.g(i2); i = (i - 8) - i2; if (j2 == 1937011815) { bVar = xr.c(a); } else if (j2 == 1885436268) { charSequence = xr.a((String) null, a.trim(), Collections.emptyList()); } } else { throw new pl("Incomplete vtt cue box header found."); } } if (charSequence == null) { charSequence = ""; } if (bVar != null) { return bVar.a(charSequence).a(); } return xr.a(charSequence); } }