Add Russian translation provided by Валерий Крувялис <valkru@mail.ru>
[xiph-mirror.git] / theora-old / lib / codec_internal.h
blobb2443d24850d7660bc4369566416ee3a9ac7e290
1 /********************************************************************
2 * *
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7 * *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2005 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
13 function:
14 last mod: $Id$
16 ********************************************************************/
18 #ifndef ENCODER_INTERNAL_H
19 #define ENCODER_INTERNAL_H
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include "theora/theora.h"
26 #include "huffman.h"
27 #include "dsp.h"
29 #ifndef LIBOGG2
30 #define theora_read(x,y,z) ( *z = oggpackB_read(x,y) )
31 #else
32 #define theora_read(x,y,z) ( oggpackB_read(x,y,z) )
33 #endif
35 #ifdef DEBUG
36 #include <stdio.h>
37 #define TH_DEBUG(x) fprintf(stderr, x)
38 #else
39 #define TH_DEBUG(x)
40 #endif
42 #define CURRENT_ENCODE_VERSION 1
43 #define HUGE_ERROR (1<<28) /* Out of range test value */
45 /* Baseline dct height and width. */
46 #define BLOCK_HEIGHT_WIDTH 8
47 #define HFRAGPIXELS 8
48 #define VFRAGPIXELS 8
50 /* Blocks on INTRA/INTER Y/U/V planes */
51 enum BlockMode {
52 BLOCK_Y,
53 BLOCK_U,
54 BLOCK_V,
55 BLOCK_INTER_Y,
56 BLOCK_INTER_U,
57 BLOCK_INTER_V
60 /* Encoding profiles */
61 enum EncodingProfiles {
62 PROFILE_VP3,
63 PROFILE_FULL
66 /* Baseline dct block size */
67 #define BLOCK_SIZE (BLOCK_HEIGHT_WIDTH * BLOCK_HEIGHT_WIDTH)
69 /* Border is for unrestricted mv's */
70 #define UMV_BORDER 16
71 #define STRIDE_EXTRA (UMV_BORDER * 2)
73 #define Q_TABLE_SIZE 64
75 #define KEY_FRAME 0
76 #define DELTA_FRAME 1
78 #define MAX_MODES 8
79 #define MODE_BITS 3
80 #define MODE_METHODS 8
81 #define MODE_METHOD_BITS 3
83 /* Different key frame types/methods */
84 #define DCT_KEY_FRAME 0
86 #define KEY_FRAME_CONTEXT 5
88 /* Preprocessor defines */
89 #define MAX_PREV_FRAMES 16
91 /* Number of search sites for a 4-step search (at pixel accuracy) */
92 #define MAX_SEARCH_SITES 33
94 #define VERY_BEST_Q 10
95 #define MIN_BPB_FACTOR 0.3
96 #define MAX_BPB_FACTOR 3.0
98 #define MAX_MV_EXTENT 31 /* Max search distance in half pixel increments */
100 typedef struct CONFIG_TYPE2{
101 double OutputFrameRate;
102 ogg_uint32_t TargetBandwidth;
103 ogg_uint32_t KeyFrameDataTarget ; /* Data rate target for key frames */
105 ogg_uint32_t FirstFrameQ;
106 ogg_uint32_t BaseQ;
107 ogg_uint32_t MaxQ; /* Absolute Max Q allowed. */
108 ogg_uint32_t ActiveMaxQ; /* Currently active Max Q */
110 } CONFIG_TYPE2;
112 typedef struct coeffNode{
113 int i;
114 struct coeffNode *next;
115 } COEFFNODE;
117 typedef struct{
118 unsigned char * Yuv0ptr;
119 unsigned char * Yuv1ptr;
120 unsigned char * SrfWorkSpcPtr;
121 unsigned char * disp_fragments;
123 ogg_uint32_t * RegionIndex; /* Gives pixel index for top left of
124 each block */
125 ogg_uint32_t VideoFrameHeight;
126 ogg_uint32_t VideoFrameWidth;
128 } SCAN_CONFIG_DATA;
130 typedef unsigned char YUV_BUFFER_ENTRY;
132 typedef struct{
133 ogg_int32_t x;
134 ogg_int32_t y;
135 } MOTION_VECTOR;
137 typedef MOTION_VECTOR COORDINATE;
139 /** Quantizer matrix entry */
140 typedef ogg_int16_t Q_LIST_ENTRY;
142 /** Decode Post-Processor instance */
143 typedef struct PP_INSTANCE {
144 ogg_uint32_t PrevFrameLimit;
146 ogg_uint32_t *ScanPixelIndexTable;
147 signed char *ScanDisplayFragments;
149 signed char *PrevFragments[MAX_PREV_FRAMES];
151 ogg_uint32_t *FragScores; /* The individual frame difference ratings. */
152 signed char *SameGreyDirPixels;
153 signed char *BarBlockMap;
155 /* Number of pixels changed by diff threshold in row of a fragment. */
156 unsigned char *FragDiffPixels;
158 unsigned char *PixelScores;
159 unsigned char *PixelChangedMap;
160 unsigned char *ChLocals;
161 ogg_int16_t *yuv_differences;
162 ogg_int32_t *RowChangedPixels;
163 signed char *TmpCodedMap;
165 /* Plane pointers and dimension variables */
166 unsigned char * YPlanePtr0;
167 unsigned char * YPlanePtr1;
168 unsigned char * UPlanePtr0;
169 unsigned char * UPlanePtr1;
170 unsigned char * VPlanePtr0;
171 unsigned char * VPlanePtr1;
173 ogg_uint32_t VideoYPlaneWidth;
174 ogg_uint32_t VideoYPlaneHeight;
175 ogg_uint32_t VideoUVPlaneWidth;
176 ogg_uint32_t VideoUVPlaneHeight;
178 ogg_uint32_t VideoYPlaneStride;
179 ogg_uint32_t VideoUPlaneStride;
180 ogg_uint32_t VideoVPlaneStride;
182 /* Scan control variables. */
183 unsigned char HFragPixels;
184 unsigned char VFragPixels;
186 ogg_uint32_t ScanFrameFragments;
187 ogg_uint32_t ScanYPlaneFragments;
188 ogg_uint32_t ScanUVPlaneFragments;
189 ogg_uint32_t ScanHFragments;
190 ogg_uint32_t ScanVFragments;
192 ogg_uint32_t YFramePixels;
193 ogg_uint32_t UVFramePixels;
195 ogg_uint32_t SgcThresh;
197 ogg_uint32_t OutputBlocksUpdated;
198 ogg_uint32_t KFIndicator;
200 /* The pre-processor scan configuration. */
201 SCAN_CONFIG_DATA ScanConfig;
203 ogg_int32_t SRFGreyThresh;
204 ogg_int32_t SRFColThresh;
205 ogg_int32_t SgcLevelThresh;
206 ogg_int32_t SuvcLevelThresh;
208 ogg_uint32_t NoiseSupLevel;
210 /* Block Thresholds. */
211 ogg_uint32_t PrimaryBlockThreshold;
212 unsigned char LineSearchTripTresh;
214 int PAKEnabled;
216 int LevelThresh;
217 int NegLevelThresh;
218 int SrfThresh;
219 int NegSrfThresh;
220 int HighChange;
221 int NegHighChange;
223 /* Threshold lookup tables */
224 unsigned char SrfPakThreshTable[512];
225 unsigned char SrfThreshTable[512];
226 unsigned char SgcThreshTable[512];
228 /* Variables controlling S.A.D. break outs. */
229 ogg_uint32_t GrpLowSadThresh;
230 ogg_uint32_t GrpHighSadThresh;
231 ogg_uint32_t ModifiedGrpLowSadThresh;
232 ogg_uint32_t ModifiedGrpHighSadThresh;
234 ogg_int32_t PlaneHFragments;
235 ogg_int32_t PlaneVFragments;
236 ogg_int32_t PlaneHeight;
237 ogg_int32_t PlaneWidth;
238 ogg_int32_t PlaneStride;
240 ogg_uint32_t BlockThreshold;
241 ogg_uint32_t BlockSgcThresh;
242 double UVBlockThreshCorrection;
243 double UVSgcCorrection;
245 double YUVPlaneCorrectionFactor;
246 double AbsDiff_ScoreMultiplierTable[256];
247 unsigned char NoiseScoreBoostTable[256];
248 unsigned char MaxLineSearchLen;
250 ogg_int32_t YuvDiffsCircularBufferSize;
251 ogg_int32_t ChLocalsCircularBufferSize;
252 ogg_int32_t PixelMapCircularBufferSize;
254 DspFunctions dsp; /* Selected functions for this platform */
256 } PP_INSTANCE;
258 /** block coding modes */
259 typedef enum{
260 CODE_INTER_NO_MV = 0x0, /* INTER prediction, (0,0) motion
261 vector implied. */
262 CODE_INTRA = 0x1, /* INTRA i.e. no prediction. */
263 CODE_INTER_PLUS_MV = 0x2, /* INTER prediction, non zero motion
264 vector. */
265 CODE_INTER_LAST_MV = 0x3, /* Use Last Motion vector */
266 CODE_INTER_PRIOR_LAST = 0x4, /* Prior last motion vector */
267 CODE_USING_GOLDEN = 0x5, /* 'Golden frame' prediction (no MV). */
268 CODE_GOLDEN_MV = 0x6, /* 'Golden frame' prediction plus MV. */
269 CODE_INTER_FOURMV = 0x7 /* Inter prediction 4MV per macro block. */
270 } CODING_MODE;
272 /** Huffman table entry */
273 typedef struct HUFF_ENTRY {
274 struct HUFF_ENTRY *ZeroChild;
275 struct HUFF_ENTRY *OneChild;
276 struct HUFF_ENTRY *Previous;
277 struct HUFF_ENTRY *Next;
278 ogg_int32_t Value;
279 ogg_uint32_t Frequency;
281 } HUFF_ENTRY;
283 typedef struct qmat_range_table {
284 int startq, startqi; /* index where this range starts */
285 Q_LIST_ENTRY *qmat; /* qmat at this range boundary */
286 } qmat_range_table;
288 /** codec setup data, maps to the third bitstream header */
289 typedef struct codec_setup_info {
290 ogg_uint32_t QThreshTable[Q_TABLE_SIZE];
291 Q_LIST_ENTRY DcScaleFactorTable[Q_TABLE_SIZE];
293 int MaxQMatrixIndex;
294 Q_LIST_ENTRY *qmats;
295 qmat_range_table *range_table[6];
297 HUFF_ENTRY *HuffRoot[NUM_HUFF_TABLES];
299 unsigned char LoopFilterLimitValues[Q_TABLE_SIZE];
300 } codec_setup_info;
302 /** Decoder (Playback) instance -- installed in a theora_state */
303 typedef struct PB_INSTANCE {
304 oggpack_buffer *opb;
305 theora_info info;
306 /* how far do we shift the granulepos to seperate out P frame counts? */
307 int keyframe_granule_shift;
310 /***********************************************************************/
311 /* Decoder and Frame Type Information */
313 int DecoderErrorCode;
314 int FramesHaveBeenSkipped;
316 int PostProcessEnabled;
317 ogg_uint32_t PostProcessingLevel; /* Perform post processing */
319 /* Frame Info */
320 CODING_MODE CodingMode;
321 unsigned char FrameType;
322 unsigned char KeyFrameType;
323 ogg_uint32_t QualitySetting;
324 ogg_uint32_t FrameQIndex; /* Quality specified as a
325 table index */
326 ogg_uint32_t ThisFrameQualityValue; /* Quality value for this frame */
327 ogg_uint32_t LastFrameQualityValue; /* Last Frame's Quality */
328 ogg_int32_t CodedBlockIndex; /* Number of Coded Blocks */
329 ogg_uint32_t CodedBlocksThisFrame; /* Index into coded blocks */
330 ogg_uint32_t FrameSize; /* The number of bytes in the frame. */
332 /**********************************************************************/
333 /* Frame Size & Index Information */
335 ogg_uint32_t YPlaneSize;
336 ogg_uint32_t UVPlaneSize;
337 ogg_uint32_t YStride;
338 ogg_uint32_t UVStride;
339 ogg_uint32_t VFragments;
340 ogg_uint32_t HFragments;
341 ogg_uint32_t UnitFragments;
342 ogg_uint32_t YPlaneFragments;
343 ogg_uint32_t UVPlaneFragments;
345 ogg_uint32_t ReconYPlaneSize;
346 ogg_uint32_t ReconUVPlaneSize;
348 ogg_uint32_t YDataOffset;
349 ogg_uint32_t UDataOffset;
350 ogg_uint32_t VDataOffset;
351 ogg_uint32_t ReconYDataOffset;
352 ogg_uint32_t ReconUDataOffset;
353 ogg_uint32_t ReconVDataOffset;
354 ogg_uint32_t YSuperBlocks; /* Number of SuperBlocks in a Y frame */
355 ogg_uint32_t UVSuperBlocks; /* Number of SuperBlocks in a U or V frame */
356 ogg_uint32_t SuperBlocks; /* Total number of SuperBlocks in a
357 Y,U,V frame */
359 ogg_uint32_t YSBRows; /* Number of rows of SuperBlocks in a
360 Y frame */
361 ogg_uint32_t YSBCols; /* Number of cols of SuperBlocks in a
362 Y frame */
363 ogg_uint32_t UVSBRows; /* Number of rows of SuperBlocks in a
364 U or V frame */
365 ogg_uint32_t UVSBCols; /* Number of cols of SuperBlocks in a
366 U or V frame */
368 ogg_uint32_t YMacroBlocks; /* Number of Macro-Blocks in Y component */
369 ogg_uint32_t UVMacroBlocks; /* Number of Macro-Blocks in U/V component */
370 ogg_uint32_t MacroBlocks; /* Total number of Macro-Blocks */
372 /**********************************************************************/
373 /* Frames */
374 YUV_BUFFER_ENTRY *ThisFrameRecon;
375 YUV_BUFFER_ENTRY *GoldenFrame;
376 YUV_BUFFER_ENTRY *LastFrameRecon;
377 YUV_BUFFER_ENTRY *PostProcessBuffer;
379 /**********************************************************************/
380 /* Fragment Information */
381 ogg_uint32_t *pixel_index_table; /* start address of first
382 pixel of fragment in
383 source */
384 ogg_uint32_t *recon_pixel_index_table; /* start address of first
385 pixel in recon buffer */
387 unsigned char *display_fragments; /* Fragment update map */
388 unsigned char *skipped_display_fragments;/* whether fragment YUV
389 Conversion and update is to be
390 skipped */
391 ogg_int32_t *CodedBlockList; /* A list of fragment indices for
392 coded blocks. */
393 MOTION_VECTOR *FragMVect; /* fragment motion vectors */
395 ogg_uint32_t *FragTokenCounts; /* Number of tokens per fragment */
396 ogg_uint32_t (*TokenList)[128]; /* Fragment Token Pointers */
398 ogg_int32_t *FragmentVariances;
399 ogg_uint32_t *FragQIndex; /* Fragment Quality used in
400 PostProcess */
401 Q_LIST_ENTRY (*PPCoefBuffer)[64]; /* PostProcess Buffer for
402 coefficients data */
404 unsigned char *FragCoeffs; /* # of coeffs decoded so far for
405 fragment */
406 unsigned char *FragCoefEOB; /* Position of last non 0 coef
407 within QFragData */
408 Q_LIST_ENTRY (*QFragData)[64]; /* Fragment Coefficients
409 Array Pointers */
410 CODING_MODE *FragCodingMethod; /* coding method for the
411 fragment */
413 /***********************************************************************/
414 /* pointers to addresses used for allocation and deallocation the
415 others are rounded up to the nearest 32 bytes */
417 COEFFNODE *_Nodes;
418 ogg_uint32_t *transIndex; /* ptr to table of
419 transposed indexes */
421 /***********************************************************************/
422 ogg_int32_t bumpLast;
424 /* Macro Block and SuperBlock Information */
425 ogg_int32_t (*BlockMap)[4][4]; /* super block + sub macro
426 block + sub frag ->
427 FragIndex */
429 /* Coded flag arrays and counters for them */
430 unsigned char *SBCodedFlags;
431 unsigned char *SBFullyFlags;
432 unsigned char *MBCodedFlags;
433 unsigned char *MBFullyFlags;
435 /**********************************************************************/
436 ogg_uint32_t EOB_Run;
438 COORDINATE *FragCoordinates;
439 MOTION_VECTOR MVector;
440 ogg_int32_t ReconPtr2Offset; /* Offset for second reconstruction
441 in half pixel MC */
442 Q_LIST_ENTRY *quantized_list;
443 ogg_int16_t *ReconDataBuffer;
444 Q_LIST_ENTRY InvLastIntraDC;
445 Q_LIST_ENTRY InvLastInterDC;
446 Q_LIST_ENTRY LastIntraDC;
447 Q_LIST_ENTRY LastInterDC;
449 ogg_uint32_t BlocksToDecode; /* Blocks to be decoded this frame */
450 ogg_uint32_t DcHuffChoice; /* Huffman table selection variables */
451 unsigned char ACHuffChoice;
452 ogg_uint32_t QuadMBListIndex;
454 ogg_int32_t ByteCount;
456 ogg_uint32_t bit_pattern;
457 unsigned char bits_so_far;
458 unsigned char NextBit;
459 ogg_int32_t BitsLeft;
461 ogg_int16_t *DequantBuffer;
463 ogg_int32_t fp_quant_InterUV_coeffs[64];
464 ogg_int32_t fp_quant_InterUV_round[64];
465 ogg_int32_t fp_ZeroBinSize_InterUV[64];
467 ogg_int16_t *TmpReconBuffer;
468 ogg_int16_t *TmpDataBuffer;
470 /* Loop filter bounding values */
471 unsigned char LoopFilterLimits[Q_TABLE_SIZE];
472 ogg_int16_t FiltBoundingValue[256];
474 /* encoder profiles differ by their quantization table usage */
475 int encoder_profile;
477 /* Naming convention for all quant matrices and related data structures:
478 * Fields containing "Inter" in their name are for Inter frames, the
479 * rest is Intra. */
481 /* Dequantiser and rounding tables */
482 ogg_uint32_t QThreshTable[Q_TABLE_SIZE];
483 Q_LIST_ENTRY DcScaleFactorTable[Q_TABLE_SIZE];
484 Q_LIST_ENTRY Y_coeffs[64];
485 Q_LIST_ENTRY U_coeffs[64];
486 Q_LIST_ENTRY V_coeffs[64];
487 Q_LIST_ENTRY InterY_coeffs[64];
488 Q_LIST_ENTRY InterU_coeffs[64];
489 Q_LIST_ENTRY InterV_coeffs[64];
490 Q_LIST_ENTRY *dequant_Y_coeffs;
491 Q_LIST_ENTRY *dequant_U_coeffs;
492 Q_LIST_ENTRY *dequant_V_coeffs;
493 Q_LIST_ENTRY *dequant_InterY_coeffs;
494 Q_LIST_ENTRY *dequant_InterU_coeffs;
495 Q_LIST_ENTRY *dequant_InterV_coeffs;
496 Q_LIST_ENTRY *dequant_coeffs; /* currently active quantizer */
497 unsigned int zigzag_index[64];
498 ogg_int32_t quant_Y_coeffs[64];
499 ogg_int32_t quant_UV_coeffs[64];
502 HUFF_ENTRY *HuffRoot_VP3x[NUM_HUFF_TABLES];
503 ogg_uint32_t *HuffCodeArray_VP3x[NUM_HUFF_TABLES];
504 unsigned char *HuffCodeLengthArray_VP3x[NUM_HUFF_TABLES];
505 const unsigned char *ExtraBitLengths_VP3x;
507 /* Quantiser and rounding tables */
508 ogg_int32_t fp_quant_Y_coeffs[64]; /* used in reiniting quantizers */
509 ogg_int32_t fp_quant_U_coeffs[64];
510 ogg_int32_t fp_quant_V_coeffs[64];
511 ogg_int32_t fp_quant_Inter_Y_coeffs[64];
512 ogg_int32_t fp_quant_Inter_U_coeffs[64];
513 ogg_int32_t fp_quant_Inter_V_coeffs[64];
515 ogg_int32_t fp_quant_Y_round[64];
516 ogg_int32_t fp_quant_U_round[64];
517 ogg_int32_t fp_quant_V_round[64];
518 ogg_int32_t fp_quant_Inter_Y_round[64];
519 ogg_int32_t fp_quant_Inter_U_round[64];
520 ogg_int32_t fp_quant_Inter_V_round[64];
522 ogg_int32_t fp_ZeroBinSize_Y[64];
523 ogg_int32_t fp_ZeroBinSize_U[64];
524 ogg_int32_t fp_ZeroBinSize_V[64];
525 ogg_int32_t fp_ZeroBinSize_Inter_Y[64];
526 ogg_int32_t fp_ZeroBinSize_Inter_U[64];
527 ogg_int32_t fp_ZeroBinSize_Inter_V[64];
529 ogg_int32_t *fquant_coeffs;
530 ogg_int32_t *fquant_round;
531 ogg_int32_t *fquant_ZbSize;
533 /* Predictor used in choosing entropy table for decoding block patterns. */
534 unsigned char BlockPatternPredictor;
536 short Modifier[4][512];
537 short *ModifierPointer[4];
539 unsigned char *DataOutputInPtr;
541 DspFunctions dsp; /* Selected functions for this platform */
543 } PB_INSTANCE;
545 /* Encoder (Compressor) instance -- installed in a theora_state */
546 typedef struct CP_INSTANCE {
548 /* Compressor Configuration */
549 SCAN_CONFIG_DATA ScanConfig;
550 CONFIG_TYPE2 Configuration;
551 int GoldenFrameEnabled;
552 int InterPrediction;
553 int MotionCompensation;
555 ogg_uint32_t LastKeyFrame ;
556 ogg_int32_t DropCount ;
557 ogg_int32_t MaxConsDroppedFrames ;
558 ogg_int32_t DropFrameTriggerBytes;
559 int DropFrameCandidate;
561 /* Compressor Statistics */
562 double TotErrScore;
563 ogg_int64_t KeyFrameCount; /* Count of key frames. */
564 ogg_int64_t TotKeyFrameBytes;
565 ogg_uint32_t LastKeyFrameSize;
566 ogg_uint32_t PriorKeyFrameSize[KEY_FRAME_CONTEXT];
567 ogg_uint32_t PriorKeyFrameDistance[KEY_FRAME_CONTEXT];
568 ogg_int32_t FrameQuality[6];
569 int DecoderErrorCode; /* Decoder error flag. */
570 ogg_int32_t ThreshMapThreshold;
571 ogg_int32_t TotalMotionScore;
572 ogg_int64_t TotalByteCount;
573 ogg_int32_t FixedQ;
575 /* Frame Statistics */
576 signed char InterCodeCount;
577 ogg_int64_t CurrentFrame;
578 ogg_int64_t CarryOver ;
579 ogg_uint32_t LastFrameSize;
580 ogg_uint32_t FrameBitCount;
581 int ThisIsFirstFrame;
582 int ThisIsKeyFrame;
584 ogg_int32_t MotionScore;
585 ogg_uint32_t RegulationBlocks;
586 ogg_int32_t RecoveryMotionScore;
587 int RecoveryBlocksAdded ;
588 double ProportionRecBlocks;
589 double MaxRecFactor ;
591 /* Rate Targeting variables. */
592 ogg_uint32_t ThisFrameTargetBytes;
593 double BpbCorrectionFactor;
595 /* Up regulation variables */
596 ogg_uint32_t FinalPassLastPos; /* Used to regulate a final
597 unrestricted high quality
598 pass. */
599 ogg_uint32_t LastEndSB; /* Where we were in the loop
600 last time. */
601 ogg_uint32_t ResidueLastEndSB; /* Where we were in the residue
602 update loop last time. */
604 /* Controlling Block Selection */
605 ogg_uint32_t MVChangeFactor;
606 ogg_uint32_t FourMvChangeFactor;
607 ogg_uint32_t MinImprovementForNewMV;
608 ogg_uint32_t ExhaustiveSearchThresh;
609 ogg_uint32_t MinImprovementForFourMV;
610 ogg_uint32_t FourMVThreshold;
612 /* Module shared data structures. */
613 ogg_int32_t frame_target_rate;
614 ogg_int32_t BaseLineFrameTargetRate;
615 ogg_int32_t min_blocks_per_frame;
616 ogg_uint32_t tot_bytes_old;
618 /*********************************************************************/
619 /* Frames Used in the selecetive convolution filtering of the Y plane. */
620 unsigned char *ConvDestBuffer;
621 YUV_BUFFER_ENTRY *yuv0ptr;
622 YUV_BUFFER_ENTRY *yuv1ptr;
623 /*********************************************************************/
625 /*********************************************************************/
626 /* Token Buffers */
627 ogg_uint32_t *OptimisedTokenListEb; /* Optimised token list extra bits */
628 unsigned char *OptimisedTokenList; /* Optimised token list. */
629 unsigned char *OptimisedTokenListHi; /* Optimised token list huffman
630 table index */
632 unsigned char *OptimisedTokenListPl; /* Plane to which the token
633 belongs Y = 0 or UV = 1 */
634 ogg_int32_t OptimisedTokenCount; /* Count of Optimized tokens */
635 ogg_uint32_t RunHuffIndex; /* Huffman table in force at
636 the start of a run */
637 ogg_uint32_t RunPlaneIndex; /* The plane (Y=0 UV=1) to
638 which the first token in
639 an EOB run belonged. */
642 ogg_uint32_t TotTokenCount;
643 ogg_int32_t TokensToBeCoded;
644 ogg_int32_t TokensCoded;
645 /********************************************************************/
647 /* SuperBlock, MacroBLock and Fragment Information */
648 /* Coded flag arrays and counters for them */
649 unsigned char *PartiallyCodedFlags;
650 unsigned char *PartiallyCodedMbPatterns;
651 unsigned char *UncodedMbFlags;
653 unsigned char *extra_fragments; /* extra updates not
654 recommended by pre-processor */
655 ogg_int16_t *OriginalDC;
657 ogg_uint32_t *FragmentLastQ; /* Array used to keep track of
658 quality at which each
659 fragment was last
660 updated. */
661 unsigned char *FragTokens;
662 ogg_uint32_t *FragTokenCounts; /* Number of tokens per fragment */
664 ogg_uint32_t *RunHuffIndices;
665 ogg_uint32_t *LastCodedErrorScore;
666 ogg_uint32_t *ModeList;
667 MOTION_VECTOR *MVList;
669 unsigned char *BlockCodedFlags;
671 ogg_uint32_t MvListCount;
672 ogg_uint32_t ModeListCount;
675 unsigned char *DataOutputBuffer;
676 /*********************************************************************/
678 ogg_uint32_t RunLength;
679 ogg_uint32_t MaxBitTarget; /* Cut off target for rate capping */
680 double BitRateCapFactor; /* Factor relating delta frame target
681 to cut off target. */
683 unsigned char MBCodingMode; /* Coding mode flags */
685 ogg_int32_t MVPixelOffsetY[MAX_SEARCH_SITES];
686 ogg_uint32_t InterTripOutThresh;
687 unsigned char MVEnabled;
688 ogg_uint32_t MotionVectorSearchCount;
689 ogg_uint32_t FrameMVSearcOunt;
690 ogg_int32_t MVSearchSteps;
691 ogg_int32_t MVOffsetX[MAX_SEARCH_SITES];
692 ogg_int32_t MVOffsetY[MAX_SEARCH_SITES];
693 ogg_int32_t HalfPixelRef2Offset[9]; /* Offsets for half pixel
694 compensation */
695 signed char HalfPixelXOffset[9]; /* Half pixel MV offsets for X */
696 signed char HalfPixelYOffset[9]; /* Half pixel MV offsets for Y */
698 ogg_uint32_t bit_pattern ;
699 unsigned char bits_so_far ;
700 ogg_uint32_t lastval ;
701 ogg_uint32_t lastrun ;
703 Q_LIST_ENTRY *quantized_list;
705 MOTION_VECTOR MVector;
706 ogg_uint32_t TempBitCount;
707 ogg_int16_t *DCT_codes; /* Buffer that stores the result of
708 Forward DCT */
709 ogg_int16_t *DCTDataBuffer; /* Input data buffer for Forward DCT */
711 /* Motion compensation related variables */
712 ogg_uint32_t MvMaxExtent;
714 double QTargetModifier[Q_TABLE_SIZE];
716 /* instances (used for reconstructing buffers and to hold tokens etc.) */
717 PP_INSTANCE pp; /* preprocessor */
718 PB_INSTANCE pb; /* playback */
720 /* ogg bitpacker for use in packet coding, other API state */
721 oggpack_buffer *oggbuffer;
722 #ifdef LIBOGG2 /* Remember, this is just until we drop libogg1 */
723 ogg_buffer_state *oggbufferstate;
724 #endif
725 int readyflag;
726 int packetflag;
727 int doneflag;
729 DspFunctions dsp; /* Selected functions for this platform */
731 } CP_INSTANCE;
733 #define clamp255(x) ((unsigned char)((((x)<0)-1) & ((x) | -((x)>255))))
735 extern void ConfigurePP( PP_INSTANCE *ppi, int Level ) ;
736 extern ogg_uint32_t YUVAnalyseFrame( PP_INSTANCE *ppi,
737 ogg_uint32_t * KFIndicator );
739 extern void ClearPPInstance(PP_INSTANCE *ppi);
740 extern void InitPPInstance(PP_INSTANCE *ppi, DspFunctions *funcs);
741 extern int GetFrameType(PB_INSTANCE *pbi);
742 extern void InitPBInstance(PB_INSTANCE *pbi);
743 extern void ClearPBInstance(PB_INSTANCE *pbi);
745 extern void IDct1( Q_LIST_ENTRY * InputData,
746 ogg_int16_t *QuantMatrix,
747 ogg_int16_t * OutputData );
749 extern void ReconIntra( PB_INSTANCE *pbi, unsigned char * ReconPtr,
750 ogg_int16_t * ChangePtr, ogg_uint32_t LineStep );
752 extern void ReconInter( PB_INSTANCE *pbi, unsigned char * ReconPtr,
753 unsigned char * RefPtr, ogg_int16_t * ChangePtr,
754 ogg_uint32_t LineStep ) ;
756 extern void ReconInterHalfPixel2( PB_INSTANCE *pbi, unsigned char * ReconPtr,
757 unsigned char * RefPtr1,
758 unsigned char * RefPtr2,
759 ogg_int16_t * ChangePtr,
760 ogg_uint32_t LineStep ) ;
762 extern void SetupLoopFilter(PB_INSTANCE *pbi);
763 extern void CopyBlock(unsigned char *src,
764 unsigned char *dest,
765 unsigned int srcstride);
766 extern void LoopFilter(PB_INSTANCE *pbi);
767 extern void ReconRefFrames (PB_INSTANCE *pbi);
768 extern void ExpandToken( Q_LIST_ENTRY * ExpandedBlock,
769 unsigned char * CoeffIndex, ogg_uint32_t Token,
770 ogg_int32_t ExtraBits );
771 extern void ClearDownQFragData(PB_INSTANCE *pbi);
773 extern void select_quantiser (PB_INSTANCE *pbi, int type);
775 extern void quantize( PB_INSTANCE *pbi,
776 ogg_int16_t * DCT_block,
777 Q_LIST_ENTRY * quantized_list);
778 extern void UpdateQ( PB_INSTANCE *pbi, int NewQIndex );
779 extern void UpdateQC( CP_INSTANCE *cpi, ogg_uint32_t NewQ );
780 extern void fdct_short ( ogg_int16_t * InputData, ogg_int16_t * OutputData );
781 extern ogg_uint32_t DPCMTokenizeBlock (CP_INSTANCE *cpi,
782 ogg_int32_t FragIndex);
783 extern void TransformQuantizeBlock (CP_INSTANCE *cpi, ogg_int32_t FragIndex,
784 ogg_uint32_t PixelsPerLine ) ;
785 extern void ClearFragmentInfo(PB_INSTANCE * pbi);
786 extern void InitFragmentInfo(PB_INSTANCE * pbi);
787 extern void ClearFrameInfo(PB_INSTANCE * pbi);
788 extern void InitFrameInfo(PB_INSTANCE * pbi, unsigned int FrameSize);
789 extern void InitializeFragCoordinates(PB_INSTANCE *pbi);
790 extern void InitFrameDetails(PB_INSTANCE *pbi);
791 extern void WriteQTables(PB_INSTANCE *pbi,oggpack_buffer *opb);
792 extern int ReadQTables(codec_setup_info *ci,oggpack_buffer* opb);
793 extern void CopyQTables(PB_INSTANCE *pbi, codec_setup_info *ci);
794 extern void InitQTables( PB_INSTANCE *pbi );
795 extern void InitHuffmanSet( PB_INSTANCE *pbi );
796 extern void ClearHuffmanSet( PB_INSTANCE *pbi );
797 extern int ReadHuffmanTrees(codec_setup_info *ci, oggpack_buffer *opb);
798 extern void WriteHuffmanTrees(HUFF_ENTRY *HuffRoot[NUM_HUFF_TABLES],
799 oggpack_buffer *opb);
800 extern void InitHuffmanTrees(PB_INSTANCE *pbi, const codec_setup_info *ci);
801 extern void ClearHuffmanTrees(HUFF_ENTRY *HuffRoot[NUM_HUFF_TABLES]);
802 extern void WriteFilterTables(PB_INSTANCE *pbi, oggpack_buffer *opb);
803 extern int ReadFilterTables(codec_setup_info *ci, oggpack_buffer *opb);
804 extern void CopyFilterTables(PB_INSTANCE *pbi, codec_setup_info *ci);
805 extern void InitFilterTables(PB_INSTANCE *pbi);
806 extern void QuadDecodeDisplayFragments ( PB_INSTANCE *pbi );
807 extern void PackAndWriteDFArray( CP_INSTANCE *cpi );
808 extern void UpdateFragQIndex(PB_INSTANCE *pbi);
809 extern void PostProcess(PB_INSTANCE *pbi);
810 extern void InitMotionCompensation ( CP_INSTANCE *cpi );
811 extern ogg_uint32_t GetMBIntraError (CP_INSTANCE *cpi, ogg_uint32_t FragIndex,
812 ogg_uint32_t PixelsPerLine ) ;
813 extern ogg_uint32_t GetMBInterError (CP_INSTANCE *cpi,
814 unsigned char * SrcPtr,
815 unsigned char * RefPtr,
816 ogg_uint32_t FragIndex,
817 ogg_int32_t LastXMV,
818 ogg_int32_t LastYMV,
819 ogg_uint32_t PixelsPerLine ) ;
820 extern void WriteFrameHeader( CP_INSTANCE *cpi) ;
821 extern ogg_uint32_t GetMBMVInterError (CP_INSTANCE *cpi,
822 unsigned char * RefFramePtr,
823 ogg_uint32_t FragIndex,
824 ogg_uint32_t PixelsPerLine,
825 ogg_int32_t *MVPixelOffset,
826 MOTION_VECTOR *MV );
827 extern ogg_uint32_t GetMBMVExhaustiveSearch (CP_INSTANCE *cpi,
828 unsigned char * RefFramePtr,
829 ogg_uint32_t FragIndex,
830 ogg_uint32_t PixelsPerLine,
831 MOTION_VECTOR *MV );
832 extern ogg_uint32_t GetFOURMVExhaustiveSearch (CP_INSTANCE *cpi,
833 unsigned char * RefFramePtr,
834 ogg_uint32_t FragIndex,
835 ogg_uint32_t PixelsPerLine,
836 MOTION_VECTOR *MV ) ;
837 extern ogg_uint32_t EncodeData(CP_INSTANCE *cpi);
838 extern ogg_uint32_t PickIntra( CP_INSTANCE *cpi,
839 ogg_uint32_t SBRows,
840 ogg_uint32_t SBCols);
841 extern ogg_uint32_t PickModes(CP_INSTANCE *cpi,
842 ogg_uint32_t SBRows,
843 ogg_uint32_t SBCols,
844 ogg_uint32_t PixelsPerLine,
845 ogg_uint32_t *InterError,
846 ogg_uint32_t *IntraError);
848 extern CODING_MODE FrArrayUnpackMode(PB_INSTANCE *pbi);
849 extern void CreateBlockMapping ( ogg_int32_t (*BlockMap)[4][4],
850 ogg_uint32_t YSuperBlocks,
851 ogg_uint32_t UVSuperBlocks,
852 ogg_uint32_t HFrags, ogg_uint32_t VFrags );
853 extern void UpRegulateDataStream (CP_INSTANCE *cpi, ogg_uint32_t RegulationQ,
854 ogg_int32_t RecoveryBlocks ) ;
855 extern void RegulateQ( CP_INSTANCE *cpi, ogg_int32_t UpdateScore );
856 extern void CopyBackExtraFrags(CP_INSTANCE *cpi);
858 extern void UpdateUMVBorder( PB_INSTANCE *pbi,
859 unsigned char * DestReconPtr );
860 extern void PInitFrameInfo(PP_INSTANCE * ppi);
861 extern int GetFrameType(PB_INSTANCE *pbi);
862 extern void SetFrameType( PB_INSTANCE *pbi,unsigned char FrType );
863 extern double GetEstimatedBpb( CP_INSTANCE *cpi, ogg_uint32_t TargetQ );
864 extern void ClearTmpBuffers(PB_INSTANCE * pbi);
865 extern void InitTmpBuffers(PB_INSTANCE * pbi);
866 extern void ScanYUVInit( PP_INSTANCE * ppi,
867 SCAN_CONFIG_DATA * ScanConfigPtr);
868 extern int LoadAndDecode(PB_INSTANCE *pbi);
870 #endif /* ENCODER_INTERNAL_H */