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.

1339 lines
37KB

  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 used to disable unwanted
  734. * CPU features (i.e. MMX, SSE. ...)
  735. */
  736. unsigned dsp_mask;
  737. /**
  738. * bits per sample/pixel from the demuxer (needed for huffyuv).
  739. * - encoding: set by lavc
  740. * - decoding: set by user
  741. */
  742. int bits_per_sample;
  743. /**
  744. * prediction method (needed for huffyuv).
  745. * - encoding: set by user
  746. * - decoding: unused
  747. */
  748. int prediction_method;
  749. #define FF_PRED_LEFT 0
  750. #define FF_PRED_PLANE 1
  751. #define FF_PRED_MEDIAN 2
  752. /**
  753. * aspect ratio (0 if unknown).
  754. * - encoding: set by user.
  755. * - decoding: set by lavc.
  756. */
  757. float aspect_ratio;
  758. /**
  759. * the picture in the bitstream.
  760. * - encoding: set by lavc
  761. * - decoding: set by lavc
  762. */
  763. AVFrame *coded_frame;
  764. /**
  765. * debug.
  766. * - encoding: set by user.
  767. * - decoding: set by user.
  768. */
  769. int debug;
  770. #define FF_DEBUG_PICT_INFO 1
  771. #define FF_DEBUG_RC 2
  772. #define FF_DEBUG_BITSTREAM 4
  773. #define FF_DEBUG_MB_TYPE 8
  774. #define FF_DEBUG_QP 16
  775. #define FF_DEBUG_MV 32
  776. #define FF_DEBUG_VIS_MV 0x00000040
  777. #define FF_DEBUG_SKIP 0x00000080
  778. #define FF_DEBUG_STARTCODE 0x00000100
  779. #define FF_DEBUG_PTS 0x00000200
  780. /**
  781. * error.
  782. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
  783. * - decoding: unused
  784. */
  785. uint64_t error[4];
  786. /**
  787. * minimum MB quantizer.
  788. * - encoding: set by user.
  789. * - decoding: unused
  790. */
  791. int mb_qmin;
  792. /**
  793. * maximum MB quantizer.
  794. * - encoding: set by user.
  795. * - decoding: unused
  796. */
  797. int mb_qmax;
  798. /**
  799. * motion estimation compare function.
  800. * - encoding: set by user.
  801. * - decoding: unused
  802. */
  803. int me_cmp;
  804. /**
  805. * subpixel motion estimation compare function.
  806. * - encoding: set by user.
  807. * - decoding: unused
  808. */
  809. int me_sub_cmp;
  810. /**
  811. * macroblock compare function (not supported yet).
  812. * - encoding: set by user.
  813. * - decoding: unused
  814. */
  815. int mb_cmp;
  816. #define FF_CMP_SAD 0
  817. #define FF_CMP_SSE 1
  818. #define FF_CMP_SATD 2
  819. #define FF_CMP_DCT 3
  820. #define FF_CMP_PSNR 4
  821. #define FF_CMP_BIT 5
  822. #define FF_CMP_RD 6
  823. #define FF_CMP_ZERO 7
  824. #define FF_CMP_CHROMA 256
  825. /**
  826. * ME diamond size & shape.
  827. * - encoding: set by user.
  828. * - decoding: unused
  829. */
  830. int dia_size;
  831. /**
  832. * amount of previous MV predictors (2a+1 x 2a+1 square).
  833. * - encoding: set by user.
  834. * - decoding: unused
  835. */
  836. int last_predictor_count;
  837. /**
  838. * pre pass for motion estimation.
  839. * - encoding: set by user.
  840. * - decoding: unused
  841. */
  842. int pre_me;
  843. /**
  844. * motion estimation pre pass compare function.
  845. * - encoding: set by user.
  846. * - decoding: unused
  847. */
  848. int me_pre_cmp;
  849. /**
  850. * ME pre pass diamond size & shape.
  851. * - encoding: set by user.
  852. * - decoding: unused
  853. */
  854. int pre_dia_size;
  855. /**
  856. * subpel ME quality.
  857. * - encoding: set by user.
  858. * - decoding: unused
  859. */
  860. int me_subpel_quality;
  861. /**
  862. * callback to negotiate the pixelFormat.
  863. * @param fmt is the list of formats which are supported by the codec,
  864. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  865. * the first is allways the native one
  866. * @return the choosen format
  867. * - encoding: unused
  868. * - decoding: set by user, if not set then the native format will always be choosen
  869. */
  870. enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
  871. /**
  872. * DTG active format information (additionnal aspect ratio
  873. * information only used in DVB MPEG2 transport streams). 0 if
  874. * not set.
  875. *
  876. * - encoding: unused.
  877. * - decoding: set by decoder
  878. */
  879. int dtg_active_format;
  880. #define FF_DTG_AFD_SAME 8
  881. #define FF_DTG_AFD_4_3 9
  882. #define FF_DTG_AFD_16_9 10
  883. #define FF_DTG_AFD_14_9 11
  884. #define FF_DTG_AFD_4_3_SP_14_9 13
  885. #define FF_DTG_AFD_16_9_SP_14_9 14
  886. #define FF_DTG_AFD_SP_4_3 15
  887. int me_range;
  888. /**
  889. * Maximum motion estimation search range in subpel units.
  890. * if 0 then no limit
  891. *
  892. * - encoding: set by user.
  893. * - decoding: unused.
  894. */
  895. } AVCodecContext;
  896. //void avcodec_getopt(AVCodecContext* avctx, const char* str, avc_config_t** config);
  897. /**
  898. * AVOption.
  899. */
  900. typedef struct AVOption {
  901. /** options' name */
  902. const char *name; /* if name is NULL, it indicates a link to next */
  903. /** short English text help */
  904. const char *help;
  905. /** offset to context structure where the parsed value should be stored */
  906. int offset;
  907. /** options' type */
  908. int type;
  909. #define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
  910. #define FF_OPT_TYPE_DOUBLE 2 ///< double
  911. #define FF_OPT_TYPE_INT 3 ///< integer
  912. #define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
  913. #define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
  914. //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
  915. #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
  916. #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
  917. /** min value (min == max -> no limits) */
  918. double min;
  919. /** maximum value for double/int */
  920. double max;
  921. /** default boo [0,1]l/double/int value */
  922. double defval;
  923. /**
  924. * default string value (with optional semicolon delimited extra option-list
  925. * i.e. option1;option2;option3
  926. * defval might select other then first argument as default
  927. */
  928. const char *defstr;
  929. const struct AVOption *sub; /* used when name is NULL */
  930. /* when it's NULL return to previous level (or finish reading) */
  931. #define FF_OPT_MAX_DEPTH 10
  932. } AVOption;
  933. /**
  934. * AVCodec.
  935. */
  936. typedef struct AVCodec {
  937. const char *name;
  938. int type;
  939. int id;
  940. int priv_data_size;
  941. int (*init)(AVCodecContext *);
  942. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  943. int (*close)(AVCodecContext *);
  944. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  945. uint8_t *buf, int buf_size);
  946. int capabilities;
  947. const AVOption *options;
  948. struct AVCodec *next;
  949. } AVCodec;
  950. /**
  951. * four components are given, that's all.
  952. * the last component is alpha
  953. */
  954. typedef struct AVPicture {
  955. uint8_t *data[4];
  956. int linesize[4];
  957. } AVPicture;
  958. extern AVCodec ac3_encoder;
  959. extern AVCodec mp2_encoder;
  960. extern AVCodec mp3lame_encoder;
  961. extern AVCodec oggvorbis_encoder;
  962. extern AVCodec mpeg1video_encoder;
  963. extern AVCodec h263_encoder;
  964. extern AVCodec h263p_encoder;
  965. extern AVCodec rv10_encoder;
  966. extern AVCodec mjpeg_encoder;
  967. extern AVCodec mpeg4_encoder;
  968. extern AVCodec msmpeg4v1_encoder;
  969. extern AVCodec msmpeg4v2_encoder;
  970. extern AVCodec msmpeg4v3_encoder;
  971. extern AVCodec wmv1_encoder;
  972. extern AVCodec wmv2_encoder;
  973. extern AVCodec huffyuv_encoder;
  974. extern AVCodec h263_decoder;
  975. extern AVCodec mpeg4_decoder;
  976. extern AVCodec msmpeg4v1_decoder;
  977. extern AVCodec msmpeg4v2_decoder;
  978. extern AVCodec msmpeg4v3_decoder;
  979. extern AVCodec wmv1_decoder;
  980. extern AVCodec wmv2_decoder;
  981. extern AVCodec mpeg_decoder;
  982. extern AVCodec h263i_decoder;
  983. extern AVCodec rv10_decoder;
  984. extern AVCodec svq1_decoder;
  985. extern AVCodec dvvideo_decoder;
  986. extern AVCodec dvaudio_decoder;
  987. extern AVCodec wmav1_decoder;
  988. extern AVCodec wmav2_decoder;
  989. extern AVCodec mjpeg_decoder;
  990. extern AVCodec mjpegb_decoder;
  991. extern AVCodec mp2_decoder;
  992. extern AVCodec mp3_decoder;
  993. extern AVCodec mace3_decoder;
  994. extern AVCodec mace6_decoder;
  995. extern AVCodec huffyuv_decoder;
  996. extern AVCodec oggvorbis_decoder;
  997. extern AVCodec cyuv_decoder;
  998. /* pcm codecs */
  999. #define PCM_CODEC(id, name) \
  1000. extern AVCodec name ## _decoder; \
  1001. extern AVCodec name ## _encoder
  1002. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  1003. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  1004. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  1005. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  1006. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  1007. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  1008. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  1009. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  1010. /* adpcm codecs */
  1011. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  1012. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  1013. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  1014. #undef PCM_CODEC
  1015. /* dummy raw video codec */
  1016. extern AVCodec rawvideo_codec;
  1017. /* the following codecs use external GPL libs */
  1018. extern AVCodec ac3_decoder;
  1019. /* resample.c */
  1020. struct ReSampleContext;
  1021. typedef struct ReSampleContext ReSampleContext;
  1022. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  1023. int output_rate, int input_rate);
  1024. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  1025. void audio_resample_close(ReSampleContext *s);
  1026. /* YUV420 format is assumed ! */
  1027. struct ImgReSampleContext;
  1028. typedef struct ImgReSampleContext ImgReSampleContext;
  1029. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  1030. int input_width, int input_height);
  1031. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  1032. int iwidth, int iheight,
  1033. int topBand, int bottomBand,
  1034. int leftBand, int rightBand);
  1035. void img_resample(ImgReSampleContext *s,
  1036. AVPicture *output, AVPicture *input);
  1037. void img_resample_close(ImgReSampleContext *s);
  1038. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  1039. int pix_fmt, int width, int height);
  1040. int avpicture_get_size(int pix_fmt, int width, int height);
  1041. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  1042. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  1043. /* convert among pixel formats */
  1044. int img_convert(AVPicture *dst, int dst_pix_fmt,
  1045. AVPicture *src, int pix_fmt,
  1046. int width, int height);
  1047. /* deinterlace a picture */
  1048. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  1049. int pix_fmt, int width, int height);
  1050. /* external high level API */
  1051. extern AVCodec *first_avcodec;
  1052. /* returns LIBAVCODEC_VERSION_INT constant */
  1053. unsigned avcodec_version(void);
  1054. /* returns LIBAVCODEC_BUILD constant */
  1055. unsigned avcodec_build(void);
  1056. void avcodec_init(void);
  1057. void register_avcodec(AVCodec *format);
  1058. AVCodec *avcodec_find_encoder(enum CodecID id);
  1059. AVCodec *avcodec_find_encoder_by_name(const char *name);
  1060. AVCodec *avcodec_find_decoder(enum CodecID id);
  1061. AVCodec *avcodec_find_decoder_by_name(const char *name);
  1062. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  1063. void avcodec_get_context_defaults(AVCodecContext *s);
  1064. AVCodecContext *avcodec_alloc_context(void);
  1065. AVFrame *avcodec_alloc_frame(void);
  1066. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  1067. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  1068. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  1069. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  1070. int *frame_size_ptr,
  1071. uint8_t *buf, int buf_size);
  1072. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  1073. int *got_picture_ptr,
  1074. uint8_t *buf, int buf_size);
  1075. int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
  1076. int *data_size_ptr,
  1077. uint8_t *buf, int buf_size);
  1078. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1079. const short *samples);
  1080. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1081. const AVFrame *pict);
  1082. int avcodec_close(AVCodecContext *avctx);
  1083. void avcodec_register_all(void);
  1084. void avcodec_flush_buffers(AVCodecContext *avctx);
  1085. /**
  1086. * Interface for 0.5.0 version
  1087. *
  1088. * do not even think about it's usage for this moment
  1089. */
  1090. typedef struct {
  1091. /// compressed size used from given memory buffer
  1092. int size;
  1093. /// I/P/B frame type
  1094. int frame_type;
  1095. } avc_enc_result_t;
  1096. /**
  1097. * Commands
  1098. * order can't be changed - once it was defined
  1099. */
  1100. typedef enum {
  1101. // general commands
  1102. AVC_OPEN_BY_NAME = 0xACA000,
  1103. AVC_OPEN_BY_CODEC_ID,
  1104. AVC_OPEN_BY_FOURCC,
  1105. AVC_CLOSE,
  1106. AVC_FLUSH,
  1107. // pin - struct { uint8_t* src, uint_t src_size }
  1108. // pout - struct { AVPicture* img, consumed_bytes,
  1109. AVC_DECODE,
  1110. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  1111. // pout - uint_t used_from_dest_size
  1112. AVC_ENCODE,
  1113. // query/get video commands
  1114. AVC_GET_VERSION = 0xACB000,
  1115. AVC_GET_WIDTH,
  1116. AVC_GET_HEIGHT,
  1117. AVC_GET_DELAY,
  1118. AVC_GET_QUANT_TABLE,
  1119. // ...
  1120. // query/get audio commands
  1121. AVC_GET_FRAME_SIZE = 0xABC000,
  1122. // maybe define some simple structure which
  1123. // might be passed to the user - but they can't
  1124. // contain any codec specific parts and these
  1125. // calls are usualy necessary only few times
  1126. // set video commands
  1127. AVC_SET_WIDTH = 0xACD000,
  1128. AVC_SET_HEIGHT,
  1129. // set video encoding commands
  1130. AVC_SET_FRAME_RATE = 0xACD800,
  1131. AVC_SET_QUALITY,
  1132. AVC_SET_HURRY_UP,
  1133. // set audio commands
  1134. AVC_SET_SAMPLE_RATE = 0xACE000,
  1135. AVC_SET_CHANNELS,
  1136. } avc_cmd_t;
  1137. /**
  1138. * \param handle allocated private structure by libavcodec
  1139. * for initialization pass NULL - will be returned pout
  1140. * user is supposed to know nothing about its structure
  1141. * \param cmd type of operation to be performed
  1142. * \param pint input parameter
  1143. * \param pout output parameter
  1144. *
  1145. * \returns command status - eventually for query command it might return
  1146. * integer resulting value
  1147. */
  1148. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  1149. /* memory */
  1150. void *av_malloc(unsigned int size);
  1151. void *av_mallocz(unsigned int size);
  1152. void *av_realloc(void *ptr, unsigned int size);
  1153. void av_free(void *ptr);
  1154. char *av_strdup(const char *s);
  1155. void __av_freep(void **ptr);
  1156. #define av_freep(p) __av_freep((void **)(p))
  1157. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
  1158. /* for static data only */
  1159. /* call av_free_static to release all staticaly allocated tables */
  1160. void av_free_static(void);
  1161. void *__av_mallocz_static(void** location, unsigned int size);
  1162. #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
  1163. #ifdef __cplusplus
  1164. }
  1165. #endif
  1166. #endif /* AVCODEC_H */