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.

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