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.

1257 lines
35KB

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