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.

1265 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 4654
  15. #define LIBAVCODEC_BUILD_STR "4654"
  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_FAKE_SCALABILITY 16 //autodetection should work 100%
  471. /**
  472. * encoding: set by user
  473. * decoding: unused
  474. */
  475. int luma_elim_threshold;
  476. /**
  477. * encoding: set by user
  478. * decoding: unused
  479. */
  480. int chroma_elim_threshold;
  481. /**
  482. * strictly follow the std (MPEG4, ...)
  483. * encoding: set by user
  484. * decoding: unused
  485. */
  486. int strict_std_compliance;
  487. /**
  488. * qscale offset between ip and b frames
  489. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  490. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  491. * encoding: set by user.
  492. * decoding: unused
  493. */
  494. float b_quant_offset;
  495. /**
  496. * error resilience higher values will detect more errors but may missdetect
  497. * some more or less valid parts as errors
  498. * encoding: unused
  499. * decoding: set by user
  500. */
  501. int error_resilience;
  502. #define FF_ER_CAREFULL 1
  503. #define FF_ER_COMPLIANT 2
  504. #define FF_ER_AGGRESSIVE 3
  505. #define FF_ER_VERY_AGGRESSIVE 4
  506. /**
  507. * called at the beginning of each frame to get a buffer for it.
  508. * if pic.reference is set then the frame will be read later by lavc
  509. * encoding: unused
  510. * decoding: set by lavc, user can override
  511. */
  512. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  513. /**
  514. * called to release buffers which where allocated with get_buffer.
  515. * a released buffer can be reused in get_buffer()
  516. * pic.data[*] must be set to NULL
  517. * encoding: unused
  518. * decoding: set by lavc, user can override
  519. */
  520. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  521. /**
  522. * is 1 if the decoded stream contains b frames, 0 otherwise
  523. * encoding: unused
  524. * decoding: set by lavc
  525. */
  526. int has_b_frames;
  527. int block_align; /* used by some WAV based audio codecs */
  528. int parse_only; /* decoding only: if true, only parsing is done
  529. (function avcodec_parse_frame()). The frame
  530. data is returned. Only MPEG codecs support this now. */
  531. /**
  532. * 0-> h263 quant 1-> mpeg quant
  533. * encoding: set by user.
  534. * decoding: unused
  535. */
  536. int mpeg_quant;
  537. /**
  538. * pass1 encoding statistics output buffer
  539. * encoding: set by lavc
  540. * decoding: unused
  541. */
  542. char *stats_out; /* encoding statistics output buffer */
  543. /**
  544. * pass2 encoding statistics input buffer.
  545. * concatenated stuff from stats_out of pass1 should be placed here
  546. * encoding: allocated/set/freed by user
  547. * decoding: unused
  548. */
  549. char *stats_in;
  550. /**
  551. * ratecontrol qmin qmax limiting method
  552. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  553. * encoding: set by user.
  554. * decoding: unused
  555. */
  556. float rc_qsquish;
  557. float rc_qmod_amp;
  558. int rc_qmod_freq;
  559. /**
  560. * ratecontrol override, see RcOverride
  561. * encoding: allocated/set/freed by user.
  562. * decoding: unused
  563. */
  564. RcOverride *rc_override;
  565. int rc_override_count;
  566. /**
  567. * rate control equation
  568. * encoding: set by user
  569. * decoding: unused
  570. */
  571. char *rc_eq;
  572. /**
  573. * maximum bitrate
  574. * encoding: set by user.
  575. * decoding: unused
  576. */
  577. int rc_max_rate;
  578. /**
  579. * minimum bitrate
  580. * encoding: set by user.
  581. * decoding: unused
  582. */
  583. int rc_min_rate;
  584. /**
  585. * decoder bitstream buffer size
  586. * encoding: set by user.
  587. * decoding: unused
  588. */
  589. int rc_buffer_size;
  590. float rc_buffer_aggressivity;
  591. /**
  592. * qscale factor between p and i frames
  593. * encoding: set by user.
  594. * decoding: unused
  595. */
  596. float i_quant_factor;
  597. /**
  598. * qscale offset between p and i frames
  599. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  600. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  601. * encoding: set by user.
  602. * decoding: unused
  603. */
  604. float i_quant_offset;
  605. /**
  606. * initial complexity for pass1 ratecontrol
  607. * encoding: set by user.
  608. * decoding: unused
  609. */
  610. float rc_initial_cplx;
  611. /**
  612. * dct algorithm, see FF_DCT_* below
  613. * encoding: set by user
  614. * decoding: unused
  615. */
  616. int dct_algo;
  617. #define FF_DCT_AUTO 0
  618. #define FF_DCT_FASTINT 1
  619. #define FF_DCT_INT 2
  620. #define FF_DCT_MMX 3
  621. #define FF_DCT_MLIB 4
  622. #define FF_DCT_ALTIVEC 5
  623. /**
  624. * luminance masking (0-> disabled)
  625. * encoding: set by user
  626. * decoding: unused
  627. */
  628. float lumi_masking;
  629. /**
  630. * temporary complexity masking (0-> disabled)
  631. * encoding: set by user
  632. * decoding: unused
  633. */
  634. float temporal_cplx_masking;
  635. /**
  636. * spatial complexity masking (0-> disabled)
  637. * encoding: set by user
  638. * decoding: unused
  639. */
  640. float spatial_cplx_masking;
  641. /**
  642. * p block masking (0-> disabled)
  643. * encoding: set by user
  644. * decoding: unused
  645. */
  646. float p_masking;
  647. /**
  648. * darkness masking (0-> disabled)
  649. * encoding: set by user
  650. * decoding: unused
  651. */
  652. float dark_masking;
  653. /**
  654. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A')
  655. * this is used to workaround some encoder bugs
  656. * encoding: unused
  657. * decoding: set by user, will be converted to upper case by lavc during init
  658. */
  659. int fourcc;
  660. /**
  661. * idct algorithm, see FF_IDCT_* below
  662. * encoding: set by user
  663. * decoding: set by user
  664. */
  665. int idct_algo;
  666. #define FF_IDCT_AUTO 0
  667. #define FF_IDCT_INT 1
  668. #define FF_IDCT_SIMPLE 2
  669. #define FF_IDCT_SIMPLEMMX 3
  670. #define FF_IDCT_LIBMPEG2MMX 4
  671. #define FF_IDCT_PS2 5
  672. #define FF_IDCT_MLIB 6
  673. #define FF_IDCT_ARM 7
  674. #define FF_IDCT_ALTIVEC 8
  675. /**
  676. * slice count
  677. * encoding: set by lavc
  678. * decoding: set by user (or 0)
  679. */
  680. int slice_count;
  681. /**
  682. * slice offsets in the frame in bytes
  683. * encoding: set/allocated by lavc
  684. * decoding: set/allocated by user (or NULL)
  685. */
  686. int *slice_offset;
  687. /**
  688. * error concealment flags
  689. * encoding: unused
  690. * decoding: set by user
  691. */
  692. int error_concealment;
  693. #define FF_EC_GUESS_MVS 1
  694. #define FF_EC_DEBLOCK 2
  695. /**
  696. * dsp_mask could be used to disable unwanted
  697. * CPU features (i.e. MMX, SSE. ...)
  698. */
  699. unsigned dsp_mask;
  700. /**
  701. * bits per sample/pixel from the demuxer (needed for huffyuv)
  702. * encoding: set by lavc
  703. * decoding: set by user
  704. */
  705. int bits_per_sample;
  706. /**
  707. * prediction method (needed for huffyuv)
  708. * encoding: set by user
  709. * decoding: unused
  710. */
  711. int prediction_method;
  712. #define FF_PRED_LEFT 0
  713. #define FF_PRED_PLANE 1
  714. #define FF_PRED_MEDIAN 2
  715. /**
  716. * aspect ratio. (0 if unknown)
  717. * encoding: set by user.
  718. * decoding: set by lavc.
  719. */
  720. float aspect_ratio;
  721. /**
  722. * the picture in the bitstream
  723. * encoding: set by lavc
  724. * decoding: set by lavc
  725. */
  726. AVFrame *coded_frame;
  727. /**
  728. * debug
  729. * encoding: set by user.
  730. * decoding: set by user.
  731. */
  732. int debug;
  733. #define FF_DEBUG_PICT_INFO 1
  734. #define FF_DEBUG_RC 2
  735. #define FF_DEBUG_BITSTREAM 4
  736. #define FF_DEBUG_MB_TYPE 8
  737. #define FF_DEBUG_QP 16
  738. #define FF_DEBUG_MV 32
  739. #define FF_DEBUG_VIS_MV 0x00000040
  740. #define FF_DEBUG_SKIP 0x00000080
  741. #define FF_DEBUG_STARTCODE 0x00000100
  742. #define FF_DEBUG_PTS 0x00000200
  743. /**
  744. * error
  745. * encoding: set by lavc if flags&CODEC_FLAG_PSNR
  746. * decoding: unused
  747. */
  748. uint64_t error[4];
  749. /**
  750. * minimum MB quantizer
  751. * encoding: set by user.
  752. * decoding: unused
  753. */
  754. int mb_qmin;
  755. /**
  756. * maximum MB quantizer
  757. * encoding: set by user.
  758. * decoding: unused
  759. */
  760. int mb_qmax;
  761. /**
  762. * motion estimation compare function
  763. * encoding: set by user.
  764. * decoding: unused
  765. */
  766. int me_cmp;
  767. /**
  768. * subpixel motion estimation compare function
  769. * encoding: set by user.
  770. * decoding: unused
  771. */
  772. int me_sub_cmp;
  773. /**
  774. * macroblock compare function (not supported yet)
  775. * encoding: set by user.
  776. * decoding: unused
  777. */
  778. int mb_cmp;
  779. #define FF_CMP_SAD 0
  780. #define FF_CMP_SSE 1
  781. #define FF_CMP_SATD 2
  782. #define FF_CMP_DCT 3
  783. #define FF_CMP_PSNR 4
  784. #define FF_CMP_BIT 5
  785. #define FF_CMP_RD 6
  786. #define FF_CMP_ZERO 7
  787. #define FF_CMP_CHROMA 256
  788. /**
  789. * ME diamond size & shape
  790. * encoding: set by user.
  791. * decoding: unused
  792. */
  793. int dia_size;
  794. /**
  795. * amount of previous MV predictors (2a+1 x 2a+1 square)
  796. * encoding: set by user.
  797. * decoding: unused
  798. */
  799. int last_predictor_count;
  800. /**
  801. * pre pass for motion estimation
  802. * encoding: set by user.
  803. * decoding: unused
  804. */
  805. int pre_me;
  806. /**
  807. * motion estimation pre pass compare function
  808. * encoding: set by user.
  809. * decoding: unused
  810. */
  811. int me_pre_cmp;
  812. /**
  813. * ME pre pass diamond size & shape
  814. * encoding: set by user.
  815. * decoding: unused
  816. */
  817. int pre_dia_size;
  818. /**
  819. * subpel ME quality
  820. * encoding: set by user.
  821. * decoding: unused
  822. */
  823. int me_subpel_quality;
  824. /**
  825. * callback to negotiate the pixelFormat
  826. * @param fmt is the list of formats which are supported by the codec,
  827. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  828. * the first is allways the native one
  829. * @return the choosen format
  830. * encoding: unused
  831. * decoding: set by user, if not set then the native format will always be choosen
  832. */
  833. enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
  834. } AVCodecContext;
  835. typedef struct AVCodec {
  836. const char *name;
  837. int type;
  838. int id;
  839. int priv_data_size;
  840. int (*init)(AVCodecContext *);
  841. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  842. int (*close)(AVCodecContext *);
  843. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  844. UINT8 *buf, int buf_size);
  845. int capabilities;
  846. struct AVCodec *next;
  847. } AVCodec;
  848. /**
  849. * four components are given, that's all.
  850. * the last component is alpha
  851. */
  852. typedef struct AVPicture {
  853. UINT8 *data[4];
  854. int linesize[4];
  855. } AVPicture;
  856. extern AVCodec ac3_encoder;
  857. extern AVCodec mp2_encoder;
  858. extern AVCodec mp3lame_encoder;
  859. extern AVCodec oggvorbis_encoder;
  860. extern AVCodec mpeg1video_encoder;
  861. extern AVCodec h263_encoder;
  862. extern AVCodec h263p_encoder;
  863. extern AVCodec rv10_encoder;
  864. extern AVCodec mjpeg_encoder;
  865. extern AVCodec mpeg4_encoder;
  866. extern AVCodec msmpeg4v1_encoder;
  867. extern AVCodec msmpeg4v2_encoder;
  868. extern AVCodec msmpeg4v3_encoder;
  869. extern AVCodec wmv1_encoder;
  870. extern AVCodec wmv2_encoder;
  871. extern AVCodec huffyuv_encoder;
  872. extern AVCodec h263_decoder;
  873. extern AVCodec mpeg4_decoder;
  874. extern AVCodec msmpeg4v1_decoder;
  875. extern AVCodec msmpeg4v2_decoder;
  876. extern AVCodec msmpeg4v3_decoder;
  877. extern AVCodec wmv1_decoder;
  878. extern AVCodec wmv2_decoder;
  879. extern AVCodec mpeg_decoder;
  880. extern AVCodec h263i_decoder;
  881. extern AVCodec rv10_decoder;
  882. extern AVCodec svq1_decoder;
  883. extern AVCodec dvvideo_decoder;
  884. extern AVCodec dvaudio_decoder;
  885. extern AVCodec wmav1_decoder;
  886. extern AVCodec wmav2_decoder;
  887. extern AVCodec mjpeg_decoder;
  888. extern AVCodec mjpegb_decoder;
  889. extern AVCodec mp2_decoder;
  890. extern AVCodec mp3_decoder;
  891. extern AVCodec mace3_decoder;
  892. extern AVCodec mace6_decoder;
  893. extern AVCodec huffyuv_decoder;
  894. extern AVCodec oggvorbis_decoder;
  895. /* pcm codecs */
  896. #define PCM_CODEC(id, name) \
  897. extern AVCodec name ## _decoder; \
  898. extern AVCodec name ## _encoder
  899. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  900. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  901. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  902. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  903. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  904. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  905. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  906. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  907. /* adpcm codecs */
  908. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  909. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  910. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  911. #undef PCM_CODEC
  912. /* dummy raw video codec */
  913. extern AVCodec rawvideo_codec;
  914. /* the following codecs use external GPL libs */
  915. extern AVCodec ac3_decoder;
  916. /* resample.c */
  917. struct ReSampleContext;
  918. typedef struct ReSampleContext ReSampleContext;
  919. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  920. int output_rate, int input_rate);
  921. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  922. void audio_resample_close(ReSampleContext *s);
  923. /* YUV420 format is assumed ! */
  924. struct ImgReSampleContext;
  925. typedef struct ImgReSampleContext ImgReSampleContext;
  926. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  927. int input_width, int input_height);
  928. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  929. int iwidth, int iheight,
  930. int topBand, int bottomBand,
  931. int leftBand, int rightBand);
  932. void img_resample(ImgReSampleContext *s,
  933. AVPicture *output, AVPicture *input);
  934. void img_resample_close(ImgReSampleContext *s);
  935. int avpicture_fill(AVPicture *picture, UINT8 *ptr,
  936. int pix_fmt, int width, int height);
  937. int avpicture_get_size(int pix_fmt, int width, int height);
  938. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  939. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  940. /* convert among pixel formats */
  941. int img_convert(AVPicture *dst, int dst_pix_fmt,
  942. AVPicture *src, int pix_fmt,
  943. int width, int height);
  944. /* deinterlace a picture */
  945. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  946. int pix_fmt, int width, int height);
  947. /* external high level API */
  948. extern AVCodec *first_avcodec;
  949. /* returns LIBAVCODEC_VERSION_INT constant */
  950. unsigned avcodec_version(void);
  951. /* returns LIBAVCODEC_BUILD constant */
  952. unsigned avcodec_build(void);
  953. void avcodec_init(void);
  954. void avcodec_set_bit_exact(void);
  955. void register_avcodec(AVCodec *format);
  956. AVCodec *avcodec_find_encoder(enum CodecID id);
  957. AVCodec *avcodec_find_encoder_by_name(const char *name);
  958. AVCodec *avcodec_find_decoder(enum CodecID id);
  959. AVCodec *avcodec_find_decoder_by_name(const char *name);
  960. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  961. void avcodec_get_context_defaults(AVCodecContext *s);
  962. AVCodecContext *avcodec_alloc_context(void);
  963. AVFrame *avcodec_alloc_frame(void);
  964. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  965. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  966. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  967. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  968. int *frame_size_ptr,
  969. UINT8 *buf, int buf_size);
  970. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  971. int *got_picture_ptr,
  972. UINT8 *buf, int buf_size);
  973. int avcodec_parse_frame(AVCodecContext *avctx, UINT8 **pdata,
  974. int *data_size_ptr,
  975. UINT8 *buf, int buf_size);
  976. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  977. const short *samples);
  978. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  979. const AVFrame *pict);
  980. int avcodec_close(AVCodecContext *avctx);
  981. void avcodec_register_all(void);
  982. void avcodec_flush_buffers(AVCodecContext *avctx);
  983. typedef struct {
  984. /** options' name with default value*/
  985. const char* name;
  986. /** English text help */
  987. const char* help;
  988. /** type of variable */
  989. int type;
  990. #define FF_CONF_TYPE_BOOL 1 // boolean - true,1,on (or simply presence)
  991. #define FF_CONF_TYPE_DOUBLE 2 // double
  992. #define FF_CONF_TYPE_INT 3 // integer
  993. #define FF_CONF_TYPE_STRING 4 // string (finished with \0)
  994. #define FF_CONF_TYPE_MASK 0x1f // mask for types - upper bits are various flags
  995. #define FF_CONF_TYPE_EXPERT 0x20 // flag for expert option
  996. #define FF_CONF_TYPE_FLAG (FF_CONF_TYPE_BOOL | 0x40)
  997. #define FF_CONF_TYPE_RCOVERIDE (FF_CONF_TYPE_STRING | 0x80)
  998. /** where the parsed value should be stored */
  999. void* val;
  1000. /** min value (min == max -> no limits) */
  1001. double min;
  1002. /** maximum value for double/int */
  1003. double max;
  1004. /** default boo [0,1]l/double/int value */
  1005. double defval;
  1006. /**
  1007. * default string value (with optional semicolon delimited extra option-list
  1008. * i.e. option1;option2;option3
  1009. * defval might select other then first argument as default
  1010. */
  1011. const char* defstr;
  1012. /** char* list of supported codecs (i.e. ",msmpeg4,h263," NULL - everything */
  1013. const char* supported;
  1014. } avc_config_t;
  1015. void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
  1016. /**
  1017. * Interface for 0.5.0 version
  1018. *
  1019. * do not even think about it's usage for this moment
  1020. */
  1021. typedef struct {
  1022. // compressed size used from given memory buffer
  1023. int size;
  1024. /// I/P/B frame type
  1025. int frame_type;
  1026. } avc_enc_result_t;
  1027. /**
  1028. * Commands
  1029. * order can't be changed - once it was defined
  1030. */
  1031. typedef enum {
  1032. // general commands
  1033. AVC_OPEN_BY_NAME = 0xACA000,
  1034. AVC_OPEN_BY_CODEC_ID,
  1035. AVC_OPEN_BY_FOURCC,
  1036. AVC_CLOSE,
  1037. AVC_FLUSH,
  1038. // pin - struct { uint8_t* src, uint_t src_size }
  1039. // pout - struct { AVPicture* img, consumed_bytes,
  1040. AVC_DECODE,
  1041. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  1042. // pout - uint_t used_from_dest_size
  1043. AVC_ENCODE,
  1044. // query/get video commands
  1045. AVC_GET_VERSION = 0xACB000,
  1046. AVC_GET_WIDTH,
  1047. AVC_GET_HEIGHT,
  1048. AVC_GET_DELAY,
  1049. AVC_GET_QUANT_TABLE,
  1050. // ...
  1051. // query/get audio commands
  1052. AVC_GET_FRAME_SIZE = 0xABC000,
  1053. // maybe define some simple structure which
  1054. // might be passed to the user - but they can't
  1055. // contain any codec specific parts and these
  1056. // calls are usualy necessary only few times
  1057. // set video commands
  1058. AVC_SET_WIDTH = 0xACD000,
  1059. AVC_SET_HEIGHT,
  1060. // set video encoding commands
  1061. AVC_SET_FRAME_RATE = 0xACD800,
  1062. AVC_SET_QUALITY,
  1063. AVC_SET_HURRY_UP,
  1064. // set audio commands
  1065. AVC_SET_SAMPLE_RATE = 0xACE000,
  1066. AVC_SET_CHANNELS,
  1067. } avc_cmd_t;
  1068. /**
  1069. * \param handle allocated private structure by libavcodec
  1070. * for initialization pass NULL - will be returned pout
  1071. * user is supposed to know nothing about its structure
  1072. * \param cmd type of operation to be performed
  1073. * \param pint input parameter
  1074. * \param pout output parameter
  1075. *
  1076. * \returns command status - eventually for query command it might return
  1077. * integer resulting value
  1078. */
  1079. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  1080. /* memory */
  1081. void *av_malloc(unsigned int size);
  1082. void *av_mallocz(unsigned int size);
  1083. void *av_realloc(void *ptr, unsigned int size);
  1084. void av_free(void *ptr);
  1085. char *av_strdup(const char *s);
  1086. void __av_freep(void **ptr);
  1087. #define av_freep(p) __av_freep((void **)(p))
  1088. void *av_fast_realloc(void *ptr, int *size, int min_size);
  1089. /* for static data only */
  1090. /* call av_free_static to release all staticaly allocated tables */
  1091. void av_free_static(void);
  1092. void *__av_mallocz_static(void** location, unsigned int size);
  1093. #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
  1094. #ifdef __cplusplus
  1095. }
  1096. #endif
  1097. #endif /* AVCODEC_H */