📄 sesenc.cpp
字号:
/*************************************************************************
This software module was originally developed by
Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
Bruce Lin (blin@microsoft.com), Microsoft Corporation
Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation
(date: March, 1996)
and edited by
Wei Wu (weiwu@stallion.risc.rockwell.com) Rockwell Science Center
and also edited by
Yoshihiro Kikuchi (TOSHIBA CORPORATION)
Takeshi Nagai (TOSHIBA CORPORATION)
Toshiaki Watanabe (TOSHIBA CORPORATION)
Noboru Yamaguchi (TOSHIBA CORPORATION)
Marc Mongenet (Marc.Mongenet@epfl.ch), Swiss Federal Institute of Technology, Lausanne (EPFL)
in the course of development of the MPEG-4 Video (ISO/IEC 14496-2).
This software module is an implementation of a part of one or more MPEG-4 Video tools
as specified by the MPEG-4 Video.
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video.
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents.
The original developer of this software module and his/her company,
the subsequent editors and their companies,
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation.
Copyright is not released for non MPEG-4 Video conforming products.
Microsoft retains full right to use the code for his/her own purpose,
assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products.
This copyright notice must be included in all copies or derivative works.
Copyright (c) 1996, 1997.
Module Name:
sesEnc.cpp
Abstract:
Encoder for one video session.
Revision History:
Sept. 30, 1997: Error resilient tools added by Toshiba
Nov. 27, 1997: Spatial Scalable tools added, and modified for Spatial Scalable
by Takefumi Nagumo(nagumo@av.crl.sony.co.jp) SONY
Dec 11, 1997: Interlaced tools added by NextLevel Systems (GI)
(B.Eifrig, beifrig@nlvl.com, X.Chen, xchen@nlvl.com)
Jun 17, 1998: add Complexity Estimation syntax support
Marc Mongenet (Marc.Mongenet@epfl) - EPFL
May 9, 1999: tm5 rate control by DemoGraFX, duhoff@mediaone.net
*************************************************************************/
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
#include "fstream.h"
#include "iostream.h"
#include "typeapi.h"
#include "codehead.h"
#include "global.hpp"
#include "entropy/bitstrm.hpp"
#include "entropy/entropy.hpp"
#include "entropy/huffman.hpp"
#include "mode.hpp"
#include "sesenc.hpp"
#include "tps_enhcbuf.hpp" // added by Sharp (98/2/12)
#include "vopses.hpp"
#include "vopseenc.hpp"
#include "enhcbufenc.hpp" // added by Sharp (98/2/12)
#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_
#ifdef __PC_COMPILER_ //OS specific stuff
#define SUB_CMPFILE "%s\\%2.2d\\%s.cmp"
#define SUB_TRCFILE "%s\\%2.2d\\%s.trc"
#define SUB_YUVFILE "%s\\%2.2d\\%s.yuv"
#define SUB_SEGFILE "%s\\%2.2d\\%s.seg"
#define ENHN_SUB_CMPFILE "%s\\%2.2d\\%s_e.cmp"
#define ENHN_SUB_TRCFILE "%s\\%2.2d\\%s_e.trc"
#define ENHN_SUB_YUVFILE "%s\\%2.2d\\%s_e.yuv"
#define ENHN_SUB_SEGFILE "%s\\%2.2d\\%s_e.seg"
#define SUB_VDLFILE "%s\\%2.2d\\%s.spt" //for sprite i/o
#define SUB_PNTFILE "%s\\%2.2d\\%s.pnt" //for sprite i/o
#define ROOT_YUVFILE "%s\\%s.yuv"
#define ROOT_SEGFILE "%s\\%s.seg"
#define IOS_BINARY ios::binary
#define MKDIR "mkdir %s\\%2.2d"
#else
#define SUB_CMPFILE "%s/%2.2d/%s.cmp"
#define SUB_TRCFILE "%s/%2.2d/%s.trc"
#define SUB_YUVFILE "%s/%2.2d/%s.yuv"
#define SUB_SEGFILE "%s/%2.2d/%s.seg"
#define ENHN_SUB_CMPFILE "%s/%2.2d/%s_e.cmp"
#define ENHN_SUB_TRCFILE "%s/%2.2d/%s_e.trc"
#define ENHN_SUB_YUVFILE "%s/%2.2d/%s_e.yuv"
#define ENHN_SUB_SEGFILE "%s/%2.2d/%s_e.seg"
#define SUB_VDLFILE "%s/%2.2d/%s.vdl" //for sprite i/o
#define SUB_PNTFILE "%s/%2.2d/%s.pnt" //for sprite i/o
#define ROOT_YUVFILE "%s/%s.yuv"
#define ROOT_SEGFILE "%s/%s.seg"
//#define IOS_BINARY ios::bin
#define IOS_BINARY 0
#define MKDIR "mkdir %s/%2.2d"
#endif
#define BASE_LAYER 0
#define ENHN_LAYER 1
#define _FOR_GSSP_
Bool fileExistence (const Char* pchFile)
{
Bool ret = 1;
FILE* pf = fopen (pchFile, "r");
if (pf == NULL)
ret = 0;
else
fclose (pf);
return ret;
}
Void CSessionEncoder::createReconDir (UInt idx) const
{
Char pchTmp [100];
sprintf (pchTmp, SUB_YUVFILE, m_pchReconYUVDir, idx, m_pchPrefix);
FILE* pf = fopen (pchTmp, "wb");
if (pf == NULL) {
sprintf (pchTmp, MKDIR, m_pchReconYUVDir, idx);
system (pchTmp);
}
else
fclose (pf);
}
Void CSessionEncoder::createCmpDir (UInt idx) const
{
Char pchTmp [100];
sprintf (pchTmp, SUB_CMPFILE, m_pchOutStrFiles, idx, m_pchPrefix);
FILE* pf = fopen (pchTmp, "wb");
if (pf == NULL) {
sprintf (pchTmp, MKDIR, m_pchOutStrFiles, idx);
system (pchTmp);
}
else
fclose (pf);
}
CSessionEncoder::~CSessionEncoder ()
{
delete [] m_rgvolmd [BASE_LAYER];
delete [] m_rgvolmd [ENHN_LAYER];
delete [] m_rgvopmd [BASE_LAYER];
delete [] m_rgvopmd [ENHN_LAYER];
// sprite
for (Int iVO = 0; iVO < m_iNumVO; iVO++) {
delete [] m_ppstSrc [iVO];
for (Int ifr = 0; ifr < m_iNumFrame; ifr++)
delete [] m_pppstDst [iVO] [ifr];
delete [] m_pppstDst [iVO];
}
delete [] m_ppstSrc;
delete [] m_pppstDst;
}
CSessionEncoder::CSessionEncoder (
// general info
UInt uiFrmWidth, // frame width
UInt uiFrmHeight, // frame height
Int iFirstFrm, // first frame number
Int iLastFrm, // last frame number
Bool bNot8Bit, // NBIT: not 8-bit flag
UInt uiQuantPrecision, // NBIT: quant precision
UInt nBits, // NBIT: number of bits per pixel
Int iFirstVO, // first VOP index
Int iLastVO, // last VOP index
const Bool* rgbSpatialScalability, // spatial scalability indicator
const Int* rgiTemporalScalabilityType, // temporal scalability formation case // added by Sharp (98/02/09)
const Int* rgiEnhancementType, // enhancement_type for scalability // added by Sharp (98/02/09)
UInt* rguiRateControl [], // rate control type
UInt* rguiBudget [], // for rate control
// for shape coding
const AlphaUsage* rgfAlphaUsage, // alpha usage for each VOP. 0: binary, 1: 8-bit
const Bool* rgbShapeOnly, // disable texture motion coding
const Int* rgiBinaryAlphaTH, // threhold is shape size conversion
const Int* rgiBinaryAlphaRR, // refrash rate for binary shape coding: Added for error resilient mode by Toshiba(1997-11-14)
const Bool* rgbNoCrChange, // no change of cr from mb to mb
// motion estimation part for each VOP
UInt** rguiSearchRange, // motion search range
Bool** rgbOriginalForME, // flag indicating whether use the original previous VOP for ME
Bool** rgbAdvPredDisable,//no advanced MC (currenly = obmc, later = obmc + 8x8)
// START: Complexity Estimation syntax support - Marc Mongenet (EPFL) - 17 Jun 1998
Bool ** rgbComplexityEstimationDisable,
Bool ** rgbOpaque,
Bool ** rgbTransparent,
Bool ** rgbIntraCAE,
Bool ** rgbInterCAE,
Bool ** rgbNoUpdate,
Bool ** rgbUpsampling,
Bool ** rgbIntraBlocks,
Bool ** rgbInterBlocks,
Bool ** rgbInter4vBlocks,
Bool ** rgbNotCodedBlocks,
Bool ** rgbDCTCoefs,
Bool ** rgbDCTLines,
Bool ** rgbVLCSymbols,
Bool ** rgbVLCBits,
Bool ** rgbAPM,
Bool ** rgbNPM,
Bool ** rgbInterpolateMCQ,
Bool ** rgbForwBackMCQ,
Bool ** rgbHalfpel2,
Bool ** rgbHalfpel4,
// END: Complexity Estimation syntax support
// START: VOL Control Parameters
UInt ** rguiVolControlParameters,
UInt ** rguiChromaFormat,
UInt ** rguiLowDelay,
UInt ** rguiVBVParams,
UInt ** rguiBitRate,
UInt ** rguiVbvBufferSize,
UInt ** rguiVbvBufferOccupany,
// END: VOL Control Parameters
Double** rgdFrameFrequency,
// interlace coding
Bool** rgbInterlacedCoding, // interlace flag
Bool** rgbTopFieldFirst, // top field first flag
Bool** rgbAlternateScan, // alternate scan flag
Int** rgiDirectModeRadius, // Direct mode search radius
// motion vector file I/O
Int** rgiMVFileUsage,
Char*** pchMVFileName,
// major syntax mode
Int** rgbVPBitTh, // Bit threshold for video packet spacing control
Bool** rgbDataPartitioning, //data partitioning
Bool** rgbReversibleVlc, //reversible VLC
// for texture coding
Quantizer** rgfQuant, // quantizer selection, either H.263 or MPEG
Bool** rgbLoadIntraMatrix, // load user-defined intra Q-Matrix
Int*** rgppiIntraQuantizerMatrix, // Intra Q-Matrix
Bool** rgbLoadInterMatrix, // load user-defined inter Q-Matrix
Int*** rgppiInterQuantizerMatrix, // Inter Q-Matrix
Int** rgiIntraDCSwitchingThr, //threshold to code dc as ac when pred. is on
Int** rgiStepI, // I-VOP quantization stepsize
Int** rgiStepP, // P-VOP quantization stepsize
Bool** rgbLoadIntraMatrixAlpha,
Int*** rgppiIntraQuantizerMatrixAlpha,
Bool** rgbLoadInterMatrixAlpha,
Int*** rgppiInterQuantizerMatrixAlpha,
Int** rgiStepIAlpha, // I-VOP quantization stepsize for Alpha
Int** rgiStepPAlpha, // P-VOP quantization stepsize for Alpha
Int** rgiStepBAlpha, // P-VOP quantization stepsize for Alpha
Int** rgbNoAlphaQuantUpdate, // discouple gray quant update with tex. quant
Int** rgiStepB, // quantization stepsize for B-VOP
const Int* rgiNumOfBbetweenPVOP, // no of B-VOPs between P-VOPs
const Int* rgiNumOfPbetweenIVOP, // no of P-VOPs between I-VOPs
//added to encode GOVheader by SONY 980212
const Int* rgiGOVperiod,
//980212
const Bool* rgbDeblockFilterDisable, //deblocing filter disable
const Bool *rgbAllowSkippedPMBs,
// file information
const Char* pchPrefix, // prefix name of the movie
const Char* pchBmpFiles, // bmp file directory location
const ChromType* rgfChrType, // input chrominance type. 0 - 4:4:4, 1 - 4:2:2, 0 - 4:2:0
const Char* pchOutBmpFiles, // quantized frame file directory
const Char* pchOutStrFiles, // output bitstream file
const Int* rgiTemporalRate, // temporal subsampling rate
const Int* rgiEnhnTemporalRate, // temporal subsampling rate // added by Sharp (98/02/09)
// statistics dumping options
const Bool* rgbDumpMB,
const Bool* rgbTrace,
// rounding control
const Bool* rgbRoundingControlDisable,
const Int* rgiInitialRoundingType,
// for sprite info
const UInt* rguiSpriteUsage, // sprite usage
const UInt* rguiWarpingAccuracy, // warping accuracy
const Int* rgNumOfPnts, // number of points for sprite, 0 for stationary and -1 for no sprite
const Char* pchSptDir, // sprite directory
const Char* pchSptPntDir, // sprite point file
SptMode *pSpriteMode, // sprite reconstruction mode, i.e. Low-latency-sprite-enable
Int iSpatialOption,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -