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.

2074 lines
60KB

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