package I0;

import Q4.Y;
import Z6.AbstractC0385z;
import android.media.MediaCodec;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import java.util.concurrent.atomic.AtomicReference;
import n4.u0;

/* JADX INFO: loaded from: classes.dex */
public final class e extends Handler {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f3197a = 1;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f3198b;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public e(E6.i iVar) {
        super(Looper.getMainLooper());
        P6.g.e(iVar, "backgroundDispatcher");
        this.f3198b = iVar;
    }

    @Override // android.os.Handler
    public final void handleMessage(Message message) {
        String string;
        switch (this.f3197a) {
            case u0.f15495q /* 0 */:
                g gVar = (g) this.f3198b;
                gVar.getClass();
                int i = message.what;
                f fVar = null;
                if (i == 1) {
                    f fVar2 = (f) message.obj;
                    try {
                        gVar.f3206a.queueInputBuffer(fVar2.f3199a, 0, fVar2.f3200b, fVar2.f3202d, fVar2.f3203e);
                        break;
                    } catch (RuntimeException e8) {
                        AtomicReference atomicReference = gVar.f3209d;
                        while (!atomicReference.compareAndSet(null, e8) && atomicReference.get() == null) {
                        }
                    }
                    fVar = fVar2;
                } else if (i == 2) {
                    f fVar3 = (f) message.obj;
                    int i5 = fVar3.f3199a;
                    MediaCodec.CryptoInfo cryptoInfo = fVar3.f3201c;
                    long j8 = fVar3.f3202d;
                    int i8 = fVar3.f3203e;
                    try {
                        synchronized (g.f3205h) {
                            gVar.f3206a.queueSecureInputBuffer(i5, 0, cryptoInfo, j8, i8);
                            break;
                        }
                    } catch (RuntimeException e9) {
                        AtomicReference atomicReference2 = gVar.f3209d;
                        while (!atomicReference2.compareAndSet(null, e9) && atomicReference2.get() == null) {
                        }
                    }
                    fVar = fVar3;
                } else if (i == 3) {
                    gVar.f3210e.f();
                } else if (i != 4) {
                    AtomicReference atomicReference3 = gVar.f3209d;
                    IllegalStateException illegalStateException = new IllegalStateException(String.valueOf(message.what));
                    while (!atomicReference3.compareAndSet(null, illegalStateException) && atomicReference3.get() == null) {
                    }
                } else {
                    try {
                        gVar.f3206a.setParameters((Bundle) message.obj);
                        break;
                    } catch (RuntimeException e10) {
                        AtomicReference atomicReference4 = gVar.f3209d;
                        while (!atomicReference4.compareAndSet(null, e10) && atomicReference4.get() == null) {
                        }
                    }
                }
                if (fVar != null) {
                    g.e(fVar);
                    return;
                }
                return;
            default:
                P6.g.e(message, "msg");
                if (message.what != 3) {
                    Log.w("SessionLifecycleClient", "Received unexpected event from the SessionLifecycleService: " + message);
                    super.handleMessage(message);
                    return;
                }
                Bundle data = message.getData();
                if (data == null || (string = data.getString("SessionUpdateExtra")) == null) {
                    string = "";
                }
                Log.d("SessionLifecycleClient", "Session update received.");
                AbstractC0385z.r(AbstractC0385z.b((E6.i) this.f3198b), null, new Y(string, null), 3);
                return;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public e(g gVar, Looper looper) {
        super(looper);
        this.f3198b = gVar;
    }
}
