package com.google.android.exoplayer2.source;

import android.net.Uri;
import com.google.android.exoplayer2.c.b;
import com.google.android.exoplayer2.c.k;
import com.google.android.exoplayer2.h.f;
import com.google.android.exoplayer2.h.i;
import com.google.android.exoplayer2.h.s.c;
import com.google.android.exoplayer2.i.a;
import com.google.android.exoplayer2.i.e;
import com.google.android.exoplayer2.i.v;
import com.tencent.matrix.trace.core.AppMethodBeat;

final class f$a implements c {
    private final f aSF;
    private final f$b bgJ;
    private final e bgK;
    long bgY = -1;
    final /* synthetic */ f bhd;
    private final k bhe = new k();
    private volatile boolean bhf;
    private boolean bhg = true;
    private long bhh;
    private final Uri uri;

    public f$a(f fVar, Uri uri, f fVar2, f$b f_b, e eVar) {
        this.bhd = fVar;
        AppMethodBeat.i(95480);
        this.uri = (Uri) a.checkNotNull(uri);
        this.aSF = (f) a.checkNotNull(fVar2);
        this.bgJ = (f$b) a.checkNotNull(f_b);
        this.bgK = eVar;
        AppMethodBeat.o(95480);
    }

    public final void j(long j, long j2) {
        this.bhe.position = j;
        this.bhh = j2;
        this.bhg = true;
    }

    public final void se() {
        this.bhf = true;
    }

    public final boolean sf() {
        return this.bhf;
    }

    public final void sg() {
        Throwable th;
        com.google.android.exoplayer2.c.f fVar;
        AppMethodBeat.i(95481);
        int i = 0;
        while (i == 0 && !this.bhf) {
            int a;
            try {
                long j = this.bhe.position;
                this.bgY = this.aSF.a(new i(this.uri, j, -1, this.bhd.bgG));
                if (this.bgY != -1) {
                    this.bgY += j;
                }
                b bVar = new b(this.aSF, j, this.bgY);
                try {
                    int i2;
                    com.google.android.exoplayer2.c.e a2 = this.bgJ.a(bVar, this.aSF.getUri());
                    if (this.bhg) {
                        a2.g(j, this.bhh);
                        this.bhg = false;
                    }
                    int i3 = i;
                    while (i3 == 0) {
                        try {
                            if (this.bhf) {
                                break;
                            }
                            this.bgK.block();
                            a = a2.a(bVar, this.bhe);
                            try {
                                if (bVar.getPosition() > this.bhd.bgH + j) {
                                    j = bVar.getPosition();
                                    this.bgK.tw();
                                    this.bhd.handler.post(this.bhd.bgM);
                                    i3 = a;
                                } else {
                                    i3 = a;
                                }
                            } catch (Throwable th2) {
                                th = th2;
                                fVar = bVar;
                                this.bhe.position = fVar.getPosition();
                                v.a(this.aSF);
                                AppMethodBeat.o(95481);
                                throw th;
                            }
                        } catch (Throwable th3) {
                            th = th3;
                            fVar = bVar;
                            a = i3;
                            this.bhe.position = fVar.getPosition();
                            v.a(this.aSF);
                            AppMethodBeat.o(95481);
                            throw th;
                        }
                    }
                    if (i3 == 1) {
                        i2 = 0;
                    } else {
                        this.bhe.position = bVar.getPosition();
                        i2 = i3;
                    }
                    v.a(this.aSF);
                    i = i2;
                } catch (Throwable th22) {
                    th = th22;
                    fVar = bVar;
                    a = i;
                    this.bhe.position = fVar.getPosition();
                    v.a(this.aSF);
                    AppMethodBeat.o(95481);
                    throw th;
                }
            } catch (Throwable th4) {
                th = th4;
                fVar = null;
                a = i;
                if (!(a == 1 || fVar == null)) {
                    this.bhe.position = fVar.getPosition();
                }
                v.a(this.aSF);
                AppMethodBeat.o(95481);
                throw th;
            }
        }
        AppMethodBeat.o(95481);
    }
}
