From 52897c2fda8d1d97796af1477c2748e3a2f25436 Mon Sep 17 00:00:00 2001 From: Dharmaray Kundargi Date: Wed, 26 Jan 2011 21:46:15 -0800 Subject: [PATCH] Fixed the SRC interface bug - 3369860 Change-Id: I6b866d334af9c9aea1db0295bf19edbc4123293d --- .../vss/common/inc/VideoEditorResampler.h | 1 + libvideoeditor/vss/mcs/src/M4MCS_API.c | 8 +++- libvideoeditor/vss/src/M4VSS3GPP_AudioMixing.c | 7 ++++ libvideoeditor/vss/src/VideoEditorResampler.cpp | 44 +++++++++++++++++++--- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/libvideoeditor/vss/common/inc/VideoEditorResampler.h b/libvideoeditor/vss/common/inc/VideoEditorResampler.h index 26862128f9..fe9876ca45 100755 --- a/libvideoeditor/vss/common/inc/VideoEditorResampler.h +++ b/libvideoeditor/vss/common/inc/VideoEditorResampler.h @@ -29,6 +29,7 @@ void LVAudiosetSampleRate(M4OSA_Int32 resamplerContext,M4OSA_Int32 inSampleRate) void LVAudiosetVolume(M4OSA_Int32 resamplerContext, M4OSA_Int16 left, M4OSA_Int16 right) ; void LVAudioresample_LowQuality(M4OSA_Int16* out, M4OSA_Int16* input, M4OSA_Int32 outFrameCount, M4OSA_Int32 resamplerContext); +void LVDestroy(M4OSA_Int32 resamplerContext); void MonoTo2I_16( const M4OSA_Int16 *src, M4OSA_Int16 *dst, diff --git a/libvideoeditor/vss/mcs/src/M4MCS_API.c b/libvideoeditor/vss/mcs/src/M4MCS_API.c index b2b341e9ea..d04befa018 100755 --- a/libvideoeditor/vss/mcs/src/M4MCS_API.c +++ b/libvideoeditor/vss/mcs/src/M4MCS_API.c @@ -2212,7 +2212,7 @@ M4OSA_ERR M4MCS_init( M4MCS_Context *pContext, pC->iSsrcNbSamplIn = 0; pC->iSsrcNbSamplOut = 0; pC->SsrcScratch = M4OSA_NULL; - + pC->pLVAudioResampler = M4OSA_NULL; /** * Audio encoder */ pC->pAudioEncCtxt = M4OSA_NULL; @@ -3378,6 +3378,12 @@ M4OSA_ERR M4MCS_cleanUp( M4MCS_Context pContext ) pC->pSsrcBufferOut = M4OSA_NULL; } + if (pC->pLVAudioResampler != M4OSA_NULL) + { + LVDestroy((M4OSA_Int32)pC->pLVAudioResampler); + pC->pLVAudioResampler = M4OSA_NULL; + } + /* ----- Free the audio encoder stuff ----- */ if( M4OSA_NULL != pC->pAudioEncCtxt ) diff --git a/libvideoeditor/vss/src/M4VSS3GPP_AudioMixing.c b/libvideoeditor/vss/src/M4VSS3GPP_AudioMixing.c index 157f2003f0..c94351385c 100755 --- a/libvideoeditor/vss/src/M4VSS3GPP_AudioMixing.c +++ b/libvideoeditor/vss/src/M4VSS3GPP_AudioMixing.c @@ -189,6 +189,7 @@ M4OSA_ERR M4VSS3GPP_audioMixingInit( M4VSS3GPP_AudioMixingContext *pContext, pC->ewc.pEncContext = M4OSA_NULL; pC->ewc.pDummyAuBuffer = M4OSA_NULL; pC->ewc.p3gpWriterContext = M4OSA_NULL; + pC->pLVAudioResampler = M4OSA_NULL; /** * Set the OSAL filesystem function set */ pC->pOsaFileReadPtr = pFileReadPtrFct; @@ -592,6 +593,12 @@ M4OSA_ERR M4VSS3GPP_audioMixingCleanUp( M4VSS3GPP_AudioMixingContext pContext ) pC->pTempBuffer = M4OSA_NULL; } + if (pC->pLVAudioResampler != M4OSA_NULL) + { + LVDestroy(pC->pLVAudioResampler); + pC->pLVAudioResampler = M4OSA_NULL; + } + /** * Free the shells interfaces */ M4VSS3GPP_unRegisterAllWriters(&pC->ShellAPI); diff --git a/libvideoeditor/vss/src/VideoEditorResampler.cpp b/libvideoeditor/vss/src/VideoEditorResampler.cpp index 82a2423e47..c4d1a8a0c4 100755 --- a/libvideoeditor/vss/src/VideoEditorResampler.cpp +++ b/libvideoeditor/vss/src/VideoEditorResampler.cpp @@ -45,19 +45,27 @@ struct VideoEditorResampler : public AudioBufferProvider { int16_t* mInput; int nbChannels; int nbSamples; + M4OSA_Int32 outSamplingRate; + M4OSA_Int32 inSamplingRate; }; +#define MAX_SAMPLEDURATION_FOR_CONVERTION 40 //ms status_t VideoEditorResampler::getNextBuffer(AudioBufferProvider::Buffer *pBuffer) { - pBuffer->raw = (void*)(this->mInput); + uint32_t dataSize = pBuffer->frameCount * this->nbChannels * sizeof(int16_t); + int16_t *pTmpInBuffer = (int16_t*)malloc(dataSize); + memcpy(pTmpInBuffer, this->mInput, dataSize); + pBuffer->raw = (void*)pTmpInBuffer; + return OK; } void VideoEditorResampler::releaseBuffer(AudioBufferProvider::Buffer *pBuffer) { if(pBuffer->raw != NULL) { + free(pBuffer->raw); pBuffer->raw = NULL; } pBuffer->frameCount = 0; @@ -74,9 +82,11 @@ M4OSA_Int32 LVAudioResamplerCreate(M4OSA_Int32 bitDepth, M4OSA_Int32 inChannelCo if (context->mResampler == NULL) { return NO_MEMORY; } - context->mResampler->setSampleRate(32000); + context->mResampler->setSampleRate(android::VideoEditorResampler::kFreq32000Hz); context->mResampler->setVolume(0x1000, 0x1000); context->nbChannels = inChannelCount; + context->outSamplingRate = sampleRate; + context->mInput = NULL; return ((M4OSA_Int32)context); } @@ -91,9 +101,10 @@ void LVAudiosetSampleRate(M4OSA_Int32 resamplerContext, M4OSA_Int32 inSampleRate * nbSamples is calculated for 40ms worth of data;hence sample rate * is used to calculate the nbSamples */ - context->nbSamples = inSampleRate / 25; - context->mInput = (int16_t*)malloc(context->nbSamples * - context->nbChannels * sizeof(int16_t)); + context->inSamplingRate = inSampleRate; + // Allocate buffer for maximum allowed number of samples. + context->mInput = (int16_t*)malloc( (inSampleRate * MAX_SAMPLEDURATION_FOR_CONVERTION * + context->nbChannels * sizeof(int16_t)) / 1000); } void LVAudiosetVolume(M4OSA_Int32 resamplerContext, M4OSA_Int16 left, M4OSA_Int16 right) { @@ -103,6 +114,26 @@ void LVAudiosetVolume(M4OSA_Int32 resamplerContext, M4OSA_Int16 left, M4OSA_Int1 context->mResampler->setVolume(left,right); } +void LVDestroy(M4OSA_Int32 resamplerContext) { + + VideoEditorResampler *context = + (VideoEditorResampler *)resamplerContext; + + if (context->mInput != NULL) { + free(context->mInput); + context->mInput = NULL; + } + + if (context->mResampler != NULL) { + delete context->mResampler; + context->mResampler = NULL; + } + + if (context != NULL) { + delete context; + context = NULL; + } +} void LVAudioresample_LowQuality(M4OSA_Int16* out, M4OSA_Int16* input, M4OSA_Int32 outFrameCount, M4OSA_Int32 resamplerContext) { @@ -110,7 +141,10 @@ void LVAudioresample_LowQuality(M4OSA_Int16* out, M4OSA_Int16* input, VideoEditorResampler *context = (VideoEditorResampler *)resamplerContext; int32_t *pTmpBuffer = NULL; + + context->nbSamples = (context->inSamplingRate * outFrameCount) / context->outSamplingRate; memcpy(context->mInput,input,(context->nbSamples * context->nbChannels * sizeof(int16_t))); + /* SRC module always gives stereo output, hence 2 for stereo audio */ -- 2.11.0