package defpackage;

import android.content.Context;
import android.content.IntentFilter;
import android.media.AudioAttributes;
import android.media.AudioDeviceInfo;
import android.media.AudioFormat;
import android.media.AudioTrack;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import androidx.media3.exoplayer.audio.AudioOutputProvider$InitializationException;
import j$.util.Objects;

/* renamed from: ᐧﹶ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2171 implements InterfaceC3601 {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final float f8564;

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

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public C5128 f8566;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C3086 f8567;

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

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final Context f8569;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final ʾᵠᵦ f8570;

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

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public Context f8572;

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

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final C2931 f8574;

    public C2171(C1332 c1332) {
        Context context = c1332.f5486;
        this.f8569 = context;
        C3086 c3086 = c1332.f5487;
        c3086.getClass();
        this.f8567 = c3086;
        this.f8570 = c1332.f5485;
        this.f8573 = c1332.f5488;
        this.f8574 = context == null ? null : new C2931(this);
        this.f8564 = c1332.f5484;
        this.f8565 = C1875.f7592;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m5804(C3151 c3151) {
        Context context;
        C3303 c3303M7692;
        AudioDeviceInfo audioDeviceInfo = c3151.f11967;
        C1028 c1028 = c3151.f11969;
        m5807();
        C0744 c0744 = this.f8568;
        if (c0744 == null && (context = this.f8569) != null) {
            C0744 c07442 = new C0744(context, new ʾᵛ(1, this), c1028, audioDeviceInfo);
            this.f8568 = c07442;
            Handler handler = (Handler) c07442.f3580;
            Context context2 = (Context) c07442.f3576;
            if (c07442.f3575) {
                c3303M7692 = (C3303) c07442.f3574;
                c3303M7692.getClass();
            } else {
                c07442.f3575 = true;
                C0303 c0303 = (C0303) c07442.f3571;
                if (c0303 != null) {
                    c0303.f1938.registerContentObserver(c0303.f1939, false, c0303);
                }
                AbstractC4618.m9787(context2).registerAudioDeviceCallback((C0350) c07442.f3570, handler);
                if (Build.VERSION.SDK_INT >= 32 && ((C1434) c07442.f3579) == null) {
                    c07442.f3579 = new C1434(context2, new RunnableC3566(5, c07442), Boolean.valueOf(AbstractC3558.m8147(context2)));
                }
                c3303M7692 = C3303.m7692(context2, context2.registerReceiver((C2481) c07442.f3572, new IntentFilter("android.media.action.HDMI_AUDIO_PLUG"), null, handler), (C1028) c07442.f3578, (AudioDeviceInfo) c07442.f3577, c07442.m2809());
                c07442.f3574 = c3303M7692;
            }
            this.f8573 = c3303M7692;
        } else if (c0744 != null) {
            if (audioDeviceInfo != null && !audioDeviceInfo.equals((AudioDeviceInfo) c0744.f3577)) {
                c0744.f3577 = audioDeviceInfo;
                c0744.m2811(C3303.m7694((Context) c0744.f3576, (C1028) c0744.f3578, audioDeviceInfo, c0744.m2809()));
            }
            C0744 c07443 = this.f8568;
            if (!Objects.equals(c1028, (C1028) c07443.f3578)) {
                c07443.f3578 = c1028;
                c07443.m2811(C3303.m7694((Context) c07443.f3576, c1028, (AudioDeviceInfo) c07443.f3577, c07443.m2809()));
            }
        }
        this.f8573.getClass();
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final C2361 m5805(C1091 c1091) throws UnsupportedOperationException, AudioOutputProvider$InitializationException, IllegalArgumentException {
        Context context;
        Context context2;
        try {
            int i = c1091.f4701;
            int i2 = c1091.f4696;
            if (i2 == -1 || (context2 = this.f8569) == null || Build.VERSION.SDK_INT < 34) {
                context = null;
            } else {
                Context context3 = this.f8572;
                if (context3 == null || context3.getDeviceId() != i2) {
                    this.f8572 = context2.createDeviceContext(i2);
                }
                context = this.f8572;
                i = 0;
            }
            try {
                AudioTrack.Builder sessionId = new AudioTrack.Builder().setAudioAttributes(c1091.f4702 ? new AudioAttributes.Builder().setContentType(3).setFlags(16).setUsage(1).build() : c1091.f4693.m3392()).setAudioFormat(new AudioFormat.Builder().setSampleRate(c1091.f4698).setChannelMask(c1091.f4695).setEncoding(c1091.f4697).build()).setTransferMode(1).setBufferSizeInBytes(c1091.f4694).setSessionId(i);
                int i3 = Build.VERSION.SDK_INT;
                if (i3 >= 29) {
                    sessionId.setOffloadedPlayback(c1091.f4692);
                }
                if (i3 >= 34 && context != null) {
                    sessionId.setContext(context);
                }
                AudioTrack audioTrackBuild = sessionId.build();
                if (audioTrackBuild.getState() == 1) {
                    return new C2361(audioTrackBuild, c1091, this.f8574, this.f8564, this.f8565);
                }
                try {
                    audioTrackBuild.release();
                } catch (Exception unused) {
                }
                throw new AudioOutputProvider$InitializationException();
            } catch (IllegalArgumentException e) {
                e = e;
                throw new AudioOutputProvider$InitializationException(e);
            }
        } catch (IllegalArgumentException | UnsupportedOperationException e2) {
            e = e2;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x008a  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x008e  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0165  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0167  */
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final defpackage.C1091 m5806(defpackage.C3151 r24) {
        /*
            Method dump skipped, instructions count: 400
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: defpackage.C2171.m5806(ᵠᵯˊˋ):ˈᵩᵜ");
    }

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final void m5807() {
        if (this.f8569 == null) {
            return;
        }
        Looper looperMyLooper = Looper.myLooper();
        Looper looper = this.f8571;
        boolean z = looper == null || looper == looperMyLooper;
        String name = looper == null ? "null" : looper.getThread().getName();
        String name2 = looperMyLooper != null ? looperMyLooper.getThread().getName() : "null";
        if (z) {
            this.f8571 = looperMyLooper;
        } else {
            ᵹˉᵞ.ᵳٴᵶ(ˊˉʤﹳ.ˁˑᵰ("AudioTrackAudioOutputProvider accessed on multiple threads: %s and %s", new Object[]{name, name2}));
        }
    }
}
