package z0;

import a0.n;
import a0.r;
import android.util.Log;
import b0.D;
import b0.o;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import k1.Y;

/* JADX INFO: renamed from: z0.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0753d implements r.c {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private static int f7147h;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private C0750a f7148a;

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private volatile boolean f7151d;

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

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

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

    public C0753d(InputStream inputStream, n.b bVar, long j2, long j3) {
        ReentrantLock reentrantLock = new ReentrantLock();
        this.f7149b = reentrantLock;
        this.f7150c = reentrantLock.newCondition();
        this.f7154g = inputStream;
        if (inputStream instanceof Y) {
            this.f7148a = new C0750a(inputStream, bVar, j2, 1);
        } else {
            Log.e("DLNAStreamLoadable", "Not expected network type");
            this.f7148a = new C0750a(inputStream, bVar, j2, 1);
        }
    }

    public int a(long j2, byte[] bArr, int i2) {
        long jCurrentTimeMillis = System.currentTimeMillis();
        synchronized (this) {
            try {
                int iJ = this.f7148a.j(j2, bArr, i2);
                o.d("DLNAStreamLoadable", "readAt-, return " + iJ + ", spendTime(ms) = " + (System.currentTimeMillis() - jCurrentTimeMillis), 64);
                this.f7152e = iJ;
                if (iJ >= 0) {
                    return iJ;
                }
                this.f7149b.lock();
                this.f7150c.signal();
                this.f7149b.unlock();
                return this.f7152e;
            } catch (Exception unused) {
                D.h(this.f7154g);
                return this.f7152e;
            }
        }
    }

    public void b(long j2) {
        Log.d("DLNAStreamLoadable", "seekTo(Us): " + j2);
        if (f7147h != 1) {
            Log.d("DLNAStreamLoadable", "skip seekTo");
            return;
        }
        Log.d("DLNAStreamLoadable", "Loadable_FLG_DMR");
        if (this.f7153f == 2) {
            boolean z2 = this.f7154g instanceof Y;
        }
    }

    @Override // a0.r.c
    public final boolean m() {
        return this.f7151d;
    }

    @Override // a0.r.c
    public final void q() throws IOException {
        Log.d("DLNAStreamLoadable", "load");
        this.f7148a.p();
        try {
            try {
                this.f7149b.lock();
                this.f7150c.await();
                this.f7149b.unlock();
                if (this.f7152e != -2) {
                    return;
                }
                Log.e("DLNAStreamLoadable", "loaderResult == STATUS_DMS_BUSY.");
                throw new IOException("dms busy");
            } catch (Exception e2) {
                Log.e("DLNAStreamLoadable", "Exception: load(), ex: " + e2.getMessage());
                this.f7149b.unlock();
                if (this.f7152e != -2) {
                    return;
                }
                Log.e("DLNAStreamLoadable", "loaderResult == STATUS_DMS_BUSY.");
                throw new IOException("dms busy");
            }
        } catch (Throwable th) {
            this.f7149b.unlock();
            if (this.f7152e != -2) {
                throw th;
            }
            Log.e("DLNAStreamLoadable", "loaderResult == STATUS_DMS_BUSY.");
            throw new IOException("dms busy");
        }
    }

    @Override // a0.r.c
    public final void u() {
        Log.d("DLNAStreamLoadable", "cancelLoad");
        this.f7151d = true;
        this.f7149b.lock();
        this.f7148a.i();
        this.f7150c.signal();
        this.f7149b.unlock();
    }
}
