mirror of
https://github.com/androidx/media.git
synced 2025-05-16 20:19:57 +08:00
Don't use WavHeader.averageBytesPerSecond
It's unreliable for at least one IMA ADPCM file I've found. Calculating the blockIndex to seek to using exact properties also seems more robust. Note this doesn't change anything for the existing PCM test, since averageBytesPerSecond is set correctly. It does make a difference for an upcoming IMA ADPCM test though. PiperOrigin-RevId: 287814947
This commit is contained in:
parent
3cf88bb48b
commit
1edcc6c4f7
@ -203,7 +203,7 @@ public final class WavExtractor implements Extractor {
|
||||
/* id= */ null,
|
||||
MimeTypes.AUDIO_RAW,
|
||||
/* codecs= */ null,
|
||||
/* bitrate= */ header.averageBytesPerSecond * 8,
|
||||
/* bitrate= */ header.frameRateHz * bytesPerFrame * 8,
|
||||
targetSampleSize,
|
||||
header.numChannels,
|
||||
header.frameRateHz,
|
||||
|
@ -49,20 +49,18 @@ import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
@Override
|
||||
public SeekPoints getSeekPoints(long timeUs) {
|
||||
// Calculate the expected number of bytes of sample data corresponding to the requested time.
|
||||
long positionOffset = (timeUs * wavHeader.averageBytesPerSecond) / C.MICROS_PER_SECOND;
|
||||
// Calculate the containing block index, constraining to valid indices.
|
||||
long blockSize = wavHeader.blockSize;
|
||||
long blockIndex = Util.constrainValue(positionOffset / blockSize, 0, blockCount - 1);
|
||||
long blockIndex = (timeUs * wavHeader.frameRateHz) / (C.MICROS_PER_SECOND * framesPerBlock);
|
||||
blockIndex = Util.constrainValue(blockIndex, 0, blockCount - 1);
|
||||
|
||||
long seekPosition = firstBlockPosition + (blockIndex * blockSize);
|
||||
long seekPosition = firstBlockPosition + (blockIndex * wavHeader.blockSize);
|
||||
long seekTimeUs = blockIndexToTimeUs(blockIndex);
|
||||
SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
|
||||
if (seekTimeUs >= timeUs || blockIndex == blockCount - 1) {
|
||||
return new SeekPoints(seekPoint);
|
||||
} else {
|
||||
long secondBlockIndex = blockIndex + 1;
|
||||
long secondSeekPosition = firstBlockPosition + (secondBlockIndex * blockSize);
|
||||
long secondSeekPosition = firstBlockPosition + (secondBlockIndex * wavHeader.blockSize);
|
||||
long secondSeekTimeUs = blockIndexToTimeUs(secondBlockIndex);
|
||||
SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
|
||||
return new SeekPoints(seekPoint, secondSeekPoint);
|
||||
|
Loading…
x
Reference in New Issue
Block a user