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

📄 common.h

📁 Linux环境下做的x264的全部源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * 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/**************************************************************************** * Macros ****************************************************************************/#define X264_MIN(a,b) ( (a)<(b) ? (a) : (b) )#define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) )#define X264_MIN3(a,b,c) X264_MIN((a),X264_MIN((b),(c)))#define X264_MAX3(a,b,c) X264_MAX((a),X264_MAX((b),(c)))#define X264_MIN4(a,b,c,d) X264_MIN((a),X264_MIN3((b),(c),(d)))#define X264_MAX4(a,b,c,d) X264_MAX((a),X264_MAX3((b),(c),(d)))#define XCHG(type,a,b) { type t = a; a = b; b = t; }#define FIX8(f) ((int)(f*(1<<8)+.5))#ifndef offsetof#define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))#endif#define CHECKED_MALLOC( var, size )\{\    var = x264_malloc( size );\    if( !var )\    {\        x264_log( h, X264_LOG_ERROR, "malloc failed\n" );\        goto fail;\    }\}#define X264_BFRAME_MAX 16#define X264_THREAD_MAX 128#define X264_SLICE_MAX 4#define X264_NAL_MAX (4 + X264_SLICE_MAX)// number of pixels (per thread) in progress at any given time.// 16 for the macroblock in progress + 3 for deblocking + 3 for motion compensation filter + 2 for extra safety#define X264_THREAD_HEIGHT 24/**************************************************************************** * Includes ****************************************************************************/#include "osdep.h"#include <stdarg.h>#include <stdlib.h>#include <string.h>#include <assert.h>#include "x264.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 ****************************************************************************//* x264_malloc : will do or emulate a memalign * you have to use x264_free for buffers allocated with x264_malloc */void *x264_malloc( int );void *x264_realloc( void *p, int i_size );void  x264_free( void * );/* x264_slurp_file: malloc space for the whole file and read it */char *x264_slurp_file( const char *filename );/* mdate: return the current date in microsecond */int64_t x264_mdate( void );/* x264_param2string: return a (malloced) string containing most of * the encoding options */char *x264_param2string( x264_param_t *p, int b_res );/* log */void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... );void x264_reduce_fraction( int *n, int *d );static inline int x264_clip3( int v, int i_min, int i_max ){    return ( (v < i_min) ? i_min : (v > i_max) ? i_max : v );}static inline double x264_clip3f( double v, double f_min, double f_max ){    return ( (v < f_min) ? f_min : (v > f_max) ? f_max : v );}static inline int x264_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{    x264_sps_t *sps;    x264_pps_t *pps;    int i_type;    int i_first_mb;    int i_last_mb;    int i_pps_id;    int i_frame_num;    int b_mbaff;    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;} x264_slice_header_t;/* From ffmpeg */#define X264_SCAN8_SIZE (6*8)#define X264_SCAN8_0 (4+1*8)static const int x264_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*/typedef struct x264_ratecontrol_t   x264_ratecontrol_t;typedef struct x264_vlc_table_t     x264_vlc_table_t;struct x264_t{    /* encoder parameters */    x264_param_t    param;    x264_t          *thread[X264_THREAD_MAX];    x264_pthread_t  thread_handle;    int             b_thread_active;    int             i_thread_phase; /* which thread to use for the next frame */    /* bitstream output */    struct    {        int         i_nal;        x264_nal_t  nal[X264_NAL_MAX];        int         i_bitstream;    /* size of p_bitstream */        uint8_t     *p_bitstream;   /* will hold data for all nal */        bs_t        bs;        int         i_frame_size;    } 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 */    x264_sps_t      sps_array[1];    x264_sps_t      *sps;    x264_pps_t      pps_array[1];    x264_pps_t      *pps;    int             i_idr_pic_id;    /* quantization matrix for decoding, [cqm][qp%6][coef_y][coef_x] */    int             (*dequant4_mf[4])[4][4]; /* [4][6][4][4] */    int             (*dequant8_mf[2])[8][8]; /* [2][6][8][8] */    /* quantization matrix for trellis, [cqm][qp][coef] */    int             (*unquant4_mf[4])[16];   /* [4][52][16] */    int             (*unquant8_mf[2])[64];   /* [2][52][64] */    /* quantization matrix for deadzone */    uint16_t        (*quant4_mf[4])[16];     /* [4][52][16] */    uint16_t        (*quant8_mf[2])[64];     /* [2][52][64] */    uint16_t        (*quant4_bias[4])[16];   /* [4][52][16] */    uint16_t        (*quant8_bias[2])[64];   /* [2][52][64] */    uint32_t        nr_residual_sum[2][64];    uint32_t        nr_offset[2][64];    uint32_t        nr_count[2];    /* Slice header */    x264_slice_header_t sh;

⌨️ 快捷键说明

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