summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2010-11-27 10:00:17 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2010-11-27 10:00:17 (GMT)
commit239377ba8a2420c2f80bf70c045fac472542e1db (patch)
tree4b9fdbd2ad106fc96aafde7869a5350f9809857a
parent47054f4f197b6664165effc0d8a936ccda40bb8b (diff)
Under some circumstances, the size of the buffer used for float conversion was too small. So we increase it to the maximum theorical size used by ffmpeg. Also identified an issue where the buffer used for resampling could be too small (if resampling factor is > 4). This fix the memory corruption seen in #9282. This doesn't fix the other problem reported with videos playing too fast. I expect to be a problem introduced with #8500.
git-svn-id: http://svn.mythtv.org/svn/trunk@27358 7dbf422c-18fa-0310-86e9-fd20926502f2
-rw-r--r--mythtv/libs/libmyth/audiooutputbase.cpp18
-rw-r--r--mythtv/libs/libmyth/audiooutputbase.h10
2 files changed, 24 insertions, 4 deletions
diff --git a/mythtv/libs/libmyth/audiooutputbase.cpp b/mythtv/libs/libmyth/audiooutputbase.cpp
index e79976f..aa2ae32 100644
--- a/mythtv/libs/libmyth/audiooutputbase.cpp
+++ b/mythtv/libs/libmyth/audiooutputbase.cpp
@@ -93,6 +93,7 @@ AudioOutputBase::AudioOutputBase(const AudioSettings &settings) :
memory_corruption_test0(0xdeadbeef),
memory_corruption_test1(0xdeadbeef),
+ src_out(NULL), kAudioSRCOutputSize(0),
memory_corruption_test2(0xdeadbeef),
memory_corruption_test3(0xdeadbeef)
{
@@ -100,7 +101,6 @@ AudioOutputBase::AudioOutputBase(const AudioSettings &settings) :
// The following are not bzero() because MS Windows doesn't like it.
memset(&src_data, 0, sizeof(SRC_DATA));
memset(src_in, 0, sizeof(float) * kAudioSRCInputSize);
- memset(src_out, 0, sizeof(float) * kAudioSRCOutputSize);
memset(audiobuffer, 0, sizeof(char) * kAudioRingBufferSize);
// Default SRC quality - QUALITY_HIGH is quite expensive
@@ -474,6 +474,16 @@ void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
src_data.src_ratio = (double)samplerate / settings.samplerate;
src_data.data_in = src_in;
+ if (kAudioSRCOutputSize < (int)
+ ((float)kAudioSRCInputSize * samplerate / settings.samplerate) + 1)
+ {
+ kAudioSRCOutputSize = (int)
+ ((float) kAudioSRCInputSize * samplerate /
+ settings.samplerate) + 1;
+ if (src_out)
+ delete[] src_out;
+ src_out = new float[kAudioSRCOutputSize];
+ }
src_data.data_out = src_out;
src_data.output_frames = kAudioSRCOutputSize;
src_data.end_of_input = 0;
@@ -645,6 +655,12 @@ void AudioOutputBase::KillAudio()
if (src_ctx)
{
src_delete(src_ctx);
+ if (kAudioSRCOutputSize > 0)
+ {
+ kAudioSRCOutputSize = 0;
+ delete[] src_out;
+ src_out = NULL;
+ }
src_ctx = NULL;
}
diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h
index f46928d..3f82821 100644
--- a/mythtv/libs/libmyth/audiooutputbase.h
+++ b/mythtv/libs/libmyth/audiooutputbase.h
@@ -19,6 +19,10 @@ using namespace std;
#include "samplerate.h"
#include "mythverbose.h"
+// make sure AVCODEC_MAX_AUDIO_FRAME_SIZE definition match the one in
+// libavcodec/avcodec.h
+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
+
#define VBAUDIO(str) VERBOSE(VB_AUDIO, LOC + str)
#define VBAUDIOTS(str) VERBOSE(VB_AUDIO+VB_TIMESTAMP, LOC + str)
#define VBGENERAL(str) VERBOSE(VB_GENERAL, LOC + str)
@@ -95,8 +99,7 @@ class AudioOutputBase : public AudioOutput, public QThread
virtual void bufferOutputData(bool y){ buffer_output_data_for_use = y; }
virtual int readOutputData(unsigned char *read_buffer, int max_length);
- static const uint kAudioSRCInputSize = 16384<<1;
- static const uint kAudioSRCOutputSize = 16384<<3;
+ static const uint kAudioSRCInputSize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
/// Audio Buffer Size -- should be divisible by 32,24,16,12,10,8,6,4,2..
static const uint kAudioRingBufferSize = 3072000;
@@ -224,7 +227,8 @@ class AudioOutputBase : public AudioOutput, public QThread
uint memory_corruption_test0;
float src_in_buf[kAudioSRCInputSize + 16];
uint memory_corruption_test1;
- float src_out[kAudioSRCOutputSize];
+ float *src_out;
+ int kAudioSRCOutputSize;
uint memory_corruption_test2;
/** main audio buffer */
uchar audiobuffer[kAudioRingBufferSize];