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.

320 lines
9.9KB

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