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.

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