Lines Matching refs:pC
87 static M4OSA_ERR M4MCS_intStepSet( M4MCS_InternalContext *pC );
89 M4MCS_InternalContext *pC );
91 M4MCS_InternalContext *pC );
93 M4MCS_InternalContext *pC );
94 static M4OSA_ERR M4MCS_intPrepareWriter( M4MCS_InternalContext *pC );
96 M4MCS_InternalContext *pC );
98 M4MCS_InternalContext *pC,
101 M4MCS_InternalContext *pC );
103 M4MCS_InternalContext *pC );
104 static M4OSA_ERR M4MCS_intAudioNullEncoding( M4MCS_InternalContext *pC );
105 static M4OSA_ERR M4MCS_intAudioTranscoding( M4MCS_InternalContext *pC );
106 static M4OSA_ERR M4MCS_intVideoNullEncoding( M4MCS_InternalContext *pC );
107 static M4OSA_ERR M4MCS_intVideoTranscoding( M4MCS_InternalContext *pC );
119 M4MCS_InternalContext *pC );
124 M4MCS_InternalContext *pC);
2125 M4MCS_InternalContext *pC = M4OSA_NULL;
2143 pC = (M4MCS_InternalContext *)M4OSA_32bitAlignedMalloc(sizeof(M4MCS_InternalContext),
2145 *pContext = pC;
2147 if( M4OSA_NULL == pC )
2157 pC->State = M4MCS_kState_CREATED;
2158 pC->pOsaFileReadPtr = pFileReadPtrFct;
2159 pC->pOsaFileWritPtr = pFileWritePtrFct;
2160 pC->VideoState = M4MCS_kStreamState_NOSTREAM;
2161 pC->AudioState = M4MCS_kStreamState_NOSTREAM;
2162 pC->noaudio = M4OSA_FALSE;
2163 pC->novideo = M4OSA_FALSE;
2164 pC->uiProgress = 0;
2168 pC->pInputFile = M4OSA_NULL;
2169 pC->InputFileType = M4VIDEOEDITING_kFileType_Unsupported;
2170 pC->bFileOpenedInFastMode = M4OSA_FALSE;
2171 pC->pReaderContext = M4OSA_NULL;
2172 pC->pReaderVideoStream = M4OSA_NULL;
2173 pC->pReaderAudioStream = M4OSA_NULL;
2174 pC->bUnsupportedVideoFound = M4OSA_FALSE;
2175 pC->bUnsupportedAudioFound = M4OSA_FALSE;
2176 pC->iAudioCtsOffset = 0;
2178 pC->ReaderVideoAU1.m_structSize = 0;
2180 pC->ReaderVideoAU2.m_structSize = 0;
2181 pC->ReaderAudioAU1.m_structSize = 0;
2182 pC->ReaderAudioAU2.m_structSize = 0;
2183 pC->m_audioAUDuration = 0;
2184 pC->m_pDataAddress1 = M4OSA_NULL;
2185 pC->m_pDataAddress2 = M4OSA_NULL;
2187 pC->m_pDataVideoAddress1 = M4OSA_NULL;
2189 pC->m_pDataVideoAddress2 = M4OSA_NULL;
2193 pC->pViDecCtxt = M4OSA_NULL;
2194 pC->dViDecStartingCts = 0.0;
2195 pC->iVideoBeginDecIncr = 0;
2196 pC->dViDecCurrentCts = 0.0;
2197 pC->dCtsIncrement = 0.0;
2198 pC->isRenderDup = M4OSA_FALSE;
2202 pC->pViEncCtxt = M4OSA_NULL;
2203 pC->pPreResizeFrame = M4OSA_NULL;
2204 pC->uiEncVideoBitrate = 0;
2205 pC->encoderState = M4MCS_kNoEncoder;
2209 pC->pAudioDecCtxt = M4OSA_NULL;
2210 pC->AudioDecBufferIn.m_dataAddress = M4OSA_NULL;
2211 pC->AudioDecBufferIn.m_bufferSize = 0;
2212 pC->AudioDecBufferOut.m_dataAddress = M4OSA_NULL;
2213 pC->AudioDecBufferOut.m_bufferSize = 0;
2214 pC->pPosInDecBufferOut = M4OSA_NULL;
2217 pC->pSsrcBufferIn = M4OSA_NULL;
2218 pC->pSsrcBufferOut = M4OSA_NULL;
2219 pC->pPosInSsrcBufferIn = M4OSA_NULL;
2220 pC->pPosInSsrcBufferOut = M4OSA_NULL;
2221 pC->iSsrcNbSamplIn = 0;
2222 pC->iSsrcNbSamplOut = 0;
2223 pC->SsrcScratch = M4OSA_NULL;
2224 pC->pLVAudioResampler = M4OSA_NULL;
2227 pC->pAudioEncCtxt = M4OSA_NULL;
2228 pC->pAudioEncDSI.infoSize = 0;
2229 pC->pAudioEncDSI.pInfo = M4OSA_NULL;
2230 pC->pAudioEncoderBuffer = M4OSA_NULL;
2231 pC->pPosInAudioEncoderBuffer = M4OSA_NULL;
2232 pC->audioEncoderGranularity = 0;
2236 pC->pOutputFile = M4OSA_NULL;
2237 pC->pTemporaryFile = M4OSA_NULL;
2238 pC->pWriterContext = M4OSA_NULL;
2239 pC->uiVideoAUCount = 0;
2240 pC->uiVideoMaxAuSize = 0;
2241 pC->uiVideoMaxChunckSize = 0;
2242 pC->uiAudioAUCount = 0;
2243 pC->uiAudioMaxAuSize = 0;
2245 pC->uiAudioCts = 0;
2246 pC->b_isRawWriter = M4OSA_FALSE;
2247 pC->pOutputPCMfile = M4OSA_NULL;
2250 pC->EncodingVideoFormat = M4ENCODER_kNULL; /**< No format set yet */
2251 pC->EncodingWidth = 0; /**< No size set yet */
2252 pC->EncodingHeight = 0; /**< No size set yet */
2253 pC->EncodingVideoFramerate = 0; /**< No framerate set yet */
2255 pC->uiBeginCutTime = 0; /**< No begin cut */
2256 pC->uiEndCutTime = 0; /**< No end cut */
2257 pC->uiMaxFileSize = 0; /**< No limit */
2258 pC->uiAudioBitrate =
2260 pC->uiVideoBitrate =
2263 pC->WriterVideoStream.streamType = M4SYS_kVideoUnknown;
2264 pC->WriterVideoStreamInfo.Header.pBuf = M4OSA_NULL;
2265 pC->WriterAudioStream.streamType = M4SYS_kAudioUnknown;
2267 pC->outputVideoTimescale = 0;
2270 pC->MediaRendering = M4MCS_kResizing;
2271 pC->m_air_context = M4OSA_NULL;
2276 pC->pEffects = M4OSA_NULL;
2277 pC->nbEffects = 0;
2278 pC->pActiveEffectNumber = -1;
2283 err = M4MCS_clearInterfaceTables(pC);
2288 err = M4MCS_subscribeMediaAndCodec(pC);
2295 err = M4MCS_stillPicInit(pC, pFileReadPtrFct, pFileWritePtrFct);
2298 pC->m_bIsStillPicture = M4OSA_FALSE;
2302 pC->m_pInstance = M4OSA_NULL;
2303 pC->H264MCSTempBuffer = M4OSA_NULL;
2304 pC->H264MCSTempBufferSize = 0;
2305 pC->H264MCSTempBufferDataSize = 0;
2306 pC->bH264Trim = M4OSA_FALSE;
2309 pC->bLastDecodedFrameCTS = M4OSA_FALSE;
2311 if( pC->m_pInstance == M4OSA_NULL )
2313 err = H264MCS_Getinstance(&pC->m_pInstance);
2315 pC->bExtOMXAudDecoder = M4OSA_FALSE;
2351 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
2377 pC->m_bIsStillPicture = M4OSA_TRUE;
2381 return M4MCS_stillPicOpen(pC, pFileIn, InputFileType, pFileOut);
2395 if( M4MCS_kState_CREATED != pC->State )
2398 pC->State);
2403 pC->pInputFile = pFileIn;
2404 pC->InputFileType = InputFileType;
2405 pC->pOutputFile = pFileOut;
2406 pC->pTemporaryFile = pTempFile;
2407 pC->uiProgress = 0;
2413 err = M4MCS_setCurrentReader(pContext, pC->InputFileType);
2418 pC->VideoState = M4MCS_kStreamState_NOSTREAM;
2419 pC->AudioState = M4MCS_kStreamState_NOSTREAM;
2420 pC->pReaderVideoStream = M4OSA_NULL;
2421 pC->pReaderAudioStream = M4OSA_NULL;
2426 err = pC->m_pReader->m_pFctCreate(&pC->pReaderContext);
2437 pC->m_pReaderDataIt->m_readerContext = pC->pReaderContext;
2441 err = pC->m_pReader->m_pFctSetOption(pC->pReaderContext,
2443 (M4OSA_DataOption)pC->pOsaFileReadPtr);
2454 if( M4OSA_FALSE == pC->bFileOpenedInFastMode )
2459 err = pC->m_pReader->m_pFctSetOption(pC->pReaderContext,
2464 pC->bFileOpenedInFastMode = M4OSA_TRUE;
2476 pC->bFileOpenedInFastMode = M4OSA_FALSE;
2487 err = pC->m_pReader->m_pFctSetOption(pC->pReaderContext,
2496 err = pC->m_pReader->m_pFctOpen(pC->pReaderContext, pC->pInputFile);
2521 pC->m_pReader->m_pFctGetNextStream( pC->pReaderContext,
2539 && (M4OSA_NULL == pC->pReaderVideoStream) )
2552 pC->pReaderVideoStream =
2554 pC->bUnsupportedVideoFound = M4OSA_FALSE;
2559 pC->VideoState = M4MCS_kStreamState_STARTED;
2563 err = pC->m_pReader->m_pFctReset(pC->pReaderContext,
2564 (M4_StreamHandler *)pC->pReaderVideoStream);
2577 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
2578 pStreamHandler, &pC->ReaderVideoAU);
2595 pC->bUnsupportedVideoFound = M4OSA_TRUE;
2604 pC->m_pInstance->m_pDecoderSpecificInfo =
2606 pC->m_pInstance->m_decoderSpecificInfoSize =
2614 && (M4OSA_NULL == pC->pReaderAudioStream) )
2629 pC->pReaderAudioStream =
2632 pC->bUnsupportedAudioFound = M4OSA_FALSE;
2636 pC->AudioState = M4MCS_kStreamState_STARTED;
2640 err = pC->m_pReader->m_pFctReset(pC->pReaderContext,
2641 (M4_StreamHandler *)pC->pReaderAudioStream);
2654 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
2655 pStreamHandler, &pC->ReaderAudioAU);
2669 pC->uiAudioMaxAuSize = pStreamHandler->m_maxAUSize;
2677 pC->bUnsupportedAudioFound = M4OSA_TRUE;
2686 if( ( M4OSA_NULL == pC->pReaderVideoStream)
2687 && (M4OSA_NULL == pC->pReaderAudioStream) )
2694 if( pC->VideoState == M4MCS_kStreamState_STARTED )
2697 pC->pReaderVideoStream->m_basicProperties.m_streamType);
2715 if( pC->AudioState == M4MCS_kStreamState_STARTED )
2723 pC->pReaderAudioStream->m_basicProperties.m_streamType);
2730 err = M4MCS_intGetInputClipProperties(pC);
2741 if( 0. != pC->InputFileProperties.fAverageFrameRate ) /**< sanity check */
2743 pC->iVideoBeginDecIncr = (M4OSA_Int32)(3000.
2744 / pC->InputFileProperties.
2749 pC->iVideoBeginDecIncr =
2755 pC->State = M4MCS_kState_OPENED;
2782 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
2795 if( pC->m_bIsStillPicture )
2799 return M4MCS_stillPicStep(pC, pProgress);
2807 switch( pC->State )
2811 return M4MCS_intStepSet(pC);
2815 *pProgress = pC->uiProgress;
2816 return M4MCS_intStepBeginVideoJump(pC);
2820 *pProgress = pC->uiProgress;
2821 return M4MCS_intStepBeginVideoDecode(pC);
2827 err = M4MCS_intStepEncoding(pC, pProgress);
2829 pC->uiProgress = *pProgress;
2837 pC->State);
2857 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
2869 if( pC->m_bIsStillPicture )
2873 return M4MCS_stillPicPause(pC);
2881 switch( pC->State )
2893 pC->State);
2899 if( pC->dViDecCurrentCts > pC->dViDecStartingCts )
2903 pC->dViDecStartingCts = pC->dViDecCurrentCts;
2913 if( M4OSA_NULL != pC->pViDecCtxt )
2915 err = pC->m_pVideoDecoder->m_pFctDestroy(pC->pViDecCtxt);
2916 pC->pViDecCtxt = M4OSA_NULL;
2928 pC->State = M4MCS_kState_PAUSED;
2949 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
2961 if( pC->m_bIsStillPicture )
2965 return M4MCS_stillPicResume(pC);
2973 switch( pC->State )
2981 pC->State);
2988 err = M4MCS_intPrepareVideoDecoder(pC);
2999 if( 0.0 == pC->dViDecStartingCts )
3003 pC->State = M4MCS_kState_PROCESSING;
3009 pC->State = M4MCS_kState_BEGINVIDEOJUMP;
3029 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
3044 if( pC->m_bIsStillPicture )
3048 pC->m_bIsStillPicture = M4OSA_FALSE;
3052 return M4MCS_stillPicClose(pC);
3060 if( M4MCS_kState_FINISHED != pC->State )
3063 pC->State);
3071 if( M4MCS_kEncoderRunning == pC->encoderState )
3073 if( pC->pVideoEncoderGlobalFcts->pFctStop != M4OSA_NULL )
3075 err = pC->pVideoEncoderGlobalFcts->pFctStop(pC->pViEncCtxt);
3086 pC->encoderState = M4MCS_kEncoderStopped;
3090 if( M4MCS_kEncoderStopped == pC->encoderState )
3092 err = pC->pVideoEncoderGlobalFcts->pFctClose(pC->pViEncCtxt);
3102 pC->encoderState = M4MCS_kEncoderClosed;
3108 if( M4OSA_NULL != pC->pWriterContext ) /* happens in state _SET */
3113 if( pC->novideo != M4OSA_TRUE )
3115 if( ( M4ENCODER_kMPEG4 == pC->EncodingVideoFormat)
3116 || (M4ENCODER_kH264 == pC->EncodingVideoFormat) )
3118 err = pC->pVideoEncoderGlobalFcts->pFctGetOption(pC->pViEncCtxt,
3139 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
3151 if( ( M4OSA_TRUE == pC->bH264Trim)
3152 && (M4ENCODER_kNULL == pC->EncodingVideoFormat) )
3154 if(pC->uiBeginCutTime == 0)
3157 pC->m_pInstance->m_decoderSpecificInfoSize);
3158 pC->m_pInstance->m_pFinalDSISize =
3159 pC->m_pInstance->m_decoderSpecificInfoSize;
3161 (M4OSA_MemAddr8)pC->m_pInstance->m_pDecoderSpecificInfo);
3163 pC->m_pInstance->m_pFinalDSI =
3164 (M4OSA_UInt8 *)M4OSA_32bitAlignedMalloc(pC->m_pInstance-> \
3168 if( pC->m_pInstance->m_pFinalDSI == M4OSA_NULL )
3173 memcpy((void *)pC->m_pInstance->m_pFinalDSI,
3174 (void *)pC-> \
3176 pC->m_pInstance->m_decoderSpecificInfoSize);
3179 streamHeader.size = pC->m_pInstance->m_pFinalDSISize;
3181 (M4OSA_MemAddr32)pC->m_pInstance->m_pFinalDSI;
3183 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
3196 err2 = pC->pWriterGlobalFcts->pFctCloseWrite(pC->pWriterContext);
3197 pC->pWriterContext = M4OSA_NULL;
3212 if( pC->pOutputPCMfile != M4OSA_NULL )
3214 pC->pOsaFileWritPtr->closeWrite(pC->pOutputPCMfile);
3215 pC->pOutputPCMfile = M4OSA_NULL;
3220 if( M4OSA_NULL != pC->pEffects )
3222 free(pC->pEffects);
3223 pC->pEffects = M4OSA_NULL;
3225 pC->nbEffects = 0;
3226 pC->pActiveEffectNumber = -1;
3230 pC->State = M4MCS_kState_CLOSED;
3232 if( M4OSA_NULL != pC->H264MCSTempBuffer )
3234 free(pC->H264MCSTempBuffer);
3255 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
3293 if( M4MCS_kState_CLOSED != pC->State )
3297 pC->State);
3301 if( M4OSA_NULL != pC->m_pInstance )
3303 err = H264MCS_Freeinstance(pC->m_pInstance);
3304 pC->m_pInstance = M4OSA_NULL;
3309 if( ( M4OSA_NULL != pC->pViEncCtxt)
3310 && (M4OSA_NULL != pC->pVideoEncoderGlobalFcts) )
3312 err = pC->pVideoEncoderGlobalFcts->pFctCleanup(pC->pViEncCtxt);
3313 pC->pViEncCtxt = M4OSA_NULL;
3323 pC->encoderState = M4MCS_kNoEncoder;
3328 if( ( M4ENCODER_kH263 == pC->EncodingVideoFormat)
3329 && (M4OSA_NULL != pC->WriterVideoStreamInfo.Header.pBuf) )
3331 free(pC->WriterVideoStreamInfo.Header.pBuf);
3332 pC->WriterVideoStreamInfo.Header.pBuf = M4OSA_NULL;
3335 if( M4OSA_NULL != pC->pPreResizeFrame )
3337 if( M4OSA_NULL != pC->pPreResizeFrame[0].pac_data )
3339 free(pC->pPreResizeFrame[0].pac_data);
3340 pC->pPreResizeFrame[0].pac_data = M4OSA_NULL;
3343 if( M4OSA_NULL != pC->pPreResizeFrame[1].pac_data )
3345 free(pC->pPreResizeFrame[1].pac_data);
3346 pC->pPreResizeFrame[1].pac_data = M4OSA_NULL;
3349 if( M4OSA_NULL != pC->pPreResizeFrame[2].pac_data )
3351 free(pC->pPreResizeFrame[2].pac_data);
3352 pC->pPreResizeFrame[2].pac_data = M4OSA_NULL;
3354 free(pC->pPreResizeFrame);
3355 pC->pPreResizeFrame = M4OSA_NULL;
3360 if( M4OSA_NULL != pC->SsrcScratch )
3362 free(pC->SsrcScratch);
3363 pC->SsrcScratch = M4OSA_NULL;
3366 if( M4OSA_NULL != pC->pSsrcBufferIn )
3368 free(pC->pSsrcBufferIn);
3369 pC->pSsrcBufferIn = M4OSA_NULL;
3372 if( M4OSA_NULL != pC->pSsrcBufferOut )
3374 free(pC->pSsrcBufferOut);
3375 pC->pSsrcBufferOut = M4OSA_NULL;
3378 if (pC->pLVAudioResampler != M4OSA_NULL)
3380 LVDestroy(pC->pLVAudioResampler);
3381 pC->pLVAudioResampler = M4OSA_NULL;
3386 if( M4OSA_NULL != pC->pAudioEncCtxt )
3388 err = pC->pAudioEncoderGlobalFcts->pFctClose(pC->pAudioEncCtxt);
3398 err = pC->pAudioEncoderGlobalFcts->pFctCleanUp(pC->pAudioEncCtxt);
3408 pC->pAudioEncCtxt = M4OSA_NULL;
3411 if( M4OSA_NULL != pC->pAudioEncoderBuffer )
3413 free(pC->pAudioEncoderBuffer);
3414 pC->pAudioEncoderBuffer = M4OSA_NULL;
3421 M4MCS_intCleanUp_ReadersDecoders(pC);
3427 M4MCS_stillPicCleanUp(pC);
3441 free(pC);
3442 pC = M4OSA_NULL;
3463 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
3470 if( ( pC->State == M4MCS_kState_CREATED)
3471 || (pC->State == M4MCS_kState_CLOSED) )
3473 pC->State = M4MCS_kState_CLOSED;
3486 if( pC->m_bIsStillPicture )
3490 err = M4MCS_stillPicCancel(pC);
3502 pC->State = M4MCS_kState_FINISHED;
3541 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
3555 if( pC->m_bIsStillPicture )
3559 return M4MCS_stillPicGetInputFileProperties(pC, pFileProperties);
3567 if( M4MCS_kState_OPENED != pC->State )
3571 pC->State);
3578 (void *) &pC->InputFileProperties,
3609 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
3627 if( pC->m_bIsStillPicture )
3631 return M4MCS_stillPicSetOutputParams(pC, pParams);
3639 if( M4MCS_kState_OPENED != pC->State )
3643 pC->State);
3651 || (pC->VideoState == M4MCS_kStreamState_NOSTREAM)
3655 pC->novideo = M4OSA_TRUE;
3659 || (pC->AudioState == M4MCS_kStreamState_NOSTREAM) )
3661 pC->noaudio = M4OSA_TRUE;
3664 if( pC->noaudio && pC->novideo )
3676 if( pC->novideo == M4OSA_FALSE )
3687 pC->EncodingVideoFormat = M4ENCODER_kH263;
3695 pC->EncodingVideoFormat = M4ENCODER_kMPEG4;
3703 pC->EncodingVideoFormat = M4ENCODER_kH264;
3711 && (pC->InputFileProperties.VideoStreamType
3717 pC->EncodingVideoFormat = M4ENCODER_kNULL;
3719 pC->InputFileProperties.VideoStreamType);
3735 pC->EncodingWidth = pC->InputFileProperties.uiVideoWidth;
3737 pC->EncodingHeight = pC->InputFileProperties.uiVideoHeight;
3741 pC->encodingVideoProfile = pC->InputFileProperties.uiVideoProfile;
3746 pC->encodingVideoLevel = pParams->outputVideoLevel;
3752 uint32_t remainder = pC->EncodingWidth % 16;
3756 pC->EncodingWidth =
3757 pC->EncodingWidth + (16-remainder);
3760 pC->EncodingWidth =
3761 pC->EncodingWidth - remainder;
3763 uiFrameWidth = pC->EncodingWidth;
3766 remainder = pC->EncodingHeight % 16;
3770 pC->EncodingHeight =
3771 pC->EncodingHeight + (16-remainder);
3774 pC->EncodingHeight =
3775 pC->EncodingHeight - remainder;
3777 uiFrameHeight = pC->EncodingHeight;
3785 pC->encodingVideoProfile = pParams->outputVideoProfile;
3786 pC->encodingVideoLevel = pParams->outputVideoLevel;
3791 uiFrameWidth = pC->EncodingWidth = M4ENCODER_SQCIF_Width;
3792 uiFrameHeight = pC->EncodingHeight = M4ENCODER_SQCIF_Height;
3796 uiFrameWidth = pC->EncodingWidth = M4ENCODER_QQVGA_Width;
3797 uiFrameHeight = pC->EncodingHeight = M4ENCODER_QQVGA_Height;
3801 uiFrameWidth = pC->EncodingWidth = M4ENCODER_QCIF_Width;
3802 uiFrameHeight = pC->EncodingHeight = M4ENCODER_QCIF_Height;
3806 uiFrameWidth = pC->EncodingWidth = M4ENCODER_QVGA_Width;
3807 uiFrameHeight = pC->EncodingHeight = M4ENCODER_QVGA_Height;
3811 uiFrameWidth = pC->EncodingWidth = M4ENCODER_CIF_Width;
3812 uiFrameHeight = pC->EncodingHeight = M4ENCODER_CIF_Height;
3816 uiFrameWidth = pC->EncodingWidth = M4ENCODER_VGA_Width;
3817 uiFrameHeight = pC->EncodingHeight = M4ENCODER_VGA_Height;
3821 uiFrameWidth = pC->EncodingWidth = M4ENCODER_WVGA_Width;
3822 uiFrameHeight = pC->EncodingHeight = M4ENCODER_WVGA_Height;
3826 uiFrameWidth = pC->EncodingWidth = M4ENCODER_NTSC_Width;
3827 uiFrameHeight = pC->EncodingHeight = M4ENCODER_NTSC_Height;
3832 uiFrameWidth = pC->EncodingWidth = M4ENCODER_640_360_Width;
3834 pC->EncodingHeight = M4ENCODER_640_360_Height;
3839 pC->EncodingWidth = M4ENCODER_854_480_Width;
3841 pC->EncodingHeight = M4ENCODER_854_480_Height;
3846 pC->EncodingWidth = M4ENCODER_1280_720_Width;
3848 pC->EncodingHeight = M4ENCODER_1280_720_Height;
3853 pC->EncodingWidth = M4ENCODER_1080_720_Width;
3855 pC->EncodingHeight = M4ENCODER_1080_720_Height;
3860 pC->EncodingWidth = M4ENCODER_960_720_Width;
3862 pC->EncodingHeight = M4ENCODER_960_720_Height;
3867 pC->EncodingWidth = M4ENCODER_1920_1080_Width;
3869 pC->EncodingHeight = M4ENCODER_1920_1080_Height;
3885 pC->uiVideoMaxAuSize =
3888 pC->uiVideoMaxChunckSize = (M4OSA_UInt32)(pC->uiVideoMaxAuSize \
3892 if( 0 == pC->uiVideoMaxAuSize )
3929 pC->EncodingVideoFramerate = M4ENCODER_k5_FPS;
3933 pC->EncodingVideoFramerate = M4ENCODER_k7_5_FPS;
3937 pC->EncodingVideoFramerate = M4ENCODER_k10_FPS;
3941 pC->EncodingVideoFramerate = M4ENCODER_k12_5_FPS;
3945 pC->EncodingVideoFramerate = M4ENCODER_k15_FPS;
3949 pC->EncodingVideoFramerate = M4ENCODER_k20_FPS;
3953 pC->EncodingVideoFramerate = M4ENCODER_k25_FPS;
3957 pC->EncodingVideoFramerate = M4ENCODER_k30_FPS;
3973 switch( pC->EncodingVideoFramerate )
3993 if( pC->noaudio == M4OSA_FALSE )
4005 pC->AudioEncParams.Format = M4ENCODER_kAMRNB;
4006 pC->AudioEncParams.Frequency = M4ENCODER_k8000Hz;
4007 pC->AudioEncParams.ChannelNum = M4ENCODER_kMono;
4008 pC->AudioEncParams.SpecifParam.AmrSID = M4ENCODER_kAmrNoSID;
4017 pC->AudioEncParams.Format = M4ENCODER_kAAC;
4018 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4023 pC->AudioEncParams.Frequency = M4ENCODER_k8000Hz;
4027 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4031 pC->AudioEncParams.Frequency = M4ENCODER_k22050Hz;
4035 pC->AudioEncParams.Frequency = M4ENCODER_k24000Hz;
4039 pC->AudioEncParams.Frequency = M4ENCODER_k32000Hz;
4043 pC->AudioEncParams.Frequency = M4ENCODER_k44100Hz;
4047 pC->AudioEncParams.Frequency = M4ENCODER_k48000Hz;
4055 pC->AudioEncParams.ChannelNum =
4058 pC->AudioEncParams.SpecifParam.AacParam.Regulation =
4061 pC->AudioEncParams.SpecifParam.AacParam.bIS = M4OSA_FALSE;
4062 pC->AudioEncParams.SpecifParam.AacParam.bMS = M4OSA_FALSE;
4063 pC->AudioEncParams.SpecifParam.AacParam.bPNS = M4OSA_FALSE;
4064 pC->AudioEncParams.SpecifParam.AacParam.bTNS = M4OSA_FALSE;
4066 pC->AudioEncParams.SpecifParam.AacParam.bHighSpeed =
4076 pC->AudioEncParams.Format = M4ENCODER_kMP3;
4077 pC->AudioEncParams.ChannelNum =
4081 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4086 pC->AudioEncParams.Frequency = M4ENCODER_k8000Hz;
4090 pC->AudioEncParams.Frequency = M4ENCODER_k11025Hz;
4094 pC->AudioEncParams.Frequency = M4ENCODER_k12000Hz;
4098 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4102 pC->AudioEncParams.Frequency = M4ENCODER_k22050Hz;
4106 pC->AudioEncParams.Frequency = M4ENCODER_k24000Hz;
4110 pC->AudioEncParams.Frequency = M4ENCODER_k32000Hz;
4114 pC->AudioEncParams.Frequency = M4ENCODER_k44100Hz;
4118 pC->AudioEncParams.Frequency = M4ENCODER_k48000Hz;
4131 pC->AudioEncParams.Format = M4ENCODER_kAudioNULL;
4132 pC->AudioEncParams.Frequency =
4133 pC->pReaderAudioStream->m_samplingFrequency;
4134 pC->AudioEncParams.ChannelNum =
4135 (pC->pReaderAudioStream->m_nbChannels == 1) ? \
4140 pC->AudioEncParams.Frequency =
4141 pC->pReaderAudioStream->m_samplingFrequency;
4142 pC->AudioEncParams.ChannelNum =
4143 (pC->pReaderAudioStream->m_nbChannels == 1) ? \
4146 switch( pC->InputFileProperties.AudioStreamType )
4153 pC->InputFileProperties.AudioStreamType);
4156 pC->AudioEncParams.Format = M4ENCODER_kAMRNB;
4157 pC->AudioEncParams.Frequency = M4ENCODER_k8000Hz;
4158 pC->AudioEncParams.ChannelNum = M4ENCODER_kMono;
4160 if( pC->pReaderAudioStream->m_samplingFrequency
4163 pC->AudioEncParams.Format = M4ENCODER_kAMRNB;
4165 pC->AudioEncParams.SpecifParam.AmrSID =
4174 pC->InputFileProperties.AudioStreamType);
4177 pC->AudioEncParams.Format = M4ENCODER_kAAC;
4178 pC->AudioEncParams.SpecifParam.AacParam.Regulation =
4180 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4181 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4183 switch( pC->pReaderAudioStream->
4187 pC->AudioEncParams.Frequency =
4192 pC->AudioEncParams.Frequency =
4197 pC->AudioEncParams.Frequency =
4202 pC->AudioEncParams.Frequency =
4207 pC->AudioEncParams.Frequency =
4212 pC->AudioEncParams.Frequency =
4217 pC->AudioEncParams.Format = M4ENCODER_kAAC;
4221 pC->AudioEncParams.SpecifParam.AacParam.bIS =
4223 pC->AudioEncParams.SpecifParam.AacParam.bMS =
4225 pC->AudioEncParams.SpecifParam.AacParam.bPNS =
4227 pC->AudioEncParams.SpecifParam.AacParam.bTNS =
4230 pC->AudioEncParams.SpecifParam.AacParam.bHighSpeed =
4239 pC->InputFileProperties.AudioStreamType);
4242 pC->AudioEncParams.Format = M4ENCODER_kMP3;
4243 pC->AudioEncParams.Frequency = M4ENCODER_k16000Hz;
4245 switch( pC->pReaderAudioStream->
4249 pC->AudioEncParams.Frequency =
4254 pC->AudioEncParams.Frequency =
4259 pC->AudioEncParams.Frequency =
4264 pC->AudioEncParams.Frequency =
4269 pC->AudioEncParams.Frequency =
4274 pC->AudioEncParams.Frequency =
4279 pC->AudioEncParams.Frequency =
4284 pC->AudioEncParams.Format = M4ENCODER_kMP3;
4296 pC->InputFileProperties.AudioStreamType);
4308 // pC->AudioEncParams.Format = M4ENCODER_kEVRC;
4309 // pC->AudioEncParams.Frequency = M4ENCODER_k8000Hz;
4310 // pC->AudioEncParams.ChannelNum = M4ENCODER_kMono;
4323 pC->pOutputPCMfile = pParams->pOutputPCMfile;
4326 pC->pOsaFileWritPtr->openWrite(&(pC->pOutputPCMfile),
4331 pC->pOutputPCMfile = M4OSA_NULL;
4335 pC->MediaRendering = pParams->MediaRendering;
4342 pC->nbEffects = pParams->nbEffects;
4343 pC->pEffects = (M4MCS_EffectSettings *)M4OSA_32bitAlignedMalloc(pC->nbEffects \
4347 if( pC->pEffects == M4OSA_NULL )
4353 for ( j = 0; j < pC->nbEffects; j++ )
4356 memcpy((void *) &(pC->pEffects[j]),
4360 switch( pC->pEffects[j].AudioEffectType )
4365 pC->pEffects[j].pExtAudioEffectFctCtxt = M4OSA_NULL;
4366 pC->pEffects[j].ExtAudioEffectFct = M4OSA_NULL;
4372 pC->pEffects[j].pExtAudioEffectFctCtxt = M4OSA_NULL;
4373 pC->pEffects[j].ExtAudioEffectFct =
4381 pC->pEffects[j].pExtAudioEffectFctCtxt = M4OSA_NULL;
4382 pC->pEffects[j].ExtAudioEffectFct =
4400 pC->pEffects[j].pExtAudioEffectFctCtxt =
4403 pC->pEffects[j].ExtAudioEffectFct =
4418 pC->nbEffects = 0;
4419 pC->pEffects = M4OSA_NULL;
4424 pC->State = M4MCS_kState_SET;
4458 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
4474 if( pC->m_bIsStillPicture )
4478 return M4MCS_stillPicSetEncodingParams(pC, pRates);
4486 if( M4MCS_kState_SET != pC->State )
4490 pC->State);
4495 pC->uiVideoBitrate = pRates->OutputVideoBitrate;
4496 pC->uiAudioBitrate = pRates->OutputAudioBitrate;
4497 pC->uiBeginCutTime = pRates->BeginCutTime;
4498 pC->uiEndCutTime = pRates->EndCutTime;
4499 pC->uiMaxFileSize = pRates->OutputFileSize;
4503 if( pC->uiBeginCutTime >= pC->InputFileProperties.uiClipDuration )
4507 pC->uiBeginCutTime, pC->InputFileProperties.uiClipDuration);
4513 if( pC->uiEndCutTime > pC->InputFileProperties.uiClipDuration )
4515 pC->uiEndCutTime = pC->InputFileProperties.uiClipDuration;
4520 if( pC->uiEndCutTime > 0 )
4522 if( pC->uiEndCutTime < pC->uiBeginCutTime )
4526 pC->uiBeginCutTime, pC->uiEndCutTime);
4530 if( pC->uiEndCutTime == pC->uiBeginCutTime )
4534 pC->uiBeginCutTime, pC->uiEndCutTime);
4541 for ( j = 0; j < pC->nbEffects; j++ )
4543 M4OSA_UInt32 outputEndCut = pC->uiEndCutTime;
4545 if( pC->uiEndCutTime == 0 )
4547 outputEndCut = pC->InputFileProperties.uiClipDuration;
4550 if( pC->pEffects[j].uiStartTime > (outputEndCut - pC->uiBeginCutTime) )
4554 pC->pEffects[j].uiStartTime,
4555 (pC->uiEndCutTime - pC->uiBeginCutTime));
4559 if( pC->pEffects[j].uiStartTime + pC->pEffects[j].uiDuration > \
4560 (outputEndCut - pC->uiBeginCutTime) )
4563 pC->pEffects[j].uiDuration = (outputEndCut - pC->uiBeginCutTime) - \
4564 pC->pEffects[j].uiStartTime;
4569 if( ( pC->noaudio == M4OSA_FALSE)
4570 && (pC->AudioEncParams.Format != M4ENCODER_kAudioNULL) )
4572 if( pC->uiAudioBitrate != M4VIDEOEDITING_kUndefinedBitrate )
4574 if( pC->AudioEncParams.Format == M4ENCODER_kAMRNB )
4576 if( pC->uiAudioBitrate > M4VIDEOEDITING_k12_2_KBPS )
4579 if( pC->uiAudioBitrate < M4VIDEOEDITING_k12_2_KBPS )
4583 // else if(pC->AudioEncParams.Format == M4ENCODER_kEVRC)
4585 // if(pC->uiAudioBitrate > M4VIDEOEDITING_k9_2_KBPS)
4587 // if(pC->uiAudioBitrate < M4VIDEOEDITING_k9_2_KBPS)
4591 else if( pC->AudioEncParams.Format == M4ENCODER_kMP3 )
4593 if( pC->AudioEncParams.Frequency >= M4ENCODER_k32000Hz )
4596 if( pC->uiAudioBitrate > 320000 )
4599 if( pC->uiAudioBitrate < 32000 )
4602 else if( pC->AudioEncParams.Frequency >= M4ENCODER_k16000Hz )
4605 if( pC->uiAudioBitrate > 160000 )
4608 if( ( pC->uiAudioBitrate < 8000
4609 && pC->AudioEncParams.ChannelNum == M4ENCODER_kMono)
4610 || (pC->uiAudioBitrate < 16000
4611 && pC->AudioEncParams.ChannelNum
4615 else if( pC->AudioEncParams.Frequency == M4ENCODER_k8000Hz
4616 || pC->AudioEncParams.Frequency == M4ENCODER_k11025Hz
4617 || pC->AudioEncParams.Frequency == M4ENCODER_k12000Hz )
4620 if( pC->uiAudioBitrate > 64000 )
4623 if( ( pC->uiAudioBitrate < 8000
4624 && pC->AudioEncParams.ChannelNum == M4ENCODER_kMono)
4625 || (pC->uiAudioBitrate < 16000
4626 && pC->AudioEncParams.ChannelNum
4633 (%d)", pC->AudioEncParams.Frequency);
4639 if( pC->uiAudioBitrate > M4VIDEOEDITING_k192_KBPS )
4642 if( pC->AudioEncParams.ChannelNum == M4ENCODER_kMono )
4644 if( pC->uiAudioBitrate < M4VIDEOEDITING_k16_KBPS )
4649 if( pC->uiAudioBitrate < M4VIDEOEDITING_k32_KBPS )
4658 pC->uiAudioBitrate = pC->InputFileProperties.uiAudioBitrate;
4662 if( ( pC->novideo == M4OSA_FALSE)
4663 && (pC->EncodingVideoFormat != M4ENCODER_kNULL) )
4665 if( pC->uiVideoBitrate != M4VIDEOEDITING_kUndefinedBitrate )
4667 if( pC->uiVideoBitrate > M4VIDEOEDITING_k8_MBPS )
4670 if( pC->uiVideoBitrate < M4VIDEOEDITING_k16_KBPS )
4677 pC->uiVideoBitrate = pC->InputFileProperties.uiVideoBitrate;
4683 pC->outputVideoTimescale = pRates->OutputVideoTimescale;
4687 return M4MCS_intCheckMaxFileSize(pC);
4707 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
4723 if( pC->m_bIsStillPicture )
4727 return M4MCS_stillPicGetExtendedEncodingParams(pC, pRates);
4733 M4MCS_intGetNearestBitrate(pC->uiVideoBitrate, 0);
4735 M4MCS_intGetNearestBitrate(pC->uiAudioBitrate, 0);
4736 pRates->BeginCutTime = pC->uiBeginCutTime;
4737 pRates->EndCutTime = pC->uiEndCutTime;
4738 pRates->OutputFileSize = pC->uiMaxFileSize;
4742 if( M4MCS_kState_SET != pC->State )
4745 returning M4ERR_STATE", pC->State);
4750 if( pC->noaudio )
4756 else if( pC->AudioEncParams.Format == M4ENCODER_kAudioNULL )
4759 pRates->OutputAudioBitrate = pC->InputFileProperties.uiAudioBitrate;
4760 minaudiobitrate = pC->InputFileProperties.uiAudioBitrate;
4764 if( pC->AudioEncParams.Format == M4ENCODER_kAMRNB )
4771 // if(pC->AudioEncParams.Format == M4ENCODER_kEVRC)
4778 else if( pC->AudioEncParams.Format == M4ENCODER_kMP3 )
4786 minaudiobitrate = (pC->AudioEncParams.ChannelNum == M4ENCODER_kMono)
4794 if( ( pC->uiAudioBitrate > 0)
4807 if( pC->novideo )
4813 else if( pC->EncodingVideoFormat == M4ENCODER_kNULL )
4816 pRates->OutputVideoBitrate = pC->InputFileProperties.uiVideoBitrate;
4817 minvideobitrate = pC->InputFileProperties.uiVideoBitrate;
4827 if( ( pC->uiVideoBitrate > 0)
4841 if( ( pRates->BeginCutTime >= pC->InputFileProperties.uiClipDuration)
4851 pC->InputFileProperties.uiClipDuration - pRates->BeginCutTime;
4861 pRates->EndCutTime = pC->InputFileProperties.uiClipDuration;
4886 + pRates->BeginCutTime > pC->InputFileProperties.uiClipDuration )
4889 pC->InputFileProperties.uiClipDuration - pRates->BeginCutTime;
4917 if( pC->novideo )
5046 > pC->InputFileProperties.uiClipDuration )
5048 maxduration = pC->InputFileProperties.uiClipDuration
5074 > pC->InputFileProperties.uiClipDuration )
5076 maxduration = pC->InputFileProperties.uiClipDuration
5126 > pC->InputFileProperties.uiClipDuration )
5128 maxduration = pC->InputFileProperties.uiClipDuration
5169 > pC
5171 maxduration = pC->InputFileProperties.uiClipDuration
5192 if( pC->novideo )
5240 maxduration = pC->InputFileProperties.uiClipDuration;
5244 + pRates->BeginCutTime > pC->InputFileProperties.uiClipDuration )
5247 pC->InputFileProperties.uiClipDuration - pRates->BeginCutTime;
5311 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
5322 if( pC->m_bIsStillPicture )
5326 return M4MCS_stillPicCheckParamsAndStart(pC);
5334 if( M4MCS_kState_SET != pC->State )
5338 pC->State);
5343 if( ( pC->noaudio == M4OSA_FALSE)
5344 && (pC->AudioEncParams.Format != M4ENCODER_kAudioNULL)
5345 && (pC->uiAudioBitrate == M4VIDEOEDITING_kUndefinedBitrate) )
5352 if( ( pC->novideo == M4OSA_FALSE)
5353 && (pC->EncodingVideoFormat != M4ENCODER_kNULL)
5354 && (pC->uiVideoBitrate == M4VIDEOEDITING_kUndefinedBitrate) )
5361 if( pC->uiEndCutTime == 0 )
5363 pC->uiEndCutTime = pC->InputFileProperties.uiClipDuration;
5367 VerifyRates.OutputVideoBitrate = pC->uiVideoBitrate;
5368 VerifyRates.OutputAudioBitrate = pC->uiAudioBitrate;
5369 VerifyRates.BeginCutTime = pC->uiBeginCutTime;
5370 VerifyRates.EndCutTime = pC->uiEndCutTime;
5371 VerifyRates.OutputFileSize = pC->uiMaxFileSize;
5372 VerifyRates.OutputVideoTimescale = pC->outputVideoTimescale;
5386 pC->uiEncVideoBitrate = pC->uiVideoBitrate;
5387 pC->AudioEncParams.Bitrate = pC->uiAudioBitrate;
5393 if( M4OSA_TRUE == pC->bFileOpenedInFastMode )
5396 M4MCS_intCleanUp_ReadersDecoders(pC);
5398 pC->State = M4MCS_kState_CREATED;
5401 err = M4MCS_open(pContext, pC->pInputFile, pC->InputFileType,
5402 pC->pOutputFile, pC->pTemporaryFile);
5414 pC->State = M4MCS_kState_READY;
5421 * M4OSA_ERR M4MCS_intStepSet(M4MCS_InternalContext* pC)
5424 static M4OSA_ERR M4MCS_intStepSet( M4MCS_InternalContext *pC )
5431 err = M4MCS_intPrepareVideoDecoder(pC);
5441 if( ( pC->InputFileProperties.VideoStreamType == M4VIDEOEDITING_kH264)
5442 && (pC->EncodingVideoFormat == M4ENCODER_kNULL) )
5444 pC->bH264Trim = M4OSA_TRUE;
5449 err = M4MCS_intPrepareVideoEncoder(pC);
5459 if( ( pC->uiBeginCutTime != 0)
5460 && (pC->InputFileProperties.VideoStreamType == M4VIDEOEDITING_kH264)
5461 && (pC->EncodingVideoFormat == M4ENCODER_kNULL) )
5464 err = pC->pVideoEncoderGlobalFcts->pFctSetOption(pC->pViEncCtxt,
5466 (M4OSA_DataOption)pC->m_pInstance);
5475 err = pC->pVideoEncoderGlobalFcts->pFctSetOption(pC->pViEncCtxt,
5486 err = pC->pVideoEncoderGlobalFcts->pFctGetOption(pC->pViEncCtxt,
5502 pC->m_pInstance->m_encoderSPSSize =
5505 pC->m_pInstance->m_pEncoderSPS =
5508 pC->m_pInstance->m_encoderPPSSize =
5510 + pC->m_pInstance->m_encoderSPSSize] << 8)
5512 + pC->m_pInstance->m_encoderSPSSize];
5513 pC->m_pInstance->m_pEncoderPPS = (M4OSA_UInt8 *)encHeader->pBuf + SPS_START_POS + 5
5514 + pC->m_pInstance->m_encoderSPSSize;
5517 if( encHeader->Size != (pC->m_pInstance->m_encoderSPSSize
5518 + pC->m_pInstance->m_encoderPPSSize + 5 + SPS_START_POS) )
5522 encHeader->Size, pC->m_pInstance->m_encoderSPSSize,
5523 pC->m_pInstance->m_encoderPPSSize);
5531 err = M4MCS_intPrepareAudioProcessing(pC);
5543 err = M4MCS_intPrepareWriter(pC);
5556 err = M4MCS_intPrepareAudioBeginCut(pC);
5568 if( 0 == pC->uiBeginCutTime )
5570 pC->dViDecStartingCts = 0.0;
5573 pC->State = M4MCS_kState_PROCESSING;
5579 pC->dViDecStartingCts = (M4OSA_Double)pC->uiBeginCutTime;
5583 pC->State = M4MCS_kState_BEGINVIDEOJUMP;
5594 * M4OSA_ERR M4MCS_intPrepareVideoDecoder(M4MCS_InternalContext* pC);
5596 * @param pC (IN) MCS private context
5602 static M4OSA_ERR M4MCS_intPrepareVideoDecoder( M4MCS_InternalContext *pC )
5608 if( pC->novideo )
5613 if( M4OSA_NULL == pC->pViDecCtxt )
5617 decoderUserData = pC->m_pCurrentVideoDecoderUserData;
5625 err = pC->m_pVideoDecoder->m_pFctCreate(&pC->pViDecCtxt,
5626 &pC->pReaderVideoStream->m_basicProperties, pC->m_pReader,
5627 pC->m_pReaderDataIt, &pC->ReaderVideoAU, decoderUserData);
5646 if( M4VIDEOEDITING_kH264 == pC->InputFileProperties.VideoStreamType )
5651 err = pC->m_pVideoDecoder->m_pFctSetOption(pC->pViDecCtxt,
5672 * M4OSA_ERR M4MCS_intPrepareVideoEncoder(M4MCS_InternalContext* pC);
5674 * @param pC (IN) MCS private context
5679 static M4OSA_ERR M4MCS_intPrepareVideoEncoder( M4MCS_InternalContext *pC )
5686 if( pC->novideo )
5689 if( pC->EncodingVideoFormat == M4ENCODER_kNULL )
5692 pC->dCtsIncrement = 1000.0 / pC->pReaderVideoStream->m_averageFrameRate;
5694 if( pC->uiBeginCutTime == 0 )
5707 EncParams.videoProfile = pC->encodingVideoProfile;
5708 EncParams.videoLevel= pC->encodingVideoLevel;
5710 switch( pC->InputFileProperties.VideoStreamType )
5727 pC->InputFileProperties.VideoStreamType);
5731 EncParams.FrameWidth = pC->EncodingWidth;
5732 EncParams.FrameHeight = pC->EncodingHeight;
5733 EncParams.Bitrate = pC->uiEncVideoBitrate;
5736 EncParams.FrameRate = pC->EncodingVideoFramerate;
5751 EncParams.uiTimeScale = pC->InputFileProperties.uiVideoTimeScale;
5762 EncParams.Format = pC->EncodingVideoFormat;
5764 EncParams.videoProfile = pC->encodingVideoProfile;
5765 EncParams.videoLevel= pC->encodingVideoLevel;
5769 EncParams.FrameWidth = pC->EncodingWidth;
5770 EncParams.FrameHeight = pC->EncodingHeight;
5774 EncParams.Bitrate = pC->uiEncVideoBitrate;
5797 EncParams.FrameRate = pC->EncodingVideoFramerate;
5798 EncParams.uiTimeScale = pC->outputVideoTimescale;
5800 switch( pC->EncodingVideoFramerate )
5838 pC->EncodingVideoFramerate);
5846 pC->dCtsIncrement = 1001.0 / dFrameRate;
5850 pC->dCtsIncrement = 1000.0 / dFrameRate;
5867 err = pC->pVideoEncoderGlobalFcts->pFctInit(&pC->pViEncCtxt,
5868 pC->pWriterDataFcts, \
5869 M4MCS_intApplyVPP, pC, pC->pCurrentVideoEncoderExternalAPI, \
5870 pC->pCurrentVideoEncoderUserData);
5881 pC->encoderState = M4MCS_kEncoderClosed;
5883 if( M4OSA_TRUE == pC->bH264Trim )
5884 //if((M4ENCODER_kNULL == pC->EncodingVideoFormat)
5885 // && (M4VIDEOEDITING_kH264 == pC->InputFileProperties.VideoStreamType))
5899 err = pC->pVideoEncoderGlobalFcts->pFctOpen(pC->pViEncCtxt,
5900 &pC->WriterVideoAU, &EncParams1);
5906 err = pC->pVideoEncoderGlobalFcts->pFctOpen(pC->pViEncCtxt,
5907 &pC->WriterVideoAU, &EncParams);
5918 pC->encoderState = M4MCS_kEncoderStopped;
5920 if( M4OSA_NULL != pC->pVideoEncoderGlobalFcts->pFctStart )
5922 err = pC->pVideoEncoderGlobalFcts->pFctStart(pC->pViEncCtxt);
5933 pC->encoderState = M4MCS_kEncoderRunning;
5941 != pC->pReaderVideoStream->m_videoWidth)
5943 != pC->pReaderVideoStream->m_videoHeight) )
5948 pC->pPreResizeFrame =
5952 if( M4OSA_NULL == pC->pPreResizeFrame )
5959 pC->pPreResizeFrame[0].pac_data = M4OSA_NULL;
5960 pC->pPreResizeFrame[1].pac_data = M4OSA_NULL;
5961 pC->pPreResizeFrame[2].pac_data = M4OSA_NULL;
5965 pC->pPreResizeFrame[0].u_topleft = 0;
5966 pC->pPreResizeFrame[0].u_width = pC->pReaderVideoStream->
5968 pC->pPreResizeFrame[0].u_height = pC->pReaderVideoStream->
5970 pC->pPreResizeFrame[0].u_stride = pC->
5973 pC->pPreResizeFrame[0].pac_data =
5974 (M4VIFI_UInt8 *)M4OSA_32bitAlignedMalloc(pC->pPreResizeFrame[0].u_stride \
5975 *pC->pPreResizeFrame[0].u_height, M4MCS,
5978 if( M4OSA_NULL == pC->pPreResizeFrame[0].pac_data )
5988 pC->pPreResizeFrame[1].u_topleft = 0;
5989 pC->pPreResizeFrame[1].u_width = pC->pPreResizeFrame[0].u_width
5991 pC->pPreResizeFrame[1].u_height = pC->pPreResizeFrame[0].u_height
5993 pC->pPreResizeFrame[1].u_stride = pC->
5996 pC->pPreResizeFrame[1].pac_data =
5997 (M4VIFI_UInt8 *)M4OSA_32bitAlignedMalloc(pC->pPreResizeFrame[1].u_stride \
5998 *pC->pPreResizeFrame[1].u_height, M4MCS,
6001 if( M4OSA_NULL == pC->pPreResizeFrame[1].pac_data )
6011 pC->pPreResizeFrame[2].u_topleft = 0;
6012 pC->pPreResizeFrame[2].u_width = pC->
6014 pC->pPreResizeFrame[2].u_height = pC->
6016 pC->pPreResizeFrame[2].u_stride = pC->
6019 pC->pPreResizeFrame[2].pac_data =
6020 (M4VIFI_UInt8 *)M4OSA_32bitAlignedMalloc(pC->pPreResizeFrame[2].u_stride \
6021 *pC->pPreResizeFrame[2].u_height, M4MCS,
6024 if( M4OSA_NULL == pC->pPreResizeFrame[2].pac_data )
6041 * M4OSA_ERR M4MCS_intPrepareAudioProcessing(M4MCS_InternalContext* pC);
6043 * @param pC (IN) MCS private context
6048 static M4OSA_ERR M4MCS_intPrepareAudioProcessing( M4MCS_InternalContext *pC )
6071 if( pC->noaudio )
6074 if( pC->AudioEncParams.Format == M4ENCODER_kAudioNULL )
6086 if( M4OSA_NULL == pC->m_pAudioDecoder )
6093 if( M4OSA_NULL == pC->pAudioDecCtxt )
6095 err = pC->m_pAudioDecoder->m_pFctCreateAudioDec(&pC->pAudioDecCtxt,
6096 pC->pReaderAudioStream, pC->m_pCurrentAudioDecoderUserData);
6107 if( M4VIDEOEDITING_kAMR_NB == pC->InputFileProperties.AudioStreamType ) {
6112 else if( M4VIDEOEDITING_kEVRC == pC->InputFileProperties.AudioStreamType ) {
6117 else if( M4VIDEOEDITING_kMP3 == pC->InputFileProperties.AudioStreamType ) {
6130 if( pC->AudioEncParams.Format == M4ENCODER_kAMRNB )
6137 if( M4ENCODER_kMono == pC->AudioEncParams.ChannelNum )
6147 pC->m_pAudioDecoder->m_pFctSetOptionAudioDec(pC->pAudioDecCtxt,
6151 pC->m_pAudioDecoder->m_pFctSetOptionAudioDec(pC->pAudioDecCtxt,
6152 M4AD_kOptionID_3gpReaderInterface, (M4OSA_DataOption) pC->m_pReaderDataIt);
6154 pC->m_pAudioDecoder->m_pFctSetOptionAudioDec(pC->pAudioDecCtxt,
6155 M4AD_kOptionID_AudioAU, (M4OSA_DataOption) &pC->ReaderAudioAU);
6157 if( pC->m_pAudioDecoder->m_pFctStartAudioDec != M4OSA_NULL )
6160 err = pC->m_pAudioDecoder->m_pFctStartAudioDec(pC->pAudioDecCtxt);
6173 pC->InputFileProperties.uiDecodedPcmSize =
6174 pC->pReaderAudioStream->m_byteFrameLength
6175 * pC->pReaderAudioStream->m_byteSampleSize
6176 * pC->pReaderAudioStream->m_nbChannels;
6178 if( pC->InputFileProperties.uiDecodedPcmSize > 0 )
6180 pC->AudioDecBufferOut.m_bufferSize =
6181 pC->InputFileProperties.uiDecodedPcmSize;
6182 pC->AudioDecBufferOut.m_dataAddress =
6183 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->AudioDecBufferOut.m_bufferSize \
6187 if( M4OSA_NULL == pC->AudioDecBufferOut.m_dataAddress )
6200 switch( pC->pReaderAudioStream->m_samplingFrequency )
6242 pC->pReaderAudioStream->m_samplingFrequency);
6246 if( 1 == pC->pReaderAudioStream->m_nbChannels )
6256 if( pC->AudioEncParams.Format == M4ENCODER_kAAC
6257 || pC->AudioEncParams.Format == M4ENCODER_kMP3 )
6259 switch( pC->AudioEncParams.Frequency )
6301 pC->AudioEncParams.Frequency);
6424 pC->iSsrcNbSamplIn = (LVM_INT16)(
6427 pC->iSsrcNbSamplOut = (LVM_INT16)(ssrcParams.NrSamplesOut);
6431 pC->pSsrcBufferIn =
6432 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->iSsrcNbSamplIn * sizeof(short) \
6433 *pC->pReaderAudioStream->m_nbChannels, M4MCS,
6436 if( M4OSA_NULL == pC->pSsrcBufferIn )
6443 pC->pPosInSsrcBufferIn = (M4OSA_MemAddr8)pC->pSsrcBufferIn;
6447 pC->pSsrcBufferOut =
6448 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->iSsrcNbSamplOut * sizeof(short) \
6449 *pC->pReaderAudioStream->m_nbChannels, M4MCS,
6452 if( M4OSA_NULL == pC->pSsrcBufferOut )
6461 pC->pLVAudioResampler = LVAudioResamplerCreate(
6463 (M4OSA_Int16)pC->InputFileProperties.uiNbChannels/*ssrcParams.SSRC_NrOfChannels*/,
6464 (M4OSA_Int32)(pC->AudioEncParams.Frequency)/*ssrcParams.SSRC_Fs_Out*/, 1);
6466 if( M4OSA_NULL == pC->pLVAudioResampler)
6471 LVAudiosetSampleRate(pC->pLVAudioResampler,
6473 /*pC->pAddedClipCtxt->pSettings->ClipProperties.uiSamplingFrequency*/
6474 pC->InputFileProperties.uiSamplingFrequency/*ssrcParams.SSRC_Fs_In*/);
6476 LVAudiosetVolume(pC->pLVAudioResampler, (M4OSA_Int16)(0x1000 /* 0x7fff */),
6487 err = pC->pAudioEncoderGlobalFcts->pFctInit(&pC->pAudioEncCtxt,
6488 pC->pCurrentAudioEncoderUserData);
6499 err = pC->pAudioEncoderGlobalFcts->pFctOpen(pC->pAudioEncCtxt,
6500 &pC->AudioEncParams, &pC->pAudioEncDSI,
6512 switch( pC->AudioEncParams.Format )
6515 pC->audioEncoderGranularity = M4MCS_PCM_AMR_GRANULARITY_SAMPLES;
6519 pC->audioEncoderGranularity = M4MCS_PCM_AAC_GRANULARITY_SAMPLES;
6524 pC->audioEncoderGranularity = M4MCS_PCM_MP3_GRANULARITY_SAMPLES;
6531 if( M4ENCODER_kMono == pC->AudioEncParams.ChannelNum )
6532 pC->audioEncoderGranularity *= sizeof(short);
6534 pC->audioEncoderGranularity *= sizeof(short) * 2;
6536 pC->pPosInAudioEncoderBuffer = M4OSA_NULL;
6537 pC->pAudioEncoderBuffer =
6538 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->audioEncoderGranularity, M4MCS,
6539 (M4OSA_Char *)"pC->pAudioEncoderBuffer");
6549 * M4OSA_ERR M4MCS_intPrepareWriter(M4MCS_InternalContext* pC);
6551 * @param pC (IN) MCS private context
6556 static M4OSA_ERR M4MCS_intPrepareWriter( M4MCS_InternalContext *pC )
6567 err = pC->pWriterGlobalFcts->pFctOpen(&pC->pWriterContext, pC->pOutputFile,
6568 pC->pOsaFileWritPtr, pC->pTemporaryFile, pC->pOsaFileReadPtr);
6580 pC->pWriterDataFcts->pWriterContext = pC->pWriterContext;
6584 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
6602 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
6617 if( pC->novideo == M4OSA_FALSE )
6621 pC->WriterVideoStreamInfo.height = pC->EncodingHeight;
6622 pC->WriterVideoStreamInfo.width = pC->EncodingWidth;
6623 pC->WriterVideoStreamInfo.fps =
6625 pC->WriterVideoStreamInfo.Header.pBuf =
6627 pC->WriterVideoStreamInfo.Header.Size = 0; /**< Will be updated later */
6631 switch( pC->EncodingVideoFormat )
6634 pC->WriterVideoStream.streamType = M4SYS_kMPEG_4;
6638 pC->WriterVideoStream.streamType = M4SYS_kH263;
6642 pC->WriterVideoStream.streamType = M4SYS_kH264;
6646 switch( pC->InputFileProperties.VideoStreamType )
6649 pC->WriterVideoStream.streamType = M4SYS_kMPEG_4;
6653 pC->WriterVideoStream.streamType = M4SYS_kH263;
6657 pC->WriterVideoStream.streamType = M4SYS_kH264;
6665 pC->EncodingVideoFormat);
6674 pC->EncodingVideoFormat);
6680 pC->WriterVideoStream.averageBitrate =
6681 (M4OSA_Int32)pC->uiEncVideoBitrate;
6682 pC->WriterVideoStream.maxBitrate = (M4OSA_Int32)pC->uiEncVideoBitrate;
6686 pC->WriterVideoStream.streamID = M4MCS_WRITER_VIDEO_STREAM_ID;
6687 pC->WriterVideoStream.timeScale =
6689 pC->WriterVideoStream.profileLevel =
6691 pC->WriterVideoStream.duration =
6693 pC->WriterVideoStream.decoderSpecificInfoSize =
6695 pC->WriterVideoStream.decoderSpecificInfo =
6696 (M4OSA_MemAddr32) &(pC->WriterVideoStreamInfo);
6700 if( M4ENCODER_kH263 == pC->EncodingVideoFormat )
6704 pC->WriterVideoStreamInfo.Header.Size =
6707 *)"pC->WriterVideoStreamInfo.Header.pBuf (DSI H263)");
6729 switch( pC->EncodingWidth )
6733 if( ( pC->uiEncVideoBitrate <= M4ENCODER_k64_KBPS)
6734 && (pC->EncodingVideoFramerate <= M4ENCODER_k15_FPS) )
6738 else if( ( pC->uiEncVideoBitrate <= M4ENCODER_k128_KBPS)
6739 && (pC->EncodingVideoFramerate <= M4ENCODER_k15_FPS) )
6743 else if( ( pC->uiEncVideoBitrate <= M4ENCODER_k128_KBPS)
6744 && (pC->EncodingVideoFramerate <= M4ENCODER_k30_FPS) )
6748 else if( ( pC->uiEncVideoBitrate <= M4ENCODER_k384_KBPS)
6749 && (pC->EncodingVideoFramerate <= M4ENCODER_k30_FPS) )
6753 else if( ( pC->uiEncVideoBitrate
6755 && (pC->EncodingVideoFramerate <= M4ENCODER_k30_FPS) )
6762 if( ( pC->uiEncVideoBitrate <= M4ENCODER_k128_KBPS)
6763 && (pC->EncodingVideoFramerate <= M4ENCODER_k15_FPS) )
6767 else if( ( pC->uiEncVideoBitrate <= M4ENCODER_k384_KBPS)
6768 && (pC->EncodingVideoFramerate <= M4ENCODER_k30_FPS) )
6772 else if( ( pC->uiEncVideoBitrate
6774 && (pC->EncodingVideoFramerate <= M4ENCODER_k30_FPS) )
6788 pC->WriterVideoStreamInfo.Header.pBuf = pDSI;
6790 else if( M4ENCODER_kNULL == pC->EncodingVideoFormat )
6794 pC->WriterVideoStreamInfo.Header.Size = pC->pReaderVideoStream->
6796 pC->WriterVideoStreamInfo.Header.pBuf =
6797 (M4OSA_MemAddr8)pC->pReaderVideoStream->
6804 if( pC->bH264Trim == M4OSA_TRUE )
6807 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
6825 err = pC->pWriterGlobalFcts->pFctAddStream(pC->pWriterContext,
6826 &pC->WriterVideoStream);
6838 pC->WriterVideoAU.stream = &(pC->WriterVideoStream);
6839 pC->WriterVideoAU.dataAddress = M4OSA_NULL;
6840 pC->WriterVideoAU.size = 0;
6841 pC->WriterVideoAU.CTS = 0; /** Reset time */
6842 pC->WriterVideoAU.DTS = 0;
6843 pC->WriterVideoAU.attribute = AU_RAP;
6844 pC->WriterVideoAU.nbFrag = 0; /** No fragment */
6845 pC->WriterVideoAU.frag = M4OSA_NULL;
6850 optionValue.value = pC->uiVideoMaxAuSize;
6851 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
6866 optionValue.value = pC->uiVideoMaxChunckSize;
6867 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
6884 if( pC->noaudio == M4OSA_FALSE )
6892 pC->WriterAudioStream.averageBitrate =
6894 pC->WriterAudioStream.maxBitrate =
6899 switch( pC->AudioEncParams.Format )
6902 pC->WriterAudioStream.streamType = M4SYS_kAMR;
6906 pC->WriterAudioStream.streamType = M4SYS_kAAC;
6907 pC->WriterAudioStream.averageBitrate =
6908 pC->AudioEncParams.Bitrate;
6909 pC->WriterAudioStream.maxBitrate = pC->AudioEncParams.Bitrate;
6914 pC->WriterAudioStream.streamType = M4SYS_kMP3;
6918 switch( pC->InputFileProperties.AudioStreamType )
6921 pC->WriterAudioStream.streamType = M4SYS_kAMR;
6925 pC->WriterAudioStream.streamType = M4SYS_kMP3;
6931 pC->WriterAudioStream.streamType = M4SYS_kAAC;
6932 pC->WriterAudioStream.averageBitrate =
6933 pC->AudioEncParams.Bitrate;
6934 pC->WriterAudioStream.maxBitrate =
6935 pC->AudioEncParams.Bitrate;
6939 pC->WriterAudioStream.streamType = M4SYS_kEVRC;
6954 pC->AudioEncParams.Format);
6960 pC->WriterAudioStream.streamID = M4MCS_WRITER_AUDIO_STREAM_ID;
6961 pC->WriterAudioStream.duration =
6963 pC->WriterAudioStream.profileLevel =
6965 pC->WriterAudioStream.timeScale = pC->AudioEncParams.Frequency;
6967 if( pC->AudioEncParams.Format == M4ENCODER_kAudioNULL )
6970 streamAudioInfo.Header.Size = pC->pReaderAudioStream->
6973 (M4OSA_MemAddr8)pC->pReaderAudioStream->
6978 if( pC->pAudioEncDSI.pInfo != M4OSA_NULL )
6981 streamAudioInfo.Header.Size = pC->pAudioEncDSI.infoSize;
6982 streamAudioInfo.Header.pBuf = pC->pAudioEncDSI.pInfo;
6995 pC->WriterAudioStream.decoderSpecificInfo =
7000 err = pC->pWriterGlobalFcts->pFctAddStream(pC->pWriterContext,
7001 &pC->WriterAudioStream);
7013 pC->WriterAudioAU.stream = &(pC->WriterAudioStream);
7014 pC->WriterAudioAU.dataAddress = M4OSA_NULL;
7015 pC->WriterAudioAU.size = 0;
7016 pC->WriterAudioAU.CTS = 0; /** Reset time */
7017 pC->WriterAudioAU.DTS = 0;
7018 pC->WriterAudioAU.attribute = 0;
7019 pC->WriterAudioAU.nbFrag = 0; /** No fragment */
7020 pC->WriterAudioAU.frag = M4OSA_NULL;
7029 //pC->uiAudioMaxAuSize = M4MCS_AUDIO_MAX_AU_SIZE;
7030 switch( pC->WriterAudioStream.streamType )
7033 pC->uiAudioMaxAuSize = M4MCS_PCM_AMR_GRANULARITY_SAMPLES
7034 * (( pC->InputFileProperties.uiNbChannels
7039 pC->uiAudioMaxAuSize = M4MCS_PCM_MP3_GRANULARITY_SAMPLES
7040 * (( pC->InputFileProperties.uiNbChannels
7045 pC->uiAudioMaxAuSize = M4MCS_PCM_AAC_GRANULARITY_SAMPLES
7046 * (( pC->InputFileProperties.uiNbChannels
7050 pC->uiAudioMaxAuSize = M4MCS_PCM_EVRC_GRANULARITY_SAMPLES*
7051 ((pC->InputFileProperties.uiNbChannels * sizeof(short))+3);
7057 pC->WriterAudioStream.streamType);
7062 optionValue.value = pC->uiAudioMaxAuSize;
7063 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
7077 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
7094 TargetedFileSize = pC->uiMaxFileSize;
7099 err = pC->pWriterGlobalFcts->pFctSetOption(pC->pWriterContext,
7115 err = pC->pWriterGlobalFcts->pFctStartWriting(pC->pWriterContext);
7133 * M4OSA_ERR M4MCS_intPrepareAudioBeginCut(M4MCS_InternalContext* pC);
7135 * @param pC (IN) MCS private context
7140 static M4OSA_ERR M4MCS_intPrepareAudioBeginCut( M4MCS_InternalContext *pC )
7146 if( pC->noaudio )
7151 if( ( M4OSA_NULL == pC->pReaderAudioStream) || (0 == pC->uiBeginCutTime) )
7162 iCts = pC->uiBeginCutTime;
7163 err = pC->m_pReader->m_pFctJump(pC->pReaderContext,
7164 (M4_StreamHandler *)pC->pReaderAudioStream, &iCts);
7176 pC->iAudioCtsOffset = iCts;
7182 == pC->pReaderAudioStream->m_basicProperties.m_streamType)
7184 == pC->pReaderAudioStream->m_basicProperties.m_streamType) )
7190 if( ( iCts + 20) < (M4OSA_Int32)pC->uiBeginCutTime )
7194 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
7195 (M4_StreamHandler *)pC->pReaderAudioStream,
7196 &pC->ReaderAudioAU);
7218 while( ( iCts + 20) <= (M4OSA_Int32)pC->uiBeginCutTime )
7222 switch( pC->pReaderAudioStream->m_basicProperties.m_streamType )
7226 pC->ReaderAudioAU.m_dataAddress);
7231 pC->ReaderAudioAU.m_dataAddress);
7253 pC->ReaderAudioAU.m_dataAddress += uiFrameSize;
7254 pC->ReaderAudioAU.m_size -= uiFrameSize;
7259 pC->ReaderAudioAU.m_CTS = iCts;
7260 pC->ReaderAudioAU.m_DTS = iCts;
7265 pC->iAudioCtsOffset = iCts;
7277 * M4OSA_ERR M4MCS_intStepEncoding(M4MCS_InternalContext* pC, M4OSA_UInt8* pProgress)
7280 static M4OSA_ERR M4MCS_intStepEncoding( M4MCS_InternalContext *pC,
7288 if( ( pC->novideo == M4OSA_FALSE) && (M4MCS_kStreamState_STARTED
7289 == pC->VideoState) ) /**< If the video encoding is going on */
7291 if( pC->EncodingVideoFormat == M4ENCODER_kNULL )
7293 err = M4MCS_intVideoNullEncoding(pC);
7297 err = M4MCS_intVideoTranscoding(pC);
7304 *pProgress = (M4OSA_UInt8)(( ( (M4OSA_UInt32)pC->dViDecCurrentCts
7305 - pC->uiBeginCutTime) * 100)
7306 / (pC->uiEndCutTime - pC->uiBeginCutTime));
7308 pC->State = M4MCS_kState_FINISHED;
7311 if( pC->dViDecCurrentCts - pC->uiBeginCutTime == 0 )
7324 if( M4OSA_NULL != pC->m_air_context )
7326 err = M4AIR_cleanUp(pC->m_air_context);
7335 pC->m_air_context = M4OSA_NULL;
7359 if( ( pC->noaudio == M4OSA_FALSE) && (M4MCS_kStreamState_STARTED
7360 == pC->AudioState) ) /**< If there is an audio stream */
7364 ( ( pC->novideo == M4OSA_FALSE)
7365 && (M4MCS_kStreamState_STARTED == pC->VideoState)
7366 && (pC->ReaderAudioAU.m_CTS
7367 + pC->m_audioAUDuration < pC->ReaderVideoAU.m_CTS)) ||
7369 (( M4MCS_kStreamState_STARTED == pC->AudioState)
7375 err = M4MCS_intCheckAudioEffects(pC);
7385 if( pC->AudioEncParams.Format == M4ENCODER_kAudioNULL )
7387 err = M4MCS_intAudioNullEncoding(pC);
7391 err = M4MCS_intAudioTranscoding(pC);
7399 (M4OSA_UInt8)(( ( (M4OSA_UInt32)pC->ReaderAudioAU.m_CTS
7400 - pC->uiBeginCutTime) * 100)
7401 / (pC->uiEndCutTime - pC->uiBeginCutTime));
7403 pC->State = M4MCS_kState_FINISHED;
7406 if( pC->ReaderAudioAU.m_CTS - pC->uiBeginCutTime == 0 )
7419 if( M4OSA_NULL != pC->m_air_context )
7421 err = M4AIR_cleanUp(pC->m_air_context);
7430 pC->m_air_context = M4OSA_NULL;
7444 pC->AudioState = M4MCS_kStreamState_FINISHED;
7460 (2*pC->m_audioAUDuration) */
7461 if( (M4OSA_UInt32)pC->ReaderAudioAU.m_CTS
7462 + (2 *pC->m_audioAUDuration) > pC->uiEndCutTime )
7464 pC->AudioState = M4MCS_kStreamState_FINISHED;
7474 if( pC->novideo )
7476 if( pC->ReaderAudioAU.m_CTS < pC->uiBeginCutTime )
7482 *pProgress = (M4OSA_UInt8)(( ( (M4OSA_UInt32)pC->ReaderAudioAU.m_CTS
7483 - pC->uiBeginCutTime) * 100)
7484 / (pC->uiEndCutTime - pC->uiBeginCutTime));
7486 //printf(": %6.0f\b\b\b\b\b\b\b\b", pC->ReaderAudioAU.m_CTS);
7491 if( pC->dViDecCurrentCts < pC->uiBeginCutTime )
7497 *pProgress = (M4OSA_UInt8)(( ( (M4OSA_UInt32)pC->dViDecCurrentCts
7498 - pC->uiBeginCutTime) * 100)
7499 / (pC->uiEndCutTime - pC->uiBeginCutTime));
7501 //printf(": %6.0f\b\b\b\b\b\b\b\b", pC->dViDecCurrentCts);
7513 if( pC->novideo == M4OSA_FALSE )
7515 if( pC->EncodingVideoFormat == M4ENCODER_kNULL )
7517 pC->dViDecCurrentCts += 1;
7521 pC->dViDecCurrentCts += pC->dCtsIncrement;
7527 if( ( ( pC->novideo) || (M4MCS_kStreamState_FINISHED == pC->VideoState))
7528 && (( pC->noaudio) || (M4MCS_kStreamState_FINISHED == pC
7534 if( M4OSA_NULL != pC->m_air_context )
7536 err = M4AIR_cleanUp(pC->m_air_context);
7545 pC->m_air_context = M4OSA_NULL;
7552 pC->State = M4MCS_kState_FINISHED;
7566 * M4OSA_ERR M4MCS_intStepBeginVideoJump(M4MCS_InternalContext* pC)
7569 static M4OSA_ERR M4MCS_intStepBeginVideoJump( M4MCS_InternalContext *pC )
7574 if( pC->novideo )
7576 pC->State = M4MCS_kState_BEGINVIDEODECODE;
7582 iCts = (M4OSA_Int32)pC->dViDecStartingCts;
7583 err = pC->m_pReader->m_pFctGetPrevRapTime(pC->pReaderContext,
7584 (M4_StreamHandler *)pC->pReaderVideoStream, &iCts);
7589 iCts = (M4OSA_Int32)pC->dViDecStartingCts - M4MCS_NO_STSS_JUMP_POINT;
7604 if( M4OSA_TRUE == pC->bH264Trim )
7612 err = pC->m_pReader->m_pFctJump(pC->pReaderContext,
7613 (M4_StreamHandler *)pC->pReaderVideoStream, &iCts);
7623 if( pC->ReaderVideoAU1.m_structSize == 0 )
7627 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
7628 (M4_StreamHandler *)pC->pReaderVideoStream,
7629 &pC->ReaderVideoAU1);
7638 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
7639 (M4_StreamHandler *)pC->pReaderVideoStream,
7640 &pC->ReaderVideoAU1);
7648 pC->VideoState = M4MCS_kStreamState_FINISHED;
7660 pC->ReaderVideoAU1.m_structSize = 0;
7663 err = H264MCS_ProcessSPS_PPS(pC->m_pInstance,
7664 (M4OSA_UInt8 *)pC->ReaderVideoAU1.m_dataAddress, pC->ReaderVideoAU1.m_size);
7685 pC->dViDecCurrentCts = (M4OSA_Double)(iCts + pC->iVideoBeginDecIncr);
7689 if( pC->dViDecCurrentCts > pC->dViDecStartingCts )
7691 pC->dViDecCurrentCts = pC->dViDecStartingCts;
7698 pC->dViDecCurrentCts);
7699 pC->isRenderDup = M4OSA_FALSE;
7701 pC->m_pVideoDecoder->m_pFctDecode(pC->pViDecCtxt, &pC->dViDecCurrentCts,
7715 pC->isRenderDup = M4OSA_TRUE;
7720 pC->dViDecCurrentCts += (M4OSA_Double)pC->iVideoBeginDecIncr;
7724 if( pC->dViDecCurrentCts > pC->dViDecStartingCts )
7728 pC->dViDecCurrentCts = pC->dViDecStartingCts;
7729 pC->State = M4MCS_kState_PROCESSING;
7733 pC->State = M4MCS_kState_BEGINVIDEODECODE;
7744 * M4OSA_ERR M4MCS_intStepBeginVideoDecode(M4MCS_InternalContext* pC)
7747 static M4OSA_ERR M4MCS_intStepBeginVideoDecode( M4MCS_InternalContext *pC )
7752 if( pC->novideo )
7754 pC->State = M4MCS_kState_PROCESSING;
7760 dDecTarget = pC->dViDecCurrentCts;
7762 pC->dViDecCurrentCts);
7763 pC->isRenderDup = M4OSA_FALSE;
7764 err = pC->m_pVideoDecoder->m_pFctDecode(pC->pViDecCtxt, &dDecTarget,
7778 pC->isRenderDup = M4OSA_TRUE;
7783 pC->dViDecCurrentCts += (M4OSA_Double)pC->iVideoBeginDecIncr;
7787 if( ( (M4OSA_UInt32)pC->dViDecCurrentCts > pC->dViDecStartingCts)
7792 pC->dViDecCurrentCts = (M4OSA_Double)pC->dViDecStartingCts;
7793 pC->State = M4MCS_kState_PROCESSING;
7864 * M4OSA_ERR M4MCS_intAudioNullEncoding(M4MCS_InternalContext* pC)
7869 static M4OSA_ERR M4MCS_intAudioNullEncoding( M4MCS_InternalContext *pC )
7873 if( pC->noaudio )
7877 if( pC->ReaderAudioAU.m_size == 0 )
7881 if( pC->ReaderAudioAU1.m_structSize == 0 )
7885 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
7886 (M4_StreamHandler *)pC->pReaderAudioStream,
7887 &pC->ReaderAudioAU1);
7897 pC->m_pDataAddress1 =
7898 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->ReaderAudioAU1.m_maxsize,
7901 if( pC->m_pDataAddress1 == M4OSA_NULL )
7908 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
7909 (M4_StreamHandler *)pC->pReaderAudioStream,
7910 &pC->ReaderAudioAU1);
7918 pC->AudioState = M4MCS_kStreamState_FINISHED;
7931 if( pC->ReaderAudioAU1.m_maxsize
7932 > pC->pReaderAudioStream->m_basicProperties.m_maxAUSize )
7936 *) &(pC->m_pDataAddress1), pC->ReaderAudioAU1.m_maxsize);
7937 /* pC->m_pDataAddress1 and
7938 pC->m_pDataAddress2 must be reallocated at the same time */
7939 /* because pC->pReaderAudioStream->m_basicProperties.m_maxAUSize take
7940 maximum value. Then the test "if(pC->ReaderAudioAU?.m_maxsize >
7941 pC->pReaderAudioStream->m_basicProperties.m_maxAUSize)" is never true */
7944 *) &(pC->m_pDataAddress2), pC->ReaderAudioAU1.m_maxsize);
7945 /* pC->m_pDataAddress1 and
7946 pC->m_pDataAddress2 must be reallocated at the same time */
7948 pC->pReaderAudioStream->m_basicProperties.m_maxAUSize =
7949 pC->ReaderAudioAU1.m_maxsize;
7952 memcpy((void *)pC->m_pDataAddress1,
7953 (void *)pC->ReaderAudioAU1.m_dataAddress,
7954 pC->ReaderAudioAU1.m_size);
7957 if( pC->ReaderAudioAU2.m_structSize == 0 )
7961 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
7962 (M4_StreamHandler *)pC->pReaderAudioStream,
7963 &pC->ReaderAudioAU2);
7972 pC->m_pDataAddress2 =
7973 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->ReaderAudioAU2.m_maxsize,
7976 if( pC->m_pDataAddress2 == M4OSA_NULL )
7985 if( pC->ReaderAudioAU2.m_CTS > pC->ReaderAudioAU1.m_CTS )
7987 memcpy((void *) &pC->ReaderAudioAU,
7988 (void *) &pC->ReaderAudioAU2, sizeof(M4_AccessUnit));
7989 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
7990 (M4_StreamHandler *)pC->pReaderAudioStream,
7991 &pC->ReaderAudioAU1);
7993 if( pC->ReaderAudioAU1.m_maxsize
7994 > pC->pReaderAudioStream->m_basicProperties.m_maxAUSize )
7998 *) &(pC->m_pDataAddress1), pC->ReaderAudioAU1.m_maxsize);
7999 /* pC->m_pDataAddress1
8000 * and pC->m_pDataAddress2 must be reallocated at the same time *
8001 * because pC->pReaderAudioStream->m_basicProperties.m_maxAUSize take
8002 * maximum value. Then the test "if(pC->ReaderAudioAU?.m_maxsize >
8003 * pC->pReaderAudioStream->m_basicProperties.m_maxAUSize)" is never true *
8007 *) &(pC->m_pDataAddress2), pC->ReaderAudioAU1.m_maxsize);
8008 /* pC->m_pDataAddress1 and
8009 * pC->m_pDataAddress2 must be reallocated at the same time
8012 pC->pReaderAudioStream->m_basicProperties.m_maxAUSize =
8013 pC->ReaderAudioAU1.m_maxsize;
8016 memcpy((void *)pC->m_pDataAddress1,
8017 (void *)pC->ReaderAudioAU1.m_dataAddress,
8018 pC->ReaderAudioAU1.m_size);
8019 pC->m_audioAUDuration =
8020 pC->ReaderAudioAU1.m_CTS - pC->ReaderAudioAU2.m_CTS;
8021 pC->ReaderAudioAU.m_dataAddress = pC->m_pDataAddress2;
8025 memcpy((void *) &pC
8026 (void *) &pC->ReaderAudioAU1, sizeof(M4_AccessUnit));
8027 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
8028 (M4_StreamHandler *)pC->pReaderAudioStream,
8029 &pC->ReaderAudioAU2);
8033 if( pC->ReaderAudioAU2.m_maxsize
8034 > pC->pReaderAudioStream->m_basicProperties.m_maxAUSize )
8038 *) &(pC->m_pDataAddress2), pC->ReaderAudioAU2.m_maxsize);
8039 /* pC->m_pDataAddress1 and
8040 * pC->m_pDataAddress2 must be reallocated at the same time
8041 * because pC->pReaderAudioStream->m_basicProperties.m_maxAUSize take maximum
8042 * value. Then the test "if(pC->ReaderAudioAU?.m_maxsize > pC->pReaderAudioStream->
8047 *) &(pC->m_pDataAddress1), pC->ReaderAudioAU2.m_maxsize);
8048 /* [ END ] 20091008 JFV PR fix surnxpsw#1071: pC->m_pDataAddress1 and
8049 pC->m_pDataAddress2 must be reallocated at the same time */
8051 pC->pReaderAudioStream->m_basicProperties.m_maxAUSize =
8052 pC->ReaderAudioAU2.m_maxsize;
8055 memcpy((void *)pC->m_pDataAddress2,
8056 (void *)pC->ReaderAudioAU2.m_dataAddress,
8057 pC->ReaderAudioAU2.m_size);
8058 pC->m_audioAUDuration =
8059 pC->ReaderAudioAU2.m_CTS - pC->ReaderAudioAU1.m_CTS;
8060 pC->ReaderAudioAU.m_dataAddress = pC->m_pDataAddress1;
8069 pC->AudioState = M4MCS_kStreamState_FINISHED;
8084 err = pC->pWriterDataFcts->pStartAU(pC->pWriterContext,
8085 M4MCS_WRITER_AUDIO_STREAM_ID, &pC->WriterAudioAU);
8095 if( pC->uiAudioAUCount
8099 if( pC->InputFileProperties.AudioStreamType == M4VIDEOEDITING_kAAC
8100 || pC->InputFileProperties.AudioStreamType
8102 || pC->InputFileProperties.AudioStreamType
8105 if( pC->InputFileProperties.uiNbChannels == 1 )
8107 pC->WriterAudioAU.size = M4VSS3GPP_AAC_AU_SILENCE_MONO_SIZE;
8108 memcpy((void *)pC->WriterAudioAU.dataAddress,
8110 pC->WriterAudioAU.size);
8112 else if( pC->InputFileProperties.uiNbChannels == 2 )
8114 pC->WriterAudioAU.size = M4VSS3GPP_AAC_AU_SILENCE_STEREO_SIZE;
8115 memcpy((void *)pC->WriterAudioAU.dataAddress,
8117 pC->WriterAudioAU.size);
8127 else if( pC->InputFileProperties.AudioStreamType
8130 pC->WriterAudioAU.size = M4VSS3GPP_AMR_AU_SILENCE_FRAME_048_SIZE;
8131 memcpy((void *)pC->WriterAudioAU.dataAddress,
8133 pC->WriterAudioAU.size);
8135 if( pC->ReaderAudioAU.m_size != 0 )
8138 pC->WriterAudioAU.size += pC->ReaderAudioAU.m_size;
8139 memcpy((void *)(pC->WriterAudioAU.dataAddress
8141 (void *)pC->ReaderAudioAU.m_dataAddress,
8142 pC->ReaderAudioAU.m_size);
8150 pC->ReaderAudioAU.m_size);
8151 memcpy((void *)pC->WriterAudioAU.dataAddress,
8152 (void *)pC->ReaderAudioAU.m_dataAddress,
8153 pC->ReaderAudioAU.m_size);
8154 pC->WriterAudioAU.size = pC->ReaderAudioAU.m_size;
8163 pC->ReaderAudioAU.m_size);
8164 memcpy((void *)pC->WriterAudioAU.dataAddress,
8165 (void *)pC->ReaderAudioAU.m_dataAddress,
8166 pC->ReaderAudioAU.m_size);
8167 pC->WriterAudioAU.size = pC->ReaderAudioAU.m_size;
8172 pC->WriterAudioAU.CTS =
8173 (M4OSA_Time)((( pC->ReaderAudioAU.m_CTS - pC->iAudioCtsOffset)
8174 * (pC->WriterAudioStream.timeScale / 1000.0)));
8176 if( pC->InputFileProperties.AudioStreamType == M4VIDEOEDITING_kAMR_NB
8177 && pC->uiAudioAUCount == 0 )
8179 pC->iAudioCtsOffset -=
8183 pC->WriterAudioAU.nbFrag = 0;
8185 pC->WriterAudioAU.CTS);
8189 pC->uiAudioAUCount++;
8190 err = pC->pWriterDataFcts->pProcessAU(pC->pWriterContext,
8191 M4MCS_WRITER_AUDIO_STREAM_ID, &pC->WriterAudioAU);
8202 pC->ReaderAudioAU.m_size = 0;
8216 static M4OSA_ERR M4MCS_intAudioTranscoding( M4MCS_InternalContext *pC )
8260 M4OSA_Int8 *pActiveEffectNumber = &(pC->pActiveEffectNumber);
8264 if( pC->noaudio )
8273 if( M4OSA_NULL != pC->pPosInDecBufferOut )
8278 err = pC->m_pAudioDecoder->m_pFctStepAudioDec(pC->pAudioDecCtxt,
8279 M4OSA_NULL, &pC->AudioDecBufferOut, M4OSA_FALSE);
8292 fwrite(pC->AudioDecBufferOut.m_dataAddress,
8293 pC->AudioDecBufferOut.m_bufferSize, 1, file_pcm_decoder);
8297 pC->m_pAudioDecoder->m_pFctGetOptionAudioDec(pC->pAudioDecCtxt,
8301 pC->AudioState = M4MCS_kStreamState_FINISHED;
8309 pC->pPosInDecBufferOut = pC->AudioDecBufferOut.m_dataAddress;
8319 if( M4OSA_NULL != pC->pPosInSsrcBufferOut )
8325 uiSsrcInSize = pC->iSsrcNbSamplIn * sizeof(short)
8326 * pC->pReaderAudioStream->m_nbChannels;
8327 uiBytesDec = ( pC->AudioDecBufferOut.m_dataAddress
8328 + pC->AudioDecBufferOut.m_bufferSize) - pC->pPosInDecBufferOut;
8331 if( ( pC->pPosInSsrcBufferIn == pC->pSsrcBufferIn)
8334 pSsrcInput = pC->pPosInDecBufferOut;
8338 pC->pPosInDecBufferOut = M4OSA_NULL;
8340 pC->pPosInDecBufferOut += uiSsrcInSize;
8347 uiSsrcInRoom = ( pC->pSsrcBufferIn + uiSsrcInSize) - pC->pPosInSsrcBufferIn;
8357 memcpy((void *)pC->pPosInSsrcBufferIn, (void *)pC->pPosInDecBufferOut,
8362 pC->pPosInDecBufferOut += uiDecoder2Ssrc_NbBytes;
8366 pC->pPosInSsrcBufferIn += uiDecoder2Ssrc_NbBytes;
8370 if( ( pC->pPosInDecBufferOut - pC->AudioDecBufferOut.m_dataAddress)
8371 == (M4OSA_Int32)pC->AudioDecBufferOut.m_bufferSize )
8373 pC->pPosInDecBufferOut = M4OSA_NULL;
8377 if( ( pC->pPosInSsrcBufferIn - pC->pSsrcBufferIn)
8383 pSsrcInput = pC->pSsrcBufferIn;
8386 pC->pPosInSsrcBufferIn = pC->pSsrcBufferIn;
8401 if( pC->pReaderAudioStream->m_nbChannels == 1 )
8404 (short *)M4OSA_32bitAlignedMalloc((pC->iSsrcNbSamplOut * sizeof(short) * 2
8405 * ((*pC).InputFileProperties).uiNbChannels),
8407 memset((void *)tempBuffOut, 0,(pC->iSsrcNbSamplOut * sizeof(short) * 2
8408 * ((*pC).InputFileProperties).uiNbChannels));
8411 pC->iSsrcNbSamplOut, pC->pLVAudioResampler);
8415 memset((void *)pC->pSsrcBufferOut, 0, (pC->iSsrcNbSamplOut * sizeof(short)
8416 * ((*pC).InputFileProperties).uiNbChannels));
8418 LVAudioresample_LowQuality((short *)pC->pSsrcBufferOut,
8419 (short *)pSsrcInput, pC->iSsrcNbSamplOut, pC->pLVAudioResampler);
8422 if( pC->pReaderAudioStream->m_nbChannels == 1 )
8424 From2iToMono_16((short *)tempBuffOut, (short *)pC->pSsrcBufferOut,
8425 (short)pC->iSsrcNbSamplOut);
8439 pC->pPosInSsrcBufferOut = pC->pSsrcBufferOut;
8449 if( ( pC->AudioEncParams.ChannelNum == M4ENCODER_kMono)
8450 && (pC->pReaderAudioStream->m_nbChannels == 2) )
8455 else if( ( pC->AudioEncParams.ChannelNum == M4ENCODER_kStereo)
8456 && (pC->pReaderAudioStream->m_nbChannels == 1) )
8468 uiSsrcOutSize = pC->iSsrcNbSamplOut * sizeof(short)
8469 * pC->pReaderAudioStream->m_nbChannels;
8471 pC->pSsrcBufferOut + uiSsrcOutSize) - pC->pPosInSsrcBufferOut;
8474 if( pC->pPosInSsrcBufferOut == pC->pSsrcBufferOut )
8477 pC->audioEncoderGranularity * uiChannelConvertorCoeff / 2;
8480 if( ( pC->pPosInAudioEncoderBuffer == M4OSA_NULL)
8485 pC->pPosInSsrcBufferOut = M4OSA_NULL;
8487 pC->pPosInSsrcBufferOut += uiSsrc2Encoder_NbBytes;
8490 pC->pPosInAudioEncoderBuffer =
8491 pC->pAudioEncoderBuffer + pC->audioEncoderGranularity;
8496 pEncoderInput = pC->pAudioEncoderBuffer;
8498 pChannelConvertorInput = pC->pSsrcBufferOut;
8499 pChannelConvertorOutput = pC->pAudioEncoderBuffer;
8508 pEncoderInput = pC->pSsrcBufferOut;
8517 if( pC->pPosInAudioEncoderBuffer == M4OSA_NULL )
8519 pC->pPosInAudioEncoderBuffer = pC->pAudioEncoderBuffer;
8522 uiEncoderInRoom = ( pC->pAudioEncoderBuffer + pC->audioEncoderGranularity)
8523 - pC->pPosInAudioEncoderBuffer;
8524 pEncoderInput = pC->pAudioEncoderBuffer;
8536 pChannelConvertorInput = pC->pPosInSsrcBufferOut;
8537 pChannelConvertorOutput = pC->pPosInAudioEncoderBuffer;
8543 memcpy((void *)pC->pPosInAudioEncoderBuffer, (void *)pC->pPosInSsrcBufferOut,
8548 pC->pPosInSsrcBufferOut += uiSsrc2Encoder_NbBytes;
8551 pC->pPosInAudioEncoderBuffer +=
8555 if( ( pC->pPosInSsrcBufferOut - pC->pSsrcBufferOut)
8558 pC->pPosInSsrcBufferOut = M4OSA_NULL;
8598 if( ( pC->pPosInAudioEncoderBuffer - pC->pAudioEncoderBuffer)
8599 < (M4OSA_Int32)pC->audioEncoderGranularity )
8606 pEncInBuffer.pTableBufferSize[0] = pC->audioEncoderGranularity;
8613 / sizeof(short) / pC->pReaderAudioStream->m_nbChannels;
8617 err = pC->pWriterDataFcts->pStartAU(pC->pWriterContext,
8618 M4MCS_WRITER_AUDIO_STREAM_ID, &pC->WriterAudioAU);
8629 if( *pActiveEffectNumber >= 0 && *pActiveEffectNumber < pC->nbEffects )
8631 if( pC->pEffects[*pActiveEffectNumber].ExtAudioEffectFct != M4OSA_NULL )
8635 pProgress.uiClipTime = (M4OSA_UInt32)pC->ReaderAudioAU.m_CTS;
8637 pProgress.uiOutputTime = ( pC->WriterAudioAU.CTS * 1000)
8638 / pC->WriterAudioStream.timeScale;
8639 tempProgress = ( (M4OSA_UInt32)pC->ReaderAudioAU.m_CTS
8640 - pC->pEffects[*pActiveEffectNumber].uiStartTime
8641 - pC->uiBeginCutTime) * 1000;
8643 (M4OSA_UInt32)(tempProgress / (M4OSA_UInt32)pC->pEffects[
8646 err = pC->pEffects[*pActiveEffectNumber].ExtAudioEffectFct(
8647 pC->pEffects[*pActiveEffectNumber].pExtAudioEffectFctCtxt,
8664 (M4OSA_MemAddr8)pC->WriterAudioAU.dataAddress;
8674 if( M4OSA_FALSE == pC->b_isRawWriter )
8678 if( pC->pOutputPCMfile != M4OSA_NULL )
8680 pC->pOsaFileWritPtr->writeData(pC->pOutputPCMfile,
8686 err = pC->pAudioEncoderGlobalFcts->pFctStep(pC->pAudioEncCtxt,
8698 pC->pPosInAudioEncoderBuffer = M4OSA_NULL;
8702 pC->WriterAudioAU.size =
8705 pC->WriterAudioAU.CTS += frameTimeDelta;
8709 pC->m_audioAUDuration =
8710 ( frameTimeDelta * 1000) / pC->WriterAudioStream.timeScale;
8714 pC->uiAudioAUCount++;
8715 err = pC->pWriterDataFcts->pProcessAU(pC->pWriterContext,
8716 M4MCS_WRITER_AUDIO_STREAM_ID, &pC->WriterAudioAU);
8729 pC->pPosInAudioEncoderBuffer = M4OSA_NULL;
8731 pC->WriterAudioAU.dataAddress =
8734 pC->WriterAudioAU.size = pC->audioEncoderGranularity;
8735 pC->uiAudioAUCount++;
8737 err = pC->pWriterDataFcts->pProcessAU(pC->pWriterContext,
8738 M4MCS_WRITER_AUDIO_STREAM_ID, &pC->WriterAudioAU);
8790 * M4OSA_ERR M4MCS_intVideoNullEncoding(M4MCS_InternalContext* pC)
8795 static M4OSA_ERR M4MCS_intVideoNullEncoding( M4MCS_InternalContext *pC )
8807 if( pC->novideo )
8811 if( ( ( pC->bH264Trim == M4OSA_TRUE)
8812 && (pC->uiVideoAUCount < pC->m_pInstance->clip_sps.num_ref_frames)
8813 && (pC->uiBeginCutTime > 0))
8814 || (( pC->uiVideoAUCount == 0) && (pC->uiBeginCutTime > 0)) )
8816 err = M4MCS_intVideoTranscoding(pC);
8821 if((pC->bLastDecodedFrameCTS == M4OSA_FALSE) && (pC->uiBeginCutTime > 0))
8826 || (M4MCS_kEncoderRunning != pC->encoderState) )
8830 "returns 0x%X w/ encState=%d", err, pC->encoderState);
8836 if( pC->pVideoEncoderGlobalFcts->pFctStop != M4OSA_NULL )
8838 err = pC->pVideoEncoderGlobalFcts->pFctStop(pC->pViEncCtxt);
8848 pC->encoderState = M4MCS_kEncoderStopped;
8849 err = pC->pVideoEncoderGlobalFcts->pFctClose(pC->pViEncCtxt);
8858 pC->encoderState = M4MCS_kEncoderClosed;
8862 if ((pC->EncodingVideoFormat == M4ENCODER_kNULL)
8863 && (pC->bLastDecodedFrameCTS == M4OSA_FALSE)
8864 && (pC->uiBeginCutTime > 0)) {
8866 pC->bLastDecodedFrameCTS = M4OSA_TRUE;
8867 err = pC->m_pVideoDecoder->m_pFctGetOption(pC->pViDecCtxt,
8879 if (M4OSA_NULL != pC->pViDecCtxt) {
8880 err = pC->m_pVideoDecoder->m_pFctDestroy(pC->pViDecCtxt);
8881 pC->pViDecCtxt = M4OSA_NULL;
8891 err = pC->m_pReader->m_pFctJump(pC->pReaderContext,
8892 (M4_StreamHandler *)pC->pReaderVideoStream, &lastdecodedCTS);
8904 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
8905 (M4_StreamHandler *)pC->pReaderVideoStream, &lReaderVideoAU);
8914 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
8915 (M4_StreamHandler *)pC->pReaderVideoStream, &lReaderVideoAU);
8922 pC->VideoState = M4MCS_kStreamState_FINISHED;
8941 pC->bLastDecodedFrameCTS = M4OSA_TRUE;
8948 if (pC->ReaderVideoAU1.m_structSize == 0) {
8951 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
8952 (M4_StreamHandler *)pC->pReaderVideoStream,
8953 &pC->ReaderVideoAU1);
8962 pC->m_pDataVideoAddress1 =
8963 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->ReaderVideoAU1.m_maxsize, M4MCS,
8966 if (pC->m_pDataVideoAddress1 == M4OSA_NULL) {
8971 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
8972 (M4_StreamHandler *)pC->pReaderVideoStream,
8973 &pC->ReaderVideoAU1);
8981 pC->VideoState = M4MCS_kStreamState_FINISHED;
8992 if( pC->ReaderVideoAU1.m_maxsize
8993 > pC->pReaderVideoStream->m_basicProperties.m_maxAUSize )
8997 *) &(pC->m_pDataVideoAddress1), pC->ReaderVideoAU1.m_maxsize);
8998 /* pC->m_pDataVideoAddress1
8999 and pC->m_pDataVideoAddress2 must be reallocated at the same time */
9000 /* because pC->pReaderVideoStream->m_basicProperties.m_maxAUSize take maximum value.
9001 Then the test "if(pC->ReaderVideoAU?.m_maxsize > pC->pReaderVideoStream->
9005 *) &(pC->m_pDataVideoAddress2), pC->ReaderVideoAU1.m_maxsize);
9006 /* pC->m_pDataVideoAddress1 and
9007 pC->m_pDataVideoAddress2 must be reallocated at the same time */
9009 pC->pReaderVideoStream->m_basicProperties.m_maxAUSize =
9010 pC->ReaderVideoAU1.m_maxsize;
9012 memcpy((void *)pC->m_pDataVideoAddress1,
9013 (void *)pC->ReaderVideoAU1.m_dataAddress,
9014 pC->ReaderVideoAU1.m_size);
9017 if( pC->ReaderVideoAU2.m_structSize == 0 )
9021 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext,
9022 (M4_StreamHandler *)pC->pReaderVideoStream,
9023 &pC->ReaderVideoAU2);
9032 pC->m_pDataVideoAddress2 =
9033 (M4OSA_MemAddr8)M4OSA_32bitAlignedMalloc(pC->ReaderVideoAU2.m_maxsize, M4MCS,
9036 if( pC->m_pDataVideoAddress2 == M4OSA_NULL )
9044 if( pC->ReaderVideoAU2.m_CTS > pC->ReaderVideoAU1.m_CTS )
9046 memcpy((void *) &pC->ReaderVideoAU,
9047 (void *) &pC->ReaderVideoAU2, sizeof(M4_AccessUnit));
9048 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
9049 (M4_StreamHandler *)pC->pReaderVideoStream,
9050 &pC->ReaderVideoAU1);
9052 if( pC->ReaderVideoAU1.m_maxsize
9053 > pC->pReaderVideoStream->m_basicProperties.m_maxAUSize )
9057 *) &(pC->m_pDataVideoAddress1), pC->ReaderVideoAU1.m_maxsize);
9058 /* pC->m_pDataVideoAddress1 and
9059 pC->m_pDataVideoAddress2 must be reallocated at the same time */
9060 /* because pC->pReaderVideoStream->m_basicProperties.m_maxAUSize take maximum value.
9061 Then the test "if(pC->ReaderVideoAU?.m_maxsize > pC->pReaderVideoStream->
9065 *) &(pC->m_pDataVideoAddress2), pC->ReaderVideoAU1.m_maxsize);
9066 /* pC->m_pDataVideoAddress1 and
9067 pC->m_pDataVideoAddress2 must be reallocated at the same time */
9069 pC->pReaderVideoStream->m_basicProperties.m_maxAUSize =
9070 pC->ReaderVideoAU1.m_maxsize;
9072 memcpy((void *)pC->m_pDataVideoAddress1,
9073 (void *)pC->ReaderVideoAU1.m_dataAddress,
9074 pC->ReaderVideoAU1.m_size);
9075 videoAUDuration = pC->ReaderVideoAU1.m_CTS - pC->ReaderVideoAU2.m_CTS;
9076 pC->ReaderVideoAU.m_dataAddress = pC->m_pDataVideoAddress2;
9080 memcpy((void *) &pC->ReaderVideoAU,
9081 (void *) &pC->ReaderVideoAU1, sizeof(M4_AccessUnit));
9082 err = pC->m_pReaderDataIt->m_pFctGetNextAu(pC->pReaderContext,
9083 (M4_StreamHandler *)pC->pReaderVideoStream,
9084 &pC->ReaderVideoAU2);
9086 if( pC->ReaderVideoAU2.m_maxsize
9087 > pC->pReaderVideoStream->m_basicProperties.m_maxAUSize )
9091 *) &(pC->m_pDataVideoAddress2), pC->ReaderVideoAU2.m_maxsize);
9092 /* pC->m_pDataVideoAddress1 and
9093 pC->m_pDataVideoAddress2 must be reallocated at the same time */
9094 /* because pC->pReaderVideoStream->m_basicProperties.m_maxAUSize take maximum value.
9095 Then the test "if(pC->ReaderVideoAU?.m_maxsize > pC->pReaderVideoStream->
9099 *) &(pC->m_pDataVideoAddress1), pC->ReaderVideoAU2.m_maxsize);
9100 /* pC->m_pDataVideoAddress1 and
9101 pC->m_pDataVideoAddress2 must be reallocated at the same time */
9103 pC->pReaderVideoStream->m_basicProperties.m_maxAUSize =
9104 pC->ReaderVideoAU2.m_maxsize;
9106 memcpy((void *)pC->m_pDataVideoAddress2,
9107 (void *)pC->ReaderVideoAU2.m_dataAddress,
9108 pC->ReaderVideoAU2.m_size);
9109 videoAUDuration = pC->ReaderVideoAU2.m_CTS - pC->ReaderVideoAU1.m_CTS;
9110 pC->ReaderVideoAU.m_dataAddress = pC->m_pDataVideoAddress1;
9119 pC->VideoState = M4MCS_kStreamState_FINISHED;
9133 err = pC->pWriterDataFcts->pStartAU(pC->pWriterContext,
9134 M4MCS_WRITER_VIDEO_STREAM_ID, &pC->WriterVideoAU);
9147 pC->ReaderVideoAU.m_size);
9149 if( M4OSA_TRUE == pC->bH264Trim )
9151 if( pC->H264MCSTempBufferSize
9152 < (pC->ReaderVideoAU.m_size + 2048) )
9154 pC->H264MCSTempBufferSize =
9155 (pC->ReaderVideoAU.m_size + 2048);
9157 if( pC->H264MCSTempBuffer != M4OSA_NULL )
9159 free(pC->H264MCSTempBuffer);
9161 pC->H264MCSTempBuffer =
9162 (M4OSA_UInt8 *)M4OSA_32bitAlignedMalloc(pC->H264MCSTempBufferSize,
9163 M4MCS, (M4OSA_Char *)"pC->H264MCSTempBuffer");
9165 if( pC->H264MCSTempBuffer == M4OSA_NULL )
9173 pC->H264MCSTempBufferDataSize = pC->H264MCSTempBufferSize;
9175 err = H264MCS_ProcessNALU(pC->m_pInstance,
9176 (M4OSA_UInt8 *)pC->ReaderVideoAU.m_dataAddress,
9177 pC->ReaderVideoAU.m_size, pC->H264MCSTempBuffer,
9178 (M4OSA_Int32 *)&pC->H264MCSTempBufferDataSize);
9180 if( pC->m_pInstance->is_done == 1 )
9183 (M4OSA_UInt8 *)pC->ReaderVideoAU.m_dataAddress ,
9184 pC->ReaderVideoAU.m_size);
9186 memcpy((void *)pC->WriterVideoAU.dataAddress,
9187 (void *)(pC->ReaderVideoAU.m_dataAddress + 4),
9188 pC->ReaderVideoAU.m_size - 4);
9189 pC->WriterVideoAU.size = pC->ReaderVideoAU.m_size - 4;
9191 (M4OSA_MemAddr8)pC->WriterVideoAU.dataAddress;
9195 memcpy((void *)pC->WriterVideoAU.dataAddress,
9196 (void *)(pC->H264MCSTempBuffer + 4),
9197 pC->H264MCSTempBufferDataSize - 4);
9198 pC->WriterVideoAU.size = pC->H264MCSTempBufferDataSize - 4;
9200 (M4OSA_MemAddr8)pC->WriterVideoAU.dataAddress;
9206 memcpy((void *)pC->WriterVideoAU.dataAddress,
9207 (void *)pC->ReaderVideoAU.m_dataAddress,
9208 pC->ReaderVideoAU.m_size);
9209 pC->WriterVideoAU.size = pC->ReaderVideoAU.m_size;
9213 pC->WriterVideoAU.CTS =
9214 (M4OSA_Time)((( pC->ReaderVideoAU.m_CTS - pC->dViDecStartingCts)
9215 * (pC->WriterVideoStream.timeScale / 1000.0)));
9216 pC->WriterVideoAU.nbFrag = 0;
9217 pC->WriterVideoAU.attribute = pC->ReaderVideoAU.m_attribute;
9220 pC->WriterVideoAU.CTS);
9224 pC->uiVideoAUCount++;
9225 err = pC->pWriterDataFcts->pProcessAU(pC->pWriterContext,
9226 M4MCS_WRITER_VIDEO_STREAM_ID, &pC->WriterVideoAU);
9236 if( M4OSA_TRUE == pC->bH264Trim )
9238 if( pC->m_pInstance->is_done == 1 )
9241 (void *)(pC->ReaderVideoAU.m_dataAddress), 4);
9246 (void *)(pC->H264MCSTempBuffer), 4);
9254 if( pC->ReaderVideoAU.m_CTS + (2 *videoAUDuration) > pC->uiEndCutTime )
9256 pC->VideoState = M4MCS_kStreamState_FINISHED;
9267 * M4OSA_ERR M4MCS_intVideoTranscoding(M4MCS_InternalContext* pC)
9272 static M4OSA_ERR M4MCS_intVideoTranscoding( M4MCS_InternalContext *pC )
9281 mtTranscodedTime = pC->dViDecCurrentCts;
9289 pC->isRenderDup = M4OSA_FALSE;
9290 err = pC->m_pVideoDecoder->m_pFctDecode(pC->pViDecCtxt, &mtTranscodedTime,
9298 pC->VideoState = M4MCS_kStreamState_FINISHED;
9303 pC->isRenderDup = M4OSA_TRUE;
9317 if( ( pC->dViDecCurrentCts + pC->dCtsIncrement ) >= (pC->uiEndCutTime
9318 + M4MCS_ABS(pC->dViDecStartingCts - pC->uiBeginCutTime)) )
9323 pC->VideoState = M4MCS_kStreamState_FINISHED;
9324 derive = (M4OSA_Int32)(( pC->dViDecCurrentCts + pC->dCtsIncrement + 0.5)
9325 - (pC->uiEndCutTime
9326 + M4MCS_ABS(pC->dViDecStartingCts - pC->uiBeginCutTime)));
9331 if( pC->uiVideoAUCount == 0 )
9333 pC->dViDecStartingCts = mtTranscodedTime;
9334 pC->dViDecCurrentCts = pC->dViDecStartingCts;
9341 = %.2f",pC->ReaderVideoAU.m_CTS);
9342 pC->uiVideoAUCount++;
9344 err = pC->pVideoEncoderGlobalFcts->pFctEncode(pC->pViEncCtxt, M4OSA_NULL,
9345 (pC->dViDecCurrentCts - pC->dViDecStartingCts - (derive >> 1)),
9361 static M4OSA_ERR M4MCS_intGetInputClipProperties( M4MCS_InternalContext *pC )
9372 M4OSA_DEBUG_IF2(M4OSA_NULL == pC, M4ERR_PARAMETER,
9373 "M4MCS_intGetInputClipProperties: pC is M4OSA_NULL");
9377 pC->InputFileProperties.bAnalysed = M4OSA_FALSE;
9378 pC->InputFileProperties.FileType = 0;
9379 pC->InputFileProperties.Version[0] = M4VIDEOEDITING_VERSION_MAJOR;
9380 pC->InputFileProperties.Version[1] = M4VIDEOEDITING_VERSION_MINOR;
9381 pC->InputFileProperties.Version[2] = M4VIDEOEDITING_VERSION_REVISION;
9382 pC->InputFileProperties.uiClipDuration = 0;
9384 memset((void *) &pC->InputFileProperties.ftyp,
9389 pC->InputFileProperties.VideoStreamType = M4VIDEOEDITING_kNoneVideo;
9390 pC->InputFileProperties.uiClipVideoDuration = 0;
9391 pC->InputFileProperties.uiVideoBitrate = 0;
9392 pC->InputFileProperties.uiVideoMaxAuSize = 0;
9393 pC->InputFileProperties.uiVideoWidth = 0;
9394 pC->InputFileProperties.uiVideoHeight = 0;
9395 pC->InputFileProperties.uiVideoTimeScale = 0;
9396 pC->InputFileProperties.fAverageFrameRate = 0.0;
9397 pC->InputFileProperties.uiVideoLevel =
9399 pC->InputFileProperties.uiVideoProfile =
9401 pC->InputFileProperties.bMPEG4dataPartition = M4OSA_FALSE;
9402 pC->InputFileProperties.bMPEG4rvlc = M4OSA_FALSE;
9403 pC->InputFileProperties.bMPEG4resynchMarker = M4OSA_FALSE;
9407 pC->InputFileProperties.AudioStreamType = M4VIDEOEDITING_kNoneAudio;
9408 pC->InputFileProperties.uiClipAudioDuration = 0;
9409 pC->InputFileProperties.uiAudioBitrate = 0;
9410 pC->InputFileProperties.uiAudioMaxAuSize = 0;
9411 pC->InputFileProperties.uiNbChannels = 0;
9412 pC->InputFileProperties.uiSamplingFrequency = 0;
9413 pC->InputFileProperties.uiExtendedSamplingFrequency = 0;
9414 pC->InputFileProperties.uiDecodedPcmSize = 0;
9417 pC->InputFileProperties.bVideoIsEditable = M4OSA_FALSE;
9418 pC->InputFileProperties.bAudioIsEditable = M4OSA_FALSE;
9419 pC->InputFileProperties.bVideoIsCompatibleWithMasterClip = M4OSA_FALSE;
9420 pC->InputFileProperties.bAudioIsCompatibleWithMasterClip = M4OSA_FALSE;
9424 if( M4OSA_NULL != pC->pReaderVideoStream )
9426 switch( pC->pReaderVideoStream->m_basicProperties.m_streamType )
9429 pC->InputFileProperties.VideoStreamType = M4VIDEOEDITING_kMPEG4;
9433 pC->InputFileProperties.VideoStreamType = M4VIDEOEDITING_kH263;
9437 pC->InputFileProperties.VideoStreamType = M4VIDEOEDITING_kH264;
9442 pC->InputFileProperties.VideoStreamType =
9448 pC->InputFileProperties.uiVideoBitrate =
9449 pC->pReaderVideoStream->m_basicProperties.m_averageBitRate;
9451 if( 0 == pC->InputFileProperties.uiVideoBitrate )
9453 pC->m_pReader->m_pFctGetOption(pC->pReaderContext,
9456 if( M4OSA_NULL != pC->pReaderAudioStream )
9460 pC->pReaderAudioStream->m_basicProperties.m_averageBitRate;
9462 pC->InputFileProperties.uiVideoBitrate = videoBitrate;
9467 if( ( M4VIDEOEDITING_kH263 != pC->InputFileProperties.VideoStreamType)
9469 != pC->InputFileProperties.VideoStreamType) )
9475 err = M4DECODER_EXTERNAL_ParseVideoDSI(pC->pReaderVideoStream->
9477 pC->pReaderVideoStream->
9490 pC->pReaderVideoStream->m_videoWidth = videoSize.m_uiWidth;
9491 pC->pReaderVideoStream->m_videoHeight = videoSize.m_uiHeight;
9492 pC->InputFileProperties.uiVideoTimeScale = DecConfInfo.uiTimeScale;
9493 pC->InputFileProperties.bMPEG4dataPartition =
9495 pC->InputFileProperties.bMPEG4rvlc = DecConfInfo.bUseOfRVLC;
9496 pC->InputFileProperties.bMPEG4resynchMarker =
9500 &(pC->InputFileProperties.uiVideoProfile),
9501 &(pC->InputFileProperties.uiVideoLevel));
9509 pC->InputFileProperties.VideoStreamType ) {
9511 err = getH263ProfileAndLevel(pC->pReaderVideoStream->
9513 pC->pReaderVideoStream->m_basicProperties.m_decoderSpecificInfoSize,
9514 &(pC->InputFileProperties.uiVideoProfile),
9515 &(pC->InputFileProperties.uiVideoLevel));
9522 pC->InputFileProperties.uiVideoTimeScale = 30000;
9525 pC->InputFileProperties.VideoStreamType ) {
9527 pC->InputFileProperties.uiVideoTimeScale = 30000;
9528 err = getAVCProfileAndLevel(pC->pReaderVideoStream->
9530 pC->pReaderVideoStream->m_basicProperties.m_decoderSpecificInfoSize,
9531 &(pC->InputFileProperties.uiVideoProfile),
9532 &(pC->InputFileProperties.uiVideoLevel));
9542 pC->InputFileProperties.uiVideoHeight =
9543 pC->pReaderVideoStream->m_videoHeight;
9544 pC->InputFileProperties.uiVideoWidth =
9545 pC->pReaderVideoStream->m_videoWidth;
9546 pC->InputFileProperties.uiClipVideoDuration =
9547 (M4OSA_UInt32)pC->pReaderVideoStream->m_basicProperties.m_duration;
9548 pC->InputFileProperties.fAverageFrameRate =
9549 pC->pReaderVideoStream->m_averageFrameRate;
9550 pC->InputFileProperties.uiVideoMaxAuSize =
9551 pC->pReaderVideoStream->m_basicProperties.m_maxAUSize;
9552 pC->InputFileProperties.videoRotationDegrees =
9553 pC->pReaderVideoStream->videoRotationDegrees;
9557 if( M4OSA_TRUE == pC->bUnsupportedVideoFound )
9559 pC->InputFileProperties.VideoStreamType =
9564 pC->InputFileProperties.VideoStreamType = M4VIDEOEDITING_kNoneVideo;
9570 if( M4OSA_NULL != pC->pReaderAudioStream )
9572 switch( pC->pReaderAudioStream->m_basicProperties.m_streamType )
9575 pC->InputFileProperties.AudioStreamType =
9580 pC->InputFileProperties.AudioStreamType = M4VIDEOEDITING_kAAC;
9584 pC->InputFileProperties.AudioStreamType = M4VIDEOEDITING_kMP3;
9588 pC->InputFileProperties.AudioStreamType = M4VIDEOEDITING_kEVRC;
9593 pC->InputFileProperties.AudioStreamType =
9598 if( ( M4OSA_NULL != pC->m_pAudioDecoder)
9599 && (M4OSA_NULL == pC->pAudioDecCtxt) )
9603 pC->m_pCurrentAudioDecoderUserData);
9605 if( M4OSA_FALSE == pC->bExtOMXAudDecoder ) {
9606 err = M4MCS_intCheckAndGetCodecProperties(pC);
9610 err = pC->m_pAudioDecoder->m_pFctCreateAudioDec(
9611 &pC->pAudioDecCtxt, pC->pReaderAudioStream,
9612 pC->m_pCurrentAudioDecoderUserData);
9619 pC->AacProperties.aNumChan =
9620 pC->pReaderAudioStream->m_nbChannels;
9621 pC->AacProperties.aSampFreq =
9622 pC->pReaderAudioStream->m_samplingFrequency;
9624 err = pC->m_pAudioDecoder->m_pFctGetOptionAudioDec(
9625 pC->pAudioDecCtxt, M4AD_kOptionID_StreamType,
9648 pC->AacProperties.aSBRPresent = 0;
9649 pC->AacProperties.aPSPresent = 0;
9653 pC->AacProperties.aSBRPresent = 1;
9654 pC->AacProperties.aPSPresent = 0;
9655 pC->AacProperties.aExtensionSampFreq =
9656 pC->pReaderAudioStream->
9661 pC->AacProperties.aSBRPresent = 1;
9662 pC->AacProperties.aPSPresent = 1;
9663 pC->AacProperties.aExtensionSampFreq =
9664 pC->pReaderAudioStream->
9674 pC->AacProperties.aNumChan,
9675 pC->AacProperties.aSampFreq);
9690 if( pC->pReaderAudioStream->m_basicProperties.m_streamType
9694 pC->pReaderAudioStream->m_nbChannels = 1;
9695 pC->pReaderAudioStream->m_samplingFrequency = 8000;
9701 if( 0 == pC->pReaderAudioStream->m_basicProperties.m_averageBitRate )
9704 == pC->InputFileProperties.AudioStreamType )
9709 pC->InputFileProperties.uiAudioBitrate =
9713 == pC->InputFileProperties.AudioStreamType )
9718 pC->InputFileProperties.uiAudioBitrate =
9727 err = pC->m_pReader->m_pFctGetOption(pC->pReaderContext,
9738 pC->InputFileProperties.uiAudioBitrate =
9740 - pC->
9747 pC->InputFileProperties.uiAudioBitrate =
9748 pC
9751 pC->InputFileProperties.uiNbChannels =
9752 pC->pReaderAudioStream->m_nbChannels;
9753 pC->InputFileProperties.uiSamplingFrequency =
9754 pC->pReaderAudioStream->m_samplingFrequency;
9755 pC->InputFileProperties.uiClipAudioDuration =
9756 (M4OSA_UInt32)pC->pReaderAudioStream->m_basicProperties.m_duration;
9757 pC->InputFileProperties.uiAudioMaxAuSize =
9758 pC->pReaderAudioStream->m_basicProperties.m_maxAUSize;
9761 pC->InputFileProperties.uiDecodedPcmSize =
9762 pC->pReaderAudioStream->m_byteFrameLength
9763 * pC->pReaderAudioStream->m_byteSampleSize
9764 * pC->pReaderAudioStream->m_nbChannels;
9768 == pC->pReaderAudioStream->m_basicProperties.m_streamType )
9770 pC->InputFileProperties.uiNbChannels = pC->AacProperties.aNumChan;
9771 pC->InputFileProperties.uiSamplingFrequency =
9772 pC->AacProperties.aSampFreq;
9774 if( pC->AacProperties.aSBRPresent )
9776 pC->InputFileProperties.AudioStreamType =
9778 pC->InputFileProperties.uiExtendedSamplingFrequency =
9779 pC->AacProperties.aExtensionSampFreq;
9782 if( pC->AacProperties.aPSPresent )
9784 pC->InputFileProperties.AudioStreamType =
9791 if( M4OSA_TRUE == pC->bUnsupportedAudioFound )
9793 pC->InputFileProperties.AudioStreamType =
9798 pC->InputFileProperties.AudioStreamType = M4VIDEOEDITING_kNoneAudio;
9803 err = pC->m_pReader->m_pFctGetOption(pC->pReaderContext,
9804 M4READER_kOptionID_3gpFtypBox, &pC->InputFileProperties.ftyp);
9807 if( pC->InputFileProperties.uiClipVideoDuration
9808 > pC->InputFileProperties.uiClipAudioDuration )
9809 pC->InputFileProperties.uiClipDuration =
9810 pC->InputFileProperties.uiClipVideoDuration;
9812 pC->InputFileProperties.uiClipDuration =
9813 pC->InputFileProperties.uiClipAudioDuration;
9815 pC->InputFileProperties.FileType = pC->InputFileType;
9816 pC->InputFileProperties.bAnalysed = M4OSA_TRUE;
9968 M4MCS_InternalContext *pC = (M4MCS_InternalContext *)(pContext);
9975 if( pC->uiMaxFileSize == 0 )
9979 if( pC->uiEndCutTime == 0 )
9981 duration = pC->InputFileProperties.uiClipDuration - pC->uiBeginCutTime;
9985 duration = pC->uiEndCutTime - pC->uiBeginCutTime;
9989 if( pC->noaudio )
9993 else if( pC->AudioEncParams.Format == M4ENCODER_kAudioNULL )
9995 audiobitrate = pC->InputFileProperties.uiAudioBitrate;
9997 else if( pC->uiAudioBitrate == M4VIDEOEDITING_kUndefinedBitrate )
9999 switch( pC->AudioEncParams.Format )
10011 (pC->AudioEncParams.ChannelNum == M4ENCODER_kMono)
10018 audiobitrate = pC->uiAudioBitrate;
10022 if( pC->novideo )
10026 else if( pC->EncodingVideoFormat == M4ENCODER_kNULL )
10028 videobitrate = pC->InputFileProperties.uiVideoBitrate;
10030 else if( pC->uiVideoBitrate == M4VIDEOEDITING_kUndefinedBitrate )
10036 videobitrate = pC->uiVideoBitrate;
10040 if( (M4OSA_UInt32)pC->uiMaxFileSize
10108 * M4OSA_ERR M4MCS_intCleanUp_ReadersDecoders(M4MCS_InternalContext* pC);
10114 static M4OSA_ERR M4MCS_intCleanUp_ReadersDecoders( M4MCS_InternalContext *pC )
10118 M4OSA_TRACE2_1("M4MCS_intCleanUp_ReadersDecoders called with pC=0x%x", pC);
10123 if( M4OSA_NULL != pC->pViDecCtxt )
10125 err = pC->m_pVideoDecoder->m_pFctDestroy(pC->pViDecCtxt);
10126 pC->pViDecCtxt = M4OSA_NULL;
10139 if( M4OSA_NULL != pC->pAudioDecCtxt )
10141 err = pC->m_pAudioDecoder->m_pFctDestroyAudioDec(pC->pAudioDecCtxt);
10142 pC->pAudioDecCtxt = M4OSA_NULL;
10153 if( M4OSA_NULL != pC->AudioDecBufferOut.m_dataAddress )
10155 free(pC->AudioDecBufferOut.m_dataAddress);
10156 pC->AudioDecBufferOut.m_dataAddress = M4OSA_NULL;
10163 if( M4OSA_NULL != pC->
10166 err = pC->m_pReader->m_pFctClose(pC->pReaderContext);
10175 err = pC->m_pReader->m_pFctDestroy(pC->pReaderContext);
10176 pC->pReaderContext = M4OSA_NULL;
10186 if( pC->m_pDataAddress1 != M4OSA_NULL )
10188 free(pC->m_pDataAddress1);
10189 pC->m_pDataAddress1 = M4OSA_NULL;
10192 if( pC->m_pDataAddress2 != M4OSA_NULL )
10194 free(pC->m_pDataAddress2);
10195 pC->m_pDataAddress2 = M4OSA_NULL;
10198 if( pC->m_pDataVideoAddress1 != M4OSA_NULL )
10200 free(pC->m_pDataVideoAddress1);
10201 pC->m_pDataVideoAddress1 = M4OSA_NULL;
10204 if( pC->m_pDataVideoAddress2 != M4OSA_NULL )
10206 free(pC->m_pDataVideoAddress2);
10207 pC->m_pDataVideoAddress2 = M4OSA_NULL;
10245 M4MCS_InternalContext *pC = (M4MCS_InternalContext*)(pContext);
10273 if (M4MCS_kState_CREATED != pC->State)
10276 pC->State);
10281 pC->pInputFile = pFileIn;
10282 pC->InputFileType = InputFileType;
10283 pC->pOutputFile = pFileOut;
10284 pC->pTemporaryFile = pTempFile;
10290 err = M4MCS_setCurrentReader(pContext, pC->InputFileType);
10295 pC->VideoState = M4MCS_kStreamState_NOSTREAM;
10296 pC->AudioState = M4MCS_kStreamState_NOSTREAM;
10297 pC->pReaderVideoStream = M4OSA_NULL;
10298 pC->pReaderAudioStream = M4OSA_NULL;
10303 err = pC->m_pReader->m_pFctCreate(&pC->pReaderContext);
10312 pC->m_pReaderDataIt->m_readerContext = pC->pReaderContext;
10316 err = pC->m_pReader->m_pFctSetOption(pC->pReaderContext,
10318 (M4OSA_DataOption)pC->pOsaFileReadPtr);
10327 err = pC->m_pReader->m_pFctOpen(pC->pReaderContext, pC->pInputFile);
10353 err = pC->m_pReader->m_pFctGetNextStream(pC->pReaderContext, &mediaFamily,
10370 && (M4OSA_NULL == pC->pReaderVideoStream))
10378 &&(pC->m_pVideoDecoderItTable[M4DECODER_kVideoTypeAVC] != M4OSA_NULL)))
10386 pC->pReaderVideoStream = (M4_VideoStreamHandler*)pStreamHandler;
10387 pC->bUnsupportedVideoFound = M4OSA_FALSE;
10392 pC->VideoState = M4MCS_kStreamState_STARTED;
10396 err = pC->m_pReader->m_pFctReset(pC->pReaderContext,
10397 (M4_StreamHandler*)pC->pReaderVideoStream);
10407 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext, pStreamHandler,
10408 &pC->ReaderVideoAU);
10422 pC->bUnsupportedVideoFound = M4OSA_TRUE;
10429 && (M4OSA_NULL == pC->pReaderAudioStream))
10441 pC->pReaderAudioStream = (M4_AudioStreamHandler*)pStreamHandler;
10443 pC->bUnsupportedAudioFound = M4OSA_FALSE;
10447 pC->AudioState = M4MCS_kStreamState_STARTED;
10451 err = pC->m_pReader->m_pFctReset(pC->pReaderContext,
10452 (M4_StreamHandler*)pC->pReaderAudioStream);
10462 err = pC->m_pReader->m_pFctFillAuStruct(pC->pReaderContext, pStreamHandler,
10463 &pC->ReaderAudioAU);
10474 pC->uiAudioMaxAuSize = pStreamHandler->m_maxAUSize;
10483 pC->bUnsupportedAudioFound = M4OSA_TRUE;
10492 if((M4OSA_NULL == pC->pReaderVideoStream) && (M4OSA_NULL == pC->pReaderAudioStream))
10500 if(pC->VideoState == M4MCS_kStreamState_STARTED)
10503 pC->pReaderVideoStream->m_basicProperties.m_streamType);
10508 if(pC->AudioState == M4MCS_kStreamState_STARTED)
10515 pC->pReaderAudioStream->m_basicProperties.m_streamType);
10522 err = M4MCS_intGetInputClipProperties(pC);
10532 if (0. != pC->InputFileProperties.fAverageFrameRate) /**< sanity check */
10534 pC->iVideoBeginDecIncr = (M4OSA_Int32)(3000. \
10535 / pC->InputFileProperties.fAverageFrameRate); /**< about 3 frames */
10539 pC->iVideoBeginDecIncr = 200; /**< default value: 200 milliseconds (3 frames @ 15fps)*/
10544 pC->State = M4MCS_kState_OPENED;
10553 M4MCS_InternalContext *pC) {
10564 pC->pReaderAudioStream->m_basicProperties.m_streamType) {
10566 err = pC->m_pAudioDecoder->m_pFctCreateAudioDec(
10567 &pC->pAudioDecCtxt,
10568 pC->pReaderAudioStream, &(pC->AacProperties));
10570 err = pC->m_pAudioDecoder->m_pFctCreateAudioDec(
10571 &pC->pAudioDecCtxt,
10572 pC->pReaderAudioStream,
10573 pC->m_pCurrentAudioDecoderUserData);
10583 pC->m_pAudioDecoder->m_pFctSetOptionAudioDec(pC->pAudioDecCtxt,
10584 M4AD_kOptionID_3gpReaderInterface, (M4OSA_DataOption) pC->m_pReaderDataIt);
10586 pC->m_pAudioDecoder->m_pFctSetOptionAudioDec(pC->pAudioDecCtxt,
10587 M4AD_kOptionID_AudioAU, (M4OSA_DataOption) &pC->ReaderAudioAU);
10589 if( pC->m_pAudioDecoder->m_pFctStartAudioDec != M4OSA_NULL ) {
10591 err = pC->m_pAudioDecoder->m_pFctStartAudioDec(pC->pAudioDecCtxt);
10604 pC->pReaderAudioStream->m_byteFrameLength
10605 * pC->pReaderAudioStream->m_byteSampleSize
10606 * pC->pReaderAudioStream->m_nbChannels;
10623 err = pC->m_pAudioDecoder->m_pFctStepAudioDec(pC->pAudioDecCtxt,
10629 pC->m_pAudioDecoder->m_pFctGetOptionAudioDec(pC->pAudioDecCtxt,
10633 pC->pReaderAudioStream->m_nbChannels = optionValue;
10635 pC->m_pAudioDecoder->m_pFctGetOptionAudioDec(pC->pAudioDecCtxt,
10639 pC->pReaderAudioStream->m_samplingFrequency = optionValue;
10642 pC->pReaderAudioStream->m_basicProperties.m_streamType) {
10644 pC->AacProperties.aNumChan =
10645 pC->pReaderAudioStream->m_nbChannels;
10646 pC->AacProperties.aSampFreq =
10647 pC->pReaderAudioStream->m_samplingFrequency;
10659 err = pC->m_pReader->m_pFctReset(pC->pReaderContext,
10660 (M4_StreamHandler *)pC->pReaderAudioStream);