SilenceSampleStream.readData: Handle flags-only buffers

The SampleStream.readData contract is that when reading a sample
with a flags-only buffer, the buffer timestamp and flags should
be set and the read position should not be advanced.

#minor-release

PiperOrigin-RevId: 357842130
This commit is contained in:
olly 2021-02-17 01:38:19 +00:00 committed by kim-vde
parent 5da9fd83e9
commit 2e5e1e7c0f

View File

@ -305,11 +305,15 @@ public final class SilenceMediaSource extends BaseMediaSource {
return C.RESULT_BUFFER_READ;
}
buffer.timeUs = getAudioPositionUs(positionBytes);
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
if (buffer.isFlagsOnly()) {
return C.RESULT_BUFFER_READ;
}
int bytesToWrite = (int) min(SILENCE_SAMPLE.length, bytesRemaining);
buffer.ensureSpaceForWrite(bytesToWrite);
buffer.data.put(SILENCE_SAMPLE, /* offset= */ 0, bytesToWrite);
buffer.timeUs = getAudioPositionUs(positionBytes);
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
positionBytes += bytesToWrite;
return C.RESULT_BUFFER_READ;
}