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.

2201 lines
65KB

  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. #include "rational.h"
  12. #include <sys/types.h> /* size_t */
  13. #define FFMPEG_VERSION_INT 0x000408
  14. #define FFMPEG_VERSION "0.4.8"
  15. #define LIBAVCODEC_BUILD 4716
  16. #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
  17. #define LIBAVCODEC_VERSION FFMPEG_VERSION
  18. #define AV_STRINGIFY(s) AV_TOSTRING(s)
  19. #define AV_TOSTRING(s) #s
  20. #define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD)
  21. #define AV_NOPTS_VALUE int64_t_C(0x8000000000000000)
  22. #define AV_TIME_BASE 1000000
  23. enum CodecID {
  24. CODEC_ID_NONE,
  25. CODEC_ID_MPEG1VIDEO,
  26. CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
  27. CODEC_ID_MPEG2VIDEO_XVMC,
  28. CODEC_ID_H261,
  29. CODEC_ID_H263,
  30. CODEC_ID_RV10,
  31. CODEC_ID_RV20,
  32. CODEC_ID_MP2,
  33. CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
  34. CODEC_ID_VORBIS,
  35. CODEC_ID_AC3,
  36. CODEC_ID_MJPEG,
  37. CODEC_ID_MJPEGB,
  38. CODEC_ID_LJPEG,
  39. CODEC_ID_SP5X,
  40. CODEC_ID_MPEG4,
  41. CODEC_ID_RAWVIDEO,
  42. CODEC_ID_MSMPEG4V1,
  43. CODEC_ID_MSMPEG4V2,
  44. CODEC_ID_MSMPEG4V3,
  45. CODEC_ID_WMV1,
  46. CODEC_ID_WMV2,
  47. CODEC_ID_H263P,
  48. CODEC_ID_H263I,
  49. CODEC_ID_FLV1,
  50. CODEC_ID_SVQ1,
  51. CODEC_ID_SVQ3,
  52. CODEC_ID_DVVIDEO,
  53. CODEC_ID_DVAUDIO,
  54. CODEC_ID_WMAV1,
  55. CODEC_ID_WMAV2,
  56. CODEC_ID_MACE3,
  57. CODEC_ID_MACE6,
  58. CODEC_ID_HUFFYUV,
  59. CODEC_ID_CYUV,
  60. CODEC_ID_H264,
  61. CODEC_ID_INDEO3,
  62. CODEC_ID_VP3,
  63. CODEC_ID_THEORA,
  64. CODEC_ID_AAC,
  65. CODEC_ID_MPEG4AAC,
  66. CODEC_ID_ASV1,
  67. CODEC_ID_ASV2,
  68. CODEC_ID_FFV1,
  69. CODEC_ID_4XM,
  70. CODEC_ID_VCR1,
  71. CODEC_ID_CLJR,
  72. CODEC_ID_MDEC,
  73. CODEC_ID_ROQ,
  74. CODEC_ID_INTERPLAY_VIDEO,
  75. CODEC_ID_XAN_WC3,
  76. CODEC_ID_XAN_WC4,
  77. CODEC_ID_RPZA,
  78. CODEC_ID_CINEPAK,
  79. CODEC_ID_WS_VQA,
  80. CODEC_ID_MSRLE,
  81. CODEC_ID_MSVIDEO1,
  82. CODEC_ID_IDCIN,
  83. CODEC_ID_8BPS,
  84. CODEC_ID_SMC,
  85. CODEC_ID_FLIC,
  86. CODEC_ID_TRUEMOTION1,
  87. CODEC_ID_VMDVIDEO,
  88. CODEC_ID_VMDAUDIO,
  89. CODEC_ID_MSZH,
  90. CODEC_ID_ZLIB,
  91. CODEC_ID_QTRLE,
  92. /* various pcm "codecs" */
  93. CODEC_ID_PCM_S16LE,
  94. CODEC_ID_PCM_S16BE,
  95. CODEC_ID_PCM_U16LE,
  96. CODEC_ID_PCM_U16BE,
  97. CODEC_ID_PCM_S8,
  98. CODEC_ID_PCM_U8,
  99. CODEC_ID_PCM_MULAW,
  100. CODEC_ID_PCM_ALAW,
  101. /* various adpcm codecs */
  102. CODEC_ID_ADPCM_IMA_QT,
  103. CODEC_ID_ADPCM_IMA_WAV,
  104. CODEC_ID_ADPCM_IMA_DK3,
  105. CODEC_ID_ADPCM_IMA_DK4,
  106. CODEC_ID_ADPCM_IMA_WS,
  107. CODEC_ID_ADPCM_IMA_SMJPEG,
  108. CODEC_ID_ADPCM_MS,
  109. CODEC_ID_ADPCM_4XM,
  110. CODEC_ID_ADPCM_XA,
  111. CODEC_ID_ADPCM_ADX,
  112. CODEC_ID_ADPCM_EA,
  113. CODEC_ID_ADPCM_G726,
  114. /* AMR */
  115. CODEC_ID_AMR_NB,
  116. CODEC_ID_AMR_WB,
  117. /* RealAudio codecs*/
  118. CODEC_ID_RA_144,
  119. CODEC_ID_RA_288,
  120. /* various DPCM codecs */
  121. CODEC_ID_ROQ_DPCM,
  122. CODEC_ID_INTERPLAY_DPCM,
  123. CODEC_ID_XAN_DPCM,
  124. CODEC_ID_FLAC,
  125. CODEC_ID_MPEG2TS, /* _FAKE_ codec to indicate a raw MPEG2 transport
  126. stream (only used by libavformat) */
  127. };
  128. /* CODEC_ID_MP3LAME is absolete */
  129. #define CODEC_ID_MP3LAME CODEC_ID_MP3
  130. enum CodecType {
  131. CODEC_TYPE_UNKNOWN = -1,
  132. CODEC_TYPE_VIDEO,
  133. CODEC_TYPE_AUDIO,
  134. CODEC_TYPE_DATA,
  135. };
  136. /**
  137. * Pixel format. Notes:
  138. *
  139. * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA
  140. * color is put together as:
  141. * (A << 24) | (R << 16) | (G << 8) | B
  142. * This is stored as BGRA on little endian CPU architectures and ARGB on
  143. * big endian CPUs.
  144. *
  145. * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
  146. * image data is stored in AVFrame.data[0]. The palette is transported in
  147. * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
  148. * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
  149. * also endian-specific). Note also that the individual RGB palette
  150. * components stored in AVFrame.data[1] should be in the range 0..255.
  151. * This is important as many custom PAL8 video codecs that were designed
  152. * to run on the IBM VGA graphics adapter use 6-bit palette components.
  153. */
  154. enum PixelFormat {
  155. PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples)
  156. PIX_FMT_YUV422,
  157. PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB...
  158. PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR...
  159. PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
  160. PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
  161. PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
  162. PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
  163. PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
  164. PIX_FMT_RGB565, ///< always stored in cpu endianness
  165. PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
  166. PIX_FMT_GRAY8,
  167. PIX_FMT_MONOWHITE, ///< 0 is white
  168. PIX_FMT_MONOBLACK, ///< 0 is black
  169. PIX_FMT_PAL8, ///< 8 bit with RGBA palette
  170. PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg)
  171. PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg)
  172. PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg)
  173. PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
  174. PIX_FMT_XVMC_MPEG2_IDCT,
  175. PIX_FMT_NB,
  176. };
  177. /* currently unused, may be used if 24/32 bits samples ever supported */
  178. enum SampleFormat {
  179. SAMPLE_FMT_S16 = 0, ///< signed 16 bits
  180. };
  181. /* in bytes */
  182. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
  183. /**
  184. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  185. * this is mainly needed because some optimized bitstream readers read
  186. * 32 or 64 bit at once and could read over the end<br>
  187. * Note, if the first 23 bits of the additional bytes are not 0 then damaged
  188. * MPEG bitstreams could cause overread and segfault
  189. */
  190. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  191. /* motion estimation type, EPZS by default */
  192. enum Motion_Est_ID {
  193. ME_ZERO = 1,
  194. ME_FULL,
  195. ME_LOG,
  196. ME_PHODS,
  197. ME_EPZS,
  198. ME_X1
  199. };
  200. typedef struct RcOverride{
  201. int start_frame;
  202. int end_frame;
  203. int qscale; // if this is 0 then quality_factor will be used instead
  204. float quality_factor;
  205. } RcOverride;
  206. /* only for ME compatiblity with old apps */
  207. extern int motion_estimation_method;
  208. #define FF_MAX_B_FRAMES 8
  209. /* encoding support
  210. these flags can be passed in AVCodecContext.flags before initing
  211. Note: note not everything is supported yet
  212. */
  213. #define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
  214. #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / Advanced prediction for H263
  215. #define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
  216. #define CODEC_FLAG_GMC 0x0020 ///< use GMC
  217. #define CODEC_FLAG_MV0 0x0040 ///< always try a MB with MV=<0,0>
  218. #define CODEC_FLAG_PART 0x0080 ///< use data partitioning
  219. /* parent program gurantees that the input for b-frame containing streams is not written to
  220. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  221. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  222. #define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
  223. #define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
  224. #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
  225. #define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
  226. #define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges
  227. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
  228. #define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
  229. of only at frame boundaries */
  230. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
  231. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
  232. #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay
  233. #define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
  234. #define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
  235. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
  236. #define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
  237. /* Fx : Flag for h263+ extra options */
  238. #define CODEC_FLAG_H263P_AIC 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction (remove this)
  239. #define CODEC_FLAG_AC_PRED 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction
  240. #define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
  241. #define CODEC_FLAG_CBP_RD 0x04000000 ///< use rate distortion optimization for cbp
  242. #define CODEC_FLAG_QP_RD 0x08000000 ///< use rate distortion optimization for qp selectioon
  243. #define CODEC_FLAG_H263P_AIV 0x00000008 ///< H263 Alternative inter vlc
  244. #define CODEC_FLAG_OBMC 0x00000001 ///< OBMC
  245. #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter
  246. #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000
  247. #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation
  248. #define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data
  249. #define CODEC_FLAG_CLOSED_GOP 0x80000000
  250. /* Unsupported options :
  251. * Syntax Arithmetic coding (SAC)
  252. * Reference Picture Selection
  253. * Independant Segment Decoding */
  254. /* /Fx */
  255. /* codec capabilities */
  256. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback
  257. /**
  258. * Codec uses get_buffer() for allocating buffers.
  259. * direct rendering method 1
  260. */
  261. #define CODEC_CAP_DR1 0x0002
  262. /* if 'parse_only' field is true, then avcodec_parse_frame() can be
  263. used */
  264. #define CODEC_CAP_PARSE_ONLY 0x0004
  265. #define CODEC_CAP_TRUNCATED 0x0008
  266. /* codec can export data for HW decoding (XvMC) */
  267. #define CODEC_CAP_HWACCEL 0x0010
  268. //the following defines might change, so dont expect compatibility if u use them
  269. #define MB_TYPE_INTRA4x4 0x0001
  270. #define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific
  271. #define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific
  272. #define MB_TYPE_16x16 0x0008
  273. #define MB_TYPE_16x8 0x0010
  274. #define MB_TYPE_8x16 0x0020
  275. #define MB_TYPE_8x8 0x0040
  276. #define MB_TYPE_INTERLACED 0x0080
  277. #define MB_TYPE_DIRECT2 0x0100 //FIXME
  278. #define MB_TYPE_ACPRED 0x0200
  279. #define MB_TYPE_GMC 0x0400
  280. #define MB_TYPE_SKIP 0x0800
  281. #define MB_TYPE_P0L0 0x1000
  282. #define MB_TYPE_P1L0 0x2000
  283. #define MB_TYPE_P0L1 0x4000
  284. #define MB_TYPE_P1L1 0x8000
  285. #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
  286. #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
  287. #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
  288. #define MB_TYPE_QUANT 0x00010000
  289. #define MB_TYPE_CBP 0x00020000
  290. //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...)
  291. /**
  292. * Pan Scan area.
  293. * this specifies the area which should be displayed. Note there may be multiple such areas for one frame
  294. */
  295. typedef struct AVPanScan{
  296. /**
  297. * id.
  298. * - encoding: set by user.
  299. * - decoding: set by lavc
  300. */
  301. int id;
  302. /**
  303. * width and height in 1/16 pel
  304. * - encoding: set by user.
  305. * - decoding: set by lavc
  306. */
  307. int width;
  308. int height;
  309. /**
  310. * position of the top left corner in 1/16 pel for up to 3 fields/frames.
  311. * - encoding: set by user.
  312. * - decoding: set by lavc
  313. */
  314. int16_t position[3][2];
  315. }AVPanScan;
  316. #define FF_COMMON_FRAME \
  317. /**\
  318. * pointer to the picture planes.\
  319. * this might be different from the first allocated byte\
  320. * - encoding: \
  321. * - decoding: \
  322. */\
  323. uint8_t *data[4];\
  324. int linesize[4];\
  325. /**\
  326. * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
  327. * this isnt used by lavc unless the default get/release_buffer() is used\
  328. * - encoding: \
  329. * - decoding: \
  330. */\
  331. uint8_t *base[4];\
  332. /**\
  333. * 1 -> keyframe, 0-> not\
  334. * - encoding: set by lavc\
  335. * - decoding: set by lavc\
  336. */\
  337. int key_frame;\
  338. \
  339. /**\
  340. * picture type of the frame, see ?_TYPE below.\
  341. * - encoding: set by lavc for coded_picture (and set by user for input)\
  342. * - decoding: set by lavc\
  343. */\
  344. int pict_type;\
  345. \
  346. /**\
  347. * presentation timestamp in AV_TIME_BASE (=micro seconds currently) (time when frame should be shown to user)\
  348. * if AV_NOPTS_VALUE then the frame_rate will be used as reference\
  349. * - encoding: MUST be set by user\
  350. * - decoding: set by lavc\
  351. */\
  352. int64_t pts;\
  353. \
  354. /**\
  355. * picture number in bitstream order.\
  356. * - encoding: set by\
  357. * - decoding: set by lavc\
  358. */\
  359. int coded_picture_number;\
  360. /**\
  361. * picture number in display order.\
  362. * - encoding: set by\
  363. * - decoding: set by lavc\
  364. */\
  365. int display_picture_number;\
  366. \
  367. /**\
  368. * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \
  369. * - encoding: set by lavc for coded_picture (and set by user for input)\
  370. * - decoding: set by lavc\
  371. */\
  372. int quality; \
  373. \
  374. /**\
  375. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  376. * set to INT_MAX if the buffer has not been used yet \
  377. * - encoding: unused\
  378. * - decoding: MUST be set by get_buffer()\
  379. */\
  380. int age;\
  381. \
  382. /**\
  383. * is this picture used as reference\
  384. * - encoding: unused\
  385. * - decoding: set by lavc (before get_buffer() call))\
  386. */\
  387. int reference;\
  388. \
  389. /**\
  390. * QP table\
  391. * - encoding: unused\
  392. * - decoding: set by lavc\
  393. */\
  394. int8_t *qscale_table;\
  395. /**\
  396. * QP store stride\
  397. * - encoding: unused\
  398. * - decoding: set by lavc\
  399. */\
  400. int qstride;\
  401. \
  402. /**\
  403. * mbskip_table[mb]>=1 if MB didnt change\
  404. * stride= mb_width = (width+15)>>4\
  405. * - encoding: unused\
  406. * - decoding: set by lavc\
  407. */\
  408. uint8_t *mbskip_table;\
  409. \
  410. /**\
  411. * Motion vector table\
  412. * - encoding: set by user\
  413. * - decoding: set by lavc\
  414. */\
  415. int16_t (*motion_val[2])[2];\
  416. \
  417. /**\
  418. * Macroblock type table\
  419. * mb_type_base + mb_width + 2\
  420. * - encoding: set by user\
  421. * - decoding: set by lavc\
  422. */\
  423. uint32_t *mb_type;\
  424. \
  425. /**\
  426. * Macroblock size: (0->16x16, 1->8x8, 2-> 4x4, 3-> 2x2)\
  427. * - encoding: unused\
  428. * - decoding: set by lavc\
  429. */\
  430. uint8_t motion_subsample_log2;\
  431. \
  432. /**\
  433. * for some private data of the user\
  434. * - encoding: unused\
  435. * - decoding: set by user\
  436. */\
  437. void *opaque;\
  438. \
  439. /**\
  440. * error\
  441. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
  442. * - decoding: unused\
  443. */\
  444. uint64_t error[4];\
  445. \
  446. /**\
  447. * type of the buffer (to keep track of who has to dealloc data[*])\
  448. * - encoding: set by the one who allocs it\
  449. * - decoding: set by the one who allocs it\
  450. * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
  451. */\
  452. int type;\
  453. \
  454. /**\
  455. * when decoding, this signal how much the picture must be delayed.\
  456. * extra_delay = repeat_pict / (2*fps)\
  457. * - encoding: unused\
  458. * - decoding: set by lavc\
  459. */\
  460. int repeat_pict;\
  461. \
  462. /**\
  463. * \
  464. */\
  465. int qscale_type;\
  466. \
  467. /**\
  468. * The content of the picture is interlaced.\
  469. * - encoding: set by user\
  470. * - decoding: set by lavc (default 0)\
  471. */\
  472. int interlaced_frame;\
  473. \
  474. /**\
  475. * if the content is interlaced, is top field displayed first.\
  476. * - encoding: set by user\
  477. * - decoding: set by lavc\
  478. */\
  479. int top_field_first;\
  480. \
  481. /**\
  482. * Pan scan.\
  483. * - encoding: set by user\
  484. * - decoding: set by lavc\
  485. */\
  486. AVPanScan *pan_scan;\
  487. \
  488. /**\
  489. * tell user application that palette has changed from previous frame.\
  490. * - encoding: ??? (no palette-enabled encoder yet)\
  491. * - decoding: set by lavc (default 0)\
  492. */\
  493. int palette_has_changed;\
  494. \
  495. /**\
  496. * Codec suggestion on buffer type if != 0\
  497. * - encoding: unused\
  498. * - decoding: set by lavc (before get_buffer() call))\
  499. */\
  500. int buffer_hints;\
  501. \
  502. /**\
  503. * DCT coeffitients\
  504. * - encoding: unused\
  505. * - decoding: set by lavc\
  506. */\
  507. short *dct_coeff;\
  508. \
  509. /**\
  510. * Motion referece frame index\
  511. * - encoding: set by user\
  512. * - decoding: set by lavc\
  513. */\
  514. int8_t *ref_index[2];
  515. #define FF_QSCALE_TYPE_MPEG1 0
  516. #define FF_QSCALE_TYPE_MPEG2 1
  517. #define FF_BUFFER_TYPE_INTERNAL 1
  518. #define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user)
  519. #define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base), all other tables are not shared
  520. #define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything
  521. #define FF_I_TYPE 1 // Intra
  522. #define FF_P_TYPE 2 // Predicted
  523. #define FF_B_TYPE 3 // Bi-dir predicted
  524. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  525. #define FF_SI_TYPE 5
  526. #define FF_SP_TYPE 6
  527. #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore)
  528. #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer
  529. #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content
  530. #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update)
  531. /**
  532. * Audio Video Frame.
  533. */
  534. typedef struct AVFrame {
  535. FF_COMMON_FRAME
  536. } AVFrame;
  537. #define DEFAULT_FRAME_RATE_BASE 1001000
  538. /**
  539. * Used by av_log
  540. */
  541. typedef struct AVCLASS AVClass;
  542. struct AVCLASS {
  543. const char* class_name;
  544. const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
  545. or AVFormatContext, which begin with an AVClass.
  546. Needed because av_log is in libavcodec and has no visibility
  547. of AVIn/OutputFormat */
  548. };
  549. /**
  550. * main external api structure.
  551. */
  552. typedef struct AVCodecContext {
  553. /**
  554. * Info on struct for av_log
  555. * - set by avcodec_alloc_context
  556. */
  557. AVClass *av_class;
  558. /**
  559. * the average bitrate.
  560. * - encoding: set by user. unused for constant quantizer encoding
  561. * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  562. */
  563. int bit_rate;
  564. /**
  565. * number of bits the bitstream is allowed to diverge from the reference.
  566. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  567. * - encoding: set by user. unused for constant quantizer encoding
  568. * - decoding: unused
  569. */
  570. int bit_rate_tolerance;
  571. /**
  572. * CODEC_FLAG_*.
  573. * - encoding: set by user.
  574. * - decoding: set by user.
  575. */
  576. int flags;
  577. /**
  578. * some codecs needs additionnal format info. It is stored here
  579. * - encoding: set by user.
  580. * - decoding: set by lavc. (FIXME is this ok?)
  581. */
  582. int sub_id;
  583. /**
  584. * motion estimation algorithm used for video coding.
  585. * - encoding: MUST be set by user.
  586. * - decoding: unused
  587. */
  588. int me_method;
  589. /**
  590. * some codecs need / can use extra-data like huffman tables.
  591. * mjpeg: huffman tables
  592. * rv10: additional flags
  593. * mpeg4: global headers (they can be in the bitstream or here)
  594. * - encoding: set/allocated/freed by lavc.
  595. * - decoding: set/allocated/freed by user.
  596. */
  597. void *extradata;
  598. int extradata_size;
  599. /* video only */
  600. /**
  601. * frames per sec multiplied by frame_rate_base.
  602. * for variable fps this is the precission, so if the timestamps
  603. * can be specified in msec precssion then this is 1000*frame_rate_base
  604. * - encoding: MUST be set by user
  605. * - decoding: set by lavc. 0 or the frame_rate if available
  606. */
  607. int frame_rate;
  608. /**
  609. * width / height.
  610. * - encoding: MUST be set by user.
  611. * - decoding: set by user if known, codec should override / dynamically change if needed
  612. */
  613. int width, height;
  614. #define FF_ASPECT_EXTENDED 15
  615. /**
  616. * the number of pictures in a group of pitures, or 0 for intra_only.
  617. * - encoding: set by user.
  618. * - decoding: unused
  619. */
  620. int gop_size;
  621. /**
  622. * pixel format, see PIX_FMT_xxx.
  623. * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt
  624. * conversion is in order. This only works for
  625. * codecs with one supported pix_fmt, we should
  626. * do something for a generic case as well.
  627. * - decoding: set by lavc.
  628. */
  629. enum PixelFormat pix_fmt;
  630. /**
  631. * Frame rate emulation. If not zero lower layer (i.e. format handler)
  632. * has to read frames at native frame rate.
  633. * - encoding: set by user.
  634. * - decoding: unused.
  635. */
  636. int rate_emu;
  637. /**
  638. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  639. * decoder to draw an horizontal band. It improve cache usage. Not
  640. * all codecs can do that. You must check the codec capabilities
  641. * before
  642. * - encoding: unused
  643. * - decoding: set by user.
  644. * @param height the height of the slice
  645. * @param y the y position of the slice
  646. * @param type 1->top field, 2->bottom field, 3->frame
  647. * @param offset offset into the AVFrame.data from which the slice should be read
  648. */
  649. void (*draw_horiz_band)(struct AVCodecContext *s,
  650. const AVFrame *src, int offset[4],
  651. int y, int type, int height);
  652. /* audio only */
  653. int sample_rate; ///< samples per sec
  654. int channels;
  655. int sample_fmt; ///< sample format, currenly unused
  656. /* the following data should not be initialized */
  657. int frame_size; ///< in samples, initialized when calling 'init'
  658. int frame_number; ///< audio or video frame number
  659. int real_pict_num; ///< returns the real picture number of previous encoded frame
  660. /**
  661. * number of frames the decoded output will be delayed relative to
  662. * the encoded input.
  663. * - encoding: set by lavc.
  664. * - decoding: unused
  665. */
  666. int delay;
  667. /* - encoding parameters */
  668. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  669. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  670. /**
  671. * minimum quantizer.
  672. * - encoding: set by user.
  673. * - decoding: unused
  674. */
  675. int qmin;
  676. /**
  677. * maximum quantizer.
  678. * - encoding: set by user.
  679. * - decoding: unused
  680. */
  681. int qmax;
  682. /**
  683. * maximum quantizer difference etween frames.
  684. * - encoding: set by user.
  685. * - decoding: unused
  686. */
  687. int max_qdiff;
  688. /**
  689. * maximum number of b frames between non b frames.
  690. * note: the output will be delayed by max_b_frames+1 relative to the input
  691. * - encoding: set by user.
  692. * - decoding: unused
  693. */
  694. int max_b_frames;
  695. /**
  696. * qscale factor between ip and b frames.
  697. * - encoding: set by user.
  698. * - decoding: unused
  699. */
  700. float b_quant_factor;
  701. /** obsolete FIXME remove */
  702. int rc_strategy;
  703. int b_frame_strategy;
  704. /**
  705. * hurry up amount.
  706. * - encoding: unused
  707. * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  708. */
  709. int hurry_up;
  710. struct AVCodec *codec;
  711. void *priv_data;
  712. /* unused, FIXME remove*/
  713. int rtp_mode;
  714. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  715. /* do it's best to deliver a chunk with size */
  716. /* below rtp_payload_size, the chunk will start */
  717. /* with a start code on some codecs like H.263 */
  718. /* This doesn't take account of any particular */
  719. /* headers inside the transmited RTP payload */
  720. /* The RTP callcack: This function is called */
  721. /* every time the encoder as a packet to send */
  722. /* Depends on the encoder if the data starts */
  723. /* with a Start Code (it should) H.263 does */
  724. void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int packet_number);
  725. /* statistics, used for 2-pass encoding */
  726. int mv_bits;
  727. int header_bits;
  728. int i_tex_bits;
  729. int p_tex_bits;
  730. int i_count;
  731. int p_count;
  732. int skip_count;
  733. int misc_bits;
  734. /**
  735. * number of bits used for the previously encoded frame.
  736. * - encoding: set by lavc
  737. * - decoding: unused
  738. */
  739. int frame_bits;
  740. /**
  741. * private data of the user, can be used to carry app specific stuff.
  742. * - encoding: set by user
  743. * - decoding: set by user
  744. */
  745. void *opaque;
  746. char codec_name[32];
  747. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  748. enum CodecID codec_id; /* see CODEC_ID_xxx */
  749. /**
  750. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  751. * this is used to workaround some encoder bugs
  752. * - encoding: set by user, if not then the default based on codec_id will be used
  753. * - decoding: set by user, will be converted to upper case by lavc during init
  754. */
  755. unsigned int codec_tag;
  756. /**
  757. * workaround bugs in encoders which sometimes cannot be detected automatically.
  758. * - encoding: unused
  759. * - decoding: set by user
  760. */
  761. int workaround_bugs;
  762. #define FF_BUG_AUTODETECT 1 ///< autodetection
  763. #define FF_BUG_OLD_MSMPEG4 2
  764. #define FF_BUG_XVID_ILACE 4
  765. #define FF_BUG_UMP4 8
  766. #define FF_BUG_NO_PADDING 16
  767. #define FF_BUG_AMV 32
  768. #define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default
  769. #define FF_BUG_QPEL_CHROMA 64
  770. #define FF_BUG_STD_QPEL 128
  771. #define FF_BUG_QPEL_CHROMA2 256
  772. #define FF_BUG_DIRECT_BLOCKSIZE 512
  773. #define FF_BUG_EDGE 1024
  774. #define FF_BUG_HPEL_CHROMA 2048
  775. #define FF_BUG_DC_CLIP 4096
  776. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  777. /**
  778. * luma single coeff elimination threshold.
  779. * - encoding: set by user
  780. * - decoding: unused
  781. */
  782. int luma_elim_threshold;
  783. /**
  784. * chroma single coeff elimination threshold.
  785. * - encoding: set by user
  786. * - decoding: unused
  787. */
  788. int chroma_elim_threshold;
  789. /**
  790. * strictly follow the std (MPEG4, ...).
  791. * - encoding: set by user
  792. * - decoding: unused
  793. */
  794. int strict_std_compliance;
  795. /**
  796. * qscale offset between ip and b frames.
  797. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  798. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  799. * - encoding: set by user.
  800. * - decoding: unused
  801. */
  802. float b_quant_offset;
  803. /**
  804. * error resilience higher values will detect more errors but may missdetect
  805. * some more or less valid parts as errors.
  806. * - encoding: unused
  807. * - decoding: set by user
  808. */
  809. int error_resilience;
  810. #define FF_ER_CAREFULL 1
  811. #define FF_ER_COMPLIANT 2
  812. #define FF_ER_AGGRESSIVE 3
  813. #define FF_ER_VERY_AGGRESSIVE 4
  814. /**
  815. * called at the beginning of each frame to get a buffer for it.
  816. * if pic.reference is set then the frame will be read later by lavc
  817. * avcodec_align_dimensions() should be used to find the required width and
  818. * height, as they normally need to be rounded up to the next multiple of 16
  819. * - encoding: unused
  820. * - decoding: set by lavc, user can override
  821. */
  822. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  823. /**
  824. * called to release buffers which where allocated with get_buffer.
  825. * a released buffer can be reused in get_buffer()
  826. * pic.data[*] must be set to NULL
  827. * - encoding: unused
  828. * - decoding: set by lavc, user can override
  829. */
  830. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  831. /**
  832. * if 1 the stream has a 1 frame delay during decoding.
  833. * - encoding: set by lavc
  834. * - decoding: set by lavc
  835. */
  836. int has_b_frames;
  837. int block_align; ///< used by some WAV based audio codecs
  838. int parse_only; /* - decoding only: if true, only parsing is done
  839. (function avcodec_parse_frame()). The frame
  840. data is returned. Only MPEG codecs support this now. */
  841. /**
  842. * 0-> h263 quant 1-> mpeg quant.
  843. * - encoding: set by user.
  844. * - decoding: unused
  845. */
  846. int mpeg_quant;
  847. /**
  848. * pass1 encoding statistics output buffer.
  849. * - encoding: set by lavc
  850. * - decoding: unused
  851. */
  852. char *stats_out;
  853. /**
  854. * pass2 encoding statistics input buffer.
  855. * concatenated stuff from stats_out of pass1 should be placed here
  856. * - encoding: allocated/set/freed by user
  857. * - decoding: unused
  858. */
  859. char *stats_in;
  860. /**
  861. * ratecontrol qmin qmax limiting method.
  862. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  863. * - encoding: set by user.
  864. * - decoding: unused
  865. */
  866. float rc_qsquish;
  867. float rc_qmod_amp;
  868. int rc_qmod_freq;
  869. /**
  870. * ratecontrol override, see RcOverride.
  871. * - encoding: allocated/set/freed by user.
  872. * - decoding: unused
  873. */
  874. RcOverride *rc_override;
  875. int rc_override_count;
  876. /**
  877. * rate control equation.
  878. * - encoding: set by user
  879. * - decoding: unused
  880. */
  881. char *rc_eq;
  882. /**
  883. * maximum bitrate.
  884. * - encoding: set by user.
  885. * - decoding: unused
  886. */
  887. int rc_max_rate;
  888. /**
  889. * minimum bitrate.
  890. * - encoding: set by user.
  891. * - decoding: unused
  892. */
  893. int rc_min_rate;
  894. /**
  895. * decoder bitstream buffer size.
  896. * - encoding: set by user.
  897. * - decoding: unused
  898. */
  899. int rc_buffer_size;
  900. float rc_buffer_aggressivity;
  901. /**
  902. * qscale factor between p and i frames.
  903. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  904. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  905. * - encoding: set by user.
  906. * - decoding: unused
  907. */
  908. float i_quant_factor;
  909. /**
  910. * qscale offset between p and i frames.
  911. * - encoding: set by user.
  912. * - decoding: unused
  913. */
  914. float i_quant_offset;
  915. /**
  916. * initial complexity for pass1 ratecontrol.
  917. * - encoding: set by user.
  918. * - decoding: unused
  919. */
  920. float rc_initial_cplx;
  921. /**
  922. * dct algorithm, see FF_DCT_* below.
  923. * - encoding: set by user
  924. * - decoding: unused
  925. */
  926. int dct_algo;
  927. #define FF_DCT_AUTO 0
  928. #define FF_DCT_FASTINT 1
  929. #define FF_DCT_INT 2
  930. #define FF_DCT_MMX 3
  931. #define FF_DCT_MLIB 4
  932. #define FF_DCT_ALTIVEC 5
  933. #define FF_DCT_FAAN 6
  934. /**
  935. * luminance masking (0-> disabled).
  936. * - encoding: set by user
  937. * - decoding: unused
  938. */
  939. float lumi_masking;
  940. /**
  941. * temporary complexity masking (0-> disabled).
  942. * - encoding: set by user
  943. * - decoding: unused
  944. */
  945. float temporal_cplx_masking;
  946. /**
  947. * spatial complexity masking (0-> disabled).
  948. * - encoding: set by user
  949. * - decoding: unused
  950. */
  951. float spatial_cplx_masking;
  952. /**
  953. * p block masking (0-> disabled).
  954. * - encoding: set by user
  955. * - decoding: unused
  956. */
  957. float p_masking;
  958. /**
  959. * darkness masking (0-> disabled).
  960. * - encoding: set by user
  961. * - decoding: unused
  962. */
  963. float dark_masking;
  964. /* for binary compatibility */
  965. int unused;
  966. /**
  967. * idct algorithm, see FF_IDCT_* below.
  968. * - encoding: set by user
  969. * - decoding: set by user
  970. */
  971. int idct_algo;
  972. #define FF_IDCT_AUTO 0
  973. #define FF_IDCT_INT 1
  974. #define FF_IDCT_SIMPLE 2
  975. #define FF_IDCT_SIMPLEMMX 3
  976. #define FF_IDCT_LIBMPEG2MMX 4
  977. #define FF_IDCT_PS2 5
  978. #define FF_IDCT_MLIB 6
  979. #define FF_IDCT_ARM 7
  980. #define FF_IDCT_ALTIVEC 8
  981. #define FF_IDCT_SH4 9
  982. #define FF_IDCT_SIMPLEARM 10
  983. /**
  984. * slice count.
  985. * - encoding: set by lavc
  986. * - decoding: set by user (or 0)
  987. */
  988. int slice_count;
  989. /**
  990. * slice offsets in the frame in bytes.
  991. * - encoding: set/allocated by lavc
  992. * - decoding: set/allocated by user (or NULL)
  993. */
  994. int *slice_offset;
  995. /**
  996. * error concealment flags.
  997. * - encoding: unused
  998. * - decoding: set by user
  999. */
  1000. int error_concealment;
  1001. #define FF_EC_GUESS_MVS 1
  1002. #define FF_EC_DEBLOCK 2
  1003. /**
  1004. * dsp_mask could be add used to disable unwanted CPU features
  1005. * CPU features (i.e. MMX, SSE. ...)
  1006. *
  1007. * with FORCE flag you may instead enable given CPU features
  1008. * (Dangerous: usable in case of misdetection, improper usage however will
  1009. * result into program crash)
  1010. */
  1011. unsigned dsp_mask;
  1012. #define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
  1013. /* lower 16 bits - CPU features */
  1014. #ifdef HAVE_MMX
  1015. #define FF_MM_MMX 0x0001 /* standard MMX */
  1016. #define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
  1017. #define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
  1018. #define FF_MM_SSE 0x0008 /* SSE functions */
  1019. #define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
  1020. #endif /* HAVE_MMX */
  1021. /**
  1022. * bits per sample/pixel from the demuxer (needed for huffyuv).
  1023. * - encoding: set by lavc
  1024. * - decoding: set by user
  1025. */
  1026. int bits_per_sample;
  1027. /**
  1028. * prediction method (needed for huffyuv).
  1029. * - encoding: set by user
  1030. * - decoding: unused
  1031. */
  1032. int prediction_method;
  1033. #define FF_PRED_LEFT 0
  1034. #define FF_PRED_PLANE 1
  1035. #define FF_PRED_MEDIAN 2
  1036. /**
  1037. * sample aspect ratio (0 if unknown).
  1038. * numerator and denominator must be relative prime and smaller then 256 for some video standards
  1039. * - encoding: set by user.
  1040. * - decoding: set by lavc.
  1041. */
  1042. AVRational sample_aspect_ratio;
  1043. /**
  1044. * the picture in the bitstream.
  1045. * - encoding: set by lavc
  1046. * - decoding: set by lavc
  1047. */
  1048. AVFrame *coded_frame;
  1049. /**
  1050. * debug.
  1051. * - encoding: set by user.
  1052. * - decoding: set by user.
  1053. */
  1054. int debug;
  1055. #define FF_DEBUG_PICT_INFO 1
  1056. #define FF_DEBUG_RC 2
  1057. #define FF_DEBUG_BITSTREAM 4
  1058. #define FF_DEBUG_MB_TYPE 8
  1059. #define FF_DEBUG_QP 16
  1060. #define FF_DEBUG_MV 32
  1061. #define FF_DEBUG_DCT_COEFF 0x00000040
  1062. #define FF_DEBUG_SKIP 0x00000080
  1063. #define FF_DEBUG_STARTCODE 0x00000100
  1064. #define FF_DEBUG_PTS 0x00000200
  1065. #define FF_DEBUG_ER 0x00000400
  1066. #define FF_DEBUG_MMCO 0x00000800
  1067. #define FF_DEBUG_BUGS 0x00001000
  1068. #define FF_DEBUG_VIS_QP 0x00002000
  1069. #define FF_DEBUG_VIS_MB_TYPE 0x00004000
  1070. /**
  1071. * debug.
  1072. * - encoding: set by user.
  1073. * - decoding: set by user.
  1074. */
  1075. int debug_mv;
  1076. #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames
  1077. #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames
  1078. #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames
  1079. /**
  1080. * error.
  1081. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
  1082. * - decoding: unused
  1083. */
  1084. uint64_t error[4];
  1085. /**
  1086. * minimum MB quantizer.
  1087. * - encoding: set by user.
  1088. * - decoding: unused
  1089. */
  1090. int mb_qmin;
  1091. /**
  1092. * maximum MB quantizer.
  1093. * - encoding: set by user.
  1094. * - decoding: unused
  1095. */
  1096. int mb_qmax;
  1097. /**
  1098. * motion estimation compare function.
  1099. * - encoding: set by user.
  1100. * - decoding: unused
  1101. */
  1102. int me_cmp;
  1103. /**
  1104. * subpixel motion estimation compare function.
  1105. * - encoding: set by user.
  1106. * - decoding: unused
  1107. */
  1108. int me_sub_cmp;
  1109. /**
  1110. * macroblock compare function (not supported yet).
  1111. * - encoding: set by user.
  1112. * - decoding: unused
  1113. */
  1114. int mb_cmp;
  1115. /**
  1116. * interlaced dct compare function
  1117. * - encoding: set by user.
  1118. * - decoding: unused
  1119. */
  1120. int ildct_cmp;
  1121. #define FF_CMP_SAD 0
  1122. #define FF_CMP_SSE 1
  1123. #define FF_CMP_SATD 2
  1124. #define FF_CMP_DCT 3
  1125. #define FF_CMP_PSNR 4
  1126. #define FF_CMP_BIT 5
  1127. #define FF_CMP_RD 6
  1128. #define FF_CMP_ZERO 7
  1129. #define FF_CMP_VSAD 8
  1130. #define FF_CMP_VSSE 9
  1131. #define FF_CMP_NSSE 10
  1132. #define FF_CMP_CHROMA 256
  1133. /**
  1134. * ME diamond size & shape.
  1135. * - encoding: set by user.
  1136. * - decoding: unused
  1137. */
  1138. int dia_size;
  1139. /**
  1140. * amount of previous MV predictors (2a+1 x 2a+1 square).
  1141. * - encoding: set by user.
  1142. * - decoding: unused
  1143. */
  1144. int last_predictor_count;
  1145. /**
  1146. * pre pass for motion estimation.
  1147. * - encoding: set by user.
  1148. * - decoding: unused
  1149. */
  1150. int pre_me;
  1151. /**
  1152. * motion estimation pre pass compare function.
  1153. * - encoding: set by user.
  1154. * - decoding: unused
  1155. */
  1156. int me_pre_cmp;
  1157. /**
  1158. * ME pre pass diamond size & shape.
  1159. * - encoding: set by user.
  1160. * - decoding: unused
  1161. */
  1162. int pre_dia_size;
  1163. /**
  1164. * subpel ME quality.
  1165. * - encoding: set by user.
  1166. * - decoding: unused
  1167. */
  1168. int me_subpel_quality;
  1169. /**
  1170. * callback to negotiate the pixelFormat.
  1171. * @param fmt is the list of formats which are supported by the codec,
  1172. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  1173. * the first is allways the native one
  1174. * @return the choosen format
  1175. * - encoding: unused
  1176. * - decoding: set by user, if not set then the native format will always be choosen
  1177. */
  1178. enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt);
  1179. /**
  1180. * DTG active format information (additionnal aspect ratio
  1181. * information only used in DVB MPEG2 transport streams). 0 if
  1182. * not set.
  1183. *
  1184. * - encoding: unused.
  1185. * - decoding: set by decoder
  1186. */
  1187. int dtg_active_format;
  1188. #define FF_DTG_AFD_SAME 8
  1189. #define FF_DTG_AFD_4_3 9
  1190. #define FF_DTG_AFD_16_9 10
  1191. #define FF_DTG_AFD_14_9 11
  1192. #define FF_DTG_AFD_4_3_SP_14_9 13
  1193. #define FF_DTG_AFD_16_9_SP_14_9 14
  1194. #define FF_DTG_AFD_SP_4_3 15
  1195. /**
  1196. * Maximum motion estimation search range in subpel units.
  1197. * if 0 then no limit
  1198. *
  1199. * - encoding: set by user.
  1200. * - decoding: unused.
  1201. */
  1202. int me_range;
  1203. /**
  1204. * frame_rate_base.
  1205. * for variable fps this is 1
  1206. * - encoding: set by user.
  1207. * - decoding: set by lavc.
  1208. * @todo move this after frame_rate
  1209. */
  1210. int frame_rate_base;
  1211. /**
  1212. * intra quantizer bias.
  1213. * - encoding: set by user.
  1214. * - decoding: unused
  1215. */
  1216. int intra_quant_bias;
  1217. #define FF_DEFAULT_QUANT_BIAS 999999
  1218. /**
  1219. * inter quantizer bias.
  1220. * - encoding: set by user.
  1221. * - decoding: unused
  1222. */
  1223. int inter_quant_bias;
  1224. /**
  1225. * color table ID.
  1226. * - encoding: unused.
  1227. * - decoding: which clrtable should be used for 8bit RGB images
  1228. * table have to be stored somewhere FIXME
  1229. */
  1230. int color_table_id;
  1231. /**
  1232. * internal_buffer count.
  1233. * Dont touch, used by lavc default_get_buffer()
  1234. */
  1235. int internal_buffer_count;
  1236. /**
  1237. * internal_buffers.
  1238. * Dont touch, used by lavc default_get_buffer()
  1239. */
  1240. void *internal_buffer;
  1241. #define FF_LAMBDA_SHIFT 7
  1242. #define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT)
  1243. #define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
  1244. #define FF_LAMBDA_MAX (256*128-1)
  1245. #define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
  1246. /**
  1247. * global quality for codecs which cannot change it per frame.
  1248. * this should be proportional to MPEG1/2/4 qscale.
  1249. * - encoding: set by user.
  1250. * - decoding: unused
  1251. */
  1252. int global_quality;
  1253. #define FF_CODER_TYPE_VLC 0
  1254. #define FF_CODER_TYPE_AC 1
  1255. /**
  1256. * coder type
  1257. * - encoding: set by user.
  1258. * - decoding: unused
  1259. */
  1260. int coder_type;
  1261. /**
  1262. * context model
  1263. * - encoding: set by user.
  1264. * - decoding: unused
  1265. */
  1266. int context_model;
  1267. /**
  1268. * slice flags
  1269. * - encoding: unused
  1270. * - decoding: set by user.
  1271. */
  1272. int slice_flags;
  1273. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  1274. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
  1275. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  1276. /**
  1277. * XVideo Motion Acceleration
  1278. * - encoding: forbidden
  1279. * - decoding: set by decoder
  1280. */
  1281. int xvmc_acceleration;
  1282. /**
  1283. * macroblock decision mode
  1284. * - encoding: set by user.
  1285. * - decoding: unused
  1286. */
  1287. int mb_decision;
  1288. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  1289. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  1290. #define FF_MB_DECISION_RD 2 ///< rate distoration
  1291. /**
  1292. * custom intra quantization matrix
  1293. * - encoding: set by user, can be NULL
  1294. * - decoding: set by lavc
  1295. */
  1296. uint16_t *intra_matrix;
  1297. /**
  1298. * custom inter quantization matrix
  1299. * - encoding: set by user, can be NULL
  1300. * - decoding: set by lavc
  1301. */
  1302. uint16_t *inter_matrix;
  1303. /**
  1304. * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1305. * this is used to workaround some encoder bugs
  1306. * - encoding: unused
  1307. * - decoding: set by user, will be converted to upper case by lavc during init
  1308. */
  1309. unsigned int stream_codec_tag;
  1310. /**
  1311. * scene change detection threshold.
  1312. * 0 is default, larger means fewer detected scene changes
  1313. * - encoding: set by user.
  1314. * - decoding: unused
  1315. */
  1316. int scenechange_threshold;
  1317. /**
  1318. * minimum lagrange multipler
  1319. * - encoding: set by user.
  1320. * - decoding: unused
  1321. */
  1322. int lmin;
  1323. /**
  1324. * maximum lagrange multipler
  1325. * - encoding: set by user.
  1326. * - decoding: unused
  1327. */
  1328. int lmax;
  1329. /**
  1330. * Palette control structure
  1331. * - encoding: ??? (no palette-enabled encoder yet)
  1332. * - decoding: set by user.
  1333. */
  1334. struct AVPaletteControl *palctrl;
  1335. /**
  1336. * noise reduction strength
  1337. * - encoding: set by user.
  1338. * - decoding: unused
  1339. */
  1340. int noise_reduction;
  1341. /**
  1342. * called at the beginning of a frame to get cr buffer for it.
  1343. * buffer type (size, hints) must be the same. lavc won't check it.
  1344. * lavc will pass previous buffer in pic, function should return
  1345. * same buffer or new buffer with old frame "painted" into it.
  1346. * if pic.data[0] == NULL must behave like get_buffer().
  1347. * - encoding: unused
  1348. * - decoding: set by lavc, user can override
  1349. */
  1350. int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic);
  1351. /**
  1352. * number of bits which should be loaded into the rc buffer before decoding starts
  1353. * - encoding: set by user.
  1354. * - decoding: unused
  1355. */
  1356. int rc_initial_buffer_occupancy;
  1357. /**
  1358. *
  1359. * - encoding: set by user.
  1360. * - decoding: unused
  1361. */
  1362. int inter_threshold;
  1363. /**
  1364. * CODEC_FLAG2_*.
  1365. * - encoding: set by user.
  1366. * - decoding: set by user.
  1367. */
  1368. int flags2;
  1369. /**
  1370. * simulates errors in the bitstream to test error concealment.
  1371. * - encoding: set by user.
  1372. * - decoding: unused.
  1373. */
  1374. int error_rate;
  1375. /**
  1376. * MP3 antialias algorithm, see FF_AA_* below.
  1377. * - encoding: unused
  1378. * - decoding: set by user
  1379. */
  1380. int antialias_algo;
  1381. #define FF_AA_AUTO 0
  1382. #define FF_AA_FASTINT 1 //not implemented yet
  1383. #define FF_AA_INT 2
  1384. #define FF_AA_FLOAT 3
  1385. /**
  1386. * Quantizer noise shaping.
  1387. * - encoding: set by user
  1388. * - decoding: unused
  1389. */
  1390. int quantizer_noise_shaping;
  1391. /**
  1392. * Thread count.
  1393. * is used to decide how many independant tasks should be passed to execute()
  1394. * - encoding: set by user
  1395. * - decoding: set by user
  1396. */
  1397. int thread_count;
  1398. /**
  1399. * the codec may call this to execute several independant things. it will return only after
  1400. * finishing all tasks, the user may replace this with some multithreaded implementation, the
  1401. * default implementation will execute the parts serially
  1402. * @param count the number of things to execute
  1403. * - encoding: set by lavc, user can override
  1404. * - decoding: set by lavc, user can override
  1405. */
  1406. int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count);
  1407. /**
  1408. * Thread opaque.
  1409. * can be used by execute() to store some per AVCodecContext stuff.
  1410. * - encoding: set by execute()
  1411. * - decoding: set by execute()
  1412. */
  1413. void *thread_opaque;
  1414. /**
  1415. * Motion estimation threshold. under which no motion estimation is
  1416. * performed, but instead the user specified motion vectors are used
  1417. *
  1418. * - encoding: set by user
  1419. * - decoding: unused
  1420. */
  1421. int me_threshold;
  1422. /**
  1423. * Macroblock threshold. under which the user specified macroblock types will be used
  1424. * - encoding: set by user
  1425. * - decoding: unused
  1426. */
  1427. int mb_threshold;
  1428. /**
  1429. * precision of the intra dc coefficient - 8.
  1430. * - encoding: set by user
  1431. * - decoding: unused
  1432. */
  1433. int intra_dc_precision;
  1434. /**
  1435. * noise vs. sse weight for the nsse comparsion function.
  1436. * - encoding: set by user
  1437. * - decoding: unused
  1438. */
  1439. int nsse_weight;
  1440. } AVCodecContext;
  1441. /**
  1442. * AVOption.
  1443. */
  1444. typedef struct AVOption {
  1445. /** options' name */
  1446. const char *name; /* if name is NULL, it indicates a link to next */
  1447. /** short English text help or const struct AVOption* subpointer */
  1448. const char *help; // const struct AVOption* sub;
  1449. /** offset to context structure where the parsed value should be stored */
  1450. int offset;
  1451. /** options' type */
  1452. int type;
  1453. #define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
  1454. #define FF_OPT_TYPE_DOUBLE 2 ///< double
  1455. #define FF_OPT_TYPE_INT 3 ///< integer
  1456. #define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
  1457. #define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
  1458. //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
  1459. #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
  1460. #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
  1461. /** min value (min == max -> no limits) */
  1462. double min;
  1463. /** maximum value for double/int */
  1464. double max;
  1465. /** default boo [0,1]l/double/int value */
  1466. double defval;
  1467. /**
  1468. * default string value (with optional semicolon delimited extra option-list
  1469. * i.e. option1;option2;option3
  1470. * defval might select other then first argument as default
  1471. */
  1472. const char *defstr;
  1473. #define FF_OPT_MAX_DEPTH 10
  1474. } AVOption;
  1475. /**
  1476. * Parse option(s) and sets fields in passed structure
  1477. * @param strct structure where the parsed results will be written
  1478. * @param list list with AVOptions
  1479. * @param opts string with options for parsing
  1480. */
  1481. int avoption_parse(void* strct, const AVOption* list, const char* opts);
  1482. /**
  1483. * AVCodec.
  1484. */
  1485. typedef struct AVCodec {
  1486. const char *name;
  1487. enum CodecType type;
  1488. int id;
  1489. int priv_data_size;
  1490. int (*init)(AVCodecContext *);
  1491. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  1492. int (*close)(AVCodecContext *);
  1493. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  1494. uint8_t *buf, int buf_size);
  1495. int capabilities;
  1496. const AVOption *options;
  1497. struct AVCodec *next;
  1498. void (*flush)(AVCodecContext *);
  1499. const AVRational *supported_framerates; ///array of supported framerates, or NULL if any, array is terminated by {0,0}
  1500. const enum PixelFormat *pix_fmts; ///array of supported pixel formats, or NULL if unknown, array is terminanted by -1
  1501. } AVCodec;
  1502. /**
  1503. * four components are given, that's all.
  1504. * the last component is alpha
  1505. */
  1506. typedef struct AVPicture {
  1507. uint8_t *data[4];
  1508. int linesize[4]; ///< number of bytes per line
  1509. } AVPicture;
  1510. /**
  1511. * AVPaletteControl
  1512. * This structure defines a method for communicating palette changes
  1513. * between and demuxer and a decoder.
  1514. */
  1515. #define AVPALETTE_SIZE 1024
  1516. #define AVPALETTE_COUNT 256
  1517. typedef struct AVPaletteControl {
  1518. /* demuxer sets this to 1 to indicate the palette has changed;
  1519. * decoder resets to 0 */
  1520. int palette_changed;
  1521. /* 4-byte ARGB palette entries, stored in native byte order; note that
  1522. * the individual palette components should be on a 8-bit scale; if
  1523. * the palette data comes from a IBM VGA native format, the component
  1524. * data is probably 6 bits in size and needs to be scaled */
  1525. unsigned int palette[AVPALETTE_COUNT];
  1526. } AVPaletteControl;
  1527. extern AVCodec ac3_encoder;
  1528. extern AVCodec mp2_encoder;
  1529. extern AVCodec mp3lame_encoder;
  1530. extern AVCodec oggvorbis_encoder;
  1531. extern AVCodec faac_encoder;
  1532. extern AVCodec mpeg1video_encoder;
  1533. extern AVCodec mpeg2video_encoder;
  1534. extern AVCodec h263_encoder;
  1535. extern AVCodec h263p_encoder;
  1536. extern AVCodec flv_encoder;
  1537. extern AVCodec rv10_encoder;
  1538. extern AVCodec rv20_encoder;
  1539. extern AVCodec dvvideo_encoder;
  1540. extern AVCodec mjpeg_encoder;
  1541. extern AVCodec ljpeg_encoder;
  1542. extern AVCodec mpeg4_encoder;
  1543. extern AVCodec msmpeg4v1_encoder;
  1544. extern AVCodec msmpeg4v2_encoder;
  1545. extern AVCodec msmpeg4v3_encoder;
  1546. extern AVCodec wmv1_encoder;
  1547. extern AVCodec wmv2_encoder;
  1548. extern AVCodec huffyuv_encoder;
  1549. extern AVCodec h264_encoder;
  1550. extern AVCodec asv1_encoder;
  1551. extern AVCodec asv2_encoder;
  1552. extern AVCodec vcr1_encoder;
  1553. extern AVCodec ffv1_encoder;
  1554. extern AVCodec mdec_encoder;
  1555. extern AVCodec zlib_encoder;
  1556. extern AVCodec svq1_encoder;
  1557. extern AVCodec h263_decoder;
  1558. extern AVCodec h261_decoder;
  1559. extern AVCodec mpeg4_decoder;
  1560. extern AVCodec msmpeg4v1_decoder;
  1561. extern AVCodec msmpeg4v2_decoder;
  1562. extern AVCodec msmpeg4v3_decoder;
  1563. extern AVCodec wmv1_decoder;
  1564. extern AVCodec wmv2_decoder;
  1565. extern AVCodec mpeg1video_decoder;
  1566. extern AVCodec mpeg2video_decoder;
  1567. extern AVCodec mpegvideo_decoder;
  1568. extern AVCodec mpeg_xvmc_decoder;
  1569. extern AVCodec h263i_decoder;
  1570. extern AVCodec flv_decoder;
  1571. extern AVCodec rv10_decoder;
  1572. extern AVCodec rv20_decoder;
  1573. extern AVCodec svq1_decoder;
  1574. extern AVCodec svq3_decoder;
  1575. extern AVCodec dvvideo_decoder;
  1576. extern AVCodec wmav1_decoder;
  1577. extern AVCodec wmav2_decoder;
  1578. extern AVCodec mjpeg_decoder;
  1579. extern AVCodec mjpegb_decoder;
  1580. extern AVCodec sp5x_decoder;
  1581. extern AVCodec mp2_decoder;
  1582. extern AVCodec mp3_decoder;
  1583. extern AVCodec mace3_decoder;
  1584. extern AVCodec mace6_decoder;
  1585. extern AVCodec huffyuv_decoder;
  1586. extern AVCodec oggvorbis_decoder;
  1587. extern AVCodec cyuv_decoder;
  1588. extern AVCodec h264_decoder;
  1589. extern AVCodec indeo3_decoder;
  1590. extern AVCodec vp3_decoder;
  1591. extern AVCodec theora_decoder;
  1592. extern AVCodec amr_nb_decoder;
  1593. extern AVCodec amr_nb_encoder;
  1594. extern AVCodec amr_wb_encoder;
  1595. extern AVCodec amr_wb_decoder;
  1596. extern AVCodec aac_decoder;
  1597. extern AVCodec mpeg4aac_decoder;
  1598. extern AVCodec asv1_decoder;
  1599. extern AVCodec asv2_decoder;
  1600. extern AVCodec vcr1_decoder;
  1601. extern AVCodec cljr_decoder;
  1602. extern AVCodec ffv1_decoder;
  1603. extern AVCodec fourxm_decoder;
  1604. extern AVCodec mdec_decoder;
  1605. extern AVCodec roq_decoder;
  1606. extern AVCodec interplay_video_decoder;
  1607. extern AVCodec xan_wc3_decoder;
  1608. extern AVCodec rpza_decoder;
  1609. extern AVCodec cinepak_decoder;
  1610. extern AVCodec msrle_decoder;
  1611. extern AVCodec msvideo1_decoder;
  1612. extern AVCodec vqa_decoder;
  1613. extern AVCodec idcin_decoder;
  1614. extern AVCodec eightbps_decoder;
  1615. extern AVCodec smc_decoder;
  1616. extern AVCodec flic_decoder;
  1617. extern AVCodec vmdvideo_decoder;
  1618. extern AVCodec vmdaudio_decoder;
  1619. extern AVCodec truemotion1_decoder;
  1620. extern AVCodec mszh_decoder;
  1621. extern AVCodec zlib_decoder;
  1622. extern AVCodec ra_144_decoder;
  1623. extern AVCodec ra_288_decoder;
  1624. extern AVCodec roq_dpcm_decoder;
  1625. extern AVCodec interplay_dpcm_decoder;
  1626. extern AVCodec xan_dpcm_decoder;
  1627. extern AVCodec qtrle_decoder;
  1628. extern AVCodec flac_decoder;
  1629. /* pcm codecs */
  1630. #define PCM_CODEC(id, name) \
  1631. extern AVCodec name ## _decoder; \
  1632. extern AVCodec name ## _encoder
  1633. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  1634. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  1635. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  1636. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  1637. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  1638. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  1639. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  1640. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  1641. /* adpcm codecs */
  1642. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  1643. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  1644. PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
  1645. PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
  1646. PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
  1647. PCM_CODEC(CODEC_ID_ADPCM_SMJPEG, adpcm_ima_smjpeg);
  1648. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  1649. PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
  1650. PCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
  1651. PCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx);
  1652. PCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
  1653. PCM_CODEC(CODEC_ID_ADPCM_G726, adpcm_g726);
  1654. #undef PCM_CODEC
  1655. /* dummy raw video codec */
  1656. extern AVCodec rawvideo_encoder;
  1657. extern AVCodec rawvideo_decoder;
  1658. /* the following codecs use external GPL libs */
  1659. extern AVCodec ac3_decoder;
  1660. /* resample.c */
  1661. struct ReSampleContext;
  1662. typedef struct ReSampleContext ReSampleContext;
  1663. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  1664. int output_rate, int input_rate);
  1665. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  1666. void audio_resample_close(ReSampleContext *s);
  1667. /* YUV420 format is assumed ! */
  1668. struct ImgReSampleContext;
  1669. typedef struct ImgReSampleContext ImgReSampleContext;
  1670. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  1671. int input_width, int input_height);
  1672. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  1673. int iwidth, int iheight,
  1674. int topBand, int bottomBand,
  1675. int leftBand, int rightBand,
  1676. int padtop, int padbottom,
  1677. int padleft, int padright);
  1678. void img_resample(ImgReSampleContext *s,
  1679. AVPicture *output, const AVPicture *input);
  1680. void img_resample_close(ImgReSampleContext *s);
  1681. /**
  1682. * Allocate memory for a picture. Call avpicture_free to free it.
  1683. *
  1684. * @param picture the picture to be filled in.
  1685. * @param pix_fmt the format of the picture.
  1686. * @param width the width of the picture.
  1687. * @param height the height of the picture.
  1688. * @return 0 if successful, -1 if not.
  1689. */
  1690. int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height);
  1691. /* Free a picture previously allocated by avpicture_alloc. */
  1692. void avpicture_free(AVPicture *picture);
  1693. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  1694. int pix_fmt, int width, int height);
  1695. int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height,
  1696. unsigned char *dest, int dest_size);
  1697. int avpicture_get_size(int pix_fmt, int width, int height);
  1698. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  1699. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  1700. enum PixelFormat avcodec_get_pix_fmt(const char* name);
  1701. #define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
  1702. #define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */
  1703. #define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */
  1704. #define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */
  1705. #define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */
  1706. #define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
  1707. int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
  1708. int has_alpha);
  1709. int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
  1710. int has_alpha, int *loss_ptr);
  1711. #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
  1712. #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
  1713. int img_get_alpha_info(const AVPicture *src,
  1714. int pix_fmt, int width, int height);
  1715. /* convert among pixel formats */
  1716. int img_convert(AVPicture *dst, int dst_pix_fmt,
  1717. const AVPicture *src, int pix_fmt,
  1718. int width, int height);
  1719. /* deinterlace a picture */
  1720. int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
  1721. int pix_fmt, int width, int height);
  1722. /* external high level API */
  1723. extern AVCodec *first_avcodec;
  1724. /* returns LIBAVCODEC_VERSION_INT constant */
  1725. unsigned avcodec_version(void);
  1726. /* returns LIBAVCODEC_BUILD constant */
  1727. unsigned avcodec_build(void);
  1728. void avcodec_init(void);
  1729. void register_avcodec(AVCodec *format);
  1730. AVCodec *avcodec_find_encoder(enum CodecID id);
  1731. AVCodec *avcodec_find_encoder_by_name(const char *name);
  1732. AVCodec *avcodec_find_decoder(enum CodecID id);
  1733. AVCodec *avcodec_find_decoder_by_name(const char *name);
  1734. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  1735. void avcodec_get_context_defaults(AVCodecContext *s);
  1736. AVCodecContext *avcodec_alloc_context(void);
  1737. void avcodec_get_frame_defaults(AVFrame *pic);
  1738. AVFrame *avcodec_alloc_frame(void);
  1739. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  1740. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  1741. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
  1742. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
  1743. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
  1744. int avcodec_thread_init(AVCodecContext *s, int thread_count);
  1745. void avcodec_thread_free(AVCodecContext *s);
  1746. int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
  1747. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
  1748. //FIXME func typedef
  1749. /**
  1750. * opens / inits the AVCodecContext.
  1751. * not thread save!
  1752. */
  1753. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  1754. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  1755. int *frame_size_ptr,
  1756. uint8_t *buf, int buf_size);
  1757. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  1758. int *got_picture_ptr,
  1759. uint8_t *buf, int buf_size);
  1760. int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
  1761. int *data_size_ptr,
  1762. uint8_t *buf, int buf_size);
  1763. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1764. const short *samples);
  1765. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1766. const AVFrame *pict);
  1767. int avcodec_close(AVCodecContext *avctx);
  1768. void avcodec_register_all(void);
  1769. void avcodec_flush_buffers(AVCodecContext *avctx);
  1770. /* misc usefull functions */
  1771. /**
  1772. * returns a single letter to describe the picture type
  1773. */
  1774. char av_get_pict_type_char(int pict_type);
  1775. /**
  1776. * reduce a fraction.
  1777. * this is usefull for framerate calculations
  1778. * @param max the maximum allowed for dst_nom & dst_den
  1779. * @return 1 if exact, 0 otherwise
  1780. */
  1781. int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
  1782. /**
  1783. * rescale a 64bit integer.
  1784. * a simple a*b/c isnt possible as it can overflow
  1785. */
  1786. int64_t av_rescale(int64_t a, int64_t b, int64_t c);
  1787. /**
  1788. * Interface for 0.5.0 version
  1789. *
  1790. * do not even think about it's usage for this moment
  1791. */
  1792. typedef struct {
  1793. /// compressed size used from given memory buffer
  1794. int size;
  1795. /// I/P/B frame type
  1796. int frame_type;
  1797. } avc_enc_result_t;
  1798. /**
  1799. * Commands
  1800. * order can't be changed - once it was defined
  1801. */
  1802. typedef enum {
  1803. // general commands
  1804. AVC_OPEN_BY_NAME = 0xACA000,
  1805. AVC_OPEN_BY_CODEC_ID,
  1806. AVC_OPEN_BY_FOURCC,
  1807. AVC_CLOSE,
  1808. AVC_FLUSH,
  1809. // pin - struct { uint8_t* src, uint_t src_size }
  1810. // pout - struct { AVPicture* img, consumed_bytes,
  1811. AVC_DECODE,
  1812. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  1813. // pout - uint_t used_from_dest_size
  1814. AVC_ENCODE,
  1815. // query/get video commands
  1816. AVC_GET_VERSION = 0xACB000,
  1817. AVC_GET_WIDTH,
  1818. AVC_GET_HEIGHT,
  1819. AVC_GET_DELAY,
  1820. AVC_GET_QUANT_TABLE,
  1821. // ...
  1822. // query/get audio commands
  1823. AVC_GET_FRAME_SIZE = 0xABC000,
  1824. // maybe define some simple structure which
  1825. // might be passed to the user - but they can't
  1826. // contain any codec specific parts and these
  1827. // calls are usualy necessary only few times
  1828. // set video commands
  1829. AVC_SET_WIDTH = 0xACD000,
  1830. AVC_SET_HEIGHT,
  1831. // set video encoding commands
  1832. AVC_SET_FRAME_RATE = 0xACD800,
  1833. AVC_SET_QUALITY,
  1834. AVC_SET_HURRY_UP,
  1835. // set audio commands
  1836. AVC_SET_SAMPLE_RATE = 0xACE000,
  1837. AVC_SET_CHANNELS,
  1838. } avc_cmd_t;
  1839. /**
  1840. * \param handle allocated private structure by libavcodec
  1841. * for initialization pass NULL - will be returned pout
  1842. * user is supposed to know nothing about its structure
  1843. * \param cmd type of operation to be performed
  1844. * \param pint input parameter
  1845. * \param pout output parameter
  1846. *
  1847. * \returns command status - eventually for query command it might return
  1848. * integer resulting value
  1849. */
  1850. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  1851. /* frame parsing */
  1852. typedef struct AVCodecParserContext {
  1853. void *priv_data;
  1854. struct AVCodecParser *parser;
  1855. int64_t frame_offset; /* offset of the current frame */
  1856. int64_t cur_offset; /* current offset
  1857. (incremented by each av_parser_parse()) */
  1858. int64_t last_frame_offset; /* offset of the last frame */
  1859. /* video info */
  1860. int pict_type; /* XXX: put it back in AVCodecContext */
  1861. int repeat_pict; /* XXX: put it back in AVCodecContext */
  1862. int64_t pts; /* pts of the current frame */
  1863. int64_t dts; /* dts of the current frame */
  1864. /* private data */
  1865. int64_t last_pts;
  1866. int64_t last_dts;
  1867. int fetch_timestamp;
  1868. #define AV_PARSER_PTS_NB 4
  1869. int cur_frame_start_index;
  1870. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
  1871. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
  1872. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
  1873. } AVCodecParserContext;
  1874. typedef struct AVCodecParser {
  1875. int codec_ids[3]; /* several codec IDs are permitted */
  1876. int priv_data_size;
  1877. int (*parser_init)(AVCodecParserContext *s);
  1878. int (*parser_parse)(AVCodecParserContext *s,
  1879. AVCodecContext *avctx,
  1880. uint8_t **poutbuf, int *poutbuf_size,
  1881. const uint8_t *buf, int buf_size);
  1882. void (*parser_close)(AVCodecParserContext *s);
  1883. struct AVCodecParser *next;
  1884. } AVCodecParser;
  1885. extern AVCodecParser *av_first_parser;
  1886. void av_register_codec_parser(AVCodecParser *parser);
  1887. AVCodecParserContext *av_parser_init(int codec_id);
  1888. int av_parser_parse(AVCodecParserContext *s,
  1889. AVCodecContext *avctx,
  1890. uint8_t **poutbuf, int *poutbuf_size,
  1891. const uint8_t *buf, int buf_size,
  1892. int64_t pts, int64_t dts);
  1893. void av_parser_close(AVCodecParserContext *s);
  1894. extern AVCodecParser mpegvideo_parser;
  1895. extern AVCodecParser mpeg4video_parser;
  1896. extern AVCodecParser h261_parser;
  1897. extern AVCodecParser h263_parser;
  1898. extern AVCodecParser h264_parser;
  1899. extern AVCodecParser mpegaudio_parser;
  1900. extern AVCodecParser ac3_parser;
  1901. /* memory */
  1902. void *av_malloc(unsigned int size);
  1903. void *av_mallocz(unsigned int size);
  1904. void *av_realloc(void *ptr, unsigned int size);
  1905. void av_free(void *ptr);
  1906. char *av_strdup(const char *s);
  1907. void av_freep(void *ptr);
  1908. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
  1909. /* for static data only */
  1910. /* call av_free_static to release all staticaly allocated tables */
  1911. void av_free_static(void);
  1912. void *av_mallocz_static(unsigned int size);
  1913. /* add by bero : in adx.c */
  1914. int is_adx(const unsigned char *buf,size_t bufsize);
  1915. void img_copy(AVPicture *dst, const AVPicture *src,
  1916. int pix_fmt, int width, int height);
  1917. /* av_log API */
  1918. #include <stdarg.h>
  1919. #define AV_LOG_QUIET -1
  1920. #define AV_LOG_ERROR 0
  1921. #define AV_LOG_INFO 1
  1922. #define AV_LOG_DEBUG 2
  1923. #ifdef __GNUC__
  1924. extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
  1925. #else
  1926. extern void av_log(void*, int level, const char *fmt, ...);
  1927. #endif
  1928. extern void av_vlog(void*, int level, const char *fmt, va_list);
  1929. extern int av_log_get_level(void);
  1930. extern void av_log_set_level(int);
  1931. extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
  1932. /* endian macros */
  1933. #if !defined(BE_16) || !defined(BE_32) || !defined(LE_16) || !defined(LE_32)
  1934. #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
  1935. #define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
  1936. (((uint8_t*)(x))[1] << 16) | \
  1937. (((uint8_t*)(x))[2] << 8) | \
  1938. ((uint8_t*)(x))[3])
  1939. #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
  1940. #define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
  1941. (((uint8_t*)(x))[2] << 16) | \
  1942. (((uint8_t*)(x))[1] << 8) | \
  1943. ((uint8_t*)(x))[0])
  1944. #endif
  1945. #ifdef __cplusplus
  1946. }
  1947. #endif
  1948. #endif /* AVCODEC_H */