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.

1636 lines
46KB

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