⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codec_internal.h

📁 从FFMPEG转换而来的H264解码程序,VC下编译..
💻 H
📖 第 1 页 / 共 3 页
字号:
/********************************************************************
 *                                                                  *
 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
 *                                                                  *
 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2005                *
 * by the Xiph.Org Foundation http://www.xiph.org/                  *
 *                                                                  *
 ********************************************************************

  function:

 ********************************************************************/

#ifndef ENCODER_INTERNAL_H
#define ENCODER_INTERNAL_H

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <theora/theora.h>
#include "huffman.h"
#include "dsp.h"

#ifndef LIBOGG2
#define theora_read(x,y,z) ( *z = oggpackB_read(x,y) )
#else
#define theora_read(x,y,z) ( oggpackB_read(x,y,z) )
#endif

#define CURRENT_ENCODE_VERSION   1
#define HUGE_ERROR              (1<<28)  /*  Out of range test value */

/* Baseline dct height and width. */
#define BLOCK_HEIGHT_WIDTH          8
#define HFRAGPIXELS                 8
#define VFRAGPIXELS                 8

/* Baseline dct block size */
#define BLOCK_SIZE              (BLOCK_HEIGHT_WIDTH * BLOCK_HEIGHT_WIDTH)

/* Border is for unrestricted mv's */
#define UMV_BORDER              16
#define STRIDE_EXTRA            (UMV_BORDER * 2)

#define Q_TABLE_SIZE            64

#define KEY_FRAME              0
#define DELTA_FRAME            1

#define MAX_MODES               8
#define MODE_BITS               3
#define MODE_METHODS            8
#define MODE_METHOD_BITS        3

/* Different key frame types/methods */
#define DCT_KEY_FRAME           0

#define KEY_FRAME_CONTEXT       5

/* Preprocessor defines */
#define MAX_PREV_FRAMES        16

/* Number of search sites for a 4-step search (at pixel accuracy) */
#define MAX_SEARCH_SITES       33

#define VERY_BEST_Q            10
#define MIN_BPB_FACTOR        0.3
#define MAX_BPB_FACTOR        3.0

#define MAX_MV_EXTENT 31  /* Max search distance in half pixel increments */

typedef struct CONFIG_TYPE2{
  double       OutputFrameRate;
  ogg_uint32_t TargetBandwidth;
  ogg_uint32_t KeyFrameDataTarget ;  /* Data rate target for key frames */

  ogg_uint32_t FirstFrameQ;
  ogg_uint32_t BaseQ;
  ogg_uint32_t MaxQ;            /* Absolute Max Q allowed. */
  ogg_uint32_t ActiveMaxQ;      /* Currently active Max Q */

} CONFIG_TYPE2;

typedef struct coeffNode{
  int i;
  struct coeffNode *next;
} COEFFNODE;

typedef struct{
  unsigned char * Yuv0ptr;
  unsigned char * Yuv1ptr;
  unsigned char * SrfWorkSpcPtr;
  unsigned char * disp_fragments;

  ogg_uint32_t  * RegionIndex; /* Gives pixel index for top left of
                                 each block */
  ogg_uint32_t    VideoFrameHeight;
  ogg_uint32_t    VideoFrameWidth;

} SCAN_CONFIG_DATA;

typedef unsigned char YUV_BUFFER_ENTRY;

typedef struct{
  ogg_int32_t   x;
  ogg_int32_t   y;
} MOTION_VECTOR;

typedef MOTION_VECTOR COORDINATE;

/** Quantizer matrix entry */
typedef ogg_int16_t     Q_LIST_ENTRY;

