| @@ -80,7 +80,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 79 unmodified lines |
| 80 | 80 | assert (pCfg != NULL); |
| 81 | 81 | |
| 82 | 82 | if ((pCfg->iUsageType != CAMERA_VIDEO_REAL_TIME) && (pCfg->iUsageType != SCREEN_CONTENT_REAL_TIME)) { |
| 83 | | − WelsLog (NULL, WELS_LOG_ERROR, "ParamValidation(),Invalid usage type = %d", pCfg->iUsageType); |
| 83 | + WelsLog (NULL, WELS_LOG_ERROR, "ParamValidation(),Invalid usage type = %d\n", pCfg->iUsageType); |
| 84 | 84 | return ENC_RETURN_UNSUPPORTED_PARA; |
| 85 | 85 | } |
| 86 | 86 | for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) { |
| @@ -113,15 +113,16 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 26 unmodified lines |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | //bitrate setting validation |
| 116 | | − if (pCfg->iRCMode != RC_OFF_MODE){ |
| 116 | + if (pCfg->iRCMode != RC_OFF_MODE) { |
| 117 | 117 | int32_t iTotalBitrate = 0; |
| 118 | 118 | for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) { |
| 119 | 119 | SDLayerParam* fDlp = &pCfg->sDependencyLayers[i]; |
| 120 | 120 | iTotalBitrate += fDlp->iSpatialBitrate; |
| 121 | 121 | } |
| 122 | | − if(iTotalBitrate > pCfg->iTargetBitrate){ |
| 123 | | − WelsLog(NULL, WELS_LOG_ERROR,"Invalid setttings in bitrate. the sum of each layer bitrate(%d) is larger than total bitrate setting(%d)\n", |
| 124 | | − iTotalBitrate,pCfg->iTargetBitrate); |
| 122 | + if (iTotalBitrate > pCfg->iTargetBitrate) { |
| 123 | + WelsLog (NULL, WELS_LOG_ERROR, |
| 124 | + "Invalid setttings in bitrate. the sum of each layer bitrate(%d) is larger than total bitrate setting(%d)\n", |
| 125 | + iTotalBitrate, pCfg->iTargetBitrate); |
| 125 | 126 | } |
| 126 | 127 | } |
| 127 | 128 | |
| @@ -1303,6 +1304,8 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1175 unmodified lines |
| 1303 | 1304 | (*ppCtx)->pOut->uiSize = iCountBsLen; |
| 1304 | 1305 | (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList"); |
| 1305 | 1306 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx)) |
| 1307 | + (*ppCtx)->pOut->pNalLen = (int32_t*)pMa->WelsMallocz(iCountNals * sizeof (int32_t), "pOut->pNalLen"); |
| 1308 | + WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pNalLen), FreeMemorySvc(ppCtx)) |
| 1306 | 1309 | (*ppCtx)->pOut->iCountNals = iCountNals; |
| 1307 | 1310 | (*ppCtx)->pOut->iNalIndex = 0; |
| 1308 | 1311 | |
| @@ -1497,6 +1500,11 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 188 unmodified lines |
| 1497 | 1500 | pMa->WelsFree (pCtx->pOut->sNalList, "pOut->sNalList"); |
| 1498 | 1501 | pCtx->pOut->sNalList = NULL; |
| 1499 | 1502 | } |
| 1503 | + // NALs len |
| 1504 | + if (NULL != pCtx->pOut->pNalLen) { |
| 1505 | + pMa->WelsFree (pCtx->pOut->pNalLen, "pOut->pNalLen"); |
| 1506 | + pCtx->pOut->pNalLen = NULL; |
| 1507 | + } |
| 1500 | 1508 | pMa->WelsFree (pCtx->pOut, "SWelsEncoderOutput"); |
| 1501 | 1509 | pCtx->pOut = NULL; |
| 1502 | 1510 | } |
| @@ -2443,14 +2451,8 @@ bool SetMeMethod (const uint8_t uiMethod, PSearchMethodFunc& pSearchMethodFunc) · 940 unmodified lines |
| 2443 | 2451 | pSearchMethodFunc = WelsDiamondCrossFeatureSearch; |
| 2444 | 2452 | break; |
| 2445 | 2453 | case ME_FULL: |
| 2446 | | −#ifdef HAVE_MMX |
| 2447 | | − // make sure your cpu can support x86 sse4.1 instruction set if try it |
| 2448 | | − //pSearchMethodFunc = WelsFullSearch; |
| 2449 | | −#else |
| 2450 | 2454 | pSearchMethodFunc = WelsDiamondSearch; |
| 2451 | 2455 | return false; |
| 2452 | | −#endif//HAVE_MMX |
| 2453 | | − break; |
| 2454 | 2456 | default: |
| 2455 | 2457 | pSearchMethodFunc = WelsDiamondSearch; |
| 2456 | 2458 | return false; |
| @@ -2772,7 +2774,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 315 unmodified lines |
| 2772 | 2774 | iPayloadSize = pNalLen[*pNalIdxInLayer]; |
| 2773 | 2775 | |
| 2774 | 2776 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2775 | | − pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; |
| 2776 | 2777 | |
| 2777 | 2778 | (*pNalIdxInLayer) ++; |
| 2778 | 2779 | } else { // No Prefix NAL Unit RBSP syntax here, but need add NAL Unit Header extension |
| @@ -2789,7 +2790,6 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 10 unmodified lines |
| 2789 | 2790 | iPayloadSize = pNalLen[*pNalIdxInLayer]; |
| 2790 | 2791 | |
| 2791 | 2792 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2792 | | − pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; |
| 2793 | 2793 | |
| 2794 | 2794 | (*pNalIdxInLayer) ++; |
| 2795 | 2795 | } |
| @@ -2855,13 +2855,13 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx) { · 59 unmodified lines |
| 2855 | 2855 | int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { |
| 2856 | 2856 | SFrameBSInfo* pFbi = (SFrameBSInfo*)pDst; |
| 2857 | 2857 | SLayerBSInfo* pLayerBsInfo = &pFbi->sLayerInfo[0]; |
| 2858 | | − int32_t iNalLen[128] = {0}; |
| 2859 | 2858 | int32_t iCountNal = 0; |
| 2860 | 2859 | |
| 2861 | 2860 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs; |
| 2861 | + pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; |
| 2862 | 2862 | InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize); |
| 2863 | 2863 | |
| 2864 | | − int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); |
| 2864 | + int32_t iReturn = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal); |
| 2865 | 2865 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 2866 | 2866 | |
| 2867 | 2867 | pLayerBsInfo->uiPriorityId = 0; |
| @@ -2870,9 +2870,6 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 2 unmodified lines |
| 2870 | 2870 | pLayerBsInfo->uiQualityId = 0; |
| 2871 | 2871 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 2872 | 2872 | pLayerBsInfo->iNalCount = iCountNal; |
| 2873 | | − for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) { |
| 2874 | | − pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex]; |
| 2875 | | − } |
| 2876 | 2873 | |
| 2877 | 2874 | pCtx->eLastNalPriority = NRI_PRI_HIGHEST; |
| 2878 | 2875 | pFbi->iLayerNum = 1; |
| @@ -2904,7 +2901,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 25 unmodified lines |
| 2904 | 2901 | int32_t iSpatialNum = 0; // available count number of spatial layers due to frame size changed in this given frame |
| 2905 | 2902 | int32_t iSpatialIdx = 0; // iIndex of spatial layers due to frame size changed in this given frame |
| 2906 | 2903 | int32_t iFrameSize = 0; |
| 2907 | | − int32_t iNalLen[128] = {0}; |
| 2908 | 2904 | int32_t iNalIdxInLayer = 0; |
| 2909 | 2905 | int32_t iCountNal = 0; |
| 2910 | 2906 | EVideoFrameType eFrameType = videoFrameTypeInvalid; |
| @@ -2948,13 +2944,14 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 37 unmodified lines |
| 2948 | 2944 | pCtx->uiTemporalId = iCurTid; |
| 2949 | 2945 | |
| 2950 | 2946 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs ; |
| 2947 | + pLayerBsInfo->pNalLengthInByte = pCtx->pOut->pNalLen; |
| 2951 | 2948 | |
| 2952 | 2949 | if (eFrameType == videoFrameTypeIDR) { |
| 2953 | 2950 | ++ pCtx->sPSOVector.uiIdrPicId; |
| 2954 | 2951 | //if ( pSvcParam->bEnableSSEI ) |
| 2955 | 2952 | |
| 2956 | 2953 | // write parameter sets bitstream here |
| 2957 | | − pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); |
| 2954 | + pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &pLayerBsInfo->pNalLengthInByte[0], &iCountNal); |
| 2958 | 2955 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 2959 | 2956 | |
| 2960 | 2957 | pLayerBsInfo->uiPriorityId = 0; |
| @@ -2963,12 +2960,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines |
| 2963 | 2960 | pLayerBsInfo->uiQualityId = 0; |
| 2964 | 2961 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 2965 | 2962 | pLayerBsInfo->iNalCount = iCountNal; |
| 2966 | | − for (int32_t iNalIndex = 0; iNalIndex < iCountNal; ++ iNalIndex) { |
| 2967 | | − pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex]; |
| 2968 | | − } |
| 2969 | 2963 | |
| 2970 | 2964 | ++ pLayerBsInfo; |
| 2971 | 2965 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 2966 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal; |
| 2972 | 2967 | ++ iLayerNum; |
| 2973 | 2968 | } |
| 2974 | 2969 | |
| @@ -3089,7 +3084,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 114 unmodified lines |
| 3089 | 3084 | int32_t iPayloadSize = 0; |
| 3090 | 3085 | |
| 3091 | 3086 | if (pCtx->bNeedPrefixNalFlag) { |
| 3092 | | − pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, |
| 3087 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc, |
| 3093 | 3088 | iPayloadSize); |
| 3094 | 3089 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3095 | 3090 | iLayerSize += iPayloadSize; |
| @@ -3106,9 +3101,9 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 10 unmodified lines |
| 3106 | 3101 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3107 | 3102 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3108 | 3103 | pCtx->pFrameBs + pCtx->iPosBsBuffer, |
| 3109 | | − &iNalLen[iNalIdxInLayer]); |
| 3104 | + &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); |
| 3110 | 3105 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3111 | | − iSliceSize = iNalLen[iNalIdxInLayer]; |
| 3106 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; |
| 3112 | 3107 | |
| 3113 | 3108 | iLayerSize += iSliceSize; |
| 3114 | 3109 | pCtx->iPosBsBuffer += iSliceSize; |
| @@ -3117,7 +3112,6 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2 unmodified lines |
| 3117 | 3112 | pLayerBsInfo->uiTemporalId = iCurTid; |
| 3118 | 3113 | pLayerBsInfo->uiQualityId = 0; |
| 3119 | 3114 | pLayerBsInfo->uiPriorityId = 0; |
| 3120 | | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; |
| 3121 | 3115 | pLayerBsInfo->iNalCount = ++ iNalIdxInLayer; |
| 3122 | 3116 | } |
| 3123 | 3117 | // for dynamic slicing single threading.. |
| @@ -3260,7 +3254,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 136 unmodified lines |
| 3260 | 3254 | int32_t iSliceSize = 0; |
| 3261 | 3255 | int32_t iPayloadSize = 0; |
| 3262 | 3256 | if (bNeedPrefix) { |
| 3263 | | − pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, |
| 3257 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, eNalType, eNalRefIdc, |
| 3264 | 3258 | iPayloadSize); |
| 3265 | 3259 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3266 | 3260 | iLayerSize += iPayloadSize; |
| @@ -3275,13 +3269,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 8 unmodified lines |
| 3275 | 3269 | pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], |
| 3276 | 3270 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3277 | 3271 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3278 | | − pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]); |
| 3272 | + pCtx->pFrameBs + pCtx->iPosBsBuffer, &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); |
| 3279 | 3273 | WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| 3280 | | − iSliceSize = iNalLen[iNalIdxInLayer]; |
| 3274 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; |
| 3281 | 3275 | |
| 3282 | 3276 | pCtx->iPosBsBuffer += iSliceSize; |
| 3283 | 3277 | iLayerSize += iSliceSize; |
| 3284 | | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; |
| 3285 | 3278 | |
| 3286 | 3279 | #if defined(SLICE_INFO_OUTPUT) |
| 3287 | 3280 | fprintf (stderr, |
| @@ -3413,10 +3406,12 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 125 unmodified lines |
| 3413 | 3406 | } |
| 3414 | 3407 | #endif//STAT_OUTPUT |
| 3415 | 3408 | |
| 3409 | + iCountNal = pLayerBsInfo->iNalCount; |
| 3416 | 3410 | ++ iLayerNum; |
| 3417 | 3411 | ++ pLayerBsInfo; |
| 3418 | 3412 | |
| 3419 | 3413 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3414 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal; |
| 3420 | 3415 | |
| 3421 | 3416 | if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) { |
| 3422 | 3417 | int32_t iPaddingNalSize = 0; |
| @@ -3440,9 +3435,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 17 unmodified lines |
| 3440 | 3435 | pLayerBsInfo->uiQualityId = 0; |
| 3441 | 3436 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 3442 | 3437 | pLayerBsInfo->iNalCount = 1; |
| 3443 | | − pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize; |
| 3438 | + pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize; |
| 3444 | 3439 | ++ pLayerBsInfo; |
| 3445 | 3440 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3441 | + pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1; |
| 3446 | 3442 | ++ iLayerNum; |
| 3447 | 3443 | } |
| 3448 | 3444 | |
| @@ -3696,7 +3692,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 247 unmodified lines |
| 3696 | 3692 | |
| 3697 | 3693 | SDqLayer* pCurLayer = pCtx->pCurDqLayer; |
| 3698 | 3694 | SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx; |
| 3699 | | − int32_t iNalLen[MAX_NAL_UNITS_IN_LAYER] = {0}; |
| 3700 | 3695 | int32_t iNalIdxInLayer = *pNalIdxInLayer; |
| 3701 | 3696 | int32_t iSliceIdx = iStartSliceIdx; |
| 3702 | 3697 | const int32_t kiSliceStep = pCtx->iActiveThreadsNum; |
| @@ -3727,7 +3722,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 24 unmodified lines |
| 3727 | 3722 | } |
| 3728 | 3723 | |
| 3729 | 3724 | if (kbNeedPrefix) { |
| 3730 | | − iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); |
| 3725 | + iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &pLayerBsInfo->pNalLengthInByte[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); |
| 3731 | 3726 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 3732 | 3727 | iPartitionBsSize += iPayloadSize; |
| 3733 | 3728 | } |
| @@ -3741,13 +3736,12 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 7 unmodified lines |
| 3741 | 3736 | &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, |
| 3742 | 3737 | pCtx->iFrameBsSize - pCtx->iPosBsBuffer, |
| 3743 | 3738 | pCtx->pFrameBs + pCtx->iPosBsBuffer, |
| 3744 | | − &iNalLen[iNalIdxInLayer]); |
| 3739 | + &pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]); |
| 3745 | 3740 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 3746 | | − iSliceSize = iNalLen[iNalIdxInLayer]; |
| 3741 | + iSliceSize = pLayerBsInfo->pNalLengthInByte[iNalIdxInLayer]; |
| 3747 | 3742 | |
| 3748 | 3743 | pCtx->iPosBsBuffer += iSliceSize; |
| 3749 | 3744 | iPartitionBsSize += iSliceSize; |
| 3750 | | − pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; |
| 3751 | 3745 | |
| 3752 | 3746 | #if defined(SLICE_INFO_OUTPUT) |
| 3753 | 3747 | fprintf (stderr, |