⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umc_vc1_enc_picture_adv.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* /////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2007 Intel Corporation. All Rights Reserved.
//
//
//          VC-1 (VC1) encoder, advance profile picture level functionality
//
*/
#include "umc_defs.h"

#if defined (UMC_ENABLE_VC1_VIDEO_ENCODER)

#include "umc_vc1_enc_picture_adv.h"
#include "umc_vc1_enc_common.h"
#include "umc_vc1_enc_tables.h"
#include "umc_vc1_common_zigzag_tbl.h"
#include "ippvc.h"
#include "ippi.h"
#include "umc_vc1_enc_block.h"
#include "umc_vc1_enc_block_template.h"
#include "umc_vc1_enc_debug.h"
#include "umc_vc1_common_defs.h"
#include "umc_vc1_enc_deblocking.h"
#include "umc_vc1_enc_statistic.h"

namespace UMC_VC1_ENCODER
{

UMC::Status  VC1EncoderPictureADV::CheckParameters(vm_char* pLastError)
{
    if (!m_pSequenceHeader)
    {
        vm_string_printf(pLastError,VM_STRING("Error. pic. header parameter: seq. header is NULL\n"));
        return UMC::UMC_ERR_FAILED;
    }
    if (m_uiPictureType != VC1_ENC_I_FRAME &&
        m_uiPictureType != VC1_ENC_P_FRAME &&
       (!((m_uiPictureType == VC1_ENC_BI_FRAME||m_uiPictureType == VC1_ENC_B_FRAME))))
    {
        vm_string_printf(pLastError,VM_STRING("Error. pic. header parameter: picture type is incorrect\n"));
        return UMC::UMC_ERR_FAILED;
    }


    if (m_uiDecTypeAC1>2)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: DecTypeAC1\n"));
        m_uiDecTypeAC1 = 0;
    }

    if (m_uiDecTypeDCIntra>1)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: DecTypeAC2\n"));
        m_uiDecTypeDCIntra = 0;
    }
    if (!m_uiQuantIndex || m_uiQuantIndex >31)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: m_uiQuantIndex\n"));
        m_uiQuantIndex = 1;
    }
    if (m_bHalfQuant && m_uiQuantIndex>8)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: m_bHalfQuant\n"));
        m_bHalfQuant = false;
    }
    switch (m_pSequenceHeader->GetQuantType())
    {
    case VC1_ENC_QTYPE_IMPL:
        m_bUniformQuant = (m_uiQuantIndex>8)? false:true;
        m_uiQuant       = quantValue[m_uiQuantIndex];
        break;
    case VC1_ENC_QTYPE_UF:
        m_bUniformQuant = true;
        m_uiQuant       = m_uiQuantIndex;
        break;
    case VC1_ENC_QTYPE_NUF:
        m_bUniformQuant = false;
        m_uiQuant       = m_uiQuantIndex;
        break;
    }
    switch(m_uiPictureType)
    {
    case VC1_ENC_I_FRAME:
        return CheckParametersI(pLastError);
    case VC1_ENC_P_FRAME:
        return CheckParametersP(pLastError);
    case VC1_ENC_B_FRAME:
        return CheckParametersB(pLastError);
    }
    return false;
}

UMC::Status     VC1EncoderPictureADV::CheckParametersI(vm_char* pLastError)
{
    if (m_uiDecTypeAC2>2)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: DecTypeAC2\n"));
        m_uiDecTypeAC2 = 0;
    }

    if (m_uiRoundControl>1)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: m_uiRoundControl>1\n"));
        m_uiRoundControl = 0;
    }
    if (m_uiCondOverlap !=  VC1_ENC_COND_OVERLAP_NO   &&
        m_uiCondOverlap !=  VC1_ENC_COND_OVERLAP_SOME &&
        m_uiCondOverlap !=  VC1_ENC_COND_OVERLAP_ALL)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: CondOverlap\n"));
        m_uiCondOverlap = VC1_ENC_COND_OVERLAP_NO;
    }

    return UMC::UMC_OK;
}


