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

📄 umc_avs_dec_pic.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
//
//              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.
//
//
*/

#include "umc_defs.h"
#if defined(UMC_ENABLE_AVS_VIDEO_DECODER)

#include "umc_avs_dec_pic.h"
#include "umc_avs_dec_mb_info.h"
#include "umc_avs_dec_bit_stream.h"

namespace UMC
{

enum
{
    PLANE_ALIGN_VALUE           = 128
};

AVSPicture::AVSPicture(void)
{
    memset(m_pPlanes8u, 0, sizeof(m_pPlanes8u));
    m_iPitch = 0;
    m_colorFormat = NONE;

    memset(&m_sizeLuma, 0, sizeof(m_sizeLuma));
    memset(&m_sizeChroma, 0, sizeof(m_sizeChroma));

    m_picStructure = AVS_FRAME;

} // AVSPicture::AVSPicture(void)

AVSPicture::~AVSPicture(void)
{
    Close();

} // AVSPicture::~AVSPicture(void)

void AVSPicture::Close(void)
{
    memset(m_pPlanes8u, 0, sizeof(m_pPlanes8u));
    m_iPitch = 0;
    m_colorFormat = NONE;

    memset(&m_sizeLuma, 0, sizeof(m_sizeLuma));
    memset(&m_sizeChroma, 0, sizeof(m_sizeChroma));

    m_picStructure = AVS_FRAME;

} // void AVSPicture::Close(void)

Status AVSPicture::Init(void)
{
    // release object before initialization
    Close();

    return UMC_OK;

} // Status AVSPicture::Init(void)

void AVSPicture::ResetPicture(AVS_SEQUENCE_HEADER *pSeqHeader,
                              void **pPlanes,
                              Ipp32s iPitch,
                              eAVSPicStructure picStructure)
{
    m_picStructure = picStructure;

    // initialize dimensions
    m_sizeLuma.width = pSeqHeader->horizontal_size;
    m_sizeLuma.height = pSeqHeader->vertical_size;
    m_sizeChroma = m_sizeLuma;
    switch (pSeqHeader->chroma_format)
    {
    case AVS_CHROMA_420_FORMAT:
        m_sizeChroma.height /= 2;
        m_sizeChroma.width /= 2;
        m_colorFormat = YUV420;
        break;

    case AVS_CHROMA_422_FORMAT:
        m_sizeChroma.width /= 2;
        m_colorFormat = YUV422;
        break;

    default:
        break;
    }
    if ((AVS_LOWER_FIELD == picStructure) ||
        (AVS_UPPER_FIELD == picStructure))
    {
        m_sizeLuma.height /= 2;
        m_sizeChroma.height /= 2;
    }

    // set planes' pointers
    memcpy(m_pPlanes8u, pPlanes, sizeof(void *) * 3);
    m_iPitch = iPitch;

    if ((AVS_LOWER_FIELD == picStructure) ||
        (AVS_UPPER_FIELD == picStructure))
    {
        if (AVS_LOWER_FIELD == picStructure)
        {
            // precission of samples is 8 bits
            if (1 == pSeqHeader->sample_precission)
            {
                m_pPlanes8u[0] += iPitch;
                m_pPlanes8u[1] += iPitch;
                m_pPlanes8u[2] += iPitch;
            }

        }

        m_iPitch *= 2;
    }

} // void AVSPicture::ResetPicture(AVS_SEQUENCE_HEADER *pSeqHeader,

void AVSPicture::AssignVideoPlanes(AVSSlice *pSlice)
{
    Ipp8u *(pPlanes8u[3]);

    memcpy(pPlanes8u, m_pPlanes8u, sizeof(m_pPlanes8u));

    pPlanes8u[0] += pSlice->m_recCtx.MbY * 16 * m_iPitch;
    switch (m_colorFormat)
    {
    case YUV420:
        pPlanes8u[1] += pSlice->m_recCtx.MbY * 8 * m_iPitch;
        pPlanes8u[2] += pSlice->m_recCtx.MbY * 8 * m_iPitch;
        break;

    default:
        pPlanes8u[1] += pSlice->m_recCtx.MbY * 16 * m_iPitch;
        pPlanes8u[2] += pSlice->m_recCtx.MbY * 16 * m_iPitch;
        break;
    }

    memcpy(pSlice->m_recCtx.m_pPlanes8u, pPlanes8u, sizeof(pPlanes8u));
    pSlice->m_recCtx.m_iPitch = m_iPitch;
    memcpy(pSlice->m_debCtx.m_pPlanes8u, pPlanes8u, sizeof(pPlanes8u));
    pSlice->m_debCtx.m_iPitch = m_iPitch;

} // void AVSPicture::AssignVideoPlanes(AVSSlice *pSlice)

void AVSPicture::MarkSliceAsDone(AVSSlice *pSlice)
{
    AVSListElement<AVSSlice> *pPrev, *pCur;

    // run through the list and find the slice
    pPrev = NULL;
    pCur = m_Slices.GetHead();
    while (pCur)
    {
        if (pCur == pSlice)
            break;

        pPrev = pCur;
        pCur = pCur->GetNext();
    }
    if (NULL == pCur)
        return;

    // there is the first slice, simply move
    if (NULL == pPrev)
    {
        m_SlicesSpent.AddToHead(*m_Slices.ExtractHead());
    }
    // the slice somewhere in the middle,
    // we need to repair the list
    else
    {
        pPrev->SetNext(pCur->GetNext());
        pCur->SetNext(NULL);
        m_SlicesSpent.AddToHead(*pCur);
    }

} // void AVSPicture::MarkSliceAsDone(AVSSlice *pSlice)


AVSFrame::AVSFrame(void)
{
    m_pMbInfo = NULL;
    m_pvVideoPlane = NULL;

    m_iShown = 0;

    memset(&m_dimLumaAllocated, 0, sizeof(IppiSize));
    memset(&m_dimChromaAllocated, 0, sizeof(IppiSize));
    memset(&m_dimMBAllocated, 0, sizeof(IppiSize));

} // AVSFrame::AVSFrame(void)

AVSFrame::~AVSFrame(void)
{
    Close();

} // AVSFrame::~AVSFrame(void)

void AVSFrame::Close(void)
{
    if (m_pMbInfo)
    {
        ippsFree(m_pMbInfo);
    }

    if (m_pvVideoPlane)
    {
        ippsFree(m_pvVideoPlane);
    }

    m_pMbInfo = NULL;
    m_pvVideoPlane = NULL;

    m_iShown = 0;

    memset(&m_dimLumaAllocated, 0, sizeof(IppiSize));
    memset(&m_dimChromaAllocated, 0, sizeof(IppiSize));
    memset(&m_dimMBAllocated, 0, sizeof(IppiSize));

} // void AVSFrame::Close(void)

Status AVSFrame::Init(void)
{
    IppiSize dimReq, dimReqChroma, dimMBReq;
    Ipp8u *(pPlanes8u[3]);
    AVSListElement<AVSSlice> *pSlice, *pPrev;
    AVSListElement<AVSMemory> *pMemory;
    bool isFramePic;
    Ipp32s secondFieldMB;

    //
    // allocate macroblock info plane
    //
    dimMBReq.width = (m_seqHeader.horizontal_size + 15) / 16;
    if (m_picHeader.picture_structure)
    {
        dimMBReq.height = (m_seqHeader.vertical_size + 15) / 16;
        isFramePic = true;
        secondFieldMB = 0;
    }
    else
    {
        dimMBReq.height = 2 * ((m_seqHeader.vertical_size + 31) / 32);
        isFramePic = false;
        secondFieldMB = dimMBReq.height / 2;
    }
    if (dimMBReq.width * dimMBReq.height >
        m_dimMBAllocated.width * m_dimMBAllocated.height)
    {
        // deallocate if it exists
        if (m_pMbInfo)
        {
            ippsFree(m_pMbInfo);
            m_pMbInfo = NULL;
            m_dimMBAllocated.width = 0;
            m_dimMBAllocated.height = 0;
        }

        m_pMbInfo = (AVS_MB_INFO *) ippsMalloc_8u(sizeof(AVS_MB_INFO) *
                                                  dimMBReq.width *
                                                  dimMBReq.height);
        if (NULL == m_pMbInfo)
            return UMC_ERR_ALLOC;

        // set pointers to MbInfo to fields
        m_Fields[0].m_pMbInfo = m_pMbInfo;
        m_Fields[1].m_pMbInfo = m_pMbInfo + (dimMBReq.width * dimMBReq.height / 2);

        m_dimMBAllocated = dimMBReq;
    }

    //
    // allocated video planes
    //
    dimReq.width = align_value<Ipp32s> (m_seqHeader.horizontal_size, PLANE_ALIGN_VALUE);
    if (m_picHeader.picture_structure)
        dimReq.height = align_value<Ipp32s> (m_seqHeader.vertical_size, 16);
    else
        dimReq.height = align_value<Ipp32s> (m_seqHeader.vertical_size, 32);
    switch (m_seqHeader.chroma_format)
    {
    case AVS_CHROMA_420_FORMAT:
        dimReqChroma.width = dimReq.width / 2;
        dimReqChroma.height = dimReq.height / 2;
        break;

    case AVS_CHROMA_422_FORMAT:
        dimReqChroma.width = dimReq.width / 2;
        dimReqChroma.height = dimReq.height;
        break;

    default:
        return UMC_ERR_INVALID_STREAM;
    }
    if (dimReq.width * dimReq.height +
        dimReqChroma.width * dimReqChroma.height >
        m_dimLumaAllocated.width * m_dimLumaAllocated.height +
        m_dimChromaAllocated.width * m_dimChromaAllocated.height)
    {
        Ipp32s iReqSize;

        // deallocate if it exists
        if (m_pvVideoPlane)
        {
            ippsFree(m_pvVideoPlane);
            m_dimLumaAllocated.width = 0;
            m_dimLumaAllocated.height = 0;
            m_dimChromaAllocated.width = 0;
            m_dimChromaAllocated.height = 0;
        }

        iReqSize = dimReq.width * dimReq.height +
                   (dimReqChroma.width * dimReqChroma.height * 2);
        m_pvVideoPlane = ippsMalloc_8u(iReqSize);
        if (NULL == m_pvVideoPlane)
            return UMC_ERR_ALLOC;
        m_dimLumaAllocated = dimReq;
        m_dimChromaAllocated = dimReqChroma;
    }
#if defined(_DEBUG)
    memset(m_pvVideoPlane, 128, dimReq.width * dimReq.height + (dimReqChroma.width * dimReqChroma.height * 2));
#endif // defined(_DEBUG)
    pPlanes8u[0] = (Ipp8u *) m_pvVideoPlane;
    pPlanes8u[1] = pPlanes8u[0] + dimReq.width * dimReq.height;
    pPlanes8u[2] = pPlanes8u[1] + dimReq.width / 2;
    //

⌨️ 快捷键说明

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