From bf931df63577d9d903055469864468648084d8bf Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Thu, 14 Aug 2008 23:49:11 +0000 Subject: [PATCH] fix retarded breakage in previous commit. Originally committed to SVN as r2304. --- aegisub/audio_provider_lavc.cpp | 17 +++++++++-------- aegisub/audio_provider_lavc.h | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/aegisub/audio_provider_lavc.cpp b/aegisub/audio_provider_lavc.cpp index 9e352ee7f..14c3c086b 100644 --- a/aegisub/audio_provider_lavc.cpp +++ b/aegisub/audio_provider_lavc.cpp @@ -152,11 +152,8 @@ LAVCAudioProvider::LAVCAudioProvider(Aegisub::String _filename) if (!buffer) throw _T("ffmpeg audio provider: Failed to allocate audio decoding buffer, out of memory?"); - overshoot_buffer = (int16_t *)malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); - if (!overshoot_buffer) - throw _T("ffmpeg audio provider: Failed to allocate audio decoding buffer, out of memory?"); - - leftover_samples = 0; + leftover_samples = 0; + last_output_sample = -1; } catch (...) { Destroy(); @@ -174,8 +171,6 @@ void LAVCAudioProvider::Destroy() { if (buffer) free(buffer); - if (overshoot_buffer) - free(overshoot_buffer); if (rsct) audio_resample_close(rsct); if (codecContext) @@ -188,6 +183,12 @@ void LAVCAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) { int16_t *_buf = (int16_t *)buf; + /* this exception disabled for now */ + /* if (last_output_sample != start-1) + throw _T("ffmpeg audio provider: nonlinear access attempted, try loading audio to RAM or HD cache"); */ + + last_output_sample += count; + int64_t samples_to_decode = (num_samples - start) * channels; /* samples left to the end of the stream */ if (count < samples_to_decode) /* haven't reached the end yet, so just decode the requested number of samples */ samples_to_decode = count * channels; /* times the number of channels */ @@ -284,7 +285,7 @@ void LAVCAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) } } - samples_to_decode -= decoded_samples; + samples_to_decode -= decoded_samples; } } diff --git a/aegisub/audio_provider_lavc.h b/aegisub/audio_provider_lavc.h index 50a0dea7c..4f71cb425 100644 --- a/aegisub/audio_provider_lavc.h +++ b/aegisub/audio_provider_lavc.h @@ -76,6 +76,8 @@ private: int16_t *buffer; int16_t *overshoot_buffer; + int64_t last_output_sample; + int leftover_samples; void Destroy();