UMC::Status    VC1EncoderPictureADV::CheckParametersP(vm_char* pLastError)
{

     if  (!m_pSequenceHeader->IsExtendedMV() && m_uiMVRangeIndex>0 || m_uiMVRangeIndex>3)
     {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: MVRangeIndex\n"));
        m_uiMVRangeIndex = 0;
     }
    if (m_bIntensity)
    {
        if (m_uiIntensityLumaScale>63)
        {
            vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: IntensityLumaScale=63\n"));
            m_uiIntensityLumaScale=63;
        }
        if (m_uiIntensityLumaShift>63)
        {
            vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: IntensityLumaShift=63\n"));
            m_uiIntensityLumaShift=63;
        }
    }
    else
    {
        if (m_uiIntensityLumaScale>0)
        {
            vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: IntensityLumaScale=0\n"));
            m_uiIntensityLumaScale=0;
        }
        if (m_uiIntensityLumaShift>0)
        {
            vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: IntensityLumaShift=0\n"));
            m_uiIntensityLumaShift=0;
        }
    }
    if (m_uiMVTab>4)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: MVTab=4\n"));
        m_uiMVTab=4;
    }
    if (m_uiCBPTab>4)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: CBPTab=4\n"));
        m_uiCBPTab=4;
    }
    if (m_uiAltPQuant>0 && m_pSequenceHeader->GetDQuant()==0)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: AltPQuant=0\n"));
        m_uiAltPQuant=0;
    }
    else if (m_pSequenceHeader->GetDQuant()!=0 && (m_uiAltPQuant==0||m_uiAltPQuant>31))
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: AltPQuant=Quant\n"));
        m_uiAltPQuant = m_uiQuant;
    }
    if ( m_QuantMode != VC1_ENC_QUANT_SINGLE && m_pSequenceHeader->GetDQuant()==0)
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: QuantMode = VC1_ENC_QUANT_SINGLE\n"));
        m_QuantMode = VC1_ENC_QUANT_SINGLE;
    }
    if (m_bVSTransform && !m_pSequenceHeader->IsVSTransform())
    {
       vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: VSTransform = false\n"));
       m_bVSTransform = false;
    }
    if (!m_bVSTransform && m_uiTransformType!= VC1_ENC_8x8_TRANSFORM)
    {
       vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: TransformType == VC1_ENC_8x8_TRANSFORM\n"));
       m_uiTransformType = VC1_ENC_8x8_TRANSFORM;
    }
    return UMC::UMC_OK;
}
UMC::Status    VC1EncoderPictureADV::CheckParametersB(vm_char* pLastError)
{
    if ((m_uiBFraction.denom < 2|| m_uiBFraction.denom >8)&& (m_uiBFraction.denom != 0xff))
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: m_uiBFraction.denom\n"));
        m_uiBFraction.denom = 2;
    }
    if ((m_uiBFraction.num  < 1|| m_uiBFraction.num >= m_uiBFraction.denom)&& (m_uiBFraction.num != 0xff))
    {
        vm_string_printf(pLastError,VM_STRING("Warning. pic. header parameter: m_uiBFraction.num\n"));
        m_uiBFraction.num = 1;
    }
    return UMC::UMC_OK;
}

UMC::Status VC1EncoderPictureADV::Init (VC1EncoderSequenceADV* SequenceHeader, VC1EncoderMBs* pMBs, VC1EncoderCodedMB* pCodedMB)
{
    UMC::Status err = UMC::UMC_OK;

    if (!SequenceHeader || !pMBs || !pCodedMB)
        return UMC::UMC_ERR_NULL_PTR;

    Close();

    m_pSequenceHeader = SequenceHeader;

    m_pMBs = pMBs;
    m_pCodedMB = pCodedMB;

    return UMC::UMC_OK;
}


UMC::Status VC1EncoderPictureADV::Close()
{

   Reset();
   ResetPlanes();
   return UMC::UMC_OK;
}


UMC::Status     VC1EncoderPictureADV::SetPlaneParams  (Frame* pFrame, ePlaneType type)
{
    Ipp8u** pPlane;
    Ipp32u* pPlaneStep;
    switch(type)
    {
    case  VC1_ENC_CURR_PLANE:
        pPlane     = m_pPlane;
        pPlaneStep = m_uiPlaneStep;
        break;
    case  VC1_ENC_RAISED_PLANE:
        pPlane     = m_pRaisedPlane;
        pPlaneStep = m_uiRaisedPlaneStep;
        break;
    case  VC1_ENC_FORWARD_PLANE:
        pPlane     = m_pForwardPlane;
        pPlaneStep = m_uiForwardPlaneStep;
        break;
     case  VC1_ENC_BACKWARD_PLANE:
        pPlane     = m_pBackwardPlane;
        pPlaneStep = m_uiBackwardPlaneStep;
        break;
     default:
         return UMC::UMC_ERR_FAILED;
   }
   pPlane[0]       = pFrame->GetYPlane();
   pPlane[1]       = pFrame->GetUPlane();
   pPlane[2]       = pFrame->GetVPlane();
   pPlaneStep[0]   = pFrame->GetYStep();
   pPlaneStep[1]   = pFrame->GetUStep();
   pPlaneStep[2]   = pFrame->GetVStep();

   return UMC::UMC_OK;
}



UMC::Status VC1EncoderPictureADV::SetPictureParams(ePType Type, Ipp8u frameCount, Ipp8u QuantIndex, bool HalfQuant, Ipp16s* pSavedMV)
{

    m_uiPictureType     =  Type;
    //m_uiFrameCount      =  frameCount;
    m_uiQuantIndex      =  QuantIndex;                  // [1, 31]
    m_bHalfQuant        =  HalfQuant ;                  // can be true if  m_uiQuantIndex<8

    m_pSavedMV  = pSavedMV;
    //if (m_pSequenceHeader->IsFrameInterpolation())
    //    m_bFrameInterpolation   =  false;              // true or false
    //else
    //    m_bFrameInterpolation   =  false;


     if (m_uiQuantIndex > 31)
         return UMC::UMC_ERR_FAILED;

    switch (m_pSequenceHeader->GetQuantType())
    {
    case VC1_ENC_QTYPE_IMPL:
        m_bUniformQuant = (m_uiQuantIndex>8)? false:true;
        m_uiQuant       = quantValue[m_uiQuantIndex];
        break;
    case VC1_ENC_QTYPE_EXPL:
        m_bUniformQuant = true;                         // can be true or false
        m_uiQuant       = m_uiQuantIndex;
        break;
    case VC1_ENC_QTYPE_UF:
        m_bUniformQuant = true;
        m_uiQuant       = m_uiQuantIndex;
        break;
    case VC1_ENC_QTYPE_NUF:
        m_bUniformQuant = false;
        m_uiQuant       = m_uiQuantIndex;
        break;
    default:
        return UMC::UMC_ERR_FAILED;
    }


    m_uiDecTypeAC1      = 0;                            //[0,2] - it's used to choose decoding table
    m_uiDecTypeDCIntra  = 0;                            //[0,1] - it's used to choose decoding table

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -