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

📄 umc_h264_frame.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) 2003-2007 Intel Corporation. All Rights Reserved.
//
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_H264_VIDEO_DECODER)

#include <ippi.h>
#include "umc_h264_frame.h"
#include "umc_h264_task_supplier.h"

#include "umc_h264_log.h"

namespace UMC
{

H264DecoderFrame::H264DecoderFrame(MemoryAllocator *pMemoryAllocator)
    : H264DecYUVWorkSpace(pMemoryAllocator)
    , m_pPreviousFrame(0)
    , m_pFutureFrame(0)
    , m_wasOutputted(false)
    , m_isDisplayable(false)
    , m_dFrameTime(-1.0)
    , post_procces_complete(false)
    , m_index(-1)
    , m_UID(-1)
    , m_pSlicesInfo(0)
    , m_pSlicesInfoBottom(0)
    , m_TopSliceCount(0)
    , m_ErrorType(0)
{
    m_isShortTermRef[0] = m_isShortTermRef[1] = false;
    m_isLongTermRef[0] = m_isLongTermRef[1] = false;
    m_FrameNumWrap = m_FrameNum  = -1;
    m_LongTermFrameIdx = -1;
    m_RefPicListResetCount[0] = m_RefPicListResetCount[1] = 0;
    m_PicNum[0] = m_PicNum[1] = -1;
    m_LongTermPicNum[0] = m_PicNum[1] = -1;
    m_PicOrderCnt[0] = m_PicOrderCnt[1] = 0;
    m_bIDRFlag[0] = m_bIDRFlag[1] = false;

    // set memory managment tools
    m_pMemoryAllocator = pMemoryAllocator;
    m_midParsedFrameDataNew = 0;
    m_pParsedFrameDataNew = 0;
    m_paddedParsedFrameDataSize.width = 0;
    m_paddedParsedFrameDataSize.height = 0;

    SetBusyState(0);

    m_pSlicesInfo = new H264DecoderFrameInfo(this);
    m_pSlicesInfoBottom = new H264DecoderFrameInfo(this);
}

void H264DecoderFrame::Reset()
{
    m_TopSliceCount = 0;

    if (m_pSlicesInfo)
    {
        m_pSlicesInfo->Reset();
        m_pSlicesInfoBottom->Reset();
    }

    SetBusyState(0);
    m_isShortTermRef[0] = m_isShortTermRef[1] = false;
    m_isLongTermRef[0] = m_isLongTermRef[1] = false;

    post_procces_complete = false;
    m_bIDRFlag[0] = m_bIDRFlag[1] = false;

    m_RefPicListResetCount[0] = m_RefPicListResetCount[1] = 0;
    m_PicNum[0] = m_PicNum[1] = -1;
    m_LongTermPicNum[0] = m_LongTermPicNum[1] = -1;
    m_PicOrderCnt[0] = m_PicOrderCnt[1] = 0;

    m_bottom_field_flag[0] = m_bottom_field_flag[1] = -1;

    m_dFrameTime = -1;
    m_IsFrameExist = false;
    m_iNumberOfSlices = 0;

    m_NotifiersChain.Reset();
    m_UserData.Reset();

    m_ErrorType = 0;
    m_UID = -1;
}

void H264DecoderFrame::FreeResources()
{
    if (m_pSlicesInfo && (GetBusyState() < 2))
    {
        m_pSlicesInfo->Reset();
        m_pSlicesInfoBottom->Reset();
    }
}

void H264DecoderFrame::OnDecodingCompleted()
{
#ifdef ENABLE_LOGGING
    if (g_H264_Logging)
    {
        g_H264_Logging->LogFrame(this);
    }
#endif

    GetNotifiersChain()->Notify();
    SetisDisplayable();
}

void H264DecoderFrame::DecrementBusyState()
{
    m_BusyState--;
    VM_ASSERT(m_BusyState >= 0);
}

void H264DecoderFrame::DefaultFill(Ipp32s field, bool isChromaOnly)
{
    IppiSize roi;
    Ipp8u defaultValue = 128;

    if (field == 2)
    {
        if (!isChromaOnly)
        {
            roi = m_lumaSize;

            SetPlane(defaultValue, m_pYPlane,
                pitch_luma(), roi);
        }

        roi = m_chromaSize;

        SetPlane(defaultValue, m_pUPlane,
            pitch_chroma(), roi);
        SetPlane(defaultValue, m_pVPlane,
            pitch_chroma(), roi);
    }
    else
    {
        if (!isChromaOnly)
        {
            roi = m_lumaSize;
            roi.height >>= 1;

            SetPlane(defaultValue, m_pYPlane + field*pitch_luma(),
                2*pitch_luma(), roi);
        }

        roi = m_chromaSize;
        roi.height >>= 1;

        SetPlane(defaultValue, m_pUPlane + field*pitch_chroma(),
            2*pitch_chroma(), roi);
        SetPlane(defaultValue, m_pVPlane + field*pitch_chroma(),
            2*pitch_chroma(), roi);
    }
}

void H264DecoderFrame::deallocateParsedFrameData()
{
    m_pRefPicListTop.Reset();
    m_pRefPicListBottom.Reset();

    // new structure(s) hold pointer
    if (m_pParsedFrameDataNew)
    {
        // Free the old buffer.
        m_pMemoryAllocator->Unlock(m_midParsedFrameDataNew);
        m_pMemoryAllocator->Free(m_midParsedFrameDataNew);
        m_midParsedFrameDataNew = 0;
        m_pParsedFrameDataNew = 0;

        m_mbinfo.MV[0] = 0;
        m_mbinfo.MV[1] = 0;
        m_mbinfo.RefIdxs[0] = 0;
        m_mbinfo.RefIdxs[1] = 0;
        m_mbinfo.mbs = 0;
    }

    m_paddedParsedFrameDataSize.width = 0;
    m_paddedParsedFrameDataSize.height = 0;

}    // deallocateParsedFrameData

Status H264DecoderFrame::allocateParsedFrameData(const IppiSize &size, Ipp32s bpp)
{
    Status      umcRes = UMC_OK;
    IppiSize    desiredPaddedSize;

    m_pRefPicListTop.Init(1);
    m_pRefPicListBottom.Init(1);

    desiredPaddedSize.width  = (size.width  + 15) & ~15;
    desiredPaddedSize.height = (size.height + 15) & ~15;

    // If our buffer and internal pointers are already set up for this
    // image size, then there's nothing more to do.

    if (m_paddedParsedFrameDataSize.width != desiredPaddedSize.width ||
        m_paddedParsedFrameDataSize.height != desiredPaddedSize.height || m_bpp != bpp)
    {
        // allocate new MB structure(s)
        size_t nMBCount = (desiredPaddedSize.width>>4) * (desiredPaddedSize.height>>4);

        // allocate buffer
        size_t nMemSize = (sizeof(H264DecoderMacroblockMVs) +
                           sizeof(H264DecoderMacroblockMVs) +
                           sizeof(H264DecoderMacroblockRefIdxs) +
                           sizeof(H264DecoderMacroblockRefIdxs) +
                           sizeof(H264DecoderMacroblockGlobalInfo)) * nMBCount + 16 * 5;

        // allocate buffer
        if (UMC_OK != m_pMemoryAllocator->Alloc(&m_midParsedFrameDataNew,
                                                nMemSize,
                                                UMC_ALLOC_PERSISTENT))
            return UMC_ERR_ALLOC;
        m_pParsedFrameDataNew = (Ipp8u *) m_pMemoryAllocator->Lock(m_midParsedFrameDataNew);

        ippsZero_8u(m_pParsedFrameDataNew, (Ipp32s) nMemSize);

        // set pointer(s)
        m_mbinfo.MV[0] = align_pointer<H264DecoderMacroblockMVs *> (m_pParsedFrameDataNew, ALIGN_VALUE);
        m_mbinfo.MV[1] = align_pointer<H264DecoderMacroblockMVs *> (m_mbinfo.MV[0]+ nMBCount, ALIGN_VALUE);
        m_mbinfo.RefIdxs[0] = align_pointer<H264DecoderMacroblockRefIdxs *> (m_mbinfo.MV[1] + nMBCount, ALIGN_VALUE);
        m_mbinfo.RefIdxs[1] = align_pointer<H264DecoderMacroblockRefIdxs *> (m_mbinfo.RefIdxs[0] + nMBCount, ALIGN_VALUE);
        m_mbinfo.mbs = align_pointer<H264DecoderMacroblockGlobalInfo *> (m_mbinfo.RefIdxs[1] + nMBCount, ALIGN_VALUE);

        m_paddedParsedFrameDataSize.width = desiredPaddedSize.width;
        m_paddedParsedFrameDataSize.height = desiredPaddedSize.height;
    }

    return umcRes;

} // H264DecoderFrame::allocateParsedFrameData(const IppiSize &size)

H264DecoderFrame::~H264DecoderFrame()
{
    if (m_pSlicesInfo)
    {
        delete m_pSlicesInfo;
        delete m_pSlicesInfoBottom;
        m_pSlicesInfo = 0;
        m_pSlicesInfoBottom = 0;
    }

⌨️ 快捷键说明

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