Ejemplo n.º 1
0
EResult CBackgroundDetection::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
  EResult eReturn = RET_INVALIDPARAM;

  if (pSrcPixMap == NULL || pRefPixMap == NULL)
    return eReturn;

  m_BgdParam.pCur[0] = (uint8_t*)pSrcPixMap->pPixel[0];
  m_BgdParam.pCur[1] = (uint8_t*)pSrcPixMap->pPixel[1];
  m_BgdParam.pCur[2] = (uint8_t*)pSrcPixMap->pPixel[2];
  m_BgdParam.pRef[0] = (uint8_t*)pRefPixMap->pPixel[0];
  m_BgdParam.pRef[1] = (uint8_t*)pRefPixMap->pPixel[1];
  m_BgdParam.pRef[2] = (uint8_t*)pRefPixMap->pPixel[2];
  m_BgdParam.iBgdWidth = pSrcPixMap->sRect.iRectWidth;
  m_BgdParam.iBgdHeight = pSrcPixMap->sRect.iRectHeight;
  m_BgdParam.iStride[0] = pSrcPixMap->iStride[0];
  m_BgdParam.iStride[1] = pSrcPixMap->iStride[1];
  m_BgdParam.iStride[2] = pSrcPixMap->iStride[2];

  int32_t iCurFrameSize = m_BgdParam.iBgdWidth * m_BgdParam.iBgdHeight;
  if (m_BgdParam.pOU_array == NULL || iCurFrameSize > m_iLargestFrameSize) {
    WelsFree (m_BgdParam.pOU_array);
    m_BgdParam.pOU_array = AllocateOUArrayMemory (m_BgdParam.iBgdWidth, m_BgdParam.iBgdHeight);
    m_iLargestFrameSize = iCurFrameSize;
  }

  if (m_BgdParam.pOU_array == NULL)
    return eReturn;

  BackgroundDetection (&m_BgdParam);

  return RET_SUCCESS;
}
Ejemplo n.º 2
0
int32_t CWelsPreProcess::WelsPreprocessStep3 (void* pCtx, const int32_t kiDidx) {
  sWelsEncCtx* pEncCtx = (sWelsEncCtx*)pCtx;
  SWelsSvcCodingParam* pSvcParam = pEncCtx->pSvcParam;
  bool_t bNeededMbAq = (pSvcParam->bEnableAdaptiveQuant && (pEncCtx->eSliceType == P_SLICE));
  bool_t bCalculateBGD = (pEncCtx->eSliceType == P_SLICE && pSvcParam->bEnableBackgroundDetection);

  int32_t iCurTemporalIdx  = pEncCtx->uiSpatialLayersInTemporal[kiDidx] - 1;

  int32_t iRefTemporalIdx = (int32_t)g_kuiRefTemporalIdx[pSvcParam->iDecompStages][pEncCtx->iCodingIndex &
                            (pSvcParam->uiGopSize - 1)];
  if (pEncCtx->uiTemporalId == 0 && pEncCtx->pLtr[pEncCtx->uiDependencyId].bReceivedT0LostFlag)
    iRefTemporalIdx = pEncCtx->uiSpatialLayersInTemporal[kiDidx] + pEncCtx->pVaa->uiValidLongTermPicIdx;

  SPicture* pCurPic = pEncCtx->pSpatialPic[kiDidx][iCurTemporalIdx];
  SPicture* pRefPic = pEncCtx->pSpatialPic[kiDidx][iRefTemporalIdx];
  {
    SPicture* pLastPic = m_pLastSpatialPicture[kiDidx][0];
    bool_t bCalculateSQDiff = ((pLastPic->pData[0] == pRefPic->pData[0]) && bNeededMbAq);
    bool_t bCalculateVar = (pSvcParam->iRCMode == RC_MODE1 && pEncCtx->eSliceType == I_SLICE);

    VaaCalculation (pEncCtx->pVaa, pCurPic, pRefPic, bCalculateSQDiff, bCalculateVar, bCalculateBGD);
  }

  if (pSvcParam->bEnableBackgroundDetection) {
    BackgroundDetection (pEncCtx->pVaa, pCurPic, pRefPic, bCalculateBGD && pRefPic->iPictureType != I_SLICE);
  }

  if (bNeededMbAq) {
    SPicture* pCurPic = m_pLastSpatialPicture[kiDidx][1];
    SPicture* pRefPic = m_pLastSpatialPicture[kiDidx][0];

    AdaptiveQuantCalculation (pEncCtx->pVaa, pCurPic, pRefPic);
  }

  if (pSvcParam->bEnableRc) {
    AnalyzePictureComplexity (pEncCtx, pCurPic, pRefPic, kiDidx, bCalculateBGD);
  }

  WelsExchangeSpatialPictures (&m_pLastSpatialPicture[kiDidx][1], &m_pLastSpatialPicture[kiDidx][0]);

  return 0;
}