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

📄 umc_h264_dec_defs_dec.h

📁 audio-video-codecs.rar语音编解码器
💻 H
📖 第 1 页 / 共 4 页
字号:
/*
//
//              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) 2003-2007 Intel Corporation. All Rights Reserved.
//
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_H264_VIDEO_DECODER)

#ifndef __UMC_H264_DEC_DEFS_DEC_H__
#define __UMC_H264_DEC_DEFS_DEC_H__

#include <string.h>
#include "ippdefs.h"
#include "vm_types.h"
#include "ippvc.h"
#include "ipps.h"
#include "umc_memory_allocator.h"
#include "umc_structures.h"

#include "umc_mutex.h"

namespace UMC
{
//
// Define some useful macros
//

#if 0
    #define STRUCT_DECLSPEC_ALIGN __declspec(align(16))
#else
    #define STRUCT_DECLSPEC_ALIGN
#endif

#define ABSOWN(x) ((x) > 0 ? (x) : (-(x)))
#define    _IS_ALIGNED(p, n)    (!(((Ipp8u*)(p) - (Ipp8u*)(0)) & ((n)-1)))

//#define STORE_CABAC_BITS
//#define CABAC_DECORER_COMP
//#define CABAC_CONTEXTS_COMP
//#define STORE_VLC

#define __VLC_FILE__ "d:\\vlc.ipp"
#define __CABAC_FILE__ "d:\\cabac.tst"
#define __PICLIST_FILE__ "d:\\piclist.ipp"

enum
{
    ALIGN_VALUE                 = 16
};

// Although the standard allows for a minimum width or height of 4, this
// implementation restricts the minimum value to 32.

enum{
    FLD_STRUCTURE       = 0,
    TOP_FLD_STRUCTURE   = 0,
    BOTTOM_FLD_STRUCTURE    = 1,
    FRM_STRUCTURE   = 2,
    AFRM_STRUCTURE  = 3
};

#ifndef SHARED_ENCDEC_STRUCTURES_DEFS
#define SHARED_ENCDEC_STRUCTURES_DEFS

#define NORMAL_FRAME_PROCESSING 0
#define COMBINE_FIELDS 1
#define REPEAT_LAST_FRAME  2

enum    // Valid QP range
{
    QP_MAX = 51,
    QP_MIN = 0
};

enum
{
    LIST_0 = 0,     // Ref/mvs list 0 (L0)
    LIST_1 = 1      // Ref/mvs list 1 (L1)
};

//  NAL Unit Types
#ifndef SHARED_ENCDECBS_STRUCTURES_DEFS
#define SHARED_ENCDECBS_STRUCTURES_DEFS

// default plane & coeffs types:
typedef Ipp8u PlaneYCommon;
typedef Ipp8u PlaneUVCommon;
typedef Ipp16s CoeffsCommon;

typedef CoeffsCommon * CoeffsPtrCommon;
typedef PlaneYCommon * PlanePtrYCommon;
typedef PlaneUVCommon * PlanePtrUVCommon;


typedef enum {
        NAL_UT_RESERVED  = 0, // Reserved
        NAL_UT_SLICE     = 1, // Coded Slice - slice_layer_no_partioning_rbsp
        NAL_UT_DPA       = 2, // Coded Data partition A - dpa_layer_rbsp
        NAL_UT_DPB       = 3, // Coded Data partition A - dpa_layer_rbsp
        NAL_UT_DPC       = 4, // Coded Data partition A - dpa_layer_rbsp
        NAL_UT_IDR_SLICE = 5, // Coded Slice of a IDR Picture - slice_layer_no_partioning_rbsp
        NAL_UT_SEI       = 6, // Supplemental Enhancement Information - sei_rbsp
        NAL_UT_SPS       = 7, // Sequence Parameter Set - seq_parameter_set_rbsp
        NAL_UT_PPS       = 8, // Picture Parameter Set - pic_parameter_set_rbsp
        NAL_UT_PD        = 9, // Picture Delimiter - pic_delimiter_rbsp
        NAL_END_OF_SEQ   = 10, // End of sequence end_of_seq_rbsp()
        NAL_END_OF_STREAM = 11, // End of stream end_of_stream_rbsp
        NAL_UT_FD        = 12, // Filler Data - filler_data_rbsp
        NAL_UT_SPS_EX    = 13, // Sequence Parameter Set Extension - seq_parameter_set_extension_rbsp
        NAL_UT_AUXILIARY = 19  // Auxiliary coded picture
} NAL_Unit_Type;
#endif/* SHARED_ENCDECBS_STRUCTURES_DEFS */

