Skip to content

Commit 284bf97

Browse files
toniheichristosts
authored andcommitted
Fix timestamp comparison for seeks in fMP4
When seeking in fMP4, we try to extract as little samples as possible by only starting at the preceding sync frame. This comparison should use <= to allow sync frames at exactly the seek position. Issue: #10941 #minor-release PiperOrigin-RevId: 505098172 (cherry picked from commit ac3017b)
1 parent ace97fa commit 284bf97

File tree

5 files changed

+70
-86
lines changed

5 files changed

+70
-86
lines changed

library/extractor/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,15 +1673,15 @@ public void resetFragmentInfo() {
16731673
}
16741674

16751675
/**
1676-
* Advances {@link #firstSampleToOutputIndex} to point to the sync sample before the specified
1677-
* seek time in the current fragment.
1676+
* Advances {@link #firstSampleToOutputIndex} to point to the sync sample at or before the
1677+
* specified seek time in the current fragment.
16781678
*
16791679
* @param timeUs The seek time, in microseconds.
16801680
*/
16811681
public void seek(long timeUs) {
16821682
int searchIndex = currentSampleIndex;
16831683
while (searchIndex < fragment.sampleCount
1684-
&& fragment.getSamplePresentationTimeUs(searchIndex) < timeUs) {
1684+
&& fragment.getSamplePresentationTimeUs(searchIndex) <= timeUs) {
16851685
if (fragment.sampleIsSyncFrameTable[searchIndex]) {
16861686
firstSampleToOutputIndex = searchIndex;
16871687
}

testdata/src/test/assets/extractordumps/mp4/sample_ac3_fragmented.mp4.1.dump

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ seekMap:
77
getPosition(288000) = [[timeUs=0, position=636]]
88
numberOfTracks = 1
99
track 0:
10-
total output bytes = 10752
11-
sample count = 7
10+
total output bytes = 9216
11+
sample count = 6
1212
format 0:
1313
averageBitrate = 384000
1414
peakBitrate = 384000
@@ -18,30 +18,26 @@ track 0:
1818
sampleRate = 48000
1919
language = und
2020
sample 0:
21-
time = 64000
22-
flags = 1
23-
data = length 1536, hash 5D09685
24-
sample 1:
2521
time = 96000
2622
flags = 1
2723
data = length 1536, hash A9A24E44
28-
sample 2:
24+
sample 1:
2925
time = 128000
3026
flags = 1
3127
data = length 1536, hash 6F856273
32-
sample 3:
28+
sample 2:
3329
time = 160000
3430
flags = 1
3531
data = length 1536, hash B1737D3C
36-
sample 4:
32+
sample 3:
3733
time = 192000
3834
flags = 1
3935
data = length 1536, hash 98FDEB9D
40-
sample 5:
36+
sample 4:
4137
time = 224000
4238
flags = 1
4339
data = length 1536, hash 99B9B943
44-
sample 6:
40+
sample 5:
4541
time = 256000
4642
flags = 1
4743
data = length 1536, hash AAD9FCD2

testdata/src/test/assets/extractordumps/mp4/sample_ac3_fragmented.mp4.2.dump

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ seekMap:
77
getPosition(288000) = [[timeUs=0, position=636]]
88
numberOfTracks = 1
99
track 0:
10-
total output bytes = 6144
11-
sample count = 4
10+
total output bytes = 4608
11+
sample count = 3
1212
format 0:
1313
averageBitrate = 384000
1414
peakBitrate = 384000
@@ -18,18 +18,14 @@ track 0:
1818
sampleRate = 48000
1919
language = und
2020
sample 0:
21-
time = 160000
22-
flags = 1
23-
data = length 1536, hash B1737D3C
24-
sample 1:
2521
time = 192000
2622
flags = 1
2723
data = length 1536, hash 98FDEB9D
28-
sample 2:
24+
sample 1:
2925
time = 224000
3026
flags = 1
3127
data = length 1536, hash 99B9B943
32-
sample 3:
28+
sample 2:
3329
time = 256000
3430
flags = 1
3531
data = length 1536, hash AAD9FCD2

testdata/src/test/assets/extractordumps/mp4/sample_eac3_fragmented.mp4.1.dump

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ seekMap:
77
getPosition(1728000) = [[timeUs=0, position=638]]
88
numberOfTracks = 1
99
track 0:
10-
total output bytes = 148000
11-
sample count = 37
10+
total output bytes = 144000
11+
sample count = 36
1212
format 0:
1313
peakBitrate = 1000000
1414
id = 1
@@ -17,150 +17,146 @@ track 0:
1717
sampleRate = 48000
1818
language = und
1919
sample 0:
20-
time = 544000
21-
flags = 1
22-
data = length 4000, hash 27F20D29
23-
sample 1:
2420
time = 576000
2521
flags = 1
2622
data = length 4000, hash 6F565894
27-
sample 2:
23+
sample 1:
2824
time = 608000
2925
flags = 1
3026
data = length 4000, hash A6F07C4A
31-
sample 3:
27+
sample 2:
3228
time = 640000
3329
flags = 1
3430
data = length 4000, hash 3A0CA15C
35-
sample 4:
31+
sample 3:
3632
time = 672000
3733
flags = 1
3834
data = length 4000, hash DB365414
39-
sample 5:
35+
sample 4:
4036
time = 704000
4137
flags = 1
4238
data = length 4000, hash 31E08469
43-
sample 6:
39+
sample 5:
4440
time = 736000
4541
flags = 1
4642
data = length 4000, hash 315F5C28
47-
sample 7:
43+
sample 6:
4844
time = 768000
4945
flags = 1
5046
data = length 4000, hash CC65DF80
51-
sample 8:
47+
sample 7:
5248
time = 800000
5349
flags = 1
5450
data = length 4000, hash 503FB64C
55-
sample 9:
51+
sample 8:
5652
time = 832000
5753
flags = 1
5854
data = length 4000, hash 817CF735
59-
sample 10:
55+
sample 9:
6056
time = 864000
6157
flags = 1
6258
data = length 4000, hash 37391ADA
63-
sample 11:
59+
sample 10:
6460
time = 896000
6561
flags = 1
6662
data = length 4000, hash 37391ADA
67-
sample 12:
63+
sample 11:
6864
time = 928000
6965
flags = 1
7066
data = length 4000, hash 64DBF751
71-
sample 13:
67+
sample 12:
7268
time = 960000
7369
flags = 1
7470
data = length 4000, hash 81AE828E
75-
sample 14:
71+
sample 13:
7672
time = 992000
7773
flags = 1
7874
data = length 4000, hash 767D6C98
79-
sample 15:
75+
sample 14:
8076
time = 1024000
8177
flags = 1
8278
data = length 4000, hash A5F6D4E
83-
sample 16:
79+
sample 15:
8480
time = 1056000
8581
flags = 1
8682
data = length 4000, hash EABC6B0D
87-
sample 17:
83+
sample 16:
8884
time = 1088000
8985
flags = 1
9086
data = length 4000, hash F47EF742
91-
sample 18:
87+
sample 17:
9288
time = 1120000
9389
flags = 1
9490
data = length 4000, hash 9B2549DA
95-
sample 19:
91+
sample 18:
9692
time = 1152000
9793
flags = 1
9894
data = length 4000, hash A12733C9
99-
sample 20:
95+
sample 19:
10096
time = 1184000
10197
flags = 1
10298
data = length 4000, hash 95F62E99
103-
sample 21:
99+
sample 20:
104100
time = 1216000
105101
flags = 1
106102
data = length 4000, hash A4D858
107-
sample 22:
103+
sample 21:
108104
time = 1248000
109105
flags = 1
110106
data = length 4000, hash A4D858
111-
sample 23:
107+
sample 22:
112108
time = 1280000
113109
flags = 1
114110
data = length 4000, hash 22C1A129
115-
sample 24:
111+
sample 23:
116112
time = 1312000
117113
flags = 1
118114
data = length 4000, hash 2C51E4A1
119-
sample 25:
115+
sample 24:
120116
time = 1344000
121117
flags = 1
122118
data = length 4000, hash 3782E8BB
123-
sample 26:
119+
sample 25:
124120
time = 1376000
125121
flags = 1
126122
data = length 4000, hash 2C51E4A1
127-
sample 27:
123+
sample 26:
128124
time = 1408000
129125
flags = 1
130126
data = length 4000, hash BDB3D129
131-
sample 28:
127+
sample 27:
132128
time = 1440000
133129
flags = 1
134130
data = length 4000, hash F642A55
135-
sample 29:
131+
sample 28:
136132
time = 1472000
137133
flags = 1
138134
data = length 4000, hash 32F259F4
139-
sample 30:
135+
sample 29:
140136
time = 1504000
141137
flags = 1
142138
data = length 4000, hash 4C987B7C
143-
sample 31:
139+
sample 30:
144140
time = 1536000
145141
flags = 1
146142
data = length 4000, hash 57C98E1C
147-
sample 32:
143+
sample 31:
148144
time = 1568000
149145
flags = 1
150146
data = length 4000, hash 4C987B7C
151-
sample 33:
147+
sample 32:
152148
time = 1600000
153149
flags = 1
154150
data = length 4000, hash 4C987B7C
155-
sample 34:
151+
sample 33:
156152
time = 1632000
157153
flags = 1
158154
data = length 4000, hash 4C987B7C
159-
sample 35:
155+
sample 34:
160156
time = 1664000
161157
flags = 1
162158
data = length 4000, hash 4C987B7C
163-
sample 36:
159+
sample 35:
164160
time = 1696000
165161
flags = 1
166162
data = length 4000, hash 4C987B7C

0 commit comments

Comments
 (0)