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.

1359 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. #define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR
  16. enum CodecID {
  17. CODEC_ID_NONE,
  18. CODEC_ID_MPEG1VIDEO,
  19. CODEC_ID_H263,
  20. CODEC_ID_RV10,
  21. CODEC_ID_MP2,
  22. CODEC_ID_MP3LAME,
  23. CODEC_ID_VORBIS,
  24. CODEC_ID_AC3,
  25. CODEC_ID_MJPEG,
  26. CODEC_ID_MJPEGB,
  27. CODEC_ID_MPEG4,
  28. CODEC_ID_RAWVIDEO,
  29. CODEC_ID_MSMPEG4V1,
  30. CODEC_ID_MSMPEG4V2,
  31. CODEC_ID_MSMPEG4V3,
  32. CODEC_ID_WMV1,
  33. CODEC_ID_WMV2,
  34. CODEC_ID_H263P,
  35. CODEC_ID_H263I,
  36. CODEC_ID_SVQ1,
  37. CODEC_ID_DVVIDEO,
  38. CODEC_ID_DVAUDIO,
  39. CODEC_ID_WMAV1,
  40. CODEC_ID_WMAV2,
  41. CODEC_ID_MACE3,
  42. CODEC_ID_MACE6,
  43. CODEC_ID_HUFFYUV,
  44. CODEC_ID_CYUV,
  45. /* various pcm "codecs" */
  46. CODEC_ID_PCM_S16LE,
  47. CODEC_ID_PCM_S16BE,
  48. CODEC_ID_PCM_U16LE,
  49. CODEC_ID_PCM_U16BE,
  50. CODEC_ID_PCM_S8,
  51. CODEC_ID_PCM_U8,
  52. CODEC_ID_PCM_MULAW,
  53. CODEC_ID_PCM_ALAW,
  54. /* various adpcm codecs */
  55. CODEC_ID_ADPCM_IMA_QT,
  56. CODEC_ID_ADPCM_IMA_WAV,
  57. CODEC_ID_ADPCM_MS,
  58. };
  59. enum CodecType {
  60. CODEC_TYPE_UNKNOWN = -1,
  61. CODEC_TYPE_VIDEO,
  62. CODEC_TYPE_AUDIO,
  63. };
  64. /**
  65. * Pixel format.
  66. */
  67. enum PixelFormat {
  68. PIX_FMT_YUV420P,
  69. PIX_FMT_YUV422,
  70. PIX_FMT_RGB24, ///< 3 bytes, R is first
  71. PIX_FMT_BGR24, ///< 3 bytes, B is first
  72. PIX_FMT_YUV422P,
  73. PIX_FMT_YUV444P,
  74. PIX_FMT_RGBA32, ///< always stored in cpu endianness
  75. PIX_FMT_YUV410P,
  76. PIX_FMT_YUV411P,
  77. PIX_FMT_RGB565, ///< always stored in cpu endianness
  78. PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
  79. PIX_FMT_GRAY8,
  80. PIX_FMT_MONOWHITE, ///< 0 is white
  81. PIX_FMT_MONOBLACK, ///< 0 is black
  82. PIX_FMT_PAL8, ///< 8 bit with RGBA palette
  83. PIX_FMT_NB,
  84. };
  85. /* currently unused, may be used if 24/32 bits samples ever supported */
  86. enum SampleFormat {
  87. SAMPLE_FMT_S16 = 0, ///< signed 16 bits
  88. };
  89. /* in bytes */
  90. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
  91. /**
  92. * Required number of zero bytes at the end of the input bitstream for decoding.
  93. * to avoid overreading (and possibly segfaulting)
  94. */
  95. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  96. /* motion estimation type, EPZS by default */
  97. enum Motion_Est_ID {
  98. ME_ZERO = 1,
  99. ME_FULL,
  100. ME_LOG,
  101. ME_PHODS,
  102. ME_EPZS,
  103. ME_X1
  104. };
  105. typedef struct RcOverride{
  106. int start_frame;
  107. int end_frame;
  108. int qscale; // if this is 0 then quality_factor will be used instead
  109. float quality_factor;
  110. } RcOverride;
  111. /* only for ME compatiblity with old apps */
  112. extern int motion_estimation_method;
  113. /* ME algos sorted by quality */
  114. static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
  115. ME_X1, ME_EPZS, ME_FULL };
  116. #define FF_MAX_B_FRAMES 8
  117. /* encoding support
  118. these flags can be passed in AVCodecContext.flags before initing
  119. Note: note not everything is supported yet
  120. */
  121. #define CODEC_FLAG_HQ 0x0001 ///< brute force MB-type decission mode (slow)
  122. #define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
  123. #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed
  124. #define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
  125. #define CODEC_FLAG_GMC 0x0020 ///< use GMC
  126. #define CODEC_FLAG_PART 0x0080 ///< use data partitioning
  127. /* parent program gurantees that the input for b-frame containing streams is not written to
  128. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  129. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  130. #define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
  131. #define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
  132. #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
  133. #define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
  134. #define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges
  135. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
  136. #define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
  137. of only at frame boundaries */
  138. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
  139. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
  140. #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay / will fail on b frames
  141. #define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
  142. #define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
  143. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
  144. #define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
  145. /* Fx : Flag for h263+ extra options */
  146. #define CODEC_FLAG_H263P_AIC 0x01000000 ///< Advanced intra coding
  147. #define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
  148. /* For advanced prediction mode, we reuse the 4MV flag */
  149. /* Unsupported options :
  150. * Syntax Arithmetic coding (SAC)
  151. * Deblocking filter internal loop
  152. * Slice structured
  153. * Reference Picture Selection
  154. * Independant Segment Decoding
  155. * Alternative Inter * VLC
  156. * Modified Quantization */
  157. /* /Fx */
  158. /* codec capabilities */
  159. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback
  160. #define CODEC_CAP_DR1 0x0002 ///< direct rendering method 1
  161. /* if 'parse_only' field is true, then avcodec_parse_frame() can be
  162. used */
  163. #define CODEC_CAP_PARSE_ONLY 0x0004
  164. #define CODEC_CAP_TRUNCATED 0x0008
  165. #define FRAME_RATE_BASE 10010
  166. #define FF_COMMON_FRAME \
  167. uint8_t *data[4];\
  168. int linesize[4];\
  169. /**\
  170. * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
  171. * this isnt used by lavc unless the default get/release_buffer() is used\
  172. * - encoding: \
  173. * - decoding: \
  174. */\
  175. uint8_t *base[4];\
  176. /**\
  177. * 1 -> keyframe, 0-> not\
  178. * - encoding: set by lavc\
  179. * - decoding: set by lavc\
  180. */\
  181. int key_frame;\
  182. \
  183. /**\
  184. * picture type of the frame, see ?_TYPE below\
  185. * - encoding: set by lavc for coded_picture (and set by user for input)\
  186. * - decoding: set by lavc\
  187. */\
  188. int pict_type;\
  189. \
  190. /**\
  191. * presentation timestamp in micro seconds (time when frame should be shown to user)\
  192. * if 0 then the frame_rate will be used as reference\
  193. * - encoding: MUST be set by user\
  194. * - decoding: set by lavc\
  195. */\
  196. long long int pts;\
  197. \
  198. /**\
  199. * picture number in bitstream order.\
  200. * - encoding: set by\
  201. * - decoding: set by lavc\
  202. */\
  203. int coded_picture_number;\
  204. /**\
  205. * picture number in display order.\
  206. * - encoding: set by\
  207. * - decoding: set by lavc\
  208. */\
  209. int display_picture_number;\
  210. \
  211. /**\
  212. * quality (between 1 (good) and 31 (bad)) \
  213. * - encoding: set by lavc for coded_picture (and set by user for input)\
  214. * - decoding: set by lavc\
  215. */\
  216. float quality; \
  217. \
  218. /**\
  219. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  220. * set to something large if the buffer has not been used yet \
  221. * - encoding: unused\
  222. * - decoding: MUST be set by get_buffer()\
  223. */\
  224. int age;\
  225. \
  226. /**\
  227. * is this picture used as reference\
  228. * - encoding: unused\
  229. * - decoding: set by lavc (before get_buffer() call))\
  230. */\
  231. int reference;\
  232. \
  233. /**\
  234. * QP table\
  235. * - encoding: unused\
  236. * - decoding: set by lavc\
  237. */\
  238. int8_t *qscale_table;\
  239. /**\
  240. * QP store stride\
  241. * - encoding: unused\
  242. * - decoding: set by lavc\
  243. */\
  244. int qstride;\
  245. \
  246. /**\
  247. * mbskip_table[mb]>=1 if MB didnt change\
  248. * stride= mb_width = (width+15)>>4\
  249. * - encoding: unused\
  250. * - decoding: set by lavc\
  251. */\
  252. uint8_t *mbskip_table;\
  253. \
  254. /**\
  255. * for some private data of the user\
  256. * - encoding: unused\
  257. * - decoding: set by user\
  258. */\
  259. void *opaque;\
  260. \
  261. /**\
  262. * error\
  263. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
  264. * - decoding: unused\
  265. */\
  266. uint64_t error[4];\
  267. \
  268. /**\
  269. * type of the buffer (to keep track of who has to dealloc data[*])\
  270. * - encoding: set by the one who allocs it\
  271. * - decoding: set by the one who allocs it\
  272. * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
  273. */\
  274. int type;\
  275. \
  276. /**\
  277. * when decoding, this signal how much the picture must be delayed.\
  278. * extra_delay = repeat_pict / (2*fps)\
  279. * - encoding: unused\
  280. * - decoding: set by lavc\
  281. */\
  282. int repeat_pict;
  283. #define FF_BUFFER_TYPE_INTERNAL 1
  284. #define FF_BUFFER_TYPE_USER 2 // Direct rendering buffers
  285. #define FF_BUFFER_TYPE_SHARED 4 // input frame for encoding(wont be dealloced)
  286. #define FF_I_TYPE 1 // Intra
  287. #define FF_P_TYPE 2 // Predicted
  288. #define FF_B_TYPE 3 // Bi-dir predicted
  289. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  290. typedef struct AVFrame {
  291. FF_COMMON_FRAME
  292. } AVFrame;
  293. /**
  294. * main external api structure.
  295. */
  296. typedef struct AVCodecContext {
  297. /**
  298. * the average bitrate.
  299. * - encoding: set by user. unused for constant quantizer encoding
  300. * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  301. */
  302. int bit_rate;
  303. /**
  304. * number of bits the bitstream is allowed to diverge from the reference.
  305. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  306. * - encoding: set by user. unused for constant quantizer encoding
  307. * - decoding: unused
  308. */
  309. int bit_rate_tolerance;
  310. /**
  311. * CODEC_FLAG_*.
  312. * - encoding: set by user.
  313. * - decoding: set by user.
  314. */
  315. int flags;
  316. /**
  317. * some codecs needs additionnal format info. It is stored here
  318. * - encoding: set by user.
  319. * - decoding: set by lavc. (FIXME is this ok?)
  320. */
  321. int sub_id;
  322. /**
  323. * motion estimation algorithm used for video coding.
  324. * - encoding: MUST be set by user.
  325. * - decoding: unused
  326. */
  327. int me_method;
  328. /**
  329. * some codecs need / can use extra-data like huffman tables.
  330. * mjpeg: huffman tables
  331. * rv10: additional flags
  332. * mpeg4: global headers (they can be in the bitstream or here)
  333. * - encoding: set/allocated/freed by lavc.
  334. * - decoding: set/allocated/freed by user.
  335. */
  336. void *extradata;
  337. int extradata_size;
  338. /* video only */
  339. /**
  340. * frames per sec multiplied by FRAME_RATE_BASE.
  341. * for variable fps this is the precission, so if the timestamps
  342. * can be specified in msec precssion then this is 1000*FRAME_RATE_BASE
  343. * - encoding: MUST be set by user
  344. * - decoding: set by lavc. 0 or the frame_rate if available
  345. */
  346. int frame_rate;
  347. /**
  348. * width / height.
  349. * - encoding: MUST be set by user.
  350. * - decoding: set by user, some codecs might override / change it during playback
  351. */
  352. int width, height;
  353. #define FF_ASPECT_SQUARE 1
  354. #define FF_ASPECT_4_3_625 2
  355. #define FF_ASPECT_4_3_525 3
  356. #define FF_ASPECT_16_9_625 4
  357. #define FF_ASPECT_16_9_525 5
  358. #define FF_ASPECT_EXTENDED 15
  359. /**
  360. * the number of pictures in a group of pitures, or 0 for intra_only.
  361. * - encoding: set by user.
  362. * - decoding: unused
  363. */
  364. int gop_size;
  365. /**
  366. * pixel format, see PIX_FMT_xxx.
  367. * - encoding: unused
  368. * - decoding: set by lavc.
  369. */
  370. enum PixelFormat pix_fmt;
  371. /**
  372. * Frame rate emulation. If not zero lower layer (i.e. format handler)
  373. * has to read frames at native frame rate.
  374. * - encoding: set by user.
  375. * - decoding: unused.
  376. */
  377. int rate_emu;
  378. /**
  379. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  380. * decoder to draw an horizontal band. It improve cache usage. Not
  381. * all codecs can do that. You must check the codec capabilities
  382. * before
  383. * - encoding: unused
  384. * - decoding: set by user.
  385. */
  386. void (*draw_horiz_band)(struct AVCodecContext *s,
  387. uint8_t **src_ptr, int linesize,
  388. int y, int width, int height);
  389. /* audio only */
  390. int sample_rate; ///< samples per sec
  391. int channels;
  392. int sample_fmt; ///< sample format, currenly unused
  393. /* the following data should not be initialized */
  394. int frame_size; ///< in samples, initialized when calling 'init'
  395. int frame_number; ///< audio or video frame number
  396. int real_pict_num; ///< returns the real picture number of previous encoded frame
  397. /**
  398. * number of frames the decoded output will be delayed relative to
  399. * the encoded input.
  400. * - encoding: set by lavc.
  401. * - decoding: unused
  402. */
  403. int delay;
  404. /* - encoding parameters */
  405. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  406. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  407. /**
  408. * minimum quantizer.
  409. * - encoding: set by user.
  410. * - decoding: unused
  411. */
  412. int qmin;
  413. /**
  414. * maximum quantizer.
  415. * - encoding: set by user.
  416. * - decoding: unused
  417. */
  418. int qmax;
  419. /**
  420. * maximum quantizer difference etween frames.
  421. * - encoding: set by user.
  422. * - decoding: unused
  423. */
  424. int max_qdiff;
  425. /**
  426. * maximum number of b frames between non b frames.
  427. * note: the output will be delayed by max_b_frames+1 relative to the input
  428. * - encoding: set by user.
  429. * - decoding: unused
  430. */
  431. int max_b_frames;
  432. /**
  433. * qscale factor between ip and b frames.
  434. * - encoding: set by user.
  435. * - decoding: unused
  436. */
  437. float b_quant_factor;
  438. /** obsolete FIXME remove */
  439. int rc_strategy;
  440. int b_frame_strategy;
  441. /**
  442. * hurry up amount.
  443. * - encoding: unused
  444. * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  445. */
  446. int hurry_up;
  447. struct AVCodec *codec;
  448. void *priv_data;
  449. /* The following data is for RTP friendly coding */
  450. /* By now only H.263/H.263+/MPEG4 coder honours this */
  451. int rtp_mode; /* 1 for activate RTP friendly-mode */
  452. /* highers numbers represent more error-prone */
  453. /* enviroments, by now just "1" exist */
  454. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  455. /* do it's best to deliver a chunk with size */
  456. /* below rtp_payload_size, the chunk will start */
  457. /* with a start code on some codecs like H.263 */
  458. /* This doesn't take account of any particular */
  459. /* headers inside the transmited RTP payload */
  460. /* The RTP callcack: This function is called */
  461. /* every time the encoder as a packet to send */
  462. /* Depends on the encoder if the data starts */
  463. /* with a Start Code (it should) H.263 does */
  464. void (*rtp_callback)(void *data, int size, int packet_number);
  465. /* statistics, used for 2-pass encoding */
  466. int mv_bits;
  467. int header_bits;
  468. int i_tex_bits;
  469. int p_tex_bits;
  470. int i_count;
  471. int p_count;
  472. int skip_count;
  473. int misc_bits;
  474. /**
  475. * number of bits used for the previously encoded frame.
  476. * - encoding: set by lavc
  477. * - decoding: unused
  478. */
  479. int frame_bits;
  480. /**
  481. * private data of the user, can be used to carry app specific stuff.
  482. * - encoding: set by user
  483. * - decoding: set by user
  484. */
  485. void *opaque;
  486. char codec_name[32];
  487. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  488. enum CodecID codec_id; /* see CODEC_ID_xxx */
  489. /**
  490. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  491. * this is used to workaround some encoder bugs
  492. * - encoding: unused
  493. * - decoding: set by user, will be converted to upper case by lavc during init
  494. */
  495. unsigned int codec_tag;
  496. /**
  497. * workaround bugs in encoders which sometimes cannot be detected automatically.
  498. * - encoding: unused
  499. * - decoding: set by user
  500. */
  501. int workaround_bugs;
  502. #define FF_BUG_AUTODETECT 1 ///< autodetection
  503. #define FF_BUG_OLD_MSMPEG4 2
  504. #define FF_BUG_XVID_ILACE 4
  505. #define FF_BUG_UMP4 8
  506. #define FF_BUG_NO_PADDING 16
  507. #define FF_BUG_AC_VLC 32
  508. #define FF_BUG_QPEL_CHROMA 64
  509. #define FF_BUG_STD_QPEL 128
  510. #define FF_BUG_QPEL_CHROMA2 256
  511. #define FF_BUG_DIRECT_BLOCKSIZE 512
  512. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  513. /**
  514. * luma single coeff elimination threshold.
  515. * - encoding: set by user
  516. * - decoding: unused
  517. */
  518. int luma_elim_threshold;
  519. /**
  520. * chroma single coeff elimination threshold.
  521. * - encoding: set by user
  522. * - decoding: unused
  523. */
  524. int chroma_elim_threshold;
  525. /**
  526. * strictly follow the std (MPEG4, ...).
  527. * - encoding: set by user
  528. * - decoding: unused
  529. */
  530. int strict_std_compliance;
  531. /**
  532. * qscale offset between ip and b frames.
  533. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  534. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  535. * - encoding: set by user.
  536. * - decoding: unused
  537. */
  538. float b_quant_offset;
  539. /**
  540. * error resilience higher values will detect more errors but may missdetect
  541. * some more or less valid parts as errors.
  542. * - encoding: unused
  543. * - decoding: set by user
  544. */
  545. int error_resilience;
  546. #define FF_ER_CAREFULL 1
  547. #define FF_ER_COMPLIANT 2
  548. #define FF_ER_AGGRESSIVE 3
  549. #define FF_ER_VERY_AGGRESSIVE 4
  550. /**
  551. * called at the beginning of each frame to get a buffer for it.
  552. * if pic.reference is set then the frame will be read later by lavc
  553. * - encoding: unused
  554. * - decoding: set by lavc, user can override
  555. */
  556. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  557. /**
  558. * called to release buffers which where allocated with get_buffer.
  559. * a released buffer can be reused in get_buffer()
  560. * pic.data[*] must be set to NULL
  561. * - encoding: unused
  562. * - decoding: set by lavc, user can override
  563. */
  564. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  565. /**
  566. * is 1 if the decoded stream contains b frames, 0 otherwise.
  567. * - encoding: unused
  568. * - decoding: set by lavc
  569. */
  570. int has_b_frames;
  571. int block_align; ///< used by some WAV based audio codecs
  572. int parse_only; /* - decoding only: if true, only parsing is done
  573. (function avcodec_parse_frame()). The frame
  574. data is returned. Only MPEG codecs support this now. */
  575. /**
  576. * 0-> h263 quant 1-> mpeg quant.
  577. * - encoding: set by user.
  578. * - decoding: unused
  579. */
  580. int mpeg_quant;
  581. /**
  582. * pass1 encoding statistics output buffer.
  583. * - encoding: set by lavc
  584. * - decoding: unused
  585. */
  586. char *stats_out;
  587. /**
  588. * pass2 encoding statistics input buffer.
  589. * concatenated stuff from stats_out of pass1 should be placed here
  590. * - encoding: allocated/set/freed by user
  591. * - decoding: unused
  592. */
  593. char *stats_in;
  594. /**
  595. * ratecontrol qmin qmax limiting method.
  596. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  597. * - encoding: set by user.
  598. * - decoding: unused
  599. */
  600. float rc_qsquish;
  601. float rc_qmod_amp;
  602. int rc_qmod_freq;
  603. /**
  604. * ratecontrol override, see RcOverride.
  605. * - encoding: allocated/set/freed by user.
  606. * - decoding: unused
  607. */
  608. RcOverride *rc_override;
  609. int rc_override_count;
  610. /**
  611. * rate control equation.
  612. * - encoding: set by user
  613. * - decoding: unused
  614. */
  615. char *rc_eq;
  616. /**
  617. * maximum bitrate.
  618. * - encoding: set by user.
  619. * - decoding: unused
  620. */
  621. int rc_max_rate;
  622. /**
  623. * minimum bitrate.
  624. * - encoding: set by user.
  625. * - decoding: unused
  626. */
  627. int rc_min_rate;
  628. /**
  629. * decoder bitstream buffer size.
  630. * - encoding: set by user.
  631. * - decoding: unused
  632. */
  633. int rc_buffer_size;
  634. float rc_buffer_aggressivity;
  635. /**
  636. * qscale factor between p and i frames.
  637. * - encoding: set by user.
  638. * - decoding: unused
  639. */
  640. float i_quant_factor;
  641. /**
  642. * qscale offset between p and i frames.
  643. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  644. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  645. * - encoding: set by user.
  646. * - decoding: unused
  647. */
  648. float i_quant_offset;
  649. /**
  650. * initial complexity for pass1 ratecontrol.
  651. * - encoding: set by user.
  652. * - decoding: unused
  653. */
  654. float rc_initial_cplx;
  655. /**
  656. * dct algorithm, see FF_DCT_* below.
  657. * - encoding: set by user
  658. * - decoding: unused
  659. */
  660. int dct_algo;
  661. #define FF_DCT_AUTO 0
  662. #define FF_DCT_FASTINT 1
  663. #define FF_DCT_INT 2
  664. #define FF_DCT_MMX 3
  665. #define FF_DCT_MLIB 4
  666. #define FF_DCT_ALTIVEC 5
  667. /**
  668. * luminance masking (0-> disabled).
  669. * - encoding: set by user
  670. * - decoding: unused
  671. */
  672. float lumi_masking;
  673. /**
  674. * temporary complexity masking (0-> disabled).
  675. * - encoding: set by user
  676. * - decoding: unused
  677. */
  678. float temporal_cplx_masking;
  679. /**
  680. * spatial complexity masking (0-> disabled).
  681. * - encoding: set by user
  682. * - decoding: unused
  683. */
  684. float spatial_cplx_masking;
  685. /**
  686. * p block masking (0-> disabled).
  687. * - encoding: set by user
  688. * - decoding: unused
  689. */
  690. float p_masking;
  691. /**
  692. * darkness masking (0-> disabled).
  693. * - encoding: set by user
  694. * - decoding: unused
  695. */
  696. float dark_masking;
  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 */