Justify MP3 ConstantBitrateSeeker frame size + add tests

PiperOrigin-RevId: 291702471
This commit is contained in:
kimvde 2020-01-27 13:19:20 +00:00 committed by Oliver Woodman
parent d312b6d4c2
commit 5a6cffcf6f
16 changed files with 1677 additions and 4 deletions

View File

@ -31,6 +31,9 @@ import com.google.android.exoplayer2.extractor.ConstantBitrateSeekMap;
*/ */
public ConstantBitrateSeeker( public ConstantBitrateSeeker(
long inputLength, long firstFramePosition, MpegAudioUtil.Header mpegAudioHeader) { long inputLength, long firstFramePosition, MpegAudioUtil.Header mpegAudioHeader) {
// Set the seeker frame size to the size of the first frame (even though some constant bitrate
// streams have variable frame sizes) to avoid the need to re-synchronize for constant frame
// size streams.
super(inputLength, firstFramePosition, mpegAudioHeader.bitrate, mpegAudioHeader.frameSize); super(inputLength, firstFramePosition, mpegAudioHeader.bitrate, mpegAudioHeader.frameSize);
} }

View File

@ -0,0 +1,463 @@
seekMap:
isSeekable = true
duration = 2821187
getPosition(0) = [[timeUs=0, position=240]]
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
width = -1
height = -1
frameRate = -1.0
rotationDegrees = 0
pixelWidthHeightRatio = 1.0
channelCount = 2
sampleRate = 44100
pcmEncoding = -1
encoderDelay = 0
encoderPadding = 0
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
metadata = null
initializationData:
total output bytes = 45139
sample count = 108
sample 0:
time = 0
flags = 1
data = length 417, hash C4565176
sample 1:
time = 26122
flags = 1
data = length 418, hash 70AEC448
sample 2:
time = 52244
flags = 1
data = length 418, hash 835A8FB9
sample 3:
time = 78367
flags = 1
data = length 418, hash 3A9672BF
sample 4:
time = 104489
flags = 1
data = length 418, hash 8DBE60F9
sample 5:
time = 130612
flags = 1
data = length 418, hash 23D0867B
sample 6:
time = 156734
flags = 1
data = length 418, hash 7780AAB9
sample 7:
time = 182857
flags = 1
data = length 418, hash 3F63B2D1
sample 8:
time = 208979
flags = 1
data = length 418, hash 7A33CEBD
sample 9:
time = 235102
flags = 1
data = length 418, hash DF31D514
sample 10:
time = 261224
flags = 1
data = length 418, hash 26FA2C86
sample 11:
time = 287346
flags = 1
data = length 418, hash D9C7FB1
sample 12:
time = 313469
flags = 1
data = length 418, hash B1C40DC8
sample 13:
time = 339591
flags = 1
data = length 418, hash 1C953BEE
sample 14:
time = 365714
flags = 1
data = length 418, hash A6053C6
sample 15:
time = 391836
flags = 1
data = length 418, hash 2D90325A
sample 16:
time = 417959
flags = 1
data = length 418, hash 11A84918
sample 17:
time = 444081
flags = 1
data = length 418, hash 30F1A19A
sample 18:
time = 470204
flags = 1
data = length 418, hash 70EC67FF
sample 19:
time = 496326
flags = 1
data = length 418, hash 7BAF5828
sample 20:
time = 522448
flags = 1
data = length 418, hash 8E43B85E
sample 21:
time = 548571
flags = 1
data = length 418, hash E9A5EE78
sample 22:
time = 574693
flags = 1
data = length 418, hash F79931F8
sample 23:
time = 600816
flags = 1
data = length 418, hash C0308B40
sample 24:
time = 626938
flags = 1
data = length 418, hash 3D2E55B
sample 25:
time = 653061
flags = 1
data = length 417, hash D74A61AF
sample 26:
time = 679183
flags = 1
data = length 418, hash 96F104B1
sample 27:
time = 705306
flags = 1
data = length 418, hash CE12216
sample 28:
time = 731428
flags = 1
data = length 418, hash 899EA46D
sample 29:
time = 757551
flags = 1
data = length 418, hash 1208BBC5
sample 30:
time = 783673
flags = 1
data = length 418, hash 49F22D4D
sample 31:
time = 809795
flags = 1
data = length 418, hash 56D959B0
sample 32:
time = 835918
flags = 1
data = length 418, hash 5EC6FF8C
sample 33:
time = 862040
flags = 1
data = length 418, hash 380B6E00
sample 34:
time = 888163
flags = 1
data = length 418, hash 19494E6B
sample 35:
time = 914285
flags = 1
data = length 418, hash C751B033
sample 36:
time = 940408
flags = 1
data = length 418, hash 5F7C6DBA
sample 37:
time = 966530
flags = 1
data = length 418, hash D77E6530
sample 38:
time = 992653
flags = 1
data = length 418, hash 48A694AB
sample 39:
time = 1018775
flags = 1
data = length 418, hash A979850E
sample 40:
time = 1044897
flags = 1
data = length 418, hash 7688E4B1
sample 41:
time = 1071020
flags = 1
data = length 418, hash 255AF933
sample 42:
time = 1097142
flags = 1
data = length 418, hash D58AC838
sample 43:
time = 1123265
flags = 1
data = length 418, hash A38DC7B
sample 44:
time = 1149387
flags = 1
data = length 418, hash EA0CA21
sample 45:
time = 1175510
flags = 1
data = length 418, hash DF99B54B
sample 46:
time = 1201632
flags = 1
data = length 418, hash A1532134
sample 47:
time = 1227755
flags = 1
data = length 418, hash 520EC187
sample 48:
time = 1253877
flags = 1
data = length 418, hash 5E38E4F
sample 49:
time = 1280000
flags = 1
data = length 417, hash 4D3526FB
sample 50:
time = 1306122
flags = 1
data = length 418, hash D99092CA
sample 51:
time = 1332244
flags = 1
data = length 418, hash EDB10D8E
sample 52:
time = 1358367
flags = 1
data = length 418, hash 5B5F6439
sample 53:
time = 1384489
flags = 1
data = length 418, hash 947E2739
sample 54:
time = 1410612
flags = 1
data = length 418, hash 8C1FF29C
sample 55:
time = 1436734
flags = 1
data = length 418, hash FEADC9C3
sample 56:
time = 1462857
flags = 1
data = length 418, hash BB82E0C8
sample 57:
time = 1488979
flags = 1
data = length 418, hash 8D1494AF
sample 58:
time = 1515102
flags = 1
data = length 418, hash E8C4265C
sample 59:
time = 1541224
flags = 1
data = length 418, hash BC8F59AE
sample 60:
time = 1567346
flags = 1
data = length 418, hash C8C5DCBD
sample 61:
time = 1593469
flags = 1
data = length 418, hash 43C3D85B
sample 62:
time = 1619591
flags = 1
data = length 418, hash 238C1AFE
sample 63:
time = 1645714
flags = 1
data = length 418, hash F6099191
sample 64:
time = 1671836
flags = 1
data = length 418, hash D236BB0E
sample 65:
time = 1697959
flags = 1
data = length 418, hash 58B5B714
sample 66:
time = 1724081
flags = 1
data = length 418, hash A9DDDD52
sample 67:
time = 1750204
flags = 1
data = length 418, hash 85E7D11E
sample 68:
time = 1776326
flags = 1
data = length 418, hash 9E9D8FF4
sample 69:
time = 1802448
flags = 1
data = length 418, hash 6FF9060D
sample 70:
time = 1828571
flags = 1
data = length 418, hash 4F1FC4F5
sample 71:
time = 1854693
flags = 1
data = length 418, hash EF9885AA
sample 72:
time = 1880816
flags = 1
data = length 418, hash 7872C242
sample 73:
time = 1906938
flags = 1
data = length 418, hash EB6FEAED
sample 74:
time = 1933061
flags = 1
data = length 417, hash B02D8CF0
sample 75:
time = 1959183
flags = 1
data = length 418, hash EFB6C2DD
sample 76:
time = 1985306
flags = 1
data = length 418, hash B733E449
sample 77:
time = 2011428
flags = 1
data = length 418, hash 617B155E
sample 78:
time = 2037551
flags = 1
data = length 418, hash AE626B2E
sample 79:
time = 2063673
flags = 1
data = length 418, hash F5E232C
sample 80:
time = 2089795
flags = 1
data = length 418, hash B5F4DC29
sample 81:
time = 2115918
flags = 1
data = length 418, hash C791E3B5
sample 82:
time = 2142040
flags = 1
data = length 418, hash F42A6BDB
sample 83:
time = 2168163
flags = 1
data = length 418, hash FDAEEFE6
sample 84:
time = 2194285
flags = 1
data = length 418, hash 62AC2513
sample 85:
time = 2220408
flags = 1
data = length 418, hash A4B46783
sample 86:
time = 2246530
flags = 1
data = length 418, hash 9B7DFEFE
sample 87:
time = 2272653
flags = 1
data = length 418, hash 4010F89A
sample 88:
time = 2298775
flags = 1
data = length 418, hash 33467FC1
sample 89:
time = 2324897
flags = 1
data = length 418, hash 1DFAE1E9
sample 90:
time = 2351020
flags = 1
data = length 418, hash C208D375
sample 91:
time = 2377142
flags = 1
data = length 418, hash CD430C30
sample 92:
time = 2403265
flags = 1
data = length 418, hash 5A6F8065
sample 93:
time = 2429387
flags = 1
data = length 418, hash 7177BD8B
sample 94:
time = 2455510
flags = 1
data = length 418, hash 51C1F29B
sample 95:
time = 2481632
flags = 1
data = length 418, hash 868A0084
sample 96:
time = 2507755
flags = 1
data = length 418, hash 1E9C03E1
sample 97:
time = 2533877
flags = 1
data = length 418, hash 10069B68
sample 98:
time = 2560000
flags = 1
data = length 417, hash CC5B751D
sample 99:
time = 2586122
flags = 1
data = length 418, hash 837D650
sample 100:
time = 2612244
flags = 1
data = length 418, hash 43B75632
sample 101:
time = 2638367
flags = 1
data = length 418, hash 86E0652
sample 102:
time = 2664489
flags = 1
data = length 418, hash 4DEC63E7
sample 103:
time = 2690612
flags = 1
data = length 418, hash F094F330
sample 104:
time = 2716734
flags = 1
data = length 418, hash 2C9CAA4
sample 105:
time = 2742857
flags = 1
data = length 418, hash 1E903FFE
sample 106:
time = 2768979
flags = 1
data = length 418, hash F276CF72
sample 107:
time = 2795102
flags = 1
data = length 418, hash 1C081463
tracksEnded = true

