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

📄 stream.c

📁 Nokia H.264/AVC Encoder/Decoder Usage Manual
💻 C
📖 第 1 页 / 共 2 页
字号:
 *      mb                    Macroblock object *      skipFlag              0, MB is not skipped, 1, MB is skipped * * Function: *      Process the flag to indicate whether the MB is skipped or not.  *      The information will be sent in CAVLC.  *       * Returns: *      Number of bits generated. */int streamSendMbSkipFlag(void         *stream,                          macroblock_s *mb,                          int          skipFlag){    return vlcSendMbSkipFlag(stream, mb, skipFlag);}/* * streamSendMbType: * * Parameters: *      stream                bitbuffer for CAVLC *      mb                    Macroblock object *      picType               Picture type (intra/inter) *      cbpY                  Coded Block Pattern for luma *      cbpChromaDC           Coded Block Pattern for chroma DC *      cbpC                  Coded Block Pattern for chroma AC * * Function: *      Send mb_type in CAVLC *       * Returns: *      Number of bits generated. */static int streamSendMbType(void         *stream,                             macroblock_s *mb,                             int          picType,                            int          cbpY,                             int          cbpChromaDC,                             int          cbpC){  int mbType;  int i, bitsMBtype;  if (mb->type == MBK_INTRA)  {    mbType = streamGetMbTypeIntra      (mb->intraType, mb->intra16x16mode, cbpY, cbpChromaDC, cbpC);    mbType += (IS_SLICE_P(picType)) ? 5 : 0;  }  else    mbType = streamGetMbTypeInter(mb->interMode, mb->refIndices);    bitsMBtype = vlcuSendUVLC(stream, mbType);  if (mb->type == MBK_INTER && mb->interMode == MOT_8x8)  {      // need to send sub_mb_type      for (i = 0; i < 4; i++)        bitsMBtype += vlcuSendUVLC(stream, mb->interSubMbModes[i]);  }  return bitsMBtype;}/* * streamSendCbp: * * Parameters: *      stream                bitbuffer for CAVLC *      mb                    Macroblock object * * Function: *      Code coded block pattern in CAVLC *       * Returns: *      - */static int streamSendCbp(void         *stream,                         macroblock_s *mb){  int cbpY, cbpC;  cbpY = vlcuGetLuma8x8cbp(mb->cbpY);  cbpC = vlcuGetChromaNC(mb->cbpChromaDC, mb->cbpC);  return vlcSendCbp(stream, mb->type, (cbpC << 4) | cbpY);}/* * streamSendMbHeader: * * Parameters: *      stream                bitbuffer for CAVLC *      mb                    Macroblock object *      nRefFrames            Number of reference frames in use *      picType               Picture type (intra/inter) *      stat                  Statistics * * Function: *      Code macroblock header using CAVLC *       * Returns: *      - */void streamSendMbHeader(void         *stream,                         macroblock_s *mb,                         int          nRefFrames,                         int          picType,                        statSlice_s  *stat){  int bitsHdr, bitsMBtype, bitsPred, bitsVec;  bitsHdr  = 0;  bitsPred = 0;  bitsVec  = 0;  /* Send Macroblock type */  bitsMBtype = streamSendMbType(stream, mb, picType,                                mb->cbpY, mb->cbpChromaDC, mb->cbpC);  /* Send 4x4 intra prediction modes */  if (mb->type == MBK_INTRA)  {    if (mb->intraType == MBK_INTRA_TYPE1)       bitsPred += vlcSendIntraPred(stream, mb->ipTab);        /* Send 8x8 chroma intra prediction mode */      bitsPred += vlcuSendUVLC(stream, mb->intraModeChroma);  }  else  {    /* Send reference frame number and motion vectors */     bitsVec = vlcSendMotVecs(stream, mb->interMode, nRefFrames,         mb->diffVecs, mb->numVecs,  mb->refIndices);  }  /* Send coded block pattern */  if (!(mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2))     stat->bitsCBP += streamSendCbp(stream, mb);  /* Send delta QP */  if ((mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2) ||     (mb->cbpY | mb->cbpChromaDC | mb->cbpC) != 0)  {    CALCULATE_DELTA_QP(mb->deltaQp, mb->qp, mb->prevQp);    stat->bitsHdr += vlcuSendUVLC(stream, vlcuMapSigned(mb->deltaQp));    mb->prevQp = mb->qp;  }  else  {    mb->deltaQp = 0;    mb->qp = mb->prevQp;  }  stat->bitsMBtype += bitsMBtype;  stat->bitsPred   += bitsPred;  stat->bitsVec    += bitsVec;  // mb->headerBits should be initialized in vlcSendSkipCount  mb->headerBits += bitsMBtype + bitsPred + bitsVec;}/* * streamSendLumaCoeffs: * * Parameters: *      stream                bitbuffer for CAVLC  *      mb                    Macroblock object *      stat                  Statistics *  * Function: *      Code all luma coefficients within a macroblock in CAVLC  *       * Returns: *      Number of bits used. */int streamSendLumaCoeffs(void         *stream,                          macroblock_s *mb,                          statSlice_s  *stat){  int i, j;  int bits, totalBits;  int cbpY;  totalBits = 0;  if (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2)   {    int numCoefs;    // send DC coefficients    bits = streamSend4x4Blk(stream, mb, 1, COMP_LUMA, 0, 0,      mb->dcCoefY, BLK_CAT_Y_I16x16_DC, & numCoefs);    /* Luma DC coefficients are sent for 16x16 intra */    totalBits += bits;    stat->bitsCoefLumaDC += bits;  }  // most blocks are zero anyway, clear all of them up-front   // instead of clearing them selectively  for (j = 0; j < 4; j ++)    for (i = 0; i < 4; i ++)      mb->current[j][i].numLumaCoefs = 0;  cbpY = mb->cbpY;  if (cbpY != 0)   {    int blk8x8, blkIdx;    int blkCategory;    bits   = 0;    blkCategory = BLK_CAT_Y;    if (mb->type == MBK_INTRA && mb->intraType == MBK_INTRA_TYPE2) {      /* In 16x16 INTRA, if there is even one nonzero block in MB, */      /* all blocks will be sent (even if it means sending EOBs)   */      cbpY = 0xFFFF;      blkCategory = BLK_CAT_Y_I16x16_AC;    }    for (blk8x8 = 0; blk8x8 < 16; blk8x8 += 4)    {      if ((cbpY & 0x000F) == 0)        cbpY >>= 4;      else      {        for (blkIdx = blk8x8; blkIdx < (blk8x8 + 4); blkIdx ++)        {          int numCoefs;          int blkX, blkY;          blkX = blkRasterOrder[blkIdx] & 3;          blkY = blkRasterOrder[blkIdx] >> 2;          bits += streamSend4x4Blk(stream, mb, cbpY & 1, COMP_LUMA,             blkX, blkY, mb->coefY[blkIdx], blkCategory, & numCoefs);          mb->current[blkY][blkX].numLumaCoefs = (int8) numCoefs;          cbpY >>= 1;        }      }    }    totalBits += bits;    stat->bitsCoefLuma += bits;  }  return totalBits;}/* * streamSendChromaCoeffs: * * Parameters: *      stream                bitbuffer for CAVLC *      mb                    Macroblock object *      stat                  Statistics *  * Function: *      Code all chroma coefficients within a macroblock in CAVLC *       * Returns: *      Number of bits used. */int streamSendChromaCoeffs(void         *stream,                            macroblock_s *mb,                            statSlice_s  *stat){  int dcBits, acBits, cbpC;  dcBits = 0;  acBits = 0;  if ((mb->cbpChromaDC | mb->cbpC) != 0)  {    // although mb->cbpC == 1 && mb->cbpChromaDC == 0 is possible,    // and it seems to be it is not necessary to send dc at all,    // but this is not supported by syntax    dcBits  = streamSend2x2ChromaDC(stream, & mb->dcCoefC[0][0][0]);    dcBits += streamSend2x2ChromaDC(stream, & mb->dcCoefC[1][0][0]);  }  * ((int *) & mb->mbThis->numChromaCoefs[0][0][0]) = 0;  * ((int *) & mb->mbThis->numChromaCoefs[1][0][0]) = 0;  cbpC = mb->cbpC;  if (cbpC != 0)  {    int comp;    int i, j;    int numCoefs;    for (comp = 0; comp < 2; comp++) {      for (j = 0; j < 2; j++) {        for (i = 0; i < 2; i++) {          acBits += streamSend4x4Blk(stream, mb, cbpC & 1,            comp + 1, i, j,             mb->coefC[comp][j][i], BLK_CAT_C_AC, & numCoefs);          // store numCoefs in the buffer for future numCoefs prediction          mb->mbThis->numChromaCoefs[comp][j][i] = (int8) numCoefs;          cbpC >>= 1;        }      }    }  }  stat->bitsCoefChromaDC += dcBits;  stat->bitsCoefChroma   += acBits;  return (dcBits + acBits);}

⌨️ 快捷键说明

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