Support seeking in un-intearleaved tracks in Mp4Extractor
A client can pass the id of the track on which they want to seek. PiperOrigin-RevId: 437248055
This commit is contained in:
parent
acacb23ba6
commit
67acfc67de
@ -281,6 +281,22 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SeekPoints getSeekPoints(long timeUs) {
|
public SeekPoints getSeekPoints(long timeUs) {
|
||||||
|
return getSeekPoints(timeUs, /* trackId= */ C.INDEX_UNSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-inherited public methods.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equivalent to {@link SeekMap#getSeekPoints(long)}, except it adds the {@code trackId}
|
||||||
|
* parameter.
|
||||||
|
*
|
||||||
|
* @param timeUs A seek time in microseconds.
|
||||||
|
* @param trackId The id of the track on which to seek for {@link SeekPoints}. May be {@link
|
||||||
|
* C#INDEX_UNSET} if the extractor is expected to define the strategy for generating {@link
|
||||||
|
* SeekPoints}.
|
||||||
|
* @return The corresponding seek points.
|
||||||
|
*/
|
||||||
|
public SeekPoints getSeekPoints(long timeUs, int trackId) {
|
||||||
if (tracks.length == 0) {
|
if (tracks.length == 0) {
|
||||||
return new SeekPoints(SeekPoint.START);
|
return new SeekPoints(SeekPoint.START);
|
||||||
}
|
}
|
||||||
@ -290,9 +306,11 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
|||||||
long secondTimeUs = C.TIME_UNSET;
|
long secondTimeUs = C.TIME_UNSET;
|
||||||
long secondOffset = C.POSITION_UNSET;
|
long secondOffset = C.POSITION_UNSET;
|
||||||
|
|
||||||
|
// Note that the id matches the index in tracks.
|
||||||
|
int mainTrackIndex = trackId != C.INDEX_UNSET ? trackId : firstVideoTrackIndex;
|
||||||
// If we have a video track, use it to establish one or two seek points.
|
// If we have a video track, use it to establish one or two seek points.
|
||||||
if (firstVideoTrackIndex != C.INDEX_UNSET) {
|
if (mainTrackIndex != C.INDEX_UNSET) {
|
||||||
TrackSampleTable sampleTable = tracks[firstVideoTrackIndex].sampleTable;
|
TrackSampleTable sampleTable = tracks[mainTrackIndex].sampleTable;
|
||||||
int sampleIndex = getSynchronizationSampleIndex(sampleTable, timeUs);
|
int sampleIndex = getSynchronizationSampleIndex(sampleTable, timeUs);
|
||||||
if (sampleIndex == C.INDEX_UNSET) {
|
if (sampleIndex == C.INDEX_UNSET) {
|
||||||
return new SeekPoints(SeekPoint.START);
|
return new SeekPoints(SeekPoint.START);
|
||||||
@ -312,7 +330,8 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
|||||||
firstOffset = Long.MAX_VALUE;
|
firstOffset = Long.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take into account other tracks.
|
if (trackId == C.INDEX_UNSET) {
|
||||||
|
// Take into account other tracks, but only if the caller has not specified a trackId.
|
||||||
for (int i = 0; i < tracks.length; i++) {
|
for (int i = 0; i < tracks.length; i++) {
|
||||||
if (i != firstVideoTrackIndex) {
|
if (i != firstVideoTrackIndex) {
|
||||||
TrackSampleTable sampleTable = tracks[i].sampleTable;
|
TrackSampleTable sampleTable = tracks[i].sampleTable;
|
||||||
@ -322,6 +341,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SeekPoint firstSeekPoint = new SeekPoint(firstTimeUs, firstOffset);
|
SeekPoint firstSeekPoint = new SeekPoint(firstTimeUs, firstOffset);
|
||||||
if (secondTimeUs == C.TIME_UNSET) {
|
if (secondTimeUs == C.TIME_UNSET) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user