// Note!  The Picture Code Type values below are no longer used in the
// core encoder.   It only knows about slice types, and whether or not
// the frame is IDR, Reference or Disposable.  See enum above.

enum EnumSliceCodType        // 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
};

inline
FrameType SliceTypeToFrameType(EnumSliceCodType slice_type)
{
    switch(slice_type)
    {
    case PREDSLICE:
    case S_PREDSLICE:
        return P_PICTURE;
    case BPREDSLICE:
        return B_PICTURE;
    case INTRASLICE:
    case S_INTRASLICE:
        return I_PICTURE;
    }

    return NONE_PICTURE;
}

// Macroblock type definitions
// Keep these ordered such that intra types are first, followed by
// inter types.  Otherwise you'll need to change the definitions
// of IS_INTRA_MBTYPE and IS_INTER_MBTYPE.
//
// WARNING:  Because the decoder exposes macroblock types to the application,
// these values cannot be changed without affecting users of the decoder.
// If new macroblock types need to be inserted in the middle of the list,
// then perhaps existing types should retain their numeric value, the new
// type should be given a new value, and for coding efficiency we should
// perhaps decouple these values from the ones that are encoded in the
// bitstream.
//

typedef enum {
    MBTYPE_INTRA,            // 4x4
    MBTYPE_INTRA_16x16,
    MBTYPE_PCM,              // Raw Pixel Coding, qualifies as a INTRA type...
    MBTYPE_INTER,            // 16x16
    MBTYPE_INTER_16x8,
    MBTYPE_INTER_8x16,
    MBTYPE_INTER_8x8,
    MBTYPE_INTER_8x8_REF0,
    MBTYPE_FORWARD,
    MBTYPE_BACKWARD,
    MBTYPE_SKIPPED,
    MBTYPE_DIRECT,
    MBTYPE_BIDIR,
    MBTYPE_FWD_FWD_16x8,
    MBTYPE_FWD_FWD_8x16,
    MBTYPE_BWD_BWD_16x8,
    MBTYPE_BWD_BWD_8x16,
    MBTYPE_FWD_BWD_16x8,
    MBTYPE_FWD_BWD_8x16,
    MBTYPE_BWD_FWD_16x8,
    MBTYPE_BWD_FWD_8x16,
    MBTYPE_BIDIR_FWD_16x8,
    MBTYPE_BIDIR_FWD_8x16,
    MBTYPE_BIDIR_BWD_16x8,
    MBTYPE_BIDIR_BWD_8x16,
    MBTYPE_FWD_BIDIR_16x8,
    MBTYPE_FWD_BIDIR_8x16,
    MBTYPE_BWD_BIDIR_16x8,
    MBTYPE_BWD_BIDIR_8x16,
    MBTYPE_BIDIR_BIDIR_16x8,
    MBTYPE_BIDIR_BIDIR_8x16,
    MBTYPE_B_8x8,
    NUMBER_OF_MBTYPES
} MB_Type;

typedef enum
{
    SEI_BUFFERING_PERIOD_TYPE   = 0,
    SEI_PIC_TIMING_TYPE         = 1,
    SEI_PAN_SCAN_RECT_TYPE      = 2,
    SEI_FILLER_TYPE             = 3,
    SEI_USER_DATA_REGISTERED_TYPE   = 4,
    SEI_USER_DATA_UNREGISTERED_TYPE = 5,
    SEI_RECOVERY_POINT_TYPE         = 6,
    SEI_DEC_REF_PIC_MARKING_TYPE    = 7,
    SEI_SPARE_PIC_TYPE              = 8,
    SEI_SCENE_INFO_TYPE             = 9,
    SEI_SUB_SEQ_INFO_TYPE           = 10,
    SEI_SUB_SEQ_LAYER_TYPE          = 11,
    SEI_SUB_SEQ_TYPE                = 12,
    SEI_FULL_FRAME_FREEZE_TYPE      = 13,
    SEI_FULL_FRAME_FREEZE_RELEASE_TYPE  = 14,
    SEI_FULL_FRAME_SNAPSHOT_TYPE        = 15,
    SEI_PROGRESSIVE_REF_SEGMENT_START_TYPE  = 16,
    SEI_PROGRESSIVE_REF_SEGMENT_END_TYPE    = 17,
    SEI_MOTION_CONSTRAINED_SG_SET_TYPE      = 18,
    SEI_RESERVED                            = 19
} SEI_TYPE;

