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.

271 lines
8.2KB

  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 data is for RTP friendly coding */
  89. /* By now only H.263/H.263+ coder honours this */
  90. int rtp_mode; /* 1 for activate RTP friendly-mode */
  91. /* highers numbers represent more error-prone */
  92. /* enviroments, by now just "1" exist */
  93. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  94. /* do it's best to deliver a chunk with size */
  95. /* below rtp_payload_size, the chunk will start */
  96. /* with a start code on some codecs like H.263 */
  97. /* This doesn't take account of any particular */
  98. /* headers inside the transmited RTP payload */
  99. /* The RTP callcack: This function is called */
  100. /* every time the encoder as a packet to send */
  101. /* Depends on the encoder if the data starts */
  102. /* with a Start Code (it should) H.263 does */
  103. void (*rtp_callback)(void *data, int size, int packet_number);
  104. /* the following fields are ignored */
  105. void *opaque; /* can be used to carry app specific stuff */
  106. char codec_name[32];
  107. int codec_type; /* see CODEC_TYPE_xxx */
  108. int codec_id; /* see CODEC_ID_xxx */
  109. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  110. } AVCodecContext;
  111. typedef struct AVCodec {
  112. char *name;
  113. int type;
  114. int id;
  115. int priv_data_size;
  116. int (*init)(AVCodecContext *);
  117. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  118. int (*close)(AVCodecContext *);
  119. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  120. UINT8 *buf, int buf_size);
  121. int capabilities;
  122. struct AVCodec *next;
  123. } AVCodec;
  124. /* three components are given, that's all */
  125. typedef struct AVPicture {
  126. UINT8 *data[3];
  127. int linesize[3];
  128. } AVPicture;
  129. extern AVCodec ac3_encoder;
  130. extern AVCodec mp2_encoder;
  131. extern AVCodec mpeg1video_encoder;
  132. extern AVCodec h263_encoder;
  133. extern AVCodec h263p_encoder;
  134. extern AVCodec rv10_encoder;
  135. extern AVCodec mjpeg_encoder;
  136. extern AVCodec mpeg4_encoder;
  137. extern AVCodec msmpeg4_encoder;
  138. extern AVCodec h263_decoder;
  139. extern AVCodec mpeg4_decoder;
  140. extern AVCodec msmpeg4_decoder;
  141. extern AVCodec mpeg_decoder;
  142. extern AVCodec h263i_decoder;
  143. extern AVCodec rv10_decoder;
  144. extern AVCodec mjpeg_decoder;
  145. extern AVCodec mp3_decoder;
  146. /* pcm codecs */
  147. #define PCM_CODEC(id, name) \
  148. extern AVCodec name ## _decoder; \
  149. extern AVCodec name ## _encoder;
  150. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  151. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  152. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  153. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  154. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  155. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  156. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  157. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  158. #undef PCM_CODEC
  159. /* dummy raw video codec */
  160. extern AVCodec rawvideo_codec;
  161. /* the following codecs use external GPL libs */
  162. extern AVCodec ac3_decoder;
  163. /* resample.c */
  164. struct ReSampleContext;
  165. typedef struct ReSampleContext ReSampleContext;
  166. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  167. int output_rate, int input_rate);
  168. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  169. void audio_resample_close(ReSampleContext *s);
  170. /* YUV420 format is assumed ! */
  171. struct ImgReSampleContext;
  172. typedef struct ImgReSampleContext ImgReSampleContext;
  173. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  174. int input_width, int input_height);
  175. void img_resample(ImgReSampleContext *s,
  176. AVPicture *output, AVPicture *input);
  177. void img_resample_close(ImgReSampleContext *s);
  178. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  179. int pix_fmt, int width, int height);
  180. int avpicture_get_size(int pix_fmt, int width, int height);
  181. /* convert among pixel formats */
  182. int img_convert(AVPicture *dst, int dst_pix_fmt,
  183. AVPicture *src, int pix_fmt,
  184. int width, int height);
  185. /* deinterlace a picture */
  186. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  187. int pix_fmt, int width, int height);
  188. /* external high level API */
  189. extern AVCodec *first_avcodec;
  190. void avcodec_init(void);
  191. void register_avcodec(AVCodec *format);
  192. AVCodec *avcodec_find_encoder(enum CodecID id);
  193. AVCodec *avcodec_find_encoder_by_name(const char *name);
  194. AVCodec *avcodec_find_decoder(enum CodecID id);
  195. AVCodec *avcodec_find_decoder_by_name(const char *name);
  196. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  197. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  198. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  199. int *frame_size_ptr,
  200. UINT8 *buf, int buf_size);
  201. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  202. int *got_picture_ptr,
  203. UINT8 *buf, int buf_size);
  204. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  205. const short *samples);
  206. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  207. const AVPicture *pict);
  208. int avcodec_close(AVCodecContext *avctx);
  209. void avcodec_register_all(void);
  210. #ifdef FF_POSTPROCESS
  211. #ifndef MBC
  212. #define MBC 48
  213. #define MBR 36
  214. #endif
  215. extern int quant_store[MBR+1][MBC+1]; // [Review]
  216. #endif
  217. #endif /* AVCODEC_H */