View File

@ -0,0 +1,319 @@
seekMap:
isSeekable = true
duration = 2821187
getPosition(0) = [[timeUs=0, position=240]]
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
width = -1
height = -1
frameRate = -1.0
rotationDegrees = 0
pixelWidthHeightRatio = 1.0
channelCount = 2
sampleRate = 44100
pcmEncoding = -1
encoderDelay = 0
encoderPadding = 0
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
metadata = null
initializationData:
total output bytes = 30093
sample count = 72
sample 0:
time = 940375
flags = 1
data = length 418, hash 5F7C6DBA
sample 1:
time = 966497
flags = 1
data = length 418, hash D77E6530
sample 2:
time = 992619
flags = 1
data = length 418, hash 48A694AB
sample 3:
time = 1018742
flags = 1
data = length 418, hash A979850E
sample 4:
time = 1044864
flags = 1
data = length 418, hash 7688E4B1
sample 5:
time = 1070987
flags = 1
data = length 418, hash 255AF933
sample 6:
time = 1097109
flags = 1
data = length 418, hash D58AC838
sample 7:
time = 1123232
flags = 1
data = length 418, hash A38DC7B
sample 8:
time = 1149354
flags = 1
data = length 418, hash EA0CA21
sample 9:
time = 1175477
flags = 1
data = length 418, hash DF99B54B
sample 10:
time = 1201599
flags = 1
data = length 418, hash A1532134
sample 11:
time = 1227721
flags = 1
data = length 418, hash 520EC187
sample 12:
time = 1253844
flags = 1
data = length 418, hash 5E38E4F
sample 13:
time = 1279966
flags = 1
data = length 417, hash 4D3526FB
sample 14:
time = 1306089
flags = 1
data = length 418, hash D99092CA
sample 15:
time = 1332211
flags = 1
data = length 418, hash EDB10D8E
sample 16:
time = 1358334
flags = 1
data = length 418, hash 5B5F6439
sample 17:
time = 1384456
flags = 1
data = length 418, hash 947E2739
sample 18:
time = 1410579
flags = 1
data = length 418, hash 8C1FF29C
sample 19:
time = 1436701
flags = 1
data = length 418, hash FEADC9C3
sample 20:
time = 1462823
flags = 1
data = length 418, hash BB82E0C8
sample 21:
time = 1488946
flags = 1
data = length 418, hash 8D1494AF
sample 22:
time = 1515068
flags = 1
data = length 418, hash E8C4265C
sample 23:
time = 1541191
flags = 1
data = length 418, hash BC8F59AE
sample 24:
time = 1567313
flags = 1
data = length 418, hash C8C5DCBD
sample 25:
time = 1593436
flags = 1
data = length 418, hash 43C3D85B
sample 26:
time = 1619558
flags = 1
data = length 418, hash 238C1AFE
sample 27:
time = 1645681
flags = 1
data = length 418, hash F6099191
sample 28:
time = 1671803
flags = 1
data = length 418, hash D236BB0E
sample 29:
time = 1697926
flags = 1
data = length 418, hash 58B5B714
sample 30:
time = 1724048
flags = 1
data = length 418, hash A9DDDD52
sample 31:
time = 1750170
flags = 1
data = length 418, hash 85E7D11E
sample 32:
time = 1776293
flags = 1
data = length 418, hash 9E9D8FF4
sample 33:
time = 1802415
flags = 1
data = length 418, hash 6FF9060D
sample 34:
time = 1828538
flags = 1
data = length 418, hash 4F1FC4F5
sample 35:
time = 1854660
flags = 1
data = length 418, hash EF9885AA
sample 36:
time = 1880783
flags = 1
data = length 418, hash 7872C242
sample 37:
time = 1906905
flags = 1
data = length 418, hash EB6FEAED
sample 38:
time = 1933028
flags = 1
data = length 417, hash B02D8CF0
sample 39:
time = 1959150
flags = 1
data = length 418, hash EFB6C2DD
sample 40:
time = 1985272
flags = 1
data = length 418, hash B733E449
sample 41:
time = 2011395
flags = 1
data = length 418, hash 617B155E
sample 42:
time = 2037517
flags = 1
data = length 418, hash AE626B2E
sample 43:
time = 2063640
flags = 1
data = length 418, hash F5E232C
sample 44:
time = 2089762
flags = 1
data = length 418, hash B5F4DC29
sample 45:
time = 2115885
flags = 1
data = length 418, hash C791E3B5
sample 46:
time = 2142007
flags = 1
data = length 418, hash F42A6BDB
sample 47:
time = 2168130
flags = 1
data = length 418, hash FDAEEFE6
sample 48:
time = 2194252
flags = 1
data = length 418, hash 62AC2513
sample 49:
time = 2220375
flags = 1
data = length 418, hash A4B46783
sample 50:
time = 2246497
flags = 1
data = length 418, hash 9B7DFEFE
sample 51:
time = 2272619
flags = 1
data = length 418, hash 4010F89A
sample 52:
time = 2298742
flags = 1
data = length 418, hash 33467FC1
sample 53:
time = 2324864
flags = 1
data = length 418, hash 1DFAE1E9
sample 54:
time = 2350987
flags = 1
data = length 418, hash C208D375
sample 55:
time = 2377109
flags = 1
data = length 418, hash CD430C30
sample 56:
time = 2403232
flags = 1
data = length 418, hash 5A6F8065
sample 57:
time = 2429354
flags = 1
data = length 418, hash 7177BD8B
sample 58:
time = 2455477
flags = 1
data = length 418, hash 51C1F29B
sample 59:
time = 2481599
flags = 1
data = length 418, hash 868A0084
sample 60:
time = 2507721
flags = 1
data = length 418, hash 1E9C03E1
sample 61:
time = 2533844
flags = 1
data = length 418, hash 10069B68
sample 62:
time = 2559966
flags = 1
data = length 417, hash CC5B751D
sample 63:
time = 2586089
flags = 1
data = length 418, hash 837D650
sample 64:
time = 2612211
flags = 1
data = length 418, hash 43B75632
sample 65:
time = 2638334
flags = 1
data = length 418, hash 86E0652
sample 66:
time = 2664456
flags = 1
data = length 418, hash 4DEC63E7
sample 67:
time = 2690579
flags = 1
data = length 418, hash F094F330
sample 68:
time = 2716701
flags = 1
data = length 418, hash 2C9CAA4
sample 69:
time = 2742823
flags = 1
data = length 418, hash 1E903FFE
sample 70:
time = 2768946
flags = 1
data = length 418, hash F276CF72
sample 71:
time = 2795068
flags = 1
data = length 418, hash 1C081463
tracksEnded = true

