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.

522 lines
17KB

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