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.

361 lines
7.2KB

  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #define FFMPEG_VERSION_INT 0x000405
  4. #define FFMPEG_VERSION "0.4.5"
  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. #define CONFIG_MPGLIB 1
  67. #endif
  68. #else
  69. /* unix */
  70. #include <inttypes.h>
  71. #ifndef __WINE_WINDEF16_H
  72. /* workaround for typedef conflict in MPlayer (wine typedefs) */
  73. typedef unsigned short UINT16;
  74. typedef signed short INT16;
  75. #endif
  76. typedef unsigned char UINT8;
  77. typedef unsigned int UINT32;
  78. typedef unsigned long long UINT64;
  79. typedef signed char INT8;
  80. typedef signed int INT32;
  81. typedef signed long long INT64;
  82. #ifdef HAVE_AV_CONFIG_H
  83. #ifdef __FreeBSD__
  84. #include <sys/param.h>
  85. #endif
  86. #ifndef INT64_C
  87. #define INT64_C(c) (c ## LL)
  88. #define UINT64_C(c) (c ## ULL)
  89. #endif
  90. #include "../bswap.h"
  91. #ifdef USE_FASTMEMCPY
  92. #include "fastmemcpy.h"
  93. #endif
  94. #endif /* HAVE_AV_CONFIG_H */
  95. #endif /* !CONFIG_WIN32 */
  96. /* debug stuff */
  97. #ifdef HAVE_AV_CONFIG_H
  98. #ifndef DEBUG
  99. #define NDEBUG
  100. #endif
  101. #include <assert.h>
  102. /* dprintf macros */
  103. #if defined(CONFIG_WIN32) && !defined(__MINGW32__)
  104. inline void dprintf(const char* fmt,...) {}
  105. #else
  106. #ifdef DEBUG
  107. #define dprintf(fmt,args...) printf(fmt, ## args)
  108. #else
  109. #define dprintf(fmt,args...)
  110. #endif
  111. #endif /* !CONFIG_WIN32 */
  112. #endif /* HAVE_AV_CONFIG_H */
  113. /* bit output */
  114. struct PutBitContext;
  115. typedef void (*WriteDataFunc)(void *, UINT8 *, int);
  116. typedef struct PutBitContext {
  117. UINT32 bit_buf;
  118. int bit_cnt;
  119. UINT8 *buf, *buf_ptr, *buf_end;
  120. INT64 data_out_size; /* in bytes */
  121. void *opaque;
  122. WriteDataFunc write_data;
  123. } PutBitContext;
  124. void init_put_bits(PutBitContext *s,
  125. UINT8 *buffer, int buffer_size,
  126. void *opaque,
  127. void (*write_data)(void *, UINT8 *, int));
  128. void put_bits(PutBitContext *s, int n, unsigned int value);
  129. INT64 get_bit_count(PutBitContext *s);
  130. void align_put_bits(PutBitContext *s);
  131. void flush_put_bits(PutBitContext *s);
  132. /* jpeg specific put_bits */
  133. void jput_bits(PutBitContext *s, int n, unsigned int value);
  134. void jflush_put_bits(PutBitContext *s);
  135. /* bit input */
  136. typedef struct GetBitContext {
  137. UINT32 bit_buf;
  138. int bit_cnt;
  139. UINT8 *buf, *buf_ptr, *buf_end;
  140. } GetBitContext;
  141. typedef struct VLC {
  142. int bits;
  143. INT16 *table_codes;
  144. INT8 *table_bits;
  145. int table_size, table_allocated;
  146. } VLC;
  147. void init_get_bits(GetBitContext *s,
  148. UINT8 *buffer, int buffer_size);
  149. unsigned int get_bits_long(GetBitContext *s, int n);
  150. static inline unsigned int get_bits(GetBitContext *s, int n){
  151. if(s->bit_cnt>=n){
  152. /* most common case here */
  153. unsigned int val = s->bit_buf >> (32 - n);
  154. s->bit_buf <<= n;
  155. s->bit_cnt -= n;
  156. #ifdef STATS
  157. st_bit_counts[st_current_index] += n;
  158. #endif
  159. return val;
  160. }
  161. return get_bits_long(s,n);
  162. }
  163. static inline unsigned int get_bits1(GetBitContext *s){
  164. if(s->bit_cnt>0){
  165. /* most common case here */
  166. unsigned int val = s->bit_buf >> 31;
  167. s->bit_buf <<= 1;
  168. s->bit_cnt--;
  169. #ifdef STATS
  170. st_bit_counts[st_current_index]++;
  171. #endif
  172. return val;
  173. }
  174. return get_bits_long(s,1);
  175. }
  176. static inline void skip_bits(GetBitContext *s, int n){
  177. if(s->bit_cnt>=n){
  178. /* most common case here */
  179. s->bit_buf <<= n;
  180. s->bit_cnt -= n;
  181. #ifdef STATS
  182. st_bit_counts[st_current_index] += n;
  183. #endif
  184. } else {
  185. get_bits_long(s,n);
  186. }
  187. }
  188. static inline void skip_bits1(GetBitContext *s){
  189. if(s->bit_cnt>0){
  190. /* most common case here */
  191. s->bit_buf <<= 1;
  192. s->bit_cnt--;
  193. #ifdef STATS
  194. st_bit_counts[st_current_index]++;
  195. #endif
  196. } else {
  197. get_bits_long(s,1);
  198. }
  199. }
  200. void align_get_bits(GetBitContext *s);
  201. int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
  202. const void *bits, int bits_wrap, int bits_size,
  203. const void *codes, int codes_wrap, int codes_size);
  204. void free_vlc(VLC *vlc);
  205. int get_vlc(GetBitContext *s, VLC *vlc);
  206. /* macro to go faster */
  207. /* n must be <= 24 */
  208. /* XXX: optimize buffer end test */
  209. #define SHOW_BITS(s, val, n)\
  210. {\
  211. if (bit_cnt < n && buf_ptr < (s)->buf_end) {\
  212. bit_buf |= *buf_ptr++ << (24 - bit_cnt);\
  213. bit_cnt += 8;\
  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. }\
  221. }\
  222. }\
  223. val = bit_buf >> (32 - n);\
  224. }
  225. /* SHOW_BITS with n1 >= n must be been done before */
  226. #define FLUSH_BITS(n)\
  227. {\
  228. bit_buf <<= n;\
  229. bit_cnt -= n;\
  230. }
  231. #define SAVE_BITS(s) \
  232. {\
  233. bit_cnt = (s)->bit_cnt;\
  234. bit_buf = (s)->bit_buf;\
  235. buf_ptr = (s)->buf_ptr;\
  236. }
  237. #define RESTORE_BITS(s) \
  238. {\
  239. (s)->buf_ptr = buf_ptr;\
  240. (s)->bit_buf = bit_buf;\
  241. (s)->bit_cnt = bit_cnt;\
  242. }
  243. /* define it to include statistics code (useful only for optimizing
  244. codec efficiency */
  245. //#define STATS
  246. #ifdef STATS
  247. enum {
  248. ST_UNKNOWN,
  249. ST_DC,
  250. ST_INTRA_AC,
  251. ST_INTER_AC,
  252. ST_INTRA_MB,
  253. ST_INTER_MB,
  254. ST_MV,
  255. ST_NB,
  256. };
  257. extern int st_current_index;
  258. extern unsigned int st_bit_counts[ST_NB];
  259. extern unsigned int st_out_bit_counts[ST_NB];
  260. void print_stats(void);
  261. #endif
  262. /* misc math functions */
  263. extern inline int av_log2(unsigned int v)
  264. {
  265. int n;
  266. n = 0;
  267. if (v & 0xffff0000) {
  268. v >>= 16;
  269. n += 16;
  270. }
  271. if (v & 0xff00) {
  272. v >>= 8;
  273. n += 8;
  274. }
  275. if (v & 0xf0) {
  276. v >>= 4;
  277. n += 4;
  278. }
  279. if (v & 0xc) {
  280. v >>= 2;
  281. n += 2;
  282. }
  283. if (v & 0x2) {
  284. n++;
  285. }
  286. return n;
  287. }
  288. /* memory */
  289. void *av_mallocz(int size);
  290. #endif