📄 common.h
字号:
* @param bit_size the size of the buffer in bits */static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size){ const int buffer_size= (bit_size+7)>>3; s->buffer= buffer; s->size_in_bits= bit_size; s->buffer_end= buffer + buffer_size;#ifdef ALT_BITSTREAM_READER s->index=0;#elif defined LIBMPEG2_BITSTREAM_READER#ifdef LIBMPEG2_BITSTREAM_READER_HACK if ((int)buffer&1) { /* word alignment */ s->cache = (*buffer++)<<24; s->buffer_ptr = buffer; s->bit_count = 16-8; } else#endif { s->buffer_ptr = buffer; s->bit_count = 16; s->cache = 0; }#elif defined A32_BITSTREAM_READER s->buffer_ptr = (uint32_t*)buffer; s->bit_count = 32; s->cache0 = 0; s->cache1 = 0;#endif { OPEN_READER(re, s) UPDATE_CACHE(re, s) UPDATE_CACHE(re, s) CLOSE_READER(re, s) }#ifdef A32_BITSTREAM_READER s->cache1 = 0;#endif}int check_marker(GetBitContext *s, const char *msg);void align_get_bits(GetBitContext *s);int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size);void free_vlc(VLC *vlc);/** * * if the vlc code is invalid and max_depth=1 than no bits will be removed * if the vlc code is invalid and max_depth>1 than the number of bits removed * is undefined */#define GET_VLC(code, name, gb, table, bits, max_depth)\{\ int n, index, nb_bits;\\ index= SHOW_UBITS(name, gb, bits);\ code = table[index][0];\ n = table[index][1];\\ if(max_depth > 1 && n < 0){\ LAST_SKIP_BITS(name, gb, bits)\ UPDATE_CACHE(name, gb)\\ nb_bits = -n;\\ index= SHOW_UBITS(name, gb, nb_bits) + code;\ code = table[index][0];\ n = table[index][1];\ if(max_depth > 2 && n < 0){\ LAST_SKIP_BITS(name, gb, nb_bits)\ UPDATE_CACHE(name, gb)\\ nb_bits = -n;\\ index= SHOW_UBITS(name, gb, nb_bits) + code;\ code = table[index][0];\ n = table[index][1];\ }\ }\ SKIP_BITS(name, gb, n)\}#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth)\{\ int n, index, nb_bits;\\ index= SHOW_UBITS(name, gb, bits);\ level = table[index].level;\ n = table[index].len;\\ if(max_depth > 1 && n < 0){\ LAST_SKIP_BITS(name, gb, bits)\ UPDATE_CACHE(name, gb)\\ nb_bits = -n;\\ index= SHOW_UBITS(name, gb, nb_bits) + level;\ level = table[index].level;\ n = table[index].len;\ }\ run= table[index].run;\ SKIP_BITS(name, gb, n)\}// deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directlystatic inline int get_vlc(GetBitContext *s, VLC *vlc){ int code; VLC_TYPE (*table)[2]= vlc->table; OPEN_READER(re, s) UPDATE_CACHE(re, s) GET_VLC(code, re, s, table, vlc->bits, 3) CLOSE_READER(re, s) return code;}/** * parses a vlc code, faster then get_vlc() * @param bits is the number of bits which will be read at once, must be * identical to nb_bits in init_vlc() * @param max_depth is the number of times bits bits must be readed to completly * read the longest vlc code * = (max_vlc_length + bits - 1) / bits */static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth){ int code; OPEN_READER(re, s) UPDATE_CACHE(re, s) GET_VLC(code, re, s, table, bits, max_depth) CLOSE_READER(re, s) return code;}//#define TRACE#ifdef TRACEstatic inline void print_bin(int bits, int n){ int i; for(i=n-1; i>=0; i--){ printf("%d", (bits>>i)&1); } for(i=n; i<24; i++) printf(" ");}static inline int get_bits_trace(GetBitContext *s, int n, char *file, char *func, int line){ int r= get_bits(s, n); print_bin(r, n); printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); return r;}static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, char *func, int line){ int show= show_bits(s, 24); int pos= get_bits_count(s); int r= get_vlc2(s, table, bits, max_depth); int len= get_bits_count(s) - pos; int bits2= show>>(24-len); print_bin(bits2, len); printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); return r;}static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *func, int line){ int show= show_bits(s, n); int r= get_xbits(s, n); print_bin(show, n); printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); return r;}#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)#define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__)#else //TRACE#ifndef WINCE
#define tprintf(...) {}
#endif#endif/* define it to include statistics code (useful only for optimizing codec efficiency *///#define STATS#ifdef STATSenum { ST_UNKNOWN, ST_DC, ST_INTRA_AC, ST_INTER_AC, ST_INTRA_MB, ST_INTER_MB, ST_MV, ST_NB,};extern int st_current_index;extern unsigned int st_bit_counts[ST_NB];extern unsigned int st_out_bit_counts[ST_NB];void print_stats(void);#endif/* misc math functions */extern const uint8_t ff_log2_tab[256];static inline int av_log2(unsigned int v){ int n; n = 0; if (v & 0xffff0000) { v >>= 16; n += 16; } if (v & 0xff00) { v >>= 8; n += 8; } n += ff_log2_tab[v]; return n;}static inline int av_log2_16bit(unsigned int v){ int n; n = 0; if (v & 0xff00) { v >>= 8; n += 8; } n += ff_log2_tab[v]; return n;}/* median of 3 */static inline int mid_pred(int a, int b, int c){#if 0 int t= (a-b)&((a-b)>>31); a-=t; b+=t; b-= (b-c)&((b-c)>>31); b+= (a-b)&((a-b)>>31); return b;#else if(a>b){ if(c>b){ if(c>a) b=a; else b=c; } }else{ if(b>c){ if(c>a) b=c; else b=a; } } return b;#endif}static inline int clip(int a, int amin, int amax){ if (a < amin) return amin; else if (a > amax) return amax; else return a;}static inline int clip_uint8(int a){ if (a&(~255)) return (-a)>>31; else return a;}/* math */extern const uint8_t ff_sqrt_tab[128];int64_t ff_gcd(int64_t a, int64_t b);static inline int ff_sqrt(int a){ int ret=0; int s; int ret_sq=0; if(a<128) return ff_sqrt_tab[a]; for(s=15; s>=0; s--){ int b= ret_sq + (1<<(s*2)) + (ret<<s)*2; if(b<=a){ ret_sq=b; ret+= 1<<s; } } return ret;}/** * converts fourcc string to int */static inline int ff_get_fourcc(const char *s){#ifndef WINCE //assert
assert( strlen(s)==4 );
#endif return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);}#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))#ifdef ARCH_X86#define MASK_ABS(mask, level)\ asm volatile(\ "cdq \n\t"\ "xorl %1, %0 \n\t"\ "subl %1, %0 \n\t"\ : "+a" (level), "=&d" (mask)\ );#else#define MASK_ABS(mask, level)\ mask= level>>31;\ level= (level^mask)-mask;#endif#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)#define COPY3_IF_LT(x,y,a,b,c,d)\asm volatile (\ "cmpl %0, %3 \n\t"\ "cmovl %3, %0 \n\t"\ "cmovl %4, %1 \n\t"\ "cmovl %5, %2 \n\t"\ : "+r" (x), "+r" (a), "+r" (c)\ : "r" (y), "r" (b), "r" (d)\);#else#define COPY3_IF_LT(x,y,a,b,c,d)\if((y)<(x)){\ (x)=(y);\ (a)=(b);\ (c)=(d);\}#endif#ifdef ARCH_X86static inline long long rdtsc(){ long long l; asm volatile( "rdtsc\n\t" : "=A" (l) ); return l;}#define START_TIMER \uint64_t tend;\uint64_t tstart= rdtsc();\#define STOP_TIMER(id) \tend= rdtsc();\{\ static uint64_t tsum=0;\ static int tcount=0;\ static int tskip_count=0;\ if(tcount<2 || tend - tstart < 8*tsum/tcount){\ tsum+= tend - tstart;\ tcount++;\ }else\ tskip_count++;\ if(256*256*256*64%(tcount+tskip_count)==0){\ av_log(NULL, AV_LOG_DEBUG, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ }\}#endif#define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d)/* avoid usage of various functions *//*#define malloc please_use_av_malloc#define free please_use_av_free#define realloc please_use_av_realloc#define time time_is_forbidden_due_to_security_issues#define rand rand_is_forbidden_due_to_state_trashing#define srand srand_is_forbidden_due_to_state_trashing*/#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
#ifdef WINCE
#define printf
#define fprintf
#else#define printf please_use_av_log#define fprintf please_use_av_log#endif
#endif
#ifdef WINCE#define CHECKED_ALLOCZ(p, size)\{\ p= av_mallocz(size);\ if(p==NULL && (size)!=0){\ goto fail;\ }\}
#else
#define CHECKED_ALLOCZ(p, size)\
{\
p= av_mallocz(size);\
if(p==NULL && (size)!=0){\
perror("malloc");\
goto fail;\
}\
}
#endif#endif /* HAVE_AV_CONFIG_H */#endif /* COMMON_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -