📄 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#ifdef HAVE_STDINT_H#include <stdint.h>#else#include <inttypes.h>#endif#include <stdarg.h>#include <stdlib.h>#include <assert.h>#ifdef __GNUC__ #define printf(...)#else #define printf(x)#endif#ifdef _MSC_VER#define inline __inline#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)#define snprintf _snprintf#define X264_VERSION "" // no configure script for msvc#endif#ifdef _MSC_VER#define DECLARE_ALIGNED( type, var, n ) __declspec(align(n)) type var#else#define DECLARE_ALIGNED( type, var, n ) type var __attribute__((aligned(n)))#endif/* threads */#if defined(__WIN32__) && defined(HAVE_PTHREAD)#include <pthread.h>#define USE_CONDITION_VAR#elif defined(SYS_BEOS)#include <kernel/OS.h>#define pthread_t thread_id#define pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \ resume_thread(*(t)); }#define pthread_join(t,s) { long tmp; \ wait_for_thread(t,(s)?(long*)(s):&tmp); }#ifndef usleep#define usleep(t) snooze(t)#endif#define HAVE_PTHREAD 1#elif defined(HAVE_PTHREAD)#include <pthread.h>#define USE_CONDITION_VAR#else#define pthread_t int#define pthread_create(t,u,f,d)#define pthread_join(t,s)#endif //SYS_*#ifndef USE_CONDITION_VAR#define pthread_mutex_t int#define pthread_mutex_init(m,f)#define pthread_mutex_destroy(m)#define pthread_mutex_lock(m)#define pthread_mutex_unlock(m)#define pthread_cond_t int#define pthread_cond_init(c,f)#define pthread_cond_destroy(c)#define pthread_cond_broadcast(c)#define pthread_cond_wait(c,m) usleep(100)#endif/**************************************************************************** * 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#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)#define UNUSED __attribute__((unused))#else#define UNUSED#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)#define X264_THREAD_HEIGHT 24 // number of pixels (per thread) in progress at any given time. could theoretically be as low as 22/**************************************************************************** * Includes ****************************************************************************/#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 * XXX you HAVE TO use x264_free for buffer 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, ... );#ifdef __GNUC__ #define x264_log(...)#else #define x264_log(x)#endifvoid 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 float x264_clip3f( float v, float f_min, float 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]; 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -