You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

727 lines
16KB

  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #define FFMPEG_VERSION_INT 0x000406
  4. #define FFMPEG_VERSION "0.4.6"
  5. #if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
  6. #define CONFIG_WIN32
  7. #endif
  8. //#define ALT_BITSTREAM_WRITER
  9. //#define ALIGNED_BITSTREAM_WRITER
  10. //#define ALT_BITSTREAM_READER
  11. //#define ALIGNED_BITSTREAM
  12. #define FAST_GET_FIRST_VLC
  13. #ifdef HAVE_AV_CONFIG_H
  14. /* only include the following when compiling package */
  15. #include "../config.h"
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <errno.h>
  20. #ifndef ENODATA
  21. #define ENODATA 61
  22. #endif
  23. #endif
  24. #ifdef CONFIG_WIN32
  25. /* windows */
  26. typedef unsigned short UINT16;
  27. typedef signed short INT16;
  28. typedef unsigned char UINT8;
  29. typedef unsigned int UINT32;
  30. typedef unsigned __int64 UINT64;
  31. typedef signed char INT8;
  32. typedef signed int INT32;
  33. typedef signed __int64 INT64;
  34. typedef UINT8 uint8_t;
  35. typedef INT8 int8_t;
  36. typedef UINT16 uint16_t;
  37. typedef INT16 int16_t;
  38. typedef UINT32 uint32_t;
  39. typedef INT32 int32_t;
  40. #ifndef __MINGW32__
  41. #define INT64_C(c) (c ## i64)
  42. #define UINT64_C(c) (c ## i64)
  43. #define inline __inline
  44. /*
  45. Disable warning messages:
  46. warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
  47. warning C4305: 'argument' : truncation from 'const double' to 'float'
  48. */
  49. #pragma warning( disable : 4244 )
  50. #pragma warning( disable : 4305 )
  51. #else
  52. #define INT64_C(c) (c ## LL)
  53. #define UINT64_C(c) (c ## ULL)
  54. #endif /* __MINGW32__ */
  55. #define M_PI 3.14159265358979323846
  56. #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  57. #ifdef _DEBUG
  58. #define DEBUG
  59. #endif
  60. // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
  61. #define bswap_32(x) \
  62. ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
  63. (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
  64. #define be2me_32(x) bswap_32(x)
  65. #define snprintf _snprintf
  66. #ifndef __MINGW32__
  67. /* no config.h with VC */
  68. #define CONFIG_ENCODERS 1
  69. #define CONFIG_DECODERS 1
  70. #define CONFIG_AC3 1
  71. #endif
  72. #else
  73. /* unix */
  74. #include <inttypes.h>
  75. #ifndef __WINE_WINDEF16_H
  76. /* workaround for typedef conflict in MPlayer (wine typedefs) */
  77. typedef unsigned short UINT16;
  78. typedef signed short INT16;
  79. #endif
  80. typedef unsigned char UINT8;
  81. typedef unsigned int UINT32;
  82. typedef unsigned long long UINT64;
  83. typedef signed char INT8;
  84. typedef signed int INT32;
  85. typedef signed long long INT64;
  86. #ifdef HAVE_AV_CONFIG_H
  87. #ifdef __FreeBSD__
  88. #include <sys/param.h>
  89. #endif
  90. #ifndef INT64_C
  91. #define INT64_C(c) (c ## LL)
  92. #define UINT64_C(c) (c ## ULL)
  93. #endif
  94. #include "../bswap.h"
  95. #ifdef USE_FASTMEMCPY
  96. #include "fastmemcpy.h"
  97. #endif
  98. #endif /* HAVE_AV_CONFIG_H */
  99. #endif /* !CONFIG_WIN32 */
  100. /* debug stuff */
  101. #ifdef HAVE_AV_CONFIG_H
  102. #ifndef DEBUG
  103. #define NDEBUG
  104. #endif
  105. #include <assert.h>
  106. /* dprintf macros */
  107. #if defined(CONFIG_WIN32) && !defined(__MINGW32__)
  108. inline void dprintf(const char* fmt,...) {}
  109. #else
  110. #ifdef DEBUG
  111. #define dprintf(fmt,args...) printf(fmt, ## args)
  112. #else
  113. #define dprintf(fmt,args...)
  114. #endif
  115. #endif /* !CONFIG_WIN32 */
  116. #endif /* HAVE_AV_CONFIG_H */
  117. /* bit output */
  118. struct PutBitContext;
  119. typedef void (*WriteDataFunc)(void *, UINT8 *, int);
  120. typedef struct PutBitContext {
  121. #ifdef ALT_BITSTREAM_WRITER
  122. UINT8 *buf, *buf_end;
  123. int index;
  124. #else
  125. UINT32 bit_buf;
  126. int bit_cnt;
  127. UINT8 *buf, *buf_ptr, *buf_end;
  128. void *opaque;
  129. WriteDataFunc write_data;
  130. #endif
  131. INT64 data_out_size; /* in bytes */
  132. } PutBitContext;
  133. void init_put_bits(PutBitContext *s,
  134. UINT8 *buffer, int buffer_size,
  135. void *opaque,
  136. void (*write_data)(void *, UINT8 *, int));
  137. #ifndef ALT_BITSTREAM_WRITER
  138. void put_bits(PutBitContext *s, int n, unsigned int value);
  139. #endif
  140. INT64 get_bit_count(PutBitContext *s); /* XXX: change function name */
  141. void align_put_bits(PutBitContext *s);
  142. void flush_put_bits(PutBitContext *s);
  143. /* jpeg specific put_bits */
  144. #ifndef ALT_BITSTREAM_WRITER
  145. void jput_bits(PutBitContext *s, int n, unsigned int value);
  146. #endif
  147. void jflush_put_bits(PutBitContext *s);
  148. /* bit input */
  149. typedef struct GetBitContext {
  150. #ifdef ALT_BITSTREAM_READER
  151. int index;
  152. UINT8 *buffer;
  153. #else
  154. UINT32 bit_buf;
  155. int bit_cnt;
  156. UINT8 *buf, *buf_ptr, *buf_end;
  157. #endif
  158. } GetBitContext;
  159. typedef struct VLC {
  160. int bits;
  161. INT16 *table_codes;
  162. INT8 *table_bits;
  163. int table_size, table_allocated;
  164. } VLC;
  165. /* used to avoid missaligned exceptions on some archs (alpha, ...) */
  166. #ifdef ARCH_X86
  167. #define unaligned32(a) (*(UINT32*)(a))
  168. #else
  169. #ifdef __GNUC__
  170. static inline uint32_t unaligned32(const void *v) {
  171. struct Unaligned {
  172. uint32_t i;
  173. } __attribute__((packed));
  174. return ((const struct Unaligned *) v)->i;
  175. }
  176. #elif defined(__DECC)
  177. static inline uint32_t unaligned32(const void *v) {
  178. return *(const __unaligned uint32_t *) v;
  179. }
  180. #else
  181. static inline uint32_t unaligned32(const void *v) {
  182. return *(const uint32_t *) v;
  183. }
  184. #endif
  185. #endif //!ARCH_X86
  186. #ifdef ALT_BITSTREAM_WRITER
  187. static inline void put_bits(PutBitContext *s, int n, unsigned int value)
  188. {
  189. #ifdef ALIGNED_BITSTREAM_WRITER
  190. #ifdef ARCH_X86
  191. asm volatile(
  192. "movl %0, %%ecx \n\t"
  193. "xorl %%eax, %%eax \n\t"
  194. "shrdl %%cl, %1, %%eax \n\t"
  195. "shrl %%cl, %1 \n\t"
  196. "movl %0, %%ecx \n\t"
  197. "shrl $3, %%ecx \n\t"
  198. "andl $0xFFFFFFFC, %%ecx \n\t"
  199. "bswapl %1 \n\t"
  200. "orl %1, (%2, %%ecx) \n\t"
  201. "bswapl %%eax \n\t"
  202. "addl %3, %0 \n\t"
  203. "movl %%eax, 4(%2, %%ecx) \n\t"
  204. : "=&r" (s->index), "=&r" (value)
  205. : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
  206. : "%eax", "%ecx"
  207. );
  208. #else
  209. int index= s->index;
  210. uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
  211. value<<= 32-n;
  212. ptr[0] |= be2me_32(value>>(index&31));
  213. ptr[1] = be2me_32(value<<(32-(index&31)));
  214. //if(n>24) printf("%d %d\n", n, value);
  215. index+= n;
  216. s->index= index;
  217. #endif
  218. #else //ALIGNED_BITSTREAM_WRITER
  219. #ifdef ARCH_X86
  220. asm volatile(
  221. "movl $7, %%ecx \n\t"
  222. "andl %0, %%ecx \n\t"
  223. "addl %3, %%ecx \n\t"
  224. "negl %%ecx \n\t"
  225. "shll %%cl, %1 \n\t"
  226. "bswapl %1 \n\t"
  227. "movl %0, %%ecx \n\t"
  228. "shrl $3, %%ecx \n\t"
  229. "orl %1, (%%ecx, %2) \n\t"
  230. "addl %3, %0 \n\t"
  231. "movl $0, 4(%%ecx, %2) \n\t"
  232. : "=&r" (s->index), "=&r" (value)
  233. : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
  234. : "%ecx"
  235. );
  236. #else
  237. int index= s->index;
  238. uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
  239. ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
  240. ptr[1] = 0;
  241. //if(n>24) printf("%d %d\n", n, value);
  242. index+= n;
  243. s->index= index;
  244. #endif
  245. #endif //!ALIGNED_BITSTREAM_WRITER
  246. }
  247. #endif
  248. #ifdef ALT_BITSTREAM_WRITER
  249. static inline void jput_bits(PutBitContext *s, int n, int value)
  250. {
  251. int index= s->index;
  252. uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
  253. int v= ptr[0];
  254. //if(n>24) printf("%d %d\n", n, value);
  255. v |= be2me_32(value<<(32-n-(index&7) ));
  256. if(((v+0x01010101)^0xFFFFFFFF)&v&0x80808080)
  257. {
  258. /* handle idiotic (m)jpeg escapes */
  259. uint8_t *bPtr= (uint8_t*)ptr;
  260. int numChecked= ((index+n)>>3) - (index>>3);
  261. v= be2me_32(v);
  262. *(bPtr++)= v>>24;
  263. if((v&0xFF000000)==0xFF000000 && numChecked>0){
  264. *(bPtr++)= 0x00;
  265. index+=8;
  266. }
  267. *(bPtr++)= (v>>16)&0xFF;
  268. if((v&0x00FF0000)==0x00FF0000 && numChecked>1){
  269. *(bPtr++)= 0x00;
  270. index+=8;
  271. }
  272. *(bPtr++)= (v>>8)&0xFF;
  273. if((v&0x0000FF00)==0x0000FF00 && numChecked>2){
  274. *(bPtr++)= 0x00;
  275. index+=8;
  276. }
  277. *(bPtr++)= v&0xFF;
  278. if((v&0x000000FF)==0x000000FF && numChecked>3){
  279. *(bPtr++)= 0x00;
  280. index+=8;
  281. }
  282. *((uint32_t*)bPtr)= 0;
  283. }
  284. else
  285. {
  286. ptr[0] = v;
  287. ptr[1] = 0;
  288. }
  289. index+= n;
  290. s->index= index;
  291. }
  292. #endif
  293. static inline uint8_t* pbBufPtr(PutBitContext *s)
  294. {
  295. #ifdef ALT_BITSTREAM_WRITER
  296. return s->buf + (s->index>>3);
  297. #else
  298. return s->buf_ptr;
  299. #endif
  300. }
  301. void init_get_bits(GetBitContext *s,
  302. UINT8 *buffer, int buffer_size);
  303. #ifndef ALT_BITSTREAM_READER
  304. unsigned int get_bits_long(GetBitContext *s, int n);
  305. unsigned int show_bits_long(GetBitContext *s, int n);
  306. #endif
  307. static inline unsigned int get_bits(GetBitContext *s, int n){
  308. #ifdef ALT_BITSTREAM_READER
  309. #ifdef ALIGNED_BITSTREAM
  310. int index= s->index;
  311. uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] );
  312. uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] );
  313. #ifdef ARCH_X86
  314. asm ("shldl %%cl, %2, %0\n\t"
  315. : "=r" (result1)
  316. : "0" (result1), "r" (result2), "c" (index));
  317. #else
  318. result1<<= (index&0x1F);
  319. result2= (result2>>1) >> (31-(index&0x1F));
  320. result1|= result2;
  321. #endif
  322. result1>>= 32 - n;
  323. index+= n;
  324. s->index= index;
  325. return result1;
  326. #else //ALIGNED_BITSTREAM
  327. int index= s->index;
  328. uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) );
  329. result<<= (index&0x07);
  330. result>>= 32 - n;
  331. index+= n;
  332. s->index= index;
  333. return result;
  334. #endif //!ALIGNED_BITSTREAM
  335. #else //ALT_BITSTREAM_READER
  336. if(s->bit_cnt>=n){
  337. /* most common case here */
  338. unsigned int val = s->bit_buf >> (32 - n);
  339. s->bit_buf <<= n;
  340. s->bit_cnt -= n;
  341. #ifdef STATS
  342. st_bit_counts[st_current_index] += n;
  343. #endif
  344. return val;
  345. }
  346. return get_bits_long(s,n);
  347. #endif //!ALT_BITSTREAM_READER
  348. }
  349. static inline unsigned int get_bits1(GetBitContext *s){
  350. #ifdef ALT_BITSTREAM_READER
  351. int index= s->index;
  352. uint8_t result= s->buffer[ index>>3 ];
  353. result<<= (index&0x07);
  354. result>>= 8 - 1;
  355. index++;
  356. s->index= index;
  357. return result;
  358. #else
  359. if(s->bit_cnt>0){
  360. /* most common case here */
  361. unsigned int val = s->bit_buf >> 31;
  362. s->bit_buf <<= 1;
  363. s->bit_cnt--;
  364. #ifdef STATS
  365. st_bit_counts[st_current_index]++;
  366. #endif
  367. return val;
  368. }
  369. return get_bits_long(s,1);
  370. #endif
  371. }
  372. /* This function is identical to get_bits(), the only */
  373. /* diference is that it doesn't touch the buffer */
  374. /* it is usefull to see the buffer. */
  375. static inline unsigned int show_bits(GetBitContext *s, int n)
  376. {
  377. #ifdef ALT_BITSTREAM_READER
  378. #ifdef ALIGNED_BITSTREAM
  379. int index= s->index;
  380. uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] );
  381. uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] );
  382. #ifdef ARCH_X86
  383. asm ("shldl %%cl, %2, %0\n\t"
  384. : "=r" (result1)
  385. : "0" (result1), "r" (result2), "c" (index));
  386. #else
  387. result1<<= (index&0x1F);
  388. result2= (result2>>1) >> (31-(index&0x1F));
  389. result1|= result2;
  390. #endif
  391. result1>>= 32 - n;
  392. return result1;
  393. #else //ALIGNED_BITSTREAM
  394. int index= s->index;
  395. uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) );
  396. result<<= (index&0x07);
  397. result>>= 32 - n;
  398. return result;
  399. #endif //!ALIGNED_BITSTREAM
  400. #else //ALT_BITSTREAM_READER
  401. if(s->bit_cnt>=n) {
  402. /* most common case here */
  403. unsigned int val = s->bit_buf >> (32 - n);
  404. return val;
  405. }
  406. return show_bits_long(s,n);
  407. #endif //!ALT_BITSTREAM_READER
  408. }
  409. static inline void skip_bits(GetBitContext *s, int n){
  410. #ifdef ALT_BITSTREAM_READER
  411. s->index+= n;
  412. #else
  413. if(s->bit_cnt>=n){
  414. /* most common case here */
  415. s->bit_buf <<= n;
  416. s->bit_cnt -= n;
  417. #ifdef STATS
  418. st_bit_counts[st_current_index] += n;
  419. #endif
  420. } else {
  421. get_bits_long(s,n);
  422. }
  423. #endif
  424. }
  425. static inline void skip_bits1(GetBitContext *s){
  426. #ifdef ALT_BITSTREAM_READER
  427. s->index++;
  428. #else
  429. if(s->bit_cnt>0){
  430. /* most common case here */
  431. s->bit_buf <<= 1;
  432. s->bit_cnt--;
  433. #ifdef STATS
  434. st_bit_counts[st_current_index]++;
  435. #endif
  436. } else {
  437. get_bits_long(s,1);
  438. }
  439. #endif
  440. }
  441. static inline int get_bits_count(GetBitContext *s)
  442. {
  443. #ifdef ALT_BITSTREAM_READER
  444. return s->index;
  445. #else
  446. return (s->buf_ptr - s->buf) * 8 - s->bit_cnt;
  447. #endif
  448. }
  449. void align_get_bits(GetBitContext *s);
  450. int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
  451. const void *bits, int bits_wrap, int bits_size,
  452. const void *codes, int codes_wrap, int codes_size);
  453. void free_vlc(VLC *vlc);
  454. #ifdef ALT_BITSTREAM_READER
  455. #ifdef ALIGNED_BITSTREAM
  456. #ifdef ARCH_X86
  457. #define SHOW_BITS(s, val, n) \
  458. val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
  459. {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
  460. asm ("shldl %%cl, %2, %0\n\t"\
  461. : "=r" (val)\
  462. : "0" (val), "r" (result2), "c" (bit_cnt));\
  463. ((uint32_t)val)>>= 32 - n;}
  464. #else //ARCH_X86
  465. #define SHOW_BITS(s, val, n) \
  466. val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\
  467. {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\
  468. val<<= (bit_cnt&0x1F);\
  469. result2= (result2>>1) >> (31-(bit_cnt&0x1F));\
  470. val|= result2;\
  471. ((uint32_t)val)>>= 32 - n;}
  472. #endif //!ARCH_X86
  473. #else //ALIGNED_BITSTREAM
  474. #define SHOW_BITS(s, val, n) \
  475. val= be2me_32( unaligned32( ((uint8_t *)(s)->buffer)+(bit_cnt>>3) ) );\
  476. val<<= (bit_cnt&0x07);\
  477. ((uint32_t)val)>>= 32 - n;
  478. #endif // !ALIGNED_BITSTREAM
  479. #define FLUSH_BITS(n) bit_cnt+=n;
  480. #define SAVE_BITS(s) bit_cnt= (s)->index;
  481. #define RESTORE_BITS(s) (s)->index= bit_cnt;
  482. #else
  483. /* macro to go faster */
  484. /* n must be <= 24 */
  485. /* XXX: optimize buffer end test */
  486. #define SHOW_BITS(s, val, n)\
  487. {\
  488. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  489. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  490. bit_cnt += 8;\
  491. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  492. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  493. bit_cnt += 8;\
  494. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  495. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  496. bit_cnt += 8;\
  497. }\
  498. }\
  499. }\
  500. val = bit_buf >> (32 - n);\
  501. }
  502. /* SHOW_BITS with n1 >= n must be been done before */
  503. #define FLUSH_BITS(n)\
  504. {\
  505. bit_buf <<= n;\
  506. bit_cnt -= n;\
  507. }
  508. #define SAVE_BITS(s) \
  509. {\
  510. bit_cnt = (s)->bit_cnt;\
  511. bit_buf = (s)->bit_buf;\
  512. buf_ptr = (s)->buf_ptr;\
  513. }
  514. #define RESTORE_BITS(s) \
  515. {\
  516. (s)->buf_ptr = buf_ptr;\
  517. (s)->bit_buf = bit_buf;\
  518. (s)->bit_cnt = bit_cnt;\
  519. }
  520. #endif // !ALT_BITSTREAM_READER
  521. static inline int get_vlc(GetBitContext *s, VLC *vlc)
  522. {
  523. int code, n, nb_bits, index;
  524. INT16 *table_codes;
  525. INT8 *table_bits;
  526. int bit_cnt;
  527. #ifndef ALT_BITSTREAM_READER
  528. UINT32 bit_buf;
  529. UINT8 *buf_ptr;
  530. #endif
  531. SAVE_BITS(s);
  532. nb_bits = vlc->bits;
  533. table_codes = vlc->table_codes;
  534. table_bits = vlc->table_bits;
  535. #ifdef FAST_GET_FIRST_VLC
  536. SHOW_BITS(s, index, nb_bits);
  537. code = table_codes[index];
  538. n = table_bits[index];
  539. if (n > 0) {
  540. /* most common case (90%)*/
  541. FLUSH_BITS(n);
  542. RESTORE_BITS(s);
  543. return code;
  544. } else if (n == 0) {
  545. return -1;
  546. } else {
  547. FLUSH_BITS(nb_bits);
  548. nb_bits = -n;
  549. table_codes = vlc->table_codes + code;
  550. table_bits = vlc->table_bits + code;
  551. }
  552. #endif
  553. for(;;) {
  554. SHOW_BITS(s, index, nb_bits);
  555. code = table_codes[index];
  556. n = table_bits[index];
  557. if (n > 0) {
  558. /* most common case */
  559. FLUSH_BITS(n);
  560. #ifdef STATS
  561. st_bit_counts[st_current_index] += n;
  562. #endif
  563. break;
  564. } else if (n == 0) {
  565. return -1;
  566. } else {
  567. FLUSH_BITS(nb_bits);
  568. #ifdef STATS
  569. st_bit_counts[st_current_index] += nb_bits;
  570. #endif
  571. nb_bits = -n;
  572. table_codes = vlc->table_codes + code;
  573. table_bits = vlc->table_bits + code;
  574. }
  575. }
  576. RESTORE_BITS(s);
  577. return code;
  578. }
  579. /* define it to include statistics code (useful only for optimizing
  580. codec efficiency */
  581. //#define STATS
  582. #ifdef STATS
  583. enum {
  584. ST_UNKNOWN,
  585. ST_DC,
  586. ST_INTRA_AC,
  587. ST_INTER_AC,
  588. ST_INTRA_MB,
  589. ST_INTER_MB,
  590. ST_MV,
  591. ST_NB,
  592. };
  593. extern int st_current_index;
  594. extern unsigned int st_bit_counts[ST_NB];
  595. extern unsigned int st_out_bit_counts[ST_NB];
  596. void print_stats(void);
  597. #endif
  598. /* misc math functions */
  599. static inline int av_log2(unsigned int v)
  600. {
  601. int n;
  602. n = 0;
  603. if (v & 0xffff0000) {
  604. v >>= 16;
  605. n += 16;
  606. }
  607. if (v & 0xff00) {
  608. v >>= 8;
  609. n += 8;
  610. }
  611. if (v & 0xf0) {
  612. v >>= 4;
  613. n += 4;
  614. }
  615. if (v & 0xc) {
  616. v >>= 2;
  617. n += 2;
  618. }
  619. if (v & 0x2) {
  620. n++;
  621. }
  622. return n;
  623. }
  624. /* memory */
  625. void *av_mallocz(int size);
  626. #endif