From 50b69baa0175c390bc56830988b06987d5a04cb7 Mon Sep 17 00:00:00 2001 From: paulc Date: Tue, 21 Oct 2014 11:56:46 +0000 Subject: [PATCH] Fixed PLC for the iSAC codec, caused memory corruption and crashes. git-svn-id: http://yate.null.ro/svn/yate/trunk@5918 acf43c95-373e-0410-b603-e72c3f656dc1 --- modules/isaccodec.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/isaccodec.cpp b/modules/isaccodec.cpp index ad6f8fde..332b9343 100644 --- a/modules/isaccodec.cpp +++ b/modules/isaccodec.cpp @@ -80,6 +80,14 @@ extern "C" { // Channel adaptive: set it to 0 to use default #define ISAC_RATE 32000 +// Maximum number of concealed lost frames, can be 1 or 2 +#define ISAC_MAX_PLC 2 + +#ifdef NO_ISAC_PLC +#undef ISAC_MAX_PLC +#define ISAC_MAX_PLC 1 +#endif + using namespace TelEngine; namespace { // anonymous @@ -273,11 +281,11 @@ unsigned long iSACCodec::Consume(const DataBlock& data, unsigned long tStamp, #ifndef NO_ISAC_PLC if (flags & DataMissed) { // guess how many frames were lost - int lost = (tStamp - timeStamp()) / 480; + int lost = (tStamp - timeStamp()) / m_encodeChunk; if (lost <= 0) lost = 1; - else if (lost > 2) - lost = 2; + else if (lost > ISAC_MAX_PLC) + lost = ISAC_MAX_PLC; #ifdef ISAC_FIXED res = WebRtcIsacfix_DecodePlc(m_isac,out,lost); #else @@ -409,8 +417,9 @@ bool iSACCodec::isacInit() res = WebRtcIsac_DecoderInit(m_isac); WebRtcIsac_SetDecSampRate(m_isac,sampleRate == 16000 ? kIsacWideband : kIsacSuperWideband); #endif - // Decode may return 480 or 960 samples - m_outData.assign(0,1920); + m_encodeChunk = (sampleRate == 16000) ? 480 : 960; + // Decode may return 480 or 960 samples except when doing PLC + m_outData.assign(0,m_encodeChunk * 2 * ISAC_MAX_PLC); } if (res == 0) { if (m_encoding) {