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

📄 umc_mpeg2_spl_av.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Status ret = UMC_OK, retBuff = UMC_OK;    unsigned int   uiStartCodeMax    = MAX_CODE_COUNT;    unsigned int   get_size          = full_size;    get_size   =  full_size > PORTION_TO_READ?PORTION_TO_READ:full_size;    while(!m_bStop && full_size > 0)    {        if(retBuff == UMC_OK || m_lockedVideoBuffer.GetBufferSize() >= PORTION_TO_READ)        {            //read data            m_readVideoStream.SetBufferPointer(m_pTmpDataBuffAct, PORTION_TO_READ);            ret        = m_pDataReader->GetData(m_readVideoStream.GetBufferPointer(), &get_size);            //break immediately if data reader error            if(ret != UMC_OK) return ret;            m_readVideoStream.SetDataSize(get_size);            //Will check all MPEG2 start codes in lockedData            //untill next PIC START CODE would be found            do {                bool isSeqFound = false;                ret        = FindMPEG4StartCode(&m_readVideoStream,//input buffer                                                                  //pointer and remaining size                                                                  //will be updated                                                &m_lockedVideoBuffer,//output frame(may be swapped)                                                                  //if all ok                                                m_InfoFromPrevPES, //previous 3 bytes needed                                                                  //to not lose a start code                                                                  //on the bounds                                                &m_pStartCodes[m_uiStartCodePos],//StartCodes structure will                                                                  //be filled inside                                                uiStartCodeMax,   //limit of structure                                                m_uiStartCodeOff,                                                false, isSeqFound);                if(isSeqFound)                {                    if(!m_bSequenceFound)                    {                        ParseMP4Header* mp4_dec  = new ParseMP4Header;                        if(mp4_dec->Init((unsigned char*)m_lockedVideoBuffer.GetBufferPointer(),                                         m_lockedVideoBuffer.GetDataSize()) == UMC_OK)                        {                            pES->m_videoStreamInfo.stream_type     = MPEG4_VIDEO ;                            pES->m_videoStreamInfo.stream_subtype  = UNDEF_VIDEO_SUBTYPE;                            //pES->m_audioStreamInfo.stream_type     = UNDEF_AUDIO;                            mp4_dec->GetdecInfo(pES->m_videoStreamInfo.clip_info.width,                                                pES->m_videoStreamInfo.clip_info.height);                            m_bSequenceFound = true;                            isSeqFound = false;                        }                        delete mp4_dec;                    }                }                /*if(!m_bSequenceFound && ret == UMC_OK)                {                    m_readVideoStream.SetPointer(((unsigned char*)m_readVideoStream.GetBufferPointer()) + 4,                                                    m_readVideoStream.GetDataSize() - 4);                    m_readVideoStream.SetDataSize(m_readVideoStream.GetDataSize() - 4);                    m_lockedVideoBuffer.SetDataSize(0);                    uiStartCodeMax   = MAX_CODE_COUNT;                    m_uiStartCodePos = 0;                    m_uiStartCodeOff = 0;                }                else */                if(!m_bStop        &&                   (ret == UMC_OK) &&                   (m_lockedVideoBuffer.GetDataSize() > 0))                {                    if(m_lFlagsReq & FLAG_VSPL_VIDEO_FRAME_REQ)                    {                        m_lFlagsReq &= ~FLAG_VSPL_VIDEO_FRAME_REQ;                        m_uiStartCodeOff  = m_lockedVideoBuffer.GetDataSize();                        m_uiStartCodePos += uiStartCodeMax;                        uiStartCodeMax    = MAX_CODE_COUNT - m_uiStartCodePos;                        VM_ASSERT(uiStartCodeMax > 0);                        VM_ASSERT(m_uiStartCodePos < MAX_CODE_COUNT);                    }                    else                    {                        //align buffer size on 16 bytes                        unsigned char tmp_ptr[4];                        m_lockedVideoBuffer.SetDataSize(m_lockedVideoBuffer.GetDataSize()-4);                        memcpy(tmp_ptr, (unsigned char*)m_lockedVideoBuffer.GetBufferPointer()+                                       m_lockedVideoBuffer.GetDataSize(), 4);                        if(swapFlag == 2)//TBD need to check swap flag                        {                            //if start code was find make buffer size 16 bytes aligned                            //and swap data if needed                            VM_ASSERT(0);                            Swap4Bytes((unsigned char*)m_lockedVideoBuffer.GetBufferPointer(),                                                       m_lockedVideoBuffer.GetDataSize());                        }                        retBuff = m_pVideoBuffer->UnLockInputBuffer(&m_lockedVideoBuffer);                        m_lockedVideoBuffer.SetTime(m_dCurrVideoPts, m_dCurrVideoDts);                        m_uiVideoFrameCount++;                        m_dPrevVideoPts = -1;                        StoreLastPositionAndPTS(m_lockedVideoBuffer.GetTime(),                                                m_pDataReader->GetPosition() -                                                m_readVideoStream.GetDataSize());                        do {                            retBuff = m_pVideoBuffer->LockInputBuffer(&m_lockedVideoBuffer);                            vm_time_sleep(5);                        } while(!m_bStop && retBuff == UMC_NOT_ENOUGH_BUFFER);                        m_lockedVideoBuffer.SetDataSize(4);                        memcpy((unsigned char*)m_lockedVideoBuffer.GetBufferPointer(),tmp_ptr,  4);                        uiStartCodeMax   = MAX_CODE_COUNT;                        m_uiStartCodePos = 0;                        m_uiStartCodeOff = 0;                    }                }                else                {                    m_uiStartCodeOff  = m_lockedVideoBuffer.GetDataSize();                    m_uiStartCodePos += uiStartCodeMax;                    uiStartCodeMax    = MAX_CODE_COUNT - m_uiStartCodePos;                    VM_ASSERT(uiStartCodeMax > 0);                    VM_ASSERT(m_uiStartCodePos < MAX_CODE_COUNT);                }            } while(!m_bStop && ret == UMC_OK);            full_size -= get_size;            get_size   =  full_size > PORTION_TO_READ?PORTION_TO_READ:full_size;        }        else        {            //video buffer is full with frames, need to wait            vm_time_sleep(5);        }    }    return ret;}bool MPEG2AVSplitter::IsSOP(H264SH *fs,H264SH *ss,Ipp8u pic_order_cnt_type){    Ipp32u result=0;    result |= (fs->pic_parameter_set_id!= ss->pic_parameter_set_id);    result |= (fs->frame_num != ss->frame_num);    result |= (fs->field_pic_flag != ss->field_pic_flag);    if(fs->field_pic_flag && ss->field_pic_flag)    {        result |= (fs->bottom_field_flag != ss->bottom_field_flag);    }    result |= (fs->nal_ref_idc   != ss->nal_ref_idc);    result |= ( fs->idr_flag != ss->idr_flag);    if (fs->idr_flag && ss->idr_flag)    {        result |= (fs->idr_pic_id != ss->idr_pic_id);    }    if (pic_order_cnt_type == 0)    {        result |=  (fs->pic_order_cnt_lsb          != ss->pic_order_cnt_lsb);        result |=  (fs->delta_pic_order_cnt_bottom != ss->delta_pic_order_cnt_bottom);    }    if (pic_order_cnt_type == 1)    {        result |= (fs->delta_pic_order_cnt[0] != ss->delta_pic_order_cnt[0]);        result |= (fs->delta_pic_order_cnt[1] != ss->delta_pic_order_cnt[1]);    }    return result!=0;}Status MPEG2AVSplitter::FillBufferH264Video(ElementaryStream* pES,                                             int full_size,                                             int swapFlag){    Status ret = UMC_OK, retBuff = UMC_OK;    unsigned int    uiStartCodeMax    = MAX_CODE_COUNT;    unsigned int    get_size          = full_size;    static int      g_count = 0;    bool            isSeqFound = false;    bool            isNextAfterSeqFound = false;    get_size   =  full_size+m_h264Headers.m_puiBrokenHeaderSize > PORTION_TO_READ?PORTION_TO_READ:                                                        full_size + m_h264Headers.m_puiBrokenHeaderSize;    while(!m_bStop && full_size > 0)    {        if(retBuff == UMC_OK || m_lockedVideoBuffer.GetBufferSize() >= PORTION_TO_READ)        {            //read data            m_readVideoStream.SetBufferPointer(m_pTmpDataBuffAct, PORTION_TO_READ);            get_size -= m_h264Headers.m_puiBrokenHeaderSize;            ret        = m_pDataReader->GetData((unsigned char*)m_readVideoStream.GetBufferPointer() +                                                   m_h264Headers.m_puiBrokenHeaderSize,                                                   &get_size);            //break immediately if data reader error            if(ret != UMC_OK) return ret;            m_readVideoStream.SetDataSize(get_size+m_h264Headers.m_puiBrokenHeaderSize);            if(m_h264Headers.m_bBrokenHeader)            {                memcpy(m_readVideoStream.GetDataPointer(), m_h264Headers.m_pubBrokenHeader,                                                        m_h264Headers.m_puiBrokenHeaderSize);                m_h264Headers.m_puiBrokenHeaderSize = 0;                goto broken_header;            }            //Will check all MPEG2 start codes in lockedData            //untill next PIC START CODE would be found            do {                isSeqFound = false;                isNextAfterSeqFound = false;                ret        = FindH264StartCode(&m_readVideoStream,//input buffer                                                                  //pointer and remaining size                                                                  //will be updated                                                &m_lockedVideoBuffer,//output frame(may be swapped)                                                                  //if all ok                                                m_InfoFromPrevPES, //previous 3 bytes needed                                                                  //to not lose a start code                                                                  //on the bounds                                                &m_pStartCodes[m_uiStartCodePos],//StartCodes structure will                                                                  //be filled inside                                                uiStartCodeMax,   //limit of structure                                                m_uiStartCodeOff,                                                false,                                                isSeqFound,                                                isNextAfterSeqFound);                if(isNextAfterSeqFound)                {                    Ipp32u i;                    for(i = 0; i < m_uiStartCodePos+uiStartCodeMax; i++)                    {                        if((m_pStartCodes[i].m_startCode&0x1f) == 7)                        {                            //SPS                            unsigned char sps[4096];                            unsigned int  *uiSps = reinterpret_cast<unsigned int*>(sps);                            int size = m_pStartCodes[i+1].m_StartCodePos-m_pStartCodes[i].m_StartCodePos;                            int bf = 31;                            uiSps++;                            memcpy(sps, (unsigned char*)m_lockedVideoBuffer.GetBufferPointer()+                                    m_pStartCodes[i].m_StartCodePos, size);#ifndef _BIG_ENDIAN_                            Swap4BytesH264(sps, size);#endif //ifndef _BIG_ENDIAN_                            m_h264Headers.m_uiValidSPSIndex = GetSequenceParamSet(&uiSps, &bf, &m_h264Headers);                            pES->m_videoStreamInfo.clip_info.width =                                m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_width_in_mbs *16                                -(m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_cropping_rect_left_offset+                                m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_cropping_rect_right_offset)*2;                            pES->m_videoStreamInfo.clip_info.height =                                (2 - m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_mbs_only_flag)*                                    m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_height_in_mbs *16                                    -(m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_cropping_rect_top_offset+                                    m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_cropping_rect_bottom_offset)*2*                                    (2 - m_h264Headers.m_SPS[m_h264Headers.m_uiValidSPSIndex].frame_mbs_only_flag);                            m_h264Headers.m_uiSPSCount++;                            vm_debug_trace(0, VM_STRING("H264 SPS found\n"));                        }                        else if((m_pStartCodes[i].m_startCode&0x1f) == 8)                        {                            //PPS                            unsigned char pps[16];                            unsigned int  *uiPps = reinterpret_cast<unsigned int*>(pps);                            int size = 16;                            int bf = 31;                            uiPps++;                            memcpy(pps, (unsigned char*)m_lockedVideoBuffer.GetBufferPointer()+                                    m_pStartCodes[i].m_StartCodePos, 16);#ifndef _BIG_ENDIAN_                            Swap4BytesH264(pps, size);#endif //ifndef _BIG_ENDIAN_                            GetPictureParamSet(&uiPps, &bf, &m_h264Headers);                            m_h264Headers.m_uiPPSCount++;                            vm_debug_trace(0, VM_STRING("H264 PPS found\n"));                        }                    }                   m_bSequenceFound = true;                }                if(!m_bSequenceFound && ret == UMC_OK)                {

⌨️ 快捷键说明

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