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.

331 lines
10KB

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