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

📄 umc_vc1_enc_sm.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    Ipp32s              RecodedFrameNum = 0;

    ePType              inputPictureType;

    //only for debug
    static int z_z = 0;



    //-------------- try to save input data-------------------------------------------------------------------
    if (pVideoData )
    {
        Frame*      in_frame           =  0;
        switch (pVideoData->GetFrameType())
        {
        case UMC::I_PICTURE:
            inputPictureType = VC1_ENC_I_FRAME;
            break;
        case UMC::P_PICTURE:
            inputPictureType = VC1_ENC_P_FRAME;
            break;
        case UMC::B_PICTURE:
            inputPictureType = VC1_ENC_B_FRAME;
            break;
        default:
            inputPictureType = m_pGOP->GetPictureType(m_iFrameCount,m_uiGOPLength,m_uiBFrmLength);
            break;
        };
         m_iFrameCount++;

        in_frame = m_pStoredFrames->GetFreeFramePointer();
        if (in_frame)
        {
            in_frame->CopyPlane( (Ipp8u*)pVideoData->GetPlanePointer(0), (Ipp32u)pVideoData->GetPlanePitch(0),
                                 (Ipp8u*)pVideoData->GetPlanePointer(1), (Ipp32u)pVideoData->GetPlanePitch(1),
                                 (Ipp8u*)pVideoData->GetPlanePointer(2), (Ipp32u)pVideoData->GetPlanePitch(2),
                                 inputPictureType);

            if (!m_pWaitingList->AddFrame(in_frame))
                return UMC::UMC_ERR_NOT_ENOUGH_BUFFER;
            pVideoData->SetDataSize(0);
            stored = true;
        }
    }
    while ((frame = m_pWaitingList->GetCurrFrame())!=0)
    {
        if (!m_pGOP->AddFrame(frame))
            break;
            m_pWaitingList->MoveOnNextFrame();
    }
    //---------------------------------------------------------------------------------------------------------

    if (!pVideoData)
    {
        m_pGOP->CloseGop();
    }
    frame = m_pGOP->GetFrameForDecoding();

    if (frame)
    {
        while(frame_recoding && (RecodedFrameNum < VC1_ENC_RECODING_MAX_NUM))
        {
        Frame* pFrameRef = 0;
        m_CodedFrame->Init(out);
        if (!m_bSequenceHeader)
        {
            m_SH->SetMaxBFrames(m_uiBFrmLength);

            err = m_SH->WriteSeqHeader(m_CodedFrame);
            if (err != UMC::UMC_OK)
                return err;

            m_bSequenceHeader = true;
            seqHeaderLen = m_CodedFrame->GetDataLen();
        }
        err = m_pCurrPicture->Init(m_SH,m_pMBs,m_pCodedMB);
        if (err != UMC::UMC_OK)
            return err;

        //----------motion estimation------------
        m_pCurrPicture->SetMEParams(m_pME, m_MESearchSpeed);

        err = m_pCurrPicture->SetPlaneParams (  frame, VC1_ENC_CURR_PLANE);
        if (err != UMC::UMC_OK)
            return err;

        if (frame->GetPictureType()!= VC1_ENC_B_FRAME && m_uiGOPLength>1)
        {

            err = m_pCurrPicture->SetPlaneParams  ( frame, VC1_ENC_RAISED_PLANE);
            if (err != UMC::UMC_OK)
                return err;
        }
        if (frame->GetPictureType() != VC1_ENC_I_FRAME)
        {
            pFrameRef = m_pGOP->GetReferenceFrame();
            if (!pFrameRef)
                return UMC::UMC_ERR_FAILED;

            err = m_pCurrPicture->SetPlaneParams  (pFrameRef,   VC1_ENC_FORWARD_PLANE);
            if (err != UMC::UMC_OK)
                return err;
        }
        if (frame->GetPictureType() == VC1_ENC_B_FRAME)
        {
            pFrameRef = m_pGOP->GetReferenceFrame(true);
            if (!pFrameRef)
                return UMC::UMC_ERR_FAILED;

            err = m_pCurrPicture->SetPlaneParams  (    pFrameRef, VC1_ENC_BACKWARD_PLANE);
            if (err != UMC::UMC_OK)
                return err;
        }

         m_BitRateControl->GetQuant(frame->GetPictureType(), &m_uiPictuteQuantIndex, &m_bHalfQuant);

#ifdef VC1_BRC_DEBUG
    printf("PicType = %d\n", frame->GetPictureType());
#endif

        err = m_pCurrPicture->SetPictureParams(frame->GetPictureType(),m_iFrameCount%3,m_uiPictuteQuantIndex,m_bHalfQuant, m_pSavedMV);
        if (err != UMC::UMC_OK)
            return err;

#ifdef VC1_ENC_STAT
        m_pCurrPicture->SetStatistic(m_pEncStat);
#endif

        m_uiRoundControl= GetRoundControl (frame->GetPictureType(),m_uiRoundControl);
        m_pCurrPicture->SetRoundControl(m_uiRoundControl);

        err = m_pCurrPicture->CheckParameters(m_cLastError);
        if (err != UMC::UMC_OK)
            return err;

        err = m_pCurrPicture->WritePictureHeader(m_CodedFrame);
        if (err != UMC::UMC_OK)
        return err;

        err = m_pCurrPicture->WriteFrame(m_CodedFrame);
        if (err != UMC::UMC_OK)
        return err;
        err = m_pCurrPicture->CompletePicture(m_CodedFrame,time,seqHeaderLen);
        if (err != UMC::UMC_OK)
            return err;

#ifdef VC1_ENC_DEBUG_ON
    //debug
    pDebug->SetPicType(frame->GetPictureType());
    pDebug->SetFrameSize(m_CodedFrame->GetDataLen() - seqHeaderLen - 8);
    pDebug->WriteFrameInfo();
#endif

        err = m_BitRateControl->CheckFrameCompression(frame->GetPictureType(), m_CodedFrame->GetDataLen());
        if(err == UMC::UMC_OK)
            frame_recoding = false;
        else
            if((err == UMC::UMC_ERR_NOT_ENOUGH_BUFFER) && (m_uiPictuteQuantIndex == 31))
            frame_recoding = false;
        else
            if((err == UMC::UMC_ERR_NOT_ENOUGH_DATA) && (m_uiPictuteQuantIndex == 2))
                frame_recoding = false;
        frame_recoding = frame_recoding & m_bFrameRecoding;

        RecodedFrameNum++;

        err = m_CodedFrame->DataComplete(out);
        if (err != UMC::UMC_OK)
            return err;

        if (frame->GetPictureType() != VC1_ENC_B_FRAME && m_uiGOPLength>1)
        {
            err = frame->PadFrameProgressive();
            if (err != UMC::UMC_OK)
                return err;
        }
        }

        err = m_BitRateControl->CompleteFrame(frame->GetPictureType());
        //TODO: BRC error handling
        err = UMC::UMC_OK;

        m_pGOP->ReleaseCurrentFrame();
    }
    else if (!pVideoData)
    {
        return UMC::UMC_ERR_END_OF_STREAM;
    }

    //-------------- try to save input data-------------------------------------------------------------------
    if (pVideoData && !stored)
    {
        Frame*      in_frame           =  0;
        in_frame = m_pStoredFrames->GetFreeFramePointer();
        if (!in_frame)
            return UMC::UMC_ERR_NOT_ENOUGH_BUFFER;

        in_frame->CopyPlane( (Ipp8u*)pVideoData->GetPlanePointer(0), (Ipp32u)pVideoData->GetPlanePitch(0),
                             (Ipp8u*)pVideoData->GetPlanePointer(1), (Ipp32u)pVideoData->GetPlanePitch(1),
                             (Ipp8u*)pVideoData->GetPlanePointer(2), (Ipp32u)pVideoData->GetPlanePitch(2),
                             inputPictureType);

        if (!m_pWaitingList->AddFrame(in_frame))
            return UMC::UMC_ERR_NOT_ENOUGH_BUFFER;
         pVideoData->SetDataSize(0);
    }
    while ((frame = m_pWaitingList->GetCurrFrame())!=0)
    {
        if (!m_pGOP->AddFrame(frame))
            break;
            m_pWaitingList->MoveOnNextFrame();
    }
    //---------------------------------------------------------------------------------------------------------

    return err;
}

