mirror of
https://github.com/androidx/media.git
synced 2025-05-21 23:56:32 +08: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
2e21208f63
commit
97b717b8dc
@ -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…
x
Reference in New Issue
Block a user