From 6ad406446bd167fb91b388827f93c239b082124a Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Wed, 17 Dec 2008 06:22:05 +0000 Subject: [PATCH] Changed how the lavc audio decoder handles non-decodable audio packets. Previously, if decoding failed at any point in the audio stream, it would throw an exception that didn't get caught anywhere and hence crashed the program. Now, it'll just silently skip the broken packet and go on to next one, meaning that if the audio stream is actually corrupted and not just some weird stream with null packets you'll either get desyncs from the missing samples, or if the entire stream is non-decodable you'll just silence. tl;dr: Fixed loading of AAC files with the ffmpeg provider. Originally committed to SVN as r2507. --- aegisub/audio_provider_lavc.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/aegisub/audio_provider_lavc.cpp b/aegisub/audio_provider_lavc.cpp index cdb950bd1..93a1bfe87 100644 --- a/aegisub/audio_provider_lavc.cpp +++ b/aegisub/audio_provider_lavc.cpp @@ -223,18 +223,19 @@ void LAVCAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) int retval, decoded_bytes, decoded_samples; retval = avcodec_decode_audio2(codecContext, buffer, &temp_output_buffer_size, data, size); - if (retval <= 0) - throw _T("ffmpeg audio provider: failed to decode audio"); - /* decoding succeeded but the output buffer is empty, go to next packet */ - if (temp_output_buffer_size == 0) { - av_free_packet(&packet); + /* decoding failed, skip this packet and hope next one doesn't fail too */ + if (retval < 0) + break; + /* throw _T("ffmpeg audio provider: failed to decode audio"); */ + + size -= retval; + data += retval; + /* decoding succeeded but this audio frame is empty, continue to next frame */ + if (temp_output_buffer_size <= 0) continue; - } decoded_bytes = temp_output_buffer_size; decoded_samples = decoded_bytes / bytes_per_sample; /* FIXME: stop assuming everything is 16-bit! */ - size -= retval; - data += retval; /* do we need to resample? */ if (rsct) {