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.

305 lines
9.3KB

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