When hitting bad data, abort gracefully only if this is the last frame read

This commit is contained in:
emeric
2026-04-04 17:56:51 +02:00
parent 351c412dd3
commit 7f7c0ee187
+13 -1
View File
@@ -318,8 +318,20 @@ namespace lms::audio::ffmpeg
{
if (_inputPacket->stream_index == _inputStreamIndex)
{
const int sendError{ ::avcodec_send_packet(_decoderContext.get(), _inputPacket.get()) };
int sendError{ ::avcodec_send_packet(_decoderContext.get(), _inputPacket.get()) };
::av_packet_unref(_inputPacket.get());
if (sendError == AVERROR_INVALIDDATA)
{
// we may be close to the end of the file, abort gracefully *only* if next packet is EOF
const int peekError{ ::av_read_frame(_context.get(), _inputPacket.get()) };
::av_packet_unref(_inputPacket.get());
if (peekError == AVERROR_EOF)
{
LMS_LOG(AUDIO, DEBUG, "Invalid data in packet at end of file");
_eof = true;
sendError = 0;
}
}
if (sendError < 0)
throw FFmpegException{ "avcodec_send_packet failed", sendError };
}