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

import java.io.EOFException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes2.dex */
public abstract class bd implements cd {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Logger f9495b = Logger.getLogger(bd.class.getName());

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final com.google.android.gms.common.api.internal.x0 f9496a = new com.google.android.gms.common.api.internal.x0();

    public final ed a(k40 k40Var, fd fdVar) throws EOFException {
        int iE;
        ByteBuffer byteBuffer;
        long jLimit;
        ed idVar;
        long jG = k40Var.g();
        com.google.android.gms.common.api.internal.x0 x0Var = this.f9496a;
        ((ByteBuffer) x0Var.get()).rewind().limit(8);
        do {
            iE = k40Var.e((ByteBuffer) x0Var.get());
            byteBuffer = k40Var.f13090a;
            if (iE == 8) {
                ((ByteBuffer) x0Var.get()).rewind();
                long jD = za2.d((ByteBuffer) x0Var.get());
                if (jD < 8 && jD > 1) {
                    Level level = Level.SEVERE;
                    StringBuilder sb = new StringBuilder(80);
                    sb.append("Plausibility check failed: size < 8 (size = ");
                    sb.append(jD);
                    sb.append("). Stop parsing!");
                    f9495b.logp(level, "com.coremedia.iso.AbstractBoxParser", "parseBox", sb.toString());
                    return null;
                }
                byte[] bArr = new byte[4];
                ((ByteBuffer) x0Var.get()).get(bArr);
                try {
                    String str = new String(bArr, "ISO-8859-1");
                    if (jD == 1) {
                        ((ByteBuffer) x0Var.get()).limit(16);
                        k40Var.e((ByteBuffer) x0Var.get());
                        ((ByteBuffer) x0Var.get()).position(8);
                        jLimit = za2.E((ByteBuffer) x0Var.get()) - 16;
                    } else {
                        jLimit = jD == 0 ? ((long) byteBuffer.limit()) - k40Var.g() : jD - 8;
                    }
                    if ("uuid".equals(str)) {
                        ((ByteBuffer) x0Var.get()).limit(((ByteBuffer) x0Var.get()).limit() + 16);
                        k40Var.e((ByteBuffer) x0Var.get());
                        byte[] bArr2 = new byte[16];
                        for (int iPosition = ((ByteBuffer) x0Var.get()).position() - 16; iPosition < ((ByteBuffer) x0Var.get()).position(); iPosition++) {
                            bArr2[iPosition - (((ByteBuffer) x0Var.get()).position() - 16)] = ((ByteBuffer) x0Var.get()).get(iPosition);
                        }
                        jLimit -= 16;
                    }
                    long j10 = jLimit;
                    if (fdVar instanceof ed) {
                        ((ed) fdVar).zza();
                    }
                    if ("moov".equals(str)) {
                        idVar = new gd();
                    } else if ("mvhd".equals(str)) {
                        hd hdVar = new hd("mvhd");
                        hdVar.Q = 1.0d;
                        hdVar.R = 1.0f;
                        hdVar.S = eg2.f10784j;
                        idVar = hdVar;
                    } else {
                        idVar = new id(str, 0);
                    }
                    ((ByteBuffer) x0Var.get()).rewind();
                    idVar.e(k40Var, (ByteBuffer) x0Var.get(), j10, this);
                    return idVar;
                } catch (UnsupportedEncodingException e10) {
                    throw new RuntimeException(e10);
                }
            }
        } while (iE >= 0);
        byteBuffer.position((int) jG);
        throw new EOFException();
    }
}