// 8x8 Macroblock subblock type definitions
typedef enum {
    SBTYPE_DIRECT = 0,            // B Slice modes
    SBTYPE_8x8 = 1,               // P slice modes
    SBTYPE_8x4 = 2,
    SBTYPE_4x8 = 3,
    SBTYPE_4x4 = 4,
    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;
#endif /*SHARED_ENCDEC_STRUCTURES_DEFS*/

// macro - yields TRUE if a given MB type is INTRA
#define IS_INTRA_MBTYPE(mbtype) ((mbtype) < MBTYPE_INTER)

// macro - yields TRUE if a given MB type is INTER
#define IS_INTER_MBTYPE(mbtype) ((mbtype) >= MBTYPE_INTER)

#define IS_I_SLICE(SliceType) ((SliceType) == INTRASLICE)
#define IS_P_SLICE(SliceType) ((SliceType) == PREDSLICE || (SliceType) == S_PREDSLICE)
#define IS_B_SLICE(SliceType) ((SliceType) == BPREDSLICE)

#define IS_SKIP_DEBLOCKING_MODE_NON_REF (m_PermanentTurnOffDeblocking == 1)
#define IS_SKIP_DEBLOCKING_MODE_PERMANENT (m_PermanentTurnOffDeblocking == 2)

enum
{
    MAX_NUM_SEQ_PARAM_SETS = 32,
    MAX_NUM_PIC_PARAM_SETS = 256,

    MAX_SLICE_NUM       = 128, //INCREASE IF NEEDED OR SET to -1 for adaptive counting (increases memory usage)
    MAX_NUM_REF_FRAMES  = 32,

    // Number of reference frames initially allocated by the decoder.
    // Normally 2, significantly increased for ARM for PVP player. Decrease
    // back to 2 for ARM when building xsavcdec player to free up memory
    // for files for performance and regression testing.
#if defined(ARM) || defined(_ARM_)
    DEC_NUM_ALLOC_REF_FRAMES = 2,
#else
    DEC_NUM_ALLOC_REF_FRAMES = 2,
#endif

    MAX_NUM_SLICE_GROUPS        = 8,
    MAX_SLICE_GROUP_MAP_TYPE    = 6,

    NUM_INTRA_TYPE_ELEMENTS     = 16,

    MINIMAL_DATA_SIZE           = 4
};

// Possible values for disable_deblocking_filter_idc:
enum DeblockingModes_t
{
    DEBLOCK_FILTER_ON                   = 0,
    DEBLOCK_FILTER_OFF                  = 1,
    DEBLOCK_FILTER_ON_NO_SLICE_EDGES    = 2
};

#define SCLFLAT16     0
#define SCLDEFAULT    1
#define SCLREDEFINED  2

#pragma pack(1)

struct H264ScalingList4x4
{
    Ipp8u ScalingListCoeffs[16];
};

struct H264ScalingList8x8
{
    Ipp8u ScalingListCoeffs[64];
};

struct H264WholeQPLevelScale4x4
{
    Ipp16s LevelScaleCoeffs[88]/*since we do not support 422 and 444*/[16];
};
struct H264WholeQPLevelScale8x8
{
    Ipp16s LevelScaleCoeffs[88]/*since we do not support 422 and 444*/[64];
};

#pragma pack()

#pragma pack(16)

typedef Ipp32u IntraType;

// Sequence parameter set structure, corresponding to the H.264 bitstream definition.
struct H264SeqParamSet
{
    H264SeqParamSet()
    {
        seq_parameter_set_id = MAX_NUM_SEQ_PARAM_SETS;
        poffset_for_ref_frame = 0;
    }

    ~H264SeqParamSet()
    {
        if (poffset_for_ref_frame)
            ippsFree(poffset_for_ref_frame);
    }

    bool operator == (const H264SeqParamSet & sps) const
    {
        if (memcmp(&(this->profile_idc), &sps.profile_idc, ((Ipp8s*)&poffset_for_ref_frame - (Ipp8s*)&profile_idc)))
            return false;

        // DEBUG : need to compare poffset_for_ref_frame
        if (poffset_for_ref_frame != sps.poffset_for_ref_frame)
            return false;

        return true;
    }

    bool operator != (const H264SeqParamSet & sps) const
    {
        return !(*this == sps);
    }

    Ipp8u        profile_idc;                        // baseline, main, etc.
    Ipp8u        level_idc;
    Ipp8u        constrained_set0_flag;
    Ipp8u        constrained_set1_flag;
    Ipp8u        constrained_set2_flag;
    Ipp8u        constrained_set3_flag;
    Ipp8u        chroma_format_idc;
    Ipp8u        residual_colour_transform_flag;
    Ipp8u        bit_depth_luma;
    Ipp8u        bit_depth_chroma;
    Ipp8u        qpprime_y_zero_transform_bypass_flag;
    Ipp8u        type_of_scaling_list_used[8];
    Ipp8u        seq_scaling_matrix_present_flag;
    //Ipp8u        seq_scaling_list_present_flag[8];
    H264ScalingList4x4 ScalingLists4x4[6];
    H264ScalingList8x8 ScalingLists8x8[2];
    Ipp8u        gaps_in_frame_num_value_allowed_flag;
    Ipp8u        frame_cropping_flag;
    Ipp32u       frame_cropping_rect_left_offset;
    Ipp32u       frame_cropping_rect_right_offset;
    Ipp32u       frame_cropping_rect_top_offset;
    Ipp32u       frame_cropping_rect_bottom_offset;
    Ipp8u        more_than_one_slice_group_allowed_flag;
    Ipp8u        arbitrary_slice_order_allowed_flag;  // If zero, slice order in pictures must
                                                      // be in increasing MB address order.
    Ipp8u        redundant_pictures_allowed_flag;
    Ipp8u        seq_parameter_set_id;                // id of this sequence parameter set
    Ipp8u        log2_max_frame_num;                  // Number of bits to hold the frame_num
    Ipp8u        pic_order_cnt_type;                  // Picture order counting method

    Ipp8u        delta_pic_order_always_zero_flag;    // If zero, delta_pic_order_cnt fields are
                                                      // present in slice header.
    Ipp8u        frame_mbs_only_flag;                 // Nonzero indicates all pictures in sequence
                                                      // are coded as frames (not fields).
    Ipp8u        required_frame_num_update_behavior_flag;

    Ipp8u        mb_adaptive_frame_field_flag;        // Nonzero indicates frame/field switch
                                                      // at macroblock level
    Ipp8u        direct_8x8_inference_flag;           // Direct motion vector derivation method
    Ipp8u        vui_parameters_present_flag;         // Zero indicates default VUI parameters
    Ipp32u       log2_max_pic_order_cnt_lsb;          // Value of MaxPicOrderCntLsb.
    Ipp32s       offset_for_non_ref_pic;

    Ipp32s       offset_for_top_to_bottom_field;      // Expected pic order count difference from
                                                      // top field to bottom field.

    Ipp32u       num_ref_frames_in_pic_order_cnt_cycle;
    Ipp32u       num_ref_frames;                      // total number of pics in decoded pic buffer
    Ipp32u       frame_width_in_mbs;
    Ipp32u       frame_height_in_mbs;

    // These fields are calculated from values above.  They are not written to the bitstream
    Ipp32u       MaxMbAddress;
    Ipp32u       MaxPicOrderCntLsb;
    // vui part
    Ipp8u        aspect_ratio_info_present_flag;
    Ipp8u        aspect_ratio_idc;
    Ipp16u       sar_width;
    Ipp16u       sar_height;
    Ipp8u        overscan_info_present_flag;
    Ipp8u        overscan_appropriate_flag;
    Ipp8u        video_signal_type_present_flag;
    Ipp8u        video_format;
    Ipp8u        video_full_range_flag;
    Ipp8u        colour_description_present_flag;
    Ipp8u        colour_primaries;
    Ipp8u        transfer_characteristics;
    Ipp8u        matrix_coefficients;
    Ipp8u        chroma_loc_info_present_flag;
    Ipp8u        chroma_sample_loc_type_top_field;
    Ipp8u        chroma_sample_loc_type_bottom_field;
    Ipp8u        timing_info_present_flag;
    Ipp32u       num_units_in_tick;
    Ipp32u       time_scale;

⌨️ 快捷键说明

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