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.

310 lines
9.5KB

  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. struct AVCodec *codec;
  107. void *priv_data;
  108. /* The following data is for RTP friendly coding */
  109. /* By now only H.263/H.263+ coder honours this */
  110. int rtp_mode; /* 1 for activate RTP friendly-mode */
  111. /* highers numbers represent more error-prone */
  112. /* enviroments, by now just "1" exist */
  113. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  114. /* do it's best to deliver a chunk with size */
  115. /* below rtp_payload_size, the chunk will start */
  116. /* with a start code on some codecs like H.263 */
  117. /* This doesn't take account of any particular */
  118. /* headers inside the transmited RTP payload */
  119. /* The RTP callcack: This function is called */
  120. /* every time the encoder as a packet to send */
  121. /* Depends on the encoder if the data starts */
  122. /* with a Start Code (it should) H.263 does */
  123. void (*rtp_callback)(void *data, int size, int packet_number);
  124. /* These are for PSNR calculation, if you set get_psnr to 1 */
  125. /* after encoding you will have the PSNR on psnr_y/cb/cr */
  126. int get_psnr;
  127. float psnr_y;
  128. float psnr_cb;
  129. float psnr_cr;
  130. /* statistics, used for 2-pass encoding */
  131. int mv_bits;
  132. int header_bits;
  133. int i_tex_bits;
  134. int p_tex_bits;
  135. int i_count;
  136. int p_count;
  137. int skip_count;
  138. int misc_bits; // cbp, mb_type
  139. int frame_bits;
  140. /* the following fields are ignored */
  141. void *opaque; /* can be used to carry app specific stuff */
  142. char codec_name[32];
  143. int codec_type; /* see CODEC_TYPE_xxx */
  144. int codec_id; /* see CODEC_ID_xxx */
  145. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  146. } AVCodecContext;
  147. typedef struct AVCodec {
  148. char *name;
  149. int type;
  150. int id;
  151. int priv_data_size;
  152. int (*init)(AVCodecContext *);
  153. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  154. int (*close)(AVCodecContext *);
  155. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  156. UINT8 *buf, int buf_size);
  157. int capabilities;
  158. struct AVCodec *next;
  159. } AVCodec;
  160. /* three components are given, that's all */
  161. typedef struct AVPicture {
  162. UINT8 *data[3];
  163. int linesize[3];
  164. } AVPicture;
  165. extern AVCodec ac3_encoder;
  166. extern AVCodec mp2_encoder;
  167. extern AVCodec mp3lame_encoder;
  168. extern AVCodec mpeg1video_encoder;
  169. extern AVCodec h263_encoder;
  170. extern AVCodec h263p_encoder;
  171. extern AVCodec rv10_encoder;
  172. extern AVCodec mjpeg_encoder;
  173. extern AVCodec mpeg4_encoder;
  174. extern AVCodec msmpeg4_encoder;
  175. extern AVCodec h263_decoder;
  176. extern AVCodec mpeg4_decoder;
  177. extern AVCodec msmpeg4_decoder;
  178. extern AVCodec mpeg_decoder;
  179. extern AVCodec h263i_decoder;
  180. extern AVCodec rv10_decoder;
  181. extern AVCodec mjpeg_decoder;
  182. extern AVCodec mp3_decoder;
  183. /* pcm codecs */
  184. #define PCM_CODEC(id, name) \
  185. extern AVCodec name ## _decoder; \
  186. extern AVCodec name ## _encoder;
  187. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  188. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  189. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  190. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  191. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  192. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  193. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  194. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  195. #undef PCM_CODEC
  196. /* dummy raw video codec */
  197. extern AVCodec rawvideo_codec;
  198. /* the following codecs use external GPL libs */
  199. extern AVCodec ac3_decoder;
  200. /* resample.c */
  201. struct ReSampleContext;
  202. typedef struct ReSampleContext ReSampleContext;
  203. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  204. int output_rate, int input_rate);
  205. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  206. void audio_resample_close(ReSampleContext *s);
  207. /* YUV420 format is assumed ! */
  208. struct ImgReSampleContext;
  209. typedef struct ImgReSampleContext ImgReSampleContext;
  210. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  211. int input_width, int input_height);
  212. void img_resample(ImgReSampleContext *s,
  213. AVPicture *output, AVPicture *input);
  214. void img_resample_close(ImgReSampleContext *s);
  215. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  216. int pix_fmt, int width, int height);
  217. int avpicture_get_size(int pix_fmt, int width, int height);
  218. /* convert among pixel formats */
  219. int img_convert(AVPicture *dst, int dst_pix_fmt,
  220. AVPicture *src, int pix_fmt,
  221. int width, int height);
  222. /* deinterlace a picture */
  223. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  224. int pix_fmt, int width, int height);
  225. /* external high level API */
  226. extern AVCodec *first_avcodec;
  227. void avcodec_init(void);
  228. void register_avcodec(AVCodec *format);
  229. AVCodec *avcodec_find_encoder(enum CodecID id);
  230. AVCodec *avcodec_find_encoder_by_name(const char *name);
  231. AVCodec *avcodec_find_decoder(enum CodecID id);
  232. AVCodec *avcodec_find_decoder_by_name(const char *name);
  233. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  234. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  235. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  236. int *frame_size_ptr,
  237. UINT8 *buf, int buf_size);
  238. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  239. int *got_picture_ptr,
  240. UINT8 *buf, int buf_size);
  241. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  242. const short *samples);
  243. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  244. const AVPicture *pict);
  245. int avcodec_close(AVCodecContext *avctx);
  246. void avcodec_register_all(void);
  247. #ifdef FF_POSTPROCESS
  248. #ifndef MBC
  249. #define MBC 48
  250. #define MBR 36
  251. #endif
  252. extern int quant_store[MBR+1][MBC+1]; // [Review]
  253. #endif
  254. #endif /* AVCODEC_H */