Skip to content

Commit

Permalink
Under some circumstances, the size of the buffer used for float conve…
Browse files Browse the repository at this point in the history
…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
jyavenard committed Nov 27, 2010
1 parent 47054f4 commit 239377b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 17 additions & 1 deletion mythtv/libs/libmyth/audiooutputbase.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 7 additions & 3 deletions mythtv/libs/libmyth/audiooutputbase.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 239377b

Please sign in to comment.