View File

@ -0,0 +1,175 @@
seekMap:
isSeekable = true
duration = 2821187
getPosition(0) = [[timeUs=0, position=240]]
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
width = -1
height = -1
frameRate = -1.0
rotationDegrees = 0
pixelWidthHeightRatio = 1.0
channelCount = 2
sampleRate = 44100
pcmEncoding = -1
encoderDelay = 0
encoderPadding = 0
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
metadata = null
initializationData:
total output bytes = 15046
sample count = 36
sample 0:
time = 1880812
flags = 1
data = length 418, hash 7872C242
sample 1:
time = 1906934
flags = 1
data = length 418, hash EB6FEAED
sample 2:
time = 1933056
flags = 1
data = length 417, hash B02D8CF0
sample 3:
time = 1959179
flags = 1
data = length 418, hash EFB6C2DD
sample 4:
time = 1985301
flags = 1
data = length 418, hash B733E449
sample 5:
time = 2011424
flags = 1
data = length 418, hash 617B155E
sample 6:
time = 2037546
flags = 1
data = length 418, hash AE626B2E
sample 7:
time = 2063669
flags = 1
data = length 418, hash F5E232C
sample 8:
time = 2089791
flags = 1
data = length 418, hash B5F4DC29
sample 9:
time = 2115914
flags = 1
data = length 418, hash C791E3B5
sample 10:
time = 2142036
flags = 1
data = length 418, hash F42A6BDB
sample 11:
time = 2168158
flags = 1
data = length 418, hash FDAEEFE6
sample 12:
time = 2194281
flags = 1
data = length 418, hash 62AC2513
sample 13:
time = 2220403
flags = 1
data = length 418, hash A4B46783
sample 14:
time = 2246526
flags = 1
data = length 418, hash 9B7DFEFE
sample 15:
time = 2272648
flags = 1
data = length 418, hash 4010F89A
sample 16:
time = 2298771
flags = 1
data = length 418, hash 33467FC1
sample 17:
time = 2324893
flags = 1
data = length 418, hash 1DFAE1E9
sample 18:
time = 2351016
flags = 1
data = length 418, hash C208D375
sample 19:
time = 2377138
flags = 1
data = length 418, hash CD430C30
sample 20:
time = 2403260
flags = 1
data = length 418, hash 5A6F8065
sample 21:
time = 2429383
flags = 1
data = length 418, hash 7177BD8B
sample 22:
time = 2455505
flags = 1
data = length 418, hash 51C1F29B
sample 23:
time = 2481628
flags = 1
data = length 418, hash 868A0084
sample 24:
time = 2507750
flags = 1
data = length 418, hash 1E9C03E1
sample 25:
time = 2533873
flags = 1
data = length 418, hash 10069B68
sample 26:
time = 2559995
flags = 1
data = length 417, hash CC5B751D
sample 27:
time = 2586118
flags = 1
data = length 418, hash 837D650
sample 28:
time = 2612240
flags = 1
data = length 418, hash 43B75632
sample 29:
time = 2638363
flags = 1
data = length 418, hash 86E0652
sample 30:
time = 2664485
flags = 1
data = length 418, hash 4DEC63E7
sample 31:
time = 2690607
flags = 1
data = length 418, hash F094F330
sample 32:
time = 2716730
flags = 1
data = length 418, hash 2C9CAA4
sample 33:
time = 2742852
flags = 1
data = length 418, hash 1E903FFE
sample 34:
time = 2768975
flags = 1
data = length 418, hash F276CF72
sample 35:
time = 2795097
flags = 1
data = length 418, hash 1C081463
tracksEnded = true

