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.

572 lines
19KB

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