📄 put.cpp
字号:
Ipp16s *block, Ipp32s *dc_dct_pred, IppVCHuffmanSpec_32u* DC_Tbl, IppVCHuffmanSpec_32s* AC_Tbl, Ipp32s *scan, Ipp32s EOBLen, Ipp32s EOBCode, Ipp32s count){ Ipp32s n, m, dct_diff, run, signed_level; Ipp32s absval, size1; dct_diff = block[0] - *dc_dct_pred; *dc_dct_pred = block[0]; /* generate variable length code for DC coefficient (7.2.1)*/ if(dct_diff == 0) { ippiPutBits(*pBitStream, *pOffset, DC_Tbl[0].code, DC_Tbl[0].len ) } else { m = dct_diff >> 31; absval = (dct_diff + m) ^ m; for (size1=1; absval >>= 1; size1++); /* generate VLC for dct_dc_size (Table B-12 or B-13)*/ /* append fixed length code (dc_dct_differential)*/ absval = ((DC_Tbl[size1].code - m) << size1) + (dct_diff + m); n = DC_Tbl[size1].len + size1; ippiPutBits(*pBitStream, *pOffset, absval, n ) } run = 0; m = 0; for(n=1; m < count ; n++) { signed_level = block[scan[n]]; if( signed_level ) { mp2PutAC(pBitStream, pOffset, run, signed_level, AC_Tbl); m++; run = 0; } else run++; } ippiPutBits(*pBitStream, *pOffset, EOBCode, EOBLen ) return ippStsOk;}static IppStatus mp2PutNonIntraBlock(Ipp32u **pBitStream, Ipp32s *pOffset, Ipp16s *block, IppVCHuffmanSpec_32s *AC_Tbl, Ipp32s *scan, Ipp32s EOBLen, Ipp32s EOBCode, Ipp32s count){ Ipp32s n, m, run, signed_level; run = 0; m = 0; signed_level = block[0]; if( signed_level) { if (signed_level == 1 || signed_level == -1) { //int tmp = (signed_level == 1) ? 2 : 3; int tmp = 2 + (signed_level==-1); ippiPutBits(*pBitStream, *pOffset, tmp, 2 ) } else { mp2PutAC(pBitStream, pOffset, 0, signed_level, AC_Tbl); } m++; } else run++; for(n=1; m < count ; n++) { signed_level = block[scan[n]]; if( signed_level ) { mp2PutAC(pBitStream, pOffset, run, signed_level, AC_Tbl); m++; run = 0; } else run++; } ippiPutBits(*pBitStream, *pOffset, EOBCode, EOBLen )// End of Block return ippStsOk;}void ippMPEG2VideoEncoder::PutIntraBlock(short* block, int* dc_dct_pred, const IppVCHuffmanSpec_32u* DC_Tbl,int count, int numTh){ int EOBLen,EOBCode; IppVCHuffmanSpec_32s* AC_Tbl; int *scan = curr_scan ? AlternateScan : ZigZagScan; CHECK_BUFFER; if (curr_intra_vlc_format) { EOBCode = 6; EOBLen = 4; // (Table B-15) AC_Tbl = vlcTableB15; } else { EOBCode = 2; EOBLen = 2; // (Table B-14) AC_Tbl = vlcTableB5c_e; } mp2PutIntraBlock(&threadSpec[numTh].current_pointer, &threadSpec[numTh].bit_offset, block, dc_dct_pred, (IppVCHuffmanSpec_32u*)DC_Tbl, AC_Tbl, scan, EOBLen, EOBCode, count); CHECK_BUFFER;}void ippMPEG2VideoEncoder::PutNonIntraBlock(short* block, int count, int numTh){ int *scan = curr_scan ? AlternateScan : ZigZagScan; CHECK_BUFFER; mp2PutNonIntraBlock(&threadSpec[numTh].current_pointer, &threadSpec[numTh].bit_offset, block, vlcTableB5c_e, scan, 2, 2, count); CHECK_BUFFER;}void ippMPEG2VideoEncoder::PutIntraMacroBlock(int numTh, int k, Ipp8u *BlockSrc[3], Ipp8u *BlockRef[3], Ipp32s *dc_dct_pred, int PictureType){ IppiSize roi = {8, 8}; Ipp16s *pMBlock = threadSpec[numTh].pMBlock_; Ipp32s Count[12]; Ipp32s nYPitch = Y_pitch; Ipp32s nUPitch = U_pitch; Ipp32s nVPitch = V_pitch; Ipp32s src_stride[3]; Ipp32s ref_stride[3]; Ipp32s *block_offset; Ipp32s *block_offset_ref; int intra_dc_shift = 3 - encodeInfo.intra_dc_precision; int half_intra_dc = (1 << intra_dc_shift) >> 1; if (PictureType == I_TYPE) { PUT_BITS_TH(1, 1); } else { PUT_BITS_TH(3, 5); } if (!curr_frame_dct) { PUT_BITS_TH(pMBInfo[k].dct_type, 1); } if (pMBInfo[k].dct_type == DCT_FRAME) { block_offset = block_offset_frm; src_stride[0] = nYPitch; src_stride[1] = nUPitch; src_stride[2] = nVPitch; block_offset_ref = block_offset_frm_ref; ref_stride[0] = YFrameHSize; ref_stride[1] = UVFrameHSize; ref_stride[2] = UVFrameHSize; } else { block_offset = block_offset_fld; src_stride[0] = 2*nYPitch; src_stride[1] = nUPitch << chroma_fld_flag; src_stride[2] = nVPitch << chroma_fld_flag; block_offset_ref = block_offset_fld_ref; ref_stride[0] = 2*YFrameHSize; ref_stride[1] = UVFrameHSize << chroma_fld_flag; ref_stride[2] = UVFrameHSize << chroma_fld_flag; } Ipp32s cbp = 0; for (int blk = 0; blk < block_count; blk++) { int cc = color_index[blk]; ippiDCT8x8Fwd_8u16s_C1R(BlockSrc[cc] + block_offset[blk], src_stride[cc], pMBlock); if (pMBlock[0] < 0) { pMBlock[0] = -((-pMBlock[0] + half_intra_dc) >> intra_dc_shift); } else { pMBlock[0] = (pMBlock[0] + half_intra_dc) >> intra_dc_shift; } ippiQuantIntra_MPEG2_16s_C1I(pMBlock, quantiser_scale_value, InvIntraQMatrix, &Count[blk]); PutIntraBlock(pMBlock, &dc_dct_pred[cc], DC_Tbl[cc], Count[blk], numTh); if (PictureType != B_TYPE && !onlyIFrames) { pMBlock[0] <<= intra_dc_shift; if(Count[blk]) { ippiQuantInvIntra_MPEG2_16s_C1I(pMBlock, quantiser_scale_value, IntraQMatrix); ippiDCT8x8Inv_16s8u_C1R (pMBlock, BlockRef[cc] + block_offset_ref[blk], ref_stride[cc]); } else { ippiSet_8u_C1R((Ipp8u)(pMBlock[0]/8), BlockRef[cc] + block_offset_ref[blk], ref_stride[cc], roi); } } pMBlock += 64; cbp = (cbp << 1); if (Count[blk] != 0) cbp++; } pMBInfo[k].cbp = cbp;}void ippMPEG2VideoEncoder::PutMV_FRAME(int numTh, int k, IppMotionVector2 *vector, int motion_type){ int hor_f_code, ver_f_code; int BW = 0; if (motion_type == MB_BACKWARD) { hor_f_code = back_hor_f_code; ver_f_code = back_vert_f_code; BW = 1; } else { hor_f_code = forw_hor_f_code; ver_f_code = forw_vert_f_code; } if (picture_structure != FRAME_PICTURE) { int BW = 0; PUT_BITS_TH(pMBInfo[k].mv_field_sel[0][BW], 1); } if (motion_type) { PutMV( vector->x - threadSpec[numTh].PMV[0][BW].x, hor_f_code, numTh); PutMV( vector->y - threadSpec[numTh].PMV[0][BW].y, ver_f_code, numTh); } threadSpec[numTh].PMV[0][BW].x = threadSpec[numTh].PMV[1][BW].x = vector->x; threadSpec[numTh].PMV[0][BW].y = threadSpec[numTh].PMV[1][BW].y = vector->y;}void ippMPEG2VideoEncoder::PutMV_FIELD(int numTh, int k, IppMotionVector2 *vector, IppMotionVector2 *vector2, int motion_type){ int hor_f_code, ver_f_code; int BW = 0; int mv_shift = (picture_structure == FRAME_PICTURE) ? 1 : 0; if (motion_type == MB_BACKWARD) { hor_f_code = back_hor_f_code; ver_f_code = back_vert_f_code; BW = 1; } else { hor_f_code = forw_hor_f_code; ver_f_code = forw_vert_f_code; } /*if (motion_type)*/ { PUT_BITS_TH(pMBInfo[k].mv_field_sel[0][BW],1); PutMV( vector->x - threadSpec[numTh].PMV[0][BW].x, hor_f_code, numTh); PutMV( vector->y - (threadSpec[numTh].PMV[0][BW].y >> mv_shift), ver_f_code, numTh); PUT_BITS_TH(pMBInfo[k].mv_field_sel[1][BW],1); PutMV( vector2->x - threadSpec[numTh].PMV[1][BW].x, hor_f_code, numTh); PutMV( vector2->y - (threadSpec[numTh].PMV[1][BW].y >> mv_shift), ver_f_code, numTh); } threadSpec[numTh].PMV[0][BW].x = vector->x; threadSpec[numTh].PMV[0][BW].y = vector->y << mv_shift; threadSpec[numTh].PMV[1][BW].x = vector2->x; threadSpec[numTh].PMV[1][BW].y = vector2->y << mv_shift;}void ippMPEG2VideoEncoder::PrepareBuffers(){ int i; thread_buffer_size = (out_buffer_size/m_numThreads) &~ 3; for (i = 0; i < m_numThreads; i++) { threadSpec[i].bit_offset = 32; threadSpec[i].start_pointer = out_pointer + i*thread_buffer_size; threadSpec[i].current_pointer = (Ipp32u*)threadSpec[i].start_pointer; *(Ipp32u*)threadSpec[i].start_pointer = 0; }}void ippMPEG2VideoEncoder::flushBuffer(){ int i, size; Ipp8u *p; int fail = 0; p = out_pointer; // move encoded data from all threads to first for (i = 0; i < m_numThreads; i++) { // align to byte border (not word) FLUSH_BITSTREAM(threadSpec[i].current_pointer, threadSpec[i].bit_offset); size = (Ipp8u*)threadSpec[i].current_pointer - (Ipp8u*)threadSpec[i].start_pointer - (threadSpec[i].bit_offset>>3); if (size > thread_buffer_size) { fail = 1; } if (i) { memcpy(p, threadSpec[i].start_pointer, size); } p += size; }#ifdef MPEG2_DEBUG_CODE if (fail) { for (i = 0; i < m_numThreads; i++) { size = (Ipp8u*)threadSpec[i].current_pointer - (Ipp8u*)threadSpec[i].start_pointer - (threadSpec[i].bit_offset>>3); printf("%d: %d (%d)\n", i, size, thread_buffer_size); } exit(1); }#endif // summary size size = p - out_pointer; out_pointer += size; out_buffer_size -= size; mEncodedSize += size;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -