Commit e9249c3a by kimvde Committed by Oliver Woodman

Add methods to get the current sample info in FragmentedMp4Extractor

This enhances readability, particularly as those methods will become
more complex when partially fragmented media will be supported.

PiperOrigin-RevId: 318795536
parent 159c7791
...@@ -1246,8 +1246,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1246,8 +1246,7 @@ public class FragmentedMp4Extractor implements Extractor {
return false; return false;
} }
long nextDataPosition = currentTrackBundle.fragment long nextDataPosition = currentTrackBundle.getCurrentSampleOffset();
.trunDataPosition[currentTrackBundle.currentTrackRunIndex];
// We skip bytes preceding the next sample to read. // We skip bytes preceding the next sample to read.
int bytesToSkip = (int) (nextDataPosition - input.getPosition()); int bytesToSkip = (int) (nextDataPosition - input.getPosition());
if (bytesToSkip < 0) { if (bytesToSkip < 0) {
...@@ -1259,8 +1258,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1259,8 +1258,7 @@ public class FragmentedMp4Extractor implements Extractor {
this.currentTrackBundle = currentTrackBundle; this.currentTrackBundle = currentTrackBundle;
} }
sampleSize = currentTrackBundle.fragment sampleSize = currentTrackBundle.getCurrentSampleSize();
.sampleSizeTable[currentTrackBundle.currentSampleIndex];
if (currentTrackBundle.currentSampleIndex < currentTrackBundle.firstSampleToOutputIndex) { if (currentTrackBundle.currentSampleIndex < currentTrackBundle.firstSampleToOutputIndex) {
input.skipFully(sampleSize); input.skipFully(sampleSize);
...@@ -1293,11 +1291,9 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1293,11 +1291,9 @@ public class FragmentedMp4Extractor implements Extractor {
sampleCurrentNalBytesRemaining = 0; sampleCurrentNalBytesRemaining = 0;
} }
TrackFragment fragment = currentTrackBundle.fragment;
Track track = currentTrackBundle.track; Track track = currentTrackBundle.track;
TrackOutput output = currentTrackBundle.output; TrackOutput output = currentTrackBundle.output;
int sampleIndex = currentTrackBundle.currentSampleIndex; long sampleTimeUs = currentTrackBundle.getCurrentSamplePresentationTimeUs();
long sampleTimeUs = fragment.getSamplePresentationTimeUs(sampleIndex);
if (timestampAdjuster != null) { if (timestampAdjuster != null) {
sampleTimeUs = timestampAdjuster.adjustSampleTimestamp(sampleTimeUs); sampleTimeUs = timestampAdjuster.adjustSampleTimestamp(sampleTimeUs);
} }
...@@ -1362,14 +1358,12 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1362,14 +1358,12 @@ public class FragmentedMp4Extractor implements Extractor {
} }
} }
@C.BufferFlags int sampleFlags = fragment.sampleIsSyncFrameTable[sampleIndex] @C.BufferFlags int sampleFlags = currentTrackBundle.getCurrentSampleFlags();
? C.BUFFER_FLAG_KEY_FRAME : 0;
// Encryption data. // Encryption data.
TrackOutput.CryptoData cryptoData = null; TrackOutput.CryptoData cryptoData = null;
TrackEncryptionBox encryptionBox = currentTrackBundle.getEncryptionBoxIfEncrypted(); TrackEncryptionBox encryptionBox = currentTrackBundle.getEncryptionBoxIfEncrypted();
if (encryptionBox != null) { if (encryptionBox != null) {
sampleFlags |= C.BUFFER_FLAG_ENCRYPTED;
cryptoData = encryptionBox.cryptoData; cryptoData = encryptionBox.cryptoData;
} }
...@@ -1418,7 +1412,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1418,7 +1412,7 @@ public class FragmentedMp4Extractor implements Extractor {
if (trackBundle.currentTrackRunIndex == trackBundle.fragment.trunCount) { if (trackBundle.currentTrackRunIndex == trackBundle.fragment.trunCount) {
// This track fragment contains no more runs in the next mdat box. // This track fragment contains no more runs in the next mdat box.
} else { } else {
long trunOffset = trackBundle.fragment.trunDataPosition[trackBundle.currentTrackRunIndex]; long trunOffset = trackBundle.getCurrentSampleOffset();
if (trunOffset < nextTrackRunOffset) { if (trunOffset < nextTrackRunOffset) {
nextTrackBundle = trackBundle; nextTrackBundle = trackBundle;
nextTrackRunOffset = trunOffset; nextTrackRunOffset = trunOffset;
...@@ -1556,6 +1550,31 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1556,6 +1550,31 @@ public class FragmentedMp4Extractor implements Extractor {
} }
} }
/** Returns the presentation time of the current sample in microseconds. */
public long getCurrentSamplePresentationTimeUs() {
return fragment.getSamplePresentationTimeUs(currentSampleIndex);
}
/** Returns the byte offset of the current sample. */
public long getCurrentSampleOffset() {
return fragment.trunDataPosition[currentTrackRunIndex];
}
/** Returns the size of the current sample in bytes. */
public int getCurrentSampleSize() {
return fragment.sampleSizeTable[currentSampleIndex];
}
/** Returns the {@link C.BufferFlags} corresponding to the the current sample. */
@C.BufferFlags
public int getCurrentSampleFlags() {
int flags = fragment.sampleIsSyncFrameTable[currentSampleIndex] ? C.BUFFER_FLAG_KEY_FRAME : 0;
if (getEncryptionBoxIfEncrypted() != null) {
flags |= C.BUFFER_FLAG_ENCRYPTED;
}
return flags;
}
/** /**
* Advances the indices in the bundle to point to the next sample in the current fragment. If * Advances the indices in the bundle to point to the next sample in the current fragment. If
* the current sample is the last one in the current fragment, then the advanced state will be * the current sample is the last one in the current fragment, then the advanced state will be
...@@ -1668,7 +1687,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1668,7 +1687,7 @@ public class FragmentedMp4Extractor implements Extractor {
} }
/** Skips the encryption data for the current sample. */ /** Skips the encryption data for the current sample. */
private void skipSampleEncryptionData() { public void skipSampleEncryptionData() {
@Nullable TrackEncryptionBox encryptionBox = getEncryptionBoxIfEncrypted(); @Nullable TrackEncryptionBox encryptionBox = getEncryptionBoxIfEncrypted();
if (encryptionBox == null) { if (encryptionBox == null) {
return; return;
...@@ -1684,7 +1703,7 @@ public class FragmentedMp4Extractor implements Extractor { ...@@ -1684,7 +1703,7 @@ public class FragmentedMp4Extractor implements Extractor {
} }
@Nullable @Nullable
private TrackEncryptionBox getEncryptionBoxIfEncrypted() { public TrackEncryptionBox getEncryptionBoxIfEncrypted() {
int sampleDescriptionIndex = fragment.header.sampleDescriptionIndex; int sampleDescriptionIndex = fragment.header.sampleDescriptionIndex;
@Nullable @Nullable
TrackEncryptionBox encryptionBox = TrackEncryptionBox encryptionBox =
......
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