📄 umc_h264_pub.h
字号:
//// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2004 - 2005 Intel Corporation. All Rights Reserved.//#ifndef _H264PUB_H__#define _H264PUB_H__#define VM_DEBUG 7#include "ippvc.h"#include "ippi.h"#include "ipps.h"#include "umc_video_encoder.h"#include "umc_h264_defs.h"#include "vm_debug.h"#define SubPelFactor 4 // Don't change this!!!#undef ABS#define ABS(a) (((a) < 0) ? (-(a)) : (a))#undef MAX#define MAX(a, b) (((a) > (b)) ? (a) : (b))#undef MIN#define MIN(a, b) (((a) < (b)) ? (a) : (b))#undef SIGN#define SIGN(a) ((a) < 0 ? (-1) : (1))#define H264_QP_MIN 0#define H264_QP_MAX 51#define H264_QP_RANGE (H264_QP_MAX - H264_QP_MIN + 1)#undef H264_ALIGN#define H264_ALIGN(p, n) ((Ipp8u*)(p) + ((((Ipp8u*)(p) - (Ipp8u*)(0)) & ((n)-1)) ? \ ((n) - (((Ipp8u*)(p) - (Ipp8u*)(0)) & ((n)-1))) : 0))#undef H264_IS_ALIGNED#define H264_IS_ALIGNED(p, n) (!(((Ipp8u*)(p) - (Ipp8u*)(0)) & ((n)-1)))#define FLD_STRUCTURE 0#define TOP_FLD_STRUCTURE 0#define BOTTOM_FLD_STRUCTURE 1#define FRM_STRUCTURE 2#define AFRM_STRUCTURE 3#define MAX_SLICE_NUM 64// Perform byte swapping on a 16 or 32-byte value.#define H264_SWAP16(x) (Ipp16u( (((x) & 0xff) << 8) | (((x) & 0xff00) >> 8) ))#define H264_SWAP32(x) (Ipp32u( (((x) & 0xff) << 24) \ | (((x) & 0xff00) << 8) \ | (((x) & 0xff0000) >> 8) \ | (((x) >> 24) & 0xff) ))#define MIN_XDIM 32#define MAX_XDIM 2048#define MIN_YDIM 32#define MAX_YDIM 1152#define LIST_0 0#define LIST_1 1#define MAX_NUM_REF_FRAMES 16#define YUV_Y_PADDING 32// The Y plane has this many bytes (a.k.a. pels) of padding around each// of its 4 sides#define YUV_UV_PADDING 16// The U and V planes have this many bytes (a.k.a. pels) of padding// around each of their 4 sides#define YUV_ALIGNMENT 64// The beginning of the padded buffer is aligned thusly.// This alignment macro assumes n is a power of 2.// Note: In order to eliminate compiler warnings on pointer// truncations, (Ipp8u*(p) - Ipp8u*(0)) is used to yield ptrdiff_t// integer results. The effect of doing this is not clearly// defined, but seems to work so far.//#define STORE_DFS//#define STORE_CABAC_BITS//#define STORE_VLC//#define STORE_MVS//#define STORE_PREDICTORS//#define STORE_DMVS//#define STORE_PICLIST//#define STORE_REFIDXS//#define STORE_INPUTDATA//#define STORE_NUTS//#define STORE_DISPLAY_PICS//#define STORE_DECODING_PICS#define __DFS_FILE__ "z:\\dfs.ipp"#define __VLC_FILE__ "z:\\vlc.ipp"#define __CABAC_FILE__ "z:\\cabac.ipp"#define __DMVS_FILE__ "z:\\dmv.ipp"#define __PREDICTORS_FILE__ "z:\\mv_pred.ipp"#define __MVS_FILE__ "z:\\mv.ipp"#define __PICLIST_FILE__ "z:\\piclist.ipp"#define __REFIDXS_FILE__ "z:\\refidxs.ipp"#define __NUTS_FILE__ "z:\\nuts.ipp"#define __FINPUT_FILE__ "z:\\finput.ipp"#define __FLINPUT_FILE__ "z:\\flinput.ipp"#define __DISPLAYSPICS_FILE__ "z:\\pics_disp.ipp"#define __DECODINGPICS_FILE__ "z:\\pics_dec.ipp"namespace UMC{ typedef Ipp32u H264_Encoder_Compression_Flags; // This set of flags gets passed into each compress invocation. typedef Ipp32u H264_Encoder_Compression_Notes; // This set of flags gets returned from each compress invocation. const H264_Encoder_Compression_Flags H264_ECF_MORE_FRAMES = 0x1; // This flag indicates that the H264_Encoder's Encode method is being // called to retrieve the second (or subsequent) output image // corresponding to a single input image. const H264_Encoder_Compression_Flags H264_ECF_LAST_FRAME = 0x2; // This flag indicates that the H264_Encoder's Encode method is being // called with the final frame of the sequence. If this flag is not used // and B frames are in use, then frames which are queued for encoding waiting // for a future reference frame may not be encoded. This flag forces the last // frame to be a reference frame if it wouldn't have already been so. const H264_Encoder_Compression_Notes H264_ECN_KEY_FRAME = 0x1; // Indicates that the compressed image is a key frame. // Note that enhancement layer EI frames are not key frames, in the // traditional sense, because they have dependencies on lower layer // frames. const H264_Encoder_Compression_Notes H264_ECN_B_FRAME = 0x2; // Indicates that the compressed image is a B frame. // At most one of H264_ECN_KEY_FRAME and H264_ECN_B_FRAME will be set. const H264_Encoder_Compression_Notes H264_ECN_MORE_FRAMES = 0x4; // Indicates that the encoder has more frames to emit. This flag is // used by an encoder to inform the Hive layer that multiple output // frames are to be emitted for a given input frame. The Hive layer // will loop until this flag is no longer set. // This flag should only be returned when operating in video environments // that support multiple output frames per input frame. const H264_Encoder_Compression_Notes H264_ECN_NO_FRAME = 0x8; // Indicates that the encoder has no frames to emit. This is typically // used when encoding a B frame, since the B frame cannot be encoded // until a subsequent frame is encoded. // This flag should only be used in encoder environments for which // "Hive::Supports_Multiple_Encoder_Output_Images()" returns true. // When used, this flag causes the Hive layer to suppress returning // an encoded frame to its environment. // For other environments, the encoder should not set this flag, but // rather should return some sort of placeholder frame. // What is the significance of the CPK/APK defines sprinkled // throughout the code base? Here is a chart that might help: // // CPK APK // --- --- // F F represents the TROMSO codec with VFW and AM interfaces // T F represents the C version of the TROMSO porting kit // F T an invalid combination // T T represents the optimized version of the TROMSO porting kit // // This means that TROMSO with AM/VFW is represented if CPK is not defined. // The following combination is used to isolate code that is // sensitive to the machine IA - specifically MT or non-MT. // #if !defined(CPK) || defined(APK) // The following combination is used to isolate code that is // not sensitive to machine IA. // #if defined(CPK) && !defined(APK) const Ipp32u TR_WRAP = 256; inline void *H264_Allocate(Ipp32u size, bool zero_init) { unsigned char *p; if (size == 0) { size++; // Allocate at least one byte } p = ippsMalloc_8u(size); if (p && zero_init) (void) ippsZero_8u(p, size); return p; } // Allocate 'size' bytes of memory, optionally clear it, and // return a pointer to it. Returns NULL if allocation fails. // The caller is repsonsible for recovering from a failed allocation. // Allocating 0 bytes is supported, though it will result in // some non-zero number of bytes actually being allocated. inline void H264_Free(void* p) { if (p) { ippsFree(p); } }// // The Implementation_ID type provides symbolic names for CPU-specific // implementations of algorithms. An object of this type is used in // various places as an index into an array that contains pointers to // CPU-specific implementations of certain functions. For this reason, // do not change the order of declaration of these enumeration literals. // // Although the standard allows for a minimum width or height of 4, this // implementation restricts the minimum value to 32. enum EnumPicCodType // bits : Permitted Slice Types { // ---------------------------- INTRAPIC = 0, // 000 : I (Intra) PREDPIC = 1, // 001 : I, P (Pred) BPREDPIC = 2, // 010 : I, P, B (BiPred) S_INTRAPIC = 3, // 011 : SI (SIntra) S_PREDPIC = 4, // 100 : SI, SP (SPred) MIXED_INTRAPIC = 5, // 101 : I, SI MIXED_PREDPIC = 6, // 110 : I, SI, P, SP MIXED_BPREDPIC = 7 // 111 : I, SI, P, SP, B };#ifndef SHARED_ENCDEC_STRUCTURES_DEFS#define SHARED_ENCDEC_STRUCTURES_DEFS // Valid QP range const Ipp32u QP_MAX = 51; const Ipp32u QP_MIN = 0; enum EnumSliceType // Permitted MB Prediction Types { // ------------------------------------ PREDSLICE = 0, // I (Intra), P (Pred) BPREDSLICE = 1, // I, P, B (BiPred) INTRASLICE = 2, // I S_PREDSLICE = 3, // SP (SPred), I S_INTRASLICE = 4 // SI (SIntra), I }; typedef Ipp8s T_NumCoeffs; typedef enum { MBTYPE_INTRA = 0, // 4x4 MBTYPE_INTRA_16x16 = 1, MBTYPE_PCM = 2, // Raw Pixel Coding, qualifies as a INTRA type... MBTYPE_INTER = 3, // 16x16 MBTYPE_INTER_16x8 = 4, MBTYPE_INTER_8x16 = 5, MBTYPE_INTER_8x8 = 6, MBTYPE_INTER_8x8_REF0 = 7, // same as MBTYPE_INTER_8x8, with all RefIdx=0 MBTYPE_FORWARD = 8, MBTYPE_BACKWARD = 9, MBTYPE_SKIPPED = 10, MBTYPE_DIRECT = 11, MBTYPE_BIDIR = 12, MBTYPE_FWD_FWD_16x8 = 13, MBTYPE_FWD_FWD_8x16 = 14, MBTYPE_BWD_BWD_16x8 = 15, MBTYPE_BWD_BWD_8x16 = 16, MBTYPE_FWD_BWD_16x8 = 17, MBTYPE_FWD_BWD_8x16 = 18, MBTYPE_BWD_FWD_16x8 = 19, MBTYPE_BWD_FWD_8x16 = 20, MBTYPE_BIDIR_FWD_16x8 = 21, MBTYPE_BIDIR_FWD_8x16 = 22, MBTYPE_BIDIR_BWD_16x8 = 23, MBTYPE_BIDIR_BWD_8x16 = 24, MBTYPE_FWD_BIDIR_16x8 = 25, MBTYPE_FWD_BIDIR_8x16 = 26, MBTYPE_BWD_BIDIR_16x8 = 27, MBTYPE_BWD_BIDIR_8x16 = 28, MBTYPE_BIDIR_BIDIR_16x8 = 29, MBTYPE_BIDIR_BIDIR_8x16 = 30, MBTYPE_B_8x8 = 31, NUMBER_OF_MBTYPES = 32 } MB_Type; typedef enum { SBTYPE_8x8 = 0, // P slice modes SBTYPE_8x4 = 1, SBTYPE_4x8 = 2, SBTYPE_4x4 = 3, SBTYPE_DIRECT = 4, // B Slice modes SBTYPE_FORWARD_8x8 = 5, // Subtract 4 for mode # SBTYPE_BACKWARD_8x8 = 6, SBTYPE_BIDIR_8x8 = 7, SBTYPE_FORWARD_8x4 = 8, SBTYPE_FORWARD_4x8 = 9, SBTYPE_BACKWARD_8x4 = 10, SBTYPE_BACKWARD_4x8 = 11, SBTYPE_BIDIR_8x4 = 12, SBTYPE_BIDIR_4x8 = 13, SBTYPE_FORWARD_4x4 = 14, SBTYPE_BACKWARD_4x4 = 15, SBTYPE_BIDIR_4x4 = 16 } SB_Type; typedef struct { Ipp32u uCBP4x4; // 4x4 coded block flags: // bits 0..15 for luma blocks 0..15 // bits 16..23 for chroma blocks 0..7 // 0 == not coded (empty) Ipp32u cbp_bits; Ipp8u uMBQP; // QP for this MB Ipp32s uMBQPDelta; // QP for this MB Ipp8u uEdgeType; // picture and slice edges, to be defined MB_Type uMBType; // type of this MB, types to be defined Ipp8u uCBP; // cbp for this MB, matching bitstream definition Ipp8u uLumaAC; // 1 if any AC coeffs are coded for in the whole 16x16 MB T_NumCoeffs DC16x16Coeffs; // Number of nonzero Coeffs in 16x16 DC block (negative if DC is nonzero) Ipp8u uChromaType; // Chroma Prediction Type for both U & V Ipp8u uChromaNC; // Cbp digest for U & V planes. 0=not coded;1=DC only;2=AC coeffs Ipp8u uMBSkipFlag; Ipp16u uSlice; // Number of the Slice that this MB belongs to. Ipp32u uMVdelta; // MV delta info for deblock filter, bits 0..15 for horizontal // edges, bits 16..31 for vertical edges. SB_Type SBType[4]; // Subblock type (SB_Type) for each 8x8 of an MBTYPE_8x8 macroblock. //Ipp8u field_mb; // 1, if field coded; 0, if frame coded. } T_EncodeMBData; typedef struct { // Note: uNumCoeffs and uTotalZeros are not redundant because // this struct covers blocks with 4, 15 and 16 possible coded coeffs. Ipp8u uTrailing_Ones; // Up to 3 trailing ones are allowed (not in iLevels below) Ipp8u uTrailing_One_Signs; // Packed into up to 3 lsb, (1==neg) Ipp8u uNumCoeffs; // Total Number of non-zero coeffs (including Trailing Ones) Ipp8u uTotalZeros; // Total Number of zero coeffs Ipp16s iLevels[16]; // Up to 16 Coded coeffs are possible, in reverse zig zag order Ipp8u uRuns[16]; // Up to 16 Runs are recorded, including Trailing Ones, in rev zig zag order } T_RLE_Data; typedef struct { Ipp8u uBlockType; Ipp8u uNumSigCoeffs; Ipp8u uLastCoeff; Ipp8u uFirstCoeff; Ipp8u uFirstSignificant; Ipp8u uLastSignificant; Ipp16u uSignificantLevels[16]; Ipp8u uSignificantSigns[16]; Ipp8u uSignificantMap[16]; Ipp32s CtxBlockCat; } T_Block_CABAC_Data; // macro - yields true if a given MB type is INTRA#define IS_INTRA_MBTYPE(mbtype) ((mbtype) < MBTYPE_INTER)#define IS_TRUEINTRA_MBTYPE(mbtype) ((mbtype) < MBTYPE_PCM) // macro - yields true if a given MB type is INTER
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -