From 27a1153b9140027283f7e5c12bd4d3383c93b54b Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 14 Jul 2022 00:01:59 -0700 Subject: [PATCH] [FLAC Decoder] Correctly handle zero length frames Apparently, the decoder is capable of returning zero length frames without having hit the end of the stream. Signed-off-by: Christopher Snowhill --- Plugins/Flac/FlacDecoder.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Plugins/Flac/FlacDecoder.m b/Plugins/Flac/FlacDecoder.m index f594cec6d..537dc4397 100644 --- a/Plugins/Flac/FlacDecoder.m +++ b/Plugins/Flac/FlacDecoder.m @@ -365,12 +365,14 @@ void ErrorCallback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorS id audioChunkClass = NSClassFromString(@"AudioChunk"); AudioChunk *chunk = nil; - if(FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) { - return nil; - } + while (blockBufferFrames <= 0) { + if(FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) { + return nil; + } - if(!FLAC__stream_decoder_process_single(decoder)) { - return nil; + if(!FLAC__stream_decoder_process_single(decoder)) { + return nil; + } } if(blockBufferFrames > 0) {