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.

364 lines
7.3KB

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