History

Allow forcing copying in downscale

Normally, the DownsamplePadding skips scaling if the target size is the same as the source size, assuming that the caller will use the source data pointer in that case. This is true for the base layer (the first call to DownsamplePadding in SingleLayerPreprocess), but when downsampling the other layers, there is no special handling for the case when the target is the same size as the source. Previously, the encoding of such spatial layers will use completely uninitialized data, encoding complete garbage. Instead force DownsamplePadding to make a copy if no scaling is required, for the dependency layers. The base layer still avoids a copy unless scaling of that layer is required. Whether it actually makes sense to have lower spatial layers the same size as the original one is a different question though - currently the code allows it, and EncodeDecodeTestAPI.SetOptionEncParamExt will try to use it.

Martin Storsjö committed 11 years ago

Commit 0a2cd1e1 parent 09518da2 files · +16 −6Browse files

Showing the changes to codec/encoder/core/src/wels_preprocess.cpp (1 of 2 files). Show all

Unified · Split

codec/encoder/core/src/wels_preprocess.cpp+14−5
@@ -45,6 +45,9 @@ namespace WelsEnc { · 44 unmodified lines
4545 int32_t WelsInitScaledPic (SWelsSvcCodingParam* pParam, Scaled_Picture* pScaledPic, CMemoryAlign* pMemoryAlign);
4646 bool JudgeNeedOfScaling (SWelsSvcCodingParam* pParam, Scaled_Picture* pScaledPic);
4747 void FreeScaledPic (Scaled_Picture* pScaledPic, CMemoryAlign* pMemoryAlign);
48+void WelsMoveMemory_c (uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iDstStrideY, int32_t iDstStrideUV,
49+ uint8_t* pSrcY, uint8_t* pSrcU, uint8_t* pSrcV, int32_t iSrcStrideY, int32_t iSrcStrideUV, int32_t iWidth,
50+ int32_t iHeight);
4851
4952 //******* table definition ***********************************************************************//
5053 const uint8_t g_kuiRefTemporalIdx[MAX_TEMPORAL_LEVEL][MAX_GOP_SIZE] = {
@@ -329,7 +332,7 @@ int32_t CWelsPreProcess::SingleLayerPreprocess (sWelsEncCtx* pCtx, const SSource · 278 unmodified lines
329332 iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
330333 iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
331334 }
332− DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
335+ DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight, false);
333336
334337 if (pSvcParam->bEnableSceneChangeDetect && !pCtx->pVaa->bIdrPeriodFlag) {
335338 if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
@@ -384,7 +387,7 @@ int32_t CWelsPreProcess::SingleLayerPreprocess (sWelsEncCtx* pCtx, const SSource · 48 unmodified lines
384387 pDstPic = m_pSpatialPic[iDependencyId][iPicturePos]; // small
385388 iShrinkWidth = pScaledPicture->iScaledWidth[iDependencyId];
386389 iShrinkHeight = pScaledPicture->iScaledHeight[iDependencyId];
387− DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight);
390+ DownsamplePadding (pSrcPic, pDstPic, iSrcWidth, iSrcHeight, iShrinkWidth, iShrinkHeight, iTargetWidth, iTargetHeight, true);
388391
389392 WelsUpdateSpatialIdxMap (pCtx, iActualSpatialLayerNum - 1, pDstPic, iDependencyId);
390393
@@ -534,7 +537,7 @@ bool CWelsPreProcess::DetectSceneChange (SPicture* pCurPicture, SPicture* pRefPi · 143 unmodified lines
534537 }
535538
536539 int32_t CWelsPreProcess::DownsamplePadding (SPicture* pSrc, SPicture* pDstPic, int32_t iSrcWidth, int32_t iSrcHeight,
537− int32_t iShrinkWidth, int32_t iShrinkHeight, int32_t iTargetWidth, int32_t iTargetHeight) {
540+ int32_t iShrinkWidth, int32_t iShrinkHeight, int32_t iTargetWidth, int32_t iTargetHeight, bool bForceCopy) {
538541 int32_t iRet = 0;
539542 SPixMap sSrcPixMap;
540543 SPixMap sDstPicMap;
@@ -551,7 +554,7 @@ int32_t CWelsPreProcess::DownsamplePadding (SPicture* pSrc, SPicture* pDstPic, · 10 unmodified lines
551554 sSrcPixMap.iStride[2] = pSrc->iLineSize[2];
552555 sSrcPixMap.eFormat = VIDEO_FORMAT_I420;
553556
554− if (iSrcWidth != iShrinkWidth || iSrcHeight != iShrinkHeight) {
557+ if (iSrcWidth != iShrinkWidth || iSrcHeight != iShrinkHeight || bForceCopy) {
555558 int32_t iMethodIdx = METHOD_DOWNSAMPLE;
556559 sDstPicMap.pPixel[0] = pDstPic->pData[0];
557560 sDstPicMap.pPixel[1] = pDstPic->pData[1];
@@ -564,7 +567,13 @@ int32_t CWelsPreProcess::DownsamplePadding (SPicture* pSrc, SPicture* pDstPic, · 6 unmodified lines
564567 sDstPicMap.iStride[2] = pDstPic->iLineSize[2];
565568 sDstPicMap.eFormat = VIDEO_FORMAT_I420;
566569
567− iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sDstPicMap);
570+ if (iSrcWidth != iShrinkWidth || iSrcHeight != iShrinkHeight) {
571+ iRet = m_pInterfaceVp->Process (iMethodIdx, &sSrcPixMap, &sDstPicMap);
572+ } else {
573+ WelsMoveMemory_c (pDstPic->pData[0], pDstPic->pData[1], pDstPic->pData[2], pDstPic->iLineSize[0], pDstPic->iLineSize[1],
574+ pSrc->pData[0], pSrc->pData[1], pSrc->pData[2], pSrc->iLineSize[0], pSrc->iLineSize[1],
575+ iSrcWidth, iSrcHeight);
576+ }
568577 } else {
569578 memcpy (&sDstPicMap, &sSrcPixMap, sizeof (sDstPicMap)); // confirmed_safe_unsafe_usage
570579 }

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