Skip to content

Commit

Permalink
Fix potential cash in mythtranscode.
Browse files Browse the repository at this point in the history
Fixes #10084
  • Loading branch information
jyavenard committed Oct 10, 2011
1 parent cb01f30 commit e89d6a9
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions mythtv/programs/mythtranscode/transcode.cpp
Expand Up @@ -45,14 +45,14 @@ class AudioReencodeBuffer : public AudioOutput
audiobuffer = new unsigned char[bufsize];

ab_count = 0;
memset(ab_len, 0, sizeof(ab_len));
memset(ab_offset, 0, sizeof(ab_offset));
memset(ab_time, 0, sizeof(ab_time));
ab_size = 128;
ab = new AudioBuffer[ab_size];
}

~AudioReencodeBuffer()
{
delete [] audiobuffer;
delete [] ab;
}

// reconfigure sound out for new params
Expand Down Expand Up @@ -92,8 +92,16 @@ class AudioReencodeBuffer : public AudioOutput
audiobuffer = tmpbuf;
}

ab_len[ab_count] = frames * bytes_per_frame;
ab_offset[ab_count] = audiobuffer_len;
if (ab_count >= ab_size)
{
AudioBuffer *tmp = new AudioBuffer[ab_size + 128];
memcpy(tmp, ab, sizeof(AudioBuffer) * ab_size);
delete[] ab;
ab = tmp;
ab_size += 128;
}
ab[ab_count].len = frames * bytes_per_frame;
ab[ab_count].offset = audiobuffer_len;

memcpy(audiobuffer + audiobuffer_len, buffer,
frames * bytes_per_frame);
Expand All @@ -102,7 +110,7 @@ class AudioReencodeBuffer : public AudioOutput
// last_audiotime is at the end of the sample
last_audiotime = timecode + frames * 1000 / eff_audiorate;

ab_time[ab_count] = last_audiotime;
ab[ab_count].time = last_audiotime;
ab_count++;

return true;
Expand Down Expand Up @@ -204,10 +212,15 @@ class AudioReencodeBuffer : public AudioOutput
virtual int readOutputData(unsigned char*, int ){ return 0; }

int bufsize;
int ab_count;
int ab_len[128];
int ab_offset[128];
long long ab_time[128];
uint ab_count;
struct AudioBuffer
{
int len;
int offset;
long long time;
};
AudioBuffer *ab;
uint ab_size;
unsigned char *audiobuffer;
int audiobuffer_len, channels, bits, bytes_per_frame, eff_audiorate;
long long last_audiotime;
Expand Down Expand Up @@ -1072,12 +1085,12 @@ int Transcode::TranscodeFile(
audioframesize = arb->audiobuffer_len;
if (arb->ab_count)
{
for (int loop = 0; loop < arb->ab_count; loop++)
for (uint loop = 0; loop < arb->ab_count; loop++)
{
nvr->SetOption("audioframesize", arb->ab_len[loop]);
nvr->WriteAudio(arb->audiobuffer + arb->ab_offset[loop],
nvr->SetOption("audioframesize", arb->ab[loop].len);
nvr->WriteAudio(arb->audiobuffer + arb->ab[loop].offset,
audioFrame++,
arb->ab_time[loop] - timecodeOffset);
arb->ab[loop].time - timecodeOffset);
if (nvr->IsErrored())
{
VERBOSE(VB_IMPORTANT, "Transcode: Encountered "
Expand Down

0 comments on commit e89d6a9

Please sign in to comment.