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

📄 umc_mpeg2_spl_video.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 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 - 2005 Intel Corporation. All Rights Reserved.//*/#include "umc_mpeg2_spl_pure.h"#include <ipps.h>#pragma warning(disable: 4244)using namespace UMC;///////////////////////////////////////////////////////////////////////////////////////////////////////////MPEG2 pure video////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Status MPEG2VideoSplitter::InitProcessing(){    Status         ret;    m_bSequenceFound    = false;    m_bFirstValidVPTS   = false;    ResetInfoFromPrevPES();    m_inESCount         = 1;    m_pESArray[0].m_videoStreamInfo.stream_type = MPEG2_VIDEO;    m_pESArray[0].m_audioStreamInfo.stream_type = UNDEF_AUDIO;    m_pESArray[0].m_videoStreamInfo.streamPID = 0;    //reset chosen PIDS since only one stream availble in pure    m_iChoosedVideo = 0;    m_iChoosedAudio[0] = -1;    m_iChoosedAudio[1] = -1;    CheckEndian(true);    ret = InitVideoHelperBuffer(PORTION_TO_READ);    return ret;}Status MPEG2VideoSplitter::CloseProcessing(){    if(m_lockedVideoBuffer.GetDataSize() > 16 && !m_bStop)    {        unsigned char* ptr = (unsigned char*)m_lockedVideoBuffer.GetBufferPointer();        int pos = m_lockedVideoBuffer.GetDataSize();        ptr[pos] = 0; ptr[pos+1] = 0; ptr[pos+2] = 1; ptr[pos+3] = 0xb7;        m_lockedVideoBuffer.SetDataSize(m_lockedVideoBuffer.GetDataSize() + 4);        m_lockedVideoBuffer.SetDataSize((m_lockedVideoBuffer.GetDataSize() + 3)&~3);        if(m_uiEndian == 2)        {            //if start code was find make buffer size 16 bytes aligned            //and swap data if needed            Swap4Bytes((unsigned char*)m_lockedVideoBuffer.GetBufferPointer(),                                        m_lockedVideoBuffer.GetDataSize());        }        m_pVideoBuffer->UnLockInputBuffer(&m_lockedVideoBuffer);        m_uiVideoFrameCount++;        m_lockedVideoBuffer.SetTime(m_dCurrVideoPts, m_dCurrVideoDts);        StoreLastPositionAndPTS(m_lockedVideoBuffer.GetTime(),                                m_pDataReader->GetPosition() -                                m_readVideoStream.GetDataSize());    }    if(m_pTmpDataBuffAct)    {        ippsFree(m_pTmpDataBuffAct);        m_pTmpDataBuffAct = NULL;    }    return UMC_OK;}Status MPEG2VideoSplitter::ProcessOnePacket(int get_size){   return FillBufferMPEG2Video(&m_pESArray[0], get_size, m_uiEndian);}Status MPEG2VideoSplitter::ProcessPackets(int count){    int            curr_count = 0;    Status         ret = UMC_OK;    vm_sizet       full_size =  m_pDataReader->GetSize();    //stream will be read with portions size = PORTION_TO_READ    unsigned int   get_size  =  full_size >                                PORTION_TO_READ?                                PORTION_TO_READ:                                full_size;    if(count == -1)        ret = InitProcessing();    if(UMC_OK == ret)    {        while(!m_bStop        &&              (full_size > 0) &&              ((count == -1) || (curr_count < count)))        {            //m_uiPosCurrPacket=m_pDataReader->GetPosition();            ret = ProcessOnePacket(get_size);            if((UMC_OK != ret) && (UMC_NOT_ENOUGH_DATA != ret)) break;            full_size -= get_size;            get_size   =  full_size > PORTION_TO_READ?PORTION_TO_READ:full_size;            curr_count++;        }    }    if((count == -1) || (ret == UMC_END_OF_STREAM))        CloseProcessing();    return ret;}Status  MPEG2VideoSplitter::MoveToNextSyncWord(){    //need to find start code prefix 0x000001xx    Status err;    unsigned char byteCode;    unsigned int  longCode;    err = m_pDataReader->CheckUInt(&longCode, 0);    if((err == UMC_OK) &&      (longCode & 0xfffffe) != 0x00000100 &&      (longCode & 0xfffff0) != 0x000001b0)    {        do        {            err = m_pDataReader->GetByte(&byteCode);            if(err != UMC_OK) break;            err = m_pDataReader->CheckUInt(&longCode, 0);        } while(!m_bStop        &&                (err == UMC_OK) &&                ((longCode & 0xfffffe) != 0x00000100) &&                ((longCode & 0xfffff0) != 0x000001b0));    }    return err;}Status  MPEG2VideoSplitter::ForwardInit(){    Status ret;    vm_sizet       full_size =  m_pDataReader->GetSize();    //stream will be read with portions size = PORTION_TO_READ    unsigned int   get_size  =  full_size >                                192?                                192:                                full_size;    ret = InitProcessing();    if(UMC_OK == ret)    {        ret = UMC_NOT_ENOUGH_DATA;        while(!m_bStop        &&              (full_size > 0) &&              !m_bSequenceFound)        {            ret = ProcessOnePacket(get_size);            if((UMC_OK != ret) && (UMC_NOT_ENOUGH_DATA != ret)) break;            full_size -= get_size;            get_size   =  full_size > 192?192:full_size;        }    }    if(m_bSequenceFound == true)        return UMC_OK;    return UMC_NOT_INITIALIZED;}Status  MPEG2VideoSplitter::ForwardSearch(){    Status ret = UMC_OK;    bool   frame_found = false;    vm_sizet       full_size =  m_pDataReader->GetSize();    //stream will be read with portions size = PORTION_TO_READ    unsigned int   get_size  =  full_size >                                2048?                                2048:                                full_size;    //clear all previous data, because we seek from anothe position    m_lockedVideoBuffer.SetDataSize(0);    int count = m_uiVideoFrameCount;    if(UMC_OK == ret)    {        ret = UMC_NOT_ENOUGH_DATA;        while(!m_bStop        &&              (full_size > 0) &&              !frame_found)        {            ret = ProcessOnePacket(get_size);            if((UMC_OK != ret) && (UMC_NOT_ENOUGH_DATA != ret)) break;            full_size -= get_size;            get_size   =  full_size > 2048?2048:full_size;            if(m_uiVideoFrameCount - count > 1)                frame_found = true;        }    }    if(frame_found == true)        return UMC_OK;    return ret;}bool MPEG2VideoSplitter::IsAcceptableVideoBuffer(){    if(!m_bForwardDirection)//reverse playback    {        static bool count = true;        void* ptr = m_lockedVideoBuffer.GetBufferPointer();        bool ret = (((*((unsigned int*)ptr)>>19)& 3) < m_uiVideoAcceptanceLevel) || ((*((unsigned int*)ptr)) == 435);        //if((*((unsigned int*)ptr)) == 435)        //    return true;        //else        //    count = !count;        return (ret);//&&count);    }    return true;}Status MPEG2VideoSplitter::GetPosition(double& pos){    if(m_pDataReader)    {        vm_var64 size      = m_pDataReader->GetSize();        vm_var64 bitrate   = m_pESArray[0].m_videoStreamInfo.bitrate*400;        double dur;        if(bitrate <= 0)        {            bitrate = 700000;        }        dur  = ((double)(vm_var64s)(size))/((double)(vm_var64s)(bitrate/8));        pos  = (double)dur;        return UMC_OK;    }    return UMC_NOT_INITIALIZED;}Status MPEG2VideoSplitter::GetInfo(SplitterInfo* pSplInfo){    MPEG2AVSplitter::GetInfo(pSplInfo);     if(m_pDataReader)    {        vm_var64 size      = m_pDataReader->GetSize();        vm_var64 bitrate   = m_pESArray[0].m_videoStreamInfo.bitrate*400;        if(bitrate <= 0)        {            bitrate = 700000;        }        pSplInfo->m_video_info.duration  =                ((double)(vm_var64s)(size))/((double)(vm_var64s)(bitrate/8));    }    return UMC_OK;}///////////////////////////////////////////////////////////////////////////////////////////////////////////MPEG4-2 pure video////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Status MPEG4VideoSplitter::InitProcessing(){    Status         ret;    m_inESCount         = 1;    m_bSequenceFound    = false;    m_bFirstValidVPTS   = false;    ResetInfoFromPrevPES();    m_pESArray[0].m_videoStreamInfo.stream_type = MPEG4_VIDEO;    m_pESArray[0].m_audioStreamInfo.stream_type = UNDEF_AUDIO;    m_pESArray[0].m_videoStreamInfo.streamPID = 0;    //reset chosen PIDS since only one stream availble in pure    m_iChoosedVideo = 0;    m_iChoosedAudio[0] = -1;    m_iChoosedAudio[1] = -1;    CheckEndian(false);    m_uiEndian = 0;    ret = InitVideoHelperBuffer(PORTION_TO_READ);    return ret;}Status MPEG4VideoSplitter::CloseProcessing(){    if(m_lockedVideoBuffer.GetBufferSize() > 4 && !m_bStop)    {        m_pVideoBuffer->UnLockInputBuffer(&m_lockedVideoBuffer);        m_uiVideoFrameCount++;        m_lockedVideoBuffer.SetTime(m_dCurrVideoPts, m_dCurrVideoDts);        StoreLastPositionAndPTS(m_lockedVideoBuffer.GetTime(),                                m_pDataReader->GetPosition() -                                m_readVideoStream.GetDataSize());    }    if(m_pTmpDataBuffAct)    {        ippsFree(m_pTmpDataBuffAct);        m_pTmpDataBuffAct = NULL;    }    return UMC_OK;}Status MPEG4VideoSplitter::ProcessOnePacket(int get_size){   return  FillBufferMPEG4Video(&m_pESArray[0], get_size, m_uiEndian);}Status MPEG4VideoSplitter::ProcessPackets(int count){    int curr_count = 0;    Status         ret;    vm_sizet       full_size =  m_pDataReader->GetSize();    //stream will be read with portions size = PORTION_TO_READ    unsigned int   get_size  =  full_size >                                PORTION_TO_READ?                                PORTION_TO_READ:                                full_size;    if(count == -1)        ret = InitProcessing();    if(UMC_OK == ret)    {        while(!m_bStop        &&              (full_size > 0) &&              ((count == -1) || (curr_count < count)))        {            ret = ProcessOnePacket(get_size);            if((UMC_OK != ret) && (UMC_NOT_ENOUGH_DATA != ret)) break;            full_size -= get_size;            get_size   =  full_size > PORTION_TO_READ?PORTION_TO_READ:full_size;            curr_count++;        }    }    if((count == -1) || (ret == UMC_END_OF_STREAM))        CloseProcessing();    return ret;}Status  MPEG4VideoSplitter::MoveToNextSyncWord(){    //need to find start code prefix 0x000001xx    Status err;    unsigned char byteCode;    unsigned int  longCode;    err = m_pDataReader->CheckUInt(&longCode, 0);    if((err == UMC_OK) &&      ((longCode & 0xffffff00) != 0x00000100))    {        do        {            err = m_pDataReader->GetByte(&byteCode);            if(err != UMC_OK) break;

⌨️ 快捷键说明

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