Search in sources :

Example 1 with LeafAtom

use of com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom in project ExoPlayer by google.

the class FragmentedMp4Extractor method parseTraf.

/**
   * Parses a traf atom (defined in 14496-12).
   */
private static void parseTraf(ContainerAtom traf, SparseArray<TrackBundle> trackBundleArray, @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
    LeafAtom tfhd = traf.getLeafAtomOfType(Atom.TYPE_tfhd);
    TrackBundle trackBundle = parseTfhd(tfhd.data, trackBundleArray, flags);
    if (trackBundle == null) {
        return;
    }
    TrackFragment fragment = trackBundle.fragment;
    long decodeTime = fragment.nextFragmentDecodeTime;
    trackBundle.reset();
    LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
    if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
        decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
    }
    parseTruns(traf, trackBundle, decodeTime, flags);
    LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
    if (saiz != null) {
        TrackEncryptionBox trackEncryptionBox = trackBundle.track.sampleDescriptionEncryptionBoxes[fragment.header.sampleDescriptionIndex];
        parseSaiz(trackEncryptionBox, saiz.data, fragment);
    }
    LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
    if (saio != null) {
        parseSaio(saio.data, fragment);
    }
    LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
    if (senc != null) {
        parseSenc(senc.data, fragment);
    }
    LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
    LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
    if (sbgp != null && sgpd != null) {
        parseSgpd(sbgp.data, sgpd.data, fragment);
    }
    int leafChildrenSize = traf.leafChildren.size();
    for (int i = 0; i < leafChildrenSize; i++) {
        LeafAtom atom = traf.leafChildren.get(i);
        if (atom.type == Atom.TYPE_uuid) {
            parseUuid(atom.data, fragment, extendedTypeScratch);
        }
    }
}
Also used : LeafAtom(com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)

Example 2 with LeafAtom

use of com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom in project ExoPlayer by google.

the class FragmentedMp4Extractor method parseTruns.

private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime, @Flags int flags) {
    int trunCount = 0;
    int totalSampleCount = 0;
    List<LeafAtom> leafChildren = traf.leafChildren;
    int leafChildrenSize = leafChildren.size();
    for (int i = 0; i < leafChildrenSize; i++) {
        LeafAtom atom = leafChildren.get(i);
        if (atom.type == Atom.TYPE_trun) {
            ParsableByteArray trunData = atom.data;
            trunData.setPosition(Atom.FULL_HEADER_SIZE);
            int trunSampleCount = trunData.readUnsignedIntToInt();
            if (trunSampleCount > 0) {
                totalSampleCount += trunSampleCount;
                trunCount++;
            }
        }
    }
    trackBundle.currentTrackRunIndex = 0;
    trackBundle.currentSampleInTrackRun = 0;
    trackBundle.currentSampleIndex = 0;
    trackBundle.fragment.initTables(trunCount, totalSampleCount);
    int trunIndex = 0;
    int trunStartPosition = 0;
    for (int i = 0; i < leafChildrenSize; i++) {
        LeafAtom trun = leafChildren.get(i);
        if (trun.type == Atom.TYPE_trun) {
            trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data, trunStartPosition);
        }
    }
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) LeafAtom(com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)

Example 3 with LeafAtom

use of com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom in project edx-app-android by edx.

the class FragmentedMp4Extractor method parseTraf.

/**
 * Parses a traf atom (defined in 14496-12).
 */
private static void parseTraf(Track track, DefaultSampleValues extendsDefaults, ContainerAtom traf, TrackFragment out, int workaroundFlags, byte[] extendedTypeScratch) {
    LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
    long decodeTime = tfdtAtom == null ? 0 : parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
    LeafAtom tfhd = traf.getLeafAtomOfType(Atom.TYPE_tfhd);
    DefaultSampleValues fragmentHeader = parseTfhd(extendsDefaults, tfhd.data);
    out.sampleDescriptionIndex = fragmentHeader.sampleDescriptionIndex;
    LeafAtom trun = traf.getLeafAtomOfType(Atom.TYPE_trun);
    parseTrun(track, fragmentHeader, decodeTime, workaroundFlags, trun.data, out);
    LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
    if (saiz != null) {
        TrackEncryptionBox trackEncryptionBox = track.sampleDescriptionEncryptionBoxes[fragmentHeader.sampleDescriptionIndex];
        parseSaiz(trackEncryptionBox, saiz.data, out);
    }
    LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
    if (senc != null) {
        parseSenc(senc.data, out);
    }
    LeafAtom uuid = traf.getLeafAtomOfType(Atom.TYPE_uuid);
    if (uuid != null) {
        parseUuid(uuid.data, out, extendedTypeScratch);
    }
}
Also used : LeafAtom(com.google.android.exoplayer.parser.mp4.Atom.LeafAtom)

