Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 6 files). Show all
Unified · Split
| @@ -510,8 +510,10 @@ int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn · 509 unmodified lines | ||
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | const int32_t kiEncoderReturn = EncodeFrameInternal(kpSrcPic, pBsInfo); |
| 513 | + | |
| 513 | 514 | if(kiEncoderReturn != cmResultSuccess) |
| 514 | 515 | return kiEncoderReturn; |
| 516 | + | |
| 515 | 517 | #ifdef REC_FRAME_COUNT |
| 516 | 518 | ++ m_uiCountFrameNum; |
| 517 | 519 | WelsLog (m_pEncContext, WELS_LOG_INFO, |
| @@ -521,7 +523,7 @@ int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn · 3 unmodified lines | ||
| 521 | 523 | #ifdef DUMP_SRC_PICTURE |
| 522 | 524 | DumpSrcPicture (pSrc); |
| 523 | 525 | #endif // DUMP_SRC_PICTURE |
| 524 | − return cmResultSuccess; | |
| 526 | + return kiEncoderReturn; | |
| 525 | 527 | } |
| 526 | 528 | |
| 527 | 529 | |
| @@ -540,7 +542,6 @@ int CWelsH264SVCEncoder::EncodeFrameInternal(const SSourcePicture* pSrcPic, SFr · 12 unmodified lines | ||
| 540 | 542 | WelsLog (m_pEncContext, WELS_LOG_ERROR, "unexpected return(%d) from EncodeFrameInternal()!\n", kiEncoderReturn); |
| 541 | 543 | return cmUnkonwReason; |
| 542 | 544 | } |
| 543 | − | |
| 544 | 545 | ///////////////////for test |
| 545 | 546 | #ifdef OUTPUT_BIT_STREAM |
| 546 | 547 | if (pBsInfo->eOutputFrameType != videoFrameTypeInvalid && pBsInfo->eOutputFrameType != videoFrameTypeSkip) { |
| @@ -826,18 +827,80 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 279 unmodified lines | ||
| 826 | 827 | } |
| 827 | 828 | break; |
| 828 | 829 | case ENCODER_OPTION_BITRATE: { // Target bit-rate |
| 829 | − int32_t iValue = * ((int32_t*)pOption); | |
| 830 | + SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption)); | |
| 831 | + int32_t iBitrate = pInfo->iBitrate; | |
| 830 | 832 | #ifdef REC_FRAME_COUNT |
| 831 | 833 | WelsLog (m_pEncContext, WELS_LOG_INFO, |
| 832 | 834 | "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n", |
| 833 | 835 | m_uiCountFrameNum, m_iCspInternal, iValue); |
| 834 | 836 | #endif//REC_FRAME_COUNT |
| 835 | − if (iValue<=0) { | |
| 836 | − return cmInitParaError; | |
| 837 | + if (iBitrate<=0) { | |
| 838 | + WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iBitrate = %d\n",iBitrate); | |
| 839 | + return cmInitParaError; | |
| 837 | 840 | } |
| 841 | + iBitrate = WELS_CLIP3 (iBitrate, MIN_BIT_RATE, MAX_BIT_RATE); | |
| 842 | + switch(pInfo->iLayer){ | |
| 843 | + case SPATIAL_LAYER_ALL: | |
| 844 | + m_pEncContext->pSvcParam->iTargetBitrate = iBitrate; | |
| 845 | + break; | |
| 846 | + case SPATIAL_LAYER_0: | |
| 847 | + m_pEncContext->pSvcParam->sSpatialLayers[0].iSpatialBitrate = iBitrate; | |
| 848 | + break; | |
| 849 | + case SPATIAL_LAYER_1: | |
| 850 | + m_pEncContext->pSvcParam->sSpatialLayers[1].iSpatialBitrate = iBitrate; | |
| 851 | + break; | |
| 852 | + case SPATIAL_LAYER_2: | |
| 853 | + m_pEncContext->pSvcParam->sSpatialLayers[2].iSpatialBitrate = iBitrate; | |
| 854 | + break; | |
| 855 | + case SPATIAL_LAYER_3: | |
| 856 | + m_pEncContext->pSvcParam->sSpatialLayers[3].iSpatialBitrate = iBitrate; | |
| 857 | + break; | |
| 858 | + default: | |
| 859 | + WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d\n",pInfo->iLayer); | |
| 860 | + return cmInitParaError; | |
| 861 | + break; | |
| 862 | + } | |
| 838 | 863 | //adjust to valid range |
| 839 | − m_pEncContext->pSvcParam->iTargetBitrate = WELS_CLIP3 (iValue, MIN_BIT_RATE, MAX_BIT_RATE); | |
| 840 | − WelsEncoderApplyBitRate (m_pEncContext->pSvcParam); | |
| 864 | + WelsEncoderApplyBitRate (m_pEncContext->pSvcParam,pInfo->iLayer); | |
| 865 | + } | |
| 866 | + break; | |
| 867 | + case ENCODER_OPTION_MAX_BITRATE: { // Target bit-rate | |
| 868 | + SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption)); | |
| 869 | + int32_t iBitrate = pInfo->iBitrate; | |
| 870 | + | |
| 871 | +#ifdef REC_FRAME_COUNT | |
| 872 | + WelsLog (m_pEncContext, WELS_LOG_INFO, | |
| 873 | + "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x, iValue= %d\n", | |
| 874 | + m_uiCountFrameNum, m_iCspInternal, iValue); | |
| 875 | +#endif//REC_FRAME_COUNT | |
| 876 | + if (iBitrate<=0) { | |
| 877 | + WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_MAX_BITRATE,iBitrate = %d\n",iBitrate); | |
| 878 | + return cmInitParaError; | |
| 879 | + } | |
| 880 | + iBitrate = WELS_CLIP3 (iBitrate, MIN_BIT_RATE, MAX_BIT_RATE); | |
| 881 | + switch(pInfo->iLayer){ | |
| 882 | + case SPATIAL_LAYER_ALL: | |
| 883 | + m_pEncContext->pSvcParam->iMaxBitrate = iBitrate; | |
| 884 | + break; | |
| 885 | + case SPATIAL_LAYER_0: | |
| 886 | + m_pEncContext->pSvcParam->sSpatialLayers[0].iMaxSpatialBitrate = iBitrate; | |
| 887 | + break; | |
| 888 | + case SPATIAL_LAYER_1: | |
| 889 | + m_pEncContext->pSvcParam->sSpatialLayers[1].iMaxSpatialBitrate = iBitrate; | |
| 890 | + break; | |
| 891 | + case SPATIAL_LAYER_2: | |
| 892 | + m_pEncContext->pSvcParam->sSpatialLayers[2].iMaxSpatialBitrate = iBitrate; | |
| 893 | + break; | |
| 894 | + case SPATIAL_LAYER_3: | |
| 895 | + m_pEncContext->pSvcParam->sSpatialLayers[3].iMaxSpatialBitrate = iBitrate; | |
| 896 | + break; | |
| 897 | + default: | |
| 898 | + WelsLog (m_pEncContext, WELS_LOG_ERROR,"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_MAX_BITRATE,iLayer = %d\n",pInfo->iLayer); | |
| 899 | + return cmInitParaError; | |
| 900 | + break; | |
| 901 | + } | |
| 902 | + //adjust to valid range | |
| 903 | + WelsEncoderApplyBitRate (m_pEncContext->pSvcParam,pInfo->iLayer); | |
| 841 | 904 | } |
| 842 | 905 | break; |
| 843 | 906 | case ENCODER_OPTION_RC_MODE: { // 0:quality mode;1:bit-rate mode |
| @@ -990,7 +1053,29 @@ int CWelsH264SVCEncoder::GetOption (ENCODER_OPTION eOptionId, void* pOption) { · 146 unmodified lines | ||
| 990 | 1053 | "CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", |
| 991 | 1054 | m_uiCountFrameNum, m_iCspInternal); |
| 992 | 1055 | #endif//REC_FRAME_COUNT |
| 993 | − * ((int32_t*)pOption) = m_pEncContext->pSvcParam->iTargetBitrate; | |
| 1056 | + SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption)); | |
| 1057 | + if((pInfo->iLayer!=SPATIAL_LAYER_ALL)||(pInfo->iLayer!=SPATIAL_LAYER_0)||(pInfo->iLayer!=SPATIAL_LAYER_1)||(pInfo->iLayer!=SPATIAL_LAYER_2)||(pInfo->iLayer!=SPATIAL_LAYER_3)) | |
| 1058 | + return cmInitParaError; | |
| 1059 | + if(pInfo->iLayer == SPATIAL_LAYER_ALL){ | |
| 1060 | + pInfo->iBitrate = m_pEncContext->pSvcParam->iTargetBitrate; | |
| 1061 | + }else{ | |
| 1062 | + pInfo->iBitrate = m_pEncContext->pSvcParam->sSpatialLayers[pInfo->iLayer].iSpatialBitrate; | |
| 1063 | + } | |
| 1064 | + } | |
| 1065 | + break; | |
| 1066 | + case ENCODER_OPTION_MAX_BITRATE: { // Target bit-rate | |
| 1067 | +#ifdef REC_FRAME_COUNT | |
| 1068 | + WelsLog (m_pEncContext, WELS_LOG_INFO,"CWelsH264SVCEncoder::GetOption():ENCODER_OPTION_MAX_BITRATE, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", | |
| 1069 | + m_uiCountFrameNum, m_iCspInternal); | |
| 1070 | +#endif//REC_FRAME_COUNT | |
| 1071 | + SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption)); | |
| 1072 | + if((pInfo->iLayer!=SPATIAL_LAYER_ALL)||(pInfo->iLayer!=SPATIAL_LAYER_0)||(pInfo->iLayer!=SPATIAL_LAYER_1)||(pInfo->iLayer!=SPATIAL_LAYER_2)||(pInfo->iLayer!=SPATIAL_LAYER_3)) | |
| 1073 | + return cmInitParaError; | |
| 1074 | + if(pInfo->iLayer == SPATIAL_LAYER_ALL){ | |
| 1075 | + pInfo->iBitrate = m_pEncContext->pSvcParam->iMaxBitrate; | |
| 1076 | + }else{ | |
| 1077 | + pInfo->iBitrate = m_pEncContext->pSvcParam->sSpatialLayers[pInfo->iLayer].iMaxSpatialBitrate; | |
| 1078 | + } | |
| 994 | 1079 | } |
| 995 | 1080 | break; |
| 996 | 1081 | default: |