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.

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