📄 h261_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 ippVideoEncoderH261 (read param, init, constructor, destructor)// Contents:// ~ippVideoEncoderH261// ippVideoEncoderH261(h261_Param)// Close// ReadParam// Init//*/#include "h261_enc.hpp"ippVideoEncoderH261::ippVideoEncoderH261(h261_Param *par){ Init(par);}ippVideoEncoderH261::~ippVideoEncoderH261(){ Close();}void ippVideoEncoderH261::Close(){ if (mIsInit) { // free if (MBinfo) delete [] MBinfo; if (mbsAlloc && cBS.mBuffer) delete [] cBS.mBuffer; if (mMEfastSAD) ippsFree(mMEfastSAD); for (int i = 0; i < mPlanes; i ++) { if (mPtrYUV) if (mPtrYUV[i]) ippsFree(mPtrYUV[i]); } if (mPtrYUV) delete [] mPtrYUV; } mIsInit = false; mError = H261_ERROR_NOTINIT;}int ippVideoEncoderH261::Init(h261_Param *par){ int i; mError = H261_ERROR_PARAM; // check parameters correctness if (!((par->Width == 176 && par->Height == 144) || (par->Width == 352 && par->Height == 288))) { ErrorMessage(__VM_STRING("Size of picture is incorrect")); return H261_ERROR_PARAM; } if (par->quantIFrame < 1 || par->quantIFrame > 31) { ErrorMessage(__VM_STRING("quantIFrame must be between 1 and 31")); return H261_ERROR_PARAM; } if (par->quantPFrame < 1 || par->quantPFrame > 31) { ErrorMessage(__VM_STRING("quantPFrame must be between 1 and 31")); return H261_ERROR_PARAM; } if (par->IFramedist < 1) { ErrorMessage(__VM_STRING("IFramedist must be positive")); return H261_ERROR_PARAM; } if (par->PFramesearchWidth < 1 || par->PFramesearchWidth > 15) { ErrorMessage(__VM_STRING("PFramesearchWidth must be between 1 and 15")); return H261_ERROR_PARAM; } if (par->PFramesearchHeight < 1 || par->PFramesearchHeight > 15) { ErrorMessage(__VM_STRING("PFramesearchHeight must be between 1 and 15")); return H261_ERROR_PARAM; } Close(); mQuantIFrame = par->quantIFrame; mQuantPFrame = par->quantPFrame; mIFramedist = par->IFramedist; mMEalgorithm = par->MEalgorithm; mCalcPSNR = par->calcPSNR; mPSNR_Y = mPSNR_U = mPSNR_V = 0; mFrameCount = 0; // setup H.261 headers variables memset(&Frame, 0, sizeof(Frame)); mPFramesearchHor = par->PFramesearchWidth; mPFramesearchVer = par->PFramesearchHeight; Frame.split_screen_indicator = 0; Frame.document_camera_indicator = 0; Frame.freeze_picture_release = 0; Frame.still_image_mode = 1; if (par->Width == 176 && par->Height == 144) { Frame.source_format = 0; Frame.num_gobs_in_frame = 3; } else { Frame.source_format = 1; Frame.num_gobs_in_frame = 12; } mPlanes = 2; mSourceWidth = par->Width; mSourceHeight = par->Height; mNumMacroBlockPerFrame = Frame.num_gobs_in_frame * 33; mStepLuma = ((mSourceWidth + 15) >> 4) * 16; mLumaPlaneSize = mStepLuma * ((mSourceHeight + 15) >> 4) * 16; mStepChroma = ((mSourceWidth + 15) >> 4) * 8; mChromaPlaneSize = mStepChroma * ((mSourceHeight + 15) >> 4) * 8; mIsInit = true; // alloc buffers mPtrYUV = new Ipp8u* [mPlanes]; mPtrY = new Ipp8u* [mPlanes]; mPtrU = new Ipp8u* [mPlanes]; mPtrV = new Ipp8u* [mPlanes]; for (i = 0; i < mPlanes; i ++) { if (mPtrYUV) mPtrYUV[i] = ippsMalloc_8u(mLumaPlaneSize + 2*mChromaPlaneSize); if (!mPtrYUV[i]) { Close(); mError = H261_ERROR_NOMEM; ErrorMessage(__VM_STRING("Not enough memory")); return mError; } mPtrY[i] = mPtrYUV[i]; mPtrU[i] = mPtrYUV[i] + mLumaPlaneSize; mPtrV[i] = mPtrYUV[i] + mLumaPlaneSize + mChromaPlaneSize; } // init bitstream buffer if (par->bsBuffer && (par->bsBuffSize > 0)) { cBS.mBuffer = par->bsBuffer; cBS.mBuffSize = par->bsBuffSize; mbsAlloc = false; } else { cBS.mBuffSize = par->Width * par->Height >> 1; cBS.mBuffer = new Ipp8u[cBS.mBuffSize]; mbsAlloc = true; } cBS.mPtr = cBS.mBuffer; MBinfo = new h261_MacroBlock[mNumMacroBlockPerFrame]; mMEfastSADsize = (mPFramesearchHor * 2 + 1) * (mPFramesearchVer * 2 + 1); mMEfastSAD = ippsMalloc_32s(mMEfastSADsize); // setup thresholds for ME mMEthrSAD16x16 = par->quantPFrame >= 6 ? 256 : (4 << par->quantPFrame); mMEthrSAD8x8 = mMEthrSAD16x16 >> 2; // setup frames mCurrPtrY = mPtrY[0]; mCurrPtrU = mPtrU[0]; mCurrPtrV = mPtrV[0]; mForwPtrY = mPtrY[1]; mForwPtrU = mPtrU[1]; mForwPtrV = mPtrV[1]; mError = H261_ERROR_NOERR; return H261_ERROR_NOERR;}void ippVideoEncoderH261::ErrorMessage(vm_char *msg){ vm_debug_trace(4, __VM_STRING("H.261 encoder error: ")); vm_debug_trace(4, msg); vm_debug_trace(4, __VM_STRING("\n"));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -