mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Tweak use of TimestampAdjuster for seeking
- Fix use of getTimestampOffsetUs in TsExtractor where getFirstSampleTimestampUs should have been used. - Don't reset TimestampAdjuster if it's in no-offset mode. - Improve comment clarity #minor-release PiperOrigin-RevId: 388682711
This commit is contained in:
parent
4b1609d569
commit
a34809bb9d
@ -135,16 +135,23 @@ public final class PsExtractor implements Extractor {
|
||||
|
||||
@Override
|
||||
public void seek(long position, long timeUs) {
|
||||
boolean hasNotEncounteredFirstTimestamp =
|
||||
timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET;
|
||||
if (hasNotEncounteredFirstTimestamp
|
||||
|| (timestampAdjuster.getFirstSampleTimestampUs() != 0
|
||||
&& timestampAdjuster.getFirstSampleTimestampUs() != timeUs)) {
|
||||
// - If the timestamp adjuster in the PS stream has not encountered any sample, it's going to
|
||||
// treat the first timestamp encountered as sample time 0, which is incorrect. In this case,
|
||||
// we have to set the first sample timestamp manually.
|
||||
// - If the timestamp adjuster has its timestamp set manually before, and now we seek to a
|
||||
// different position, we need to set the first sample timestamp manually again.
|
||||
// If the timestamp adjuster has not yet established a timestamp offset, we need to reset its
|
||||
// expected first sample timestamp to be the new seek position. Without this, the timestamp
|
||||
// adjuster would incorrectly establish its timestamp offset assuming that the first sample
|
||||
// after this seek corresponds to the start of the stream (or a previous seek position, if there
|
||||
// was one).
|
||||
boolean resetTimestampAdjuster = timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET;
|
||||
if (!resetTimestampAdjuster) {
|
||||
long adjusterFirstSampleTimestampUs = timestampAdjuster.getFirstSampleTimestampUs();
|
||||
// Also reset the timestamp adjuster if its offset was calculated based on a non-zero position
|
||||
// in the stream (other than the position being seeked to), since in this case the offset may
|
||||
// not be accurate.
|
||||
resetTimestampAdjuster =
|
||||
adjusterFirstSampleTimestampUs != C.TIME_UNSET
|
||||
&& adjusterFirstSampleTimestampUs != 0
|
||||
&& adjusterFirstSampleTimestampUs != timeUs;
|
||||
}
|
||||
if (resetTimestampAdjuster) {
|
||||
timestampAdjuster.reset(timeUs);
|
||||
}
|
||||
|
||||
|
@ -252,16 +252,23 @@ public final class TsExtractor implements Extractor {
|
||||
int timestampAdjustersCount = timestampAdjusters.size();
|
||||
for (int i = 0; i < timestampAdjustersCount; i++) {
|
||||
TimestampAdjuster timestampAdjuster = timestampAdjusters.get(i);
|
||||
boolean hasNotEncounteredFirstTimestamp =
|
||||
timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET;
|
||||
if (hasNotEncounteredFirstTimestamp
|
||||
|| (timestampAdjuster.getTimestampOffsetUs() != 0
|
||||
&& timestampAdjuster.getFirstSampleTimestampUs() != timeUs)) {
|
||||
// - If a track in the TS stream has not encountered any sample, it's going to treat the
|
||||
// first sample encountered as timestamp 0, which is incorrect. So we have to set the first
|
||||
// sample timestamp for that track manually.
|
||||
// - If the timestamp adjuster has its timestamp set manually before, and now we seek to a
|
||||
// different position, we need to set the first sample timestamp manually again.
|
||||
// If the timestamp adjuster has not yet established a timestamp offset, we need to reset its
|
||||
// expected first sample timestamp to be the new seek position. Without this, the timestamp
|
||||
// adjuster would incorrectly establish its timestamp offset assuming that the first sample
|
||||
// after this seek corresponds to the start of the stream (or a previous seek position, if
|
||||
// there was one).
|
||||
boolean resetTimestampAdjuster = timestampAdjuster.getTimestampOffsetUs() == C.TIME_UNSET;
|
||||
if (!resetTimestampAdjuster) {
|
||||
long adjusterFirstSampleTimestampUs = timestampAdjuster.getFirstSampleTimestampUs();
|
||||
// Also reset the timestamp adjuster if its offset was calculated based on a non-zero
|
||||
// position in the stream (other than the position being seeked to), since in this case the
|
||||
// offset may not be accurate.
|
||||
resetTimestampAdjuster =
|
||||
adjusterFirstSampleTimestampUs != C.TIME_UNSET
|
||||
&& adjusterFirstSampleTimestampUs != 0
|
||||
&& adjusterFirstSampleTimestampUs != timeUs;
|
||||
}
|
||||
if (resetTimestampAdjuster) {
|
||||
timestampAdjuster.reset(timeUs);
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ track 256:
|
||||
initializationData:
|
||||
data = length 22, hash CE183139
|
||||
sample 0:
|
||||
time = 55610
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 20711, hash 34341E8
|
||||
sample 1:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 18112, hash EC44B35B
|
||||
track 257:
|
||||
@ -35,19 +35,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 44699
|
||||
time = 22455
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 70821
|
||||
time = 48577
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 96944
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 123066
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -17,11 +17,11 @@ track 256:
|
||||
initializationData:
|
||||
data = length 22, hash CE183139
|
||||
sample 0:
|
||||
time = 77854
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 20711, hash 34341E8
|
||||
sample 1:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 18112, hash EC44B35B
|
||||
track 257:
|
||||
@ -35,19 +35,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 66943
|
||||
time = 22455
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 93065
|
||||
time = 48577
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 119188
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 145310
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -27,11 +27,11 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 66733
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 1:
|
||||
time = 92855
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -17,75 +17,75 @@ track 256:
|
||||
initializationData:
|
||||
data = length 47, hash 7696BF67
|
||||
sample 0:
|
||||
time = 320000
|
||||
time = 240000
|
||||
flags = 0
|
||||
data = length 212, hash 835B0727
|
||||
sample 1:
|
||||
time = 360000
|
||||
time = 280000
|
||||
flags = 0
|
||||
data = length 212, hash E9AF0AB7
|
||||
sample 2:
|
||||
time = 400000
|
||||
time = 320000
|
||||
flags = 0
|
||||
data = length 212, hash E9517D06
|
||||
sample 3:
|
||||
time = 440000
|
||||
time = 360000
|
||||
flags = 0
|
||||
data = length 212, hash 4FA58096
|
||||
sample 4:
|
||||
time = 480000
|
||||
time = 400000
|
||||
flags = 0
|
||||
data = length 212, hash 4F47F2E5
|
||||
sample 5:
|
||||
time = 520000
|
||||
time = 440000
|
||||
flags = 0
|
||||
data = length 212, hash B59BF675
|
||||
sample 6:
|
||||
time = 560000
|
||||
time = 480000
|
||||
flags = 1
|
||||
data = length 11769, hash 3ED9DF06
|
||||
sample 7:
|
||||
time = 600000
|
||||
time = 520000
|
||||
flags = 0
|
||||
data = length 230, hash 2AF3505D
|
||||
sample 8:
|
||||
time = 640000
|
||||
time = 560000
|
||||
flags = 0
|
||||
data = length 222, hash F4E7436D
|
||||
sample 9:
|
||||
time = 680000
|
||||
time = 600000
|
||||
flags = 0
|
||||
data = length 222, hash F0F812FD
|
||||
sample 10:
|
||||
time = 720000
|
||||
time = 640000
|
||||
flags = 0
|
||||
data = length 222, hash 18472E8C
|
||||
sample 11:
|
||||
time = 760000
|
||||
time = 680000
|
||||
flags = 0
|
||||
data = length 222, hash 1457FE1C
|
||||
sample 12:
|
||||
time = 800000
|
||||
time = 720000
|
||||
flags = 0
|
||||
data = length 222, hash 3BA719AB
|
||||
sample 13:
|
||||
time = 840000
|
||||
time = 760000
|
||||
flags = 0
|
||||
data = length 222, hash 37B7E93B
|
||||
sample 14:
|
||||
time = 880000
|
||||
time = 800000
|
||||
flags = 0
|
||||
data = length 222, hash 5F0704CA
|
||||
sample 15:
|
||||
time = 920000
|
||||
time = 840000
|
||||
flags = 0
|
||||
data = length 222, hash 5B17D45A
|
||||
sample 16:
|
||||
time = 960000
|
||||
time = 880000
|
||||
flags = 0
|
||||
data = length 222, hash 8266EFE9
|
||||
sample 17:
|
||||
time = 1000000
|
||||
time = 920000
|
||||
flags = 0
|
||||
data = length 222, hash 7E77BF79
|
||||
tracksEnded = true
|
||||
|
@ -19,11 +19,11 @@ track 256:
|
||||
data = length 29, hash 4C2CAE9C
|
||||
data = length 9, hash D971CD89
|
||||
sample 0:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 1
|
||||
data = length 12394, hash A39F5311
|
||||
sample 1:
|
||||
time = 122344
|
||||
time = 100100
|
||||
flags = 0
|
||||
data = length 813, hash 99F7B4FA
|
||||
track 257:
|
||||
@ -37,19 +37,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 115099
|
||||
time = 92855
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 141221
|
||||
time = 118977
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 167343
|
||||
time = 145099
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -19,11 +19,11 @@ track 256:
|
||||
data = length 29, hash 4C2CAE9C
|
||||
data = length 9, hash D971CD89
|
||||
sample 0:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 1
|
||||
data = length 12394, hash A39F5311
|
||||
sample 1:
|
||||
time = 144588
|
||||
time = 100100
|
||||
flags = 0
|
||||
data = length 813, hash 99F7B4FA
|
||||
track 257:
|
||||
@ -37,19 +37,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 137343
|
||||
time = 92855
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 163465
|
||||
time = 118977
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 189587
|
||||
time = 145099
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -19,19 +19,19 @@ track 256:
|
||||
data = length 29, hash 4C2CAE9C
|
||||
data = length 9, hash D971CD89
|
||||
sample 0:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 734, hash AF0D9485
|
||||
sample 1:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 1
|
||||
data = length 10938, hash 68420875
|
||||
sample 2:
|
||||
time = 155710
|
||||
time = 133466
|
||||
flags = 0
|
||||
data = length 6, hash 34E6CF79
|
||||
sample 3:
|
||||
time = 155710
|
||||
time = 133466
|
||||
flags = 0
|
||||
data = length 518, hash 546C177
|
||||
tracksEnded = true
|
||||
|
@ -19,19 +19,19 @@ track 256:
|
||||
data = length 29, hash 4C2CAE9C
|
||||
data = length 9, hash D971CD89
|
||||
sample 0:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 734, hash AF0D9485
|
||||
sample 1:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 1
|
||||
data = length 10938, hash 68420875
|
||||
sample 2:
|
||||
time = 177954
|
||||
time = 133466
|
||||
flags = 0
|
||||
data = length 6, hash 34E6CF79
|
||||
sample 3:
|
||||
time = 177954
|
||||
time = 133466
|
||||
flags = 0
|
||||
data = length 518, hash 546C177
|
||||
tracksEnded = true
|
||||
|
@ -17,11 +17,11 @@ track 256:
|
||||
initializationData:
|
||||
data = length 22, hash CE183139
|
||||
sample 0:
|
||||
time = 55610
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 20711, hash 34341E8
|
||||
sample 1:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 18112, hash EC44B35B
|
||||
track 257:
|
||||
@ -35,19 +35,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 44699
|
||||
time = 22455
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 70821
|
||||
time = 48577
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 96944
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 123066
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
track 600:
|
||||
@ -55,17 +55,17 @@ track 600:
|
||||
sample count = 3
|
||||
format 0:
|
||||
sampleMimeType = application/x-scte35
|
||||
subsampleOffsetUs = -1377756
|
||||
subsampleOffsetUs = -1400000
|
||||
sample 0:
|
||||
time = 55610
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 35, hash A892AAAF
|
||||
sample 1:
|
||||
time = 55610
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 35, hash A892AAAF
|
||||
sample 2:
|
||||
time = 55610
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 35, hash DFA3EF74
|
||||
tracksEnded = true
|
||||
|
@ -17,11 +17,11 @@ track 256:
|
||||
initializationData:
|
||||
data = length 22, hash CE183139
|
||||
sample 0:
|
||||
time = 77854
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 20711, hash 34341E8
|
||||
sample 1:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 18112, hash EC44B35B
|
||||
track 257:
|
||||
@ -35,19 +35,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 66943
|
||||
time = 22455
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 93065
|
||||
time = 48577
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 119188
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 145310
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
track 600:
|
||||
@ -55,17 +55,17 @@ track 600:
|
||||
sample count = 3
|
||||
format 0:
|
||||
sampleMimeType = application/x-scte35
|
||||
subsampleOffsetUs = -1355512
|
||||
subsampleOffsetUs = -1400000
|
||||
sample 0:
|
||||
time = 77854
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 35, hash A892AAAF
|
||||
sample 1:
|
||||
time = 77854
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 35, hash A892AAAF
|
||||
sample 2:
|
||||
time = 77854
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 35, hash DFA3EF74
|
||||
tracksEnded = true
|
||||
|
@ -27,11 +27,11 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 66733
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 1:
|
||||
time = 92855
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
track 600:
|
||||
@ -39,5 +39,5 @@ track 600:
|
||||
sample count = 0
|
||||
format 0:
|
||||
sampleMimeType = application/x-scte35
|
||||
subsampleOffsetUs = -1355512
|
||||
subsampleOffsetUs = -1400000
|
||||
tracksEnded = true
|
||||
|
@ -17,11 +17,11 @@ track 256:
|
||||
initializationData:
|
||||
data = length 22, hash CE183139
|
||||
sample 0:
|
||||
time = 55610
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 20711, hash 34341E8
|
||||
sample 1:
|
||||
time = 88977
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 18112, hash EC44B35B
|
||||
track 257:
|
||||
@ -35,19 +35,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 44699
|
||||
time = 22455
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 70821
|
||||
time = 48577
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 96944
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 123066
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -17,11 +17,11 @@ track 256:
|
||||
initializationData:
|
||||
data = length 22, hash CE183139
|
||||
sample 0:
|
||||
time = 77854
|
||||
time = 33366
|
||||
flags = 1
|
||||
data = length 20711, hash 34341E8
|
||||
sample 1:
|
||||
time = 111221
|
||||
time = 66733
|
||||
flags = 0
|
||||
data = length 18112, hash EC44B35B
|
||||
track 257:
|
||||
@ -35,19 +35,19 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 66943
|
||||
time = 22455
|
||||
flags = 1
|
||||
data = length 1253, hash 727FD1C6
|
||||
sample 1:
|
||||
time = 93065
|
||||
time = 48577
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 2:
|
||||
time = 119188
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 3:
|
||||
time = 145310
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
@ -27,11 +27,11 @@ track 257:
|
||||
sampleRate = 44100
|
||||
language = und
|
||||
sample 0:
|
||||
time = 66733
|
||||
time = 74700
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
sample 1:
|
||||
time = 92855
|
||||
time = 100822
|
||||
flags = 1
|
||||
data = length 1254, hash 73FB07B8
|
||||
tracksEnded = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user