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.

331 lines
6.6KB

  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #define FFMPEG_VERSION "0.4.5"
  4. #ifdef WIN32
  5. #define CONFIG_WIN32
  6. #endif
  7. #ifdef HAVE_AV_CONFIG_H
  8. /* only include the following when compiling package */
  9. #include "../config.h"
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <errno.h>
  14. #ifndef ENODATA
  15. #define ENODATA 61
  16. #endif
  17. #endif
  18. #ifdef CONFIG_WIN32
  19. /* windows */
  20. typedef unsigned short UINT16;
  21. typedef signed short INT16;
  22. typedef unsigned char UINT8;
  23. typedef unsigned int UINT32;
  24. typedef unsigned __int64 UINT64;
  25. typedef signed char INT8;
  26. typedef signed int INT32;
  27. typedef signed __int64 INT64;
  28. typedef UINT8 uint8_t;
  29. typedef INT8 int8_t;
  30. typedef UINT16 uint16_t;
  31. typedef INT16 int16_t;
  32. typedef UINT32 uint32_t;
  33. typedef INT32 int32_t;
  34. #define INT64_C(c) (c ## i64)
  35. #define UINT64_C(c) (c ## i64)
  36. #define inline __inline
  37. /*
  38. Disable warning messages:
  39. warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
  40. warning C4305: 'argument' : truncation from 'const double' to 'float'
  41. */
  42. #pragma warning( disable : 4244 )
  43. #pragma warning( disable : 4305 )
  44. #define M_PI 3.14159265358979323846
  45. #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  46. #ifdef _DEBUG
  47. #define DEBUG
  48. #endif
  49. // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
  50. #define bswap_32(x) \
  51. ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
  52. (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
  53. #define be2me_32(x) bswap_32(x)
  54. #define snprintf _snprintf
  55. #define CONFIG_ENCODERS 1
  56. #define CONFIG_DECODERS 1
  57. #define CONFIG_AC3 1
  58. #define CONFIG_MPGLIB 1
  59. #else
  60. /* unix */
  61. #include <inttypes.h>
  62. #ifndef __WINE_WINDEF16_H
  63. /* workaround for typedef conflict in MPlayer (wine typedefs) */
  64. typedef unsigned short UINT16;
  65. typedef signed short INT16;
  66. #endif
  67. typedef unsigned char UINT8;
  68. typedef unsigned int UINT32;
  69. typedef unsigned long long UINT64;
  70. typedef signed char INT8;
  71. typedef signed int INT32;
  72. typedef signed long long INT64;
  73. #ifdef HAVE_AV_CONFIG_H
  74. #ifdef __FreeBSD__
  75. #include <sys/param.h>
  76. #endif
  77. #ifndef INT64_C
  78. #define INT64_C(c) (c ## LL)
  79. #define UINT64_C(c) (c ## ULL)
  80. #endif
  81. #include "../bswap.h"
  82. #ifdef USE_FASTMEMCPY
  83. #include "fastmemcpy.h"
  84. #endif
  85. #ifndef DEBUG
  86. #define NDEBUG
  87. #endif
  88. #include <assert.h>
  89. #endif /* HAVE_AV_CONFIG_H */
  90. #endif /* !CONFIG_WIN32 */
  91. /* bit output */
  92. struct PutBitContext;
  93. typedef void (*WriteDataFunc)(void *, UINT8 *, int);
  94. typedef struct PutBitContext {
  95. UINT32 bit_buf;
  96. int bit_cnt;
  97. UINT8 *buf, *buf_ptr, *buf_end;
  98. INT64 data_out_size; /* in bytes */
  99. void *opaque;
  100. WriteDataFunc write_data;
  101. } PutBitContext;
  102. void init_put_bits(PutBitContext *s,
  103. UINT8 *buffer, int buffer_size,
  104. void *opaque,
  105. void (*write_data)(void *, UINT8 *, int));
  106. void put_bits(PutBitContext *s, int n, unsigned int value);
  107. INT64 get_bit_count(PutBitContext *s);
  108. void align_put_bits(PutBitContext *s);
  109. void flush_put_bits(PutBitContext *s);
  110. /* jpeg specific put_bits */
  111. void jput_bits(PutBitContext *s, int n, unsigned int value);
  112. void jflush_put_bits(PutBitContext *s);
  113. /* bit input */
  114. typedef struct GetBitContext {
  115. UINT32 bit_buf;
  116. int bit_cnt;
  117. UINT8 *buf, *buf_ptr, *buf_end;
  118. } GetBitContext;
  119. typedef struct VLC {
  120. int bits;
  121. INT16 *table_codes;
  122. INT8 *table_bits;
  123. int table_size, table_allocated;
  124. } VLC;
  125. void init_get_bits(GetBitContext *s,
  126. UINT8 *buffer, int buffer_size);
  127. unsigned int get_bits_long(GetBitContext *s, int n);
  128. static inline unsigned int get_bits(GetBitContext *s, int n){
  129. if(s->bit_cnt>=n){
  130. /* most common case here */
  131. unsigned int val = s->bit_buf >> (32 - n);
  132. s->bit_buf <<= n;
  133. s->bit_cnt -= n;
  134. #ifdef STATS
  135. st_bit_counts[st_current_index] += n;
  136. #endif
  137. return val;
  138. }
  139. return get_bits_long(s,n);
  140. }
  141. static inline unsigned int get_bits1(GetBitContext *s){
  142. if(s->bit_cnt>0){
  143. /* most common case here */
  144. unsigned int val = s->bit_buf >> 31;
  145. s->bit_buf <<= 1;
  146. s->bit_cnt--;
  147. #ifdef STATS
  148. st_bit_counts[st_current_index]++;
  149. #endif
  150. return val;
  151. }
  152. return get_bits_long(s,1);
  153. }
  154. static inline void skip_bits(GetBitContext *s, int n){
  155. if(s->bit_cnt>=n){
  156. /* most common case here */
  157. s->bit_buf <<= n;
  158. s->bit_cnt -= n;
  159. #ifdef STATS
  160. st_bit_counts[st_current_index] += n;
  161. #endif
  162. } else {
  163. get_bits_long(s,n);
  164. }
  165. }
  166. static inline void skip_bits1(GetBitContext *s){
  167. if(s->bit_cnt>0){
  168. /* most common case here */
  169. s->bit_buf <<= 1;
  170. s->bit_cnt--;
  171. #ifdef STATS
  172. st_bit_counts[st_current_index]++;
  173. #endif
  174. } else {
  175. get_bits_long(s,1);
  176. }
  177. }
  178. void align_get_bits(GetBitContext *s);
  179. int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
  180. const void *bits, int bits_wrap, int bits_size,
  181. const void *codes, int codes_wrap, int codes_size);
  182. void free_vlc(VLC *vlc);
  183. int get_vlc(GetBitContext *s, VLC *vlc);
  184. /* macro to go faster */
  185. /* n must be <= 24 */
  186. /* XXX: optimize buffer end test */
  187. #define SHOW_BITS(s, val, n)\
  188. {\
  189. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  190. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  191. bit_cnt += 8;\
  192. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  193. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  194. bit_cnt += 8;\
  195. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  196. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  197. bit_cnt += 8;\
  198. }\
  199. }\
  200. }\
  201. val = bit_buf >> (32 - n);\
  202. }
  203. /* SHOW_BITS with n1 >= n must be been done before */
  204. #define FLUSH_BITS(n)\
  205. {\
  206. bit_buf <<= n;\
  207. bit_cnt -= n;\
  208. }
  209. #define SAVE_BITS(s) \
  210. {\
  211. bit_cnt = (s)->bit_cnt;\
  212. bit_buf = (s)->bit_buf;\
  213. buf_ptr = (s)->buf_ptr;\
  214. }
  215. #define RESTORE_BITS(s) \
  216. {\
  217. (s)->buf_ptr = buf_ptr;\
  218. (s)->bit_buf = bit_buf;\
  219. (s)->bit_cnt = bit_cnt;\
  220. }
  221. /* define it to include statistics code (useful only for optimizing
  222. codec efficiency */
  223. //#define STATS
  224. #ifdef STATS
  225. enum {
  226. ST_UNKNOWN,
  227. ST_DC,
  228. ST_INTRA_AC,
  229. ST_INTER_AC,
  230. ST_INTRA_MB,
  231. ST_INTER_MB,
  232. ST_MV,
  233. ST_NB,
  234. };
  235. extern int st_current_index;
  236. extern unsigned int st_bit_counts[ST_NB];
  237. extern unsigned int st_out_bit_counts[ST_NB];
  238. void print_stats(void);
  239. #endif
  240. /* misc math functions */
  241. extern inline int log2(unsigned int v)
  242. {
  243. int n;
  244. n = 0;
  245. if (v & 0xffff0000) {
  246. v >>= 16;
  247. n += 16;
  248. }
  249. if (v & 0xff00) {
  250. v >>= 8;
  251. n += 8;
  252. }
  253. if (v & 0xf0) {
  254. v >>= 4;
  255. n += 4;
  256. }
  257. if (v & 0xc) {
  258. v >>= 2;
  259. n += 2;
  260. }
  261. if (v & 0x2) {
  262. n++;
  263. }
  264. return n;
  265. }
  266. /* memory */
  267. void *av_mallocz(int size);
  268. #endif