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

📄 usccodec.c

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
   tmp = ((unsigned int)out->bitrate)>>8;
   pDst[1] = (char)(tmp&0xFF);
   pDst[2] = (char)(out->bitrate&0xFF);
   pDst[3] = (char)out->frametype;
   tmp = ((unsigned short)out->nbytes)>>8;
   pDst[4] = (char)(tmp&0xFF);
   pDst[5] = (char)(out->nbytes&0xFF);
   return out->nbytes+FRAME_HEADER_SIZE;
}

/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCDecoderPreProcessFrame
//  Purpose:     Pre-process frame to decode.
//  Returns:     lenght of processed data from the input stream.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    pSrc      pointer to the input bitstream data.
//    pDst      pointer to the output PCM data.
//    in        pointer to the output USC_Bitstream structure for the frame.
//    out       pointer to the output USC_PCMStream structure for the frame.
*/
int USCDecoderPreProcessFrame(USCParams *uscPrms, char *pSrc, char *pDst,USC_Bitstream *in,USC_PCMStream *out)
{
   in->bitrate = (int)(((unsigned char)(pSrc[0])<<16)|((unsigned char)(pSrc[1])<<8)|(unsigned char)pSrc[2]);
   in->frametype = (int)((signed char)pSrc[3]);
   in->nbytes = (int)(((unsigned char)(pSrc[4])<<8)|(unsigned char)pSrc[5]);
   in->pBuffer = pSrc+FRAME_HEADER_SIZE;
   out->pBuffer = pDst;
   return FRAME_HEADER_SIZE;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCDecoderPostProcessFrame
//  Purpose:     Post-process of decoded frame.
//  Returns:     lenght of processed data from the input stream.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    pSrc      pointer to the input bitstream data.
//    pDst      pointer to the output PCM data.
//    in        pointer to the output USC_Bitstream structure for the frame.
//    out       pointer to the output USC_PCMStream structure for the frame.
*/
int USCDecoderPostProcessFrame(USCParams *uscPrms, char *pSrc, char *pDst,USC_Bitstream *in,USC_PCMStream *out)
{
   return out->nbytes;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecEncode
//  Purpose:     Encode pre-processed frame.
//  Returns:     lenght of processed data from the input stream.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    in        pointer to the input USC_Bitstream structure for the frame.
//    out       pointer to the output USC_PCMStream structure for the frame.
*/
int USCCodecEncode(USCParams *uscPrms, USC_PCMStream *in,USC_Bitstream *out, int channel)
{
   USC_Status status;
   status = uscPrms->USC_Fns->Encode (uscPrms->uCodec[channel].hUSCCodec, in, out);
   if(status!=USC_NoError) return -1;

   return in->nbytes;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecDecode
//  Purpose:     Decode pre-processed frame.
//  Returns:     lenght of processed data from the input stream.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    in        pointer to the input USC_PCMStream structure for the frame.
//    out       pointer to the output USC_Bitstream structure for the frame.
*/
int USCCodecDecode(USCParams *uscPrms, USC_Bitstream *in,USC_PCMStream *out, int channel)
{
   USC_Status status;
   status = uscPrms->USC_Fns->Decode (uscPrms->uCodec[channel].hUSCCodec, in, out);
   if(status!=USC_NoError) return -1;

   return in->nbytes;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecGetSize
//  Purpose:     Get output stream size.
//  Returns:     0 if success, -1 if fails.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
//    lenSrc    length of the input stream.
//    lenDst    pointer to the length of the output stream.
*/
int USCCodecGetSize(USCParams *uscPrms, int lenSrc, int *lenDst)
{
   USC_Status status;
   *lenDst = 0;
   status = uscPrms->USC_Fns->GetOutStreamSize(&uscPrms->pInfo.params, uscPrms->pInfo.params.modes.bitrate, lenSrc, lenDst);
   if(status!=USC_NoError) return -1;
   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecCorrectSize
//  Purpose:     Correct output stream size to include frame headers.
//  Returns:     0 if success.
//  Parameters:
//    uscPrms          pointer to the input USC codec parametres.
//    lenSrc           length of the input stream.
//    pSrcDstOutLen    pointer to the corrected length of the output stream.
*/
int USCCodecCorrectSize(USCParams *uscPrms, int lenSrc, int *pSrcDstOutLen)
{
   int nFrames;
   if(uscPrms->pInfo.params.direction==0) {
      nFrames = lenSrc/uscPrms->pInfo.framesize;
      /* Add block to hold the last compressed frame*/
      if (lenSrc % uscPrms->pInfo.framesize != 0) {
         nFrames++;
      }
      *pSrcDstOutLen += nFrames*FRAME_HEADER_SIZE;
   }

   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCCodecCorrectSize
//  Purpose:     Get termination condition to organize encode\decode loop.
//  Returns:     0 if success.
//  Parameters:
//    uscPrms          pointer to the input USC codec parametres.
//    pLowBound        pointer to the low bound of the data to process.
//    pSrcDstOutLen    pointer to the corrected length of the output stream.
*/
int USCCodecGetTerminationCondition(USCParams *uscPrms, int *pLowBound)
{
   if(uscPrms->pInfo.params.direction==0) {
      /* In encode mode than we only operate under the whole frame*/
      *pLowBound = uscPrms->pInfo.framesize-1;
   } else {
      /* In decode mode we estimate the whole encoded frame presents in bitstream*/
      *pLowBound = 0;
   }

   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCFree
//  Purpose:     Release resources of the USC codec.
//  Returns:     0 if success.
//  Parameters:
//    uscPrms   pointer to the input USC codec parametres.
*/
int USCFree(USCParams *uscPrms)
{
   int i,j;
   for(j=0;j<uscPrms->nChannels;j++) {
      for(i=0; i<uscPrms->nbanks;i++){
         ippsFree(uscPrms->uCodec[j].pBanks[i].pMem);
         uscPrms->uCodec[j].pBanks[i].pMem = NULL;
      }
      ippsFree(uscPrms->uCodec[j].pBanks);
      uscPrms->uCodec[j].pBanks = NULL;
   }

   return 0;
}
/* /////////////////////////////////////////////////////////////////////////////
//  Name:        USCGetFrameHeaderSize
//  Purpose:     Retrieve frame header size.
//  Returns:     frame header size.
//  Parameters:
*/
int USCGetFrameHeaderSize()
{
   return FRAME_HEADER_SIZE;
}

int USC_CvtToLiniar(USCParams *uscPrms, int PCMType, char **inputBuffer, int *pLen)
{
   if (PCMType > LINIAR_PCM) {
      unsigned char *cvt_buff = NULL;
      int lCvtLen = *pLen << 1;

      if(!(cvt_buff=ippsMalloc_8u(lCvtLen+uscPrms->pInfo.framesize))){
         return -1;
      }
      /* unpack to linear PCM if compound input */
      if (PCMType==ALAW_PCM) { /* A-Law input */
         ippsALawToLin_8u16s((unsigned char*)*inputBuffer, (short*)cvt_buff, *pLen);
      } else if (PCMType==MULAW_PCM){    /* Mu-Law input */
         ippsMuLawToLin_8u16s((unsigned char*)*inputBuffer, (short*)cvt_buff, *pLen);
      } else {
         return -1;
      }
      ippsFree(*inputBuffer);
      *inputBuffer = (char*)cvt_buff;
      *pLen = lCvtLen;
   }

   return 0;
}

int USC_CvtToLaw(USCParams *uscPrms, int PCMType, char *inputBuffer, int *pLen)
{
   if (PCMType > LINIAR_PCM) {
      int lCvtLen = *pLen >> 1;
      if (PCMType==ALAW_PCM) { /* A-Law output */
         ippsLinToALaw_16s8u((const short*) inputBuffer, (Ipp8u*) inputBuffer, lCvtLen);
      } else if (PCMType==MULAW_PCM) {   /* Mu-Law output */
         short *tmpBuffer=NULL;
         tmpBuffer = ippsMalloc_16s(lCvtLen);
         if(tmpBuffer==NULL) return -1;
         ippsCopy_16s((short*)inputBuffer,tmpBuffer,lCvtLen);
         ippsLinToMuLaw_16s8u(tmpBuffer, (Ipp8u*) inputBuffer, lCvtLen);
         ippsFree(tmpBuffer);
      } else {
         return -1;
      }
      *pLen = lCvtLen;
   }
   return 0;
}

⌨️ 快捷键说明

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