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.

318 lines
9.8KB

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