package E;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import b0.AbstractC0399d;
import java.io.IOException;
import n.C;
import n.C0633A;
import n.C0643i;
import n.InterfaceC0634B;
import n.x;
import n.y;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public final class b extends C implements Handler.Callback {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private final E.a f522q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private final a f523r;

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

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

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private final C0633A f526u;

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

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

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private Object f529x;

    public interface a {
        void g(Object obj);
    }

    public b(InterfaceC0634B interfaceC0634B, E.a aVar, a aVar2, Looper looper) {
        super(HttpUrl.FRAGMENT_ENCODE_SET, interfaceC0634B);
        this.f522q = (E.a) AbstractC0399d.d(aVar);
        this.f523r = (a) AbstractC0399d.d(aVar2);
        this.f524s = looper == null ? null : new Handler(looper, this);
        this.f525t = new y();
        this.f526u = new C0633A(1);
    }

    private void N(Object obj) {
        Handler handler = this.f524s;
        if (handler != null) {
            handler.obtainMessage(0, obj).sendToTarget();
        } else {
            O(obj);
        }
    }

    private void O(Object obj) {
        this.f523r.g(obj);
    }

    @Override // n.C
    protected void D(long j2, long j3, boolean z2) throws C0643i {
        if (!this.f527v && this.f529x == null) {
            this.f526u.a();
            int iK = K(j2, this.f525t, this.f526u);
            if (iK == -3) {
                C0633A c0633a = this.f526u;
                this.f528w = c0633a.f5412e;
                try {
                    this.f529x = this.f522q.b(c0633a.f5409b.array(), this.f526u.f5410c);
                } catch (IOException e2) {
                    throw new C0643i(e2);
                }
            } else if (iK == -1) {
                this.f527v = true;
            }
        }
        Object obj = this.f529x;
        if (obj == null || this.f528w > j2) {
            return;
        }
        N(obj);
        this.f529x = null;
    }

    @Override // n.C
    protected boolean F(x xVar) {
        return this.f522q.a(xVar.f5842g);
    }

    @Override // n.C
    protected void J(long j2) {
        this.f529x = null;
        this.f527v = false;
    }

    @Override // n.C, n.G
    protected long g() {
        return -3L;
    }

    @Override // android.os.Handler.Callback
    public boolean handleMessage(Message message) {
        if (message.what != 0) {
            return false;
        }
        O(message.obj);
        return true;
    }

    @Override // n.G
    protected boolean n() {
        return this.f527v;
    }

    @Override // n.G
    protected boolean o() {
        return true;
    }

    @Override // n.C, n.G
    protected void q(long j2) {
        this.f529x = null;
        super.q(j2);
    }
}
