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.

2105 lines
61KB

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