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.

1304 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 4660
  15. #define LIBAVCODEC_BUILD_STR "4660"
  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. #define CODEC_FLAG_BITEXACT 0x00800000 /* use only bitexact stuff (except (i)dct) */
  142. /* codec capabilities */
  143. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 /* decoder can use draw_horiz_band callback */
  144. #define CODEC_CAP_DR1 0x0002 /* direct rendering method 1 */
  145. /* if 'parse_only' field is true, then avcodec_parse_frame() can be
  146. used */
  147. #define CODEC_CAP_PARSE_ONLY 0x0004
  148. #define CODEC_CAP_TRUNCATED 0x0008
  149. #define FRAME_RATE_BASE 10010
  150. #define FF_COMMON_FRAME \
  151. uint8_t *data[4];\
  152. int linesize[4];\
  153. /**\
  154. * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
  155. * this isnt used by lavc unless the default get/release_buffer() is used\
  156. * encoding: \
  157. * decoding: \
  158. */\
  159. uint8_t *base[4];\
  160. /**\
  161. * 1 -> keyframe, 0-> not\
  162. * encoding: set by lavc\
  163. * decoding: set by lavc\
  164. */\
  165. int key_frame;\
  166. \
  167. /**\
  168. * picture type of the frame, see ?_TYPE below\
  169. * encoding: set by lavc for coded_picture (and set by user for input)\
  170. * decoding: set by lavc\
  171. */\
  172. int pict_type;\
  173. \
  174. /**\
  175. * presentation timestamp in micro seconds (time when frame should be shown to user)\
  176. * if 0 then the frame_rate will be used as reference\
  177. * encoding: MUST be set by user\
  178. * decoding: set by lavc\
  179. */\
  180. long long int pts;\
  181. \
  182. /**\
  183. * picture number in bitstream order.\
  184. * encoding: set by\
  185. * decoding: set by lavc\
  186. */\
  187. int coded_picture_number;\
  188. /**\
  189. * encoding: set by\
  190. * decoding: set by lavc\
  191. * picture number in display order.\
  192. */\
  193. int display_picture_number;\
  194. \
  195. /**\
  196. * quality (between 1 (good) and 31 (bad)) \
  197. * encoding: set by lavc for coded_picture (and set by user for input)\
  198. * decoding: set by lavc\
  199. */\
  200. float quality; \
  201. \
  202. /**\
  203. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  204. * set to something large if the buffer has not been used yet \
  205. * encoding: unused\
  206. * decoding: MUST be set by get_buffer()\
  207. */\
  208. int age;\
  209. \
  210. /**\
  211. * is this picture used as reference\
  212. * encoding: unused\
  213. * decoding: set by lavc (before get_buffer() call))\
  214. */\
  215. int reference;\
  216. \
  217. /**\
  218. * QP table\
  219. * encoding: unused\
  220. * decoding: set by lavc\
  221. */\
  222. int8_t *qscale_table;\
  223. /**\
  224. * QP store stride\
  225. * encoding: unused\
  226. * decoding: set by lavc\
  227. */\
  228. int qstride;\
  229. \
  230. /**\
  231. * mbskip_table[mb]>=1 if MB didnt change\
  232. * stride= mb_width = (width+15)>>4\
  233. * encoding: unused\
  234. * decoding: set by lavc\
  235. */\
  236. uint8_t *mbskip_table;\
  237. \
  238. /**\
  239. * for some private data of the user\
  240. * encoding: unused\
  241. * decoding: set by user\
  242. */\
  243. void *opaque;\
  244. \
  245. /**\
  246. * error\
  247. * encoding: set by lavc if flags&CODEC_FLAG_PSNR\
  248. * decoding: unused\
  249. */\
  250. uint64_t error[4];\
  251. \
  252. /**\
  253. * type of the buffer (to keep track of who has to dealloc data[*])\
  254. * encoding: set by the one who allocs it\
  255. * decoding: set by the one who allocs it\
  256. * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
  257. */\
  258. int type;\
  259. \
  260. /**\
  261. * when decoding, this signal how much the picture must be delayed.\
  262. * extra_delay = repeat_pict / (2*fps)\
  263. * encoding: unused\
  264. * decoding: set by lavc\
  265. */\
  266. int repeat_pict;
  267. #define FF_BUFFER_TYPE_INTERNAL 1
  268. #define FF_BUFFER_TYPE_USER 2 // Direct rendering buffers
  269. #define FF_BUFFER_TYPE_SHARED 4 // input frame for encoding(wont be dealloced)
  270. #define FF_I_TYPE 1 // Intra
  271. #define FF_P_TYPE 2 // Predicted
  272. #define FF_B_TYPE 3 // Bi-dir predicted
  273. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  274. typedef struct AVFrame {
  275. FF_COMMON_FRAME
  276. } AVFrame;
  277. typedef struct AVCodecContext {
  278. /**
  279. * the average bitrate
  280. * encoding: set by user. unused for constant quantizer encoding
  281. * decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  282. */
  283. int bit_rate;
  284. /**
  285. * number of bits the bitstream is allowed to diverge from the reference
  286. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  287. * encoding: set by user. unused for constant quantizer encoding
  288. * decoding: unused
  289. */
  290. int bit_rate_tolerance;
  291. /**
  292. * CODEC_FLAG_*
  293. * encoding: set by user.
  294. * decoding: set by user.
  295. */
  296. int flags;
  297. /**
  298. * some codecs needs additionnal format info. It is stored here
  299. * encoding: set by user.
  300. * decoding: set by lavc. (FIXME is this ok?)
  301. */
  302. int sub_id;
  303. /**
  304. * motion estimation algorithm used for video coding
  305. * encoding: MUST be set by user.
  306. * decoding: unused
  307. */
  308. int me_method;
  309. /**
  310. * some codecs need / can use extra-data like huffman tables
  311. * mjpeg: huffman tables
  312. * rv10: additional flags
  313. * mpeg4: global headers (they can be in the bitstream or here)
  314. * encoding: set/allocated/freed by lavc.
  315. * decoding: set/allocated/freed by user.
  316. */
  317. void *extradata;
  318. int extradata_size;
  319. /* video only */
  320. /**
  321. * frames per sec multiplied by FRAME_RATE_BASE
  322. * for variable fps this is the precission, so if the timestamps
  323. * can be specified in msec precssion then this is 1000*FRAME_RATE_BASE
  324. * encoding: MUST be set by user
  325. * decoding: set by lavc. 0 or the frame_rate if available
  326. */
  327. int frame_rate;
  328. /**
  329. * encoding: MUST be set by user.
  330. * decoding: set by user, some codecs might override / change it during playback
  331. */
  332. int width, height;
  333. #define FF_ASPECT_SQUARE 1
  334. #define FF_ASPECT_4_3_625 2
  335. #define FF_ASPECT_4_3_525 3
  336. #define FF_ASPECT_16_9_625 4
  337. #define FF_ASPECT_16_9_525 5
  338. #define FF_ASPECT_EXTENDED 15
  339. /**
  340. * the number of pictures in a group of pitures, or 0 for intra_only
  341. * encoding: set by user.
  342. * decoding: unused
  343. */
  344. int gop_size;
  345. /**
  346. * pixel format, see PIX_FMT_xxx
  347. * encoding: unused
  348. * decoding: set by lavc.
  349. */
  350. enum PixelFormat pix_fmt;
  351. /**
  352. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  353. * decoder to draw an horizontal band. It improve cache usage. Not
  354. * all codecs can do that. You must check the codec capabilities
  355. * before
  356. * encoding: unused
  357. * decoding: set by user.
  358. */
  359. void (*draw_horiz_band)(struct AVCodecContext *s,
  360. uint8_t **src_ptr, int linesize,
  361. int y, int width, int height);
  362. /* audio only */
  363. int sample_rate; /* samples per sec */
  364. int channels;
  365. int sample_fmt; /* sample format, currenly unused */
  366. /* the following data should not be initialized */
  367. int frame_size; /* in samples, initialized when calling 'init' */
  368. int frame_number; /* audio or video frame number */
  369. int real_pict_num; /* returns the real picture number of
  370. previous encoded frame */
  371. /**
  372. * number of frames the decoded output will be delayed relative to
  373. * the encoded input
  374. * encoding: set by lavc.
  375. * decoding: unused
  376. */
  377. int delay;
  378. /* encoding parameters */
  379. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  380. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  381. /**
  382. * minimum quantizer
  383. * encoding: set by user.
  384. * decoding: unused
  385. */
  386. int qmin;
  387. /**
  388. * maximum quantizer
  389. * encoding: set by user.
  390. * decoding: unused
  391. */
  392. int qmax;
  393. /**
  394. * maximum quantizer difference etween frames
  395. * encoding: set by user.
  396. * decoding: unused
  397. */
  398. int max_qdiff;
  399. /**
  400. * maximum number of b frames between non b frames
  401. * note: the output will be delayed by max_b_frames+1 relative to the input
  402. * encoding: set by user.
  403. * decoding: unused
  404. */
  405. int max_b_frames;
  406. /**
  407. * qscale factor between ip and b frames
  408. * encoding: set by user.
  409. * decoding: unused
  410. */
  411. float b_quant_factor;
  412. /** obsolete FIXME remove */
  413. int rc_strategy;
  414. int b_frame_strategy;
  415. /**
  416. * encoding: unused
  417. * decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  418. */
  419. int hurry_up;
  420. struct AVCodec *codec;
  421. void *priv_data;
  422. /* The following data is for RTP friendly coding */
  423. /* By now only H.263/H.263+/MPEG4 coder honours this */
  424. int rtp_mode; /* 1 for activate RTP friendly-mode */
  425. /* highers numbers represent more error-prone */
  426. /* enviroments, by now just "1" exist */
  427. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  428. /* do it's best to deliver a chunk with size */
  429. /* below rtp_payload_size, the chunk will start */
  430. /* with a start code on some codecs like H.263 */
  431. /* This doesn't take account of any particular */
  432. /* headers inside the transmited RTP payload */
  433. /* The RTP callcack: This function is called */
  434. /* every time the encoder as a packet to send */
  435. /* Depends on the encoder if the data starts */
  436. /* with a Start Code (it should) H.263 does */
  437. void (*rtp_callback)(void *data, int size, int packet_number);
  438. /* statistics, used for 2-pass encoding */
  439. int mv_bits;
  440. int header_bits;
  441. int i_tex_bits;
  442. int p_tex_bits;
  443. int i_count;
  444. int p_count;
  445. int skip_count;
  446. int misc_bits;
  447. /**
  448. * number of bits used for the previously encoded frame
  449. * encoding: set by lavc
  450. * decoding: - for audio - bits_per_sample
  451. */
  452. int frame_bits;
  453. /**
  454. * private data of the user, can be used to carry app specific stuff
  455. * encoding: set by user
  456. * decoding: set by user
  457. */
  458. void *opaque;
  459. char codec_name[32];
  460. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  461. enum CodecID codec_id; /* see CODEC_ID_xxx */
  462. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  463. /**
  464. * workaround bugs in encoders which sometimes cannot be detected automatically
  465. * encoding: unused
  466. * decoding: set by user
  467. */
  468. int workaround_bugs;
  469. #define FF_BUG_AUTODETECT 1 //autodetection
  470. #define FF_BUG_OLD_MSMPEG4 2
  471. #define FF_BUG_XVID_ILACE 4
  472. #define FF_BUG_UMP4 8
  473. #define FF_BUG_NO_PADDING 16
  474. #define FF_BUG_AC_VLC 32
  475. #define FF_BUG_QPEL_CHROMA 64
  476. #define FF_BUG_STD_QPEL 128
  477. #define FF_BUG_QPEL_CHROMA2 256
  478. #define FF_BUG_DIRECT_BLOCKSIZE 512
  479. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  480. /**
  481. * encoding: set by user
  482. * decoding: unused
  483. */
  484. int luma_elim_threshold;
  485. /**
  486. * encoding: set by user
  487. * decoding: unused
  488. */
  489. int chroma_elim_threshold;
  490. /**
  491. * strictly follow the std (MPEG4, ...)
  492. * encoding: set by user
  493. * decoding: unused
  494. */
  495. int strict_std_compliance;
  496. /**
  497. * qscale offset between ip and b frames
  498. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  499. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  500. * encoding: set by user.
  501. * decoding: unused
  502. */
  503. float b_quant_offset;
  504. /**
  505. * error resilience higher values will detect more errors but may missdetect
  506. * some more or less valid parts as errors
  507. * encoding: unused
  508. * decoding: set by user
  509. */
  510. int error_resilience;
  511. #define FF_ER_CAREFULL 1
  512. #define FF_ER_COMPLIANT 2
  513. #define FF_ER_AGGRESSIVE 3
  514. #define FF_ER_VERY_AGGRESSIVE 4
  515. /**
  516. * called at the beginning of each frame to get a buffer for it.
  517. * if pic.reference is set then the frame will be read later by lavc
  518. * encoding: unused
  519. * decoding: set by lavc, user can override
  520. */
  521. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  522. /**
  523. * called to release buffers which where allocated with get_buffer.
  524. * a released buffer can be reused in get_buffer()
  525. * pic.data[*] must be set to NULL
  526. * encoding: unused
  527. * decoding: set by lavc, user can override
  528. */
  529. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  530. /**
  531. * is 1 if the decoded stream contains b frames, 0 otherwise
  532. * encoding: unused
  533. * decoding: set by lavc
  534. */
  535. int has_b_frames;
  536. int block_align; /* used by some WAV based audio codecs */
  537. int parse_only; /* decoding only: if true, only parsing is done
  538. (function avcodec_parse_frame()). The frame
  539. data is returned. Only MPEG codecs support this now. */
  540. /**
  541. * 0-> h263 quant 1-> mpeg quant
  542. * encoding: set by user.
  543. * decoding: unused
  544. */
  545. int mpeg_quant;
  546. /**
  547. * pass1 encoding statistics output buffer
  548. * encoding: set by lavc
  549. * decoding: unused
  550. */
  551. char *stats_out; /* encoding statistics output buffer */
  552. /**
  553. * pass2 encoding statistics input buffer.
  554. * concatenated stuff from stats_out of pass1 should be placed here
  555. * encoding: allocated/set/freed by user
  556. * decoding: unused
  557. */
  558. char *stats_in;
  559. /**
  560. * ratecontrol qmin qmax limiting method
  561. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  562. * encoding: set by user.
  563. * decoding: unused
  564. */
  565. float rc_qsquish;
  566. float rc_qmod_amp;
  567. int rc_qmod_freq;
  568. /**
  569. * ratecontrol override, see RcOverride
  570. * encoding: allocated/set/freed by user.
  571. * decoding: unused
  572. */
  573. RcOverride *rc_override;
  574. int rc_override_count;
  575. /**
  576. * rate control equation
  577. * encoding: set by user
  578. * decoding: unused
  579. */
  580. char *rc_eq;
  581. /**
  582. * maximum bitrate
  583. * encoding: set by user.
  584. * decoding: unused
  585. */
  586. int rc_max_rate;
  587. /**
  588. * minimum bitrate
  589. * encoding: set by user.
  590. * decoding: unused
  591. */
  592. int rc_min_rate;
  593. /**
  594. * decoder bitstream buffer size
  595. * encoding: set by user.
  596. * decoding: unused
  597. */
  598. int rc_buffer_size;
  599. float rc_buffer_aggressivity;
  600. /**
  601. * qscale factor between p and i frames
  602. * encoding: set by user.
  603. * decoding: unused
  604. */
  605. float i_quant_factor;
  606. /**
  607. * qscale offset between p and i frames
  608. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  609. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  610. * encoding: set by user.
  611. * decoding: unused
  612. */
  613. float i_quant_offset;
  614. /**
  615. * initial complexity for pass1 ratecontrol
  616. * encoding: set by user.
  617. * decoding: unused
  618. */
  619. float rc_initial_cplx;
  620. /**
  621. * dct algorithm, see FF_DCT_* below
  622. * encoding: set by user
  623. * decoding: unused
  624. */
  625. int dct_algo;
  626. #define FF_DCT_AUTO 0
  627. #define FF_DCT_FASTINT 1
  628. #define FF_DCT_INT 2
  629. #define FF_DCT_MMX 3
  630. #define FF_DCT_MLIB 4
  631. #define FF_DCT_ALTIVEC 5
  632. /**
  633. * luminance masking (0-> disabled)
  634. * encoding: set by user
  635. * decoding: unused
  636. */
  637. float lumi_masking;
  638. /**
  639. * temporary complexity masking (0-> disabled)
  640. * encoding: set by user
  641. * decoding: unused
  642. */
  643. float temporal_cplx_masking;
  644. /**
  645. * spatial complexity masking (0-> disabled)
  646. * encoding: set by user
  647. * decoding: unused
  648. */
  649. float spatial_cplx_masking;
  650. /**
  651. * p block masking (0-> disabled)
  652. * encoding: set by user
  653. * decoding: unused
  654. */
  655. float p_masking;
  656. /**
  657. * darkness masking (0-> disabled)
  658. * encoding: set by user
  659. * decoding: unused
  660. */
  661. float dark_masking;
  662. /**
  663. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A')
  664. * this is used to workaround some encoder bugs
  665. * encoding: unused
  666. * decoding: set by user, will be converted to upper case by lavc during init
  667. */
  668. int fourcc;
  669. /**
  670. * idct algorithm, see FF_IDCT_* below
  671. * encoding: set by user
  672. * decoding: set by user
  673. */
  674. int idct_algo;
  675. #define FF_IDCT_AUTO 0
  676. #define FF_IDCT_INT 1
  677. #define FF_IDCT_SIMPLE 2
  678. #define FF_IDCT_SIMPLEMMX 3
  679. #define FF_IDCT_LIBMPEG2MMX 4
  680. #define FF_IDCT_PS2 5
  681. #define FF_IDCT_MLIB 6
  682. #define FF_IDCT_ARM 7
  683. #define FF_IDCT_ALTIVEC 8
  684. /**
  685. * slice count
  686. * encoding: set by lavc
  687. * decoding: set by user (or 0)
  688. */
  689. int slice_count;
  690. /**
  691. * slice offsets in the frame in bytes
  692. * encoding: set/allocated by lavc
  693. * decoding: set/allocated by user (or NULL)
  694. */
  695. int *slice_offset;
  696. /**
  697. * error concealment flags
  698. * encoding: unused
  699. * decoding: set by user
  700. */
  701. int error_concealment;
  702. #define FF_EC_GUESS_MVS 1
  703. #define FF_EC_DEBLOCK 2
  704. /**
  705. * dsp_mask could be used to disable unwanted
  706. * CPU features (i.e. MMX, SSE. ...)
  707. */
  708. unsigned dsp_mask;
  709. /**
  710. * bits per sample/pixel from the demuxer (needed for huffyuv)
  711. * encoding: set by lavc
  712. * decoding: set by user
  713. */
  714. int bits_per_sample;
  715. /**
  716. * prediction method (needed for huffyuv)
  717. * encoding: set by user
  718. * decoding: unused
  719. */
  720. int prediction_method;
  721. #define FF_PRED_LEFT 0
  722. #define FF_PRED_PLANE 1
  723. #define FF_PRED_MEDIAN 2
  724. /**
  725. * aspect ratio. (0 if unknown)
  726. * encoding: set by user.
  727. * decoding: set by lavc.
  728. */
  729. float aspect_ratio;
  730. /**
  731. * the picture in the bitstream
  732. * encoding: set by lavc
  733. * decoding: set by lavc
  734. */
  735. AVFrame *coded_frame;
  736. /**
  737. * debug
  738. * encoding: set by user.
  739. * decoding: set by user.
  740. */
  741. int debug;
  742. #define FF_DEBUG_PICT_INFO 1
  743. #define FF_DEBUG_RC 2
  744. #define FF_DEBUG_BITSTREAM 4
  745. #define FF_DEBUG_MB_TYPE 8
  746. #define FF_DEBUG_QP 16
  747. #define FF_DEBUG_MV 32
  748. #define FF_DEBUG_VIS_MV 0x00000040
  749. #define FF_DEBUG_SKIP 0x00000080
  750. #define FF_DEBUG_STARTCODE 0x00000100
  751. #define FF_DEBUG_PTS 0x00000200
  752. /**
  753. * error
  754. * encoding: set by lavc if flags&CODEC_FLAG_PSNR
  755. * decoding: unused
  756. */
  757. uint64_t error[4];
  758. /**
  759. * minimum MB quantizer
  760. * encoding: set by user.
  761. * decoding: unused
  762. */
  763. int mb_qmin;
  764. /**
  765. * maximum MB quantizer
  766. * encoding: set by user.
  767. * decoding: unused
  768. */
  769. int mb_qmax;
  770. /**
  771. * motion estimation compare function
  772. * encoding: set by user.
  773. * decoding: unused
  774. */
  775. int me_cmp;
  776. /**
  777. * subpixel motion estimation compare function
  778. * encoding: set by user.
  779. * decoding: unused
  780. */
  781. int me_sub_cmp;
  782. /**
  783. * macroblock compare function (not supported yet)
  784. * encoding: set by user.
  785. * decoding: unused
  786. */
  787. int mb_cmp;
  788. #define FF_CMP_SAD 0
  789. #define FF_CMP_SSE 1
  790. #define FF_CMP_SATD 2
  791. #define FF_CMP_DCT 3
  792. #define FF_CMP_PSNR 4
  793. #define FF_CMP_BIT 5
  794. #define FF_CMP_RD 6
  795. #define FF_CMP_ZERO 7
  796. #define FF_CMP_CHROMA 256
  797. /**
  798. * ME diamond size & shape
  799. * encoding: set by user.
  800. * decoding: unused
  801. */
  802. int dia_size;
  803. /**
  804. * amount of previous MV predictors (2a+1 x 2a+1 square)
  805. * encoding: set by user.
  806. * decoding: unused
  807. */
  808. int last_predictor_count;
  809. /**
  810. * pre pass for motion estimation
  811. * encoding: set by user.
  812. * decoding: unused
  813. */
  814. int pre_me;
  815. /**
  816. * motion estimation pre pass compare function
  817. * encoding: set by user.
  818. * decoding: unused
  819. */
  820. int me_pre_cmp;
  821. /**
  822. * ME pre pass diamond size & shape
  823. * encoding: set by user.
  824. * decoding: unused
  825. */
  826. int pre_dia_size;
  827. /**
  828. * subpel ME quality
  829. * encoding: set by user.
  830. * decoding: unused
  831. */
  832. int me_subpel_quality;
  833. /**
  834. * callback to negotiate the pixelFormat
  835. * @param fmt is the list of formats which are supported by the codec,
  836. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  837. * the first is allways the native one
  838. * @return the choosen format
  839. * encoding: unused
  840. * decoding: set by user, if not set then the native format will always be choosen
  841. */
  842. enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
  843. /**
  844. * DTG active format information (additionnal aspect ratio
  845. * information only used in DVB MPEG2 transport streams). 0 if
  846. * not set.
  847. *
  848. * encoding: unused.
  849. * decoding: set by decoder
  850. */
  851. int dtg_active_format;
  852. #define FF_DTG_AFD_SAME 8
  853. #define FF_DTG_AFD_4_3 9
  854. #define FF_DTG_AFD_16_9 10
  855. #define FF_DTG_AFD_14_9 11
  856. #define FF_DTG_AFD_4_3_SP_14_9 13
  857. #define FF_DTG_AFD_16_9_SP_14_9 14
  858. #define FF_DTG_AFD_SP_4_3 15
  859. int me_range;
  860. /**
  861. * Maximum motion estimation search range in subpel units.
  862. * if 0 then no limit
  863. *
  864. * encoding: set by user.
  865. * decoding: unused.
  866. */
  867. } AVCodecContext;
  868. //void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
  869. typedef struct AVOption {
  870. /** options' name */
  871. const char *name; /* if name is NULL, it indicates a link to next */
  872. /** short English text help */
  873. const char *help;
  874. /** offset to context structure where the parsed value should be stored */
  875. int offset;
  876. /** options' type */
  877. int type;
  878. #define FF_OPT_TYPE_BOOL 1 // boolean - true,1,on (or simply presence)
  879. #define FF_OPT_TYPE_DOUBLE 2 // double
  880. #define FF_OPT_TYPE_INT 3 // integer
  881. #define FF_OPT_TYPE_STRING 4 // string (finished with \0)
  882. #define FF_OPT_TYPE_MASK 0x1f // mask for types - upper bits are various flags
  883. //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
  884. #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
  885. #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
  886. /** min value (min == max -> no limits) */
  887. double min;
  888. /** maximum value for double/int */
  889. double max;
  890. /** default boo [0,1]l/double/int value */
  891. double defval;
  892. /**
  893. * default string value (with optional semicolon delimited extra option-list
  894. * i.e. option1;option2;option3
  895. * defval might select other then first argument as default
  896. */
  897. const char *defstr;
  898. const struct AVOption *sub; /* used when name is NULL */
  899. /* when it's NULL return to previous level (or finish reading) */
  900. #define FF_OPT_MAX_DEPTH 10
  901. } AVOption;
  902. typedef struct AVCodec {
  903. const char *name;
  904. int type;
  905. int id;
  906. int priv_data_size;
  907. int (*init)(AVCodecContext *);
  908. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  909. int (*close)(AVCodecContext *);
  910. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  911. uint8_t *buf, int buf_size);
  912. int capabilities;
  913. const AVOption *options;
  914. struct AVCodec *next;
  915. } AVCodec;
  916. /**
  917. * four components are given, that's all.
  918. * the last component is alpha
  919. */
  920. typedef struct AVPicture {
  921. uint8_t *data[4];
  922. int linesize[4];
  923. } AVPicture;
  924. extern AVCodec ac3_encoder;
  925. extern AVCodec mp2_encoder;
  926. extern AVCodec mp3lame_encoder;
  927. extern AVCodec oggvorbis_encoder;
  928. extern AVCodec mpeg1video_encoder;
  929. extern AVCodec h263_encoder;
  930. extern AVCodec h263p_encoder;
  931. extern AVCodec rv10_encoder;
  932. extern AVCodec mjpeg_encoder;
  933. extern AVCodec mpeg4_encoder;
  934. extern AVCodec msmpeg4v1_encoder;
  935. extern AVCodec msmpeg4v2_encoder;
  936. extern AVCodec msmpeg4v3_encoder;
  937. extern AVCodec wmv1_encoder;
  938. extern AVCodec wmv2_encoder;
  939. extern AVCodec huffyuv_encoder;
  940. extern AVCodec h263_decoder;
  941. extern AVCodec mpeg4_decoder;
  942. extern AVCodec msmpeg4v1_decoder;
  943. extern AVCodec msmpeg4v2_decoder;
  944. extern AVCodec msmpeg4v3_decoder;
  945. extern AVCodec wmv1_decoder;
  946. extern AVCodec wmv2_decoder;
  947. extern AVCodec mpeg_decoder;
  948. extern AVCodec h263i_decoder;
  949. extern AVCodec rv10_decoder;
  950. extern AVCodec svq1_decoder;
  951. extern AVCodec dvvideo_decoder;
  952. extern AVCodec dvaudio_decoder;
  953. extern AVCodec wmav1_decoder;
  954. extern AVCodec wmav2_decoder;
  955. extern AVCodec mjpeg_decoder;
  956. extern AVCodec mjpegb_decoder;
  957. extern AVCodec mp2_decoder;
  958. extern AVCodec mp3_decoder;
  959. extern AVCodec mace3_decoder;
  960. extern AVCodec mace6_decoder;
  961. extern AVCodec huffyuv_decoder;
  962. extern AVCodec oggvorbis_decoder;
  963. extern AVCodec cyuv_decoder;
  964. /* pcm codecs */
  965. #define PCM_CODEC(id, name) \
  966. extern AVCodec name ## _decoder; \
  967. extern AVCodec name ## _encoder
  968. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  969. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  970. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  971. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  972. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  973. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  974. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  975. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  976. /* adpcm codecs */
  977. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  978. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  979. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  980. #undef PCM_CODEC
  981. /* dummy raw video codec */
  982. extern AVCodec rawvideo_codec;
  983. /* the following codecs use external GPL libs */
  984. extern AVCodec ac3_decoder;
  985. /* resample.c */
  986. struct ReSampleContext;
  987. typedef struct ReSampleContext ReSampleContext;
  988. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  989. int output_rate, int input_rate);
  990. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  991. void audio_resample_close(ReSampleContext *s);
  992. /* YUV420 format is assumed ! */
  993. struct ImgReSampleContext;
  994. typedef struct ImgReSampleContext ImgReSampleContext;
  995. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  996. int input_width, int input_height);
  997. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  998. int iwidth, int iheight,
  999. int topBand, int bottomBand,
  1000. int leftBand, int rightBand);
  1001. void img_resample(ImgReSampleContext *s,
  1002. AVPicture *output, AVPicture *input);
  1003. void img_resample_close(ImgReSampleContext *s);
  1004. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  1005. int pix_fmt, int width, int height);
  1006. int avpicture_get_size(int pix_fmt, int width, int height);
  1007. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  1008. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  1009. /* convert among pixel formats */
  1010. int img_convert(AVPicture *dst, int dst_pix_fmt,
  1011. AVPicture *src, int pix_fmt,
  1012. int width, int height);
  1013. /* deinterlace a picture */
  1014. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  1015. int pix_fmt, int width, int height);
  1016. /* external high level API */
  1017. extern AVCodec *first_avcodec;
  1018. /* returns LIBAVCODEC_VERSION_INT constant */
  1019. unsigned avcodec_version(void);
  1020. /* returns LIBAVCODEC_BUILD constant */
  1021. unsigned avcodec_build(void);
  1022. void avcodec_init(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 */