📄 h263_enc_misc.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) 2005 Intel Corporation. All Rights Reserved.//// Description: class ippVideoEncoderH263// Contents:// ~ippVideoEncoderH263// ippVideoEncoderH263(h263_Param)// Close// Init// ExpandFrame//*/#include "h263_enc.hpp"ippVideoEncoderH263::ippVideoEncoderH263(h263_Param *par){ Init(par);}ippVideoEncoderH263::~ippVideoEncoderH263(){ Close();}void ippVideoEncoderH263::Close(){ if (mIsInit) { // free if (MBinfo) delete [] MBinfo; if (mbsAlloc && cBS.mBuffer) ippsFree(cBS.mBuffer); if (mBuffer_1) ippsFree(mBuffer_1); if (mBuffer_2) ippsFree(mBuffer_2); if (mMEfastSAD) ippsFree(mMEfastSAD); if (mMBpos) ippsFree(mMBpos); if (mMBquant) ippsFree(mMBquant); if (mMBpredMV) ippsFree(mMBpredMV); for (int i = 0; i < mPlanes; i ++) { if (mPtreY) if (mPtreY[i]) ippsFree(mPtreY[i]); if (mPtreU) if (mPtreU[i]) ippsFree(mPtreU[i]); if (mPtreV) if (mPtreV[i]) ippsFree(mPtreV[i]); } if (mPtreY) delete [] mPtreY; if (mPtreU) delete [] mPtreU; if (mPtreV) delete [] mPtreV; if (mPtrY) delete [] mPtrY; if (mPtrU) delete [] mPtrU; if (mPtrV) delete [] mPtrV; } mIsInit = false;}int ippVideoEncoderH263::Init(h263_Param *par){ int i, j; // check parameters correctness if (par->Width < 1 || par->Width > 8191) { ErrorMessage(VM_STRING("Width must be between 1 and 8191")); return H263_STS_ERR_PARAM; } if (par->Width & 1) { ErrorMessage(VM_STRING("Width must be a even")); return H263_STS_ERR_PARAM; } if (par->Height < 1 || par->Height > 8191) { ErrorMessage(VM_STRING("Height must be between 1 and 8191")); return H263_STS_ERR_PARAM; } if (par->Height & 1) { ErrorMessage(VM_STRING("Height must be a even")); return H263_STS_ERR_PARAM; } if (par->quantIVOP < 1 || par->quantIVOP > 31) { ErrorMessage(VM_STRING("quantIVOP must be between 1 and 31")); return H263_STS_ERR_PARAM; } if (par->quantPVOP < 1 || par->quantPVOP > 31) { ErrorMessage(VM_STRING("quantPVOP must be between 1 and 31")); return H263_STS_ERR_PARAM; } if (par->quantBVOP < 1 || par->quantBVOP > 31) { ErrorMessage(VM_STRING("quantBVOP must be between 1 and 31")); return H263_STS_ERR_PARAM; } if (par->IVOPdist < 1) { ErrorMessage(VM_STRING("IVOPdist must be positive")); return H263_STS_ERR_PARAM; } if (par->BitRate <= 0) { ErrorMessage(VM_STRING("BitRate must be positive")); return H263_STS_ERR_PARAM; } if (par->SceneChangeThreshold < 0 || par->SceneChangeThreshold > 100) { ErrorMessage(VM_STRING("SceneChangeThreshold must be between 0 and 100")); return H263_STS_ERR_PARAM; } if (1) { // ??? tmp if (par->TimeResolution != 30000) { ErrorMessage(VM_STRING("TimeResolution must equal 30000 in the current implementation")); // ??? return H263_STS_ERR_PARAM; } if ((par->TimeIncrement % 1001) || par->TimeIncrement < 1001 || par->TimeIncrement > 256 * 1001) { ErrorMessage(VM_STRING("TimeIncrement must equal i*1001 (i=1,256) in the current implementation")); // ??? return H263_STS_ERR_PARAM; } } else { if (par->TimeResolution < 1) { ErrorMessage(VM_STRING("TimeResolution must be positive")); return H263_STS_ERR_PARAM; } if (par->TimeIncrement < 1) { ErrorMessage(VM_STRING("TimeIncrement must be positive")); return H263_STS_ERR_PARAM; } if (par->PVOPdist < 1) { ErrorMessage(VM_STRING("PVOPdist must be positive")); return H263_STS_ERR_PARAM; } if (par->IVOPdist % par->PVOPdist != 0) { ErrorMessage(VM_STRING("IVOPdist must be an integer multiple of PVOPdist")); return H263_STS_ERR_PARAM; } if (par->PVOPsearchWidth < 1 || par->PVOPsearchWidth > IPP_MIN(1023, par->Width)) { ErrorMessage(VM_STRING("PVOPsearchWidth must be between 1 and MIN(1023, Width)")); return H263_STS_ERR_PARAM; } if (par->PVOPsearchHeight < 1 || par->PVOPsearchHeight > IPP_MIN(1023, par->Height)) { ErrorMessage(VM_STRING("PVOPsearchWidth must be between 1 and MIN(1023, Height)")); return H263_STS_ERR_PARAM; }/* if (par->BVOPsearchWidthForw < 1 || par->BVOPsearchWidthForw > IPP_MIN(1023, par->Width)) { ErrorMessage(VM_STRING("BVOPsearchWidthForw must be between 1 and MIN(1023, Width)")); return H263_STS_ERR_PARAM; } if (par->BVOPsearchHeightForw < 1 || par->BVOPsearchHeightForw > IPP_MIN(1023, par->Height)) { ErrorMessage(VM_STRING("BVOPsearchWidthForw must be between 1 and MIN(1023, Height)")); return H263_STS_ERR_PARAM; } if (par->BVOPsearchWidthBack < 1 || par->BVOPsearchWidthBack > IPP_MIN(1023, par->Width)) { ErrorMessage(VM_STRING("BVOPsearchWidthBack must be between 1 and MIN(1023, Width)")); return H263_STS_ERR_PARAM; } if (par->BVOPsearchHeightBack < 1 || par->BVOPsearchHeightBack > IPP_MIN(1023, par->Height)) { ErrorMessage(VM_STRING("BVOPsearchWidthBack must be between 1 and MIN(1023, Height)")); return H263_STS_ERR_PARAM; }*/ } Close(); mNumOfFrames = par->NumOfFrames;// mNumOfFrames = -1; ??? mRateControl = par->RateControl; if (mRateControl) { double ppb = (double)par->Width * par->Height * par->TimeResolution / ((double)par->TimeIncrement * (par->BitRate << 10)); mBitRate = par->BitRate; mQuantIVOP = (int)(1.2 * ppb); mQuantPVOP = (int)(1.5 * ppb); mQuantBVOP = (int)(1.8 * ppb); h263_Clip(mQuantIVOP, 1, 31); h263_Clip(mQuantPVOP, 1, 31); h263_Clip(mQuantBVOP, 1, 31); } else { mQuantIVOP = par->quantIVOP; mQuantPVOP = par->quantPVOP; mQuantBVOP = par->quantBVOP; } mBitsPerFrameRC = (Ipp32s)((double)(mBitRate << 10) * (double)par->TimeIncrement / (double)par->TimeResolution); mBitsDesiredRC = 0; mBitsEncoded = 0; mIVOPdist = par->IVOPdist; mPVOPdist = par->PVOPdist; mBVOPdist = mPVOPdist - 1; mMEalgorithm = par->MEalgorithm; mMEaccuracy = par->MEaccuracy; mMEfastHP = 0; // using fast algorithm for halfpel MVs (faster but with lower PSNR and compression) mCalcPSNR = par->calcPSNR; mFrameCount = 0; mLastIVOP = -mIVOPdist; memset(&VOL, 0, sizeof(VOL)); memset(&VOP, 0, sizeof(VOP)); VOL.aspect_ratio_info = H263_ASPECT_RATIO_1_1; VOL.vop_time_increment_resolution = par->TimeResolution; VOL.fixed_vop_rate = (par->TimeResolution > par->TimeIncrement) ? 1 : 0; VOL.fixed_vop_time_increment = par->TimeIncrement; VOL.vop_time_increment_resolution_bits = 1; i = VOL.vop_time_increment_resolution - 1; while (i >> VOL.vop_time_increment_resolution_bits) VOL.vop_time_increment_resolution_bits ++; VOP.vop_width = par->Width; VOP.vop_height = par->Height; mVideoPacketLength = par->VideoPacketLength; VOP.advIntra = par->advIntra; VOP.UMV = par->UMV; VOP.advPred = par->advPred;// VOP.deblockFilt = par->deblockFilt; VOP.deblockFilt = 0;// VOL.newpred_enable = 0; //f VOL.requested_upstream_message_type; //f VOL.newpred_segment_type;// VOL.reduced_resolution_vop_enable = 0;// VOL.scalability = 0; //f VOL.ScalabilityParameters; VOP.vop_time_increment = 0; mInterlacedME = 1; // in this version only frame prediction implemented VOP.vop_rounding_type = 0; mPVOPsearchHor = par->PVOPsearchWidth; mPVOPsearchVer = par->PVOPsearchHeight; // calc vop_fcode_forward for PVOPs i = IPP_MAX(mPVOPsearchHor, mPVOPsearchVer);// j = i << 1;// mPVOPfcodeForw = 1;// while (j > ((16 << mPVOPfcodeForw) - 1))// mPVOPfcodeForw ++; { mPVOPdist = 1; mBVOPdist = 0; VOL.data_partitioned = 0;// VOL.scalability = 0; VOP.vop_rounding_type = 0; VOP.split_screen_indicator = 0; VOP.document_camera_indicator = 0; VOP.full_picture_freeze_release = 0; if (par->Width == 128 && par->Height == 96) { VOP.source_format = 1; VOP.num_gobs_in_vop = 6; VOP.num_macroblocks_in_gob = 8; } else if (par->Width == 176 && par->Height == 144) { VOP.source_format = 2; VOP.num_gobs_in_vop = 9; VOP.num_macroblocks_in_gob = 11; } else if (par->Width == 352 && par->Height == 288) { VOP.source_format = 3; VOP.num_gobs_in_vop = 18; VOP.num_macroblocks_in_gob = 22; } else if (par->Width == 704 && par->Height == 576) { VOP.source_format = 4; VOP.num_gobs_in_vop = 18; VOP.num_macroblocks_in_gob = 88; } else if (par->Width == 1408 && par->Height == 1152) { VOP.source_format = 5; VOP.num_gobs_in_vop = 18; VOP.num_macroblocks_in_gob = 352; } else { ErrorMessage(VM_STRING("Currently unsupported picture size")); return H263_STS_ERR_PARAM; } VOP.temporal_reference_increment = VOL.fixed_vop_time_increment / 1001; if (mMEaccuracy > 2) mMEaccuracy = 2;// mBVOPsearchHorForw = mBVOPsearchVerForw = mBVOPsearchHorBack = mBVOPsearchVerBack = 0; mME4mv = 0; }#if 0 else { mBVOPsearchHorForw = par->BVOPsearchWidthForw; mBVOPsearchVerForw = par->BVOPsearchHeightForw; mBVOPsearchHorBack = par->BVOPsearchWidthBack; mBVOPsearchVerBack = par->BVOPsearchHeightBack; // calc vop_fcode_forward for BVOPs i = IPP_MAX(mBVOPsearchHorForw, mBVOPsearchVerForw); j = i << 1; mBVOPfcodeForw = 1; while (j > ((16 << mBVOPfcodeForw) - 1)) mBVOPfcodeForw ++; // calc vop_fcode_backward for BVOPs i = IPP_MAX(mBVOPsearchHorBack, mBVOPsearchHorBack); j = i << 1; mBVOPfcodeBack = 1; while (j > ((16 << mBVOPfcodeBack) - 1))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -