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.

294 lines
9.0KB

  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. /* the following fields are ignored */
  126. void *opaque; /* can be used to carry app specific stuff */
  127. char codec_name[32];
  128. int codec_type; /* see CODEC_TYPE_xxx */
  129. int codec_id; /* see CODEC_ID_xxx */
  130. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  131. } AVCodecContext;
  132. typedef struct AVCodec {
  133. char *name;
  134. int type;
  135. int id;
  136. int priv_data_size;
  137. int (*init)(AVCodecContext *);
  138. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  139. int (*close)(AVCodecContext *);
  140. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  141. UINT8 *buf, int buf_size);
  142. int capabilities;
  143. struct AVCodec *next;
  144. } AVCodec;
  145. /* three components are given, that's all */
  146. typedef struct AVPicture {
  147. UINT8 *data[3];
  148. int linesize[3];
  149. } AVPicture;
  150. extern AVCodec ac3_encoder;
  151. extern AVCodec mp2_encoder;
  152. extern AVCodec mp3lame_encoder;
  153. extern AVCodec mpeg1video_encoder;
  154. extern AVCodec h263_encoder;
  155. extern AVCodec h263p_encoder;
  156. extern AVCodec rv10_encoder;
  157. extern AVCodec mjpeg_encoder;
  158. extern AVCodec mpeg4_encoder;
  159. extern AVCodec msmpeg4_encoder;
  160. extern AVCodec h263_decoder;
  161. extern AVCodec mpeg4_decoder;
  162. extern AVCodec msmpeg4_decoder;
  163. extern AVCodec mpeg_decoder;
  164. extern AVCodec h263i_decoder;
  165. extern AVCodec rv10_decoder;
  166. extern AVCodec mjpeg_decoder;
  167. extern AVCodec mp3_decoder;
  168. /* pcm codecs */
  169. #define PCM_CODEC(id, name) \
  170. extern AVCodec name ## _decoder; \
  171. extern AVCodec name ## _encoder;
  172. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  173. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  174. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  175. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  176. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  177. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  178. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  179. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  180. #undef PCM_CODEC
  181. /* dummy raw video codec */
  182. extern AVCodec rawvideo_codec;
  183. /* the following codecs use external GPL libs */
  184. extern AVCodec ac3_decoder;
  185. /* resample.c */
  186. struct ReSampleContext;
  187. typedef struct ReSampleContext ReSampleContext;
  188. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  189. int output_rate, int input_rate);
  190. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  191. void audio_resample_close(ReSampleContext *s);
  192. /* YUV420 format is assumed ! */
  193. struct ImgReSampleContext;
  194. typedef struct ImgReSampleContext ImgReSampleContext;
  195. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  196. int input_width, int input_height);
  197. void img_resample(ImgReSampleContext *s,
  198. AVPicture *output, AVPicture *input);
  199. void img_resample_close(ImgReSampleContext *s);
  200. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  201. int pix_fmt, int width, int height);
  202. int avpicture_get_size(int pix_fmt, int width, int height);
  203. /* convert among pixel formats */
  204. int img_convert(AVPicture *dst, int dst_pix_fmt,
  205. AVPicture *src, int pix_fmt,
  206. int width, int height);
  207. /* deinterlace a picture */
  208. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  209. int pix_fmt, int width, int height);
  210. /* external high level API */
  211. extern AVCodec *first_avcodec;
  212. void avcodec_init(void);
  213. void register_avcodec(AVCodec *format);
  214. AVCodec *avcodec_find_encoder(enum CodecID id);
  215. AVCodec *avcodec_find_encoder_by_name(const char *name);
  216. AVCodec *avcodec_find_decoder(enum CodecID id);
  217. AVCodec *avcodec_find_decoder_by_name(const char *name);
  218. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  219. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  220. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  221. int *frame_size_ptr,
  222. UINT8 *buf, int buf_size);
  223. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  224. int *got_picture_ptr,
  225. UINT8 *buf, int buf_size);
  226. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  227. const short *samples);
  228. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  229. const AVPicture *pict);
  230. int avcodec_close(AVCodecContext *avctx);
  231. void avcodec_register_all(void);
  232. #ifdef FF_POSTPROCESS
  233. #ifndef MBC
  234. #define MBC 48
  235. #define MBR 36
  236. #endif
  237. extern int quant_store[MBR+1][MBC+1]; // [Review]
  238. #endif
  239. #endif /* AVCODEC_H */