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.

349 lines
11KB

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