Commit 38dd1bb7 by kimvde Committed by kim-vde

FragmentedMp4Extractor: simplify extra tracks logic

This will simplify the addition of nullness annotations.

PiperOrigin-RevId: 325221749
parent ea347a46
...@@ -114,11 +114,13 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -114,11 +114,13 @@ public class FragmentedMp4Extractor implements Extractor {
@SuppressWarnings("ConstantCaseForConstants") @SuppressWarnings("ConstantCaseForConstants")
private static final int SAMPLE_GROUP_TYPE_seig = 0x73656967; private static final int SAMPLE_GROUP_TYPE_seig = 0x73656967;
private static final byte[] PIFF_SAMPLE_ENCRYPTION_BOX_EXTENDED_TYPE = private static final byte[] PIFF_SAMPLE_ENCRYPTION_BOX_EXTENDED_TYPE =
new byte[] {-94, 57, 79, 82, 90, -101, 79, 20, -94, 68, 108, 66, 124, 100, -115, -12}; new byte[] {-94, 57, 79, 82, 90, -101, 79, 20, -94, 68, 108, 66, 124, 100, -115, -12};
// Extra tracks constants.
private static final Format EMSG_FORMAT = private static final Format EMSG_FORMAT =
new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_EMSG).build(); new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_EMSG).build();
private static final int EXTRA_TRACKS_BASE_ID = 100;
// Parser states. // Parser states.
private static final int STATE_READING_ATOM_HEADER = 0; private static final int STATE_READING_ATOM_HEADER = 0;
...@@ -172,7 +174,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -172,7 +174,7 @@ public class FragmentedMp4Extractor implements Extractor {
private int sampleCurrentNalBytesRemaining; private int sampleCurrentNalBytesRemaining;
private boolean processSeiNalUnitPayload; private boolean processSeiNalUnitPayload;
// Extractor output. // Outputs.
private @MonotonicNonNull ExtractorOutput extractorOutput; private @MonotonicNonNull ExtractorOutput extractorOutput;
private TrackOutput[] emsgTrackOutputs; private TrackOutput[] emsgTrackOutputs;
private TrackOutput[] ceaTrackOutputs; private TrackOutput[] ceaTrackOutputs;
...@@ -268,6 +270,8 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -268,6 +270,8 @@ public class FragmentedMp4Extractor implements Extractor {
durationUs = C.TIME_UNSET; durationUs = C.TIME_UNSET;
pendingSeekTimeUs = C.TIME_UNSET; pendingSeekTimeUs = C.TIME_UNSET;
segmentIndexEarliestPresentationTimeUs = C.TIME_UNSET; segmentIndexEarliestPresentationTimeUs = C.TIME_UNSET;
emsgTrackOutputs = new TrackOutput[0];
ceaTrackOutputs = new TrackOutput[0];
enterReadingAtomHeaderState(); enterReadingAtomHeaderState();
} }
...@@ -279,6 +283,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -279,6 +283,7 @@ public class FragmentedMp4Extractor implements Extractor {
@Override @Override
public void init(ExtractorOutput output) { public void init(ExtractorOutput output) {
extractorOutput = output; extractorOutput = output;
initExtraTracks();
if (sideloadedTrack != null) { if (sideloadedTrack != null) {
TrackBundle bundle = new TrackBundle(output.track(0, sideloadedTrack.type)); TrackBundle bundle = new TrackBundle(output.track(0, sideloadedTrack.type));
bundle.init( bundle.init(
...@@ -293,7 +298,6 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -293,7 +298,6 @@ public class FragmentedMp4Extractor implements Extractor {
new DefaultSampleValues( new DefaultSampleValues(
/* sampleDescriptionIndex= */ 0, /* duration= */ 0, /* size= */ 0, /* flags= */ 0)); /* sampleDescriptionIndex= */ 0, /* duration= */ 0, /* size= */ 0, /* flags= */ 0));
trackBundles.put(0, bundle); trackBundles.put(0, bundle);
maybeInitExtraTracks();
extractorOutput.endTracks(); extractorOutput.endTracks();
} }
} }
...@@ -518,7 +522,6 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -518,7 +522,6 @@ public class FragmentedMp4Extractor implements Extractor {
trackBundles.put(track.id, trackBundle); trackBundles.put(track.id, trackBundle);
durationUs = max(durationUs, track.durationUs); durationUs = max(durationUs, track.durationUs);
} }
maybeInitExtraTracks();
extractorOutput.endTracks(); extractorOutput.endTracks();
} else { } else {
Assertions.checkState(trackBundles.size() == trackCount); Assertions.checkState(trackBundles.size() == trackCount);
...@@ -567,30 +570,28 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -567,30 +570,28 @@ public class FragmentedMp4Extractor implements Extractor {
} }
} }
private void maybeInitExtraTracks() { private void initExtraTracks() {
if (emsgTrackOutputs == null) { int nextExtraTrackId = EXTRA_TRACKS_BASE_ID;
emsgTrackOutputs = new TrackOutput[2];
int emsgTrackOutputCount = 0;
if (additionalEmsgTrackOutput != null) {
emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
}
if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
emsgTrackOutputs[emsgTrackOutputCount++] =
extractorOutput.track(trackBundles.size(), C.TRACK_TYPE_METADATA);
}
emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);
for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) { emsgTrackOutputs = new TrackOutput[2];
eventMessageTrackOutput.format(EMSG_FORMAT); int emsgTrackOutputCount = 0;
} if (additionalEmsgTrackOutput != null) {
emsgTrackOutputs[emsgTrackOutputCount++] = additionalEmsgTrackOutput;
} }
if (ceaTrackOutputs == null) { if ((flags & FLAG_ENABLE_EMSG_TRACK) != 0) {
ceaTrackOutputs = new TrackOutput[closedCaptionFormats.size()]; emsgTrackOutputs[emsgTrackOutputCount++] =
for (int i = 0; i < ceaTrackOutputs.length; i++) { extractorOutput.track(nextExtraTrackId++, C.TRACK_TYPE_METADATA);
TrackOutput output = extractorOutput.track(trackBundles.size() + 1 + i, C.TRACK_TYPE_TEXT); }
output.format(closedCaptionFormats.get(i)); emsgTrackOutputs = Arrays.copyOf(emsgTrackOutputs, emsgTrackOutputCount);
ceaTrackOutputs[i] = output; for (TrackOutput eventMessageTrackOutput : emsgTrackOutputs) {
} eventMessageTrackOutput.format(EMSG_FORMAT);
}
ceaTrackOutputs = new TrackOutput[closedCaptionFormats.size()];
for (int i = 0; i < ceaTrackOutputs.length; i++) {
TrackOutput output = extractorOutput.track(nextExtraTrackId++, C.TRACK_TYPE_TEXT);
output.format(closedCaptionFormats.get(i));
ceaTrackOutputs[i] = output;
} }
} }
......
...@@ -330,7 +330,7 @@ track 1: ...@@ -330,7 +330,7 @@ track 1:
time = 1044897 time = 1044897
flags = 1 flags = 1
data = length 10, hash A453EEBE data = length 10, hash A453EEBE
track 3: track 100:
total output bytes = 0 total output bytes = 0
sample count = 0 sample count = 0
format 0: format 0:
......
...@@ -330,7 +330,7 @@ track 1: ...@@ -330,7 +330,7 @@ track 1:
time = 1044897 time = 1044897
flags = 1 flags = 1
data = length 10, hash A453EEBE data = length 10, hash A453EEBE
track 3: track 100:
total output bytes = 0 total output bytes = 0
sample count = 0 sample count = 0
format 0: format 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment