Skip to content

Commit

Permalink
Don't fail on empty audio blocks
Browse files Browse the repository at this point in the history
Summary:
When the provided sample count is zero, it means it's not explicitly provided and we may need to compute it according to the content block's size. This diff makes sure, that:
- we send a onAudioRead notification is sent in all cases
- we use the form that explicitly sets the size of the block, if we can't compute the sample's count based on the remaining size.

Reviewed By: kiminoue7

Differential Revision: D52225600

fbshipit-source-id: 9dbc0af8c242b1e3828959787e7052579d1315b2
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Dec 18, 2023
1 parent 0beb40f commit 0f78024
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions vrs/ContentBlockReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool AudioBlockReader::readAudioContentBlock(
size_t sampleCount = audioContent.getSampleCount();
if (sampleCount == 0) {
if (remainingBlockSize != ContentBlock::kSizeUnknown) {
if (audioContent.getAudioFormat() == AudioFormat::PCM) {
if (remainingBlockSize > 0 && audioContent.getAudioFormat() == AudioFormat::PCM) {
// The sample count is undefined, but we can to do the math,
// using the remaining bytes in the record.
uint8_t sampleBlockStride = audioContent.getSampleBlockStride();
Expand All @@ -160,10 +160,9 @@ bool AudioBlockReader::readAudioContentBlock(
static_cast<uint32_t>(remainingBlockSize / sampleBlockStride),
audioContent.getSampleBlockStride()));
}
} else {
return player.onAudioRead(
record, blockIndex_, ContentBlock(contentBlock, remainingBlockSize));
}
return player.onAudioRead(
record, blockIndex_, ContentBlock(contentBlock, remainingBlockSize));
}
} else {
size_t expectedSize = sampleCount * audioContent.getSampleBlockStride();
Expand Down

0 comments on commit 0f78024

Please sign in to comment.