package defpackage;

import androidx.media3.decoder.DecoderException;
import java.util.ArrayDeque;

/* renamed from: ˀᵧᴵ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public abstract class AbstractC0588 implements InterfaceC3574 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final C2441[] f2973;

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public boolean f2974;

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public int f2975;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final AbstractC0554[] f2976;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public C2441 f2978;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final ˏᵸ f2979;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public int f2981;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public DecoderException f2983;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public boolean f2984;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public int f2985;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final Object f2982 = new Object();

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public long f2980 = -9223372036854775807L;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final ArrayDeque f2977 = new ArrayDeque();

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final ArrayDeque f2986 = new ArrayDeque();

    public AbstractC0588(C2441[] c2441Arr, AbstractC0554[] abstractC0554Arr) {
        this.f2973 = c2441Arr;
        this.f2975 = c2441Arr.length;
        for (int i = 0; i < this.f2975; i++) {
            this.f2973[i] = mo362();
        }
        this.f2976 = abstractC0554Arr;
        this.f2985 = abstractC0554Arr.length;
        for (int i2 = 0; i2 < this.f2985; i2++) {
            this.f2976[i2] = mo366();
        }
        ˏᵸ r4 = new ˏᵸ(this);
        this.f2979 = r4;
        r4.start();
    }

    @Override // defpackage.InterfaceC3574
    public final void flush() {
        synchronized (this.f2982) {
            try {
                this.f2984 = true;
                this.f2981 = 0;
                C2441 c2441 = this.f2978;
                if (c2441 != null) {
                    c2441.mo6221();
                    C2441[] c2441Arr = this.f2973;
                    int i = this.f2975;
                    this.f2975 = i + 1;
                    c2441Arr[i] = c2441;
                    this.f2978 = null;
                }
                while (!this.f2977.isEmpty()) {
                    C2441 c24412 = (C2441) this.f2977.removeFirst();
                    c24412.mo6221();
                    C2441[] c2441Arr2 = this.f2973;
                    int i2 = this.f2975;
                    this.f2975 = i2 + 1;
                    c2441Arr2[i2] = c24412;
                }
                while (!this.f2986.isEmpty()) {
                    ((AbstractC0554) this.f2986.removeFirst()).mo359();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // defpackage.InterfaceC3574
    /* renamed from: ˇʼʤˎ */
    public final Object mo1214() {
        C2441 c2441;
        synchronized (this.f2982) {
            try {
                DecoderException decoderException = this.f2983;
                if (decoderException != null) {
                    throw decoderException;
                }
                ᵛᵾˏ.ᵿʗᵝʽ(this.f2978 == null);
                int i = this.f2975;
                if (i == 0) {
                    c2441 = null;
                } else {
                    C2441[] c2441Arr = this.f2973;
                    int i2 = i - 1;
                    this.f2975 = i2;
                    c2441 = c2441Arr[i2];
                }
                this.f2978 = c2441;
            } catch (Throwable th) {
                throw th;
            }
        }
        return c2441;
    }

    @Override // defpackage.InterfaceC3574
    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public final AbstractC0554 mo1222() {
        synchronized (this.f2982) {
            try {
                DecoderException decoderException = this.f2983;
                if (decoderException != null) {
                    throw decoderException;
                }
                if (this.f2986.isEmpty()) {
                    return null;
                }
                return (AbstractC0554) this.f2986.removeFirst();
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ˎˏʜʾ */
    public abstract C2441 mo362();

    /* renamed from: ᵝᵵᵺ */
    public abstract DecoderException mo363(Throwable th);

    @Override // defpackage.InterfaceC3574
    /* renamed from: ᵥᵯˎ */
    public void mo364() throws InterruptedException {
        synchronized (this.f2982) {
            this.f2974 = true;
            this.f2982.notify();
        }
        try {
            this.f2979.join();
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
        }
    }

    @Override // defpackage.InterfaceC3574
    /* renamed from: ᵪʩ, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public final void mo1216(C2441 c2441) {
        synchronized (this.f2982) {
            try {
                DecoderException decoderException = this.f2983;
                if (decoderException != null) {
                    throw decoderException;
                }
                ᵛᵾˏ.ᵯٴᵦ(c2441 == this.f2978);
                this.f2977.addLast(c2441);
                if (!this.f2977.isEmpty() && this.f2985 > 0) {
                    this.f2982.notify();
                }
                this.f2978 = null;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final boolean m2469(long j) {
        boolean z;
        synchronized (this.f2982) {
            long j2 = this.f2980;
            z = j2 == -9223372036854775807L || j >= j2;
        }
        return z;
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final void m2470(AbstractC0554 abstractC0554) {
        synchronized (this.f2982) {
            abstractC0554.mo360();
            AbstractC0554[] abstractC0554Arr = this.f2976;
            int i = this.f2985;
            this.f2985 = i + 1;
            abstractC0554Arr[i] = abstractC0554;
            if (!this.f2977.isEmpty() && this.f2985 > 0) {
                this.f2982.notify();
            }
        }
    }

    @Override // defpackage.InterfaceC3574
    /* renamed from: ᵴᵳ */
    public final void mo1219(long j) {
        synchronized (this.f2982) {
            try {
                ᵛᵾˏ.ᵿʗᵝʽ(this.f2975 == this.f2973.length || this.f2984);
                this.f2980 = j;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ᵶᵷᵕ */
    public abstract DecoderException mo365(C2441 c2441, AbstractC0554 abstractC0554, boolean z);

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final boolean m2471() {
        DecoderException decoderExceptionMo363;
        synchronized (this.f2982) {
            while (!this.f2974) {
                try {
                    if (!this.f2977.isEmpty() && this.f2985 > 0) {
                        break;
                    }
                    this.f2982.wait();
                } finally {
                }
            }
            if (this.f2974) {
                return false;
            }
            C2441 c2441 = (C2441) this.f2977.removeFirst();
            AbstractC0554[] abstractC0554Arr = this.f2976;
            int i = this.f2985 - 1;
            this.f2985 = i;
            AbstractC0554 abstractC0554 = abstractC0554Arr[i];
            boolean z = this.f2984;
            this.f2984 = false;
            if (c2441.m9873(4)) {
                abstractC0554.m9874(4);
            } else {
                abstractC0554.f2897 = c2441.f9512;
                if (c2441.m9873(134217728)) {
                    abstractC0554.m9874(134217728);
                }
                if (!m2469(c2441.f9512)) {
                    abstractC0554.f2895 = true;
                }
                try {
                    decoderExceptionMo363 = mo365(c2441, abstractC0554, z);
                } catch (OutOfMemoryError e) {
                    decoderExceptionMo363 = mo363(e);
                } catch (RuntimeException e2) {
                    decoderExceptionMo363 = mo363(e2);
                }
                if (decoderExceptionMo363 != null) {
                    synchronized (this.f2982) {
                        this.f2983 = decoderExceptionMo363;
                    }
                    return false;
                }
            }
            synchronized (this.f2982) {
                try {
                    if (this.f2984) {
                        abstractC0554.mo359();
                    } else {
                        boolean z2 = abstractC0554.f2895;
                        int i2 = this.f2981;
                        if (z2) {
                            this.f2981 = i2 + 1;
                            abstractC0554.mo359();
                        } else {
                            abstractC0554.f2896 = i2;
                            this.f2981 = 0;
                            this.f2986.addLast(abstractC0554);
                        }
                    }
                    c2441.mo6221();
                    C2441[] c2441Arr = this.f2973;
                    int i3 = this.f2975;
                    this.f2975 = i3 + 1;
                    c2441Arr[i3] = c2441;
                } finally {
                }
            }
            return true;
        }
    }

    /* renamed from: ᵹᵝᵶ */
    public abstract AbstractC0554 mo366();
}
