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.

1305 lines
36KB

  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 4659
  15. #define LIBAVCODEC_BUILD_STR "4659"
  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. \
  259. /**\
  260. * when decoding, this signal how much the picture must be delayed.\
  261. * extra_delay = repeat_pict / (2*fps)\
  262. * encoding: unused\
  263. * decoding: set by lavc\
  264. */\
  265. int repeat_pict;
  266. #define FF_BUFFER_TYPE_INTERNAL 1
  267. #define FF_BUFFER_TYPE_USER 2 // Direct rendering buffers
  268. #define FF_BUFFER_TYPE_SHARED 4 // input frame for encoding(wont be dealloced)
  269. #define FF_I_TYPE 1 // Intra
  270. #define FF_P_TYPE 2 // Predicted
  271. #define FF_B_TYPE 3 // Bi-dir predicted
  272. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  273. typedef struct AVFrame {
  274. FF_COMMON_FRAME
  275. } AVFrame;
  276. typedef struct AVCodecContext {
  277. /**
  278. * the average bitrate
  279. * encoding: set by user. unused for constant quantizer encoding
  280. * decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  281. */
  282. int bit_rate;
  283. /**
  284. * number of bits the bitstream is allowed to diverge from the reference
  285. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  286. * encoding: set by user. unused for constant quantizer encoding
  287. * decoding: unused
  288. */
  289. int bit_rate_tolerance;
  290. /**
  291. * CODEC_FLAG_*
  292. * encoding: set by user.
  293. * decoding: set by user.
  294. */
  295. int flags;
  296. /**
  297. * some codecs needs additionnal format info. It is stored here
  298. * encoding: set by user.
  299. * decoding: set by lavc. (FIXME is this ok?)
  300. */
  301. int sub_id;
  302. /**
  303. * motion estimation algorithm used for video coding
  304. * encoding: MUST be set by user.
  305. * decoding: unused
  306. */
  307. int me_method;
  308. /**
  309. * some codecs need / can use extra-data like huffman tables
  310. * mjpeg: huffman tables
  311. * rv10: additional flags
  312. * mpeg4: global headers (they can be in the bitstream or here)
  313. * encoding: set/allocated/freed by lavc.
  314. * decoding: set/allocated/freed by user.
  315. */
  316. void *extradata;
  317. int extradata_size;
  318. /* video only */
  319. /**
  320. * frames per sec multiplied by FRAME_RATE_BASE
  321. * for variable fps this is the precission, so if the timestamps
  322. * can be specified in msec precssion then this is 1000*FRAME_RATE_BASE
  323. * encoding: MUST be set by user
  324. * decoding: set by lavc. 0 or the frame_rate if available
  325. */
  326. int frame_rate;
  327. /**
  328. * encoding: MUST be set by user.
  329. * decoding: set by user, some codecs might override / change it during playback
  330. */
  331. int width, height;
  332. #define FF_ASPECT_SQUARE 1
  333. #define FF_ASPECT_4_3_625 2
  334. #define FF_ASPECT_4_3_525 3
  335. #define FF_ASPECT_16_9_625 4
  336. #define FF_ASPECT_16_9_525 5
  337. #define FF_ASPECT_EXTENDED 15
  338. /**
  339. * the number of pictures in a group of pitures, or 0 for intra_only
  340. * encoding: set by user.
  341. * decoding: unused
  342. */
  343. int gop_size;
  344. /**
  345. * pixel format, see PIX_FMT_xxx
  346. * encoding: unused
  347. * decoding: set by lavc.
  348. */
  349. enum PixelFormat pix_fmt;
  350. /**
  351. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  352. * decoder to draw an horizontal band. It improve cache usage. Not
  353. * all codecs can do that. You must check the codec capabilities
  354. * before
  355. * encoding: unused
  356. * decoding: set by user.
  357. */
  358. void (*draw_horiz_band)(struct AVCodecContext *s,
  359. uint8_t **src_ptr, int linesize,
  360. int y, int width, int height);
  361. /* audio only */
  362. int sample_rate; /* samples per sec */
  363. int channels;
  364. int sample_fmt; /* sample format, currenly unused */
  365. /* the following data should not be initialized */
  366. int frame_size; /* in samples, initialized when calling 'init' */
  367. int frame_number; /* audio or video frame number */
  368. int real_pict_num; /* returns the real picture number of
  369. previous encoded frame */
  370. /**
  371. * number of frames the decoded output will be delayed relative to
  372. * the encoded input
  373. * encoding: set by lavc.
  374. * decoding: unused
  375. */
  376. int delay;
  377. /* encoding parameters */
  378. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  379. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  380. /**
  381. * minimum quantizer
  382. * encoding: set by user.
  383. * decoding: unused
  384. */
  385. int qmin;
  386. /**
  387. * maximum quantizer
  388. * encoding: set by user.
  389. * decoding: unused
  390. */
  391. int qmax;
  392. /**
  393. * maximum quantizer difference etween frames
  394. * encoding: set by user.
  395. * decoding: unused
  396. */
  397. int max_qdiff;
  398. /**
  399. * maximum number of b frames between non b frames
  400. * note: the output will be delayed by max_b_frames+1 relative to the input
  401. * encoding: set by user.
  402. * decoding: unused
  403. */
  404. int max_b_frames;
  405. /**
  406. * qscale factor between ip and b frames
  407. * encoding: set by user.
  408. * decoding: unused
  409. */
  410. float b_quant_factor;
  411. /** obsolete FIXME remove */
  412. int rc_strategy;
  413. int b_frame_strategy;
  414. /**
  415. * encoding: unused
  416. * decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  417. */
  418. int hurry_up;
  419. struct AVCodec *codec;
  420. void *priv_data;
  421. /* The following data is for RTP friendly coding */
  422. /* By now only H.263/H.263+/MPEG4 coder honours this */
  423. int rtp_mode; /* 1 for activate RTP friendly-mode */
  424. /* highers numbers represent more error-prone */
  425. /* enviroments, by now just "1" exist */
  426. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  427. /* do it's best to deliver a chunk with size */
  428. /* below rtp_payload_size, the chunk will start */
  429. /* with a start code on some codecs like H.263 */
  430. /* This doesn't take account of any particular */
  431. /* headers inside the transmited RTP payload */
  432. /* The RTP callcack: This function is called */
  433. /* every time the encoder as a packet to send */
  434. /* Depends on the encoder if the data starts */
  435. /* with a Start Code (it should) H.263 does */
  436. void (*rtp_callback)(void *data, int size, int packet_number);
  437. /* statistics, used for 2-pass encoding */
  438. int mv_bits;
  439. int header_bits;
  440. int i_tex_bits;
  441. int p_tex_bits;
  442. int i_count;
  443. int p_count;
  444. int skip_count;
  445. int misc_bits;
  446. /**
  447. * number of bits used for the previously encoded frame
  448. * encoding: set by lavc
  449. * decoding: - for audio - bits_per_sample
  450. */
  451. int frame_bits;
  452. /**
  453. * private data of the user, can be used to carry app specific stuff
  454. * encoding: set by user
  455. * decoding: set by user
  456. */
  457. void *opaque;
  458. char codec_name[32];
  459. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  460. enum CodecID codec_id; /* see CODEC_ID_xxx */
  461. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  462. /**
  463. * workaround bugs in encoders which sometimes cannot be detected automatically
  464. * encoding: unused
  465. * decoding: set by user
  466. */
  467. int workaround_bugs;
  468. #define FF_BUG_AUTODETECT 1 //autodetection
  469. #define FF_BUG_OLD_MSMPEG4 2
  470. #define FF_BUG_XVID_ILACE 4
  471. #define FF_BUG_UMP4 8
  472. #define FF_BUG_NO_PADDING 16
  473. #define FF_BUG_AC_VLC 32
  474. #define FF_BUG_QPEL_CHROMA 64
  475. #define FF_BUG_STD_QPEL 128
  476. #define FF_BUG_QPEL_CHROMA2 256
  477. #define FF_BUG_DIRECT_BLOCKSIZE 512
  478. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  479. /**
  480. * encoding: set by user
  481. * decoding: unused
  482. */
  483. int luma_elim_threshold;
  484. /**
  485. * encoding: set by user
  486. * decoding: unused
  487. */
  488. int chroma_elim_threshold;
  489. /**
  490. * strictly follow the std (MPEG4, ...)
  491. * encoding: set by user
  492. * decoding: unused
  493. */
  494. int strict_std_compliance;
  495. /**
  496. * qscale offset between ip and b frames
  497. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  498. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  499. * encoding: set by user.
  500. * decoding: unused
  501. */
  502. float b_quant_offset;
  503. /**
  504. * error resilience higher values will detect more errors but may missdetect
  505. * some more or less valid parts as errors
  506. * encoding: unused
  507. * decoding: set by user
  508. */
  509. int error_resilience;
  510. #define FF_ER_CAREFULL 1
  511. #define FF_ER_COMPLIANT 2
  512. #define FF_ER_AGGRESSIVE 3
  513. #define FF_ER_VERY_AGGRESSIVE 4
  514. /**
  515. * called at the beginning of each frame to get a buffer for it.
  516. * if pic.reference is set then the frame will be read later by lavc
  517. * encoding: unused
  518. * decoding: set by lavc, user can override
  519. */
  520. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  521. /**
  522. * called to release buffers which where allocated with get_buffer.
  523. * a released buffer can be reused in get_buffer()
  524. * pic.data[*] must be set to NULL
  525. * encoding: unused
  526. * decoding: set by lavc, user can override
  527. */
  528. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  529. /**
  530. * is 1 if the decoded stream contains b frames, 0 otherwise
  531. * encoding: unused
  532. * decoding: set by lavc
  533. */
  534. int has_b_frames;
  535. int block_align; /* used by some WAV based audio codecs */
  536. int parse_only; /* decoding only: if true, only parsing is done
  537. (function avcodec_parse_frame()). The frame
  538. data is returned. Only MPEG codecs support this now. */
  539. /**
  540. * 0-> h263 quant 1-> mpeg quant
  541. * encoding: set by user.
  542. * decoding: unused
  543. */
  544. int mpeg_quant;
  545. /**
  546. * pass1 encoding statistics output buffer
  547. * encoding: set by lavc
  548. * decoding: unused
  549. */
  550. char *stats_out; /* encoding statistics output buffer */
  551. /**
  552. * pass2 encoding statistics input buffer.
  553. * concatenated stuff from stats_out of pass1 should be placed here
  554. * encoding: allocated/set/freed by user
  555. * decoding: unused
  556. */
  557. char *stats_in;
  558. /**
  559. * ratecontrol qmin qmax limiting method
  560. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  561. * encoding: set by user.
  562. * decoding: unused
  563. */
  564. float rc_qsquish;
  565. float rc_qmod_amp;
  566. int rc_qmod_freq;
  567. /**
  568. * ratecontrol override, see RcOverride
  569. * encoding: allocated/set/freed by user.
  570. * decoding: unused
  571. */
  572. RcOverride *rc_override;
  573. int rc_override_count;
  574. /**
  575. * rate control equation
  576. * encoding: set by user
  577. * decoding: unused
  578. */
  579. char *rc_eq;
  580. /**
  581. * maximum bitrate
  582. * encoding: set by user.
  583. * decoding: unused
  584. */
  585. int rc_max_rate;
  586. /**
  587. * minimum bitrate
  588. * encoding: set by user.
  589. * decoding: unused
  590. */
  591. int rc_min_rate;
  592. /**
  593. * decoder bitstream buffer size
  594. * encoding: set by user.
  595. * decoding: unused
  596. */
  597. int rc_buffer_size;
  598. float rc_buffer_aggressivity;
  599. /**
  600. * qscale factor between p and i frames
  601. * encoding: set by user.
  602. * decoding: unused
  603. */
  604. float i_quant_factor;
  605. /**
  606. * qscale offset between p and i frames
  607. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  608. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  609. * encoding: set by user.
  610. * decoding: unused
  611. */
  612. float i_quant_offset;
  613. /**
  614. * initial complexity for pass1 ratecontrol
  615. * encoding: set by user.
  616. * decoding: unused
  617. */
  618. float rc_initial_cplx;
  619. /**
  620. * dct algorithm, see FF_DCT_* below
  621. * encoding: set by user
  622. * decoding: unused
  623. */
  624. int dct_algo;
  625. #define FF_DCT_AUTO 0
  626. #define FF_DCT_FASTINT 1
  627. #define FF_DCT_INT 2
  628. #define FF_DCT_MMX 3
  629. #define FF_DCT_MLIB 4
  630. #define FF_DCT_ALTIVEC 5
  631. /**
  632. * luminance masking (0-> disabled)
  633. * encoding: set by user
  634. * decoding: unused
  635. */
  636. float lumi_masking;
  637. /**
  638. * temporary complexity masking (0-> disabled)
  639. * encoding: set by user
  640. * decoding: unused
  641. */
  642. float temporal_cplx_masking;
  643. /**
  644. * spatial complexity masking (0-> disabled)
  645. * encoding: set by user
  646. * decoding: unused
  647. */
  648. float spatial_cplx_masking;
  649. /**
  650. * p block masking (0-> disabled)
  651. * encoding: set by user
  652. * decoding: unused
  653. */
  654. float p_masking;
  655. /**
  656. * darkness masking (0-> disabled)
  657. * encoding: set by user
  658. * decoding: unused
  659. */
  660. float dark_masking;
  661. /**
  662. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A')
  663. * this is used to workaround some encoder bugs
  664. * encoding: unused
  665. * decoding: set by user, will be converted to upper case by lavc during init
  666. */
  667. int fourcc;
  668. /**
  669. * idct algorithm, see FF_IDCT_* below
  670. * encoding: set by user
  671. * decoding: set by user
  672. */
  673. int idct_algo;
  674. #define FF_IDCT_AUTO 0
  675. #define FF_IDCT_INT 1
  676. #define FF_IDCT_SIMPLE 2
  677. #define FF_IDCT_SIMPLEMMX 3
  678. #define FF_IDCT_LIBMPEG2MMX 4
  679. #define FF_IDCT_PS2 5
  680. #define FF_IDCT_MLIB 6
  681. #define FF_IDCT_ARM 7
  682. #define FF_IDCT_ALTIVEC 8
  683. /**
  684. * slice count
  685. * encoding: set by lavc
  686. * decoding: set by user (or 0)
  687. */
  688. int slice_count;
  689. /**
  690. * slice offsets in the frame in bytes
  691. * encoding: set/allocated by lavc
  692. * decoding: set/allocated by user (or NULL)
  693. */
  694. int *slice_offset;
  695. /**
  696. * error concealment flags
  697. * encoding: unused
  698. * decoding: set by user
  699. */
  700. int error_concealment;
  701. #define FF_EC_GUESS_MVS 1
  702. #define FF_EC_DEBLOCK 2
  703. /**
  704. * dsp_mask could be used to disable unwanted
  705. * CPU features (i.e. MMX, SSE. ...)
  706. */
  707. unsigned dsp_mask;
  708. /**
  709. * bits per sample/pixel from the demuxer (needed for huffyuv)
  710. * encoding: set by lavc
  711. * decoding: set by user
  712. */
  713. int bits_per_sample;
  714. /**
  715. * prediction method (needed for huffyuv)
  716. * encoding: set by user
  717. * decoding: unused
  718. */
  719. int prediction_method;
  720. #define FF_PRED_LEFT 0
  721. #define FF_PRED_PLANE 1
  722. #define FF_PRED_MEDIAN 2
  723. /**
  724. * aspect ratio. (0 if unknown)
  725. * encoding: set by user.
  726. * decoding: set by lavc.
  727. */
  728. float aspect_ratio;
  729. /**
  730. * the picture in the bitstream
  731. * encoding: set by lavc
  732. * decoding: set by lavc
  733. */
  734. AVFrame *coded_frame;
  735. /**
  736. * debug
  737. * encoding: set by user.
  738. * decoding: set by user.
  739. */
  740. int debug;
  741. #define FF_DEBUG_PICT_INFO 1
  742. #define FF_DEBUG_RC 2
  743. #define FF_DEBUG_BITSTREAM 4
  744. #define FF_DEBUG_MB_TYPE 8
  745. #define FF_DEBUG_QP 16
  746. #define FF_DEBUG_MV 32
  747. #define FF_DEBUG_VIS_MV 0x00000040
  748. #define FF_DEBUG_SKIP 0x00000080
  749. #define FF_DEBUG_STARTCODE 0x00000100
  750. #define FF_DEBUG_PTS 0x00000200
  751. /**
  752. * error
  753. * encoding: set by lavc if flags&CODEC_FLAG_PSNR
  754. * decoding: unused
  755. */
  756. uint64_t error[4];
  757. /**
  758. * minimum MB quantizer
  759. * encoding: set by user.
  760. * decoding: unused
  761. */
  762. int mb_qmin;
  763. /**
  764. * maximum MB quantizer
  765. * encoding: set by user.
  766. * decoding: unused
  767. */
  768. int mb_qmax;
  769. /**
  770. * motion estimation compare function
  771. * encoding: set by user.
  772. * decoding: unused
  773. */
  774. int me_cmp;
  775. /**
  776. * subpixel motion estimation compare function
  777. * encoding: set by user.
  778. * decoding: unused
  779. */
  780. int me_sub_cmp;
  781. /**
  782. * macroblock compare function (not supported yet)
  783. * encoding: set by user.
  784. * decoding: unused
  785. */
  786. int mb_cmp;
  787. #define FF_CMP_SAD 0
  788. #define FF_CMP_SSE 1
  789. #define FF_CMP_SATD 2
  790. #define FF_CMP_DCT 3
  791. #define FF_CMP_PSNR 4
  792. #define FF_CMP_BIT 5
  793. #define FF_CMP_RD 6
  794. #define FF_CMP_ZERO 7
  795. #define FF_CMP_CHROMA 256
  796. /**
  797. * ME diamond size & shape
  798. * encoding: set by user.
  799. * decoding: unused
  800. */
  801. int dia_size;
  802. /**
  803. * amount of previous MV predictors (2a+1 x 2a+1 square)
  804. * encoding: set by user.
  805. * decoding: unused
  806. */
  807. int last_predictor_count;
  808. /**
  809. * pre pass for motion estimation
  810. * encoding: set by user.
  811. * decoding: unused
  812. */
  813. int pre_me;
  814. /**
  815. * motion estimation pre pass compare function
  816. * encoding: set by user.
  817. * decoding: unused
  818. */
  819. int me_pre_cmp;
  820. /**
  821. * ME pre pass diamond size & shape
  822. * encoding: set by user.
  823. * decoding: unused
  824. */
  825. int pre_dia_size;
  826. /**
  827. * subpel ME quality
  828. * encoding: set by user.
  829. * decoding: unused
  830. */
  831. int me_subpel_quality;
  832. /**
  833. * callback to negotiate the pixelFormat
  834. * @param fmt is the list of formats which are supported by the codec,
  835. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  836. * the first is allways the native one
  837. * @return the choosen format
  838. * encoding: unused
  839. * decoding: set by user, if not set then the native format will always be choosen
  840. */
  841. enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
  842. /**
  843. * DTG active format information (additionnal aspect ratio
  844. * information only used in DVB MPEG2 transport streams). 0 if
  845. * not set.
  846. *
  847. * encoding: unused.
  848. * decoding: set by decoder
  849. */
  850. int dtg_active_format;
  851. #define FF_DTG_AFD_SAME 8
  852. #define FF_DTG_AFD_4_3 9
  853. #define FF_DTG_AFD_16_9 10
  854. #define FF_DTG_AFD_14_9 11
  855. #define FF_DTG_AFD_4_3_SP_14_9 13
  856. #define FF_DTG_AFD_16_9_SP_14_9 14
  857. #define FF_DTG_AFD_SP_4_3 15
  858. int me_range;
  859. /**
  860. * Maximum motion estimation search range in subpel units.
  861. * if 0 then no limit
  862. *
  863. * encoding: set by user.
  864. * decoding: unused.
  865. */
  866. } AVCodecContext;
  867. //void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
  868. typedef struct AVOption {
  869. /** options' name */
  870. const char *name; /* if name is NULL, it indicates a link to next */
  871. /** short English text help */
  872. const char *help;
  873. /** offset to context structure where the parsed value should be stored */
  874. int offset;
  875. /** options' type */
  876. int type;
  877. #define FF_OPT_TYPE_BOOL 1 // boolean - true,1,on (or simply presence)
  878. #define FF_OPT_TYPE_DOUBLE 2 // double
  879. #define FF_OPT_TYPE_INT 3 // integer
  880. #define FF_OPT_TYPE_STRING 4 // string (finished with \0)
  881. #define FF_OPT_TYPE_MASK 0x1f // mask for types - upper bits are various flags
  882. //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
  883. #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
  884. #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
  885. /** min value (min == max -> no limits) */
  886. double min;
  887. /** maximum value for double/int */
  888. double max;
  889. /** default boo [0,1]l/double/int value */
  890. double defval;
  891. /**
  892. * default string value (with optional semicolon delimited extra option-list
  893. * i.e. option1;option2;option3
  894. * defval might select other then first argument as default
  895. */
  896. const char *defstr;
  897. const struct AVOption *sub; /* used when name is NULL */
  898. /* when it's NULL return to previous level (or finish reading) */
  899. #define FF_OPT_MAX_DEPTH 10
  900. } AVOption;
  901. typedef struct AVCodec {
  902. const char *name;
  903. int type;
  904. int id;
  905. int priv_data_size;
  906. int (*init)(AVCodecContext *);
  907. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  908. int (*close)(AVCodecContext *);
  909. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  910. uint8_t *buf, int buf_size);
  911. int capabilities;
  912. const AVOption *options;
  913. struct AVCodec *next;
  914. } AVCodec;
  915. /**
  916. * four components are given, that's all.
  917. * the last component is alpha
  918. */
  919. typedef struct AVPicture {
  920. uint8_t *data[4];
  921. int linesize[4];
  922. } AVPicture;
  923. extern AVCodec ac3_encoder;
  924. extern AVCodec mp2_encoder;
  925. extern AVCodec mp3lame_encoder;
  926. extern AVCodec oggvorbis_encoder;
  927. extern AVCodec mpeg1video_encoder;
  928. extern AVCodec h263_encoder;
  929. extern AVCodec h263p_encoder;
  930. extern AVCodec rv10_encoder;
  931. extern AVCodec mjpeg_encoder;
  932. extern AVCodec mpeg4_encoder;
  933. extern AVCodec msmpeg4v1_encoder;
  934. extern AVCodec msmpeg4v2_encoder;
  935. extern AVCodec msmpeg4v3_encoder;
  936. extern AVCodec wmv1_encoder;
  937. extern AVCodec wmv2_encoder;
  938. extern AVCodec huffyuv_encoder;
  939. extern AVCodec h263_decoder;
  940. extern AVCodec mpeg4_decoder;
  941. extern AVCodec msmpeg4v1_decoder;
  942. extern AVCodec msmpeg4v2_decoder;
  943. extern AVCodec msmpeg4v3_decoder;
  944. extern AVCodec wmv1_decoder;
  945. extern AVCodec wmv2_decoder;
  946. extern AVCodec mpeg_decoder;
  947. extern AVCodec h263i_decoder;
  948. extern AVCodec rv10_decoder;
  949. extern AVCodec svq1_decoder;
  950. extern AVCodec dvvideo_decoder;
  951. extern AVCodec dvaudio_decoder;
  952. extern AVCodec wmav1_decoder;
  953. extern AVCodec wmav2_decoder;
  954. extern AVCodec mjpeg_decoder;
  955. extern AVCodec mjpegb_decoder;
  956. extern AVCodec mp2_decoder;
  957. extern AVCodec mp3_decoder;
  958. extern AVCodec mace3_decoder;
  959. extern AVCodec mace6_decoder;
  960. extern AVCodec huffyuv_decoder;
  961. extern AVCodec oggvorbis_decoder;
  962. extern AVCodec cyuv_decoder;
  963. /* pcm codecs */
  964. #define PCM_CODEC(id, name) \
  965. extern AVCodec name ## _decoder; \
  966. extern AVCodec name ## _encoder
  967. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  968. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  969. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  970. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  971. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  972. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  973. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  974. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  975. /* adpcm codecs */
  976. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  977. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  978. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  979. #undef PCM_CODEC
  980. /* dummy raw video codec */
  981. extern AVCodec rawvideo_codec;
  982. /* the following codecs use external GPL libs */
  983. extern AVCodec ac3_decoder;
  984. /* resample.c */
  985. struct ReSampleContext;
  986. typedef struct ReSampleContext ReSampleContext;
  987. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  988. int output_rate, int input_rate);
  989. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  990. void audio_resample_close(ReSampleContext *s);
  991. /* YUV420 format is assumed ! */
  992. struct ImgReSampleContext;
  993. typedef struct ImgReSampleContext ImgReSampleContext;
  994. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  995. int input_width, int input_height);
  996. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  997. int iwidth, int iheight,
  998. int topBand, int bottomBand,
  999. int leftBand, int rightBand);
  1000. void img_resample(ImgReSampleContext *s,
  1001. AVPicture *output, AVPicture *input);
  1002. void img_resample_close(ImgReSampleContext *s);
  1003. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  1004. int pix_fmt, int width, int height);
  1005. int avpicture_get_size(int pix_fmt, int width, int height);
  1006. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  1007. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  1008. /* convert among pixel formats */
  1009. int img_convert(AVPicture *dst, int dst_pix_fmt,
  1010. AVPicture *src, int pix_fmt,
  1011. int width, int height);
  1012. /* deinterlace a picture */
  1013. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  1014. int pix_fmt, int width, int height);
  1015. /* external high level API */
  1016. extern AVCodec *first_avcodec;
  1017. /* returns LIBAVCODEC_VERSION_INT constant */
  1018. unsigned avcodec_version(void);
  1019. /* returns LIBAVCODEC_BUILD constant */
  1020. unsigned avcodec_build(void);
  1021. void avcodec_init(void);
  1022. void avcodec_set_bit_exact(void);
  1023. void register_avcodec(AVCodec *format);
  1024. AVCodec *avcodec_find_encoder(enum CodecID id);
  1025. AVCodec *avcodec_find_encoder_by_name(const char *name);
  1026. AVCodec *avcodec_find_decoder(enum CodecID id);
  1027. AVCodec *avcodec_find_decoder_by_name(const char *name);
  1028. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  1029. void avcodec_get_context_defaults(AVCodecContext *s);
  1030. AVCodecContext *avcodec_alloc_context(void);
  1031. AVFrame *avcodec_alloc_frame(void);
  1032. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  1033. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  1034. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  1035. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  1036. int *frame_size_ptr,
  1037. uint8_t *buf, int buf_size);
  1038. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  1039. int *got_picture_ptr,
  1040. uint8_t *buf, int buf_size);
  1041. int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
  1042. int *data_size_ptr,
  1043. uint8_t *buf, int buf_size);
  1044. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1045. const short *samples);
  1046. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1047. const AVFrame *pict);
  1048. int avcodec_close(AVCodecContext *avctx);
  1049. void avcodec_register_all(void);
  1050. void avcodec_flush_buffers(AVCodecContext *avctx);
  1051. /**
  1052. * Interface for 0.5.0 version
  1053. *
  1054. * do not even think about it's usage for this moment
  1055. */
  1056. typedef struct {
  1057. // compressed size used from given memory buffer
  1058. int size;
  1059. /// I/P/B frame type
  1060. int frame_type;
  1061. } avc_enc_result_t;
  1062. /**
  1063. * Commands
  1064. * order can't be changed - once it was defined
  1065. */
  1066. typedef enum {
  1067. // general commands
  1068. AVC_OPEN_BY_NAME = 0xACA000,
  1069. AVC_OPEN_BY_CODEC_ID,
  1070. AVC_OPEN_BY_FOURCC,
  1071. AVC_CLOSE,
  1072. AVC_FLUSH,
  1073. // pin - struct { uint8_t* src, uint_t src_size }
  1074. // pout - struct { AVPicture* img, consumed_bytes,
  1075. AVC_DECODE,
  1076. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  1077. // pout - uint_t used_from_dest_size
  1078. AVC_ENCODE,
  1079. // query/get video commands
  1080. AVC_GET_VERSION = 0xACB000,
  1081. AVC_GET_WIDTH,
  1082. AVC_GET_HEIGHT,
  1083. AVC_GET_DELAY,
  1084. AVC_GET_QUANT_TABLE,
  1085. // ...
  1086. // query/get audio commands
  1087. AVC_GET_FRAME_SIZE = 0xABC000,
  1088. // maybe define some simple structure which
  1089. // might be passed to the user - but they can't
  1090. // contain any codec specific parts and these
  1091. // calls are usualy necessary only few times
  1092. // set video commands
  1093. AVC_SET_WIDTH = 0xACD000,
  1094. AVC_SET_HEIGHT,
  1095. // set video encoding commands
  1096. AVC_SET_FRAME_RATE = 0xACD800,
  1097. AVC_SET_QUALITY,
  1098. AVC_SET_HURRY_UP,
  1099. // set audio commands
  1100. AVC_SET_SAMPLE_RATE = 0xACE000,
  1101. AVC_SET_CHANNELS,
  1102. } avc_cmd_t;
  1103. /**
  1104. * \param handle allocated private structure by libavcodec
  1105. * for initialization pass NULL - will be returned pout
  1106. * user is supposed to know nothing about its structure
  1107. * \param cmd type of operation to be performed
  1108. * \param pint input parameter
  1109. * \param pout output parameter
  1110. *
  1111. * \returns command status - eventually for query command it might return
  1112. * integer resulting value
  1113. */
  1114. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  1115. /* memory */
  1116. void *av_malloc(unsigned int size);
  1117. void *av_mallocz(unsigned int size);
  1118. void *av_realloc(void *ptr, unsigned int size);
  1119. void av_free(void *ptr);
  1120. char *av_strdup(const char *s);
  1121. void __av_freep(void **ptr);
  1122. #define av_freep(p) __av_freep((void **)(p))
  1123. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
  1124. /* for static data only */
  1125. /* call av_free_static to release all staticaly allocated tables */
  1126. void av_free_static(void);
  1127. void *__av_mallocz_static(void** location, unsigned int size);
  1128. #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
  1129. #ifdef __cplusplus
  1130. }
  1131. #endif
  1132. #endif /* AVCODEC_H */