📄 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 - 2007 Intel Corporation. All Rights Reserved.
//
#ifndef UMC_H264_PUB_H
#define UMC_H264_PUB_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"
#include "umc_h264_video_encoder.h"
#define SUB_PEL_SHIFT 2
#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 32
#define YUV_Y_PADDING 96
// The Y plane has this many bytes (a.k.a. pels) of padding around each
// of its 4 sides
#define YUV_UV_PADDING 64
// 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_CABAC_BITS
//#define CABAC_CONTEXTS_COMP
//#define STORE_PICLIST
#define __CABAC_FILE__ VM_STRING("cabac_enc.ipp")
#define __PICLIST_FILE__ VM_STRING("piclist_enc.ipp")
using namespace UMC;
namespace UMC_H264_ENCODER
{
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;
extern const H264MotionVector null_mv;
inline void *H264_Allocate(Ipp32u size, bool zero_init)
{
Ipp8u *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);
p = NULL;
}
}
// 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;
typedef Ipp8s T_NumCoeffs;
typedef enum {
MBTYPE_INTRA = 0, // 4x4 or 8x8
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 sad;
T_RefIdx ref_idx;
H264MotionVector mv;
H264MotionVector predicted_mv;
} ME_Info;
// 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
#define IS_INTER_MBTYPE(mbtype) ((mbtype) >= MBTYPE_INTER)
#define IS_SKIP_MBTYPE(mbtype) ((mbtype == MBTYPE_SKIPPED) || (mbtype == MBTYPE_DIRECT))
// 8x8 Macroblock subblock type definitions
typedef enum { /* UNITs from 1 till 5 inclusive are VCL units, other UNITs - not */
NAL_UT_RESERVED = 0x00, // Reserved / Unspecified in the spec
NAL_UT_SLICE = 0x01, // Coded Slice - slice_layer_no_partioning_rbsp
NAL_UT_DPA = 0x02, // Coded Data partition A - dpa_layer_rbsp
NAL_UT_DPB = 0x03, // Coded Data partition B - dpa_layer_rbsp
NAL_UT_DPC = 0x04, // Coded Data partition C - dpa_layer_rbsp
NAL_UT_IDR_SLICE = 0x05, // Coded Slice of a IDR Picture - slice_layer_no_partioning_rbsp
NAL_UT_SEI = 0x06, // Supplemental Enhancement Information - sei_rbsp
NAL_UT_SPS = 0x07, // Sequence Parameter Set - seq_parameter_set_rbsp
NAL_UT_PPS = 0x08, // Picture Parameter Set - pic_parameter_set_rbsp
NAL_UT_AUD = 0x09, // Access Unit Delimiter - access_unit_delimiter_rbsp
NAL_UT_EOSEQ = 0x0a, // End of sequence - end_of_seq_rbsp
NAL_UT_EOSTREAM = 0x0b, // End of stream - end_of_stream_rbsp
NAL_UT_FILL = 0x0c, // Filler data - filler_data_rbsp
NAL_UT_SEQEXT = 0x0d, // Sequence parameter set extension - seq_parameter_set_extension_rbsp
/* 0x0e..0x12 - Reserved */
NAL_UT_LAYERNOPART = 0x13 // Coded slice of an auxiliary coded picture without paritioning - slice_layer_without_partitioning_rbsp
/* 0x14..0x17 - Reserved */
/* 0x18..0x1f - Unspcified */
} NAL_Unit_Type;
#endif /*SHARED_ENCDEC_STRUCTURES_DEFS*/
// Define constants representing the pixel aspect ratio codes from table 5
// of the H.263+ standard.
#define PARC_FORBIDDEN 0
#define PARC_SQUARE 1
#define PARC_CIF 2
#define PARC_10_11 3
#define PARC_16_11 4
#define PARC_40_33 5
// values between 6 and 14 are reserved
#define PARC_EXTENDED 15
enum FrameSize {
FORBIDDEN = 0, Reserved000 = 0,
SQCIF = 1,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -