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.

1316 lines
36KB

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