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.

2229 lines
66KB

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