mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
Duration readers: Return TIME_UNSET rather than a negative value
This typically happens if there's a discontinuity in the stream. It's better to say we don't know, than it is to return a negative position. Issue: #8346 #exofixit #minor-release PiperOrigin-RevId: 395224088
This commit is contained in:
parent
140e110e44
commit
ced4232fd8
2 changed files with 14 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ import com.google.android.exoplayer2.C;
|
|||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer2.extractor.PositionHolder;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.TimestampAdjuster;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
|
@ -41,6 +42,8 @@ import java.io.IOException;
|
|||
*/
|
||||
/* package */ final class PsDurationReader {
|
||||
|
||||
private static final String TAG = "PsDurationReader";
|
||||
|
||||
private static final int TIMESTAMP_SEARCH_BYTES = 20_000;
|
||||
|
||||
private final TimestampAdjuster scrTimestampAdjuster;
|
||||
|
|
@ -102,6 +105,10 @@ import java.io.IOException;
|
|||
long minScrPositionUs = scrTimestampAdjuster.adjustTsTimestamp(firstScrValue);
|
||||
long maxScrPositionUs = scrTimestampAdjuster.adjustTsTimestamp(lastScrValue);
|
||||
durationUs = maxScrPositionUs - minScrPositionUs;
|
||||
if (durationUs < 0) {
|
||||
Log.w(TAG, "Invalid duration: " + durationUs + ". Using TIME_UNSET instead.");
|
||||
durationUs = C.TIME_UNSET;
|
||||
}
|
||||
return finishReadDuration(input);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import com.google.android.exoplayer2.C;
|
|||
import com.google.android.exoplayer2.extractor.Extractor;
|
||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||
import com.google.android.exoplayer2.extractor.PositionHolder;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.TimestampAdjuster;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
|
@ -38,6 +39,8 @@ import java.io.IOException;
|
|||
*/
|
||||
/* package */ final class TsDurationReader {
|
||||
|
||||
private static final String TAG = "TsDurationReader";
|
||||
|
||||
private final int timestampSearchBytes;
|
||||
private final TimestampAdjuster pcrTimestampAdjuster;
|
||||
private final ParsableByteArray packetBuffer;
|
||||
|
|
@ -98,6 +101,10 @@ import java.io.IOException;
|
|||
long minPcrPositionUs = pcrTimestampAdjuster.adjustTsTimestamp(firstPcrValue);
|
||||
long maxPcrPositionUs = pcrTimestampAdjuster.adjustTsTimestamp(lastPcrValue);
|
||||
durationUs = maxPcrPositionUs - minPcrPositionUs;
|
||||
if (durationUs < 0) {
|
||||
Log.w(TAG, "Invalid duration: " + durationUs + ". Using TIME_UNSET instead.");
|
||||
durationUs = C.TIME_UNSET;
|
||||
}
|
||||
return finishReadDuration(input);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue