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.

2116 lines
62KB

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