From ae4fdf484681aae99f0f5ad3c71f391730b8e887 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 21 Jan 2019 10:02:37 +1100 Subject: [PATCH] fixed audio buffer size overflow on long clips --- playback/audio.cpp | 8 ++++---- playback/audio.h | 4 ++-- playback/cacher.cpp | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/playback/audio.cpp b/playback/audio.cpp index 19e2f656f..bfdf8972e 100644 --- a/playback/audio.cpp +++ b/playback/audio.cpp @@ -33,7 +33,7 @@ bool audio_rendering = false; bool recording = false; qint8 audio_ibuffer[audio_ibuffer_size]; -int audio_ibuffer_read = 0; +unsigned long audio_ibuffer_read = 0; long audio_ibuffer_frame = 0; double audio_ibuffer_timecode = 0; @@ -114,9 +114,9 @@ int current_audio_freq() { return audio_rendering ? sequence->audio_frequency : audio_output->format().sampleRate(); } -int get_buffer_offset_from_frame(double framerate, long frame) { +unsigned long get_buffer_offset_from_frame(double framerate, long frame) { if (frame >= audio_ibuffer_frame) { - return qFloor(((double) (frame - audio_ibuffer_frame)/framerate)*current_audio_freq())*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO); + return static_cast(((double(frame - audio_ibuffer_frame)/framerate)*current_audio_freq())*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)*av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO)); } else { qWarning() << "Invalid values passed to get_buffer_offset_from_frame"; return 0; @@ -168,7 +168,7 @@ int AudioSenderThread::send_audio_to_output(int offset, int max) { // send audio to device int actual_write = audio_io_device->write((const char*) audio_ibuffer+offset, max); - int audio_ibuffer_limit = audio_ibuffer_read + actual_write; + unsigned long audio_ibuffer_limit = audio_ibuffer_read + actual_write; // send samples to audio monitor cache // TODO make this work for the footage viewer - currently, enabling it causes crash due to an ASSERT diff --git a/playback/audio.h b/playback/audio.h index c2836a6f0..980641854 100644 --- a/playback/audio.h +++ b/playback/audio.h @@ -37,7 +37,7 @@ extern QMutex audio_write_lock; #define audio_ibuffer_size 192000 extern qint8 audio_ibuffer[audio_ibuffer_size]; -extern int audio_ibuffer_read; +extern unsigned long audio_ibuffer_read; extern long audio_ibuffer_frame; extern double audio_ibuffer_timecode; extern bool audio_scrub; @@ -51,7 +51,7 @@ bool is_audio_device_set(); void init_audio(); void stop_audio(); -int get_buffer_offset_from_frame(double framerate, long frame); +unsigned long get_buffer_offset_from_frame(double framerate, long frame); bool start_recording(); void stop_recording(); diff --git a/playback/cacher.cpp b/playback/cacher.cpp index 9770279d2..e11269088 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -364,7 +364,9 @@ void cache_audio_worker(Clip* c, bool scrubbing, QVector& nests) { if (frame->nb_samples == 0) { break; } else { - long buffer_timeline_out = get_buffer_offset_from_frame(c->sequence->frame_rate, timeline_out); + unsigned long buffer_timeline_out = get_buffer_offset_from_frame(c->sequence->frame_rate, timeline_out); + qDebug() << "bto:" << buffer_timeline_out; + audio_write_lock.lock(); while (c->frame_sample_index < nb_bytes