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.

1269 lines
35KB

  1. #ifndef AVCODEC_H
  2. #define AVCODEC_H
  3. /**
  4. * @file avcodec.h
  5. * @brief
  6. * external api header
  7. */
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #include "common.h"
  12. #define LIBAVCODEC_VERSION_INT 0x000406
  13. #define LIBAVCODEC_VERSION "0.4.6"
  14. #define LIBAVCODEC_BUILD 4656
  15. #define LIBAVCODEC_BUILD_STR "4656"
  16. enum CodecID {
  17. CODEC_ID_NONE,
  18. CODEC_ID_MPEG1VIDEO,
  19. CODEC_ID_H263,
  20. CODEC_ID_RV10,
  21. CODEC_ID_MP2,
  22. CODEC_ID_MP3LAME,
  23. CODEC_ID_VORBIS,
  24. CODEC_ID_AC3,
  25. CODEC_ID_MJPEG,
  26. CODEC_ID_MJPEGB,
  27. CODEC_ID_MPEG4,
  28. CODEC_ID_RAWVIDEO,
  29. CODEC_ID_MSMPEG4V1,
  30. CODEC_ID_MSMPEG4V2,
  31. CODEC_ID_MSMPEG4V3,
  32. CODEC_ID_WMV1,
  33. CODEC_ID_WMV2,
  34. CODEC_ID_H263P,
  35. CODEC_ID_H263I,
  36. CODEC_ID_SVQ1,
  37. CODEC_ID_DVVIDEO,
  38. CODEC_ID_DVAUDIO,
  39. CODEC_ID_WMAV1,
  40. CODEC_ID_WMAV2,
  41. CODEC_ID_MACE3,
  42. CODEC_ID_MACE6,
  43. CODEC_ID_HUFFYUV,
  44. CODEC_ID_CYUV,
  45. /* various pcm "codecs" */
  46. CODEC_ID_PCM_S16LE,
  47. CODEC_ID_PCM_S16BE,
  48. CODEC_ID_PCM_U16LE,
  49. CODEC_ID_PCM_U16BE,
  50. CODEC_ID_PCM_S8,
  51. CODEC_ID_PCM_U8,
  52. CODEC_ID_PCM_MULAW,
  53. CODEC_ID_PCM_ALAW,
  54. /* various adpcm codecs */
  55. CODEC_ID_ADPCM_IMA_QT,
  56. CODEC_ID_ADPCM_IMA_WAV,
  57. CODEC_ID_ADPCM_MS,
  58. };
  59. enum CodecType {
  60. CODEC_TYPE_UNKNOWN = -1,
  61. CODEC_TYPE_VIDEO,
  62. CODEC_TYPE_AUDIO,
  63. };
  64. enum PixelFormat {
  65. PIX_FMT_YUV420P,
  66. PIX_FMT_YUV422,
  67. PIX_FMT_RGB24, /* 3 bytes, R is first */
  68. PIX_FMT_BGR24, /* 3 bytes, B is first */
  69. PIX_FMT_YUV422P,
  70. PIX_FMT_YUV444P,
  71. PIX_FMT_RGBA32, /* always stored in cpu endianness */
  72. PIX_FMT_YUV410P,
  73. PIX_FMT_YUV411P,
  74. PIX_FMT_RGB565, /* always stored in cpu endianness */
  75. PIX_FMT_RGB555, /* always stored in cpu endianness, most significant bit to 1 */
  76. PIX_FMT_GRAY8,
  77. PIX_FMT_MONOWHITE, /* 0 is white */
  78. PIX_FMT_MONOBLACK, /* 0 is black */
  79. PIX_FMT_PAL8, /* 8 bit with RGBA palette */
  80. PIX_FMT_NB,
  81. };
  82. /* currently unused, may be used if 24/32 bits samples ever supported */
  83. enum SampleFormat {
  84. SAMPLE_FMT_S16 = 0, /* signed 16 bits */
  85. };
  86. /* in bytes */
  87. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
  88. /**
  89. * Required number of zero bytes at the end of the input bitstream for decoding.
  90. * to avoid overreading (and possibly segfaulting)
  91. */
  92. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  93. /* motion estimation type, EPZS by default */
  94. enum Motion_Est_ID {
  95. ME_ZERO = 1,
  96. ME_FULL,
  97. ME_LOG,
  98. ME_PHODS,
  99. ME_EPZS,
  100. ME_X1
  101. };
  102. typedef struct RcOverride{
  103. int start_frame;
  104. int end_frame;
  105. int qscale; // if this is 0 then quality_factor will be used instead
  106. float quality_factor;
  107. } RcOverride;
  108. /* only for ME compatiblity with old apps */
  109. extern int motion_estimation_method;
  110. /* ME algos sorted by quality */
  111. static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
  112. ME_X1, ME_EPZS, ME_FULL };
  113. #define FF_MAX_B_FRAMES 8
  114. /* encoding support
  115. these flags can be passed in AVCodecContext.flags before initing
  116. Note: note not everything is supported yet
  117. */
  118. #define CODEC_FLAG_HQ 0x0001 /* brute force MB-type decission mode (slow) */
  119. #define CODEC_FLAG_QSCALE 0x0002 /* use fixed qscale */
  120. #define CODEC_FLAG_4MV 0x0004 /* 4 MV per MB allowed */
  121. #define CODEC_FLAG_QPEL 0x0010 /* use qpel MC */
  122. #define CODEC_FLAG_GMC 0x0020 /* use GMC */
  123. #define CODEC_FLAG_PART 0x0080 /* use data partitioning */
  124. /* parent program gurantees that the input for b-frame containing streams is not written to
  125. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  126. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  127. #define CODEC_FLAG_PASS1 0x0200 /* use internal 2pass ratecontrol in first pass mode */
  128. #define CODEC_FLAG_PASS2 0x0400 /* use internal 2pass ratecontrol in second pass mode */
  129. #define CODEC_FLAG_EXTERN_HUFF 0x1000 /* use external huffman table (for mjpeg) */
  130. #define CODEC_FLAG_GRAY 0x2000 /* only decode/encode grayscale */
  131. #define CODEC_FLAG_EMU_EDGE 0x4000/* dont draw edges */
  132. #define CODEC_FLAG_PSNR 0x8000 /* error[?] variables will be set during encoding */
  133. #define CODEC_FLAG_TRUNCATED 0x00010000 /* input bitstream might be truncated at a random location instead
  134. of only at frame boundaries */
  135. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 /* normalize adaptive quantization */
  136. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 /* use interlaced dct */
  137. #define CODEC_FLAG_LOW_DELAY 0x00080000 /* force low delay / will fail on b frames */
  138. #define CODEC_FLAG_ALT_SCAN 0x00100000 /* use alternate scan */
  139. #define CODEC_FLAG_TRELLIS_QUANT 0x00200000 /* use trellis quantization */
  140. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 /* place global headers in extradata instead of every keyframe */
  141. /* codec capabilities */
  142. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 /* decoder can use draw_horiz_band callback */
  143. #define CODEC_CAP_DR1 0x0002 /* direct rendering method 1 */
  144. /* if 'parse_only' field is true, then avcodec_parse_frame() can be
  145. used */
  146. #define CODEC_CAP_PARSE_ONLY 0x0004
  147. #define CODEC_CAP_TRUNCATED 0x0008
  148. #define FRAME_RATE_BASE 10000
  149. #define FF_COMMON_FRAME \
  150. uint8_t *data[4];\
  151. int linesize[4];\
  152. /**\
  153. * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
  154. * this isnt used by lavc unless the default get/release_buffer() is used\
  155. * encoding: \
  156. * decoding: \
  157. */\
  158. uint8_t *base[4];\
  159. /**\
  160. * 1 -> keyframe, 0-> not\
  161. * encoding: set by lavc\
  162. * decoding: set by lavc\
  163. */\
  164. int key_frame;\
  165. \
  166. /**\
  167. * picture type of the frame, see ?_TYPE below\
  168. * encoding: set by lavc for coded_picture (and set by user for input)\
  169. * decoding: set by lavc\
  170. */\
  171. int pict_type;\
  172. \
  173. /**\
  174. * presentation timestamp in micro seconds (time when frame should be shown to user)\
  175. * if 0 then the frame_rate will be used as reference\
  176. * encoding: MUST be set by user\
  177. * decoding: set by lavc\
  178. */\
  179. long long int pts;\
  180. \
  181. /**\
  182. * picture number in bitstream order.\
  183. * encoding: set by\
  184. * decoding: set by lavc\
  185. */\
  186. int coded_picture_number;\
  187. /**\
  188. * encoding: set by\
  189. * decoding: set by lavc\
  190. * picture number in display order.\
  191. */\
  192. int display_picture_number;\
  193. \
  194. /**\
  195. * quality (between 1 (good) and 31 (bad)) \
  196. * encoding: set by lavc for coded_picture (and set by user for input)\
  197. * decoding: set by lavc\
  198. */\
  199. float quality; \
  200. \
  201. /**\
  202. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  203. * set to something large if the buffer has not been used yet \
  204. * encoding: unused\
  205. * decoding: MUST be set by get_buffer()\
  206. */\
  207. int age;\
  208. \
  209. /**\
  210. * is this picture used as reference\
  211. * encoding: unused\
  212. * decoding: set by lavc (before get_buffer() call))\
  213. */\
  214. int reference;\
  215. \
  216. /**\
  217. * QP table\
  218. * encoding: unused\
  219. * decoding: set by lavc\
  220. */\
  221. int8_t *qscale_table;\
  222. /**\
  223. * QP store stride\
  224. * encoding: unused\
  225. * decoding: set by lavc\
  226. */\
  227. int qstride;\
  228. \
  229. /**\
  230. * mbskip_table[mb]>=1 if MB didnt change\
  231. * stride= mb_width = (width+15)>>4\
  232. * encoding: unused\
  233. * decoding: set by lavc\
  234. */\
  235. uint8_t *mbskip_table;\
  236. \
  237. /**\
  238. * for some private data of the user\
  239. * encoding: unused\
  240. * decoding: set by user\
  241. */\
  242. void *opaque;\
  243. \
  244. /**\
  245. * error\
  246. * encoding: set by lavc if flags&CODEC_FLAG_PSNR\
  247. * decoding: unused\
  248. */\
  249. uint64_t error[4];\
  250. \
  251. /**\
  252. * type of the buffer (to keep track of who has to dealloc data[*])\
  253. * encoding: set by the one who allocs it\
  254. * decoding: set by the one who allocs it\
  255. * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
  256. */\
  257. int type;\
  258. #define FF_BUFFER_TYPE_INTERNAL 1
  259. #define FF_BUFFER_TYPE_USER 2 // Direct rendering buffers
  260. #define FF_BUFFER_TYPE_SHARED 4 // input frame for encoding(wont be dealloced)
  261. #define FF_I_TYPE 1 // Intra
  262. #define FF_P_TYPE 2 // Predicted
  263. #define FF_B_TYPE 3 // Bi-dir predicted
  264. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  265. typedef struct AVFrame {
  266. FF_COMMON_FRAME
  267. } AVFrame;
  268. typedef struct AVCodecContext {
  269. /**
  270. * the average bitrate
  271. * encoding: set by user. unused for constant quantizer encoding
  272. * decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  273. */
  274. int bit_rate;
  275. /**
  276. * number of bits the bitstream is allowed to diverge from the reference
  277. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  278. * encoding: set by user. unused for constant quantizer encoding
  279. * decoding: unused
  280. */
  281. int bit_rate_tolerance;
  282. /**
  283. * CODEC_FLAG_*
  284. * encoding: set by user.
  285. * decoding: set by user.
  286. */
  287. int flags;
  288. /**
  289. * some codecs needs additionnal format info. It is stored here
  290. * encoding: set by user.
  291. * decoding: set by lavc. (FIXME is this ok?)
  292. */
  293. int sub_id;
  294. /**
  295. * motion estimation algorithm used for video coding
  296. * encoding: MUST be set by user.
  297. * decoding: unused
  298. */
  299. int me_method;
  300. /**
  301. * some codecs need / can use extra-data like huffman tables
  302. * mjpeg: huffman tables
  303. * rv10: additional flags
  304. * mpeg4: global headers (they can be in the bitstream or here)
  305. * encoding: set/allocated/freed by lavc.
  306. * decoding: set/allocated/freed by user.
  307. */
  308. void *extradata;
  309. int extradata_size;
  310. /* video only */
  311. /**
  312. * frames per sec multiplied by FRAME_RATE_BASE
  313. * for variable fps this is the precission, so if the timestamps
  314. * can be specified in msec precssion then this is 1000*FRAME_RATE_BASE
  315. * encoding: MUST be set by user
  316. * decoding: set by lavc. 0 or the frame_rate if available
  317. */
  318. int frame_rate;
  319. /**
  320. * encoding: MUST be set by user.
  321. * decoding: set by user, some codecs might override / change it during playback
  322. */
  323. int width, height;
  324. #define FF_ASPECT_SQUARE 1
  325. #define FF_ASPECT_4_3_625 2
  326. #define FF_ASPECT_4_3_525 3
  327. #define FF_ASPECT_16_9_625 4
  328. #define FF_ASPECT_16_9_525 5
  329. #define FF_ASPECT_EXTENDED 15
  330. /**
  331. * the number of pictures in a group of pitures, or 0 for intra_only
  332. * encoding: set by user.
  333. * decoding: unused
  334. */
  335. int gop_size;
  336. /**
  337. * pixel format, see PIX_FMT_xxx
  338. * encoding: unused
  339. * decoding: set by lavc.
  340. */
  341. enum PixelFormat pix_fmt;
  342. int repeat_pict; /* when decoding, this signal how much the picture */
  343. /* must be delayed. */
  344. /* extra_delay = (repeat_pict / 2) * (1/fps) */
  345. /**
  346. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  347. * decoder to draw an horizontal band. It improve cache usage. Not
  348. * all codecs can do that. You must check the codec capabilities
  349. * before
  350. * encoding: unused
  351. * decoding: set by user.
  352. */
  353. void (*draw_horiz_band)(struct AVCodecContext *s,
  354. UINT8 **src_ptr, int linesize,
  355. int y, int width, int height);
  356. /* audio only */
  357. int sample_rate; /* samples per sec */
  358. int channels;
  359. int sample_fmt; /* sample format, currenly unused */
  360. /* the following data should not be initialized */
  361. int frame_size; /* in samples, initialized when calling 'init' */
  362. int frame_number; /* audio or video frame number */
  363. int real_pict_num; /* returns the real picture number of
  364. previous encoded frame */
  365. /**
  366. * number of frames the decoded output will be delayed relative to
  367. * the encoded input
  368. * encoding: set by lavc.
  369. * decoding: unused
  370. */
  371. int delay;
  372. /* encoding parameters */
  373. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  374. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  375. /**
  376. * minimum quantizer
  377. * encoding: set by user.
  378. * decoding: unused
  379. */
  380. int qmin;
  381. /**
  382. * maximum quantizer
  383. * encoding: set by user.
  384. * decoding: unused
  385. */
  386. int qmax;
  387. /**
  388. * maximum quantizer difference etween frames
  389. * encoding: set by user.
  390. * decoding: unused
  391. */
  392. int max_qdiff;
  393. /**
  394. * maximum number of b frames between non b frames
  395. * note: the output will be delayed by max_b_frames+1 relative to the input
  396. * encoding: set by user.
  397. * decoding: unused
  398. */
  399. int max_b_frames;
  400. /**
  401. * qscale factor between ip and b frames
  402. * encoding: set by user.
  403. * decoding: unused
  404. */
  405. float b_quant_factor;
  406. /** obsolete FIXME remove */
  407. int rc_strategy;
  408. int b_frame_strategy;
  409. /**
  410. * encoding: unused
  411. * decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  412. */
  413. int hurry_up;
  414. struct AVCodec *codec;
  415. void *priv_data;
  416. /* The following data is for RTP friendly coding */
  417. /* By now only H.263/H.263+/MPEG4 coder honours this */
  418. int rtp_mode; /* 1 for activate RTP friendly-mode */
  419. /* highers numbers represent more error-prone */
  420. /* enviroments, by now just "1" exist */
  421. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  422. /* do it's best to deliver a chunk with size */
  423. /* below rtp_payload_size, the chunk will start */
  424. /* with a start code on some codecs like H.263 */
  425. /* This doesn't take account of any particular */
  426. /* headers inside the transmited RTP payload */
  427. /* The RTP callcack: This function is called */
  428. /* every time the encoder as a packet to send */
  429. /* Depends on the encoder if the data starts */
  430. /* with a Start Code (it should) H.263 does */
  431. void (*rtp_callback)(void *data, int size, int packet_number);
  432. /* statistics, used for 2-pass encoding */
  433. int mv_bits;
  434. int header_bits;
  435. int i_tex_bits;
  436. int p_tex_bits;
  437. int i_count;
  438. int p_count;
  439. int skip_count;
  440. int misc_bits;
  441. /**
  442. * number of bits used for the previously encoded frame
  443. * encoding: set by lavc
  444. * decoding: - for audio - bits_per_sample
  445. */
  446. int frame_bits;
  447. /**
  448. * private data of the user, can be used to carry app specific stuff
  449. * encoding: set by user
  450. * decoding: set by user
  451. */
  452. void *opaque;
  453. char codec_name[32];
  454. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  455. enum CodecID codec_id; /* see CODEC_ID_xxx */
  456. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  457. /**
  458. * workaround bugs in encoders which sometimes cannot be detected automatically
  459. * encoding: unused
  460. * decoding: set by user
  461. */
  462. int workaround_bugs;
  463. #define FF_BUG_AUTODETECT 1 //autodetection
  464. #define FF_BUG_OLD_MSMPEG4 2
  465. #define FF_BUG_XVID_ILACE 4
  466. #define FF_BUG_UMP4 8
  467. #define FF_BUG_NO_PADDING 16
  468. #define FF_BUG_AC_VLC 32
  469. #define FF_BUG_QPEL_CHROMA 64
  470. #define FF_BUG_STD_QPEL 128
  471. #define FF_BUG_QPEL_CHROMA2 256
  472. #define FF_BUG_DIRECT_BLOCKSIZE 512
  473. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  474. /**
  475. * encoding: set by user
  476. * decoding: unused
  477. */
  478. int luma_elim_threshold;
  479. /**
  480. * encoding: set by user
  481. * decoding: unused
  482. */
  483. int chroma_elim_threshold;
  484. /**
  485. * strictly follow the std (MPEG4, ...)
  486. * encoding: set by user
  487. * decoding: unused
  488. */
  489. int strict_std_compliance;
  490. /**
  491. * qscale offset between ip and b frames
  492. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  493. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  494. * encoding: set by user.
  495. * decoding: unused
  496. */
  497. float b_quant_offset;
  498. /**
  499. * error resilience higher values will detect more errors but may missdetect
  500. * some more or less valid parts as errors
  501. * encoding: unused
  502. * decoding: set by user
  503. */
  504. int error_resilience;
  505. #define FF_ER_CAREFULL 1
  506. #define FF_ER_COMPLIANT 2
  507. #define FF_ER_AGGRESSIVE 3
  508. #define FF_ER_VERY_AGGRESSIVE 4
  509. /**
  510. * called at the beginning of each frame to get a buffer for it.
  511. * if pic.reference is set then the frame will be read later by lavc
  512. * encoding: unused
  513. * decoding: set by lavc, user can override
  514. */
  515. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  516. /**
  517. * called to release buffers which where allocated with get_buffer.
  518. * a released buffer can be reused in get_buffer()
  519. * pic.data[*] must be set to NULL
  520. * encoding: unused
  521. * decoding: set by lavc, user can override
  522. */
  523. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  524. /**
  525. * is 1 if the decoded stream contains b frames, 0 otherwise
  526. * encoding: unused
  527. * decoding: set by lavc
  528. */
  529. int has_b_frames;
  530. int block_align; /* used by some WAV based audio codecs */
  531. int parse_only; /* decoding only: if true, only parsing is done
  532. (function avcodec_parse_frame()). The frame
  533. data is returned. Only MPEG codecs support this now. */
  534. /**
  535. * 0-> h263 quant 1-> mpeg quant
  536. * encoding: set by user.
  537. * decoding: unused
  538. */
  539. int mpeg_quant;
  540. /**
  541. * pass1 encoding statistics output buffer
  542. * encoding: set by lavc
  543. * decoding: unused
  544. */
  545. char *stats_out; /* encoding statistics output buffer */
  546. /**
  547. * pass2 encoding statistics input buffer.
  548. * concatenated stuff from stats_out of pass1 should be placed here
  549. * encoding: allocated/set/freed by user
  550. * decoding: unused
  551. */
  552. char *stats_in;
  553. /**
  554. * ratecontrol qmin qmax limiting method
  555. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  556. * encoding: set by user.
  557. * decoding: unused
  558. */
  559. float rc_qsquish;
  560. float rc_qmod_amp;
  561. int rc_qmod_freq;
  562. /**
  563. * ratecontrol override, see RcOverride
  564. * encoding: allocated/set/freed by user.
  565. * decoding: unused
  566. */
  567. RcOverride *rc_override;
  568. int rc_override_count;
  569. /**
  570. * rate control equation
  571. * encoding: set by user
  572. * decoding: unused
  573. */
  574. char *rc_eq;
  575. /**
  576. * maximum bitrate
  577. * encoding: set by user.
  578. * decoding: unused
  579. */
  580. int rc_max_rate;
  581. /**
  582. * minimum bitrate
  583. * encoding: set by user.
  584. * decoding: unused
  585. */
  586. int rc_min_rate;
  587. /**
  588. * decoder bitstream buffer size
  589. * encoding: set by user.
  590. * decoding: unused
  591. */
  592. int rc_buffer_size;
  593. float rc_buffer_aggressivity;
  594. /**
  595. * qscale factor between p and i frames
  596. * encoding: set by user.
  597. * decoding: unused
  598. */
  599. float i_quant_factor;
  600. /**
  601. * qscale offset between p and i frames
  602. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  603. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  604. * encoding: set by user.
  605. * decoding: unused
  606. */
  607. float i_quant_offset;
  608. /**
  609. * initial complexity for pass1 ratecontrol
  610. * encoding: set by user.
  611. * decoding: unused
  612. */
  613. float rc_initial_cplx;
  614. /**
  615. * dct algorithm, see FF_DCT_* below
  616. * encoding: set by user
  617. * decoding: unused
  618. */
  619. int dct_algo;
  620. #define FF_DCT_AUTO 0
  621. #define FF_DCT_FASTINT 1
  622. #define FF_DCT_INT 2
  623. #define FF_DCT_MMX 3
  624. #define FF_DCT_MLIB 4
  625. #define FF_DCT_ALTIVEC 5
  626. /**
  627. * luminance masking (0-> disabled)
  628. * encoding: set by user
  629. * decoding: unused
  630. */
  631. float lumi_masking;
  632. /**
  633. * temporary complexity masking (0-> disabled)
  634. * encoding: set by user
  635. * decoding: unused
  636. */
  637. float temporal_cplx_masking;
  638. /**
  639. * spatial complexity masking (0-> disabled)
  640. * encoding: set by user
  641. * decoding: unused
  642. */
  643. float spatial_cplx_masking;
  644. /**
  645. * p block masking (0-> disabled)
  646. * encoding: set by user
  647. * decoding: unused
  648. */
  649. float p_masking;
  650. /**
  651. * darkness masking (0-> disabled)
  652. * encoding: set by user
  653. * decoding: unused
  654. */
  655. float dark_masking;
  656. /**
  657. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A')
  658. * this is used to workaround some encoder bugs
  659. * encoding: unused
  660. * decoding: set by user, will be converted to upper case by lavc during init
  661. */
  662. int fourcc;
  663. /**
  664. * idct algorithm, see FF_IDCT_* below
  665. * encoding: set by user
  666. * decoding: set by user
  667. */
  668. int idct_algo;
  669. #define FF_IDCT_AUTO 0
  670. #define FF_IDCT_INT 1
  671. #define FF_IDCT_SIMPLE 2
  672. #define FF_IDCT_SIMPLEMMX 3
  673. #define FF_IDCT_LIBMPEG2MMX 4
  674. #define FF_IDCT_PS2 5
  675. #define FF_IDCT_MLIB 6
  676. #define FF_IDCT_ARM 7
  677. #define FF_IDCT_ALTIVEC 8
  678. /**
  679. * slice count
  680. * encoding: set by lavc
  681. * decoding: set by user (or 0)
  682. */
  683. int slice_count;
  684. /**
  685. * slice offsets in the frame in bytes
  686. * encoding: set/allocated by lavc
  687. * decoding: set/allocated by user (or NULL)
  688. */
  689. int *slice_offset;
  690. /**
  691. * error concealment flags
  692. * encoding: unused
  693. * decoding: set by user
  694. */
  695. int error_concealment;
  696. #define FF_EC_GUESS_MVS 1
  697. #define FF_EC_DEBLOCK 2
  698. /**
  699. * dsp_mask could be used to disable unwanted
  700. * CPU features (i.e. MMX, SSE. ...)
  701. */
  702. unsigned dsp_mask;
  703. /**
  704. * bits per sample/pixel from the demuxer (needed for huffyuv)
  705. * encoding: set by lavc
  706. * decoding: set by user
  707. */
  708. int bits_per_sample;
  709. /**
  710. * prediction method (needed for huffyuv)
  711. * encoding: set by user
  712. * decoding: unused
  713. */
  714. int prediction_method;
  715. #define FF_PRED_LEFT 0
  716. #define FF_PRED_PLANE 1
  717. #define FF_PRED_MEDIAN 2
  718. /**
  719. * aspect ratio. (0 if unknown)
  720. * encoding: set by user.
  721. * decoding: set by lavc.
  722. */
  723. float aspect_ratio;
  724. /**
  725. * the picture in the bitstream
  726. * encoding: set by lavc
  727. * decoding: set by lavc
  728. */
  729. AVFrame *coded_frame;
  730. /**
  731. * debug
  732. * encoding: set by user.
  733. * decoding: set by user.
  734. */
  735. int debug;
  736. #define FF_DEBUG_PICT_INFO 1
  737. #define FF_DEBUG_RC 2
  738. #define FF_DEBUG_BITSTREAM 4
  739. #define FF_DEBUG_MB_TYPE 8
  740. #define FF_DEBUG_QP 16
  741. #define FF_DEBUG_MV 32
  742. #define FF_DEBUG_VIS_MV 0x00000040
  743. #define FF_DEBUG_SKIP 0x00000080
  744. #define FF_DEBUG_STARTCODE 0x00000100
  745. #define FF_DEBUG_PTS 0x00000200
  746. /**
  747. * error
  748. * encoding: set by lavc if flags&CODEC_FLAG_PSNR
  749. * decoding: unused
  750. */
  751. uint64_t error[4];
  752. /**
  753. * minimum MB quantizer
  754. * encoding: set by user.
  755. * decoding: unused
  756. */
  757. int mb_qmin;
  758. /**
  759. * maximum MB quantizer
  760. * encoding: set by user.
  761. * decoding: unused
  762. */
  763. int mb_qmax;
  764. /**
  765. * motion estimation compare function
  766. * encoding: set by user.
  767. * decoding: unused
  768. */
  769. int me_cmp;
  770. /**
  771. * subpixel motion estimation compare function
  772. * encoding: set by user.
  773. * decoding: unused
  774. */
  775. int me_sub_cmp;
  776. /**
  777. * macroblock compare function (not supported yet)
  778. * encoding: set by user.
  779. * decoding: unused
  780. */
  781. int mb_cmp;
  782. #define FF_CMP_SAD 0
  783. #define FF_CMP_SSE 1
  784. #define FF_CMP_SATD 2
  785. #define FF_CMP_DCT 3
  786. #define FF_CMP_PSNR 4
  787. #define FF_CMP_BIT 5
  788. #define FF_CMP_RD 6
  789. #define FF_CMP_ZERO 7
  790. #define FF_CMP_CHROMA 256
  791. /**
  792. * ME diamond size & shape
  793. * encoding: set by user.
  794. * decoding: unused
  795. */
  796. int dia_size;
  797. /**
  798. * amount of previous MV predictors (2a+1 x 2a+1 square)
  799. * encoding: set by user.
  800. * decoding: unused
  801. */
  802. int last_predictor_count;
  803. /**
  804. * pre pass for motion estimation
  805. * encoding: set by user.
  806. * decoding: unused
  807. */
  808. int pre_me;
  809. /**
  810. * motion estimation pre pass compare function
  811. * encoding: set by user.
  812. * decoding: unused
  813. */
  814. int me_pre_cmp;
  815. /**
  816. * ME pre pass diamond size & shape
  817. * encoding: set by user.
  818. * decoding: unused
  819. */
  820. int pre_dia_size;
  821. /**
  822. * subpel ME quality
  823. * encoding: set by user.
  824. * decoding: unused
  825. */
  826. int me_subpel_quality;
  827. /**
  828. * callback to negotiate the pixelFormat
  829. * @param fmt is the list of formats which are supported by the codec,
  830. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  831. * the first is allways the native one
  832. * @return the choosen format
  833. * encoding: unused
  834. * decoding: set by user, if not set then the native format will always be choosen
  835. */
  836. enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
  837. } AVCodecContext;
  838. typedef struct AVCodec {
  839. const char *name;
  840. int type;
  841. int id;
  842. int priv_data_size;
  843. int (*init)(AVCodecContext *);
  844. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  845. int (*close)(AVCodecContext *);
  846. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  847. UINT8 *buf, int buf_size);
  848. int capabilities;
  849. struct AVCodec *next;
  850. } AVCodec;
  851. /**
  852. * four components are given, that's all.
  853. * the last component is alpha
  854. */
  855. typedef struct AVPicture {
  856. UINT8 *data[4];
  857. int linesize[4];
  858. } AVPicture;
  859. extern AVCodec ac3_encoder;
  860. extern AVCodec mp2_encoder;
  861. extern AVCodec mp3lame_encoder;
  862. extern AVCodec oggvorbis_encoder;
  863. extern AVCodec mpeg1video_encoder;
  864. extern AVCodec h263_encoder;
  865. extern AVCodec h263p_encoder;
  866. extern AVCodec rv10_encoder;
  867. extern AVCodec mjpeg_encoder;
  868. extern AVCodec mpeg4_encoder;
  869. extern AVCodec msmpeg4v1_encoder;
  870. extern AVCodec msmpeg4v2_encoder;
  871. extern AVCodec msmpeg4v3_encoder;
  872. extern AVCodec wmv1_encoder;
  873. extern AVCodec wmv2_encoder;
  874. extern AVCodec huffyuv_encoder;
  875. extern AVCodec h263_decoder;
  876. extern AVCodec mpeg4_decoder;
  877. extern AVCodec msmpeg4v1_decoder;
  878. extern AVCodec msmpeg4v2_decoder;
  879. extern AVCodec msmpeg4v3_decoder;
  880. extern AVCodec wmv1_decoder;
  881. extern AVCodec wmv2_decoder;
  882. extern AVCodec mpeg_decoder;
  883. extern AVCodec h263i_decoder;
  884. extern AVCodec rv10_decoder;
  885. extern AVCodec svq1_decoder;
  886. extern AVCodec dvvideo_decoder;
  887. extern AVCodec dvaudio_decoder;
  888. extern AVCodec wmav1_decoder;
  889. extern AVCodec wmav2_decoder;
  890. extern AVCodec mjpeg_decoder;
  891. extern AVCodec mjpegb_decoder;
  892. extern AVCodec mp2_decoder;
  893. extern AVCodec mp3_decoder;
  894. extern AVCodec mace3_decoder;
  895. extern AVCodec mace6_decoder;
  896. extern AVCodec huffyuv_decoder;
  897. extern AVCodec oggvorbis_decoder;
  898. extern AVCodec cyuv_decoder;
  899. /* pcm codecs */
  900. #define PCM_CODEC(id, name) \
  901. extern AVCodec name ## _decoder; \
  902. extern AVCodec name ## _encoder
  903. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  904. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  905. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  906. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  907. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  908. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  909. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  910. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  911. /* adpcm codecs */
  912. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  913. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  914. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  915. #undef PCM_CODEC
  916. /* dummy raw video codec */
  917. extern AVCodec rawvideo_codec;
  918. /* the following codecs use external GPL libs */
  919. extern AVCodec ac3_decoder;
  920. /* resample.c */
  921. struct ReSampleContext;
  922. typedef struct ReSampleContext ReSampleContext;
  923. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  924. int output_rate, int input_rate);
  925. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  926. void audio_resample_close(ReSampleContext *s);
  927. /* YUV420 format is assumed ! */
  928. struct ImgReSampleContext;
  929. typedef struct ImgReSampleContext ImgReSampleContext;
  930. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  931. int input_width, int input_height);
  932. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  933. int iwidth, int iheight,
  934. int topBand, int bottomBand,
  935. int leftBand, int rightBand);
  936. void img_resample(ImgReSampleContext *s,
  937. AVPicture *output, AVPicture *input);
  938. void img_resample_close(ImgReSampleContext *s);
  939. int avpicture_fill(AVPicture *picture, UINT8 *ptr,
  940. int pix_fmt, int width, int height);
  941. int avpicture_get_size(int pix_fmt, int width, int height);
  942. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  943. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  944. /* convert among pixel formats */
  945. int img_convert(AVPicture *dst, int dst_pix_fmt,
  946. AVPicture *src, int pix_fmt,
  947. int width, int height);
  948. /* deinterlace a picture */
  949. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  950. int pix_fmt, int width, int height);
  951. /* external high level API */
  952. extern AVCodec *first_avcodec;
  953. /* returns LIBAVCODEC_VERSION_INT constant */
  954. unsigned avcodec_version(void);
  955. /* returns LIBAVCODEC_BUILD constant */
  956. unsigned avcodec_build(void);
  957. void avcodec_init(void);
  958. void avcodec_set_bit_exact(void);
  959. void register_avcodec(AVCodec *format);
  960. AVCodec *avcodec_find_encoder(enum CodecID id);
  961. AVCodec *avcodec_find_encoder_by_name(const char *name);
  962. AVCodec *avcodec_find_decoder(enum CodecID id);
  963. AVCodec *avcodec_find_decoder_by_name(const char *name);
  964. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  965. void avcodec_get_context_defaults(AVCodecContext *s);
  966. AVCodecContext *avcodec_alloc_context(void);
  967. AVFrame *avcodec_alloc_frame(void);
  968. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  969. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  970. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  971. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  972. int *frame_size_ptr,
  973. UINT8 *buf, int buf_size);
  974. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  975. int *got_picture_ptr,
  976. UINT8 *buf, int buf_size);
  977. int avcodec_parse_frame(AVCodecContext *avctx, UINT8 **pdata,
  978. int *data_size_ptr,
  979. UINT8 *buf, int buf_size);
  980. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  981. const short *samples);
  982. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  983. const AVFrame *pict);
  984. int avcodec_close(AVCodecContext *avctx);
  985. void avcodec_register_all(void);
  986. void avcodec_flush_buffers(AVCodecContext *avctx);
  987. typedef struct {
  988. /** options' name with default value*/
  989. const char* name;
  990. /** English text help */
  991. const char* help;
  992. /** type of variable */
  993. int type;
  994. #define FF_CONF_TYPE_BOOL 1 // boolean - true,1,on (or simply presence)
  995. #define FF_CONF_TYPE_DOUBLE 2 // double
  996. #define FF_CONF_TYPE_INT 3 // integer
  997. #define FF_CONF_TYPE_STRING 4 // string (finished with \0)
  998. #define FF_CONF_TYPE_MASK 0x1f // mask for types - upper bits are various flags
  999. #define FF_CONF_TYPE_EXPERT 0x20 // flag for expert option
  1000. #define FF_CONF_TYPE_FLAG (FF_CONF_TYPE_BOOL | 0x40)
  1001. #define FF_CONF_TYPE_RCOVERIDE (FF_CONF_TYPE_STRING | 0x80)
  1002. /** where the parsed value should be stored */
  1003. void* val;
  1004. /** min value (min == max -> no limits) */
  1005. double min;
  1006. /** maximum value for double/int */
  1007. double max;
  1008. /** default boo [0,1]l/double/int value */
  1009. double defval;
  1010. /**
  1011. * default string value (with optional semicolon delimited extra option-list
  1012. * i.e. option1;option2;option3
  1013. * defval might select other then first argument as default
  1014. */
  1015. const char* defstr;
  1016. /** char* list of supported codecs (i.e. ",msmpeg4,h263," NULL - everything */
  1017. const char* supported;
  1018. } avc_config_t;
  1019. void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
  1020. /**
  1021. * Interface for 0.5.0 version
  1022. *
  1023. * do not even think about it's usage for this moment
  1024. */
  1025. typedef struct {
  1026. // compressed size used from given memory buffer
  1027. int size;
  1028. /// I/P/B frame type
  1029. int frame_type;
  1030. } avc_enc_result_t;
  1031. /**
  1032. * Commands
  1033. * order can't be changed - once it was defined
  1034. */
  1035. typedef enum {
  1036. // general commands
  1037. AVC_OPEN_BY_NAME = 0xACA000,
  1038. AVC_OPEN_BY_CODEC_ID,
  1039. AVC_OPEN_BY_FOURCC,
  1040. AVC_CLOSE,
  1041. AVC_FLUSH,
  1042. // pin - struct { uint8_t* src, uint_t src_size }
  1043. // pout - struct { AVPicture* img, consumed_bytes,
  1044. AVC_DECODE,
  1045. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  1046. // pout - uint_t used_from_dest_size
  1047. AVC_ENCODE,
  1048. // query/get video commands
  1049. AVC_GET_VERSION = 0xACB000,
  1050. AVC_GET_WIDTH,
  1051. AVC_GET_HEIGHT,
  1052. AVC_GET_DELAY,
  1053. AVC_GET_QUANT_TABLE,
  1054. // ...
  1055. // query/get audio commands
  1056. AVC_GET_FRAME_SIZE = 0xABC000,
  1057. // maybe define some simple structure which
  1058. // might be passed to the user - but they can't
  1059. // contain any codec specific parts and these
  1060. // calls are usualy necessary only few times
  1061. // set video commands
  1062. AVC_SET_WIDTH = 0xACD000,
  1063. AVC_SET_HEIGHT,
  1064. // set video encoding commands
  1065. AVC_SET_FRAME_RATE = 0xACD800,
  1066. AVC_SET_QUALITY,
  1067. AVC_SET_HURRY_UP,
  1068. // set audio commands
  1069. AVC_SET_SAMPLE_RATE = 0xACE000,
  1070. AVC_SET_CHANNELS,
  1071. } avc_cmd_t;
  1072. /**
  1073. * \param handle allocated private structure by libavcodec
  1074. * for initialization pass NULL - will be returned pout
  1075. * user is supposed to know nothing about its structure
  1076. * \param cmd type of operation to be performed
  1077. * \param pint input parameter
  1078. * \param pout output parameter
  1079. *
  1080. * \returns command status - eventually for query command it might return
  1081. * integer resulting value
  1082. */
  1083. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  1084. /* memory */
  1085. void *av_malloc(unsigned int size);
  1086. void *av_mallocz(unsigned int size);
  1087. void *av_realloc(void *ptr, unsigned int size);
  1088. void av_free(void *ptr);
  1089. char *av_strdup(const char *s);
  1090. void __av_freep(void **ptr);
  1091. #define av_freep(p) __av_freep((void **)(p))
  1092. void *av_fast_realloc(void *ptr, int *size, int min_size);
  1093. /* for static data only */
  1094. /* call av_free_static to release all staticaly allocated tables */
  1095. void av_free_static(void);
  1096. void *__av_mallocz_static(void** location, unsigned int size);
  1097. #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
  1098. #ifdef __cplusplus
  1099. }
  1100. #endif
  1101. #endif /* AVCODEC_H */