/** Decode Post-Processor instance */
typedef struct PP_INSTANCE {
  ogg_uint32_t  PrevFrameLimit;

  ogg_uint32_t   *ScanPixelIndexTable;
  signed char    *ScanDisplayFragments;

  signed char    *PrevFragments[MAX_PREV_FRAMES];

  ogg_uint32_t   *FragScores; /* The individual frame difference ratings. */
  signed char    *SameGreyDirPixels;
  signed char    *BarBlockMap;

  /* Number of pixels changed by diff threshold in row of a fragment. */
  unsigned char  *FragDiffPixels;

  unsigned char  *PixelScores;
  unsigned char  *PixelChangedMap;
  unsigned char  *ChLocals;
  ogg_int16_t    *yuv_differences;
  ogg_int32_t    *RowChangedPixels;
  signed char    *TmpCodedMap;

  /* Plane pointers and dimension variables */
  unsigned char  * YPlanePtr0;
  unsigned char  * YPlanePtr1;
  unsigned char  * UPlanePtr0;
  unsigned char  * UPlanePtr1;
  unsigned char  * VPlanePtr0;
  unsigned char  * VPlanePtr1;

  ogg_uint32_t    VideoYPlaneWidth;
  ogg_uint32_t    VideoYPlaneHeight;
  ogg_uint32_t    VideoUVPlaneWidth;
  ogg_uint32_t    VideoUVPlaneHeight;

  ogg_uint32_t    VideoYPlaneStride;
  ogg_uint32_t    VideoUPlaneStride;
  ogg_uint32_t    VideoVPlaneStride;

  /* Scan control variables. */
  unsigned char   HFragPixels;
  unsigned char   VFragPixels;

  ogg_uint32_t    ScanFrameFragments;
  ogg_uint32_t    ScanYPlaneFragments;
  ogg_uint32_t    ScanUVPlaneFragments;
  ogg_uint32_t    ScanHFragments;
  ogg_uint32_t    ScanVFragments;

  ogg_uint32_t    YFramePixels;
  ogg_uint32_t    UVFramePixels;

  ogg_uint32_t    SgcThresh;

  ogg_uint32_t    OutputBlocksUpdated;
  ogg_uint32_t    KFIndicator;

  /* The pre-processor scan configuration. */
  SCAN_CONFIG_DATA ScanConfig;

  ogg_int32_t   SRFGreyThresh;
  ogg_int32_t   SRFColThresh;
  ogg_int32_t   SgcLevelThresh;
  ogg_int32_t   SuvcLevelThresh;

  ogg_uint32_t  NoiseSupLevel;

  /* Block Thresholds. */
  ogg_uint32_t  PrimaryBlockThreshold;
  unsigned char LineSearchTripTresh;

  int   PAKEnabled;

  int   LevelThresh;
  int   NegLevelThresh;
  int   SrfThresh;
  int   NegSrfThresh;
  int   HighChange;
  int   NegHighChange;

  /* Threshold lookup tables */
  unsigned char SrfPakThreshTable[512];
  unsigned char SrfThreshTable[512];
  unsigned char SgcThreshTable[512];

  /* Variables controlling S.A.D. break outs. */
  ogg_uint32_t GrpLowSadThresh;
  ogg_uint32_t GrpHighSadThresh;
  ogg_uint32_t ModifiedGrpLowSadThresh;
  ogg_uint32_t ModifiedGrpHighSadThresh;

  ogg_int32_t  PlaneHFragments;
  ogg_int32_t  PlaneVFragments;
  ogg_int32_t  PlaneHeight;
  ogg_int32_t  PlaneWidth;
  ogg_int32_t  PlaneStride;

  ogg_uint32_t BlockThreshold;
  ogg_uint32_t BlockSgcThresh;
  double UVBlockThreshCorrection;
  double UVSgcCorrection;

  double YUVPlaneCorrectionFactor;
  double AbsDiff_ScoreMultiplierTable[256];
  unsigned char  NoiseScoreBoostTable[256];
  unsigned char  MaxLineSearchLen;

  ogg_int32_t YuvDiffsCircularBufferSize;
  ogg_int32_t ChLocalsCircularBufferSize;
  ogg_int32_t PixelMapCircularBufferSize;

} PP_INSTANCE;

/** block coding modes */
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_LAST_MV    = 0x3, /* Use Last Motion vector */
    CODE_INTER_PRIOR_LAST = 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. */
} CODING_MODE;

/** Huffman table entry */
typedef struct HUFF_ENTRY {
  struct HUFF_ENTRY *ZeroChild;
  struct HUFF_ENTRY *OneChild;
  struct HUFF_ENTRY *Previous;
  struct HUFF_ENTRY *Next;
  ogg_int32_t        Value;
  ogg_uint32_t       Frequency;

} HUFF_ENTRY;

typedef struct qmat_range_table {
  int startq, startqi; /* index where this range starts */
  Q_LIST_ENTRY *qmat;  /* qmat at this range boundary */
} qmat_range_table;

/** codec setup data, maps to the third bitstream header */
typedef struct codec_setup_info {
  ogg_uint32_t QThreshTable[Q_TABLE_SIZE];
  Q_LIST_ENTRY DcScaleFactorTable[Q_TABLE_SIZE];

  int MaxQMatrixIndex;
  Q_LIST_ENTRY *qmats;
  qmat_range_table *range_table[6];

  HUFF_ENTRY *HuffRoot[NUM_HUFF_TABLES];

  unsigned char LoopFilterLimitValues[Q_TABLE_SIZE];
} codec_setup_info;

/** Decoder (Playback) instance -- installed in a theora_state */
typedef struct PB_INSTANCE {
  oggpack_buffer *opb;
  theora_info    info;
  /* how far do we shift the granulepos to seperate out P frame counts? */
  int            keyframe_granule_shift;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -