392 lines
10 KiB
Java
392 lines
10 KiB
Java
package c.i.a.c.h2.y;
|
|
|
|
import android.net.Uri;
|
|
import androidx.annotation.Nullable;
|
|
import c.i.a.c.h2.h;
|
|
import c.i.a.c.h2.j;
|
|
import c.i.a.c.h2.l;
|
|
import c.i.a.c.h2.w;
|
|
import c.i.a.c.h2.x;
|
|
import c.i.a.c.i2.f0;
|
|
import com.airbnb.lottie.parser.AnimatableValueParser;
|
|
import com.google.android.exoplayer2.upstream.DataSourceException;
|
|
import com.google.android.exoplayer2.upstream.cache.Cache;
|
|
import java.io.IOException;
|
|
import java.io.InterruptedIOException;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
/* compiled from: CacheDataSource */
|
|
public final class c implements j {
|
|
public final Cache a;
|
|
public final j b;
|
|
@Nullable
|
|
|
|
/* renamed from: c reason: collision with root package name */
|
|
public final j f893c;
|
|
public final j d;
|
|
public final g e = a.b;
|
|
@Nullable
|
|
public final a f;
|
|
public final boolean g;
|
|
public final boolean h;
|
|
public final boolean i;
|
|
@Nullable
|
|
public Uri j;
|
|
@Nullable
|
|
public l k;
|
|
@Nullable
|
|
public j l;
|
|
public boolean m;
|
|
public long n;
|
|
public long o;
|
|
@Nullable
|
|
public h p;
|
|
public boolean q;
|
|
public boolean r;
|
|
|
|
/* renamed from: s reason: collision with root package name */
|
|
public long f894s;
|
|
public long t;
|
|
|
|
/* compiled from: CacheDataSource */
|
|
public interface a {
|
|
void a(int i);
|
|
|
|
void b(long j, long j2);
|
|
}
|
|
|
|
public c(Cache cache, @Nullable j jVar, j jVar2, @Nullable h hVar, int i, @Nullable a aVar) {
|
|
this.a = cache;
|
|
this.b = jVar2;
|
|
int i2 = g.a;
|
|
boolean z2 = false;
|
|
this.g = (i & 1) != 0;
|
|
this.h = (i & 2) != 0;
|
|
this.i = (i & 4) != 0 ? true : z2;
|
|
this.d = jVar;
|
|
this.f893c = new w(jVar, hVar);
|
|
this.f = null;
|
|
}
|
|
|
|
@Override // c.i.a.c.h2.j
|
|
public long a(l lVar) throws IOException {
|
|
a aVar;
|
|
try {
|
|
Objects.requireNonNull((a) this.e);
|
|
String str = lVar.h;
|
|
if (str == null) {
|
|
str = lVar.a.toString();
|
|
}
|
|
l.b a2 = lVar.a();
|
|
a2.h = str;
|
|
l a3 = a2.a();
|
|
this.k = a3;
|
|
Cache cache = this.a;
|
|
Uri uri = a3.a;
|
|
byte[] bArr = ((n) cache.b(str)).f900c.get("exo_redir");
|
|
Uri uri2 = null;
|
|
String str2 = bArr != null ? new String(bArr, c.i.b.a.c.f1266c) : null;
|
|
if (str2 != null) {
|
|
uri2 = Uri.parse(str2);
|
|
}
|
|
if (uri2 != null) {
|
|
uri = uri2;
|
|
}
|
|
this.j = uri;
|
|
this.n = lVar.f;
|
|
boolean z2 = true;
|
|
int i = (!this.h || !this.q) ? (!this.i || lVar.g != -1) ? -1 : 1 : 0;
|
|
if (i == -1) {
|
|
z2 = false;
|
|
}
|
|
this.r = z2;
|
|
if (z2 && (aVar = this.f) != null) {
|
|
aVar.a(i);
|
|
}
|
|
long j = lVar.g;
|
|
if (j == -1) {
|
|
if (!this.r) {
|
|
long a4 = k.a(this.a.b(str));
|
|
this.o = a4;
|
|
if (a4 != -1) {
|
|
long j2 = a4 - lVar.f;
|
|
this.o = j2;
|
|
if (j2 <= 0) {
|
|
throw new DataSourceException(0);
|
|
}
|
|
}
|
|
r(a3, false);
|
|
return this.o;
|
|
}
|
|
}
|
|
this.o = j;
|
|
r(a3, false);
|
|
return this.o;
|
|
} catch (Throwable th) {
|
|
p(th);
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // c.i.a.c.h2.j
|
|
public void close() throws IOException {
|
|
this.k = null;
|
|
this.j = null;
|
|
this.n = 0;
|
|
a aVar = this.f;
|
|
if (aVar != null && this.f894s > 0) {
|
|
aVar.b(this.a.h(), this.f894s);
|
|
this.f894s = 0;
|
|
}
|
|
try {
|
|
o();
|
|
} catch (Throwable th) {
|
|
p(th);
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
@Override // c.i.a.c.h2.j
|
|
public void d(x xVar) {
|
|
Objects.requireNonNull(xVar);
|
|
this.b.d(xVar);
|
|
this.d.d(xVar);
|
|
}
|
|
|
|
@Override // c.i.a.c.h2.j
|
|
public Map<String, List<String>> j() {
|
|
return q() ^ true ? this.d.j() : Collections.emptyMap();
|
|
}
|
|
|
|
@Override // c.i.a.c.h2.j
|
|
@Nullable
|
|
public Uri m() {
|
|
return this.j;
|
|
}
|
|
|
|
/* JADX WARNING: Unknown variable types count: 1 */
|
|
public final void o() throws IOException {
|
|
j jVar = this.l;
|
|
if (jVar != null) {
|
|
boolean z2 = false;
|
|
?? r2 = 0;
|
|
try {
|
|
jVar.close();
|
|
} finally {
|
|
this.l = r2;
|
|
this.m = z2;
|
|
h hVar = this.p;
|
|
if (hVar != null) {
|
|
this.a.i(hVar);
|
|
this.p = r2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public final void p(Throwable th) {
|
|
if (q() || (th instanceof Cache.CacheException)) {
|
|
this.q = true;
|
|
}
|
|
}
|
|
|
|
public final boolean q() {
|
|
return this.l == this.b;
|
|
}
|
|
|
|
public final void r(l lVar, boolean z2) throws IOException {
|
|
h hVar;
|
|
l lVar2;
|
|
j jVar;
|
|
String str = lVar.h;
|
|
int i = f0.a;
|
|
Uri uri = null;
|
|
if (this.r) {
|
|
hVar = null;
|
|
} else if (this.g) {
|
|
try {
|
|
hVar = this.a.f(str, this.n, this.o);
|
|
} catch (InterruptedException unused) {
|
|
Thread.currentThread().interrupt();
|
|
throw new InterruptedIOException();
|
|
}
|
|
} else {
|
|
hVar = this.a.e(str, this.n, this.o);
|
|
}
|
|
if (hVar == null) {
|
|
jVar = this.d;
|
|
l.b a2 = lVar.a();
|
|
a2.f = this.n;
|
|
a2.g = this.o;
|
|
lVar2 = a2.a();
|
|
} else if (hVar.l) {
|
|
Uri fromFile = Uri.fromFile(hVar.m);
|
|
long j = hVar.j;
|
|
long j2 = this.n - j;
|
|
long j3 = hVar.k - j2;
|
|
long j4 = this.o;
|
|
if (j4 != -1) {
|
|
j3 = Math.min(j3, j4);
|
|
}
|
|
l.b a3 = lVar.a();
|
|
a3.a = fromFile;
|
|
a3.b = j;
|
|
a3.f = j2;
|
|
a3.g = j3;
|
|
lVar2 = a3.a();
|
|
jVar = this.b;
|
|
} else {
|
|
long j5 = hVar.k;
|
|
if (j5 == -1) {
|
|
j5 = this.o;
|
|
} else {
|
|
long j6 = this.o;
|
|
if (j6 != -1) {
|
|
j5 = Math.min(j5, j6);
|
|
}
|
|
}
|
|
l.b a4 = lVar.a();
|
|
a4.f = this.n;
|
|
a4.g = j5;
|
|
lVar2 = a4.a();
|
|
jVar = this.f893c;
|
|
if (jVar == null) {
|
|
jVar = this.d;
|
|
this.a.i(hVar);
|
|
hVar = null;
|
|
}
|
|
}
|
|
this.t = (this.r || jVar != this.d) ? Long.MAX_VALUE : this.n + 102400;
|
|
if (z2) {
|
|
AnimatableValueParser.D(this.l == this.d);
|
|
if (jVar != this.d) {
|
|
try {
|
|
o();
|
|
} catch (Throwable th) {
|
|
if (!hVar.l) {
|
|
this.a.i(hVar);
|
|
}
|
|
throw th;
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
if (hVar != null && (!hVar.l)) {
|
|
this.p = hVar;
|
|
}
|
|
this.l = jVar;
|
|
this.m = lVar2.g == -1;
|
|
long a5 = jVar.a(lVar2);
|
|
m mVar = new m();
|
|
if (this.m && a5 != -1) {
|
|
this.o = a5;
|
|
m.a(mVar, this.n + a5);
|
|
}
|
|
if (!q()) {
|
|
Uri m = jVar.m();
|
|
this.j = m;
|
|
if (!lVar.a.equals(m)) {
|
|
uri = this.j;
|
|
}
|
|
if (uri == null) {
|
|
mVar.b.add("exo_redir");
|
|
mVar.a.remove("exo_redir");
|
|
} else {
|
|
String uri2 = uri.toString();
|
|
Map<String, Object> map = mVar.a;
|
|
Objects.requireNonNull(uri2);
|
|
map.put("exo_redir", uri2);
|
|
mVar.b.remove("exo_redir");
|
|
}
|
|
}
|
|
if (this.l == this.f893c) {
|
|
this.a.c(str, mVar);
|
|
}
|
|
}
|
|
|
|
@Override // c.i.a.c.h2.f
|
|
public int read(byte[] bArr, int i, int i2) throws IOException {
|
|
l lVar = this.k;
|
|
Objects.requireNonNull(lVar);
|
|
boolean z2 = false;
|
|
if (i2 == 0) {
|
|
return 0;
|
|
}
|
|
if (this.o == 0) {
|
|
return -1;
|
|
}
|
|
try {
|
|
if (this.n >= this.t) {
|
|
r(lVar, true);
|
|
}
|
|
j jVar = this.l;
|
|
Objects.requireNonNull(jVar);
|
|
int read = jVar.read(bArr, i, i2);
|
|
if (read != -1) {
|
|
if (q()) {
|
|
this.f894s += (long) read;
|
|
}
|
|
long j = (long) read;
|
|
this.n += j;
|
|
long j2 = this.o;
|
|
if (j2 != -1) {
|
|
this.o = j2 - j;
|
|
}
|
|
} else if (this.m) {
|
|
String str = lVar.h;
|
|
int i3 = f0.a;
|
|
s(str);
|
|
} else {
|
|
long j3 = this.o;
|
|
if (j3 <= 0) {
|
|
if (j3 == -1) {
|
|
}
|
|
}
|
|
o();
|
|
r(lVar, false);
|
|
return read(bArr, i, i2);
|
|
}
|
|
return read;
|
|
} catch (IOException e) {
|
|
if (this.m) {
|
|
int i4 = DataSourceException.i;
|
|
Throwable th = e;
|
|
while (true) {
|
|
if (th != null) {
|
|
if ((th instanceof DataSourceException) && ((DataSourceException) th).reason == 0) {
|
|
z2 = true;
|
|
break;
|
|
}
|
|
th = th.getCause();
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
if (z2) {
|
|
String str2 = lVar.h;
|
|
int i5 = f0.a;
|
|
s(str2);
|
|
return -1;
|
|
}
|
|
}
|
|
p(e);
|
|
throw e;
|
|
} catch (Throwable th2) {
|
|
p(th2);
|
|
throw th2;
|
|
}
|
|
}
|
|
|
|
public final void s(String str) throws IOException {
|
|
this.o = 0;
|
|
if (this.l == this.f893c) {
|
|
m mVar = new m();
|
|
m.a(mVar, this.n);
|
|
this.a.c(str, mVar);
|
|
}
|
|
}
|
|
}
|