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.

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