package x2;

import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.extractor.z0;
import java.util.Collections;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class i implements j {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final List f34466a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final z0[] f34467b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f34468c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f34469d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f34470e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public long f34471f = -9223372036854775807L;

    public i(List list) {
        this.f34466a = list;
        this.f34467b = new z0[list.size()];
    }

    @Override // x2.j
    public final void a() {
        this.f34468c = false;
        this.f34471f = -9223372036854775807L;
    }

    @Override // x2.j
    public final void c(ParsableByteArray parsableByteArray) {
        if (this.f34468c) {
            if (this.f34469d == 2) {
                if (parsableByteArray.bytesLeft() == 0) {
                    return;
                }
                if (parsableByteArray.readUnsignedByte() != 32) {
                    this.f34468c = false;
                }
                this.f34469d--;
                if (!this.f34468c) {
                    return;
                }
            }
            if (this.f34469d == 1) {
                if (parsableByteArray.bytesLeft() == 0) {
                    return;
                }
                if (parsableByteArray.readUnsignedByte() != 0) {
                    this.f34468c = false;
                }
                this.f34469d--;
                if (!this.f34468c) {
                    return;
                }
            }
            int position = parsableByteArray.getPosition();
            int iBytesLeft = parsableByteArray.bytesLeft();
            for (z0 z0Var : this.f34467b) {
                parsableByteArray.setPosition(position);
                z0Var.sampleData(parsableByteArray, iBytesLeft);
            }
            this.f34470e += iBytesLeft;
        }
    }

    @Override // x2.j
    public final void d(boolean z10) {
        if (this.f34468c) {
            Assertions.checkState(this.f34471f != -9223372036854775807L);
            for (z0 z0Var : this.f34467b) {
                z0Var.sampleMetadata(this.f34471f, 1, this.f34470e, 0, null);
            }
            this.f34468c = false;
        }
    }

    @Override // x2.j
    public final void e(int i10, long j10) {
        if ((i10 & 4) == 0) {
            return;
        }
        this.f34468c = true;
        this.f34471f = j10;
        this.f34470e = 0;
        this.f34469d = 2;
    }

    @Override // x2.j
    public final void f(androidx.media3.extractor.b0 b0Var, o0 o0Var) {
        int i10 = 0;
        while (true) {
            z0[] z0VarArr = this.f34467b;
            if (i10 >= z0VarArr.length) {
                return;
            }
            l0 l0Var = (l0) this.f34466a.get(i10);
            o0Var.a();
            o0Var.b();
            z0 z0VarTrack = b0Var.track(o0Var.f34560d, 3);
            Format.Builder builder = new Format.Builder();
            o0Var.b();
            z0VarTrack.format(builder.setId(o0Var.f34561e).setContainerMimeType(MimeTypes.VIDEO_MP2T).setSampleMimeType(MimeTypes.APPLICATION_DVBSUBS).setInitializationData(Collections.singletonList(l0Var.f34528b)).setLanguage(l0Var.f34527a).build());
            z0VarArr[i10] = z0VarTrack;
            i10++;
        }
    }
}
