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.

537 lines
18KB

  1. #ifndef AVCODEC_H
  2. #define AVCODEC_H
  3. #include "common.h"
  4. #define LIBAVCODEC_VERSION_INT 0x000406
  5. #define LIBAVCODEC_VERSION "0.4.6"
  6. #define LIBAVCODEC_BUILD 4615
  7. #define LIBAVCODEC_BUILD_STR "4615"
  8. enum CodecID {
  9. CODEC_ID_NONE,
  10. CODEC_ID_MPEG1VIDEO,
  11. CODEC_ID_H263,
  12. CODEC_ID_RV10,
  13. CODEC_ID_MP2,
  14. CODEC_ID_MP3LAME,
  15. CODEC_ID_AC3,
  16. CODEC_ID_MJPEG,
  17. CODEC_ID_MPEG4,
  18. CODEC_ID_RAWVIDEO,
  19. CODEC_ID_MSMPEG4V1,
  20. CODEC_ID_MSMPEG4V2,
  21. CODEC_ID_MSMPEG4V3,
  22. CODEC_ID_WMV1,
  23. CODEC_ID_WMV2,
  24. CODEC_ID_H263P,
  25. CODEC_ID_H263I,
  26. CODEC_ID_SVQ1,
  27. /* various pcm "codecs" */
  28. CODEC_ID_PCM_S16LE,
  29. CODEC_ID_PCM_S16BE,
  30. CODEC_ID_PCM_U16LE,
  31. CODEC_ID_PCM_U16BE,
  32. CODEC_ID_PCM_S8,
  33. CODEC_ID_PCM_U8,
  34. CODEC_ID_PCM_MULAW,
  35. CODEC_ID_PCM_ALAW,
  36. };
  37. #define CODEC_ID_MSMPEG4 CODEC_ID_MSMPEG4V3
  38. enum CodecType {
  39. CODEC_TYPE_UNKNOWN = -1,
  40. CODEC_TYPE_VIDEO,
  41. CODEC_TYPE_AUDIO,
  42. };
  43. enum PixelFormat {
  44. PIX_FMT_ANY = -1,
  45. PIX_FMT_YUV420P,
  46. PIX_FMT_YUV422,
  47. PIX_FMT_RGB24,
  48. PIX_FMT_BGR24,
  49. PIX_FMT_YUV422P,
  50. PIX_FMT_YUV444P,
  51. PIX_FMT_YUV410P
  52. };
  53. /* currently unused, may be used if 24/32 bits samples ever supported */
  54. enum SampleFormat {
  55. SAMPLE_FMT_S16 = 0, /* signed 16 bits */
  56. };
  57. /* in bytes */
  58. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 18432
  59. /* motion estimation type, EPZS by default */
  60. enum Motion_Est_ID {
  61. ME_ZERO = 1,
  62. ME_FULL,
  63. ME_LOG,
  64. ME_PHODS,
  65. ME_EPZS,
  66. ME_X1
  67. };
  68. /* only for ME compatiblity with old apps */
  69. extern int motion_estimation_method;
  70. /* ME algos sorted by quality */
  71. static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
  72. ME_X1, ME_EPZS, ME_FULL };
  73. #define FF_MAX_B_FRAMES 4
  74. /* encoding support */
  75. /* note not everything is supported yet */
  76. #define CODEC_FLAG_HQ 0x0001 /* high quality (non real time) encoding */
  77. #define CODEC_FLAG_QSCALE 0x0002 /* use fixed qscale */
  78. #define CODEC_FLAG_4MV 0x0004 /* 4 MV per MB allowed */
  79. #define CODEC_FLAG_QPEL 0x0010 /* use qpel MC */
  80. #define CODEC_FLAG_GMC 0x0020 /* use GMC */
  81. #define CODEC_FLAG_TYPE 0x0040 /* fixed I/P frame type, from avctx->key_frame */
  82. #define CODEC_FLAG_PART 0x0080 /* use data partitioning */
  83. /* parent program gurantees that the input for b-frame containing streams is not written to
  84. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  85. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  86. #define CODEC_FLAG_PASS1 0x0200 /* use internal 2pass ratecontrol in first pass mode */
  87. #define CODEC_FLAG_PASS2 0x0400 /* use internal 2pass ratecontrol in second pass mode */
  88. #define CODEC_FLAG_EXTERN_HUFF 0x1000 /* use external huffman table (for mjpeg) */
  89. #define CODEC_FLAG_GRAY 0x2000 /* only decode/encode grayscale */
  90. /* codec capabilities */
  91. /* decoder can use draw_horiz_band callback */
  92. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001
  93. #define FRAME_RATE_BASE 10000
  94. typedef struct AVCodecContext {
  95. int bit_rate;
  96. int bit_rate_tolerance; /* amount of +- bits (>0)*/
  97. int flags;
  98. int sub_id; /* some codecs needs additionnal format info. It is
  99. stored there */
  100. int me_method; /* ME algorithm used for video coding */
  101. /* extra data from parent application to codec, e.g. huffman table
  102. for mjpeg */
  103. /* the parent should allocate and free this buffer */
  104. void *extradata;
  105. int extradata_size;
  106. /* video only */
  107. int frame_rate; /* frames per sec multiplied by FRAME_RATE_BASE */
  108. int width, height;
  109. int aspect_ratio_info;
  110. #define FF_ASPECT_SQUARE 1
  111. #define FF_ASPECT_4_3_625 2
  112. #define FF_ASPECT_4_3_525 3
  113. #define FF_ASPECT_16_9_625 4
  114. #define FF_ASPECT_16_9_525 5
  115. int gop_size; /* 0 = intra only */
  116. enum PixelFormat pix_fmt; /* pixel format, see PIX_FMT_xxx */
  117. int repeat_pict; /* when decoding, this signal how much the picture */
  118. /* must be delayed. */
  119. /* extra_delay = (repeat_pict / 2) * (1/fps) */
  120. /* if non NULL, 'draw_horiz_band' is called by the libavcodec
  121. decoder to draw an horizontal band. It improve cache usage. Not
  122. all codecs can do that. You must check the codec capabilities
  123. before */
  124. void (*draw_horiz_band)(struct AVCodecContext *s,
  125. UINT8 **src_ptr, int linesize,
  126. int y, int width, int height);
  127. /* audio only */
  128. int sample_rate; /* samples per sec */
  129. int channels;
  130. int sample_fmt; /* sample format, currenly unused */
  131. /* the following data should not be initialized */
  132. int frame_size; /* in samples, initialized when calling 'init' */
  133. int frame_number; /* audio or video frame number */
  134. int real_pict_num; /* returns the real picture number of
  135. previous encoded frame */
  136. int key_frame; /* true if the previous compressed frame was
  137. a key frame (intra, or seekable) */
  138. int pict_type; /* picture type of the previous
  139. encoded frame */
  140. /* FIXME: these should have FF_ */
  141. #define I_TYPE 1 // Intra
  142. #define P_TYPE 2 // Predicted
  143. #define B_TYPE 3 // Bi-dir predicted
  144. #define S_TYPE 4 // S(GMC)-VOP MPEG4
  145. int delay; /* number of frames the decoded output
  146. will be delayed relative to the encoded input */
  147. uint8_t *mbskip_table; /* =1 if MB didnt change, is only valid for I/P frames
  148. stride= mb_width = (width+15)>>4 */
  149. /* encoding parameters */
  150. int quality; /* quality of the previous encoded frame
  151. (between 1 (good) and 31 (bad))
  152. this is allso used to set the quality in vbr mode
  153. and the per frame quality in CODEC_FLAG_TYPE (second pass mode) */
  154. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  155. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  156. int qmin; /* min qscale */
  157. int qmax; /* max qscale */
  158. int max_qdiff; /* max qscale difference between frames */
  159. int max_b_frames; /* maximum b frames, the output will be delayed by max_b_frames+1 relative to the input */
  160. float b_quant_factor;/* qscale factor between ips and b frames */
  161. int rc_strategy;
  162. int b_frame_strategy;
  163. int hurry_up; /* when set to 1 during decoding, b frames will be skiped
  164. when set to 2 idct/dequant will be skipped too */
  165. struct AVCodec *codec;
  166. void *priv_data;
  167. /* The following data is for RTP friendly coding */
  168. /* By now only H.263/H.263+/MPEG4 coder honours this */
  169. int rtp_mode; /* 1 for activate RTP friendly-mode */
  170. /* highers numbers represent more error-prone */
  171. /* enviroments, by now just "1" exist */
  172. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  173. /* do it's best to deliver a chunk with size */
  174. /* below rtp_payload_size, the chunk will start */
  175. /* with a start code on some codecs like H.263 */
  176. /* This doesn't take account of any particular */
  177. /* headers inside the transmited RTP payload */
  178. /* The RTP callcack: This function is called */
  179. /* every time the encoder as a packet to send */
  180. /* Depends on the encoder if the data starts */
  181. /* with a Start Code (it should) H.263 does */
  182. void (*rtp_callback)(void *data, int size, int packet_number);
  183. /* These are for PSNR calculation, if you set get_psnr to 1 */
  184. /* after encoding you will have the PSNR on psnr_y/cb/cr */
  185. int get_psnr;
  186. float psnr_y;
  187. float psnr_cb;
  188. float psnr_cr;
  189. /* statistics, used for 2-pass encoding */
  190. int mv_bits;
  191. int header_bits;
  192. int i_tex_bits;
  193. int p_tex_bits;
  194. int i_count;
  195. int p_count;
  196. int skip_count;
  197. int misc_bits; // cbp, mb_type
  198. int frame_bits;
  199. /* the following fields are ignored */
  200. void *opaque; /* can be used to carry app specific stuff */
  201. char codec_name[32];
  202. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  203. enum CodecID codec_id; /* see CODEC_ID_xxx */
  204. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  205. int workaround_bugs; /* workaround bugs in encoders which cannot be detected automatically */
  206. int luma_elim_threshold;
  207. int chroma_elim_threshold;
  208. int strict_std_compliance; /* strictly follow the std (MPEG4, ...) */
  209. float b_quant_offset;/* qscale offset between ips and b frames, not implemented yet */
  210. int error_resilience;
  211. #ifndef MBC
  212. #define MBC 128
  213. #define MBR 96
  214. #endif
  215. int *quant_store; /* field for communicating with external postprocessing */
  216. unsigned qstride;
  217. //FIXME this should be reordered after kabis API is finished ...
  218. /*
  219. Note: Below are located reserved fields for further usage
  220. It requires for ABI !!!
  221. If you'll perform some changes then borrow new space from these fields
  222. (void * can be safety replaced with struct * ;)
  223. P L E A S E ! ! !
  224. IMPORTANT: Never change order of already declared fields!!!
  225. */
  226. unsigned long long int
  227. ull_res0,ull_res1,ull_res2,ull_res3,ull_res4,ull_res5,
  228. ull_res6,ull_res7,ull_res8,ull_res9,ull_res10,ull_res11,ull_res12;
  229. float
  230. flt_res0,flt_res1,flt_res2,flt_res3,flt_res4,flt_res5,
  231. flt_res6,flt_res7,flt_res8,flt_res9,flt_res10,flt_res11;
  232. void
  233. *ptr_res0,*ptr_res1,*ptr_res2,*ptr_res3,*ptr_res4,*ptr_res5,
  234. *ptr_res6,*ptr_res7,*ptr_res8,*ptr_res9,*ptr_res10,*ptr_res11;
  235. unsigned long int
  236. ul_res0,ul_res1,ul_res2,ul_res3,ul_res4,ul_res5,
  237. ul_res6,ul_res7,ul_res8,ul_res9,ul_res10,ul_res11,ul_res12;
  238. unsigned int
  239. ui_res0,ui_res1,ui_res2,ui_res3,ui_res4,ui_res5,
  240. ui_res6;
  241. unsigned short int
  242. us_res0,us_res1,us_res2,us_res3,us_res4,us_res5,
  243. us_res6,us_res7,us_res8,us_res9,us_res10,us_res11,us_res12;
  244. unsigned char
  245. uc_res0,uc_res1,uc_res2,uc_res3,uc_res4,uc_res5,
  246. uc_res6,uc_res7,uc_res8,uc_res9,uc_res10,uc_res11,uc_res12;
  247. } AVCodecContext;
  248. typedef struct AVCodec {
  249. char *name;
  250. int type;
  251. int id;
  252. int priv_data_size;
  253. int (*init)(AVCodecContext *);
  254. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  255. int (*close)(AVCodecContext *);
  256. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  257. UINT8 *buf, int buf_size);
  258. int capabilities;
  259. struct AVCodec *next;
  260. /*
  261. Note: Below are located reserved fields for further usage
  262. It requires for ABI !!!
  263. If you'll perform some changes then borrow new space from these fields
  264. (void * can be safety replaced with struct * ;)
  265. P L E A S E ! ! !
  266. IMPORTANT: Never change order of already declared fields!!!
  267. */
  268. unsigned long long int
  269. ull_res0,ull_res1,ull_res2,ull_res3,ull_res4,ull_res5,
  270. ull_res6,ull_res7,ull_res8,ull_res9,ull_res10,ull_res11,ull_res12;
  271. float
  272. flt_res0,flt_res1,flt_res2,flt_res3,flt_res4,flt_res5,
  273. flt_res6,flt_res7,flt_res8,flt_res9,flt_res10,flt_res11,flt_res12;
  274. void
  275. *ptr_res0,*ptr_res1,*ptr_res2,*ptr_res3,*ptr_res4,*ptr_res5,
  276. *ptr_res6,*ptr_res7,*ptr_res8,*ptr_res9,*ptr_res10,*ptr_res11,*ptr_res12;
  277. } AVCodec;
  278. /* three components are given, that's all */
  279. typedef struct AVPicture {
  280. UINT8 *data[3];
  281. int linesize[3];
  282. } AVPicture;
  283. extern AVCodec ac3_encoder;
  284. extern AVCodec mp2_encoder;
  285. extern AVCodec mp3lame_encoder;
  286. extern AVCodec mpeg1video_encoder;
  287. extern AVCodec h263_encoder;
  288. extern AVCodec h263p_encoder;
  289. extern AVCodec rv10_encoder;
  290. extern AVCodec mjpeg_encoder;
  291. extern AVCodec mpeg4_encoder;
  292. extern AVCodec msmpeg4v1_encoder;
  293. extern AVCodec msmpeg4v2_encoder;
  294. extern AVCodec msmpeg4v3_encoder;
  295. extern AVCodec wmv1_encoder;
  296. extern AVCodec wmv2_encoder;
  297. extern AVCodec h263_decoder;
  298. extern AVCodec mpeg4_decoder;
  299. extern AVCodec msmpeg4v1_decoder;
  300. extern AVCodec msmpeg4v2_decoder;
  301. extern AVCodec msmpeg4v3_decoder;
  302. extern AVCodec wmv1_decoder;
  303. extern AVCodec wmv2_decoder;
  304. extern AVCodec mpeg_decoder;
  305. extern AVCodec h263i_decoder;
  306. extern AVCodec rv10_decoder;
  307. extern AVCodec svq1_decoder;
  308. extern AVCodec mjpeg_decoder;
  309. extern AVCodec mp2_decoder;
  310. extern AVCodec mp3_decoder;
  311. /* pcm codecs */
  312. #define PCM_CODEC(id, name) \
  313. extern AVCodec name ## _decoder; \
  314. extern AVCodec name ## _encoder;
  315. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  316. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  317. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  318. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  319. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  320. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  321. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  322. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  323. #undef PCM_CODEC
  324. /* dummy raw video codec */
  325. extern AVCodec rawvideo_codec;
  326. /* the following codecs use external GPL libs */
  327. extern AVCodec ac3_decoder;
  328. /* resample.c */
  329. struct ReSampleContext;
  330. typedef struct ReSampleContext ReSampleContext;
  331. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  332. int output_rate, int input_rate);
  333. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  334. void audio_resample_close(ReSampleContext *s);
  335. /* YUV420 format is assumed ! */
  336. struct ImgReSampleContext;
  337. typedef struct ImgReSampleContext ImgReSampleContext;
  338. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  339. int input_width, int input_height);
  340. void img_resample(ImgReSampleContext *s,
  341. AVPicture *output, AVPicture *input);
  342. void img_resample_close(ImgReSampleContext *s);
  343. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  344. int pix_fmt, int width, int height);
  345. int avpicture_get_size(int pix_fmt, int width, int height);
  346. /* convert among pixel formats */
  347. int img_convert(AVPicture *dst, int dst_pix_fmt,
  348. AVPicture *src, int pix_fmt,
  349. int width, int height);
  350. /* deinterlace a picture */
  351. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  352. int pix_fmt, int width, int height);
  353. /* external high level API */
  354. extern AVCodec *first_avcodec;
  355. /* returns LIBAVCODEC_VERSION_INT constant */
  356. unsigned avcodec_version(void);
  357. /* returns LIBAVCODEC_BUILD constant */
  358. unsigned avcodec_build(void);
  359. void avcodec_init(void);
  360. void avcodec_set_bit_exact(void);
  361. void register_avcodec(AVCodec *format);
  362. AVCodec *avcodec_find_encoder(enum CodecID id);
  363. AVCodec *avcodec_find_encoder_by_name(const char *name);
  364. AVCodec *avcodec_find_decoder(enum CodecID id);
  365. AVCodec *avcodec_find_decoder_by_name(const char *name);
  366. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  367. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  368. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  369. int *frame_size_ptr,
  370. UINT8 *buf, int buf_size);
  371. int avcodec_decode_video(AVCodecContext *avctx, AVPicture *picture,
  372. int *got_picture_ptr,
  373. UINT8 *buf, int buf_size);
  374. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  375. const short *samples);
  376. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  377. const AVPicture *pict);
  378. int avcodec_close(AVCodecContext *avctx);
  379. void avcodec_register_all(void);
  380. void avcodec_flush_buffers(AVCodecContext *avctx);
  381. #ifdef FF_POSTPROCESS
  382. extern int quant_store[MBR+1][MBC+1]; // [Review]
  383. #endif
  384. /**
  385. * Interface for 0.5.0 version
  386. *
  387. * do not even think about it's usage for this moment
  388. */
  389. typedef struct {
  390. // compressed size used from given memory buffer
  391. int size;
  392. /// I/P/B frame type
  393. int frame_type;
  394. } avc_enc_result_t;
  395. /**
  396. * Commands
  397. * order can't be changed - once it was defined
  398. */
  399. typedef enum {
  400. // general commands
  401. AVC_OPEN_BY_NAME = 0xACA000,
  402. AVC_OPEN_BY_CODEC_ID,
  403. AVC_OPEN_BY_FOURCC,
  404. AVC_CLOSE,
  405. AVC_FLUSH,
  406. // pin - struct { uint8_t* src, uint_t src_size }
  407. // pout - struct { AVPicture* img, consumed_bytes,
  408. AVC_DECODE,
  409. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  410. // pout - uint_t used_from_dest_size
  411. AVC_ENCODE,
  412. // query/get video commands
  413. AVC_GET_VERSION = 0xACB000,
  414. AVC_GET_WIDTH,
  415. AVC_GET_HEIGHT,
  416. AVC_GET_DELAY,
  417. AVC_GET_QUANT_TABLE,
  418. // ...
  419. // query/get audio commands
  420. AVC_GET_FRAME_SIZE = 0xABC000,
  421. // maybe define some simple structure which
  422. // might be passed to the user - but they can't
  423. // contain any codec specific parts and these
  424. // calls are usualy necessary only few times
  425. // set video commands
  426. AVC_SET_WIDTH = 0xACD000,
  427. AVC_SET_HEIGHT,
  428. // set video encoding commands
  429. AVC_SET_FRAME_RATE = 0xACD800,
  430. AVC_SET_QUALITY,
  431. AVC_SET_HURRY_UP,
  432. // set audio commands
  433. AVC_SET_SAMPLE_RATE = 0xACE000,
  434. AVC_SET_CHANNELS,
  435. } avc_cmd_t;
  436. /**
  437. * \param handle allocated private structure by libavcodec
  438. * for initialization pass NULL - will be returned pout
  439. * user is supposed to know nothing about its structure
  440. * \param cmd type of operation to be performed
  441. * \param pint input parameter
  442. * \param pout output parameter
  443. *
  444. * \returns command status - eventually for query command it might return
  445. * integer resulting value
  446. */
  447. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  448. /* memory */
  449. void *av_malloc(int size);
  450. void *av_mallocz(int size);
  451. void av_free(void *ptr);
  452. void __av_freep(void **ptr);
  453. #define av_freep(p) __av_freep((void **)(p))
  454. #endif /* AVCODEC_H */