From d96a6e58ec9140f2b0ae6b244dc404ce6fe8ffac Mon Sep 17 00:00:00 2001 From: Alexander Kojevnikov Date: Sun, 8 Jan 2023 18:39:43 -0800 Subject: [PATCH] Fix decoding for m4a and ogg --- src/spek-audio.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/spek-audio.cc b/src/spek-audio.cc index bff43f2..82d7271 100644 --- a/src/spek-audio.cc +++ b/src/spek-audio.cc @@ -73,7 +73,7 @@ std::unique_ptr Audio::open(const std::string& file_name, int stream) AudioError error = AudioError::OK; AVFormatContext *format_context = nullptr; - if (avformat_open_input(&format_context, file_name.c_str(), nullptr, nullptr) != 0) { + if (avformat_open_input(&format_context, file_name.c_str(), nullptr, nullptr) < 0) { error = AudioError::CANNOT_OPEN_FILE; } @@ -275,8 +275,10 @@ int AudioFileImpl::read() this->packet->data += len; this->packet->size -= len; this->offset += len; - // We have data, return it and come back for more later. int samples = this->frame->nb_samples; + // Occasionally the frame has no samples, move on to the next one. + if (samples == 0) continue; + // We have data, return it and come back for more later. if (samples > this->buffer_len) { this->buffer = static_cast( av_realloc(this->buffer, samples * sizeof(float))