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.

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