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

📄 umc_dv50_enc_segment_reader.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
字号:
/*
//              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) 2006-2007 Intel Corporation. All Rights Reserved.
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_DV50_VIDEO_ENCODER)

#include "umc_dv50_enc_segment_reader.h"
#include "umc_dv_enc_block.h"
#include "umc_dv_enc_segment_compressor.h"

namespace UMC
{

DV50_SegmentReader::DV50_SegmentReader(Ipp16s nNumOfDIFSeq) :
    SegmentReader(nNumOfDIFSeq)
{
}

DV50_SegmentReader::~DV50_SegmentReader(void)
{
}

static
inline
void ReadYLine(Ipp16s *lpBlockYData, Ipp16s LineNum, Ipp8u *lpcYSrc)
{
    Ipp16s iX;
    for(iX=0; iX<8; iX++)
        lpBlockYData[iX + LineNum*8] = ((Ipp16s) lpcYSrc[iX]) - 128;
}

static
inline
void ReadUVLine(Ipp16s *lpBlockUVData, Ipp16s LineNum, Ipp8u *lpcUVSrc)
{
    Ipp16s iX;
    for(iX=0; iX<8; iX++)
        lpBlockUVData[iX +  LineNum*8] =((Ipp16s)lpcUVSrc[iX]) - 128;
}

static
void ReadYUV(size_t *YOffsets, size_t *UOffsets, size_t *VOffsets,
             V_SEGMENT *lpVSegment, VideoData *pSrcFrame)
{
    Ipp8u *lpcSrcY, *lpcSrcU, *lpcSrcV;
    Ipp16s LineNum, MBNum;
    BLOCK *Y0, *Y1, *Y2, *Y3, *Cr, *Cb;

    for(MBNum=0; MBNum < 5; MBNum++)
    {
        lpcSrcY = (Ipp8u*)pSrcFrame->GetPlanePointer(0) + YOffsets[MBNum];

        Y0 = lpVSegment->m_pDCTBlocks + MBNum*6;
        Y1 = Y0 + 1;
        Y2 = Y0 + 2;
        Y3 = Y0 + 3;
        Cr = Y0 + 4;
        Cb = Y0 + 5;
        memset(Y1->m_lpsData, 0, sizeof(Ipp16s)*64);
        memset(Y3->m_lpsData, 0, sizeof(Ipp16s)*64);

        for (LineNum = 0;LineNum < 8;LineNum++)
        {
            ReadYLine(Y0->m_lpsData, LineNum, lpcSrcY + 8*0);
            ReadYLine(Y2->m_lpsData, LineNum, lpcSrcY + 8*1);

            lpcSrcY += pSrcFrame->GetPlanePitch(0);
        }

        lpcSrcU = (Ipp8u*)pSrcFrame->GetPlanePointer(1) + UOffsets[MBNum];
        lpcSrcV = (Ipp8u*)pSrcFrame->GetPlanePointer(2) + VOffsets[MBNum];

        for (LineNum = 0;LineNum < 4;LineNum++)
        {

            ReadUVLine(Cr->m_lpsData, 2*LineNum,   lpcSrcV);
            ReadUVLine(Cr->m_lpsData, 2*LineNum+1, lpcSrcV);
            ReadUVLine(Cb->m_lpsData, 2*LineNum,   lpcSrcU);
            ReadUVLine(Cb->m_lpsData, 2*LineNum+1, lpcSrcU);

            lpcSrcU += pSrcFrame->GetPlanePitch(1);
            lpcSrcV += pSrcFrame->GetPlanePitch(2);
        }
    }
}

const size_t DV50MBLummaWidth = 16;
const size_t DV50MBLummaHeight = 8;
const size_t DV50MBChromaWidth420 = 8;
const size_t DV50MBChromaHeight420 = 4;

const size_t DV50SBLummaWidth  = DV50MBLummaWidth * 9;
const size_t DV50SBLummaHeight = DV50MBLummaHeight * 3;

const size_t DV50SBChromaWidth420  = DV50MBChromaWidth420 * 9;
const size_t DV50SBChromaHeight420 = DV50MBChromaHeight420 * 3;

static
void InitOffsets(size_t *YOffsets, size_t *UOffsets, size_t *VOffsets,
                 const size_t lPitches[], Ipp16s NumOfDIFSeq, Ipp16s i, Ipp16s k)
{
    //i - DIF sequence order
    //k - order of the video segment in the DIF sequence
    //i = 0 .. 2*NumOfDIFSeq-1 (NumOfDIFSeq = 10 or 12)
    //k = 0 .. 26

    Ipp32s lMBCol, lMBRow;
    lMBCol = k / 3;

    if (lMBCol & 1)
        lMBRow = 2 - (k%3);
    else
        lMBRow = (k%3);

    Ipp32s SBLineShift[5] = {2, 6, 8, 0, 4};
    Ipp32s SBHorzOrder[5] = {2, 1, 3, 0, 4};
    Ipp32s SBNum;
    for(SBNum=0; SBNum < 5; SBNum++)
    {
        YOffsets[SBNum] = (size_t)
            // destination
            (0 +
            //
            (i / NumOfDIFSeq) * lPitches[0] * DV50SBLummaHeight +
            // offset of needed SB line
            ((i + SBLineShift[SBNum]) % NumOfDIFSeq) * lPitches[0] * DV50SBLummaHeight * 2  +
            // offset of needed SB
            SBHorzOrder[SBNum] * DV50SBLummaWidth +
            // offset of needed MB in SB
            lMBRow * DV50MBLummaHeight * lPitches[0] + lMBCol * DV50MBLummaWidth);

        UOffsets[SBNum] = (size_t) (
            // destination
            0 +
            //
            (i / NumOfDIFSeq) * lPitches[1] * DV50SBChromaHeight420 +
            // offset of needed SB line
            ((i + SBLineShift[SBNum]) % NumOfDIFSeq) * lPitches[1] * DV50SBChromaHeight420 * 2+
            // offset of needed SB
            SBHorzOrder[SBNum] * DV50SBChromaWidth420  +
            // offset of needed MB in SB
            lMBRow * DV50MBChromaHeight420 * lPitches[1] + lMBCol * DV50MBChromaWidth420);

        VOffsets[SBNum] = (size_t) (
            // destination
            0 +
            //
            (i / NumOfDIFSeq) * lPitches[2] * DV50SBChromaHeight420 +
            // offset of needed SB line
            ((i + SBLineShift[SBNum]) % NumOfDIFSeq) * lPitches[2] * DV50SBChromaHeight420 * 2+
            // offset of needed SB
            SBHorzOrder[SBNum] * DV50SBChromaWidth420  +
            // offset of needed MB in SB
            lMBRow * DV50MBChromaHeight420 * lPitches[2] + lMBCol * DV50MBChromaWidth420);
    }

} // void InitOffsets(...)

void DV50_SegmentReader::ReadSegment(V_SEGMENT *lpVSegment, Ipp16s DIFSeqNum, Ipp16s VSegmentNum)
{
    size_t YOffsets[5], UOffsets[5], VOffsets[5];
    size_t Pitches[3];
    Pitches[0] = m_lpSourceFrame->GetPlanePitch(0);
    Pitches[1] = m_lpSourceFrame->GetPlanePitch(1);
    Pitches[2] = m_lpSourceFrame->GetPlanePitch(2);

    InitOffsets(YOffsets, UOffsets, VOffsets, Pitches, m_nNumOfDIFSeq, DIFSeqNum, VSegmentNum);

    ReadYUV(YOffsets, UOffsets, VOffsets, lpVSegment, m_lpSourceFrame);
}

} // namespace UMC

#endif //(UMC_ENABLE_DV50_VIDEO_ENCODER)

⌨️ 快捷键说明

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