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.

312 lines
9.6KB

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