package com.google.android.gms.internal.ads;

import android.os.HandlerThread;
import android.os.Looper;
import androidx.annotation.GuardedBy;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes2.dex */
public final class xi2 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f18443a = new Object();

    @Nullable
    @GuardedBy("lock")
    private Looper zzb = null;

    @Nullable
    @GuardedBy("lock")
    private HandlerThread zzc = null;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f18444b = 0;

    public xi2(@Nullable Looper looper) {
    }

    public final Looper a() {
        Looper looper;
        synchronized (this.f18443a) {
            try {
                if (this.zzb == null) {
                    boolean z10 = false;
                    if (this.f18444b == 0 && this.zzc == null) {
                        z10 = true;
                    }
                    ih1.b1(z10);
                    HandlerThread handlerThread = new HandlerThread("ExoPlayer:Playback", -16);
                    this.zzc = handlerThread;
                    handlerThread.start();
                    this.zzb = this.zzc.getLooper();
                }
                this.f18444b++;
                looper = this.zzb;
            } catch (Throwable th) {
                throw th;
            }
        }
        return looper;
    }

    public final void b() {
        HandlerThread handlerThread;
        synchronized (this.f18443a) {
            try {
                ih1.b1(this.f18444b > 0);
                int i10 = this.f18444b - 1;
                this.f18444b = i10;
                if (i10 == 0 && (handlerThread = this.zzc) != null) {
                    handlerThread.quit();
                    this.zzc = null;
                    this.zzb = null;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
