From 0f780245888124a034e1ee5892c02f83f0d636f6 Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Mon, 18 Dec 2023 12:20:10 -0800 Subject: [PATCH] Don't fail on empty audio blocks 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 --- vrs/ContentBlockReader.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vrs/ContentBlockReader.cpp b/vrs/ContentBlockReader.cpp index 3fe28040..c3a90849 100644 --- a/vrs/ContentBlockReader.cpp +++ b/vrs/ContentBlockReader.cpp @@ -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(); @@ -160,10 +160,9 @@ bool AudioBlockReader::readAudioContentBlock( static_cast(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();