📄 common.h
字号:
/***************************************************************************** * common.h: h264 encoder ***************************************************************************** * Copyright (C) 2003 Laurent Aimar * $Id: common.h,v 1.1 2004/06/03 19:27:06 fenrir Exp $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/#ifndef _COMMON_H#define _COMMON_H 1
#define HAVE_STDINT_H 1 //lsp051209#ifdef HAVE_STDINT_H#include <stdint.h>#else#include <inttypes.h>#endif#include <stdarg.h>#ifdef _MSC_VER#define snprintf _snprintf#define SHU264_VERSION "" // no configure script for msvc#endif/**************************************************************************** * Macros ****************************************************************************/#define SHU264_MIN(a,b) ( (a)<(b) ? (a) : (b) )#define SHU264_MAX(a,b) ( (a)>(b) ? (a) : (b) )#define SHU264_MIN3(a,b,c) SHU264_MIN((a),SHU264_MIN((b),(c)))#define SHU264_MAX3(a,b,c) SHU264_MAX((a),SHU264_MAX((b),(c)))#define SHU264_MIN4(a,b,c,d) SHU264_MIN((a),SHU264_MIN3((b),(c),(d)))#define SHU264_MAX4(a,b,c,d) SHU264_MAX((a),SHU264_MAX3((b),(c),(d)))#define XCHG(type,a,b) { type t = a; a = b; b = t; }#define FIX8(f) ((int)(f*(1<<8)+.5))/**************************************************************************** * Includes ****************************************************************************/#include "SHU264.h"#include "bs.h"#include "set.h"#include "predict.h"#include "pixel.h"#include "mc.h"#include "frame.h"#include "dct.h"#include "cabac.h"#include "csp.h"#include "quant.h"/**************************************************************************** * Generals functions ****************************************************************************//* SHU264_malloc : will do or emulate a memalign * XXX you HAVE TO use SHU264_free for buffer allocated * with SHU264_malloc */void *SHU264_malloc( int );void *SHU264_realloc( void *p, int i_size );void SHU264_free( void * );/* mdate: return the current date in microsecond */int64_t SHU264_mdate( void );/* log */void SHU264_log( SHU264_t *h, int i_level, const char *psz_fmt, ... );static __inline int SHU264_clip3( int v, int i_min, int i_max ){ return ( (v < i_min) ? i_min : (v > i_max) ? i_max : v );}static __inline float SHU264_clip3f( float v, float f_min, float f_max ){ return ( (v < f_min) ? f_min : (v > f_max) ? f_max : v );}static __inline int SHU264_median( int a, int b, int c ){ int min = a, max =a; if( b < min ) min = b; else max = b; /* no need to do 'b > max' (more consuming than always doing affectation) */ if( c < min ) min = c; else if( c > max ) max = c; return a + b + c - min - max;}/**************************************************************************** * ****************************************************************************/enum slice_type_e{ SLICE_TYPE_P = 0, SLICE_TYPE_B = 1, SLICE_TYPE_I = 2, SLICE_TYPE_SP = 3, SLICE_TYPE_SI = 4};static const char slice_type_to_char[] = { 'P', 'B', 'I', 'S', 'S' };typedef struct{ SHU264_sps_t *sps; SHU264_pps_t *pps; int i_type; int i_first_mb; int i_last_mb; int i_pps_id; int i_frame_num; int b_field_pic; int b_bottom_field; int i_idr_pic_id; /* -1 if nal_type != 5 */ int i_poc_lsb; int i_delta_poc_bottom; int i_delta_poc[2]; int i_redundant_pic_cnt; int b_direct_spatial_mv_pred; int b_num_ref_idx_override; int i_num_ref_idx_l0_active; int i_num_ref_idx_l1_active; int b_ref_pic_list_reordering_l0; int b_ref_pic_list_reordering_l1; struct { int idc; int arg; } ref_pic_list_order[2][16]; int i_cabac_init_idc; int i_qp; int i_qp_delta; int b_sp_for_swidth; int i_qs_delta; /* deblocking filter */ int i_disable_deblocking_filter_idc; int i_alpha_c0_offset; int i_beta_offset;} SHU264_slice_header_t;/* From ffmpeg */#define SHU264_SCAN8_SIZE (6*8)#define SHU264_SCAN8_0 (4+1*8)static const int SHU264_scan8[16+2*4] ={ /* Luma */ 4+1*8, 5+1*8, 4+2*8, 5+2*8, 6+1*8, 7+1*8, 6+2*8, 7+2*8, 4+3*8, 5+3*8, 4+4*8, 5+4*8, 6+3*8, 7+3*8, 6+4*8, 7+4*8, /* Cb */ 1+1*8, 2+1*8, 1+2*8, 2+2*8, /* Cr */ 1+4*8, 2+4*8, 1+5*8, 2+5*8,};/* 0 1 2 3 4 5 6 7 0 1 B B L L L L 2 B B L L L L 3 L L L L 4 R R L L L L 5 R R*/#define SHU264_BFRAME_MAX 16#define SHU264_SLICE_MAX 4#define SHU264_NAL_MAX (4 + SHU264_SLICE_MAX)typedef struct SHU264_ratecontrol_t SHU264_ratecontrol_t;typedef struct SHU264_vlc_table_t SHU264_vlc_table_t;struct SHU264_t{ /* encoder parameters */ SHU264_param_t param; SHU264_t *thread[SHU264_SLICE_MAX]; /* bitstream output */ struct { int i_nal; SHU264_nal_t nal[SHU264_NAL_MAX]; int i_bitstream; /* size of p_bitstream */ uint8_t *p_bitstream; /* will hold data for all nal */ bs_t bs; } out; /* frame number/poc */ int i_frame; int i_frame_offset; /* decoding only */ int i_frame_num; /* decoding only */ int i_poc_msb; /* decoding only */ int i_poc_lsb; /* decoding only */ int i_poc; /* decoding only */ int i_thread_num; /* threads only */ int i_nal_type; /* threads only */ int i_nal_ref_idc; /* threads only */ /* We use only one SPS and one PPS */ SHU264_sps_t sps_array[1]; SHU264_sps_t *sps; SHU264_pps_t pps_array[1]; SHU264_pps_t *pps; int i_idr_pic_id; int dequant4_mf[4][6][4][4]; int dequant8_mf[2][6][8][8]; int quant4_mf[4][6][4][4]; int quant8_mf[2][6][8][8]; int unquant4_mf[4][52][16]; int unquant8_mf[2][52][64]; /* Slice header */ SHU264_slice_header_t sh; /* cabac context */ SHU264_cabac_t cabac; struct { /* Frames to be encoded (whose types have been decided) */ SHU264_frame_t *current[SHU264_BFRAME_MAX+3]; /* Temporary buffer (frames types not yet decided) */ SHU264_frame_t *next[SHU264_BFRAME_MAX+3];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -