package o;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioAttributes;
import android.media.AudioFormat;
import android.media.AudioTrack;
import android.util.Log;
import b0.D;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.util.ArrayList;
import java.util.Arrays;
import n.AbstractC0637c;
import n.x;

/* JADX INFO: renamed from: o.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0648b {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final C0648b f5872c = new C0648b(new int[]{2}, 2);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static boolean f5873d = true;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static boolean f5874e = true;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static boolean f5875f = true;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static boolean f5876g = true;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final int[] f5877a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final int f5878b;

    C0648b(int[] iArr, int i2) {
        if (iArr != null) {
            int[] iArrCopyOf = Arrays.copyOf(iArr, iArr.length);
            this.f5877a = iArrCopyOf;
            Arrays.sort(iArrCopyOf);
        } else {
            this.f5877a = new int[0];
        }
        this.f5878b = i2;
    }

    public static void a() {
        f5876g = true;
    }

    public static C0648b b(Context context) {
        int i2 = 1;
        try {
            i2 = Integer.parseInt(D.y("vendor.mtk.exoplayer.enable.passthrough", "1"));
            Log.i("AudioCapabilities", "ENABLE_PASSTHROUGH:" + i2);
        } catch (NumberFormatException e2) {
            Log.e("AudioCapabilities", "Invalid passthrough mode string. " + e2.toString());
        }
        if (i2 == 0) {
            f5876g = false;
        }
        if (!f5876g || (!f5873d && !f5874e && !f5875f)) {
            return c(context.registerReceiver(null, new IntentFilter("android.media.action.HDMI_AUDIO_PLUG")));
        }
        ArrayList arrayList = new ArrayList();
        if (f5873d) {
            arrayList.add(6);
            arrayList.add(5);
            arrayList.add(2);
        }
        if (f5874e) {
            arrayList.add(7);
            arrayList.add(8);
        }
        arrayList.add(Integer.valueOf(AbstractC0637c.f5496c));
        if (f5875f) {
            arrayList.add(10);
            arrayList.add(11);
            arrayList.add(12);
        }
        arrayList.add(18);
        arrayList.add(Integer.valueOf(AbstractC0637c.f5497d));
        arrayList.add(14);
        if (b0.n.c()) {
            arrayList.add(Integer.valueOf(AbstractC0637c.f5499f));
            arrayList.add(9);
        }
        Integer[] numArr = (Integer[]) arrayList.toArray(new Integer[arrayList.size()]);
        int[] iArr = new int[numArr.length];
        for (int i3 = 0; i3 < numArr.length; i3++) {
            iArr[i3] = numArr[i3].intValue();
        }
        return new C0648b(iArr, 12);
    }

    static C0648b c(Intent intent) {
        return (intent == null || intent.getIntExtra("android.media.extra.AUDIO_PLUG_STATE", 0) == 0) ? f5872c : new C0648b(intent.getIntArrayExtra("android.media.extra.ENCODINGS"), intent.getIntExtra("android.media.extra.MAX_CHANNEL_COUNT", 0));
    }

    public static boolean d(x xVar, boolean z2) {
        int i2;
        int iP;
        int iT;
        AudioFormat audioFormatBuild;
        if (xVar == null) {
            return false;
        }
        int i3 = -1;
        try {
            iP = j.P(xVar.f5840e0, xVar.f5842g);
        } catch (Exception e2) {
            e = e2;
            i2 = -1;
        }
        try {
            iT = e(xVar.f5842g) ? j.t(xVar.f5842g, -1) : 2;
            audioFormatBuild = new AudioFormat.Builder().setChannelMask(iP).setEncoding(iT).setSampleRate(xVar.f5841f0).build();
        } catch (Exception e3) {
            e = e3;
            i2 = -1;
            i3 = iP;
            Log.d("AudioCapabilities", e.toString());
            int i4 = i2;
            iP = i3;
            iT = i4;
        }
        if (D.f2965a >= 29 && z2) {
            if (AudioTrack.isDirectPlaybackSupported(audioFormatBuild, new AudioAttributes.Builder().setUsage(1).setContentType(2).setFlags(16).build())) {
                return true;
            }
            Log.d("AudioCapabilities", "Tunnel playback not supported, config(" + iT + ", " + iP + ", " + xVar.f5841f0 + ")");
            return false;
        }
        AudioTrack audioTrackBuild = new AudioTrack.Builder().setAudioFormat(audioFormatBuild).setAudioAttributes(new AudioAttributes.Builder().setLegacyStreamType(3).build()).setTransferMode(1).setBufferSizeInBytes(32768).build();
        if (audioTrackBuild != null) {
            audioTrackBuild.release();
            return true;
        }
        Log.d("AudioCapabilities", "Direct playback not supported, config(" + iT + ", " + iP + ", " + xVar.f5841f0 + ")");
        return false;
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    public static boolean e(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }
        byte b2 = -1;
        switch (str.hashCode()) {
            case -2123537834:
                if (str.equals("audio/eac3-joc")) {
                    b2 = 0;
                }
                break;
            case -2122938134:
                if (str.equals("audio/mp4a-latm-hw")) {
                    b2 = 1;
                }
                break;
            case -1365340241:
                if (str.equals("audio/vnd.dts.hd;profile=lbr")) {
                    b2 = 2;
                }
                break;
            case -1095064472:
                if (str.equals("audio/vnd.dts")) {
                    b2 = 3;
                }
                break;
            case -53558318:
                if (str.equals("audio/mp4a-latm")) {
                    b2 = 4;
                }
                break;
            case 187078296:
                if (str.equals("audio/ac3")) {
                    b2 = 5;
                }
                break;
            case 187078297:
                if (str.equals("audio/ac4")) {
                    b2 = 6;
                }
                break;
            case 187081690:
                if (str.equals("audio/dra")) {
                    b2 = 7;
                }
                break;
            case 1382920842:
                if (str.equals("audio/ac4-joc")) {
                    b2 = 8;
                }
                break;
            case 1504578661:
                if (str.equals("audio/eac3")) {
                    b2 = 9;
                }
                break;
            case 1504823652:
                if (str.equals("audio/mha1")) {
                    b2 = 10;
                }
                break;
            case 1504824024:
                if (str.equals("audio/mhm1")) {
                    b2 = SDKKeyboardCode.FUNCTION_KEY_BOARD_H;
                }
                break;
            case 1505942594:
                if (str.equals("audio/vnd.dts.hd")) {
                    b2 = SDKKeyboardCode.FUNCTION_KEY_BOARD_I;
                }
                break;
            case 1556697186:
                if (str.equals("audio/true-hd")) {
                    b2 = SDKKeyboardCode.FUNCTION_KEY_BOARD_J;
                }
                break;
        }
        switch (b2) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
                return true;
            default:
                return false;
        }
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof C0648b)) {
            return false;
        }
        C0648b c0648b = (C0648b) obj;
        return Arrays.equals(this.f5877a, c0648b.f5877a) && this.f5878b == c0648b.f5878b;
    }

    public boolean f(int i2) {
        return Arrays.binarySearch(this.f5877a, i2) >= 0;
    }

    public int hashCode() {
        return this.f5878b + (Arrays.hashCode(this.f5877a) * 31);
    }

    public String toString() {
        return "AudioCapabilities[maxChannelCount=" + this.f5878b + ", supportedEncodings=" + Arrays.toString(this.f5877a) + "]";
    }
}
