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.

354 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 4603
  7. #define LIBAVCODEC_BUILD_STR "4603"
  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 delay; /* number of frames the decoded output will be delayed relative to the encoded input */
  121. /* encoding parameters */
  122. int quality; /* quality of the previous encoded frame
  123. (between 1 (good) and 31 (bad))
  124. this is allso used to set the quality in vbr mode
  125. and the per frame quality in CODEC_FLAG_TYPE (second pass mode) */
  126. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  127. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  128. int qmin; /* min qscale */
  129. int qmax; /* max qscale */
  130. int max_qdiff; /* max qscale difference between frames */
  131. int max_b_frames; /* maximum b frames, the output will be delayed by max_b_frames+1 relative to the input */
  132. float b_quant_factor;/* qscale factor between ips and b frames */
  133. int rc_strategy;
  134. int b_frame_strategy;
  135. struct AVCodec *codec;
  136. void *priv_data;
  137. /* The following data is for RTP friendly coding */
  138. /* By now only H.263/H.263+ coder honours this */
  139. int rtp_mode; /* 1 for activate RTP friendly-mode */
  140. /* highers numbers represent more error-prone */
  141. /* enviroments, by now just "1" exist */
  142. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  143. /* do it's best to deliver a chunk with size */
  144. /* below rtp_payload_size, the chunk will start */
  145. /* with a start code on some codecs like H.263 */
  146. /* This doesn't take account of any particular */
  147. /* headers inside the transmited RTP payload */
  148. /* The RTP callcack: This function is called */
  149. /* every time the encoder as a packet to send */
  150. /* Depends on the encoder if the data starts */
  151. /* with a Start Code (it should) H.263 does */
  152. void (*rtp_callback)(void *data, int size, int packet_number);
  153. /* These are for PSNR calculation, if you set get_psnr to 1 */
  154. /* after encoding you will have the PSNR on psnr_y/cb/cr */
  155. int get_psnr;
  156. float psnr_y;
  157. float psnr_cb;
  158. float psnr_cr;
  159. /* statistics, used for 2-pass encoding */
  160. int mv_bits;
  161. int header_bits;
  162. int i_tex_bits;
  163. int p_tex_bits;
  164. int i_count;
  165. int p_count;
  166. int skip_count;
  167. int misc_bits; // cbp, mb_type
  168. int frame_bits;
  169. /* the following fields are ignored */
  170. void *opaque; /* can be used to carry app specific stuff */
  171. char codec_name[32];
  172. int codec_type; /* see CODEC_TYPE_xxx */
  173. int codec_id; /* see CODEC_ID_xxx */
  174. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  175. } AVCodecContext;
  176. typedef struct AVCodec {
  177. char *name;
  178. int type;
  179. int id;
  180. int priv_data_size;
  181. int (*init)(AVCodecContext *);
  182. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  183. int (*close)(AVCodecContext *);
  184. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  185. UINT8 *buf, int buf_size);
  186. int capabilities;
  187. struct AVCodec *next;
  188. } AVCodec;
  189. /* three components are given, that's all */
  190. typedef struct AVPicture {
  191. UINT8 *data[3];
  192. int linesize[3];
  193. } AVPicture;
  194. extern AVCodec ac3_encoder;
  195. extern AVCodec mp2_encoder;
  196. extern AVCodec mp3lame_encoder;
  197. extern AVCodec mpeg1video_encoder;
  198. extern AVCodec h263_encoder;
  199. extern AVCodec h263p_encoder;
  200. extern AVCodec rv10_encoder;
  201. extern AVCodec mjpeg_encoder;
  202. extern AVCodec mpeg4_encoder;
  203. extern AVCodec msmpeg4v1_encoder;
  204. extern AVCodec msmpeg4v2_encoder;
  205. extern AVCodec msmpeg4v3_encoder;
  206. extern AVCodec h263_decoder;
  207. extern AVCodec mpeg4_decoder;
  208. extern AVCodec msmpeg4v1_decoder;
  209. extern AVCodec msmpeg4v2_decoder;
  210. extern AVCodec msmpeg4v3_decoder;
  211. extern AVCodec wmv1_decoder;
  212. extern AVCodec mpeg_decoder;
  213. extern AVCodec h263i_decoder;
  214. extern AVCodec rv10_decoder;
  215. extern AVCodec mjpeg_decoder;
  216. extern AVCodec mp2_decoder;
  217. extern AVCodec mp3_decoder;
  218. /* pcm codecs */
  219. #define PCM_CODEC(id, name) \
  220. extern AVCodec name ## _decoder; \
  221. extern AVCodec name ## _encoder;
  222. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  223. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  224. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  225. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  226. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  227. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  228. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  229. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  230. #undef PCM_CODEC
  231. /* dummy raw video codec */
  232. extern AVCodec rawvideo_codec;
  233. /* the following codecs use external GPL libs */
  234. extern AVCodec ac3_decoder;
  235. /* resample.c */
  236. struct ReSampleContext;
  237. typedef struct ReSampleContext ReSampleContext;
  238. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  239. int output_rate, int input_rate);
  240. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  241. void audio_resample_close(ReSampleContext *s);
  242. /* YUV420 format is assumed ! */
  243. struct ImgReSampleContext;
  244. typedef struct ImgReSampleContext ImgReSampleContext;
  245. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  246. int input_width, int input_height);
  247. void img_resample(ImgReSampleContext *s,
  248. AVPicture *output, AVPicture *input);
  249. void img_resample_close(ImgReSampleContext *s);
  250. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  251. int pix_fmt, int width, int height);
  252. int avpicture_get_size(int pix_fmt, int width, int height);
  253. /* convert among pixel formats */
  254. int img_convert(AVPicture *dst, int dst_pix_fmt,
  255. AVPicture *src, int pix_fmt,
  256. int width, int height);
  257. /* deinterlace a picture */
  258. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  259. int pix_fmt, int width, int height);
  260. /* external high level API */
  261. extern AVCodec *first_avcodec;
  262. void avcodec_init(void);
  263. void register_avcodec(AVCodec *format);
  264. AVCodec *avcodec_find_encoder(enum CodecID id);
  265. AVCodec *avcodec_find_encoder_by_name(const char *name);
  266. AVCodec *avcodec_find_decoder(enum CodecID id);
  267. AVCodec *avcodec_find_decoder_by_name(const char *name);
  268. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  269. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  270. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  271. int *frame_size_ptr,
  272. UINT8 *buf, int buf_size);
  273. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  274. int *got_picture_ptr,
  275. UINT8 *buf, int buf_size);
  276. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  277. const short *samples);
  278. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  279. const AVPicture *pict);
  280. int avcodec_close(AVCodecContext *avctx);
  281. void avcodec_register_all(void);
  282. void avcodec_flush_buffers(AVCodecContext *avctx);
  283. #ifdef FF_POSTPROCESS
  284. #ifndef MBC
  285. #define MBC 128
  286. #define MBR 96
  287. #endif
  288. extern int quant_store[MBR+1][MBC+1]; // [Review]
  289. #endif
  290. #endif /* AVCODEC_H */