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.

1749 lines
50KB

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