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.

241 lines
7.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_AC3,
  11. CODEC_ID_MJPEG,
  12. CODEC_ID_MPEG4,
  13. CODEC_ID_RAWVIDEO,
  14. CODEC_ID_MSMPEG4,
  15. CODEC_ID_H263P,
  16. CODEC_ID_H263I,
  17. /* various pcm "codecs" */
  18. CODEC_ID_PCM_S16LE,
  19. CODEC_ID_PCM_S16BE,
  20. CODEC_ID_PCM_U16LE,
  21. CODEC_ID_PCM_U16BE,
  22. CODEC_ID_PCM_S8,
  23. CODEC_ID_PCM_U8,
  24. CODEC_ID_PCM_MULAW,
  25. CODEC_ID_PCM_ALAW,
  26. };
  27. enum CodecType {
  28. CODEC_TYPE_VIDEO,
  29. CODEC_TYPE_AUDIO,
  30. };
  31. enum PixelFormat {
  32. PIX_FMT_YUV420P,
  33. PIX_FMT_YUV422,
  34. PIX_FMT_RGB24,
  35. PIX_FMT_BGR24,
  36. PIX_FMT_YUV422P,
  37. PIX_FMT_YUV444P,
  38. };
  39. /* currently unused, may be used if 24/32 bits samples ever supported */
  40. enum SampleFormat {
  41. SAMPLE_FMT_S16 = 0, /* signed 16 bits */
  42. };
  43. /* in bytes */
  44. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 18432
  45. /* motion estimation type */
  46. extern int motion_estimation_method;
  47. #define ME_ZERO 0
  48. #define ME_FULL 1
  49. #define ME_LOG 2
  50. #define ME_PHODS 3
  51. /* encoding support */
  52. #define CODEC_FLAG_HQ 0x0001 /* high quality (non real time) encoding */
  53. #define CODEC_FLAG_QSCALE 0x0002 /* use fixed qscale */
  54. /* codec capabilities */
  55. /* decoder can use draw_horiz_band callback */
  56. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001
  57. #define FRAME_RATE_BASE 10000
  58. typedef struct AVCodecContext {
  59. int bit_rate;
  60. int flags;
  61. int sub_id; /* some codecs needs additionnal format info. It is
  62. stored there */
  63. /* video only */
  64. int frame_rate; /* frames per sec multiplied by FRAME_RATE_BASE */
  65. int width, height;
  66. int gop_size; /* 0 = intra only */
  67. int pix_fmt; /* pixel format, see PIX_FMT_xxx */
  68. /* if non NULL, 'draw_horiz_band' is called by the libavcodec
  69. decoder to draw an horizontal band. It improve cache usage. Not
  70. all codecs can do that. You must check the codec capabilities
  71. before */
  72. void (*draw_horiz_band)(struct AVCodecContext *s,
  73. UINT8 **src_ptr, int linesize,
  74. int y, int width, int height);
  75. /* audio only */
  76. int sample_rate; /* samples per sec */
  77. int channels;
  78. int sample_fmt; /* sample format, currenly unused */
  79. /* the following data should not be initialized */
  80. int frame_size; /* in samples, initialized when calling 'init' */
  81. int frame_number; /* audio or video frame number */
  82. int key_frame; /* true if the previous compressed frame was
  83. a key frame (intra, or seekable) */
  84. int quality; /* quality of the previous encoded frame
  85. (between 1 (good) and 31 (bad)) */
  86. struct AVCodec *codec;
  87. void *priv_data;
  88. /* the following fields are ignored */
  89. void *opaque; /* can be used to carry app specific stuff */
  90. char codec_name[32];
  91. int codec_type; /* see CODEC_TYPE_xxx */
  92. int codec_id; /* see CODEC_ID_xxx */
  93. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  94. } AVCodecContext;
  95. typedef struct AVCodec {
  96. char *name;
  97. int type;
  98. int id;
  99. int priv_data_size;
  100. int (*init)(AVCodecContext *);
  101. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  102. int (*close)(AVCodecContext *);
  103. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  104. UINT8 *buf, int buf_size);
  105. int capabilities;
  106. struct AVCodec *next;
  107. } AVCodec;
  108. /* three components are given, that's all */
  109. typedef struct AVPicture {
  110. UINT8 *data[3];
  111. int linesize[3];
  112. } AVPicture;
  113. extern AVCodec ac3_encoder;
  114. extern AVCodec mp2_encoder;
  115. extern AVCodec mpeg1video_encoder;
  116. extern AVCodec h263_encoder;
  117. extern AVCodec h263p_encoder;
  118. extern AVCodec rv10_encoder;
  119. extern AVCodec mjpeg_encoder;
  120. extern AVCodec mpeg4_encoder;
  121. extern AVCodec msmpeg4_encoder;
  122. extern AVCodec h263_decoder;
  123. extern AVCodec mpeg4_decoder;
  124. extern AVCodec msmpeg4_decoder;
  125. extern AVCodec mpeg_decoder;
  126. extern AVCodec h263i_decoder;
  127. extern AVCodec rv10_decoder;
  128. extern AVCodec mjpeg_decoder;
  129. extern AVCodec mp3_decoder;
  130. /* pcm codecs */
  131. #define PCM_CODEC(id, name) \
  132. extern AVCodec name ## _decoder; \
  133. extern AVCodec name ## _encoder;
  134. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  135. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  136. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  137. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  138. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  139. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  140. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  141. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  142. #undef PCM_CODEC
  143. /* dummy raw video codec */
  144. extern AVCodec rawvideo_codec;
  145. /* the following codecs use external GPL libs */
  146. extern AVCodec ac3_decoder;
  147. /* resample.c */
  148. struct ReSampleContext;
  149. typedef struct ReSampleContext ReSampleContext;
  150. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  151. int output_rate, int input_rate);
  152. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  153. void audio_resample_close(ReSampleContext *s);
  154. /* YUV420 format is assumed ! */
  155. struct ImgReSampleContext;
  156. typedef struct ImgReSampleContext ImgReSampleContext;
  157. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  158. int input_width, int input_height);
  159. void img_resample(ImgReSampleContext *s,
  160. AVPicture *output, AVPicture *input);
  161. void img_resample_close(ImgReSampleContext *s);
  162. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  163. int pix_fmt, int width, int height);
  164. int avpicture_get_size(int pix_fmt, int width, int height);
  165. /* convert among pixel formats */
  166. int img_convert(AVPicture *dst, int dst_pix_fmt,
  167. AVPicture *src, int pix_fmt,
  168. int width, int height);
  169. /* deinterlace a picture */
  170. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  171. int pix_fmt, int width, int height);
  172. /* external high level API */
  173. extern AVCodec *first_avcodec;
  174. void avcodec_init(void);
  175. void register_avcodec(AVCodec *format);
  176. AVCodec *avcodec_find_encoder(enum CodecID id);
  177. AVCodec *avcodec_find_decoder(enum CodecID id);
  178. AVCodec *avcodec_find_decoder_by_name(const char *name);
  179. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  180. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  181. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  182. int *frame_size_ptr,
  183. UINT8 *buf, int buf_size);
  184. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  185. int *got_picture_ptr,
  186. UINT8 *buf, int buf_size);
  187. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  188. const short *samples);
  189. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  190. const AVPicture *pict);
  191. int avcodec_close(AVCodecContext *avctx);
  192. void avcodec_register_all(void);
  193. #endif /* AVCODEC_H */