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.

1357 lines
38KB

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