void VC1EncoderSM::SetMemoryAllocator(UMC::MemoryAllocator *pMemoryAllocator, bool bOwnAllocator)
{
   m_pMemoryAllocator = pMemoryAllocator;
   m_bOwnAllocator    = bOwnAllocator;
}

UMC::Status VC1EncoderSM::Reset()
{
    UMC::Status umcSts = UMC::UMC_OK;
    m_pWaitingList->Reset();
    m_pGOP->Reset();
    m_pStoredFrames->Reset();
    m_BitRateControl->Reset();

    m_iFrameCount = 0;

    return umcSts;
}

UMC::Status VC1EncoderSM::GetInfo(UMC::VC1EncoderParams* pInfo)
{
   UMC::Status umcSts = UMC::UMC_OK;
   VC1BRInfo BRInfo;
   VC1_hrd_OutData HRDParam;

   if(!m_BitRateControl)
       return UMC::UMC_ERR_NOT_INITIALIZED;

   umcSts = m_BitRateControl->GetCurrentHRDParams(0,&HRDParam);
   if(umcSts != UMC::UMC_OK)
       return umcSts;

   umcSts = m_BitRateControl->GetBRInfo(&BRInfo);
   if(umcSts != UMC::UMC_OK)
       return umcSts;

   pInfo->qualityMeasure = -1;

   pInfo->info.bitrate      = BRInfo.bitrate;
   pInfo->info.framerate    = BRInfo.framerate;
   pInfo->m_iConstQuant     = BRInfo.constQuant;
   pInfo->m_uiHRDBufferSize = HRDParam.hrd_buffer;

   pInfo->m_uiGOPLength     = m_uiGOPLength;
   pInfo->m_uiBFrmLength    = m_uiBFrmLength;
   pInfo->m_uiMESearchSpeed = m_MESearchSpeed;
   pInfo->m_bFrameRecoding  = m_bFrameRecoding;

   pInfo->m_uiNumFrames     = m_iFrameCount;
   pInfo->numEncodedFrames  = m_iFrameCount;

   pInfo->level = m_SH->GetLevel();
   pInfo->info.stream_type    = UMC::VC1_VIDEO;
   pInfo->info.stream_subtype = UMC::VC1_VIDEO_VC1;
   pInfo->info.interlace_type = UMC::PROGRESSIVE;
   pInfo->info.color_format = UMC::YUV420;
   pInfo->info.streamPID = 0;
   pInfo->info.duration  = 0;
   pInfo->numThreads     = 0;

   pInfo->info.clip_info.height = m_SH->GetPictureHeight();
   pInfo->info.clip_info.width  = m_SH->GetPictureWidth();
   pInfo->m_bDeblocking = m_SH->IsLoopFilter();
   pInfo->m_bVSTransform = m_SH->IsVSTransform();
   pInfo->profile = VC1_ENC_PROFILE_A;

   pInfo->info.aspect_ratio_width = 1;
   pInfo->info.aspect_ratio_height = 1;

   pInfo->m_SuggestedOutputSize = 0;
   pInfo->m_SuggestedInputSize  =  0;

   pInfo->m_pData = NULL;

   return umcSts;
}

}

#endif //defined (UMC_ENABLE_VC1_VIDEO_ENCODER)

⌨️ 快捷键说明

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