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

📄 umc_mjpeg_video_decoder.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 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) 2003-2005 Intel Corporation. All Rights Reserved.////*/#include <string.h>#include "vm_debug.h"#include "umc_video_data.h"#include "umc_mjpeg_video_decoder.h"namespace UMC{MJPEGVideoDecoder::MJPEGVideoDecoder(void){  m_IsInit      = false;  m_firstFrame  = false;  m_firstField  = false;  m_interleaved = false;  m_frameNo     = 0;  m_skipped_fr  = 0;  m_frame       = 0;  m_frameStep   = 0;  m_fieldStep   = 0;  m_dec_time    = 0.0;  return;} // ctorMJPEGVideoDecoder::~MJPEGVideoDecoder(void){  Close();  return;} // dtorStatus MJPEGVideoDecoder::Init(BaseCodecParams* lpInit){  Status              status;  VideoDecoderParams* pDecoderParams;  if(0 == lpInit)    return UMC_NULL_PTR;  pDecoderParams = DynamicCast<VideoDecoderParams>(lpInit);  m_DecoderParams = *pDecoderParams;  if(0 != m_frame)    ippFree(m_frame);  m_IsInit       = true;  m_firstFrame   = true;  m_interleaved  = false;  m_frameNo      = 0;  m_skipped_fr   = 0;  m_frame        = 0;  m_frameStep    = 0;  m_fieldStep    = 0;  m_pConverter = m_DecoderParams.lpConverter;  if(0 == m_pConverter)  {    return UMC_NULL_PTR;  }  if(pDecoderParams->lpConvertInit)  {    m_ConvertParams.ConversionInit                   = *(pDecoderParams->lpConvertInit);    m_ConvertParams.ConversionInit.FormatSource      = YUY2;    m_ConvertParams.ConversionInit.FormatDest        = (*pDecoderParams).cformat;    m_ConvertParams.ConversionInit.SizeSource.width  = pDecoderParams->info.clip_info.width;    m_ConvertParams.ConversionInit.SizeSource.height = pDecoderParams->info.clip_info.height;    status = m_pConverter->Init(m_ConvertParams.ConversionInit);    if(UMC_OK != status)      return status;  }  return UMC_OK;} // MJPEGVideoDecoder::Init()Status MJPEGVideoDecoder::Reset(void){  if(0 != m_frame)    ippFree(m_frame);  m_IsInit       = true;  m_firstFrame   = true;  m_frameNo      = 0;  m_skipped_fr   = 0;  m_interleaved  = false;  m_frame        = 0;  m_frameStep    = 0;  m_fieldStep    = 0;  return UMC_OK;} // MJPEGVideoDecoder::Reset()Status MJPEGVideoDecoder::Close(void){  if(0 != m_frame)    ippFree(m_frame);  m_IsInit       = false;  m_firstFrame   = false;  m_firstField   = false;  m_interleaved  = false;  m_frameNo      = 0;  m_skipped_fr   = 0;  m_frame        = 0;  m_frameStep    = 0;  m_fieldStep    = 0;  return UMC_OK;} // MJPEGVideoDecoder::Close()Status  MJPEGVideoDecoder::SkipVideoFrame(int count){  if(!m_IsInit)    return UMC_NOT_INITIALIZED;  m_skipped_fr += count;  return UMC_OK;} // MJPEGVideoDecoder::SkipVideoFrame()vm_var32 MJPEGVideoDecoder::GetSkipedFrame(void){  return m_skipped_fr;} // MJPEGVideoDecoder::GetSkipedFrame()Status  MJPEGVideoDecoder::ResetSkipCount(void){  return UMC_NOT_IMPLEMENTED;} // MJPEGVideoDecoder::ResetSkipCount()Status MJPEGVideoDecoder::GetInfo(BaseCodecParams *lpInfo){  Status              umcRes;  VideoDecoderParams* lpParams;  if(NULL == lpInfo)    return UMC_NULL_PTR;  umcRes = VideoDecoder::GetInfo(lpInfo);  if(UMC_OK != umcRes)  {    return umcRes;  }  lpParams = DynamicCast<VideoDecoderParams>(lpInfo);  lpParams->info.clip_info.width  = m_ConvertParams.ConversionInit.SizeDest.width;  lpParams->info.clip_info.height = m_ConvertParams.ConversionInit.SizeDest.height;  return umcRes;} // MJPEGVideoDecoder::GetInfo()Status MJPEGVideoDecoder::_GetFrameInfo(Ipp8u* pBitStream, int nSize){  int      nchannels;  int      precision;  JSS      sampling;  JCOLOR   color;  JERRCODE jerr;  Status   status;  jerr = m_dec.SetSource(pBitStream,nSize);  if(JPEG_OK != jerr)    return UMC_OPERATION_FAILED;  jerr = m_dec.ReadHeader(    &m_frameDims.width,&m_frameDims.height,&nchannels,&color,&sampling,&precision);  if(JPEG_BUFF_TOO_SMALL == jerr)    return UMC_NOT_ENOUGH_DATA;  if(JPEG_OK != jerr)    return UMC_OPERATION_FAILED;  if(JS_422 == sampling && JC_YCBCR == color)  {    m_ConvertParams.ConversionInit.FormatSource = YUY2;    status = m_pConverter->Init(m_ConvertParams.ConversionInit);    if(UMC_OK != status)      return status;    m_frameStep = m_frameDims.width*2;  }  else  {    m_ConvertParams.ConversionInit.FormatSource = RGB24;    status = m_pConverter->Init(m_ConvertParams.ConversionInit);    if(UMC_OK != status)      return status;    m_frameStep = m_frameDims.width*3 + DIB_PAD_BYTES(m_frameDims.width,3);  }  // frame is interleaved if clip height is twice more than JPEG frame height  if(m_frameDims.height == (m_DecoderParams.info.clip_info.height >> 1))  {    m_interleaved = true;    m_frameDims.height *= 2;  }  return UMC_OK;} // MJPEGVideoDecoder::_GetFrameInfo()Status MJPEGVideoDecoder::_DecodeField(Ipp8u* pBitStream,int nSize,int* cnt){  int      dstStep;  Ipp8u*   pDst;  JCOLOR   color;  JSS      sampling;  JERRCODE jerr;  jerr = m_dec.SetSource(pBitStream,nSize);  if(JPEG_OK != jerr)    return UMC_OPERATION_FAILED;  jerr = m_dec.ReadHeader(    &m_frameDims.width,&m_frameDims.height,&m_frameChannels,&color,&sampling,&m_framePrecision);  if(JPEG_BUFF_TOO_SMALL == jerr)    return UMC_NOT_ENOUGH_DATA;  if(JPEG_OK != jerr)    return UMC_OPERATION_FAILED;  pDst    = m_frame;  dstStep = m_frameStep;  if(m_dec.m_avi1_app0_detected)  {    switch(m_dec.m_avi1_app0_polarity)    {      default:      case 0:        pDst    = m_interleaved & !m_firstField ? m_frame + m_frameStep : m_frame;        dstStep = m_interleaved ? m_frameStep*2 : m_frameStep;        break;      case 1:        pDst    = m_firstField ? m_frame : m_frame + m_frameStep;        dstStep = m_frameStep*2;        break;      case 2:        pDst    = m_frame + m_frameStep;        dstStep = m_frameStep*2;        break;    }  }  if(JS_422 == sampling && JC_YCBCR == color)  {    jerr = m_dec.SetDestination(pDst,dstStep,m_frameDims,m_frameChannels,JC_YCBCR,JS_422);  }  else  {    jerr = m_dec.SetDestination(pDst,dstStep,m_frameDims,m_frameChannels,JC_BGR);  }  if(JPEG_OK != jerr)    return UMC_OPERATION_FAILED;  jerr = m_dec.ReadData();  if(JPEG_BUFF_TOO_SMALL == jerr)    return UMC_NOT_ENOUGH_DATA;  if(JPEG_OK != jerr)    return UMC_OPERATION_FAILED;  *cnt = m_dec.m_src.currPos;  return UMC_OK;} // MJPEGVideoDecoder::_DecodeField()Status MJPEGVideoDecoder::GetFrame(MediaData* in, MediaData* out){  int        nSize;  int        nUsedBytes;  Ipp8u*     pBitStream;  VideoData* pOutVideoData;  Status     status;  if(0 == in || 0 == out)    return UMC_NULL_PTR;  pBitStream = (Ipp8u*)in->GetDataPointer();  nSize      =    (int)in->GetDataSize();  pOutVideoData = DynamicCast<VideoData>(out);  vm_debug_trace(0,__VM_STRING("MJPEG, frame: %d\n"),m_frameNo);  if(m_firstFrame)  {    m_firstFrame = false;    m_firstField = true;    status = _GetFrameInfo(pBitStream,nSize);    if(UMC_OK != status)      return status;    m_frame = (Ipp8u*)ippMalloc(m_frameStep*m_frameDims.height);    if(0 == m_frame)      return UMC_ALLOC;  }  if(m_interleaved)  {    // interleaved frame    // get field    status = _DecodeField(pBitStream,nSize,&nUsedBytes);    if(UMC_OK != status)      return status;    if(m_firstField)    {      // request next field      m_firstField = !m_firstField;      in->SetDataSize(nSize - nUsedBytes);      return UMC_NOT_ENOUGH_DATA;    }    else    {      m_firstField = !m_firstField;      in->SetDataSize(nSize - nUsedBytes);    }  }  else  {    // progressive frame    status = _DecodeField(pBitStream,nSize,&nUsedBytes);    if(UMC_OK != status)      return status;    in->SetDataSize(nSize - nUsedBytes);  }  // got complete frame  m_frameNo++;  // set source pointer(s)  m_ConvertParams.lpSource0 = m_frame;  m_ConvertParams.lpSource2 = 0;  m_ConvertParams.lpSource1 = 0;  m_ConvertParams.PitchSource0 = m_frameStep;  m_ConvertParams.PitchSource2 = 0;  m_ConvertParams.PitchSource1 = 0;  m_ConvertParams.lpDest0 = (Ipp8u*)pOutVideoData->m_lpDest[0];  m_ConvertParams.lpDest1 = (Ipp8u*)pOutVideoData->m_lpDest[1];  m_ConvertParams.lpDest2 = (Ipp8u*)pOutVideoData->m_lpDest[2];  m_ConvertParams.PitchDest0 = pOutVideoData->m_lPitch[0];  m_ConvertParams.PitchDest1 = pOutVideoData->m_lPitch[1];  m_ConvertParams.PitchDest2 = pOutVideoData->m_lPitch[2];  if(0 != m_pConverter)  {    status = m_pConverter->ConvertFrame(&m_ConvertParams);    if(UMC_OK != status)      return status;  }  pOutVideoData->SetFrameType(I_PICTURE);  pOutVideoData->SetTime(in->GetTime());  pOutVideoData->SetVideoParameters(    m_ConvertParams.ConversionInit.SizeDest.width,    m_ConvertParams.ConversionInit.SizeDest.height,    m_ConvertParams.ConversionInit.FormatDest);  // can't calculate time for the next frame  in->SetTime(-1.0);  return status;} // MJPEGVideoDecoder::GetFrame()} // end namespace UMC

⌨️ 快捷键说明

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