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

📄 h263decframe.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ///////////////////////////////////////////////////////////////////////////               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) 2005 Intel Corporation. All Rights Reserved.////  Description:    Decodes H.263++ frame.//*/#include "h263.h"#include "h263dec.h"#pragma warning(disable : 188)  // enumerated type mixed with another type ICLstatic h263_Status h263_InitFrame(h263_Frame *frame, int mbPerRow, int mbPerCol){  int heightY, heightC;  frame->stepY = (mbPerRow + 2 * H263_NUM_EXT_MB) << 4;  heightY = (mbPerCol + 2 * H263_NUM_EXT_MB) << 4;  frame->stepCb = frame->stepCr = (mbPerRow + 2 * H263_NUM_EXT_MB) << 3;  heightC = (mbPerCol + 2 * H263_NUM_EXT_MB) << 3;  frame->apY = ippsMalloc_8u(frame->stepY * heightY + (frame->stepCb + frame->stepCr) * heightC);  if (!frame->apY) return H263_STATUS_NO_MEM;  frame->pY = frame->apY + frame->stepY * 16 + 16;  frame->apCb = frame->apY + frame->stepY * heightY;  frame->pCb = frame->apCb + frame->stepCb * 8 + 8;  frame->apCr = frame->apCb + frame->stepCb * heightC;  frame->pCr = frame->apCr + frame->stepCr * 8 + 8;  return H263_STATUS_OK;}/*//  Free memory allocated for frame*/static void h263_FreeFrame(h263_Frame *frame){  if (frame->apY) {    ippsFree(frame->apY);    frame->apY = frame->pY = frame->apCb = frame->pCb = frame->apCr = frame->pCr = NULL;  }}static h263_EnhancedLayer *h263_InitEnhancedLayer(h263_Info* pInfo){  int mbPerRow, mbPerCol;  h263_VideoPicture *VPic = &pInfo->VideoSequence.VideoPicture;  int layer_ind = VPic->enh_layer_num - 2;  h263_EnhancedLayer *enhLayer;  void *malloc_ptr;  int stepY, stepC, heightY, heightC;  mbPerRow = VPic->MacroBlockPerRow;  mbPerCol = VPic->MacroBlockPerCol;  stepY = (mbPerRow + 2 * H263_NUM_EXT_MB) << 4;  stepC = (mbPerRow + 2 * H263_NUM_EXT_MB) << 3;  heightY = (mbPerCol + 2 * H263_NUM_EXT_MB) << 4;  heightC = (mbPerCol + 2 * H263_NUM_EXT_MB) << 3;  enhLayer = (h263_EnhancedLayer *)ippsMalloc_8u(sizeof(h263_EnhancedLayer));  if (!enhLayer) return NULL;  pInfo->VideoSequence.enhLayers[layer_ind] = enhLayer;  ippsZero_8u((Ipp8u *)enhLayer, sizeof(h263_EnhancedLayer));  enhLayer->c_Frame.mbPerRow = enhLayer->r_Frame.mbPerRow = enhLayer->n_Frame.mbPerRow = mbPerRow;  enhLayer->c_Frame.mbPerCol = enhLayer->r_Frame.mbPerCol = enhLayer->n_Frame.mbPerCol = mbPerCol;  enhLayer->c_Frame.stepY = enhLayer->r_Frame.stepY = enhLayer->n_Frame.stepY = stepY;  enhLayer->c_Frame.stepCb = enhLayer->r_Frame.stepCb = enhLayer->n_Frame.stepCb = stepC;  enhLayer->c_Frame.stepCr = enhLayer->r_Frame.stepCr = enhLayer->n_Frame.stepCr = stepC;  enhLayer->c_Frame.width = enhLayer->r_Frame.width = enhLayer->n_Frame.width = VPic->width;  enhLayer->c_Frame.height = enhLayer->r_Frame.height = enhLayer->n_Frame.height = VPic->height;  malloc_ptr = ippsMalloc_8u(stepY * heightY + 2 * stepC * heightC);  if (!malloc_ptr) return NULL;  enhLayer->c_Frame.apY = (Ipp8u *)malloc_ptr;  enhLayer->c_Frame.pY = enhLayer->c_Frame.apY + stepY * 16 + 16;  enhLayer->c_Frame.apCb = enhLayer->c_Frame.apY + stepY * heightY;  enhLayer->c_Frame.pCb = enhLayer->c_Frame.apCb + stepC * 8 + 8;  enhLayer->c_Frame.apCr = enhLayer->c_Frame.apCb + stepC * heightC;  enhLayer->c_Frame.pCr = enhLayer->c_Frame.apCr + stepC * 8 + 8;  malloc_ptr = ippsMalloc_8u(stepY * heightY + 2 * stepC * heightC);  if (!malloc_ptr) return NULL;  enhLayer->r_Frame.apY = malloc_ptr;  enhLayer->r_Frame.pY = enhLayer->r_Frame.apY + stepY * 16 + 16;  enhLayer->r_Frame.apCb = enhLayer->r_Frame.apY + stepY * heightY;  enhLayer->r_Frame.pCb = enhLayer->r_Frame.apCb + stepC * 8 + 8;  enhLayer->r_Frame.apCr = enhLayer->r_Frame.apCb + stepC * heightC;  enhLayer->r_Frame.pCr = enhLayer->r_Frame.apCr + stepC * 8 + 8;  malloc_ptr = ippsMalloc_8u(stepY * heightY + 2 * stepC * heightC);  if (!malloc_ptr) return NULL;  enhLayer->n_Frame.apY = malloc_ptr;  enhLayer->n_Frame.pY = enhLayer->n_Frame.apY + stepY * 16 + 16;  enhLayer->n_Frame.apCb = enhLayer->n_Frame.apY + stepY * heightY;  enhLayer->n_Frame.pCb = enhLayer->n_Frame.apCb + stepC * 8 + 8;  enhLayer->n_Frame.apCr = enhLayer->n_Frame.apCb + stepC * heightC;  enhLayer->n_Frame.pCr = enhLayer->n_Frame.apCr + stepC * 8 + 8;  return enhLayer;}static void h263_FreeEnhancedLayer(h263_EnhancedLayer *layer){  if (layer->c_Frame.apY) {    ippsFree(layer->c_Frame.apY);    layer->c_Frame.apY = NULL;  }  if (layer->r_Frame.apY) {    ippsFree(layer->c_Frame.apY);    layer->c_Frame.apY = NULL;  }  if (layer->n_Frame.apY) {    ippsFree(layer->c_Frame.apY);    layer->c_Frame.apY = NULL;  }  ippsFree(layer);}static h263_Status h263_SpatialInterpolateFrame(h263_Frame *srcFrame, h263_Frame *dstFrame, int scal_type){  IppiSize srcRoiSize;  int interp_type;  switch (scal_type) {  case H263_SCALABILITY_SPATIAL_X:    interp_type = IPPVC_INTERP_HORIZONTAL;    break;  case H263_SCALABILITY_SPATIAL_Y:    interp_type = IPPVC_INTERP_VERTICAL;    break;  default:    interp_type = IPPVC_INTERP_2D;  }  srcRoiSize.height = srcFrame->mbPerCol * 16;  srcRoiSize.width = srcFrame->mbPerRow * 16;  if (ippiSpatialInterpolation_H263_8u_C1R(srcFrame->pY, srcFrame->stepY, srcRoiSize, dstFrame->pY, dstFrame->stepY, interp_type) != ippStsNoErr)    return H263_STATUS_ERROR;  srcRoiSize.height = srcFrame->mbPerCol * 8;  srcRoiSize.width = srcFrame->mbPerRow * 8;  if (ippiSpatialInterpolation_H263_8u_C1R(srcFrame->pCb, srcFrame->stepCb, srcRoiSize, dstFrame->pCb, dstFrame->stepCb, interp_type) != ippStsNoErr)    return H263_STATUS_ERROR;  if (ippiSpatialInterpolation_H263_8u_C1R(srcFrame->pCr, srcFrame->stepCr, srcRoiSize, dstFrame->pCr, dstFrame->stepCr, interp_type) != ippStsNoErr)    return H263_STATUS_ERROR;  return H263_STATUS_OK;}/*//  h263_Info for decoding of Video Sequence*/h263_Status h263_InitVSeq(h263_Info* pInfo, int mbPerRow, int mbPerCol){  h263_Status status;  h263_VideoPicture *VPic = &pInfo->VideoSequence.VideoPicture;  pInfo->VideoSequence.picture_time_increment_resolution = 1800000;  pInfo->VideoSequence.PicIndex = 0;  if (mbPerRow <= 0)    mbPerRow = pInfo->VideoSequence.VideoPicture.MacroBlockPerRow;  if (mbPerCol <= 0)    mbPerCol = pInfo->VideoSequence.VideoPicture.MacroBlockPerCol;  pInfo->VideoSequence.cFrame.mbPerRow = pInfo->VideoSequence.rFrame.mbPerRow = pInfo->VideoSequence.nFrame.mbPerRow = mbPerRow;  pInfo->VideoSequence.cFrame.mbPerCol = pInfo->VideoSequence.rFrame.mbPerCol = pInfo->VideoSequence.nFrame.mbPerCol = mbPerCol;  pInfo->VideoSequence.cFrame.width = pInfo->VideoSequence.rFrame.width = pInfo->VideoSequence.nFrame.width = VPic->width;  pInfo->VideoSequence.cFrame.height = pInfo->VideoSequence.rFrame.height = pInfo->VideoSequence.nFrame.height = VPic->height;  pInfo->VideoSequence.num_of_MBs = mbPerRow * mbPerCol;  /* current frame */  /* not referenced frame (B-part of PB-frame or B-frame) */  status = h263_InitFrame(&pInfo->VideoSequence.cFrame, mbPerRow, mbPerCol);  if (status != H263_STATUS_OK)    return status;  /* ref in past frame */  status = h263_InitFrame(&pInfo->VideoSequence.rFrame, mbPerRow, mbPerCol);  if (status != H263_STATUS_OK)    return status;  /* not referenced frame (B-part of PB-frame or B-frame) */  status = h263_InitFrame(&pInfo->VideoSequence.nFrame, mbPerRow, mbPerCol);  if (status != H263_STATUS_OK)    return status;  /* not referenced frame (B-part of PB-frame or B-frame) */  status = h263_InitFrame(&pInfo->VideoSequence.bFrame, mbPerRow, mbPerCol);  if (status != H263_STATUS_OK)    return status;#ifdef _OMP_KARABAS  pInfo->number_threads = h263_GetNumOfThreads();  if (pInfo->number_threads > H263_NUM_THREADS)    pInfo->number_threads = H263_NUM_THREADS;  pInfo->pMBinfoMT = (h263_MacroBlockMT*)ippsMalloc_8u(mbPerRow * pInfo->number_threads * sizeof(h263_MacroBlockMT));  if(!pInfo->pMBinfoMT) return H263_STATUS_NO_MEM;#endif // _OMP_KARABAS  /* motion info */  pInfo->VideoSequence.MBinfo = (h263_MacroBlock*)ippsMalloc_8u(mbPerRow*mbPerCol*sizeof(h263_MacroBlock));  if (!pInfo->VideoSequence.MBinfo) return H263_STATUS_NO_MEM;  /* motion info for B-frames */  pInfo->VideoSequence.Bmv = (IppMotionVector*)ippsMalloc_8u(2*mbPerRow*sizeof(IppMotionVector));  if (!pInfo->VideoSequence.Bmv) return H263_STATUS_NO_MEM;  /* Advanced Intra Prediction info */  pInfo->VideoSequence.IntraPredBuff.block = (h263_IntraPredBlock*)ippsMalloc_8u((mbPerRow + 1)*6*sizeof(h263_IntraPredBlock));  if (!pInfo->VideoSequence.IntraPredBuff.block)    return H263_STATUS_NO_MEM;  {    h263_IntraPredBlock *mbCurr = pInfo->VideoSequence.IntraPredBuff.block;    h263_IntraPredBlock *mbA = mbCurr, *mbC = mbCurr + 6;    int                 j;    for (j = 0; j < mbPerRow; j ++) {        mbCurr[0].predA = &mbA[1];   mbCurr[0].predC = &mbC[2];        mbCurr[1].predA = &mbC[0];   mbCurr[1].predC = &mbC[3];        mbCurr[2].predA = &mbA[3];   mbCurr[2].predC = &mbC[0];        mbCurr[3].predA = &mbC[2];   mbCurr[3].predC = &mbC[1];        mbCurr[4].predA = &mbA[4];   mbCurr[4].predC = &mbC[4];        mbCurr[5].predA = &mbA[5];   mbCurr[5].predC = &mbC[5];        mbCurr += 6;  mbA += 6;  mbC += 6;    }  }/*  if (pInfo->VideoSequence.data_partitioned) {      pInfo->VideoSequence.DataPartBuff = (h263_DataPartMacroBlock*)ippsMalloc_8u(mbPerRow*mbPerCol*sizeof(h263_DataPartMacroBlock));      if (!pInfo->VideoSequence.DataPartBuff) return H263_STATUS_NO_MEM;  }*/    return H263_STATUS_OK;}/*//  Free memory allocated for h263_Info*/h263_Status h263_FreeVSeq(h263_Info* pInfo){  int i;  pInfo->VideoSequence.PicIndex = 0;  h263_FreeFrame(&pInfo->VideoSequence.cFrame);  h263_FreeFrame(&pInfo->VideoSequence.rFrame);  h263_FreeFrame(&pInfo->VideoSequence.nFrame);  h263_FreeFrame(&pInfo->VideoSequence.bFrame);#ifdef _OMP_KARABAS  ippsFree(pInfo->pMBinfoMT); pInfo->pMBinfoMT = NULL;#endif  ippsFree(pInfo->VideoSequence.MBinfo); pInfo->VideoSequence.MBinfo = NULL;  ippsFree(pInfo->VideoSequence.IntraPredBuff.block); pInfo->VideoSequence.IntraPredBuff.block = NULL;  ippsFree(pInfo->VideoSequence.Bmv); pInfo->VideoSequence.Bmv = NULL;  for (i = 0; i < H263_MAX_ENH_LAYERS; i++) {    if (pInfo->VideoSequence.enhLayers[i]) {      h263_FreeEnhancedLayer(pInfo->VideoSequence.enhLayers[i]);      pInfo->VideoSequence.enhLayers[i] = NULL;    }  }/*  if (pInfo->VideoSequence.data_partitioned) {      ippsFree(pInfo->VideoSequence.DataPartBuff); pInfo->VideoSequence.DataPartBuff = NULL;  }*/  return H263_STATUS_OK;}static void h263_ExpandFrameReplicate(Ipp8u *pSrcDstPlane, int frameWidth, int frameHeight, int expandPels, int step){    Ipp8u   *pDst1, *pDst2, *pSrc1, *pSrc2;    int     i, j;    Ipp32u  t1, t2;    pDst1 = pSrcDstPlane + step * expandPels;    pDst2 = pDst1 + frameWidth + expandPels;    if (expandPels == 8) {        for (i = 0; i < frameHeight; i ++) {            t1 = pDst1[8] + (pDst1[8] << 8);            t2 = pDst2[-1] + (pDst2[-1] << 8);            t1 = (t1 << 16) + t1;            t2 = (t2 << 16) + t2;            ((Ipp32u*)pDst1)[0] = t1;            ((Ipp32u*)pDst1)[1] = t1;            ((Ipp32u*)pDst2)[0] = t2;            ((Ipp32u*)pDst2)[1] = t2;            pDst1 += step;

⌨️ 快捷键说明

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