package com.google.android.exoplayer2.metadata.scte35;

import com.google.android.exoplayer2.i.k;
import com.google.android.exoplayer2.i.l;
import com.google.android.exoplayer2.i.s;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.Metadata$Entry;
import com.google.android.exoplayer2.metadata.d;
import com.tencent.matrix.trace.core.AppMethodBeat;
import java.nio.ByteBuffer;

public final class a implements com.google.android.exoplayer2.metadata.a {
    private s aYf;
    private final l bdm = new l();
    private final k bfE = new k();

    public a() {
        AppMethodBeat.i(95363);
        AppMethodBeat.o(95363);
    }

    public final Metadata a(d dVar) {
        Metadata$Entry spliceNullCommand;
        AppMethodBeat.i(95364);
        if (this.aYf == null || dVar.aOr != this.aYf.tQ()) {
            this.aYf = new s(dVar.aSk);
            this.aYf.ap(dVar.aSk - dVar.aOr);
        }
        ByteBuffer byteBuffer = dVar.aEY;
        byte[] array = byteBuffer.array();
        int limit = byteBuffer.limit();
        this.bdm.n(array, limit);
        this.bfE.n(array, limit);
        this.bfE.ee(39);
        long ed = ((long) this.bfE.ed(32)) | (((long) this.bfE.ed(1)) << 32);
        this.bfE.ee(20);
        int ed2 = this.bfE.ed(12);
        int ed3 = this.bfE.ed(8);
        this.bdm.eM(14);
        switch (ed3) {
            case 0:
                spliceNullCommand = new SpliceNullCommand();
                break;
            case 4:
                spliceNullCommand = SpliceScheduleCommand.y(this.bdm);
                break;
            case 5:
                spliceNullCommand = SpliceInsertCommand.a(this.bdm, ed, this.aYf);
                break;
            case 6:
                spliceNullCommand = TimeSignalCommand.b(this.bdm, ed, this.aYf);
                break;
            case 255:
                spliceNullCommand = PrivateCommand.a(this.bdm, ed2, ed);
                break;
            default:
                spliceNullCommand = null;
                break;
        }
        Metadata metadata;
        if (spliceNullCommand == null) {
            metadata = new Metadata(new Metadata$Entry[0]);
            AppMethodBeat.o(95364);
            return metadata;
        }
        metadata = new Metadata(new Metadata$Entry[]{spliceNullCommand});
        AppMethodBeat.o(95364);
        return metadata;
    }
}