View File

@ -0,0 +1,31 @@
seekMap:
isSeekable = true
duration = 2821187
getPosition(0) = [[timeUs=0, position=240]]
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
width = -1
height = -1
frameRate = -1.0
rotationDegrees = 0
pixelWidthHeightRatio = 1.0
channelCount = 2
sampleRate = 44100
pcmEncoding = -1
encoderDelay = 0
encoderPadding = 0
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
metadata = null
initializationData:
total output bytes = 0
sample count = 0
tracksEnded = true

View File

@ -0,0 +1,463 @@
seekMap:
isSeekable = false
duration = UNSET TIME
getPosition(0) = [[timeUs=0, position=240]]
numberOfTracks = 1
track 0:
format:
bitrate = -1
id = null
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
width = -1
height = -1
frameRate = -1.0
rotationDegrees = 0
pixelWidthHeightRatio = 1.0
channelCount = 2
sampleRate = 44100
pcmEncoding = -1
encoderDelay = 0
encoderPadding = 0
subsampleOffsetUs = 9223372036854775807
selectionFlags = 0
language = null
drmInitData = -
metadata = null
initializationData:
total output bytes = 45139
sample count = 108
sample 0:
time = 0
flags = 1
data = length 417, hash C4565176
sample 1:
time = 26122
flags = 1
data = length 418, hash 70AEC448
sample 2:
time = 52244
flags = 1
data = length 418, hash 835A8FB9
sample 3:
time = 78367
flags = 1
data = length 418, hash 3A9672BF
sample 4:
time = 104489
flags = 1
data = length 418, hash 8DBE60F9
sample 5:
time = 130612
flags = 1
data = length 418, hash 23D0867B
sample 6:
time = 156734
flags = 1
data = length 418, hash 7780AAB9
sample 7:
time = 182857
flags = 1
data = length 418, hash 3F63B2D1
sample 8:
time = 208979
flags = 1
data = length 418, hash 7A33CEBD
sample 9:
time = 235102
flags = 1
data = length 418, hash DF31D514
sample 10:
time = 261224
flags = 1
data = length 418, hash 26FA2C86
sample 11:
time = 287346
flags = 1
data = length 418, hash D9C7FB1
sample 12:
time = 313469
flags = 1
data = length 418, hash B1C40DC8
sample 13:
time = 339591
flags = 1
data = length 418, hash 1C953BEE
sample 14:
time = 365714
flags = 1
data = length 418, hash A6053C6
sample 15:
time = 391836
flags = 1
data = length 418, hash 2D90325A
sample 16:
time = 417959
flags = 1
data = length 418, hash 11A84918
sample 17:
time = 444081
flags = 1
data = length 418, hash 30F1A19A
sample 18:
time = 470204
flags = 1
data = length 418, hash 70EC67FF
sample 19:
time = 496326
flags = 1
data = length 418, hash 7BAF5828
sample 20:
time = 522448
flags = 1
data = length 418, hash 8E43B85E
sample 21:
time = 548571
flags = 1
data = length 418, hash E9A5EE78
sample 22:
time = 574693
flags = 1
data = length 418, hash F79931F8
sample 23:
time = 600816
flags = 1
data = length 418, hash C0308B40
sample 24:
time = 626938
flags = 1
data = length 418, hash 3D2E55B
sample 25:
time = 653061
flags = 1
data = length 417, hash D74A61AF
sample 26:
time = 679183
flags = 1
data = length 418, hash 96F104B1
sample 27:
time = 705306
flags = 1
data = length 418, hash CE12216
sample 28:
time = 731428
flags = 1
data = length 418, hash 899EA46D
sample 29:
time = 757551
flags = 1
data = length 418, hash 1208BBC5
sample 30:
time = 783673
flags = 1
data = length 418, hash 49F22D4D
sample 31:
time = 809795
flags = 1
data = length 418, hash 56D959B0
sample 32:
time = 835918
flags = 1
data = length 418, hash 5EC6FF8C
sample 33:
time = 862040
flags = 1
data = length 418, hash 380B6E00
sample 34:
time = 888163
flags = 1
data = length 418, hash 19494E6B
sample 35:
time = 914285
flags = 1
data = length 418, hash C751B033
sample 36:
time = 940408
flags = 1
data = length 418, hash 5F7C6DBA
sample 37:
time = 966530
flags = 1
data = length 418, hash D77E6530
sample 38:
time = 992653
flags = 1
data = length 418, hash 48A694AB
sample 39:
time = 1018775
flags = 1
data = length 418, hash A979850E
sample 40:
time = 1044897
flags = 1
data = length 418, hash 7688E4B1
sample 41:
time = 1071020
flags = 1
data = length 418, hash 255AF933
sample 42:
time = 1097142
flags = 1
data = length 418, hash D58AC838
sample 43:
time = 1123265
flags = 1
data = length 418, hash A38DC7B
sample 44:
time = 1149387
flags = 1
data = length 418, hash EA0CA21
sample 45:
time = 1175510
flags = 1
data = length 418, hash DF99B54B
sample 46:
time = 1201632
flags = 1
data = length 418, hash A1532134
sample 47:
time = 1227755
flags = 1
data = length 418, hash 520EC187
sample 48:
time = 1253877
flags = 1
data = length 418, hash 5E38E4F
sample 49:
time = 1280000
flags = 1
data = length 417, hash 4D3526FB
sample 50:
time = 1306122
flags = 1
data = length 418, hash D99092CA
sample 51:
time = 1332244
flags = 1
data = length 418, hash EDB10D8E
sample 52:
time = 1358367
flags = 1
data = length 418, hash 5B5F6439
sample 53:
time = 1384489
flags = 1
data = length 418, hash 947E2739
sample 54:
time = 1410612
flags = 1
data = length 418, hash 8C1FF29C
sample 55:
time = 1436734
flags = 1
data = length 418, hash FEADC9C3
sample 56:
time = 1462857
flags = 1
data = length 418, hash BB82E0C8
sample 57:
time = 1488979
flags = 1
data = length 418, hash 8D1494AF
sample 58:
time = 1515102
flags = 1
data = length 418, hash E8C4265C
sample 59:
time = 1541224
flags = 1
data = length 418, hash BC8F59AE
sample 60:
time = 1567346
flags = 1
data = length 418, hash C8C5DCBD
sample 61:
time = 1593469
flags = 1
data = length 418, hash 43C3D85B
sample 62:
time = 1619591
flags = 1
data = length 418, hash 238C1AFE
sample 63:
time = 1645714
flags = 1
data = length 418, hash F6099191
sample 64:
time = 1671836
flags = 1
data = length 418, hash D236BB0E
sample 65:
time = 1697959
flags = 1
data = length 418, hash 58B5B714
sample 66:
time = 1724081
flags = 1
data = length 418, hash A9DDDD52
sample 67:
time = 1750204
flags = 1
data = length 418, hash 85E7D11E
sample 68:
time = 1776326
flags = 1
data = length 418, hash 9E9D8FF4
sample 69:
time = 1802448
flags = 1
data = length 418, hash 6FF9060D
sample 70:
time = 1828571
flags = 1
data = length 418, hash 4F1FC4F5
sample 71:
time = 1854693
flags = 1
data = length 418, hash EF9885AA
sample 72:
time = 1880816
flags = 1
data = length 418, hash 7872C242
sample 73:
time = 1906938
flags = 1
data = length 418, hash EB6FEAED
sample 74:
time = 1933061
flags = 1
data = length 417, hash B02D8CF0
sample 75:
time = 1959183
flags = 1
data = length 418, hash EFB6C2DD
sample 76:
time = 1985306
flags = 1
data = length 418, hash B733E449
sample 77:
time = 2011428
flags = 1
data = length 418, hash 617B155E
sample 78:
time = 2037551
flags = 1
data = length 418, hash AE626B2E
sample 79:
time = 2063673
flags = 1
data = length 418, hash F5E232C
sample 80:
time = 2089795
flags = 1
data = length 418, hash B5F4DC29
sample 81:
time = 2115918
flags = 1
data = length 418, hash C791E3B5
sample 82:
time = 2142040
flags = 1
data = length 418, hash F42A6BDB
sample 83:
time = 2168163
flags = 1
data = length 418, hash FDAEEFE6
sample 84:
time = 2194285
flags = 1
data = length 418, hash 62AC2513
sample 85:
time = 2220408
flags = 1
data = length 418, hash A4B46783
sample 86:
time = 2246530
flags = 1
data = length 418, hash 9B7DFEFE
sample 87:
time = 2272653
flags = 1
data = length 418, hash 4010F89A
sample 88:
time = 2298775
flags = 1
data = length 418, hash 33467FC1
sample 89:
time = 2324897
flags = 1
data = length 418, hash 1DFAE1E9
sample 90:
time = 2351020
flags = 1
data = length 418, hash C208D375
sample 91:
time = 2377142
flags = 1
data = length 418, hash CD430C30
sample 92:
time = 2403265
flags = 1
data = length 418, hash 5A6F8065
sample 93:
time = 2429387
flags = 1
data = length 418, hash 7177BD8B
sample 94:
time = 2455510
flags = 1
data = length 418, hash 51C1F29B
sample 95:
time = 2481632
flags = 1
data = length 418, hash 868A0084
sample 96:
time = 2507755
flags = 1
data = length 418, hash 1E9C03E1
sample 97:
time = 2533877
flags = 1
data = length 418, hash 10069B68
sample 98:
time = 2560000
flags = 1
data = length 417, hash CC5B751D
sample 99:
time = 2586122
flags = 1
data = length 418, hash 837D650
sample 100:
time = 2612244
flags = 1
data = length 418, hash 43B75632
sample 101:
time = 2638367
flags = 1
data = length 418, hash 86E0652
sample 102:
time = 2664489
flags = 1
data = length 418, hash 4DEC63E7
sample 103:
time = 2690612
flags = 1
data = length 418, hash F094F330
sample 104:
time = 2716734
flags = 1
data = length 418, hash 2C9CAA4
sample 105:
time = 2742857
flags = 1
data = length 418, hash 1E903FFE
sample 106:
time = 2768979
flags = 1
data = length 418, hash F276CF72
sample 107:
time = 2795102
flags = 1
data = length 418, hash 1C081463
tracksEnded = true

