From 70b3936188316a058c05a48adc3c26e0f46337ed Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Mon, 14 Oct 2024 13:00:49 +0200 Subject: [PATCH] LibMedia: Handle EOF as end of stream in FFmpegLoader We were dealing with EOF by returning a generic I/O error, but Audio::Loader requires us to return empty chunks at the end of stream. --- Userland/Libraries/LibMedia/Audio/FFmpegLoader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibMedia/Audio/FFmpegLoader.cpp b/Userland/Libraries/LibMedia/Audio/FFmpegLoader.cpp index ffc21eba60b..ce38a961c78 100644 --- a/Userland/Libraries/LibMedia/Audio/FFmpegLoader.cpp +++ b/Userland/Libraries/LibMedia/Audio/FFmpegLoader.cpp @@ -260,8 +260,12 @@ ErrorOr>, LoaderError> FFmpegLoaderPlugin::load_chunks do { // Obtain a packet - if (av_read_frame(m_format_context, m_packet) < 0) + auto read_frame_error = av_read_frame(m_format_context, m_packet); + if (read_frame_error < 0) { + if (read_frame_error == AVERROR_EOF) + break; return LoaderError { LoaderError::Category::IO, "Failed to read frame" }; + } if (m_packet->stream_index != m_audio_stream->index) { av_packet_unref(m_packet); continue; @@ -278,7 +282,7 @@ ErrorOr>, LoaderError> FFmpegLoaderPlugin::load_chunks if (receive_frame_error == AVERROR(EAGAIN)) continue; if (receive_frame_error == AVERROR_EOF) - return Error::from_errno(EOF); + break; return LoaderError { LoaderError::Category::IO, "Failed to receive frame" }; }