Generate complete silent audio frames
`SilentAudioGenerator` could output a fractional audio frame, and this could cause downstream components to throw because of trying to read a complete audio frame but only seeing a partial one. Calculate the output buffer size based on the frame size (which is a no-op for stereo 16-bit audio) and calculate a total number of frames to output then multiple by the frame size. PiperOrigin-RevId: 494992941
This commit is contained in:
parent
e4f0b73aa3
commit
c17c23d1f1
@ -16,19 +16,21 @@
|
||||
|
||||
package com.google.android.exoplayer2.transformer;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* package */ final class SilentAudioGenerator {
|
||||
private static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||
private static final int DEFAULT_BUFFER_SIZE_FRAMES = 1024;
|
||||
|
||||
private final ByteBuffer internalBuffer;
|
||||
|
||||
private long remainingBytesToOutput;
|
||||
|
||||
public SilentAudioGenerator(long totalDurationUs, long sampleRate, int frameSize) {
|
||||
remainingBytesToOutput = (sampleRate * frameSize * totalDurationUs) / 1_000_000L;
|
||||
internalBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE).order(ByteOrder.nativeOrder());
|
||||
remainingBytesToOutput = frameSize * ((sampleRate * totalDurationUs) / C.MICROS_PER_SECOND);
|
||||
internalBuffer =
|
||||
ByteBuffer.allocate(DEFAULT_BUFFER_SIZE_FRAMES * frameSize).order(ByteOrder.nativeOrder());
|
||||
internalBuffer.flip();
|
||||
}
|
||||
|
||||
|
@ -370,8 +370,8 @@ sample:
|
||||
presentationTimeUs = 998459
|
||||
sample:
|
||||
trackIndex = 1
|
||||
dataHashCode = -1029274849
|
||||
size = 409
|
||||
dataHashCode = -587391743
|
||||
size = 408
|
||||
isKeyFrame = true
|
||||
presentationTimeUs = 1021679
|
||||
sample:
|
||||
|
Loading…
x
Reference in New Issue
Block a user