History

Set and use a proper log context in the encoder

Martin Storsjö committed 12 years ago

Commit 9583ac41 parent 8bac9315 files · +97 −73Browse files

Showing the changes to codec/encoder/plus/src/welsEncoderExt.cpp (1 of 5 files). Show all

Unified · Split

codec/encoder/plus/src/welsEncoderExt.cpp+53−37
@@ -131,17 +131,15 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder() · 130 unmodified lines
131131 }
132132
133133 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");
135136
136− if (m_pWelsTrace != NULL) {
137− delete m_pWelsTrace;
138− m_pWelsTrace = NULL;
139− }
140137 #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);
144141 #endif
142+ }
145143
146144 #ifdef REC_FRAME_COUNT
147145 m_uiCountFrameNum = 0;
@@ -161,20 +159,27 @@ CWelsH264SVCEncoder::~CWelsH264SVCEncoder() { · 13 unmodified lines
161159 #endif//OUTPUT_BIT_STREAM
162160
163161 Uninitialize();
162+
163+ if (m_pWelsTrace) {
164+ delete m_pWelsTrace;
165+ m_pWelsTrace = NULL;
166+ }
164167 }
165168
166169 void CWelsH264SVCEncoder::InitEncoder (void) {
167170
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+
168179 #ifdef REC_FRAME_COUNT
169− WelsLog (m_pEncContext, WELS_LOG_INFO,
180+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
170181 "CWelsH264SVCEncoder::InitEncoder, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
171182 #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− }
178183 }
179184
180185 /* Interfaces override from ISVCEncoder */
@@ -188,9 +193,12 @@ int CWelsH264SVCEncoder::GetDefaultParams (SEncParamExt* argv) { · 7 unmodified lines
188193 * SVC Encoder Initialization
189194 */
190195 int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) {
196+ if (m_pWelsTrace == NULL) {
197+ return cmMallocMemeError;
198+ }
191199
192200 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",
194202 argv);
195203 return cmInitParaError;
196204 }
@@ -198,7 +206,8 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { · 1 unmodified line
198206 SWelsSvcCodingParam sConfig;
199207 // Convert SEncParamBase into WelsSVCParamConfig here..
200208 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");
202211 Uninitialize();
203212 return cmInitParaError;
204213 }
@@ -207,9 +216,12 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { · 2 unmodified lines
207216 }
208217
209218 int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
219+ if (m_pWelsTrace == NULL) {
220+ return cmMallocMemeError;
221+ }
210222
211223 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",
213225 argv);
214226 return cmInitParaError;
215227 }
@@ -217,7 +229,8 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { · 1 unmodified line
217229 SWelsSvcCodingParam sConfig;
218230 // Convert SEncParamExt into WelsSVCParamConfig here..
219231 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");
221234 Uninitialize();
222235 return cmInitParaError;
223236 }
@@ -227,22 +240,24 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { · 3 unmodified lines
227240
228241 int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
229242 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",
231244 pCfg);
232245 return cmInitParaError;
233246 }
234247
235248 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",
237251 m_bInitialFlag);
238252 Uninitialize();
239253 }
240254
241255 #ifdef REC_FRAME_COUNT
242256 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",
244259 m_uiCountFrameNum, m_iCspInternal);
245− WelsLog (m_pEncContext, WELS_LOG_INFO,
260+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
246261 "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",
247262 sEncodingParam.iPicWidth,
248263 sEncodingParam.iPicHeight,
@@ -265,7 +280,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 16 unmodified lines
265280 int32_t i = 0;
266281 while (i < sEncodingParam.iSpatialLayerNum) {
267282 SSpatialLayerConfig* spatial_cfg = &sEncodingParam.sSpatialLayers[i];
268− WelsLog (m_pEncContext, WELS_LOG_INFO,
283+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
269284 "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.uiSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",
270285 i, spatial_cfg->iVideoWidth,
271286 spatial_cfg->iVideoHeight,
@@ -281,7 +296,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 9 unmodified lines
281296
282297 const int32_t iColorspace = pCfg->iInputCsp;
283298 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);
285301 Uninitialize();
286302 return cmInitParaError;
287303 }
@@ -289,7 +305,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
289305 // Check valid parameters
290306 const int32_t iNumOfLayers = pCfg->iSpatialLayerNum;
291307 if (iNumOfLayers < 1 || iNumOfLayers > MAX_DEPENDENCY_LAYER) {
292− WelsLog (m_pEncContext, WELS_LOG_ERROR,
308+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
293309 "CWelsH264SVCEncoder::Initialize(), invalid iSpatialLayerNum= %d, valid at range of [1, %d].\n", iNumOfLayers,
294310 MAX_DEPENDENCY_LAYER);
295311 Uninitialize();
@@ -298,7 +314,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 2 unmodified lines
298314 if (pCfg->iTemporalLayerNum < 1)
299315 pCfg->iTemporalLayerNum = 1;
300316 if (pCfg->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) {
301− WelsLog (m_pEncContext, WELS_LOG_ERROR,
317+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
302318 "CWelsH264SVCEncoder::Initialize(), invalid iTemporalLayerNum= %d, valid at range of [1, %d].\n",
303319 pCfg->iTemporalLayerNum, MAX_TEMPORAL_LEVEL);
304320 Uninitialize();
@@ -308,7 +324,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 3 unmodified lines
308324 // assert( cfg.uiGopSize >= 1 && ( cfg.uiIntraPeriod && (cfg.uiIntraPeriod % cfg.uiGopSize) == 0) );
309325
310326 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,
312328 "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d].\n", pCfg->uiGopSize,
313329 MAX_GOP_SIZE);
314330 Uninitialize();
@@ -316,7 +332,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
316332 }
317333
318334 if (!WELS_POWER2_IF (pCfg->uiGopSize)) {
319− WelsLog (m_pEncContext, WELS_LOG_ERROR,
335+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
320336 "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d] and yield to power of 2.\n",
321337 pCfg->uiGopSize, MAX_GOP_SIZE);
322338 Uninitialize();
@@ -324,7 +340,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
324340 }
325341
326342 if (pCfg->uiIntraPeriod && pCfg->uiIntraPeriod < pCfg->uiGopSize) {
327− WelsLog (m_pEncContext, WELS_LOG_ERROR,
343+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
328344 "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d.\n",
329345 pCfg->uiIntraPeriod, pCfg->uiGopSize);
330346 Uninitialize();
@@ -332,7 +348,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
332348 }
333349
334350 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,
336352 "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",
337353 pCfg->uiIntraPeriod, pCfg->uiGopSize);
338354 Uninitialize();
@@ -371,8 +387,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 32 unmodified lines
371387 m_iMaxPicWidth = pCfg->iPicWidth;
372388 m_iMaxPicHeight = pCfg->iPicHeight;
373389
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");
376392 Uninitialize();
377393 return cmInitParaError;
378394 }
@@ -391,10 +407,10 @@ int32_t CWelsH264SVCEncoder::Uninitialize() { · 12 unmodified lines
391407 return 0;
392408 }
393409
394− WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
410+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
395411
396412 #ifdef REC_FRAME_COUNT
397− WelsLog (m_pEncContext, WELS_LOG_INFO,
413+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
398414 "CWelsH264SVCEncoder::Uninitialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
399415 #endif//REC_FRAME_COUNT
400416
@@ -734,7 +750,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 333 unmodified lines
734750 break;
735751 }
736752 //adjust to valid range
737− WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
753+ WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer);
738754 }
739755 break;
740756 case ENCODER_OPTION_MAX_BITRATE: { // Target bit-rate
@@ -775,7 +791,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 34 unmodified lines
775791 break;
776792 }
777793 //adjust to valid range
778− WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
794+ WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer);
779795 }
780796 break;
781797 case ENCODER_OPTION_RC_MODE: { // 0:quality mode;1:bit-rate mode;2:bitrate limited mode

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t