Initial community commit

This commit is contained in:
Jef
2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit 20d28e80a5
16810 changed files with 4640254 additions and 2 deletions
@@ -0,0 +1,33 @@
/****************************************************************************
*
* Module Title : HuffTables.h
*
* Description : Video CODEC
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.01 JBB 26 Jan 01 New Huffman Code
* 1.00 PGW 12/10/00 Configuration baseline
*
*****************************************************************************
*/
#ifndef HUFFTAB_H
#define HUFFTAB_H
#include "type_aliases.h"
#include "huffman.h"
/****************************************************************************
* Hufman tables
*****************************************************************************
*/
// For details of tokens and extra bit breakdown see token definitions in huffman.h
UINT8 ExtraBitLengths_VP5[MAX_ENTROPY_TOKENS] = { 0, 1, 1, 1, 1, 2, 3, 5, 6, 12, 0 };
UINT32 DctRangeMinVals[MAX_ENTROPY_TOKENS] = { 0, 1, 2, 3, 4, 5, 7, 11, 27, 59, 0 };
#endif
@@ -0,0 +1,78 @@
/****************************************************************************
*
* Module Title : boolhuff.H
*
* Description : Video CODEC
*
* AUTHOR : James Bankoski
*
*****************************************************************************
* Revision History
*
* 1.00 JBB 01JUN01 Configuration baseline
*
*****************************************************************************
*/
/****************************************************************************
* Header Files
*****************************************************************************
*/
#ifndef boolhuff_h
#define boolhuff_h
#ifdef NOTNORMALIZED
typedef struct _boolcoder
{
unsigned char *buffer;
unsigned int pos;
union
{
unsigned int value;
unsigned char v[4];
};
unsigned int range;
} BOOL_CODER;
#else
typedef struct
{
unsigned int bits;
unsigned int bitpos;
unsigned int *source;
unsigned int pos;
} bitpump;
typedef struct
{
unsigned int lowvalue;
unsigned int range;
unsigned int value;
int count;
unsigned int pos;
unsigned char *buffer;
// Variables used to track bit costs without outputing to the bitstream
unsigned int MeasureCost;
unsigned long BitCounter;
} BOOL_CODER;
#endif
extern void StartDecode(BOOL_CODER *bc, unsigned char *buffer);
extern int DecodeBool(BOOL_CODER *bc, int context);
extern int DecodeBool128(BOOL_CODER *bc);
extern void StopDecode(BOOL_CODER *bc);
extern void StartEncode(BOOL_CODER *bc, unsigned char *buffer);
extern void EncodeBool(BOOL_CODER *bc, int x, int context);
extern void EncodeBool2(BOOL_CODER *bc, int x, int context);
extern void StopEncode(BOOL_CODER *bc);
extern double shannonCost0[256];
extern double shannonCost1[256];
extern unsigned int shannon64Cost0[256];
extern unsigned int shannon64Cost1[256];
#endif
@@ -0,0 +1,562 @@
/****************************************************************************
*
* Module Title : COMPDLL.H
*
* Description : Video CODEC demo compression DLL main header
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.34 YWX 09-Dec-02 Added Function pointers for frame/field varainces calculation
* 1.33 YWX 30-Oct-02 Added EncoderLoopFilterOff flag
* 1.32 YWX 28-Oct-02 Added function pointer for 5 region diamond search
* 1.31 YWX 28-Oct-02 Added above and left token context and 5 region
* diamond motion search sites
* 1.30 YWX 02-Jul-02 Added new funcion pointers for motion search
* 1.31 JBB 04 JUL-02 Added preprocessor code
* 1.29 AWG 20-Jun-01 Removed QuadCodeComponent function prototype & HExtra/VExtra
* 1.29 AWG 22-May-01 Added support for DCT16
* 1.28 JBB 05-May-01 Changes for VP5 (new entropytablebits and tokenextra chgs
* 1.27 JBB 23-Mar-01 Changed QuickCompress datatype from BOOL to INT32
* 1.26 JBB 11 Feb 01 Merged in: added vars for map ca move ac choice to right after dc
* 1.25 PGW 31 Jan 01 Added some stats variables and VP5 Mv entropy tables.
* 1.24 JBB 30 Nov 00 Version number changes
* 1.23 JBB 15 Nov 00 Cleaned out ifdefs
* 1.22 JBB 15 Oct 00 Added First Pass Function
* 1.21 JBB 11 Sep 00 new function pointers for subtract removed transxquant
* 1.20 JBB 07 Sep 00 Changed error metrics to Unsigned int
* 1.19 JBB 24 Aug 00 Ansi C compatible
* 1.18 JBB 27Jul00 added checks on Mallocs
* 1.17 JBB 24Jul00 Changed error functions to return INT32 instead of double
* 1.16 PGW 12 Jul 00 Removed CompAutoKeyFrameThreshold.
* 1.15 PGW 29 Jun 00 Removed instnace varibale CarryOverAdaptionEnabled.
* 1.14 PGW 27 Jun 00 Added QTargetModifier[]. Changes to CONFIG_TYPE2.
* 1.13 JBB 30/05/00 Removed hard coded size limits
* 1.12 JBB 22/05/00 Added OriginalDC support to remove max_fragments depends
* 1.11 YX 13/04/00 Add function pointers for new optimizations
* 1.10 YX 06/04/00 More buffers alligned MMX Fdct
* 1.09 YX 20/03/00 32 Byte alligned buffers, Back to Integer Forward DCT
* Additional Function pointers for optimized code
* 1.08 PGW 17/03/00 Changes to support seperate Y and UV entropy tables.
* Added PreProcFilterLevel to allow control of preprecessor
* filter level.
* 1.07 YX 09/03/00 Change to use floating point forward DCT
* 1.06 PGW 17/12/99 Draw dib functionality removed.
* 1.05 PGW 05/10/99 Remove some Windows dependancies for VFW compressor.
* 1.04 PGW 20/07/99 Rate targeting corrections for VFW version of codec
* 1.03 PGW 15/07/99 Added QuickCompress flag.
* 1.02 PGW 05/07/99 Added GetFOURMVExhaustiveSearch() function
* 1.01 PGW 29/06/99 Added GetMBMVExhaustiveSearch() function.
* 1.00 PGW 14/06/99 Configuration baseline
*
*****************************************************************************
*/
#ifndef __INC_COMPDLL_H
#define __INC_COMPDLL_H
#define MIN_BPB_FACTOR 0.1
#define MAX_BPB_FACTOR 10.0
#define KEY_FRAME_CONTEXT 5
#include "codec_common.h"
#include "preprocif.h"
#include "preproc.h"
#include "pbdll.h"
#include "vp50_comp_interface.h"
/****************************************************************************
* Module constants.
*****************************************************************************
*/
// Debug/stats code
//#define PSNR_ON
/****************************************************************************
* Types
*****************************************************************************
*/
typedef struct CONFIG_TYPE2
{
UINT32 TargetBandwidth;
UINT32 OutputFrameRate;
UINT32 FirstFrameQ;
UINT32 BaseQ;
UINT32 MaxQ; // Absolute Max Q allowed.
UINT32 ActiveWorstQuality; // Reflects worst quality Currently allowed (specified as an index where 0 is worst quality)
UINT32 ActiveBestQuality; // Reflects best quality currently allowed (specified as an index where 0 is worst quality)
} CONFIG_TYPE2;
/* Defines the largest positive integer expressable with a standard int type */
/****************************************************************************
* * Type declarations
****************************************************************************
*/
typedef enum
{
DCT_COEF_TOKEN,
MODE_TOKEN,
BLOCKMAP_TOKEN,
MV_TOKEN
} TOKENTYPE;
typedef struct _TOKENEXTRA
{
INT32 Token;
UINT32 Extra;
} TOKENEXTRA;
typedef struct LineEq2
{
double M;
double C;
} LINE_EQ2;
typedef struct
{
BLOCK_CONTEXTA * AbovePtr;
BLOCK_CONTEXTA Above;
BLOCK_CONTEXT * LeftPtr;
BLOCK_CONTEXT Left;
Q_LIST_ENTRY * LastDcPtr;
Q_LIST_ENTRY LastDc;
} MB_DC_CONTEXT;
/****************************************************************************
* MACROS
*****************************************************************************
*/
/****************************************************************************
* Global Variables
*****************************************************************************
*/
//****************************************************************
// Function Pointers now library globals!
extern UINT32 (*GetSAD16)(UINT8 *, INT32, UINT8 *, INT32, UINT32, UINT32);
extern UINT32 (*GetSadHalfPixel16)(UINT8 *, INT32, UINT8 *, UINT8 *, INT32, UINT32, UINT32);
extern void (*fdct_short) ( INT16 * InputData, INT16 * OutputData );
extern void (*idctc[65])( INT16 *InputData, INT16 *QuantMatrix, INT16 * OutputData );
extern UINT32 (*GetSAD)(UINT8 *, INT32, UINT8 *, INT32, UINT32, UINT32) ;
//extern UINT32 (*GetNextSAD)(UINT8 *, INT32, UINT8 *, UINT32, UINT32 );
extern UINT32 (*GetSadHalfPixel)(UINT8 *, INT32, UINT8 *, UINT8 *, INT32, UINT32, UINT32 );
extern UINT32 (*GetInterError)( UINT8 *, INT32, UINT8 *, UINT8 *, INT32 );
extern UINT32 (*GetIntraError)( UINT8 *, INT32);
extern void (*Sub8)( UINT8 *FiltPtr, UINT8 *ReconPtr, INT16 *DctInputPtr, UINT8 *old_ptr1, UINT8 *new_ptr1, INT32 SourceStride, INT32 ReconStride );
extern void (*Sub8_128)( UINT8 *FiltPtr, INT16 *DctInputPtr, UINT8 *old_ptr1, UINT8 *new_ptr1, INT32 SourceStride );
extern void (*Sub8Av2)( UINT8 *FiltPtr, UINT8 *ReconPtr1, UINT8 *ReconPtr2, INT16 *DctInputPtr, UINT8 *old_ptr1, UINT8 *new_ptr1, INT32 SourceStride, INT32 ReconStride );
//****************************************************************
#define HUGE_ERROR (1<<28) // Out of range test value
#define MAX_SEARCH_SITES 33 // Number of search sites for a 4-step search (at pixel accuracy)
typedef struct CP_INSTANCE * xCP_INST;
typedef struct CP_INSTANCE
{
PB_INSTANCE pb; // playback
INT32 DropCounter;
//****************************************************************************************************
// Compressor Configuration
CONFIG_TYPE2 Configuration;
YUV_BUFFER_CONFIG InputConfig;
YUV_BUFFER_CONFIG YuvInputData;
INT32 SizeStep;
INT32 QuickCompress;
BOOL GoldenFrameEnabled;
BOOL InterPrediction;
BOOL MotionCompensation;
BOOL AutoKeyFrameEnabled ;
INT32 ForceKeyFrameEvery ;
INT32 AutoKeyFrameThreshold ;
UINT32 LastKeyFrame ;
UINT32 MinimumDistanceToKeyFrame ;
INT32 KeyFrameDataTargetOrig ; // Data rate target for key frames
INT32 KeyFrameDataTarget ; // Data rate target for key frames
UINT32 KeyFrameFrequency ;
BOOL DropFramesAllowed ;
BOOL DropFrame;
INT32 DropCount ;
UINT32 QualitySetting;
UINT32 PreProcFilterLevel;
BOOL AllowSpatialResampling;
UINT8 RdOpt; // 0 - off, 1 - basic rd on, 2 - all rd options on
// Compressor Statistics
double TotErrScore;
UINT32 InterError;
UINT32 MVErrorPerBit;
UINT32 ErrorPerBit;
UINT32 IntraError;
INT64 KeyFrameCount ; // Count of key frames.
INT64 TotKeyFrameBytes ;
UINT32 LastKeyFrameSize ;
UINT32 PriorKeyFrameSize[KEY_FRAME_CONTEXT];
UINT32 PriorKeyFrameDistance[KEY_FRAME_CONTEXT];
INT32 FrameQuality[6];
int DecoderErrorCode; // Decoder error flag.
INT32 ThreshMapThreshold;
INT32 TotalMotionScore;
INT64 TotalByteCount;
INT32 FixedQ;
// Frame Statistics
INT64 CurrentFrame;
UINT32 LastFrameSize;
UINT32 ThisFrameSize;
BOOL ThisIsFirstFrame;
BOOL ThisIsKeyFrame;
BOOL GfRecoveryFrame;
INT32 MotionScore;
UINT32 FirstSixthBoundary; // Macro block index marking the first sixth of the image
UINT32 LastSixthBoundary; // Macro block index marking the last sixth of the image
/* Rate Targeting variables PGW 08/05/96). */
double BpbCorrectionFactor;
double KeyFrameBpbCorrectionFactor;
// Controlling Block Selection
UINT32 MVChangeFactor;
UINT32 FourMvChangeFactor;
UINT32 ExhaustiveSearchThresh;
UINT32 MinImprovementForFourMV;
UINT32 FourMVThreshold;
UINT32 IntraThresh;
UINT32 MinErrorForMacroBlockMVSearch;
UINT32 MinErrorForBlockMVSearch;
UINT32 MinErrorForGoldenMVSearch;
//****************************************************************************************************
//****************************************************************************************************
// Frames
// Used in the selecetive convolution filtering of the Y plane. */
YUV_BUFFER_ENTRY *yuv1ptr;
YUV_BUFFER_ENTRY *yuv1ptrAlloc;
//****************************************************************************************************
//****************************************************************************************************
// Token Buffers
TOKENEXTRA *CoeffTokens;
TOKENEXTRA *CoeffTokensAlloc;
TOKENEXTRA *CoeffTokenPtr;
INT16 LastDC[3];
BOOL_CODER bc;
//****************************************************************************************************
//****************************************************************************************************
// SuperBlock, MacroBLock and Fragment Information
// Coded flag arrays and counters for them
//****************************************************************************************************
// Live Codec Variables
UINT8 *DataOutputBuffer;
//****************************************************************************************************
//****************************************************************************************
// STATICS COPIED FROM C FILES (USED IN MULTIPLE FUNCTIONS BUT ARE NOT REALLY INSTANCE GLOBALS )
// copied from cencode.c
UINT8 MBCodingMode; // Coding mode flags
// copied from mcomp.c
INT32 MVPixelOffsetY[MAX_SEARCH_SITES];
UINT32 InterTripOutThresh;
INT32 MVSearchSteps;
INT32 MVOffsetX[MAX_SEARCH_SITES];
INT32 MVOffsetY[MAX_SEARCH_SITES];
INT32 HalfPixelRef2Offset[9]; // Offsets for half pixel compensation
INT8 HalfPixelXOffset[9]; // Half pixel MV offsets for X
INT8 HalfPixelYOffset[9]; // Half pixel MV offsets for Y
Q_LIST_ENTRY *quantized_list;
Q_LIST_ENTRY *quantized_listAlloc;
MOTION_VECTOR MVector;
INT16 *DCT_codes; //Buffer that stores the result of Forward DCT
INT16 *DCTDataBuffer; //Input data buffer for Forward DCT
INT16 *DCT_codesAlloc;
INT16 *DCTDataBufferAlloc;
// Motion compensation related variables
UINT32 MvMaxExtent;
INT32 byte_bit_offset;
// copied from cbitman.c
UINT32 NearestError[4];
UINT32 NearError[4];
UINT32 ZeroError[4];
UINT32 BestError[4];
UINT32 ErrorBins[128];
//****************************************************************
// instances (used for reconstructing buffers and to hold tokens etc.)
xPP_INST pp; // preprocessor
#if defined PSNR_ON
double TotPsnr;
double MinPsnr;
double MaxPsnr;
double TotYPsnr;
double MinYPsnr;
double MaxYPsnr;
double TotUPsnr;
double MinUPsnr;
double MaxUPsnr;
double TotVPsnr;
double MinVPsnr;
double MaxVPsnr;
#endif
// Structures for entropy contexts
UINT32 FrameDcTokenDist[2][MAX_ENTROPY_TOKENS];
UINT32 FrameAcTokenDist[PREC_CASES][2][VP5_AC_BANDS][MAX_ENTROPY_TOKENS];
// Storage for the first frame entropy probabilities.
// These are re-used for all subsequent key frames when we are operating in
// error (drop frame) ressiliant mode.
UINT8 FirstFrameDcProbs[2*(MAX_ENTROPY_TOKENS-1)];
UINT8 FirstFrameAcProbs[2*PREC_CASES*VP5_AC_BANDS*(MAX_ENTROPY_TOKENS-1)];
// The Plane Y or UV to which the current block belongs (0 = Y 1 = UV)
UINT8 EncoderPlane;
// Last token coded this block.
UINT8 ThisBlockLastToken;
UINT8 ZeroCount;
//UINT32 MBModeCount[MAX_MODES+1];
UINT32 MBModeCount[4][MAX_MODES+1];
UINT32 BModeCount[MAX_MODES+1];
UINT32 CountModeSameAsLast[4][MAX_MODES+1];
UINT32 CountModeDiffFrLast[4][MAX_MODES+1];
UINT32 ModeCodeArray[4][MAX_MODES+1][MAX_MODES+1];
UINT8 ModeLengthArray[4][MAX_MODES+1][MAX_MODES+1];
// TEMP
UINT32 ModeBitCount[2];
INT64 ModeComplexity[2];
UINT32 ModeBlocks[2];
UINT32 MBModeCostBoth[11];
UINT32 MBModeCostNoNear[11];
UINT32 MBModeCostNoNearest[11];
UINT32 BModeCost[11];
UINT32 MvBaselineDist[2][MV_ENTROPY_TOKENS];
UINT32 FrameMvCount;
UINT32 EstMVCost[2][MV_ENTROPY_TOKENS];
UINT32 EstModeCost[2][MAX_MODES];
UINT32 nExperimentals;
INT32 Experimental[C_SET_EXPERIMENTAL_MAX - C_SET_EXPERIMENTAL_MIN + 1];
// Bandwidth and buffer control variables
INT32 PerFrameBandwidth; // Target for average bandwidth per frame.
INT32 InterFrameTarget; // Average "inter" frame bit target corrected for key frame costs
INT32 ThisFrameTarget; // Modified rate target for this frame
BOOL BufferedMode; // FALSE = Tight buffering (Video Conferencing mode); TRUE = normal buffered/streaming mode.
BOOL ErrorResilliantMode; // A mode used for VC etc. to make the codec more resilliant to dropped frames.
INT32 StartingBufferLevel; // The initial encoder buffer level
INT32 CurrentBufferLevel; // Current decoder buffer fullness state
INT32 OptimalBufferLevel; // The buffer level target we strive to reach / maintain.
INT32 DropFramesWaterMark; // Buffer fullness watermark for forced drop frames.
INT32 ResampleDownWaterMark; // Buffer fullness watermark for downwards spacial re-sampling
INT32 ResampleUpWaterMark; // Buffer fullness watermark where returning to larger image size is consdered
INT32 LastKeyFrameBufferLevel; // Used to monitor changes in buffer level when considering re-sampling.
INT32 Speed;
INT32 CPUUsed;
UINT32 ModeMvCostEstimate; // Running total of cost estimates for modes and MVs in this frame.
// Variables used in regulating cost of new motion vectors based upon an estimate of new MV frequency.
UINT32 FrameNewMvCounter;
UINT32 FrameModeCounter;
UINT32 MvEpbCorrection;
UINT32 LastFrameNewMvUsage; // 0 = Low 9 = High
UINT32 * MbBestErr;
UINT32 * MbBestErrAlloc;
UINT32 EstDcTokenCosts[2][MAX_ENTROPY_TOKENS];
UINT32 EstAcTokenCosts[PREC_CASES][2][VP5_AC_BANDS][MAX_ENTROPY_TOKENS];
// Data structures used to save and restor MB and DC contexts during rate distortion
MACROBLOCK_INFO CopyMbi;
BLOCK_CONTEXTA AboveCopyY[2];
BLOCK_CONTEXTA AboveCopyU;
BLOCK_CONTEXTA AboveCopyV;
BLOCK_CONTEXT LeftYCopy[2];
BLOCK_CONTEXT LeftUCopy;
BLOCK_CONTEXT LeftVCopy;
Q_LIST_ENTRY LastDcYCopy[3];
Q_LIST_ENTRY LastDcUCopy[3];
Q_LIST_ENTRY LastDcVCopy[3];
// Above and left context for encoding
UINT8 *aboveDcTokensAlloc[3]; // 0 for y, 1 for u and 2 for v
UINT8 *aboveDcTokens[3]; // 0 for y, 1 for u and 2 for v
UINT8 leftTokens[4][64]; // 0 1 for y 2 for u and 3 for v
MB_DC_CONTEXT MbDcContexts[MAX_MODES][6]; // Per mode, per block position data structure for and MB
UINT32 avgPickModeTime;
UINT32 avgEncodeTime;
UINT32 avgPackVideoTime;
UINT32 ForceHScale;
UINT32 ForceHRatio;
UINT32 ForceVScale;
UINT32 ForceVRatio;
BOOL ForceInternalSize;
PreProcInstance preproc;
INT32 FrameRateInput;
INT32 FrameRateDropFrames;
INT32 FrameRateDropCount;
//
UINT32 EncoderLoopFilterOff;
// variables for 5 region diamond MV search
INT32 DSMVSearchSteps;
INT32 DSMVPixelOffsetY[MAX_SEARCH_SITES];
INT32 DSMVOffsetX[MAX_SEARCH_SITES];
INT32 DSMVOffsetY[MAX_SEARCH_SITES];
UINT32 (*FindMvViaSearch)( xCP_INST cpi,
UINT8 *SrcPtr,
INT32 SourceStride,
UINT8 *RefPtr,
INT32 ReconStride,
MOTION_VECTOR *MV,
UINT8 **BestBlockPtr,
UINT32 BlockSize);
void (*FindBestHalfPixelMv)(xCP_INST cpi,
UINT8 *SrcPtr,
INT32 SourceStride,
UINT8 *RefPtr,
INT32 ReconStride,
MOTION_VECTOR *MV,
UINT8 **BestBlockPtr,
UINT32 BlockSize,
UINT32 MinError);
} CP_INSTANCE;
UINT32 (*GetMBFrameVertVar)(CP_INSTANCE *cpi);
UINT32 (*GetMBFieldVertVar)(CP_INSTANCE *cpi);
/****************************************************************************
* Functions.
*****************************************************************************
*/
extern void UpdateFrame(CP_INSTANCE *cpi);
extern UINT32 QuadCodeDisplayFragments (CP_INSTANCE *cpi);
extern UINT32 QuadCodeComponent ( CP_INSTANCE *cpi, UINT32 FirstSB, UINT32 SBRows, UINT32 SBCols, UINT32 HExtra, UINT32 VExtra, INT32 SourceStride );
extern void AcquireSingleFrame( CP_INSTANCE *cpi, UINT32 CurrFrame );
extern void AcquireFirstFrame(CP_INSTANCE *cpi);
extern void AcquireNextFrame( CP_INSTANCE *cpi, UINT32 CurrFrame );
extern void InitFrameTimer( CP_INSTANCE *cpi);
extern UINT32 EncodeData(CP_INSTANCE *cpi);
// Loop optimizations
extern void InitMapArrays();
// Codec
extern UINT32 DPCMTokenizeBlock ( CP_INSTANCE *cpi, INT32 FragIndex, INT32 SourceStride );
extern void SUB8( UINT8 *FiltPtr, UINT8 *ReconPtr, INT16 *DctInputPtr, UINT8 *old_ptr1, UINT8 *new_ptr1,
INT32 SourceStride, INT32 ReconStride );
extern void SUB8_128( UINT8 *FiltPtr, INT16 *DctInputPtr, UINT8 *old_ptr1, UINT8 *new_ptr1,
INT32 SourceStride );
extern void SUB8AV2( UINT8 *FiltPtr, UINT8 *ReconPtr1, UINT8 *ReconPtr2, INT16 *DctInputPtr, UINT8 *old_ptr1, UINT8 *new_ptr1,
INT32 SourceStride, INT32 ReconStride );
extern void PackEOBRun(CP_INSTANCE *cpi);
extern void ConvertBmpToYUV( PB_INSTANCE *pbi, UINT8 * BmpDataPtr, UINT8 * YuvBufferPtr );
extern CP_INSTANCE * CreateCPInstance(void);
extern void DeleteCPInstance(CP_INSTANCE **cpi);
extern void CMachineSpecificConfig(void);
// extern void fdct_slow16 ( INT16 * InputData, INT16 * OutputData );
extern void fdct_slowf ( INT16 * InputData, INT16 * OutputData );
extern void fdct_short_C ( INT16 * InputData, INT16 * OutputData );
extern void fdct_short_C ( INT16 * InputData, INT16 * OutputData );
extern BOOL EAllocateFragmentInfo(CP_INSTANCE *cpi);
extern BOOL EAllocateFrameInfo(CP_INSTANCE *cpi);
extern void EDeleteFragmentInfo(CP_INSTANCE *cpi);
extern void EDeleteFrameInfo(CP_INSTANCE *cpi);
extern UINT32 PickIntra( CP_INSTANCE *cpi );
extern UINT32 PickModes( CP_INSTANCE *cpi, UINT32 *InterError, UINT32 *IntraError);
extern INT32 GetSpeckSumAbsDiffs( UINT8 * NewDataPtr, UINT8 * RefDataPtr,
INT32 SourceStride, INT32 ErrorSoFar, INT32 BestSoFar );
extern INT32 GetNextSpeckSumAbsDiffs( UINT8 * NewDataPtr, UINT8 * RefDataPtr,
INT32 SourceStride, INT32 ErrorSoFar, INT32 BestSoFar );
extern INT32 GetHalfPixelSpeckSumAbsDiffs( UINT8 * SrcData, UINT8 * RefDataPtr1, UINT8 * RefDataPtr2,
INT32 SourceStride, INT32 ErrorSoFar, INT32 BestSoFar );
extern void ClampAndUpdateQ ( CP_INSTANCE *cpi, UINT32 QIndex) ;
// cx\generic\encodembs.c
extern void EncodeFrameMbs(CP_INSTANCE *cpi);
// cx\generic\vfw_comp_if.c
extern void CCONV ChangeEncoderSize(CP_INSTANCE* cpi, UINT32 Width, UINT32 Height);
extern void CopyOrResize(CP_INSTANCE* cpi);
// cx\generic\tokenize.c
extern UINT16 TokenizeFrag(CP_INSTANCE* cpi, INT16* RawData, UINT16 BlockSize, UINT32 Plane, BLOCK_CONTEXTA* Above, BLOCK_CONTEXT* Left);
#endif
@@ -0,0 +1,100 @@
/****************************************************************************
*
* Module Title : decodemode.h
*
* Description : functions for decoding modes and motionvectors
*
* AUTHOR : James Bankoski
*
*****************************************************************************
* Revision History
*
* 1.00 JBB 30OCT01 New Configuration baseline.
*
*****************************************************************************
*/
/****************************************************************************
* Header Files
*****************************************************************************
*/
#ifndef STRICT
#define STRICT /* Strict type checking. */
#endif
/****************************************************************************
* Implicit Imports
*****************************************************************************
*/
extern UINT8 Stats[9][4][4][4];
extern UINT8 NNStats[7][4][4][4];
extern UINT8 NN2Stats[7][4][4][4];
extern UINT8 blockStats[3][4][4][4];
#define MODETYPES 3
#define MODEVECTORS 16
#define PROBVECTORXMIT 174
#define PROBIDEALXMIT 254
/****************************************************************************
* Exported data structures.
*****************************************************************************
*/
typedef struct _modeContext
{
UINT8 left;
UINT8 above;
UINT8 last;
} MODE_CONTEXT;
typedef struct _htorp
{
unsigned char selector : 1; // 1 bit selector 0->ptr, 1->token
unsigned char value : 7;
} torp;
typedef struct _hnode
{
torp left;
torp right;
} HNODE;
typedef enum _MODETYPE
{
MACROBLOCK,
NONEAREST_MACROBLOCK,
NONEAR_MACROBLOCK,
BLOCK
} MODETYPE;
#ifndef MAPCA
__inline
#endif
int mbClass(int i);
/****************************************************************************
* Imports
*****************************************************************************
*/
extern HNODE MBCodingMode[9];
extern HNODE NN2MBCodingMode[8];
extern HNODE NNMBCodingMode[7];
extern HNODE BlockCodingMode[3];
extern UINT8 BaselineXmittedProbs[4][2][MAX_MODES];
/****************************************************************************
* Function Prototypes
*****************************************************************************
*/
void DecodeModeProbs(PB_INSTANCE *pbi);
extern void FindNearestandNextNearest(PB_INSTANCE* pbi, UINT32 MBrow, UINT32 MBcol,
MOTION_VECTORA* nearest, MOTION_VECTORA* nextnearest, UINT8 Frame,int *type);
extern void BuildModeTree(PB_INSTANCE *pbi);
@@ -0,0 +1,45 @@
/****************************************************************************
*
* Module Title : decodemode.h
*
* Description : functions for decoding modes and motionvectors
*
* AUTHOR : James Bankoski
*
*****************************************************************************
* Revision History
*
* 1.00 JBB 30OCT01 New Configuration baseline.
*
*****************************************************************************
*/
/****************************************************************************
* Header Files
*****************************************************************************
*/
#ifndef STRICT
#define STRICT /* Strict type checking. */
#endif
#define MV_NODES 11
/****************************************************************************
* Implicit Imports
*****************************************************************************
*/
/****************************************************************************
* Exported data structures and functions
*****************************************************************************
*/
extern void FindNearestandNextNearest(PB_INSTANCE* pbi, UINT32 MBrow, UINT32 MBcol,
MOTION_VECTORA* nearest, MOTION_VECTORA* nextnearest, UINT8 Frame, int *type);
extern void ConfigureMvEntropyDecoder( PB_INSTANCE *pbi, UINT8 FrameType );
extern void decodeMotionVector( PB_INSTANCE *pbi, MOTION_VECTOR *mv, MOTION_VECTOR *nearestMv);
extern UINT8 MvUpdateProbs[2][MV_NODES];
@@ -0,0 +1,93 @@
/****************************************************************************
*
* Module Title : Huffman.h
*
* Description : Video CODEC
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.04 YWX 06-Nov-01 Changed for compatibility with Equator C compiler
* 1.03 JBB 26 Jan 01 New Huffman Code
* 1.02 PGW 11 Oct 00 Deleted reference to FrequencyCounts[].
* 1.01 PGW 15/03/00 Changes re. updated entropy tables.
* 1.00 PGW 12/10/99 Configuration baseline
*
*****************************************************************************
*/
#ifndef HUFFMAN_H
#define HUFFMAN_H
#include "type_aliases.h"
#include "boolhuff.h"
/****************************************************************************
* Constants
*****************************************************************************
*/
/****************************************************************************/
/****************************************************************************
* Types
*****************************************************************************
*/
typedef struct _tokenorptr
{
unsigned int selector : 1; // 1 bit selector 0->ptr, 1->token
unsigned int value : 7;
} tokenorptr;
typedef struct _huffnode
{
union
{
char l;
tokenorptr left;
} leftunion;
union
{
char r;
tokenorptr right;
} rightunion;
unsigned char freq;
} HUFF_NODE;
/****************************************************************************
* Data structures
*****************************************************************************
*/
/****************************************************************************
* Functions
*****************************************************************************
*/
extern void VP5_BuildHuffTree(
HUFF_NODE *hn,
unsigned int *counts,
int values );
extern void VP5_CreateCodeArray( HUFF_NODE *hn,
int node,
unsigned int *codearray,
unsigned char *lengtharray,
int codevalue,
int codelength );
extern void VP5_EncodeValue(
BOOL_CODER *bc,
HUFF_NODE *hn,
int value,
int length);
#endif
@@ -0,0 +1,53 @@
/****************************************************************************
*
* Module Title : MiscCommon.h
*
* Description : Miscellaneous common routines header file
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.00 PGW 15/10/99 Configuration baseline
*
*****************************************************************************
*/
#ifndef MISCCOMP_H
#define MISCCOMP_H
#include "type_aliases.h"
#include "compdll.h"
/****************************************************************************
* Constants
*****************************************************************************
*/
/****************************************************************************
* Types
*****************************************************************************
*/
/****************************************************************************
* Data structures
*****************************************************************************
*/
/****************************************************************************
* Function Prototypes
*****************************************************************************
*/
extern double GetEstimatedBpb( CP_INSTANCE *cpi, UINT32 TargetQIndex );
extern void UpdateBpbCorrectionFactor( CP_INSTANCE *cpi, UINT32 FrameSize );
extern void UpRegulateMB( CP_INSTANCE *cpi, UINT32 RegulationQ, UINT32 SB, UINT32 MB, BOOL NoCheck );
extern void ClampAndUpdateQ ( CP_INSTANCE *cpi, UINT32 QIndex );
extern void RegulateQ( CP_INSTANCE *cpi, INT32 TargetBits );
extern void ConfigureQuality( CP_INSTANCE *cpi, UINT32 QualityValue );
extern void CopyBackExtraFrags(CP_INSTANCE *cpi);
extern void PredictFilteredBlock(PB_INSTANCE* pbi, INT16* OutputPtr, BLOCK_POSITION bp);
#endif
@@ -0,0 +1,535 @@
/****************************************************************************
*
* Module Title : PBDLL
*
* Description : Video CODEC DEMO playback dll header
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.40 YWX 17-Dec-02 Added DeInteralceMode
* 1.39 YWX 06-Nov-01 Changed to align the MB coeffs buffer memory
* 1.38 AWG 22-MAY-01 Added support for DCT16
* 1.37 JBB 01-MAY-01 Added features to support vp5
* 1.36 JBB 06-Apr-01 Added cpufree variable
* 1.35 JBB 23-Mar-01 New data structure defined for DC prediction
* 1.34 JBX 22-Mar-01 Merged with vp4-mapca bitstream
* 1.33.PGW 08 Feb 01 Added LastFrameQIndex.
* 1.32 PGW 25 Jan 01 Changes to support new motion vector entropy coding in VP5.
* 1.31 JBB 26-JAN-01 Fixes for New Huffman Strategy
* 1.30 YWX 27-Nov-00 Added function Pointers for simple deblocker, i.e.
* Deblocking filter for low end machines
* 1.29 YWX 02-Nov-00 Added function pointers for new loopfilter
* 1.28 PGW 16 Nov 00 Deleted redundant data structures.
* Added BlockPatternPredictor.
* 1.27 YWX 02-Nov-00 Added function pointers for new loopfilter
* 1.26 YWX 19_Oct-00 Added function pointers for 1-2 scaling
* 1.25 JBB 17-oct-00 Ifdefs around version information
* 1.24 YWX 17-Oct-00 Added *FragCoordinates for new loop filter strategy
* 1.23 PGW 15 Oct 00 Added select_InterUV_quantiser() and related data structures.
* 1.22 PGW 11 Oct 00 Added CreateHuffmanTrees() and DestroyHuffmanTrees()
* Added void SelectHuffmanSet() and Huffman selector variables.
* 1.23 YWX 11-Oct-00 Added LastFrameNoMvRecon and LastFrameNoMvReconAlloc
* 1.22 YWX 04 Oct 00 Merged scaling and new loop filtering code
* 1.21 YWX 06 Sep 00 Added new deringing functions pointers
* 1.21 PGW 18 Sep 00 QThreshTable[] made instance specific.
* Added InitQTables().
* 1.20 JBB 25 Aug 00 Versioning differences
* 1.19 JBB 21 Aug 00 New More Blurry in high variance area deringer
* 1.18 YWX 2 Aug 00 Added function pointers for Postproc
* 1.17 JBB 28 Jul 00 Added Fragment Variance Value for eliminating deringer
* in some cases...
* 1.16 JBB 27 Jul 00 Moved kernel modifiers to pbi, malloc checks
* 1.15 SJL 24Jul00 Changes for Mac
* 1.14 YWX 15/05/00 More variable and function pointersf for postprocessor
* 1.13 YWX 08/05/00 Added #ifdef s and function pointers for postprocessor
* 1.12 JYX 05/05/00 Added PostProcessing (PostProcessBuffer + PostProcessLevel)
* 1.11 SJL 20/04/00 Added ability to enable new dequant code for the dxer.
* 1.10 JYX 06/04/00 Alligned Small Buffers & Live Codec Reordering
* 1.09 SJL 22/03/00 Added func ptr for the loop filter.
* 1.08 JBB 20/03/00 32 Byte alligned buffers, Back to Integer Forward DCT
* Additional function pointers for optimized code
* 1.07 PGW 20/03/00 Removed InterIntra.
* 1.06 PGW 17/03/00 Changes to support seperate Y and UV entropy tables.
* 1.05 JBB 29/01/00 Removed Globals added Playback only function externs !
* 1.04 PGW 17/12/99 Draw dib functionality removed.
* 1.03 PGW 22/11/99 Changes relating to restructuring of block map stuff.
* 1.02 PGW 15/07/99 Added bit extraction variables.
* 1.01 PGW 09/07/99 Added code to support profile timing
* 1.00 PGW 28/06/99 New Configuration baseline.
*
*****************************************************************************
*/
#ifndef __INC_PBDLL_H
#define __INC_PBDLL_H
#define VAL_RANGE 256
#include "codec_common.h"
#include "huffman.h"
#include "tokenentropy.h"
#include "vfw_pb_interface.h"
#include "postproc_if.h"
#include "vputil_if.h"
#include "quantize.h"
#include "boolhuff.h"
/****************************************************************************
* Module constants.
*****************************************************************************
*/
#ifdef MAPCA
// switch to turn on the Data streamer
#define DMAREADREFERENCE
#define DMAWRITERECON
#define RECONSTRUCTMBATONCE
#define __inline
#endif
/****************************************************************************
* Types
*****************************************************************************
*/
typedef enum
{
CODE_INTER_NO_MV = 0x0, // INTER prediction, (0,0) motion vector implied.
CODE_INTRA = 0x1, // INTRA i.e. no prediction.
CODE_INTER_PLUS_MV = 0x2, // INTER prediction, non zero motion vector.
CODE_INTER_NEAREST_MV = 0x3, // Use Last Motion vector
CODE_INTER_NEAR_MV = 0x4, // Prior last motion vector
CODE_USING_GOLDEN = 0x5, // 'Golden frame' prediction (no MV).
CODE_GOLDEN_MV = 0x6, // 'Golden frame' prediction plus MV.
CODE_INTER_FOURMV = 0x7, // Inter prediction 4MV per macro block.
CODE_GOLD_NEAREST_MV = 0x8, // Use Last Motion vector
CODE_GOLD_NEAR_MV = 0x9, // Prior last motion vector
DO_NOT_CODE = 0x10 // Fake Mode
} CODING_MODE;
typedef struct
{
unsigned int DisplayFragment : 1;
unsigned int FragCodingMode : 4;
int MVectorX : 6;
int MVectorY : 6;
} FRAG_INFO;
typedef struct _DCINFO
{
Q_LIST_ENTRY dc;
short frame;
} DCINFO;
// defined so i don't have to remember which block goes where
typedef enum
{
TOP_LEFT_Y_BLOCK = 0,
TOP_RIGHT_Y_BLOCK = 1,
BOTTOM_LEFT_Y_BLOCK = 2,
BOTTOM_RIGHT_Y_BLOCK = 3,
U_BLOCK = 4,
V_BLOCK = 5
} BLOCK_POSITION;
// all the information gathered from a block to be used as context in the next block
typedef struct
{
UINT8 Tokens[64];
CODING_MODE Mode;
UINT16 Frame;
Q_LIST_ENTRY Dc;
UINT32 EOBPos;
UINT32 unused;
} BLOCK_CONTEXT;
typedef struct
{
UINT32 EOBPos;
CODING_MODE Mode;
UINT16 Frame;
Q_LIST_ENTRY Dc;
UINT8 Tokens[1];
UINT8 unused[3];
} BLOCK_CONTEXTA;
typedef struct
{
INT16 x;
INT16 y;
} MOTION_VECTORA;
// all the contexts maintained for a frame
typedef struct
{
BLOCK_CONTEXT LeftY[2]; // 1 for each block row in a macroblock
BLOCK_CONTEXT LeftU;
BLOCK_CONTEXT LeftV;
BLOCK_CONTEXTA *AboveY;
BLOCK_CONTEXTA *AboveU;
BLOCK_CONTEXTA *AboveV;
BLOCK_CONTEXTA *AboveYAlloc;
BLOCK_CONTEXTA *AboveUAlloc;
BLOCK_CONTEXTA *AboveVAlloc;
Q_LIST_ENTRY LastDcY[3]; // 1 for each frame
Q_LIST_ENTRY LastDcU[3];
Q_LIST_ENTRY LastDcV[3];
} FRAME_CONTEXT;
// Structure to hold last token values at each position in block
typedef UINT8 TOKENBUFFER[256];
//#define BIT_STATS 1
#ifdef BIT_STATS
#define BIT_STAT_CATEGORIES 8
extern UINT32 BitStats[BIT_STAT_CATEGORIES];
extern UINT8 BitStatCategory;
#endif
typedef struct
{
Q_LIST_ENTRY (*CoeffsAlloc)[72]; // coefficients 64 per frag 4 y in raster order, u then v
Q_LIST_ENTRY (*Coeffs)[72]; // coefficients 64 per frag 4 y in raster order, u then v
CODING_MODE Mode; // mode macroblock coded as
CODING_MODE BlockMode[6]; // mode macroblock coded as
MOTION_VECTOR Mv[6]; // one motion vector per block u and v calculated from rest
MOTION_VECTOR NearestInterMVect;// nearest mv in last frame
MOTION_VECTOR NearInterMVect; // near mv in last frame
MOTION_VECTOR NearestGoldMVect; // nearest mv in gold frame
MOTION_VECTOR NearGoldMVect; // near mv in gold frame
UINT32 MBrow; // mb row
UINT32 MBcol; // mb col
BLOCK_POSITION bp; // block number 0 - 5
UINT32 Source; // address for source (compressor only)
UINT32 SourceY; // starting row
UINT32 SourceX; // starting column
INT32 CurrentSourceStride; // pitch of source (compressor only)
UINT32 Recon; // address in reconstruction buffer of block
INT32 CurrentReconStride; // pitch of reconstruction
UINT32 Plane; // plane block is from
INT32 MvShift; // motion vector shift value
INT32 MvModMask; // motion vector mod mask
INT32 FrameSourceStride; // Stride of the frame
INT32 FrameReconStride; // Stride of the frame
#ifdef RECONSTRUCTMBATONCE
UINT32 ReconIndex[6]; // ReconIndex for each block
#endif
UINT32 SourcePtr[6]; // address for source (compressor only)
UINT32 ReconPtr[6]; // address for source (compressor only)
UINT32 StripPtr[6];
#ifdef DMAREADREFERENCE
INT32 Offset[6];
UINT32 BoundaryX[6];
UINT32 BoundaryY[6];
#endif
BLOCK_CONTEXTA *Above; // above block context
BLOCK_CONTEXT *Left; // left block context
Q_LIST_ENTRY *LastDc; // last dc value seen
INT32 Interlaced; // is the macroblock interlaced?
} MACROBLOCK_INFO;
/****************************************************************************
* MACROS
*****************************************************************************
*/
// Enumeration of how block is coded
#define CURRENT_ENCODE_VERSION 5
#define CURRENT_DECODE_VERSION 5
#define UMV_BORDER 32
#define STRIDE_EXTRA (UMV_BORDER * 2)
#define MAX_MV_EXTENT 31 // Max search distance in half pixel increments
#define MV_ENTROPY_TABLES 16
#define MV_ENTROPY_TOKENS ((MAX_MV_EXTENT * 2) + 1)
#define PPROC_QTHRESH 64
#define MAX_MODES 10
#define DCT_KEY_FRAME 0
#define DEFAULT_HALF_PIXEL_PROB 85
#define DCProbOffset(A,B) \
( (A) * (MAX_ENTROPY_TOKENS-1) \
+ (B) )
#define DCContextOffset(A,B,C,D) \
( (A) * TOKEN_CONTEXTS * TOKEN_CONTEXTS * CONTEXT_NODES \
+ (B) * TOKEN_CONTEXTS * CONTEXT_NODES \
+ (C) * CONTEXT_NODES \
+ (D) )
#define ACProbOffset(A,B,C,D) \
( (A) * PREC_CASES * VP5_AC_BANDS * (MAX_ENTROPY_TOKENS-1) \
+ (B) * VP5_AC_BANDS * (MAX_ENTROPY_TOKENS-1) \
+ (C) * (MAX_ENTROPY_TOKENS-1) \
+ (D) )
#define ACContextOffset(A,B,C,D,E) \
( (A) * PREC_CASES * (VP5_AC_BANDS-3) * TOKEN_CONTEXTS * CONTEXT_NODES \
+ (B) * (VP5_AC_BANDS-3) * TOKEN_CONTEXTS * CONTEXT_NODES \
+ (C) * TOKEN_CONTEXTS * CONTEXT_NODES \
+ (D) * CONTEXT_NODES \
+ (E) )
#define MBOffset(row,col) ( (row) * pbi->MBCols + (col) )
/****************************************************************************
* Global Variables
*****************************************************************************
*/
extern UINT8 LimitVal_VP31[VAL_RANGE * 3];
extern BOOL VP5_ModeUsesMC[MAX_MODES]; // table to indicate if the given mode uses motion estimation
extern const int VP5_Mode2Frame[DO_NOT_CODE];
extern const INT32 CoeffToBand[65];
//****************************************************************
// Function Pointers some probably could be library globals!
// all the information we ever need about a macroblock
typedef struct PB_INSTANCE
{
// Should be able to delete these entries when VP5 complete
INT32 CodedBlockIndex;
UINT8 *DataOutputInPtr;
FRAG_INFO *FragInfo;
FRAG_INFO *FragInfoAlloc;
/* Current access points fopr input and output buffers */
BOOL_CODER br;
//****************************************************************************************
// Decoder and Frame Type Information
UINT8 Vp3VersionNo;
UINT32 DeInterlaceMode;
UINT32 PostProcessingLevel; /* Perform post processing */
UINT32 ProcessorFrequency; /* CPU frequency */
UINT32 CPUFree;
UINT8 FrameType;
UINT8 KeyFrameType;
//****************************************************************************************
//****************************************************************************************
// Frame Size & Index Information
CONFIG_TYPE Configuration; // frame configuration
UINT32 CurrentFrameSize;
UINT32 YPlaneSize;
UINT32 UVPlaneSize;
UINT32 VFragments;
UINT32 HFragments;
UINT32 UnitFragments;
UINT32 YPlaneFragments;
UINT32 UVPlaneFragments;
UINT32 ReconYPlaneSize;
UINT32 ReconUVPlaneSize;
UINT32 YDataOffset;
UINT32 UDataOffset;
UINT32 VDataOffset;
UINT32 ReconYDataOffset;
UINT32 ReconUDataOffset;
UINT32 ReconVDataOffset;
UINT32 MacroBlocks; // Number of Macro-Blocks in Y component
UINT32 MBRows; // Number of rows of MacroBlocks in a Y frame
UINT32 MBCols; // Number of cols of MacroBlocks in a Y frame
UINT32 ScaleWidth;
UINT32 ScaleHeight;
UINT32 OutputWidth;
UINT32 OutputHeight;
UINT32 OutputStride;
//****************************************************************************************
//****************************************************************************************
// Frames
YUV_BUFFER_ENTRY *ThisFrameRecon;
YUV_BUFFER_ENTRY *ThisFrameReconAlloc;
YUV_BUFFER_ENTRY *GoldenFrame;
YUV_BUFFER_ENTRY *GoldenFrameAlloc;
YUV_BUFFER_ENTRY *LastFrameRecon;
YUV_BUFFER_ENTRY *LastFrameReconAlloc;
YUV_BUFFER_ENTRY *PostProcessBuffer;
YUV_BUFFER_ENTRY *PostProcessBufferAlloc;
YUV_BUFFER_ENTRY *ScaleBuffer; /* new buffer for testing new loop filtering scheme */
YUV_BUFFER_ENTRY *ScaleBufferAlloc;
//****************************************************************************************
//****************************************************************************************
Q_LIST_ENTRY *quantized_list;
#ifdef RECONSTRUCTMBATONCE
INT16 (*ReconDataBuffer)[64];
INT16 (*ReconDataBufferAlloc)[64];
#else
INT16 *ReconDataBuffer;
INT16 *ReconDataBufferAlloc;
#endif
UINT8 FragCoefEOB; // Position of last non 0 coef within QFragData
INT16 *TmpReconBuffer;
INT16 *TmpReconBufferAlloc;
INT16 *TmpDataBuffer;
INT16 *TmpDataBufferAlloc;
UINT8 *LoopFilteredBlockAlloc;
UINT8 *LoopFilteredBlock;
#ifdef DMAREADREFERENCE
UINT8 (*ReferenceBlocksAlloc)[192];
UINT8 (*ReferenceBlocks)[192]; // Six Reference Blocks
UINT32 mvX[6], mvY[6];
#endif
#ifdef DMAWRITERECON
#ifdef RECONSTRUCTMBATONCE
UINT8 *ThisBandReconPtr[6]; //Current Band to write to
#else
UINT8 *ThisBandReconPtr; //Current Band to write to
#endif
UINT8 *ReconstructedMBs; //bandbuffer for DMA reconstructed MB row.
UINT8 *ReconstructedMBsAlloc;
UINT8 *FillMem;
#endif
//****************************************************************
void (**idct)(INT16 *InputData, INT16 *QuantMatrix, INT16 * OutputData );
POSTPROC_INST postproc;
QUANTIZER *quantizer;
MACROBLOCK_INFO mbi; // all the information needed for one macroblock
FRAME_CONTEXT fc; // all of the context information needed for a frame
TOKENBUFFER LastToken; // LTIndex of tokens at each position in block
CODING_MODE LastMode; // Last Mode decoded;
UINT8 DcProbs[2*(MAX_ENTROPY_TOKENS-1)];
UINT8 AcProbs[2*PREC_CASES*VP5_AC_BANDS*(MAX_ENTROPY_TOKENS-1)];
UINT8 DcNodeContexts[2*TOKEN_CONTEXTS*TOKEN_CONTEXTS*CONTEXT_NODES]; // Plane, Node, Contexts, Contexts
UINT8 AcNodeContexts[2*PREC_CASES*(VP5_AC_BANDS-3)*TOKEN_CONTEXTS*CONTEXT_NODES]; // Prec, Plane, AcBand, Context, Node
UINT8 ZeroCount;
UINT8 MBModeProb[11];
UINT8 BModeProb[11];
UINT8 Inter00Prob;
UINT32 AvgFrameQIndex;
BOOL testMode;
UINT32 mvNearOffset[16];
int probInterlaced;
char *MBInterlaced;
char *predictionMode;
MOTION_VECTORA *MBMotionVector;
char *MBInterlacedAlloc;
char *predictionModeAlloc;
MOTION_VECTORA *MBMotionVectorAlloc;
UINT8 MvSignProbs[2];
UINT8 MvZeroProbs[2];
UINT8 MvHalfPixelProbs[2];
UINT8 MvLowBitProbs[2];
UINT8 MvSizeProbs[2][((MAX_MV_EXTENT+1) >> 2) - 1];
UINT8 probXmitted[4][2][MAX_MODES];
UINT8 probModeSame[4][MAX_MODES];
UINT8 probMode[4][MAX_MODES][MAX_MODES-1]; // nearest+near,nearest only, nonearest+nonear, 10 preceding modes, 9 nodes
UINT32 maxTimePerFrame;
UINT32 thisDecodeTime;
UINT32 avgDecodeTime;
UINT32 avgPPTime[10];
UINT32 avgBlitTime;
UINT32 BlackClamp;
UINT32 WhiteClamp;
} PB_INSTANCE;
/****************************************************************************
* Functions.
*****************************************************************************
*/
//****************************************************************
// Function Pointers now library globals!
//extern void (*ReadTokens)( xPB_INST pbi, UINT32 BlockSize, UINT32 Hpos );
//****************************************************************
extern PB_INSTANCE * VP5_CreatePBInstance(void);
extern void VP5_DeletePBInstance(PB_INSTANCE **);
extern BOOL VP5_LoadFrame(PB_INSTANCE *pbi);
extern void VP5_SetFrameType(PB_INSTANCE *pbi, UINT8 FrType );
extern UINT8 VP5_GetFrameType(PB_INSTANCE *pbi);
extern BOOL VP5_InitFrameDetails(PB_INSTANCE *pbi);
extern void VP5_ErrorTrap( PB_INSTANCE *pbi, int ErrorCode );
extern BOOL VP5_AllocateFragmentInfo(PB_INSTANCE * pbi);
extern BOOL VP5_AllocateFrameInfo(PB_INSTANCE * pbi, unsigned int FrameSize);
extern void VP5_DeleteFragmentInfo(PB_INSTANCE * pbi);
extern void VP5_DeleteFrameInfo(PB_INSTANCE * pbi);
extern void VP5_DMachineSpecificConfig(void);
INLINE UINT32 VP5_bitread1(BOOL_CODER *br)
{
return (DecodeBool128(br));
}
INLINE UINT32 VP5_bitread(BOOL_CODER *br, int bits)
{
UINT32 z = 0;
int bit;
for(bit=bits-1;bit>=0;bit--)
{
z|=(DecodeBool128(br)<<bit);
}
return z;
}
extern void vp5_appendframe(PB_INSTANCE *pbi);
extern void VP5_readTSC(unsigned long *tsc);
extern void ConfigureContexts(PB_INSTANCE *pbi);
// dx\generic\decodembs.c
extern void ResetAboveContext(PB_INSTANCE* pbi);
extern void ResetLeftContext(PB_INSTANCE* pbi);
extern void UpdateContext(PB_INSTANCE* pbi, BLOCK_CONTEXT* c, BLOCK_POSITION bp);
extern void UpdateContextA(PB_INSTANCE* pbi, BLOCK_CONTEXTA* c, BLOCK_POSITION bp);
extern void PredictDC(PB_INSTANCE* pbi, BLOCK_POSITION bp, Q_LIST_ENTRY* LastDC, BLOCK_CONTEXTA* Above, BLOCK_CONTEXT* Left);
// dx\generic\recon.c
extern void ReconstructBlock(PB_INSTANCE* pbi, BLOCK_POSITION bp);
// dx\generic\decodemode.c
extern CODING_MODE DecodeBlockMode(PB_INSTANCE *pbi);
extern CODING_MODE DecodeMode(PB_INSTANCE *pbi, CODING_MODE lastmode, UINT32 type);
#endif
@@ -0,0 +1,89 @@
#ifndef QUANTIZE_H
#define QUANTIZE_H
#include "codec_common.h"
#include "codec_common_interface.h"
/****************************************************************************
* Structures
*****************************************************************************
*/
typedef struct
{
UINT32 FrameQIndex; // Quality specified as a table index
UINT32 ThisFrameQuantizerValue; // Quality value for this frame
short round[8];
short mult[8];
short zbin[8];
UINT32 LastQuantizerValue; // Quality value for this frame
UINT32 QThreshTable[Q_TABLE_SIZE]; // ac quantizer scale values
UINT32 *transIndex; // array to reorder zig zag to idct's ordering
UINT8 quant_index[64]; // array to reorder from raster to zig zag
// used by the dequantizer
Q_LIST_ENTRY * dequant_coeffs[2]; // pointer to current dequantization tables
Q_LIST_ENTRY * dequant_coeffsAlloc[2]; // alloc so we can keep alligned
INT32 QuantCoeffs[2][64]; // Quantizer values table
INT32 QuantRound[2][64]; // Quantizer rounding table
INT32 ZeroBinSize[2][64]; // Quantizer zero bin table
} QUANTIZER;
/****************************************************************************
* Functions
*****************************************************************************
*/
extern void VP5_InitQTables
(
QUANTIZER *pbi,
UINT8 Vp3VersionNo
);
extern void VP5_UpdateQ
(
QUANTIZER *pbi,
UINT8 Vp3VersionNo
);
extern void VP5_UpdateQC
(
QUANTIZER *pbi,
UINT8 Vp3VersionNo
);
extern void VP5_init_quantizer
(
QUANTIZER *pbi,
UINT8 Vp3VersionNo
);
extern void (*VP5_quantize)
(
QUANTIZER *pbi,
INT16 * DCT_block,
Q_LIST_ENTRY * quantized_list,
UINT8 bp
);
extern void VP5_init_dequantizer
(
QUANTIZER *pbi,
UINT8 Vp3VersionNo
);
extern QUANTIZER * VP5_CreateQuantizer
(
void
);
extern void VP5_DeleteQuantizer
(
QUANTIZER **pbi
);
extern UINT8 QTableSelect[6];
#endif
@@ -0,0 +1,52 @@
/****************************************************************************
*
* Module Title : SystemDependant.h
*
* Description : Miscellaneous system dependant functions header
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.00 PGW 12/10/99 Configuration baseline
*
*****************************************************************************
*/
/*******************************************3*********************************
* Header Files
*****************************************************************************
*/
/****************************************************************************
* Constants
*****************************************************************************
*/
/****************************************************************************
* Types
*****************************************************************************
*/
/****************************************************************************
* Data structures
*****************************************************************************
*/
/****************************************************************************
* Functions
*****************************************************************************
*/
// Test machine config
// Misc.
extern void VP5_IssueWarning( char * WarningMessage );
extern void PauseProcess( unsigned int SleepMs );
// System dynamic memory allocation
char * SytemGlobalAlloc( unsigned int Size );
void SystemGlobalFree( char * MemPtr );
@@ -0,0 +1,129 @@
/****************************************************************************
*
* Module Title : TokenEntropy.h
*
* Description : Video CODEC: Coefficient toke entropy header.
*
* AUTHOR : Paul Wilkins
*
*****************************************************************************
* Revision History
*
* 1.01 PGW 27 Jun 01 Module created.
*
*****************************************************************************
*/
/****************************************************************************
* Header Files
*****************************************************************************
*/
/****************************************************************************
* Header Frames
*****************************************************************************
*/
#ifndef TOKEN_ENTROPY_H
#define TOKEN_ENTROPY_H
#include "type_aliases.h"
#include "boolhuff.h"
#include "codec_common.h"
#include "huffman.h"
/****************************************************************************
* Constants
*****************************************************************************
*/
// VP5 hufman table AC bands
#define VP5_AC_BANDS 6
// Tokens Value Extra Bits (range + sign)
#define ZERO_TOKEN 0 //0 Extra Bits 0+0
#define ONE_TOKEN 1 //1 Extra Bits 0+1
#define TWO_TOKEN 2 //2 Extra Bits 0+1
#define THREE_TOKEN 3 //3 Extra Bits 0+1
#define FOUR_TOKEN 4 //4 Extra Bits 0+1
#define DCT_VAL_CATEGORY1 5 //5-6 Extra Bits 1+1
#define DCT_VAL_CATEGORY2 6 //7-10 Extra Bits 2+1
#define DCT_VAL_CATEGORY3 7 //11-26 Extra Bits 4+1
#define DCT_VAL_CATEGORY4 8 //11-26 Extra Bits 5+1
#define DCT_VAL_CATEGORY5 9 //27-58 Extra Bits 5+1
#define DCT_VAL_CATEGORY6 10 //59+ Extra Bits 11+1
#define DCT_EOB_TOKEN 11 //EOB Extra Bits 0+0
#define MAX_ENTROPY_TOKENS (DCT_EOB_TOKEN + 1)
#define ILLEGAL_TOKEN 255
#define TOKEN_CONTEXTS 6 // EOB, 0, 1, 2, 3-4, x
#define CONTEXT_NODES (MAX_ENTROPY_TOKENS-7)
#define PREC_CASES 3
#define DC_PROBABILITY_UPDATE_THRESH 100
#define ZERO_CONTEXT_NODE 0
#define EOB_CONTEXT_NODE 1
#define ONE_CONTEXT_NODE 2
#define LOW_VAL_CONTEXT_NODE 3
#define TWO_CONTEXT_NODE 4
#define THREE_CONTEXT_NODE 5
#define HIGH_LOW_CONTEXT_NODE 6
#define CAT_ONE_CONTEXT_NODE 7
#define CAT_THREEFOUR_CONTEXT_NODE 8
#define CAT_THREE_CONTEXT_NODE 9
#define CAT_FIVE_CONTEXT_NODE 10
#define PROB_UPDATE_BASELINE_COST 7
#define MAX_PROB 254
#define DCT_MAX_VALUE 2048
/****************************************************************************
* Types
*****************************************************************************
*/
extern const UINT32 ProbCost[256];
extern const UINT8 ExtraBitLengths_VP5[MAX_ENTROPY_TOKENS];
extern const UINT32 DctRangeMinVals[MAX_ENTROPY_TOKENS];
typedef struct LineEq
{
INT32 M;
INT32 C;
} LINE_EQ;
extern const UINT8 DcUpdateProbs[2][MAX_ENTROPY_TOKENS-1];
extern const UINT8 AcUpdateProbs[PREC_CASES][2][VP5_AC_BANDS][MAX_ENTROPY_TOKENS-1];
extern const UINT8 PrevTokenIndex[MAX_ENTROPY_TOKENS];
extern UINT8 PrecZeroRunLength[BLOCK_SIZE];
/****************************************************************************
* Data structures
*****************************************************************************
*/
// These table contains the normailized probabilities required to traverse the
// entropy tree for DC and AC value tokens representing values >= 2
// Probabilities are normalized to 8 bits and represent the likelyhood of a zero branch.
/****************************************************************************
* Functions
*****************************************************************************
*/
#endif
@@ -0,0 +1,37 @@
#ifndef XPRINTF_H
#define XPRINTF_H
//____________________________________________________________________________
//
// File: xprintf.h
//
// Description: Display a printf style message on the current video frame
//
// Author: Keith Looney
//
//____________________________________________________________________________
// Revision History
//
//____________________________________________________________________________
// Includes
#include "pbdll.h"
//____________________________________________________________________________
// Defines
//____________________________________________________________________________
// Declarations
#if __cplusplus
extern "C"
{
#endif
extern int vp5_xprintf(const PB_INSTANCE* ppbi, long pixel, const char* format, ...);
#if __cplusplus
}
#endif
#endif // XPRINTF_H