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

📄 mp4_enc.hpp

📁 audio-video-codecs.rar语音编解码器
💻 HPP
📖 第 1 页 / 共 3 页
字号:
/* ///////////////////////////////////////////////////////////////////////
//
//               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.
//
//  Description:    class ippVideoEncoderMPEG4
//
*/

#define USE_CV_GME          // use IPP CV for GME (nwp = 2, 3)
//#define USE_ME_SADBUFF      // store calculated SAD to buffer

#include "ippdefs.h"
#include "ippcore.h"
#include "ipps.h"
#include "ippi.h"
#include "ippvc.h"
#include "vm_debug.h"

#ifdef USE_CV_GME
#include "ippcv.h"
#endif

#if defined(_OPENMP)
#define _OMP_KARABAS
#endif

#if defined(_OMP_KARABAS) && defined(_OPENMP)
#include <omp.h>
#endif // _OMP_KARABAS

#include "mp4_enc_bitstream.hpp"

#pragma warning(disable : 4514)     // unreferenced inline function has been removed

namespace MPEG4_ENC
{
/* MPEG-4 start code values */
// ISO/IEC 14496-2: table 6-3
enum {
    MP4_VIDEO_OBJECT_MIN_SC       = 0x00,
    MP4_VIDEO_OBJECT_MAX_SC       = 0x1F,
    MP4_VIDEO_OBJECT_LAYER_MIN_SC = 0x20,
    MP4_VIDEO_OBJECT_LAYER_MAX_SC = 0x2F,
    MP4_FGS_BP_MIN_SC             = 0x40,
    MP4_FGS_BP_MAX_SC             = 0x5F,
    MP4_VISUAL_OBJECT_SEQUENCE_SC = 0xB0,
    MP4_VISUAL_OBJECT_SEQUENCE_EC = 0xB1,
    MP4_USER_DATA_SC              = 0xB2,
    MP4_GROUP_OF_VOP_SC           = 0xB3,
    MP4_VIDEO_SESSION_ERROR_SC    = 0xB4,
    MP4_VISUAL_OBJECT_SC          = 0xB5,
    MP4_VIDEO_OBJECT_PLANE_SC     = 0xB6,
    MP4_SLICE_SC                  = 0xB7,
    MP4_EXTENSION_SC              = 0xB8,
    MP4_FGS_VOP_SC                = 0xB9,
    MP4_FBA_OBJECT_SC             = 0xBA,
    MP4_FBA_OBJECT_PLANE_SC       = 0xBB,
    MP4_MESH_OBJECT_SC            = 0xBC,
    MP4_MESH_OBJECT_PLANE_SC      = 0xBD,
    MP4_STILL_TEXTURE_OBJECT_SC   = 0xBE,
    MP4_TEXTURE_SPATIAL_LAYER_SC  = 0xBF,
    MP4_TEXTURE_SNR_LAYER_SC      = 0xC0,
    MP4_TEXTURE_TILE_SC           = 0xC1,
    MP4_TEXTURE_SHAPE_LAYER_SC    = 0xC2,
    MP4_STUFFING_SC               = 0xC3
};

/* MPEG-4 code values */
// ISO/IEC 14496-2:2004 table 6-6
enum {
    MP4_VISUAL_OBJECT_TYPE_VIDEO     = 1,
    MP4_VISUAL_OBJECT_TYPE_TEXTURE   = 2,
    MP4_VISUAL_OBJECT_TYPE_MESH      = 3,
    MP4_VISUAL_OBJECT_TYPE_FBA       = 4,
    MP4_VISUAL_OBJECT_TYPE_3DMESH    = 5
};

// ISO/IEC 14496-2:2004 table 6-7
enum {
    MP4_VIDEO_FORMAT_COMPONENT      = 0,
    MP4_VIDEO_FORMAT_PAL            = 1,
    MP4_VIDEO_FORMAT_NTSC           = 2,
    MP4_VIDEO_FORMAT_SECAM          = 3,
    MP4_VIDEO_FORMAT_MAC            = 4,
    MP4_VIDEO_FORMAT_UNSPECIFIED    = 5
};

// ISO/IEC 14496-2:2004 table 6-8..10
enum {
    MP4_VIDEO_COLORS_FORBIDDEN         = 0,
    MP4_VIDEO_COLORS_ITU_R_BT_709      = 1,
    MP4_VIDEO_COLORS_UNSPECIFIED       = 2,
    MP4_VIDEO_COLORS_RESERVED          = 3,
    MP4_VIDEO_COLORS_ITU_R_BT_470_2_M  = 4,
    MP4_VIDEO_COLORS_ITU_R_BT_470_2_BG = 5,
    MP4_VIDEO_COLORS_SMPTE_170M        = 6,
    MP4_VIDEO_COLORS_SMPTE_240M        = 7,
    MP4_VIDEO_COLORS_GENERIC_FILM      = 8
};

// ISO/IEC 14496-2:2004 table 6-11
enum {
    MP4_VIDEO_OBJECT_TYPE_SIMPLE                     = 1,
    MP4_VIDEO_OBJECT_TYPE_SIMPLE_SCALABLE            = 2,
    MP4_VIDEO_OBJECT_TYPE_CORE                       = 3,
    MP4_VIDEO_OBJECT_TYPE_MAIN                       = 4,
    MP4_VIDEO_OBJECT_TYPE_NBIT                       = 5,
    MP4_VIDEO_OBJECT_TYPE_2DTEXTURE                  = 6,
    MP4_VIDEO_OBJECT_TYPE_2DMESH                     = 7,
    MP4_VIDEO_OBJECT_TYPE_SIMPLE_FACE                = 8,
    MP4_VIDEO_OBJECT_TYPE_STILL_SCALABLE_TEXTURE     = 9,
    MP4_VIDEO_OBJECT_TYPE_ADVANCED_REAL_TIME_SIMPLE  = 10,
    MP4_VIDEO_OBJECT_TYPE_CORE_SCALABLE              = 11,
    MP4_VIDEO_OBJECT_TYPE_ADVANCED_CODING_EFFICIENCY = 12,
    MP4_VIDEO_OBJECT_TYPE_ADVANCED_SCALABLE_TEXTURE  = 13,
    MP4_VIDEO_OBJECT_TYPE_SIMPLE_FBA                 = 14,
    MP4_VIDEO_OBJECT_TYPE_SIMPLE_STUDIO              = 15,
    MP4_VIDEO_OBJECT_TYPE_CORE_STUDIO                = 16,
    MP4_VIDEO_OBJECT_TYPE_ADVANCED_SIMPLE            = 17,
    MP4_VIDEO_OBJECT_TYPE_FINE_GRANULARITY_SCALABLE  = 18
};

// ISO/IEC 14496-2:2004 table 6-14
enum {
    MP4_ASPECT_RATIO_FORBIDDEN  = 0,
    MP4_ASPECT_RATIO_1_1        = 1,
    MP4_ASPECT_RATIO_12_11      = 2,
    MP4_ASPECT_RATIO_10_11      = 3,
    MP4_ASPECT_RATIO_16_11      = 4,
    MP4_ASPECT_RATIO_40_33      = 5,
    MP4_ASPECT_RATIO_EXTPAR     = 15
};

// ISO/IEC 14496-2:2004 table 6-15
#define MP4_CHROMA_FORMAT_420    1
// ISO/IEC 14496-2:2004 table 6-16
enum {
    MP4_SHAPE_TYPE_RECTANGULAR  = 0,
    MP4_SHAPE_TYPE_BINARY       = 1,
    MP4_SHAPE_TYPE_BINARYONLY   = 2,
    MP4_SHAPE_TYPE_GRAYSCALE    = 3
};

// ISO/IEC 14496-2:2004 table 6-19
#define MP4_SPRITE_STATIC   1
#define MP4_SPRITE_GMC      2
// ISO/IEC 14496-2:2004 table 6-24
enum {
    MP4_VOP_TYPE_I  = 0,
    MP4_VOP_TYPE_P  = 1,
    MP4_VOP_TYPE_B  = 2,
    MP4_VOP_TYPE_S  = 3
};

// ISO/IEC 14496-2:2004 table 6-26
enum {
    MP4_SPRITE_TRANSMIT_MODE_STOP   = 0,
    MP4_SPRITE_TRANSMIT_MODE_PIECE  = 1,
    MP4_SPRITE_TRANSMIT_MODE_UPDATE = 2,
    MP4_SPRITE_TRANSMIT_MODE_PAUSE  = 3
};

/* Block Info */
struct mp4_Block {
    mp4_Block  *predA;
    mp4_Block  *predB;
    mp4_Block  *predC;
    Ipp16s     dct_acA[8];
    Ipp16s     dct_acC[8];
    Ipp16s     dct_dc;
    Ipp16s     dct_dcq;
    Ipp8u      quant;
    Ipp8u      validPredIntra;
};

/* MacroBlock Info */
struct mp4_MacroBlock {
    IppMotionVector mv[4], mvDiff[4], mvT, mvB;
    Ipp32s          lumaErr;
    mp4_Block       block[6];
    Ipp8u           type;
    Ipp8u           not_coded;
    Ipp8u           validPredInter;
    Ipp8u           mcsel;
    Ipp8u           fieldmc;
};

/* MacroBlock Info for MT */
#ifdef _OMP_KARABAS
struct mp4_MacroBlockMT {
    Ipp16s    dctCoeffs[64*6];
    Ipp32s    nzCount[6];
    Ipp32s    pat;
    Ipp32s    ac_pred_flag;
    Ipp32s    dct_type;
    Ipp32s    predDir[6];
    Ipp32s    mb_type;
    IppMotionVector mvForw, mvBack;
    Ipp8u     dummy[8];        // align 16
};
#endif // _OMP_KARABAS

/* Video Object Plane Info */
struct mp4_VideoObjectPlane {
    Ipp32s      vop_coding_type;
    Ipp32s      modulo_time_base;
    Ipp32s      vop_time_increment;
    Ipp32s      vop_coded;
    Ipp32s      vop_id;                             // verid != 1 (newpred)
    Ipp32s      vop_id_for_prediction_indication;   // verid != 1 (newpred)
    Ipp32s      vop_id_for_prediction;              // verid != 1 (newpred)
    Ipp32s      vop_rounding_type;
    Ipp32s      vop_reduced_resolution;             // verid != 1
    Ipp32s      vop_width;
    Ipp32s      vop_height;
    Ipp32s      vop_horizontal_mc_spatial_ref;
    Ipp32s      vop_vertical_mc_spatial_ref;
    Ipp32s      background_composition;
    Ipp32s      change_conv_ratio_disable;
    Ipp32s      vop_constant_alpha;
    Ipp32s      vop_constant_alpha_value;
    // complexity Estimation
    Ipp32s          dcecs_opaque;
    Ipp32s          dcecs_transparent;
    Ipp32s          dcecs_intra_cae;
    Ipp32s          dcecs_inter_cae;
    Ipp32s          dcecs_no_update;
    Ipp32s          dcecs_upsampling;
    Ipp32s          dcecs_intra_blocks;
    Ipp32s          dcecs_inter_blocks;
    Ipp32s          dcecs_inter4v_blocks;
    Ipp32s          dcecs_not_coded_blocks;
    Ipp32s          dcecs_dct_coefs;
    Ipp32s          dcecs_dct_lines;
    Ipp32s          dcecs_vlc_symbols;
    Ipp32s          dcecs_vlc_bits;
    Ipp32s          dcecs_apm;
    Ipp32s          dcecs_npm;
    Ipp32s          dcecs_interpolate_mc_q;
    Ipp32s          dcecs_forw_back_mc_q;
    Ipp32s          dcecs_halfpel2;
    Ipp32s          dcecs_halfpel4;
    Ipp32s          dcecs_sadct;                                // verid != 1
    Ipp32s          dcecs_quarterpel;                           // verid != 1
    Ipp32s      intra_dc_vlc_thr;
    Ipp32s      top_field_first;
    Ipp32s      alternate_vertical_scan_flag;
    Ipp32s      sprite_transmit_mode;
    Ipp32s      warping_mv_code_du[4];
    Ipp32s      warping_mv_code_dv[4];
    Ipp32s      brightness_change_factor;
    Ipp32s      vop_quant;
    Ipp32s      vop_alpha_quant;
    Ipp32s      vop_fcode_forward;
    Ipp32s      vop_fcode_backward;
    Ipp32s      vop_shape_coding_type;
    //          scalability info is absent
    // short header
    Ipp32s      temporal_reference;
    Ipp32s      temporal_reference_increment;
    Ipp32s      split_screen_indicator;
    Ipp32s      document_camera_indicator;
    Ipp32s      full_picture_freeze_release;
    Ipp32s      source_format;
    Ipp32s      picture_coding_type;
    Ipp32s      gob_number;
    Ipp32s      num_gobs_in_vop;
    Ipp32s      num_macroblocks_in_gob;
    Ipp32s      gob_header_empty;
    Ipp32s      gob_frame_id;
    Ipp32s      quant_scale;
};

/* Video Object Info */
struct mp4_VideoObjectLayer {
// iso part
    Ipp32s      video_object_layer_id;
    Ipp32s      short_video_header;
    Ipp32s      random_accessible_vol;
    Ipp32s      video_object_type_indication;
    Ipp32s      is_object_layer_identifier;
    Ipp32s          video_object_layer_verid;
    Ipp32s          video_object_layer_priority;
    Ipp32s      aspect_ratio_info;
    Ipp32s          par_width;
    Ipp32s          par_height;
    Ipp32s      vol_control_parameters;
    Ipp32s          chroma_format;
    Ipp32s          low_delay;
    Ipp32s          vbv_parameters;
    Ipp32s              first_half_bit_rate;
    Ipp32s              latter_half_bit_rate;
    Ipp32s              first_half_vbv_buffer_size;
    Ipp32s              latter_half_vbv_buffer_size;
    Ipp32s              first_half_vbv_occupancy;
    Ipp32s              latter_half_vbv_occupancy;
    Ipp32s      video_object_layer_shape;
    Ipp32s      video_object_layer_shape_extension; // verid != 1
    Ipp32s      vop_time_increment_resolution;
    Ipp32s      vop_time_increment_resolution_bits;
    Ipp32s      fixed_vop_rate;
    Ipp32s          fixed_vop_time_increment;
    Ipp32s      video_object_layer_width;
    Ipp32s      video_object_layer_height;
    Ipp32s      interlaced;
    Ipp32s      obmc_disable;
    Ipp32s      sprite_enable;                  // if verid != 1 (2 bit GMC is added)
    Ipp32s      sprite_width;
    Ipp32s      sprite_height;
    Ipp32s      sprite_left_coordinate;
    Ipp32s      sprite_top_coordinate;
    Ipp32s      no_of_sprite_warping_points;
    Ipp32s      sprite_warping_accuracy;
    Ipp32s      sprite_brightness_change;
    Ipp32s      low_latency_sprite_enable;
    Ipp32s      sadct_disable;                  // verid != 1
    Ipp32s      not_8_bit;
    Ipp32s          quant_precision;
    Ipp32s          bits_per_pixel;
    Ipp32s      no_gray_quant_update;
    Ipp32s      composition_method;
    Ipp32s      linear_composition;
    Ipp32s      quant_type;

⌨️ 快捷键说明

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