package defpackage;

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

/* JADX INFO: renamed from: ᵧᵘʒ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC3661 implements InterfaceC0820 {

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public int f13885;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public int f13888;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final C3008[] f13889;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public boolean f13890;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public DecoderException f13891;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final ᵼʾᵯ f13892;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public int f13893;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public boolean f13894;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public C3008 f13896;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final AbstractC4189[] f13897;

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final Object f13884 = new Object();

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public long f13886 = -9223372036854775807L;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final ArrayDeque f13887 = new ArrayDeque();

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final ArrayDeque f13895 = new ArrayDeque();

    public AbstractC3661(C3008[] c3008Arr, AbstractC4189[] abstractC4189Arr) {
        this.f13889 = c3008Arr;
        this.f13893 = c3008Arr.length;
        for (int i = 0; i < this.f13893; i++) {
            this.f13889[i] = mo365();
        }
        this.f13897 = abstractC4189Arr;
        this.f13885 = abstractC4189Arr.length;
        for (int i2 = 0; i2 < this.f13885; i2++) {
            this.f13897[i2] = mo361();
        }
        ᵼʾᵯ r4 = new ᵼʾᵯ(this);
        this.f13892 = r4;
        r4.start();
    }

    @Override // defpackage.InterfaceC0820
    public final void flush() {
        synchronized (this.f13884) {
            try {
                this.f13894 = true;
                this.f13888 = 0;
                C3008 c3008 = this.f13896;
                if (c3008 != null) {
                    c3008.mo7091();
                    C3008[] c3008Arr = this.f13889;
                    int i = this.f13893;
                    this.f13893 = i + 1;
                    c3008Arr[i] = c3008;
                    this.f13896 = null;
                }
                while (!this.f13887.isEmpty()) {
                    C3008 c30082 = (C3008) this.f13887.removeFirst();
                    c30082.mo7091();
                    C3008[] c3008Arr2 = this.f13889;
                    int i2 = this.f13893;
                    this.f13893 = i2 + 1;
                    c3008Arr2[i2] = c30082;
                }
                while (!this.f13895.isEmpty()) {
                    ((AbstractC4189) this.f13895.removeFirst()).mo359();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ʽˈˋ */
    public final void mo2935(long j) {
        synchronized (this.f13884) {
            try {
                ᵻᵪ.ˌᴵ(this.f13893 == this.f13889.length || this.f13894);
                this.f13886 = j;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX INFO: renamed from: ˊᵫᵗ */
    public abstract AbstractC4189 mo361();

    @Override // defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public final void mo2938(C3008 c3008) {
        synchronized (this.f13884) {
            try {
                DecoderException decoderException = this.f13891;
                if (decoderException != null) {
                    throw decoderException;
                }
                ᵻᵪ.ᵱᵽʡᵚ(c3008 == this.f13896);
                this.f13887.addLast(c3008);
                if (!this.f13887.isEmpty() && this.f13885 > 0) {
                    this.f13884.notify();
                }
                this.f13896 = null;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final boolean m8251(long j) {
        boolean z;
        synchronized (this.f13884) {
            long j2 = this.f13886;
            z = j2 == -9223372036854775807L || j >= j2;
        }
        return z;
    }

    @Override // defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ᵨᵣ */
    public final Object mo2936() {
        C3008 c3008;
        synchronized (this.f13884) {
            try {
                DecoderException decoderException = this.f13891;
                if (decoderException != null) {
                    throw decoderException;
                }
                ᵻᵪ.ˌᴵ(this.f13896 == null);
                int i = this.f13893;
                if (i == 0) {
                    c3008 = null;
                } else {
                    C3008[] c3008Arr = this.f13889;
                    int i2 = i - 1;
                    this.f13893 = i2;
                    c3008 = c3008Arr[i2];
                }
                this.f13896 = c3008;
            } catch (Throwable th) {
                throw th;
            }
        }
        return c3008;
    }

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public final void m8252(AbstractC4189 abstractC4189) {
        synchronized (this.f13884) {
            abstractC4189.mo360();
            AbstractC4189[] abstractC4189Arr = this.f13897;
            int i = this.f13885;
            this.f13885 = i + 1;
            abstractC4189Arr[i] = abstractC4189;
            if (!this.f13887.isEmpty() && this.f13885 > 0) {
                this.f13884.notify();
            }
        }
    }

    @Override // defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters and merged with bridge method [inline-methods] */
    public final AbstractC4189 mo2937() {
        synchronized (this.f13884) {
            try {
                DecoderException decoderException = this.f13891;
                if (decoderException != null) {
                    throw decoderException;
                }
                if (this.f13895.isEmpty()) {
                    return null;
                }
                return (AbstractC4189) this.f13895.removeFirst();
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ */
    public abstract DecoderException mo363(C3008 c3008, AbstractC4189 abstractC4189, boolean z);

    @Override // defpackage.InterfaceC0820
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public void mo364() {
        synchronized (this.f13884) {
            this.f13890 = true;
            this.f13884.notify();
        }
        try {
            this.f13892.join();
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
        }
    }

    /* JADX INFO: renamed from: ᵵᵽ */
    public abstract C3008 mo365();

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final boolean m8254() {
        DecoderException decoderExceptionMo366;
        synchronized (this.f13884) {
            while (!this.f13890) {
                try {
                    if (!this.f13887.isEmpty() && this.f13885 > 0) {
                        break;
                    }
                    this.f13884.wait();
                } finally {
                }
            }
            if (this.f13890) {
                return false;
            }
            C3008 c3008 = (C3008) this.f13887.removeFirst();
            AbstractC4189[] abstractC4189Arr = this.f13897;
            int i = this.f13885 - 1;
            this.f13885 = i;
            AbstractC4189 abstractC4189 = abstractC4189Arr[i];
            boolean z = this.f13894;
            this.f13894 = false;
            if (c3008.m6278(4)) {
                abstractC4189.m6277(4);
            } else {
                abstractC4189.f15983 = c3008.f11577;
                if (c3008.m6278(134217728)) {
                    abstractC4189.m6277(134217728);
                }
                if (!m8251(c3008.f11577)) {
                    abstractC4189.f15985 = true;
                }
                try {
                    decoderExceptionMo366 = mo363(c3008, abstractC4189, z);
                } catch (OutOfMemoryError e) {
                    decoderExceptionMo366 = mo366(e);
                } catch (RuntimeException e2) {
                    decoderExceptionMo366 = mo366(e2);
                }
                if (decoderExceptionMo366 != null) {
                    synchronized (this.f13884) {
                        this.f13891 = decoderExceptionMo366;
                    }
                    return false;
                }
            }
            synchronized (this.f13884) {
                try {
                    if (this.f13894) {
                        abstractC4189.mo359();
                    } else {
                        boolean z2 = abstractC4189.f15985;
                        int i2 = this.f13888;
                        if (z2) {
                            this.f13888 = i2 + 1;
                            abstractC4189.mo359();
                        } else {
                            abstractC4189.f15984 = i2;
                            this.f13888 = 0;
                            this.f13895.addLast(abstractC4189);
                        }
                    }
                    c3008.mo7091();
                    C3008[] c3008Arr = this.f13889;
                    int i3 = this.f13893;
                    this.f13893 = i3 + 1;
                    c3008Arr[i3] = c3008;
                } finally {
                }
            }
            return true;
        }
    }

    /* JADX INFO: renamed from: ᵻʽᵯ */
    public abstract DecoderException mo366(Throwable th);
}
