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

import android.util.Base64;
import androidx.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public abstract class y3 {
    public static int a(int i10) {
        int i11 = 0;
        while (i10 > 0) {
            i10 >>>= 1;
            i11++;
        }
        return i11;
    }

    public static w3 b(p01 p01Var, boolean z10, boolean z11) throws zzat {
        if (z10) {
            c(3, p01Var, false);
        }
        p01Var.k((int) p01Var.a(), StandardCharsets.UTF_8);
        long jA = p01Var.a();
        String[] strArr = new String[(int) jA];
        for (int i10 = 0; i10 < jA; i10++) {
            strArr[i10] = p01Var.k((int) p01Var.a(), StandardCharsets.UTF_8);
        }
        if (z11 && (p01Var.I() & 1) == 0) {
            throw zzat.zzb("framing bit expected to be set", null);
        }
        return new w3(strArr);
    }

    public static boolean c(int i10, p01 p01Var, boolean z10) throws zzat {
        if (p01Var.y() < 7) {
            if (z10) {
                return false;
            }
            int iY = p01Var.y();
            StringBuilder sb = new StringBuilder(String.valueOf(iY).length() + 18);
            sb.append("too short header: ");
            sb.append(iY);
            throw zzat.zzb(sb.toString(), null);
        }
        if (p01Var.I() != i10) {
            if (z10) {
                return false;
            }
            throw zzat.zzb("expected header type ".concat(String.valueOf(Integer.toHexString(i10))), null);
        }
        if (p01Var.I() == 118 && p01Var.I() == 111 && p01Var.I() == 114 && p01Var.I() == 98 && p01Var.I() == 105 && p01Var.I() == 115) {
            return true;
        }
        if (z10) {
            return false;
        }
        throw zzat.zzb("expected characters 'vorbis'", null);
    }

    @Nullable
    public static ta zzc(List list) {
        ArrayList arrayList = new ArrayList();
        for (int i10 = 0; i10 < list.size(); i10++) {
            String str = (String) list.get(i10);
            String str2 = bb1.f9474a;
            String[] strArrSplit = str.split("=", 2);
            if (strArrSplit.length != 2) {
                vt0.c("Failed to parse Vorbis comment: ".concat(str));
            } else if (strArrSplit[0].equals("METADATA_BLOCK_PICTURE")) {
                try {
                    arrayList.add(c5.b(new p01(Base64.decode(strArrSplit[1], 0))));
                } catch (RuntimeException e10) {
                    vt0.zzd("VorbisUtil", "Failed to parse vorbis picture", e10);
                }
            } else {
                arrayList.add(new z5(strArrSplit[0], strArrSplit[1]));
            }
        }
        if (arrayList.isEmpty()) {
            return null;
        }
        return new ta(arrayList);
    }
}
