mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
MP3: Exclude VBRI frame from ToC position calculations
The current code assumes that the first Table of Contents segment
includes the `VBRI` frame, but I don't think this is correct and it
should only include real/audible MP3 ata - so this change updates the
logic to assume the first ToC segment starts at the frame **after** the
`VBRI` frame.
Issue: androidx/media#1904
PiperOrigin-RevId: 700269811
(cherry picked from commit f257e5511f)
This commit is contained in:
parent
7abfa764e1
commit
989c8f4fdb
6 changed files with 47 additions and 31 deletions
|
|
@ -15,8 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package androidx.media3.extractor.mp3;
|
package androidx.media3.extractor.mp3;
|
||||||
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
|
|
@ -63,15 +61,13 @@ import androidx.media3.extractor.SeekPoint;
|
||||||
int entrySize = frame.readUnsignedShort();
|
int entrySize = frame.readUnsignedShort();
|
||||||
frame.skipBytes(2);
|
frame.skipBytes(2);
|
||||||
|
|
||||||
long minPosition = position + mpegAudioHeader.frameSize;
|
position += mpegAudioHeader.frameSize;
|
||||||
// Read table of contents entries.
|
// Read table of contents entries.
|
||||||
long[] timesUs = new long[entryCount];
|
long[] timesUs = new long[entryCount];
|
||||||
long[] positions = new long[entryCount];
|
long[] positions = new long[entryCount];
|
||||||
for (int index = 0; index < entryCount; index++) {
|
for (int index = 0; index < entryCount; index++) {
|
||||||
timesUs[index] = (index * durationUs) / entryCount;
|
timesUs[index] = (index * durationUs) / entryCount;
|
||||||
// Ensure positions do not fall within the frame containing the VBRI header. This constraint
|
positions[index] = position;
|
||||||
// will normally only apply to the first entry in the table.
|
|
||||||
positions[index] = max(position, minPosition);
|
|
||||||
int segmentSize;
|
int segmentSize;
|
||||||
switch (entrySize) {
|
switch (entrySize) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ seekMap:
|
||||||
isSeekable = true
|
isSeekable = true
|
||||||
duration = 2808000
|
duration = 2808000
|
||||||
getPosition(0) = [[timeUs=0, position=141]]
|
getPosition(0) = [[timeUs=0, position=141]]
|
||||||
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10317]]
|
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10413]]
|
||||||
getPosition(1404000) = [[timeUs=1404000, position=19677]]
|
getPosition(1404000) = [[timeUs=1404000, position=19773]]
|
||||||
getPosition(2808000) = [[timeUs=2106000, position=29517]]
|
getPosition(2808000) = [[timeUs=2106000, position=29613]]
|
||||||
numberOfTracks = 1
|
numberOfTracks = 1
|
||||||
track 0:
|
track 0:
|
||||||
total output bytes = 38064
|
total output bytes = 38160
|
||||||
sample count = 116
|
sample count = 117
|
||||||
format 0:
|
format 0:
|
||||||
averageBitrate = 32000
|
averageBitrate = 32000
|
||||||
sampleMimeType = audio/mpeg
|
sampleMimeType = audio/mpeg
|
||||||
|
|
@ -480,4 +480,8 @@ track 0:
|
||||||
time = 2760000
|
time = 2760000
|
||||||
flags = 1
|
flags = 1
|
||||||
data = length 120, hash F562B52F
|
data = length 120, hash F562B52F
|
||||||
|
sample 116:
|
||||||
|
time = 2784000
|
||||||
|
flags = 1
|
||||||
|
data = length 96, hash FF8D5B98
|
||||||
tracksEnded = true
|
tracksEnded = true
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ seekMap:
|
||||||
isSeekable = true
|
isSeekable = true
|
||||||
duration = 2808000
|
duration = 2808000
|
||||||
getPosition(0) = [[timeUs=0, position=141]]
|
getPosition(0) = [[timeUs=0, position=141]]
|
||||||
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10317]]
|
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10413]]
|
||||||
getPosition(1404000) = [[timeUs=1404000, position=19677]]
|
getPosition(1404000) = [[timeUs=1404000, position=19773]]
|
||||||
getPosition(2808000) = [[timeUs=2106000, position=29517]]
|
getPosition(2808000) = [[timeUs=2106000, position=29613]]
|
||||||
numberOfTracks = 1
|
numberOfTracks = 1
|
||||||
track 0:
|
track 0:
|
||||||
total output bytes = 27792
|
total output bytes = 27888
|
||||||
sample count = 87
|
sample count = 88
|
||||||
format 0:
|
format 0:
|
||||||
averageBitrate = 32000
|
averageBitrate = 32000
|
||||||
sampleMimeType = audio/mpeg
|
sampleMimeType = audio/mpeg
|
||||||
|
|
@ -364,4 +364,8 @@ track 0:
|
||||||
time = 2766000
|
time = 2766000
|
||||||
flags = 1
|
flags = 1
|
||||||
data = length 120, hash F562B52F
|
data = length 120, hash F562B52F
|
||||||
|
sample 87:
|
||||||
|
time = 2790000
|
||||||
|
flags = 1
|
||||||
|
data = length 96, hash FF8D5B98
|
||||||
tracksEnded = true
|
tracksEnded = true
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ seekMap:
|
||||||
isSeekable = true
|
isSeekable = true
|
||||||
duration = 2808000
|
duration = 2808000
|
||||||
getPosition(0) = [[timeUs=0, position=141]]
|
getPosition(0) = [[timeUs=0, position=141]]
|
||||||
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10317]]
|
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10413]]
|
||||||
getPosition(1404000) = [[timeUs=1404000, position=19677]]
|
getPosition(1404000) = [[timeUs=1404000, position=19773]]
|
||||||
getPosition(2808000) = [[timeUs=2106000, position=29517]]
|
getPosition(2808000) = [[timeUs=2106000, position=29613]]
|
||||||
numberOfTracks = 1
|
numberOfTracks = 1
|
||||||
track 0:
|
track 0:
|
||||||
total output bytes = 18432
|
total output bytes = 18528
|
||||||
sample count = 58
|
sample count = 59
|
||||||
format 0:
|
format 0:
|
||||||
averageBitrate = 32000
|
averageBitrate = 32000
|
||||||
sampleMimeType = audio/mpeg
|
sampleMimeType = audio/mpeg
|
||||||
|
|
@ -248,4 +248,8 @@ track 0:
|
||||||
time = 2772000
|
time = 2772000
|
||||||
flags = 1
|
flags = 1
|
||||||
data = length 120, hash F562B52F
|
data = length 120, hash F562B52F
|
||||||
|
sample 58:
|
||||||
|
time = 2796000
|
||||||
|
flags = 1
|
||||||
|
data = length 96, hash FF8D5B98
|
||||||
tracksEnded = true
|
tracksEnded = true
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ seekMap:
|
||||||
isSeekable = true
|
isSeekable = true
|
||||||
duration = 2808000
|
duration = 2808000
|
||||||
getPosition(0) = [[timeUs=0, position=141]]
|
getPosition(0) = [[timeUs=0, position=141]]
|
||||||
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10317]]
|
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10413]]
|
||||||
getPosition(1404000) = [[timeUs=1404000, position=19677]]
|
getPosition(1404000) = [[timeUs=1404000, position=19773]]
|
||||||
getPosition(2808000) = [[timeUs=2106000, position=29517]]
|
getPosition(2808000) = [[timeUs=2106000, position=29613]]
|
||||||
numberOfTracks = 1
|
numberOfTracks = 1
|
||||||
track 0:
|
track 0:
|
||||||
total output bytes = 8592
|
total output bytes = 8688
|
||||||
sample count = 29
|
sample count = 30
|
||||||
format 0:
|
format 0:
|
||||||
averageBitrate = 32000
|
averageBitrate = 32000
|
||||||
sampleMimeType = audio/mpeg
|
sampleMimeType = audio/mpeg
|
||||||
|
|
@ -132,4 +132,8 @@ track 0:
|
||||||
time = 2778000
|
time = 2778000
|
||||||
flags = 1
|
flags = 1
|
||||||
data = length 120, hash F562B52F
|
data = length 120, hash F562B52F
|
||||||
|
sample 29:
|
||||||
|
time = 2802000
|
||||||
|
flags = 1
|
||||||
|
data = length 96, hash FF8D5B98
|
||||||
tracksEnded = true
|
tracksEnded = true
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ seekMap:
|
||||||
isSeekable = true
|
isSeekable = true
|
||||||
duration = 2808000
|
duration = 2808000
|
||||||
getPosition(0) = [[timeUs=0, position=141]]
|
getPosition(0) = [[timeUs=0, position=141]]
|
||||||
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10317]]
|
getPosition(1) = [[timeUs=0, position=141], [timeUs=702000, position=10413]]
|
||||||
getPosition(1404000) = [[timeUs=1404000, position=19677]]
|
getPosition(1404000) = [[timeUs=1404000, position=19773]]
|
||||||
getPosition(2808000) = [[timeUs=2106000, position=29517]]
|
getPosition(2808000) = [[timeUs=2106000, position=29613]]
|
||||||
numberOfTracks = 1
|
numberOfTracks = 1
|
||||||
track 0:
|
track 0:
|
||||||
total output bytes = 38064
|
total output bytes = 38160
|
||||||
sample count = 116
|
sample count = 117
|
||||||
format 0:
|
format 0:
|
||||||
averageBitrate = 32000
|
averageBitrate = 32000
|
||||||
sampleMimeType = audio/mpeg
|
sampleMimeType = audio/mpeg
|
||||||
|
|
@ -480,4 +480,8 @@ track 0:
|
||||||
time = 2760000
|
time = 2760000
|
||||||
flags = 1
|
flags = 1
|
||||||
data = length 120, hash F562B52F
|
data = length 120, hash F562B52F
|
||||||
|
sample 116:
|
||||||
|
time = 2784000
|
||||||
|
flags = 1
|
||||||
|
data = length 96, hash FF8D5B98
|
||||||
tracksEnded = true
|
tracksEnded = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue