Permalink
Browse files

Under some circumstances, the size of the buffer used for float conve…

…rsion 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
  • Loading branch information...
1 parent 47054f4 commit 239377ba8a2420c2f80bf70c045fac472542e1db @jyavenard jyavenard committed Nov 27, 2010
Showing with 24 additions and 4 deletions.
  1. +17 −1 mythtv/libs/libmyth/audiooutputbase.cpp
  2. +7 −3 mythtv/libs/libmyth/audiooutputbase.h
View
18 mythtv/libs/libmyth/audiooutputbase.cpp
@@ -93,14 +93,14 @@ 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)
{
src_in = (float *)AOALIGN(src_in_buf);
// 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;
}
View
10 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];

0 comments on commit 239377b

Please sign in to comment.