summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2011-10-10 05:07:55 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2011-10-10 05:26:19 (GMT)
commite89d6a9f7ed98cb60e32f0a0cfea674f573bb670 (patch)
tree228b0a0f44c69ad52bd520240856e401a028a6c3
parentcb01f3079a0eadf430178fefd5c2341235152fd1 (diff)
Fix potential cash in mythtranscode.
Fixes #10084
-rwxr-xr-xmythtv/programs/mythtranscode/transcode.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp
index 3e66f65..c39809d 100755
--- a/mythtv/programs/mythtranscode/transcode.cpp
+++ b/mythtv/programs/mythtranscode/transcode.cpp
@@ -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
@@ -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);
@@ -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;
@@ -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;
@@ -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 "