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.

332 lines
6.7KB

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