Commit b88025cc by kimvde Committed by Andrew Lewis

Fix stuck muxer

Unstuck the muxer if the next timestamp in the track with the minimum
timestamp is larger than this minimum timestamp plus
MAX_TRACK_WRITE_AHEAD_US.

PiperOrigin-RevId: 510977088
parent c79eb746
......@@ -20,7 +20,6 @@ import static com.google.android.exoplayer2.util.Assertions.checkArgument;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkState;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import android.util.SparseArray;
......@@ -254,8 +253,16 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if (trackTypeToInfo.size() == 1) {
return true;
}
if (presentationTimeUs - trackTypeToInfo.get(trackType).timeUs > MAX_TRACK_WRITE_AHEAD_US) {
TrackInfo trackInfoWithMinTimeUs = checkNotNull(getTrackInfoWithMinTimeUs(trackTypeToInfo));
if (MimeTypes.getTrackType(trackInfoWithMinTimeUs.format.sampleMimeType) == trackType) {
// Unstuck the muxer if consecutive timestamps from the same track are more than
// MAX_TRACK_WRITE_AHEAD_US apart.
return true;
}
}
if (trackType != previousTrackType) {
minTrackTimeUs = getMinTrackTimeUs(trackTypeToInfo);
minTrackTimeUs = checkNotNull(getTrackInfoWithMinTimeUs(trackTypeToInfo)).timeUs;
}
return presentationTimeUs - minTrackTimeUs <= MAX_TRACK_WRITE_AHEAD_US;
}
......@@ -301,16 +308,20 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
return fileSize > 0 ? fileSize : C.LENGTH_UNSET;
}
private static long getMinTrackTimeUs(SparseArray<TrackInfo> trackTypeToInfo) {
@Nullable
private static TrackInfo getTrackInfoWithMinTimeUs(SparseArray<TrackInfo> trackTypeToInfo) {
if (trackTypeToInfo.size() == 0) {
return C.TIME_UNSET;
return null;
}
long minTrackTimeUs = Long.MAX_VALUE;
for (int i = 0; i < trackTypeToInfo.size(); i++) {
minTrackTimeUs = min(minTrackTimeUs, trackTypeToInfo.valueAt(i).timeUs);
TrackInfo trackInfoWithMinTimeUs = trackTypeToInfo.valueAt(0);
for (int i = 1; i < trackTypeToInfo.size(); i++) {
TrackInfo trackInfo = trackTypeToInfo.valueAt(i);
if (trackInfo.timeUs < trackInfoWithMinTimeUs.timeUs) {
trackInfoWithMinTimeUs = trackInfo;
}
}
return minTrackTimeUs;
return trackInfoWithMinTimeUs;
}
private static final class TrackInfo {
......
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