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.

1773 lines
51KB

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