Example 4 with LeafAtom

use of com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom in project ExoPlayer by google.

the class FragmentedMp4Extractor method getDrmInitDataFromAtoms.

/**
 * Returns DrmInitData from leaf atoms.
 */
@Nullable
private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) {
    @Nullable ArrayList<SchemeData> schemeDatas = null;
    int leafChildrenSize = leafChildren.size();
    for (int i = 0; i < leafChildrenSize; i++) {
        LeafAtom child = leafChildren.get(i);
        if (child.type == Atom.TYPE_pssh) {
            if (schemeDatas == null) {
                schemeDatas = new ArrayList<>();
            }
            byte[] psshData = child.data.getData();
            @Nullable UUID uuid = PsshAtomUtil.parseUuid(psshData);
            if (uuid == null) {
                Log.w(TAG, "Skipped pssh atom (failed to extract uuid)");
            } else {
                schemeDatas.add(new SchemeData(uuid, MimeTypes.VIDEO_MP4, psshData));
            }
        }
    }
    return schemeDatas == null ? null : new DrmInitData(schemeDatas);
}
Also used : DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) UUID(java.util.UUID) Nullable(androidx.annotation.Nullable) LeafAtom(com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom) Nullable(androidx.annotation.Nullable)

Example 5 with LeafAtom

use of com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom in project ExoPlayer by google.

the class FragmentedMp4Extractor method parseTraf.

/**
 * Parses a traf atom (defined in 14496-12).
 */
private static void parseTraf(ContainerAtom traf, SparseArray<TrackBundle> trackBundles, boolean haveSideloadedTrack, @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
    LeafAtom tfhd = checkNotNull(traf.getLeafAtomOfType(Atom.TYPE_tfhd));
    @Nullable TrackBundle trackBundle = parseTfhd(tfhd.data, trackBundles, haveSideloadedTrack);
    if (trackBundle == null) {
        return;
    }
    TrackFragment fragment = trackBundle.fragment;
    long fragmentDecodeTime = fragment.nextFragmentDecodeTime;
    boolean fragmentDecodeTimeIncludesMoov = fragment.nextFragmentDecodeTimeIncludesMoov;
    trackBundle.resetFragmentInfo();
    trackBundle.currentlyInFragment = true;
    @Nullable LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
    if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
        fragment.nextFragmentDecodeTime = parseTfdt(tfdtAtom.data);
        fragment.nextFragmentDecodeTimeIncludesMoov = true;
    } else {
        fragment.nextFragmentDecodeTime = fragmentDecodeTime;
        fragment.nextFragmentDecodeTimeIncludesMoov = fragmentDecodeTimeIncludesMoov;
    }
    parseTruns(traf, trackBundle, flags);
    @Nullable TrackEncryptionBox encryptionBox = trackBundle.moovSampleTable.track.getSampleDescriptionEncryptionBox(checkNotNull(fragment.header).sampleDescriptionIndex);
    @Nullable LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
    if (saiz != null) {
        parseSaiz(checkNotNull(encryptionBox), saiz.data, fragment);
    }
    @Nullable LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
    if (saio != null) {
        parseSaio(saio.data, fragment);
    }
    @Nullable LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
    if (senc != null) {
        parseSenc(senc.data, fragment);
    }
    parseSampleGroups(traf, encryptionBox != null ? encryptionBox.schemeType : null, fragment);
    int leafChildrenSize = traf.leafChildren.size();
    for (int i = 0; i < leafChildrenSize; i++) {
        LeafAtom atom = traf.leafChildren.get(i);
        if (atom.type == Atom.TYPE_uuid) {
            parseUuid(atom.data, fragment, extendedTypeScratch);
        }
    }
}
Also used : LeafAtom(com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom) Nullable(androidx.annotation.Nullable)

Aggregations

LeafAtom (com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)7 Nullable (androidx.annotation.Nullable)4 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)4 LeafAtom (com.google.android.exoplayer.parser.mp4.Atom.LeafAtom)3 SuppressLint (android.annotation.SuppressLint)2 UUID (java.util.UUID)2 ContainerAtom (com.google.android.exoplayer.parser.mp4.Atom.ContainerAtom)1 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)1 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)1