Skip to content

Commit

Permalink
PSSH in MOOF support in Exo V2
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131534334
  • Loading branch information
sharjeel authored and ojw28 committed Aug 31, 2016
1 parent f8311a4 commit cf363f9
Showing 1 changed file with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,8 @@ private void onContainerAtomRead(ContainerAtom container) throws ParserException

private void onMoovContainerAtomRead(ContainerAtom moov) throws ParserException {
Assertions.checkState(sideloadedTrack == null, "Unexpected moov box.");
List<Atom.LeafAtom> moovLeafChildren = moov.leafChildren;
int moovLeafChildrenSize = moovLeafChildren.size();

ArrayList<SchemeData> schemeDatas = null;
for (int i = 0; i < moovLeafChildrenSize; i++) {
LeafAtom child = moovLeafChildren.get(i);
if (child.type == Atom.TYPE_pssh) {
if (schemeDatas == null) {
schemeDatas = new ArrayList<>();
}
byte[] psshData = child.data.data;
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));
}
}
}
DrmInitData drmInitData = schemeDatas == null ? null : new DrmInitData(schemeDatas);
DrmInitData drmInitData = getDrmInitDataFromAtoms(moov.leafChildren);

// Read declaration of track fragments in the Moov box.
ContainerAtom mvex = moov.getContainerAtomOfType(Atom.TYPE_mvex);
Expand Down Expand Up @@ -405,6 +387,13 @@ private void onMoovContainerAtomRead(ContainerAtom moov) throws ParserException

private void onMoofContainerAtomRead(ContainerAtom moof) throws ParserException {
parseMoof(moof, trackBundles, flags, extendedTypeScratch);
DrmInitData drmInitData = getDrmInitDataFromAtoms(moof.leafChildren);
if (drmInitData != null) {
int trackCount = trackBundles.size();
for (int i = 0; i < trackCount; i++) {
trackBundles.valueAt(i).updateDrmInitData(drmInitData);
}
}
}

/**
Expand Down Expand Up @@ -1090,6 +1079,29 @@ private int appendSampleEncryptionData(TrackBundle trackBundle) {
return 1 + vectorSize + subsampleDataLength;
}


/** Returns DrmInitData from leaf atoms. */
private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) {
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.data;
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);
}

/** Returns whether the extractor should decode a leaf atom with type {@code atom}. */
private static boolean shouldParseLeafAtom(int atom) {
return atom == Atom.TYPE_hdlr || atom == Atom.TYPE_mdhd || atom == Atom.TYPE_mvhd
Expand Down Expand Up @@ -1141,6 +1153,9 @@ public void reset() {
currentSampleInTrackRun = 0;
}

public void updateDrmInitData(DrmInitData drmInitData) {
output.format(track.format.copyWithDrmInitData(drmInitData));
}
}

}

0 comments on commit cf363f9

Please sign in to comment.