Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 5 files). Show all
Unified · Split
| @@ -131,17 +131,15 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder() · 130 unmodified lines | ||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | CWelsH264SVCEncoder::~CWelsH264SVCEncoder() { |
| 134 | − WelsLog (NULL, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n"); | |
| 134 | + if (m_pWelsTrace) { | |
| 135 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n"); | |
| 135 | 136 | |
| 136 | − if (m_pWelsTrace != NULL) { | |
| 137 | − delete m_pWelsTrace; | |
| 138 | − m_pWelsTrace = NULL; | |
| 139 | − } | |
| 140 | 137 | #ifdef REC_FRAME_COUNT |
| 141 | − WelsLog (m_pEncContext, WELS_LOG_INFO, | |
| 142 | − "CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, | |
| 143 | − m_iCspInternal); | |
| 138 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 139 | + "CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, | |
| 140 | + m_iCspInternal); | |
| 144 | 141 | #endif |
| 142 | + } | |
| 145 | 143 | |
| 146 | 144 | #ifdef REC_FRAME_COUNT |
| 147 | 145 | m_uiCountFrameNum = 0; |
| @@ -161,20 +159,27 @@ CWelsH264SVCEncoder::~CWelsH264SVCEncoder() { · 13 unmodified lines | ||
| 161 | 159 | #endif//OUTPUT_BIT_STREAM |
| 162 | 160 | |
| 163 | 161 | Uninitialize(); |
| 162 | + | |
| 163 | + if (m_pWelsTrace) { | |
| 164 | + delete m_pWelsTrace; | |
| 165 | + m_pWelsTrace = NULL; | |
| 166 | + } | |
| 164 | 167 | } |
| 165 | 168 | |
| 166 | 169 | void CWelsH264SVCEncoder::InitEncoder (void) { |
| 167 | 170 | |
| 171 | + m_pWelsTrace = new welsCodecTrace(); | |
| 172 | + if (m_pWelsTrace == NULL) { | |
| 173 | + return; | |
| 174 | + } | |
| 175 | + | |
| 176 | + m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR); | |
| 177 | + WelsSetLogCallback (welsCodecTrace::CODEC_TRACE); | |
| 178 | + | |
| 168 | 179 | #ifdef REC_FRAME_COUNT |
| 169 | − WelsLog (m_pEncContext, WELS_LOG_INFO, | |
| 180 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 170 | 181 | "CWelsH264SVCEncoder::InitEncoder, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal); |
| 171 | 182 | #endif |
| 172 | − | |
| 173 | − m_pWelsTrace = new welsCodecTrace(); | |
| 174 | − if (m_pWelsTrace != NULL) { | |
| 175 | − m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR); | |
| 176 | − WelsSetLogCallback (welsCodecTrace::CODEC_TRACE); | |
| 177 | − } | |
| 178 | 183 | } |
| 179 | 184 | |
| 180 | 185 | /* Interfaces override from ISVCEncoder */ |
| @@ -188,9 +193,12 @@ int CWelsH264SVCEncoder::GetDefaultParams (SEncParamExt* argv) { · 7 unmodified lines | ||
| 188 | 193 | * SVC Encoder Initialization |
| 189 | 194 | */ |
| 190 | 195 | int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { |
| 196 | + if (m_pWelsTrace == NULL) { | |
| 197 | + return cmMallocMemeError; | |
| 198 | + } | |
| 191 | 199 | |
| 192 | 200 | if (NULL == argv) { |
| 193 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n", | |
| 201 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n", | |
| 194 | 202 | argv); |
| 195 | 203 | return cmInitParaError; |
| 196 | 204 | } |
| @@ -198,7 +206,8 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { · 1 unmodified line | ||
| 198 | 206 | SWelsSvcCodingParam sConfig; |
| 199 | 207 | // Convert SEncParamBase into WelsSVCParamConfig here.. |
| 200 | 208 | if (sConfig.ParamBaseTranscode (*argv)) { |
| 201 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n"); | |
| 209 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 210 | + "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n"); | |
| 202 | 211 | Uninitialize(); |
| 203 | 212 | return cmInitParaError; |
| 204 | 213 | } |
| @@ -207,9 +216,12 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { · 2 unmodified lines | ||
| 207 | 216 | } |
| 208 | 217 | |
| 209 | 218 | int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { |
| 219 | + if (m_pWelsTrace == NULL) { | |
| 220 | + return cmMallocMemeError; | |
| 221 | + } | |
| 210 | 222 | |
| 211 | 223 | if (NULL == argv) { |
| 212 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), invalid argv= 0x%p\n", | |
| 224 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), invalid argv= 0x%p\n", | |
| 213 | 225 | argv); |
| 214 | 226 | return cmInitParaError; |
| 215 | 227 | } |
| @@ -217,7 +229,8 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { · 1 unmodified line | ||
| 217 | 229 | SWelsSvcCodingParam sConfig; |
| 218 | 230 | // Convert SEncParamExt into WelsSVCParamConfig here.. |
| 219 | 231 | if (sConfig.ParamTranscode (*argv)) { |
| 220 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), parameter_translation failed.\n"); | |
| 232 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 233 | + "CWelsH264SVCEncoder::InitializeExt(), parameter_translation failed.\n"); | |
| 221 | 234 | Uninitialize(); |
| 222 | 235 | return cmInitParaError; |
| 223 | 236 | } |
| @@ -227,22 +240,24 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { · 3 unmodified lines | ||
| 227 | 240 | |
| 228 | 241 | int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { |
| 229 | 242 | if (NULL == pCfg) { |
| 230 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n", | |
| 243 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n", | |
| 231 | 244 | pCfg); |
| 232 | 245 | return cmInitParaError; |
| 233 | 246 | } |
| 234 | 247 | |
| 235 | 248 | if (m_bInitialFlag) { |
| 236 | − WelsLog (m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n", | |
| 249 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 250 | + "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n", | |
| 237 | 251 | m_bInitialFlag); |
| 238 | 252 | Uninitialize(); |
| 239 | 253 | } |
| 240 | 254 | |
| 241 | 255 | #ifdef REC_FRAME_COUNT |
| 242 | 256 | SWelsSvcCodingParam& sEncodingParam = *pCfg; |
| 243 | − WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", | |
| 257 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 258 | + "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", | |
| 244 | 259 | m_uiCountFrameNum, m_iCspInternal); |
| 245 | − WelsLog (m_pEncContext, WELS_LOG_INFO, | |
| 260 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 246 | 261 | "coding_param->iPicWidth= %d;coding_param->iPicHeight= %d;coding_param->iTargetBitrate= %d;coding_param->iRCMode= %d;coding_param->iTemporalLayerNum= %d;coding_param->iSpatialLayerNum= %d;coding_param->fFrameRate= %.6ff;coding_param->iInputCsp= %d;coding_param->uiIntraPeriod= %d;coding_param->bEnableSpsPpsIdAddition = %d;coding_param->bPrefixNalAddingCtrl = %d;coding_param->bEnableDenoise= %d;coding_param->bEnableBackgroundDetection= %d;coding_param->bEnableAdaptiveQuant= %d;coding_param->bEnableFrameSkip= %d;coding_param->bEnableCropPic= %d;coding_param->bEnableLongTermReference= %d;coding_param->iLtrMarkPeriod= %d;\n", |
| 247 | 262 | sEncodingParam.iPicWidth, |
| 248 | 263 | sEncodingParam.iPicHeight, |
| @@ -265,7 +280,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 16 unmodified lines | ||
| 265 | 280 | int32_t i = 0; |
| 266 | 281 | while (i < sEncodingParam.iSpatialLayerNum) { |
| 267 | 282 | SSpatialLayerConfig* spatial_cfg = &sEncodingParam.sSpatialLayers[i]; |
| 268 | − WelsLog (m_pEncContext, WELS_LOG_INFO, | |
| 283 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 269 | 284 | "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.uiSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n", |
| 270 | 285 | i, spatial_cfg->iVideoWidth, |
| 271 | 286 | spatial_cfg->iVideoHeight, |
| @@ -281,7 +296,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 9 unmodified lines | ||
| 281 | 296 | |
| 282 | 297 | const int32_t iColorspace = pCfg->iInputCsp; |
| 283 | 298 | if (videoFormatI420 != iColorspace) { |
| 284 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n", iColorspace); | |
| 299 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n", | |
| 300 | + iColorspace); | |
| 285 | 301 | Uninitialize(); |
| 286 | 302 | return cmInitParaError; |
| 287 | 303 | } |
| @@ -289,7 +305,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line | ||
| 289 | 305 | // Check valid parameters |
| 290 | 306 | const int32_t iNumOfLayers = pCfg->iSpatialLayerNum; |
| 291 | 307 | if (iNumOfLayers < 1 || iNumOfLayers > MAX_DEPENDENCY_LAYER) { |
| 292 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, | |
| 308 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 293 | 309 | "CWelsH264SVCEncoder::Initialize(), invalid iSpatialLayerNum= %d, valid at range of [1, %d].\n", iNumOfLayers, |
| 294 | 310 | MAX_DEPENDENCY_LAYER); |
| 295 | 311 | Uninitialize(); |
| @@ -298,7 +314,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 2 unmodified lines | ||
| 298 | 314 | if (pCfg->iTemporalLayerNum < 1) |
| 299 | 315 | pCfg->iTemporalLayerNum = 1; |
| 300 | 316 | if (pCfg->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) { |
| 301 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, | |
| 317 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 302 | 318 | "CWelsH264SVCEncoder::Initialize(), invalid iTemporalLayerNum= %d, valid at range of [1, %d].\n", |
| 303 | 319 | pCfg->iTemporalLayerNum, MAX_TEMPORAL_LEVEL); |
| 304 | 320 | Uninitialize(); |
| @@ -308,7 +324,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 3 unmodified lines | ||
| 308 | 324 | // assert( cfg.uiGopSize >= 1 && ( cfg.uiIntraPeriod && (cfg.uiIntraPeriod % cfg.uiGopSize) == 0) ); |
| 309 | 325 | |
| 310 | 326 | if (pCfg->uiGopSize < 1 || pCfg->uiGopSize > MAX_GOP_SIZE) { |
| 311 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, | |
| 327 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 312 | 328 | "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d].\n", pCfg->uiGopSize, |
| 313 | 329 | MAX_GOP_SIZE); |
| 314 | 330 | Uninitialize(); |
| @@ -316,7 +332,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line | ||
| 316 | 332 | } |
| 317 | 333 | |
| 318 | 334 | if (!WELS_POWER2_IF (pCfg->uiGopSize)) { |
| 319 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, | |
| 335 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 320 | 336 | "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d] and yield to power of 2.\n", |
| 321 | 337 | pCfg->uiGopSize, MAX_GOP_SIZE); |
| 322 | 338 | Uninitialize(); |
| @@ -324,7 +340,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line | ||
| 324 | 340 | } |
| 325 | 341 | |
| 326 | 342 | if (pCfg->uiIntraPeriod && pCfg->uiIntraPeriod < pCfg->uiGopSize) { |
| 327 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, | |
| 343 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 328 | 344 | "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d.\n", |
| 329 | 345 | pCfg->uiIntraPeriod, pCfg->uiGopSize); |
| 330 | 346 | Uninitialize(); |
| @@ -332,7 +348,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line | ||
| 332 | 348 | } |
| 333 | 349 | |
| 334 | 350 | if ((pCfg->uiIntraPeriod && (pCfg->uiIntraPeriod & (pCfg->uiGopSize - 1)) != 0)) { |
| 335 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, | |
| 351 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, | |
| 336 | 352 | "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d also multiple of it.\n", |
| 337 | 353 | pCfg->uiIntraPeriod, pCfg->uiGopSize); |
| 338 | 354 | Uninitialize(); |
| @@ -371,8 +387,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 32 unmodified lines | ||
| 371 | 387 | m_iMaxPicWidth = pCfg->iPicWidth; |
| 372 | 388 | m_iMaxPicHeight = pCfg->iPicHeight; |
| 373 | 389 | |
| 374 | − if (WelsInitEncoderExt (&m_pEncContext, pCfg)) { | |
| 375 | − WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n"); | |
| 390 | + if (WelsInitEncoderExt (&m_pEncContext, pCfg, &m_pWelsTrace->m_sLogCtx)) { | |
| 391 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n"); | |
| 376 | 392 | Uninitialize(); |
| 377 | 393 | return cmInitParaError; |
| 378 | 394 | } |
| @@ -391,10 +407,10 @@ int32_t CWelsH264SVCEncoder::Uninitialize() { · 12 unmodified lines | ||
| 391 | 407 | return 0; |
| 392 | 408 | } |
| 393 | 409 | |
| 394 | − WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n"); | |
| 410 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n"); | |
| 395 | 411 | |
| 396 | 412 | #ifdef REC_FRAME_COUNT |
| 397 | − WelsLog (m_pEncContext, WELS_LOG_INFO, | |
| 413 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 398 | 414 | "CWelsH264SVCEncoder::Uninitialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal); |
| 399 | 415 | #endif//REC_FRAME_COUNT |
| 400 | 416 | |
| @@ -734,7 +750,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 333 unmodified lines | ||
| 734 | 750 | break; |
| 735 | 751 | } |
| 736 | 752 | //adjust to valid range |
| 737 | − WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer); | |
| 753 | + WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer); | |
| 738 | 754 | } |
| 739 | 755 | break; |
| 740 | 756 | case ENCODER_OPTION_MAX_BITRATE: { // Target bit-rate |
| @@ -775,7 +791,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 34 unmodified lines | ||
| 775 | 791 | break; |
| 776 | 792 | } |
| 777 | 793 | //adjust to valid range |
| 778 | − WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer); | |
| 794 | + WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer); | |
| 779 | 795 | } |
| 780 | 796 | break; |
| 781 | 797 | case ENCODER_OPTION_RC_MODE: { // 0:quality mode;1:bit-rate mode;2:bitrate limited mode |