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.

381 lines
12KB

  1. #ifndef AVCODEC_H
  2. #define AVCODEC_H
  3. #include "common.h"
  4. #define LIBAVCODEC_VERSION_INT 0x000406
  5. #define LIBAVCODEC_VERSION "0.4.6"
  6. #define LIBAVCODEC_BUILD 4606
  7. #define LIBAVCODEC_BUILD_STR "4606"
  8. enum CodecID {
  9. CODEC_ID_NONE,
  10. CODEC_ID_MPEG1VIDEO,
  11. CODEC_ID_H263,
  12. CODEC_ID_RV10,
  13. CODEC_ID_MP2,
  14. CODEC_ID_MP3LAME,
  15. CODEC_ID_AC3,
  16. CODEC_ID_MJPEG,
  17. CODEC_ID_MPEG4,
  18. CODEC_ID_RAWVIDEO,
  19. CODEC_ID_MSMPEG4V1,
  20. CODEC_ID_MSMPEG4V2,
  21. CODEC_ID_MSMPEG4V3,
  22. CODEC_ID_WMV1,
  23. CODEC_ID_H263P,
  24. CODEC_ID_H263I,
  25. /* various pcm "codecs" */
  26. CODEC_ID_PCM_S16LE,
  27. CODEC_ID_PCM_S16BE,
  28. CODEC_ID_PCM_U16LE,
  29. CODEC_ID_PCM_U16BE,
  30. CODEC_ID_PCM_S8,
  31. CODEC_ID_PCM_U8,
  32. CODEC_ID_PCM_MULAW,
  33. CODEC_ID_PCM_ALAW,
  34. };
  35. #define CODEC_ID_MSMPEG4 CODEC_ID_MSMPEG4V3
  36. enum CodecType {
  37. CODEC_TYPE_UNKNOWN = -1,
  38. CODEC_TYPE_VIDEO,
  39. CODEC_TYPE_AUDIO,
  40. };
  41. enum PixelFormat {
  42. PIX_FMT_ANY = -1,
  43. PIX_FMT_YUV420P,
  44. PIX_FMT_YUV422,
  45. PIX_FMT_RGB24,
  46. PIX_FMT_BGR24,
  47. PIX_FMT_YUV422P,
  48. PIX_FMT_YUV444P,
  49. };
  50. /* currently unused, may be used if 24/32 bits samples ever supported */
  51. enum SampleFormat {
  52. SAMPLE_FMT_S16 = 0, /* signed 16 bits */
  53. };
  54. /* in bytes */
  55. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 18432
  56. /* motion estimation type, EPZS by default */
  57. enum Motion_Est_ID {
  58. ME_ZERO = 1,
  59. ME_FULL,
  60. ME_LOG,
  61. ME_PHODS,
  62. ME_EPZS,
  63. ME_X1
  64. };
  65. /* only for ME compatiblity with old apps */
  66. extern int motion_estimation_method;
  67. /* ME algos sorted by quality */
  68. static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
  69. ME_X1, ME_EPZS, ME_FULL };
  70. #define FF_MAX_B_FRAMES 4
  71. /* encoding support */
  72. /* note not everything is supported yet */
  73. #define CODEC_FLAG_HQ 0x0001 /* high quality (non real time) encoding */
  74. #define CODEC_FLAG_QSCALE 0x0002 /* use fixed qscale */
  75. #define CODEC_FLAG_4MV 0x0004 /* 4 MV per MB allowed */
  76. #define CODEC_FLAG_QPEL 0x0010 /* use qpel MC */
  77. #define CODEC_FLAG_GMC 0x0020 /* use GMC */
  78. #define CODEC_FLAG_TYPE 0x0040 /* fixed I/P frame type, from avctx->key_frame */
  79. /* parent program gurantees that the input for b-frame containing streams is not written to
  80. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  81. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  82. #define CODEC_FLAG_PASS1 0x0200 /* use internal 2pass ratecontrol in first pass mode */
  83. #define CODEC_FLAG_PASS2 0x0400 /* use internal 2pass ratecontrol in second pass mode */
  84. #define CODEC_FLAG_EXTERN_HUFF 0x1000 /* use external huffman table (for mjpeg) */
  85. /* codec capabilities */
  86. /* decoder can use draw_horiz_band callback */
  87. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001
  88. #define FRAME_RATE_BASE 10000
  89. typedef struct AVCodecContext {
  90. int bit_rate;
  91. int bit_rate_tolerance; /* amount of +- bits (>0)*/
  92. int flags;
  93. int sub_id; /* some codecs needs additionnal format info. It is
  94. stored there */
  95. int me_method; /* ME algorithm used for video coding */
  96. /* extra data from parent application to codec, e.g. huffman table
  97. for mjpeg */
  98. /* the parent should allocate and free this buffer */
  99. void *extradata;
  100. int extradata_size;
  101. /* video only */
  102. int frame_rate; /* frames per sec multiplied by FRAME_RATE_BASE */
  103. int width, height;
  104. int aspect_ratio_info;
  105. #define FF_ASPECT_SQUARE 1
  106. #define FF_ASPECT_4_3_625 2
  107. #define FF_ASPECT_4_3_525 3
  108. #define FF_ASPECT_16_9_625 4
  109. #define FF_ASPECT_16_9_525 5
  110. int gop_size; /* 0 = intra only */
  111. enum PixelFormat pix_fmt; /* pixel format, see PIX_FMT_xxx */
  112. /* if non NULL, 'draw_horiz_band' is called by the libavcodec
  113. decoder to draw an horizontal band. It improve cache usage. Not
  114. all codecs can do that. You must check the codec capabilities
  115. before */
  116. void (*draw_horiz_band)(struct AVCodecContext *s,
  117. UINT8 **src_ptr, int linesize,
  118. int y, int width, int height);
  119. /* audio only */
  120. int sample_rate; /* samples per sec */
  121. int channels;
  122. int sample_fmt; /* sample format, currenly unused */
  123. /* the following data should not be initialized */
  124. int frame_size; /* in samples, initialized when calling 'init' */
  125. int frame_number; /* audio or video frame number */
  126. int real_pict_num; /* returns the real picture number of
  127. previous encoded frame */
  128. int key_frame; /* true if the previous compressed frame was
  129. a key frame (intra, or seekable) */
  130. int pict_type; /* picture type of the previous
  131. encoded frame */
  132. /* FIXME: these should have FF_ */
  133. #define I_TYPE 1 // Intra
  134. #define P_TYPE 2 // Predicted
  135. #define B_TYPE 3 // Bi-dir predicted
  136. #define S_TYPE 4 // S(GMC)-VOP MPEG4
  137. int delay; /* number of frames the decoded output
  138. will be delayed relative to the encoded input */
  139. uint8_t *mbskip_table; /* =1 if MB didnt change, is only valid for I/P frames
  140. stride= mb_width = (width+15)>>4 */
  141. /* encoding parameters */
  142. int quality; /* quality of the previous encoded frame
  143. (between 1 (good) and 31 (bad))
  144. this is allso used to set the quality in vbr mode
  145. and the per frame quality in CODEC_FLAG_TYPE (second pass mode) */
  146. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  147. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  148. int qmin; /* min qscale */
  149. int qmax; /* max qscale */
  150. int max_qdiff; /* max qscale difference between frames */
  151. int max_b_frames; /* maximum b frames, the output will be delayed by max_b_frames+1 relative to the input */
  152. float b_quant_factor;/* qscale factor between ips and b frames */
  153. int rc_strategy;
  154. int b_frame_strategy;
  155. int hurry_up; /* when set to 1 during decoding, b frames will be skiped
  156. when set to 2 idct/dequant will be skipped too */
  157. struct AVCodec *codec;
  158. void *priv_data;
  159. /* The following data is for RTP friendly coding */
  160. /* By now only H.263/H.263+ coder honours this */
  161. int rtp_mode; /* 1 for activate RTP friendly-mode */
  162. /* highers numbers represent more error-prone */
  163. /* enviroments, by now just "1" exist */
  164. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  165. /* do it's best to deliver a chunk with size */
  166. /* below rtp_payload_size, the chunk will start */
  167. /* with a start code on some codecs like H.263 */
  168. /* This doesn't take account of any particular */
  169. /* headers inside the transmited RTP payload */
  170. /* The RTP callcack: This function is called */
  171. /* every time the encoder as a packet to send */
  172. /* Depends on the encoder if the data starts */
  173. /* with a Start Code (it should) H.263 does */
  174. void (*rtp_callback)(void *data, int size, int packet_number);
  175. /* These are for PSNR calculation, if you set get_psnr to 1 */
  176. /* after encoding you will have the PSNR on psnr_y/cb/cr */
  177. int get_psnr;
  178. float psnr_y;
  179. float psnr_cb;
  180. float psnr_cr;
  181. /* statistics, used for 2-pass encoding */
  182. int mv_bits;
  183. int header_bits;
  184. int i_tex_bits;
  185. int p_tex_bits;
  186. int i_count;
  187. int p_count;
  188. int skip_count;
  189. int misc_bits; // cbp, mb_type
  190. int frame_bits;
  191. /* the following fields are ignored */
  192. void *opaque; /* can be used to carry app specific stuff */
  193. char codec_name[32];
  194. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  195. enum CodecID codec_id; /* see CODEC_ID_xxx */
  196. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  197. } AVCodecContext;
  198. typedef struct AVCodec {
  199. char *name;
  200. int type;
  201. int id;
  202. int priv_data_size;
  203. int (*init)(AVCodecContext *);
  204. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  205. int (*close)(AVCodecContext *);
  206. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  207. UINT8 *buf, int buf_size);
  208. int capabilities;
  209. struct AVCodec *next;
  210. } AVCodec;
  211. /* three components are given, that's all */
  212. typedef struct AVPicture {
  213. UINT8 *data[3];
  214. int linesize[3];
  215. } AVPicture;
  216. extern AVCodec ac3_encoder;
  217. extern AVCodec mp2_encoder;
  218. extern AVCodec mp3lame_encoder;
  219. extern AVCodec mpeg1video_encoder;
  220. extern AVCodec h263_encoder;
  221. extern AVCodec h263p_encoder;
  222. extern AVCodec rv10_encoder;
  223. extern AVCodec mjpeg_encoder;
  224. extern AVCodec mpeg4_encoder;
  225. extern AVCodec msmpeg4v1_encoder;
  226. extern AVCodec msmpeg4v2_encoder;
  227. extern AVCodec msmpeg4v3_encoder;
  228. extern AVCodec h263_decoder;
  229. extern AVCodec mpeg4_decoder;
  230. extern AVCodec msmpeg4v1_decoder;
  231. extern AVCodec msmpeg4v2_decoder;
  232. extern AVCodec msmpeg4v3_decoder;
  233. extern AVCodec wmv1_decoder;
  234. extern AVCodec mpeg_decoder;
  235. extern AVCodec h263i_decoder;
  236. extern AVCodec rv10_decoder;
  237. extern AVCodec mjpeg_decoder;
  238. extern AVCodec mp2_decoder;
  239. extern AVCodec mp3_decoder;
  240. /* pcm codecs */
  241. #define PCM_CODEC(id, name) \
  242. extern AVCodec name ## _decoder; \
  243. extern AVCodec name ## _encoder;
  244. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  245. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  246. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  247. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  248. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  249. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  250. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  251. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  252. #undef PCM_CODEC
  253. /* dummy raw video codec */
  254. extern AVCodec rawvideo_codec;
  255. /* the following codecs use external GPL libs */
  256. extern AVCodec ac3_decoder;
  257. /* resample.c */
  258. struct ReSampleContext;
  259. typedef struct ReSampleContext ReSampleContext;
  260. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  261. int output_rate, int input_rate);
  262. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  263. void audio_resample_close(ReSampleContext *s);
  264. /* YUV420 format is assumed ! */
  265. struct ImgReSampleContext;
  266. typedef struct ImgReSampleContext ImgReSampleContext;
  267. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  268. int input_width, int input_height);
  269. void img_resample(ImgReSampleContext *s,
  270. AVPicture *output, AVPicture *input);
  271. void img_resample_close(ImgReSampleContext *s);
  272. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  273. int pix_fmt, int width, int height);
  274. int avpicture_get_size(int pix_fmt, int width, int height);
  275. /* convert among pixel formats */
  276. int img_convert(AVPicture *dst, int dst_pix_fmt,
  277. AVPicture *src, int pix_fmt,
  278. int width, int height);
  279. /* deinterlace a picture */
  280. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  281. int pix_fmt, int width, int height);
  282. /* external high level API */
  283. extern AVCodec *first_avcodec;
  284. /* returns LIBAVCODEC_VERSION_INT constant */
  285. unsigned avcodec_version( void );
  286. void avcodec_init(void);
  287. void register_avcodec(AVCodec *format);
  288. AVCodec *avcodec_find_encoder(enum CodecID id);
  289. AVCodec *avcodec_find_encoder_by_name(const char *name);
  290. AVCodec *avcodec_find_decoder(enum CodecID id);
  291. AVCodec *avcodec_find_decoder_by_name(const char *name);
  292. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  293. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  294. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  295. int *frame_size_ptr,
  296. UINT8 *buf, int buf_size);
  297. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  298. int *got_picture_ptr,
  299. UINT8 *buf, int buf_size);
  300. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  301. const short *samples);
  302. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  303. const AVPicture *pict);
  304. int avcodec_close(AVCodecContext *avctx);
  305. void avcodec_register_all(void);
  306. void avcodec_flush_buffers(AVCodecContext *avctx);
  307. #ifdef FF_POSTPROCESS
  308. #ifndef MBC
  309. #define MBC 128
  310. #define MBR 96
  311. #endif
  312. extern int quant_store[MBR+1][MBC+1]; // [Review]
  313. #endif
  314. #endif /* AVCODEC_H */