View File

@ -103,7 +103,7 @@ public class FlacMetadataReaderTest {
@Test @Test
public void checkAndPeekStreamMarker_invalidData_isFalse() throws Exception { public void checkAndPeekStreamMarker_invalidData_isFalse() throws Exception {
ExtractorInput input = buildExtractorInput("mp3/bear.mp3"); ExtractorInput input = buildExtractorInput("mp3/bear-xing-header.mp3");
boolean result = FlacMetadataReader.checkAndPeekStreamMarker(input); boolean result = FlacMetadataReader.checkAndPeekStreamMarker(input);
@ -163,7 +163,7 @@ public class FlacMetadataReaderTest {
@Test @Test
public void readStreamMarker_invalidData_throwsException() throws Exception { public void readStreamMarker_invalidData_throwsException() throws Exception {
ExtractorInput input = buildExtractorInput("mp3/bear.mp3"); ExtractorInput input = buildExtractorInput("mp3/bear-xing-header.mp3");
assertThrows(ParserException.class, () -> FlacMetadataReader.readStreamMarker(input)); assertThrows(ParserException.class, () -> FlacMetadataReader.readStreamMarker(input));
} }

View File

@ -0,0 +1,213 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.extractor.mp3;
import static com.google.common.truth.Truth.assertThat;
import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.testutil.FakeExtractorOutput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Tests for {@link ConstantBitrateSeeker}. */
@RunWith(AndroidJUnit4.class)
public class ConstantBitrateSeekerTest {
private static final String CONSTANT_FRAME_SIZE_TEST_FILE =
"mp3/bear-cbr-constant-frame-size-no-seek-table.mp3";
private static final String VARIABLE_FRAME_SIZE_TEST_FILE =
"mp3/bear-cbr-variable-frame-size-no-seek-table.mp3";
private Mp3Extractor extractor;
private FakeExtractorOutput extractorOutput;
private DefaultDataSource dataSource;
@Before
public void setUp() throws Exception {
extractor = new Mp3Extractor();
extractorOutput = new FakeExtractorOutput();
dataSource =
new DefaultDataSourceFactory(ApplicationProvider.getApplicationContext(), "UserAgent")
.createDataSource();
}
@Test
public void mp3ExtractorReads_returnSeekableCbrSeeker() throws IOException, InterruptedException {
Uri fileUri = TestUtil.buildAssetUri(CONSTANT_FRAME_SIZE_TEST_FILE);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
assertThat(seekMap.getClass()).isEqualTo(ConstantBitrateSeeker.class);
assertThat(seekMap.getDurationUs()).isEqualTo(2_784_000);
assertThat(seekMap.isSeekable()).isTrue();
}
@Test
public void seeking_handlesSeekToZero() throws IOException, InterruptedException {
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = 0;
int extractedFrameIndex =
TestUtil.seekToTimeUs(
extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekIsExactFrame(
fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
@Test
public void seeking_handlesSeekToEoF() throws IOException, InterruptedException {
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = seekMap.getDurationUs();
int extractedFrameIndex =
TestUtil.seekToTimeUs(
extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekIsExactFrame(
fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
@Test
public void seeking_handlesSeekingBackward() throws IOException, InterruptedException {
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 1_234_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 987_000;
int extractedFrameIndex =
TestUtil.seekToTimeUs(
extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekIsExactFrame(
fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
@Test
public void seeking_handlesSeekingForward() throws IOException, InterruptedException {
String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 987_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 1_234_000;
int extractedFrameIndex =
TestUtil.seekToTimeUs(
extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekIsExactFrame(
fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
@Test
public void seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame()
throws IOException, InterruptedException {
String fileName = VARIABLE_FRAME_SIZE_TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = 1_234_000;
int extractedFrameIndex =
TestUtil.seekToTimeUs(
extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame(
fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
private static void assertFirstFrameAfterSeekIsExactFrame(
String fileName,
FakeTrackOutput trackOutput,
long targetSeekTimeUs,
int firstFrameIndexAfterSeek)
throws IOException, InterruptedException {
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
assertThat(trackOutput.getSampleData(firstFrameIndexAfterSeek))
.isEqualTo(expectedTrackOutput.getSampleData(exactFrameIndex));
}
private static void assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame(
String fileName,
FakeTrackOutput trackOutput,
long targetSeekTimeUs,
int firstFrameIndexAfterSeek)
throws IOException, InterruptedException {
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
boolean foundPreviousFrame =
exactFrameIndex != 0
&& Arrays.equals(
trackOutput.getSampleData(firstFrameIndexAfterSeek),
expectedTrackOutput.getSampleData(exactFrameIndex - 1));
boolean foundExactFrame =
Arrays.equals(
trackOutput.getSampleData(firstFrameIndexAfterSeek),
expectedTrackOutput.getSampleData(exactFrameIndex));
boolean foundNextFrame =
exactFrameIndex != expectedTrackOutput.getSampleCount() - 1
&& Arrays.equals(
trackOutput.getSampleData(firstFrameIndexAfterSeek),
expectedTrackOutput.getSampleData(exactFrameIndex + 1));
assertThat(foundPreviousFrame || foundExactFrame || foundNextFrame).isTrue();
}
private static FakeTrackOutput getExpectedTrackOutput(String fileName)
throws IOException, InterruptedException {
return TestUtil.extractAllSamplesFromFile(
new Mp3Extractor(), ApplicationProvider.getApplicationContext(), fileName)
.trackOutputs
.get(0);
}
private static int getFrameIndex(FakeTrackOutput trackOutput, long targetSeekTimeUs) {
List<Long> frameTimes = trackOutput.getSampleTimesUs();
return Util.binarySearchFloor(
frameTimes, targetSeekTimeUs, /* inclusive= */ true, /* stayInBounds= */ false);
}
}

View File

@ -25,8 +25,14 @@ import org.junit.runner.RunWith;
public final class Mp3ExtractorTest { public final class Mp3ExtractorTest {
@Test @Test
public void testMp3Sample() throws Exception { public void testMp3SampleWithXingHeader() throws Exception {
ExtractorAsserts.assertBehavior(Mp3Extractor::new, "mp3/bear.mp3"); ExtractorAsserts.assertBehavior(Mp3Extractor::new, "mp3/bear-xing-header.mp3");
}
@Test
public void testMp3SampleWithCbrSeeker() throws Exception {
ExtractorAsserts.assertBehavior(
Mp3Extractor::new, "mp3/bear-cbr-variable-frame-size-no-seek-table.mp3");
} }
@Test @Test