Skip to content
Permalink
Browse files

cliplogcvt: handle resample_process() failure

resample_process() returns -1 on rare occassions.  Fill in silence and
skip the rest of the input.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
  • Loading branch information...
stefanha committed Apr 1, 2018
1 parent 38875ee commit 021a87e2feb4c71722cf44f813553080dac93156
Showing with 12 additions and 3 deletions.
  1. +12 −3 cliplogcvt/cliplogcvt.cpp
@@ -51,7 +51,7 @@ class AudioBuffer
void setStereo();
void setMono();
void clear();
void resample(void *resampleState, double factor, bool drain);
bool resample(void *resampleState, double factor, bool drain);

float *getSamples();
int getFrames();
@@ -172,7 +172,8 @@ void AudioBuffer::clear()
memset(samples, 0, frames * channels * sizeof(float));
}

void AudioBuffer::resample(void *resampleState, double factor, bool drain)
/* Returns true on success, false on error (buffer remains unmodified) */
bool AudioBuffer::resample(void *resampleState, double factor, bool drain)
{
assert(channels == 1);

@@ -204,6 +205,10 @@ void AudioBuffer::resample(void *resampleState, double factor, bool drain)
&samples[inFrames], frames - inFrames,
drain, &inUsed,
&newSamples[outFrames], newFrames - outFrames);
if (ret < 0) {
delete [] newSamples;
return false;
}
inFrames += inUsed;
outFrames += ret;
}
@@ -221,6 +226,7 @@ void AudioBuffer::resample(void *resampleState, double factor, bool drain)
}
samples = newSamples;
needDelete = true;
return true;
}

float *AudioBuffer::getSamples()
@@ -371,7 +377,10 @@ static void transcode(FILE *infile, FILE *outfile, void **resampleState, VorbisE
*resampleState = resample_open(1, factor, factor);
}

abuf.resample(*resampleState, factor, drainResampler);
if (!abuf.resample(*resampleState, factor, drainResampler)) {
fillSilenceSamples(outfile, encoder, framesRemaining);
break;
}
}

if ((uint64_t)abuf.getFrames() > framesRemaining) {

0 comments on commit 021a87e

Please sign in to comment.
You can’t perform that action at this time.