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.

1693 lines
48KB

  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. #define FFMPEG_VERSION_INT 0x000408
  12. #define FFMPEG_VERSION "0.4.8"
  13. #define LIBAVCODEC_BUILD 4680
  14. #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
  15. #define LIBAVCODEC_VERSION FFMPEG_VERSION
  16. #define AV_STRINGIFY(s) AV_TOSTRING(s)
  17. #define AV_TOSTRING(s) #s
  18. #define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD)
  19. enum CodecID {
  20. CODEC_ID_NONE,
  21. CODEC_ID_MPEG1VIDEO,
  22. CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
  23. CODEC_ID_MPEG2VIDEO_XVMC,
  24. CODEC_ID_H263,
  25. CODEC_ID_RV10,
  26. CODEC_ID_MP2,
  27. CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
  28. CODEC_ID_VORBIS,
  29. CODEC_ID_AC3,
  30. CODEC_ID_MJPEG,
  31. CODEC_ID_MJPEGB,
  32. CODEC_ID_LJPEG,
  33. CODEC_ID_MPEG4,
  34. CODEC_ID_RAWVIDEO,
  35. CODEC_ID_MSMPEG4V1,
  36. CODEC_ID_MSMPEG4V2,
  37. CODEC_ID_MSMPEG4V3,
  38. CODEC_ID_WMV1,
  39. CODEC_ID_WMV2,
  40. CODEC_ID_H263P,
  41. CODEC_ID_H263I,
  42. CODEC_ID_FLV1,
  43. CODEC_ID_SVQ1,
  44. CODEC_ID_SVQ3,
  45. CODEC_ID_DVVIDEO,
  46. CODEC_ID_DVAUDIO,
  47. CODEC_ID_WMAV1,
  48. CODEC_ID_WMAV2,
  49. CODEC_ID_MACE3,
  50. CODEC_ID_MACE6,
  51. CODEC_ID_HUFFYUV,
  52. CODEC_ID_CYUV,
  53. CODEC_ID_H264,
  54. CODEC_ID_INDEO3,
  55. CODEC_ID_VP3,
  56. CODEC_ID_AAC,
  57. CODEC_ID_MPEG4AAC,
  58. CODEC_ID_ASV1,
  59. CODEC_ID_ASV2,
  60. CODEC_ID_FFV1,
  61. CODEC_ID_4XM,
  62. CODEC_ID_VCR1,
  63. CODEC_ID_CLJR,
  64. CODEC_ID_MDEC,
  65. CODEC_ID_ROQ,
  66. CODEC_ID_INTERPLAY_VIDEO,
  67. CODEC_ID_XAN_WC3,
  68. CODEC_ID_XAN_WC4,
  69. /* various pcm "codecs" */
  70. CODEC_ID_PCM_S16LE,
  71. CODEC_ID_PCM_S16BE,
  72. CODEC_ID_PCM_U16LE,
  73. CODEC_ID_PCM_U16BE,
  74. CODEC_ID_PCM_S8,
  75. CODEC_ID_PCM_U8,
  76. CODEC_ID_PCM_MULAW,
  77. CODEC_ID_PCM_ALAW,
  78. /* various adpcm codecs */
  79. CODEC_ID_ADPCM_IMA_QT,
  80. CODEC_ID_ADPCM_IMA_WAV,
  81. CODEC_ID_ADPCM_IMA_DK3,
  82. CODEC_ID_ADPCM_IMA_DK4,
  83. CODEC_ID_ADPCM_MS,
  84. CODEC_ID_ADPCM_4XM,
  85. /* AMR */
  86. CODEC_ID_AMR_NB,
  87. CODEC_ID_AMR_WB,
  88. /* RealAudio codecs*/
  89. CODEC_ID_RA_144,
  90. CODEC_ID_RA_288,
  91. /* various DPCM codecs */
  92. CODEC_ID_ROQ_DPCM,
  93. CODEC_ID_INTERPLAY_DPCM,
  94. CODEC_ID_XAN_DPCM,
  95. };
  96. /* CODEC_ID_MP3LAME is absolete */
  97. #define CODEC_ID_MP3LAME CODEC_ID_MP3
  98. enum CodecType {
  99. CODEC_TYPE_UNKNOWN = -1,
  100. CODEC_TYPE_VIDEO,
  101. CODEC_TYPE_AUDIO,
  102. };
  103. /**
  104. * Pixel format. Notes:
  105. *
  106. * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA
  107. * color is put together as:
  108. * (A << 24) | (R << 16) | (G << 8) | B
  109. * This is stored as BGRA on little endian CPU architectures and ARGB on
  110. * big endian CPUs.
  111. *
  112. * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
  113. * image data is stored in AVFrame.data[0]. The palette is transported in
  114. * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
  115. * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
  116. * also endian-specific).
  117. */
  118. enum PixelFormat {
  119. PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples)
  120. PIX_FMT_YUV422,
  121. PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB...
  122. PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR...
  123. PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
  124. PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
  125. PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
  126. PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
  127. PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
  128. PIX_FMT_RGB565, ///< always stored in cpu endianness
  129. PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
  130. PIX_FMT_GRAY8,
  131. PIX_FMT_MONOWHITE, ///< 0 is white
  132. PIX_FMT_MONOBLACK, ///< 0 is black
  133. PIX_FMT_PAL8, ///< 8 bit with RGBA palette
  134. PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg)
  135. PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg)
  136. PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg)
  137. PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
  138. PIX_FMT_XVMC_MPEG2_IDCT,
  139. PIX_FMT_NB,
  140. };
  141. /* currently unused, may be used if 24/32 bits samples ever supported */
  142. enum SampleFormat {
  143. SAMPLE_FMT_S16 = 0, ///< signed 16 bits
  144. };
  145. /* in bytes */
  146. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
  147. /**
  148. * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
  149. * this is mainly needed because some optimized bitstream readers read
  150. * 32 or 64 bit at once and could read over the end<br>
  151. * Note, if the first 23 bits of the additional bytes are not 0 then damaged
  152. * MPEG bitstreams could cause overread and segfault
  153. */
  154. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  155. /* motion estimation type, EPZS by default */
  156. enum Motion_Est_ID {
  157. ME_ZERO = 1,
  158. ME_FULL,
  159. ME_LOG,
  160. ME_PHODS,
  161. ME_EPZS,
  162. ME_X1
  163. };
  164. typedef struct RcOverride{
  165. int start_frame;
  166. int end_frame;
  167. int qscale; // if this is 0 then quality_factor will be used instead
  168. float quality_factor;
  169. } RcOverride;
  170. /* only for ME compatiblity with old apps */
  171. extern int motion_estimation_method;
  172. /* ME algos sorted by quality */
  173. static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
  174. ME_X1, ME_EPZS, ME_FULL };
  175. #define FF_MAX_B_FRAMES 8
  176. /* encoding support
  177. these flags can be passed in AVCodecContext.flags before initing
  178. Note: note not everything is supported yet
  179. */
  180. #define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
  181. #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed
  182. #define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
  183. #define CODEC_FLAG_GMC 0x0020 ///< use GMC
  184. #define CODEC_FLAG_PART 0x0080 ///< use data partitioning
  185. /* parent program gurantees that the input for b-frame containing streams is not written to
  186. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  187. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  188. #define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
  189. #define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
  190. #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
  191. #define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
  192. #define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges
  193. #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
  194. #define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
  195. of only at frame boundaries */
  196. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
  197. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
  198. #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay
  199. #define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
  200. #define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
  201. #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
  202. #define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
  203. /* Fx : Flag for h263+ extra options */
  204. #define CODEC_FLAG_H263P_AIC 0x01000000 ///< Advanced intra coding
  205. #define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
  206. /* For advanced prediction mode, we reuse the 4MV flag */
  207. /* Unsupported options :
  208. * Syntax Arithmetic coding (SAC)
  209. * Deblocking filter internal loop
  210. * Slice structured
  211. * Reference Picture Selection
  212. * Independant Segment Decoding
  213. * Alternative Inter * VLC
  214. * Modified Quantization */
  215. /* /Fx */
  216. /* codec capabilities */
  217. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback
  218. /**
  219. * Codec uses get_buffer() for allocating buffers.
  220. * direct rendering method 1
  221. */
  222. #define CODEC_CAP_DR1 0x0002
  223. /* if 'parse_only' field is true, then avcodec_parse_frame() can be
  224. used */
  225. #define CODEC_CAP_PARSE_ONLY 0x0004
  226. #define CODEC_CAP_TRUNCATED 0x0008
  227. #define FF_COMMON_FRAME \
  228. /**\
  229. * pointer to the picture planes.\
  230. * this might be different from the first allocated byte\
  231. * - encoding: \
  232. * - decoding: \
  233. */\
  234. uint8_t *data[4];\
  235. int linesize[4];\
  236. /**\
  237. * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
  238. * this isnt used by lavc unless the default get/release_buffer() is used\
  239. * - encoding: \
  240. * - decoding: \
  241. */\
  242. uint8_t *base[4];\
  243. /**\
  244. * 1 -> keyframe, 0-> not\
  245. * - encoding: set by lavc\
  246. * - decoding: set by lavc\
  247. */\
  248. int key_frame;\
  249. \
  250. /**\
  251. * picture type of the frame, see ?_TYPE below.\
  252. * - encoding: set by lavc for coded_picture (and set by user for input)\
  253. * - decoding: set by lavc\
  254. */\
  255. int pict_type;\
  256. \
  257. /**\
  258. * presentation timestamp in micro seconds (time when frame should be shown to user)\
  259. * if 0 then the frame_rate will be used as reference\
  260. * - encoding: MUST be set by user\
  261. * - decoding: set by lavc\
  262. */\
  263. int64_t pts;\
  264. \
  265. /**\
  266. * picture number in bitstream order.\
  267. * - encoding: set by\
  268. * - decoding: set by lavc\
  269. */\
  270. int coded_picture_number;\
  271. /**\
  272. * picture number in display order.\
  273. * - encoding: set by\
  274. * - decoding: set by lavc\
  275. */\
  276. int display_picture_number;\
  277. \
  278. /**\
  279. * quality (between 1 (good) and 31 (bad)) \
  280. * - encoding: set by lavc for coded_picture (and set by user for input)\
  281. * - decoding: set by lavc\
  282. */\
  283. float quality; \
  284. \
  285. /**\
  286. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  287. * set to something large if the buffer has not been used yet \
  288. * - encoding: unused\
  289. * - decoding: MUST be set by get_buffer()\
  290. */\
  291. int age;\
  292. \
  293. /**\
  294. * is this picture used as reference\
  295. * - encoding: unused\
  296. * - decoding: set by lavc (before get_buffer() call))\
  297. */\
  298. int reference;\
  299. \
  300. /**\
  301. * QP table\
  302. * - encoding: unused\
  303. * - decoding: set by lavc\
  304. */\
  305. int8_t *qscale_table;\
  306. /**\
  307. * QP store stride\
  308. * - encoding: unused\
  309. * - decoding: set by lavc\
  310. */\
  311. int qstride;\
  312. \
  313. /**\
  314. * mbskip_table[mb]>=1 if MB didnt change\
  315. * stride= mb_width = (width+15)>>4\
  316. * - encoding: unused\
  317. * - decoding: set by lavc\
  318. */\
  319. uint8_t *mbskip_table;\
  320. \
  321. /**\
  322. * for some private data of the user\
  323. * - encoding: unused\
  324. * - decoding: set by user\
  325. */\
  326. void *opaque;\
  327. \
  328. /**\
  329. * error\
  330. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
  331. * - decoding: unused\
  332. */\
  333. uint64_t error[4];\
  334. \
  335. /**\
  336. * type of the buffer (to keep track of who has to dealloc data[*])\
  337. * - encoding: set by the one who allocs it\
  338. * - decoding: set by the one who allocs it\
  339. * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
  340. */\
  341. int type;\
  342. \
  343. /**\
  344. * when decoding, this signal how much the picture must be delayed.\
  345. * extra_delay = repeat_pict / (2*fps)\
  346. * - encoding: unused\
  347. * - decoding: set by lavc\
  348. */\
  349. int repeat_pict;\
  350. \
  351. /**\
  352. * \
  353. */\
  354. int qscale_type;\
  355. #define FF_QSCALE_TYPE_MPEG1 0
  356. #define FF_QSCALE_TYPE_MPEG2 1
  357. #define FF_BUFFER_TYPE_INTERNAL 1
  358. #define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user)
  359. #define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base)
  360. #define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything
  361. #define FF_I_TYPE 1 // Intra
  362. #define FF_P_TYPE 2 // Predicted
  363. #define FF_B_TYPE 3 // Bi-dir predicted
  364. #define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
  365. #define FF_SI_TYPE 5
  366. #define FF_SP_TYPE 6
  367. /**
  368. * Audio Video Frame.
  369. */
  370. typedef struct AVFrame {
  371. FF_COMMON_FRAME
  372. } AVFrame;
  373. #define DEFAULT_FRAME_RATE_BASE 1001000
  374. /**
  375. * main external api structure.
  376. */
  377. typedef struct AVCodecContext {
  378. /**
  379. * the average bitrate.
  380. * - encoding: set by user. unused for constant quantizer encoding
  381. * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  382. */
  383. int bit_rate;
  384. /**
  385. * number of bits the bitstream is allowed to diverge from the reference.
  386. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  387. * - encoding: set by user. unused for constant quantizer encoding
  388. * - decoding: unused
  389. */
  390. int bit_rate_tolerance;
  391. /**
  392. * CODEC_FLAG_*.
  393. * - encoding: set by user.
  394. * - decoding: set by user.
  395. */
  396. int flags;
  397. /**
  398. * some codecs needs additionnal format info. It is stored here
  399. * - encoding: set by user.
  400. * - decoding: set by lavc. (FIXME is this ok?)
  401. */
  402. int sub_id;
  403. /**
  404. * motion estimation algorithm used for video coding.
  405. * - encoding: MUST be set by user.
  406. * - decoding: unused
  407. */
  408. int me_method;
  409. /**
  410. * some codecs need / can use extra-data like huffman tables.
  411. * mjpeg: huffman tables
  412. * rv10: additional flags
  413. * mpeg4: global headers (they can be in the bitstream or here)
  414. * - encoding: set/allocated/freed by lavc.
  415. * - decoding: set/allocated/freed by user.
  416. */
  417. void *extradata;
  418. int extradata_size;
  419. /* video only */
  420. /**
  421. * frames per sec multiplied by frame_rate_base.
  422. * for variable fps this is the precission, so if the timestamps
  423. * can be specified in msec precssion then this is 1000*frame_rate_base
  424. * - encoding: MUST be set by user
  425. * - decoding: set by lavc. 0 or the frame_rate if available
  426. */
  427. int frame_rate;
  428. /**
  429. * width / height.
  430. * - encoding: MUST be set by user.
  431. * - decoding: set by user, some codecs might override / change it during playback
  432. */
  433. int width, height;
  434. #define FF_ASPECT_SQUARE 1
  435. #define FF_ASPECT_4_3_625 2
  436. #define FF_ASPECT_4_3_525 3
  437. #define FF_ASPECT_16_9_625 4
  438. #define FF_ASPECT_16_9_525 5
  439. #define FF_ASPECT_EXTENDED 15
  440. /**
  441. * the number of pictures in a group of pitures, or 0 for intra_only.
  442. * - encoding: set by user.
  443. * - decoding: unused
  444. */
  445. int gop_size;
  446. /**
  447. * pixel format, see PIX_FMT_xxx.
  448. * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt
  449. * conversion is in order. This only works for
  450. * codecs with one supported pix_fmt, we should
  451. * do something for a generic case as well.
  452. * - decoding: set by lavc.
  453. */
  454. enum PixelFormat pix_fmt;
  455. /**
  456. * Frame rate emulation. If not zero lower layer (i.e. format handler)
  457. * has to read frames at native frame rate.
  458. * - encoding: set by user.
  459. * - decoding: unused.
  460. */
  461. int rate_emu;
  462. /**
  463. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  464. * decoder to draw an horizontal band. It improve cache usage. Not
  465. * all codecs can do that. You must check the codec capabilities
  466. * before
  467. * - encoding: unused
  468. * - decoding: set by user.
  469. * @param height the height of the slice
  470. * @param y the y position of the slice
  471. * @param type 1->top field, 2->bottom field, 3->frame
  472. * @param offset offset into the AVFrame.data from which the slice should be read
  473. */
  474. void (*draw_horiz_band)(struct AVCodecContext *s,
  475. AVFrame *src, int offset[4],
  476. int y, int type, int height);
  477. /* audio only */
  478. int sample_rate; ///< samples per sec
  479. int channels;
  480. int sample_fmt; ///< sample format, currenly unused
  481. /* the following data should not be initialized */
  482. int frame_size; ///< in samples, initialized when calling 'init'
  483. int frame_number; ///< audio or video frame number
  484. int real_pict_num; ///< returns the real picture number of previous encoded frame
  485. /**
  486. * number of frames the decoded output will be delayed relative to
  487. * the encoded input.
  488. * - encoding: set by lavc.
  489. * - decoding: unused
  490. */
  491. int delay;
  492. /* - encoding parameters */
  493. float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
  494. float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
  495. /**
  496. * minimum quantizer.
  497. * - encoding: set by user.
  498. * - decoding: unused
  499. */
  500. int qmin;
  501. /**
  502. * maximum quantizer.
  503. * - encoding: set by user.
  504. * - decoding: unused
  505. */
  506. int qmax;
  507. /**
  508. * maximum quantizer difference etween frames.
  509. * - encoding: set by user.
  510. * - decoding: unused
  511. */
  512. int max_qdiff;
  513. /**
  514. * maximum number of b frames between non b frames.
  515. * note: the output will be delayed by max_b_frames+1 relative to the input
  516. * - encoding: set by user.
  517. * - decoding: unused
  518. */
  519. int max_b_frames;
  520. /**
  521. * qscale factor between ip and b frames.
  522. * - encoding: set by user.
  523. * - decoding: unused
  524. */
  525. float b_quant_factor;
  526. /** obsolete FIXME remove */
  527. int rc_strategy;
  528. int b_frame_strategy;
  529. /**
  530. * hurry up amount.
  531. * - encoding: unused
  532. * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  533. */
  534. int hurry_up;
  535. struct AVCodec *codec;
  536. void *priv_data;
  537. /* The following data is for RTP friendly coding */
  538. /* By now only H.263/H.263+/MPEG4 coder honours this */
  539. int rtp_mode; /* 1 for activate RTP friendly-mode */
  540. /* highers numbers represent more error-prone */
  541. /* enviroments, by now just "1" exist */
  542. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  543. /* do it's best to deliver a chunk with size */
  544. /* below rtp_payload_size, the chunk will start */
  545. /* with a start code on some codecs like H.263 */
  546. /* This doesn't take account of any particular */
  547. /* headers inside the transmited RTP payload */
  548. /* The RTP callcack: This function is called */
  549. /* every time the encoder as a packet to send */
  550. /* Depends on the encoder if the data starts */
  551. /* with a Start Code (it should) H.263 does */
  552. void (*rtp_callback)(void *data, int size, int packet_number);
  553. /* statistics, used for 2-pass encoding */
  554. int mv_bits;
  555. int header_bits;
  556. int i_tex_bits;
  557. int p_tex_bits;
  558. int i_count;
  559. int p_count;
  560. int skip_count;
  561. int misc_bits;
  562. /**
  563. * number of bits used for the previously encoded frame.
  564. * - encoding: set by lavc
  565. * - decoding: unused
  566. */
  567. int frame_bits;
  568. /**
  569. * private data of the user, can be used to carry app specific stuff.
  570. * - encoding: set by user
  571. * - decoding: set by user
  572. */
  573. void *opaque;
  574. char codec_name[32];
  575. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  576. enum CodecID codec_id; /* see CODEC_ID_xxx */
  577. /**
  578. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  579. * this is used to workaround some encoder bugs
  580. * - encoding: set by user, if not then the default based on codec_id will be used
  581. * - decoding: set by user, will be converted to upper case by lavc during init
  582. */
  583. unsigned int codec_tag;
  584. /**
  585. * workaround bugs in encoders which sometimes cannot be detected automatically.
  586. * - encoding: unused
  587. * - decoding: set by user
  588. */
  589. int workaround_bugs;
  590. #define FF_BUG_AUTODETECT 1 ///< autodetection
  591. #define FF_BUG_OLD_MSMPEG4 2
  592. #define FF_BUG_XVID_ILACE 4
  593. #define FF_BUG_UMP4 8
  594. #define FF_BUG_NO_PADDING 16
  595. #define FF_BUG_AC_VLC 32
  596. #define FF_BUG_QPEL_CHROMA 64
  597. #define FF_BUG_STD_QPEL 128
  598. #define FF_BUG_QPEL_CHROMA2 256
  599. #define FF_BUG_DIRECT_BLOCKSIZE 512
  600. #define FF_BUG_EDGE 1024
  601. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  602. /**
  603. * luma single coeff elimination threshold.
  604. * - encoding: set by user
  605. * - decoding: unused
  606. */
  607. int luma_elim_threshold;
  608. /**
  609. * chroma single coeff elimination threshold.
  610. * - encoding: set by user
  611. * - decoding: unused
  612. */
  613. int chroma_elim_threshold;
  614. /**
  615. * strictly follow the std (MPEG4, ...).
  616. * - encoding: set by user
  617. * - decoding: unused
  618. */
  619. int strict_std_compliance;
  620. /**
  621. * qscale offset between ip and b frames.
  622. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  623. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  624. * - encoding: set by user.
  625. * - decoding: unused
  626. */
  627. float b_quant_offset;
  628. /**
  629. * error resilience higher values will detect more errors but may missdetect
  630. * some more or less valid parts as errors.
  631. * - encoding: unused
  632. * - decoding: set by user
  633. */
  634. int error_resilience;
  635. #define FF_ER_CAREFULL 1
  636. #define FF_ER_COMPLIANT 2
  637. #define FF_ER_AGGRESSIVE 3
  638. #define FF_ER_VERY_AGGRESSIVE 4
  639. /**
  640. * called at the beginning of each frame to get a buffer for it.
  641. * if pic.reference is set then the frame will be read later by lavc
  642. * width and height should be rounded up to the next multiple of 16
  643. * - encoding: unused
  644. * - decoding: set by lavc, user can override
  645. */
  646. int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
  647. /**
  648. * called to release buffers which where allocated with get_buffer.
  649. * a released buffer can be reused in get_buffer()
  650. * pic.data[*] must be set to NULL
  651. * - encoding: unused
  652. * - decoding: set by lavc, user can override
  653. */
  654. void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
  655. /**
  656. * is 1 if the decoded stream contains b frames, 0 otherwise.
  657. * - encoding: unused
  658. * - decoding: set by lavc
  659. */
  660. int has_b_frames;
  661. int block_align; ///< used by some WAV based audio codecs
  662. int parse_only; /* - decoding only: if true, only parsing is done
  663. (function avcodec_parse_frame()). The frame
  664. data is returned. Only MPEG codecs support this now. */
  665. /**
  666. * 0-> h263 quant 1-> mpeg quant.
  667. * - encoding: set by user.
  668. * - decoding: unused
  669. */
  670. int mpeg_quant;
  671. /**
  672. * pass1 encoding statistics output buffer.
  673. * - encoding: set by lavc
  674. * - decoding: unused
  675. */
  676. char *stats_out;
  677. /**
  678. * pass2 encoding statistics input buffer.
  679. * concatenated stuff from stats_out of pass1 should be placed here
  680. * - encoding: allocated/set/freed by user
  681. * - decoding: unused
  682. */
  683. char *stats_in;
  684. /**
  685. * ratecontrol qmin qmax limiting method.
  686. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  687. * - encoding: set by user.
  688. * - decoding: unused
  689. */
  690. float rc_qsquish;
  691. float rc_qmod_amp;
  692. int rc_qmod_freq;
  693. /**
  694. * ratecontrol override, see RcOverride.
  695. * - encoding: allocated/set/freed by user.
  696. * - decoding: unused
  697. */
  698. RcOverride *rc_override;
  699. int rc_override_count;
  700. /**
  701. * rate control equation.
  702. * - encoding: set by user
  703. * - decoding: unused
  704. */
  705. char *rc_eq;
  706. /**
  707. * maximum bitrate.
  708. * - encoding: set by user.
  709. * - decoding: unused
  710. */
  711. int rc_max_rate;
  712. /**
  713. * minimum bitrate.
  714. * - encoding: set by user.
  715. * - decoding: unused
  716. */
  717. int rc_min_rate;
  718. /**
  719. * decoder bitstream buffer size.
  720. * - encoding: set by user.
  721. * - decoding: unused
  722. */
  723. int rc_buffer_size;
  724. float rc_buffer_aggressivity;
  725. /**
  726. * qscale factor between p and i frames.
  727. * - encoding: set by user.
  728. * - decoding: unused
  729. */
  730. float i_quant_factor;
  731. /**
  732. * qscale offset between p and i frames.
  733. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  734. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  735. * - encoding: set by user.
  736. * - decoding: unused
  737. */
  738. float i_quant_offset;
  739. /**
  740. * initial complexity for pass1 ratecontrol.
  741. * - encoding: set by user.
  742. * - decoding: unused
  743. */
  744. float rc_initial_cplx;
  745. /**
  746. * dct algorithm, see FF_DCT_* below.
  747. * - encoding: set by user
  748. * - decoding: unused
  749. */
  750. int dct_algo;
  751. #define FF_DCT_AUTO 0
  752. #define FF_DCT_FASTINT 1
  753. #define FF_DCT_INT 2
  754. #define FF_DCT_MMX 3
  755. #define FF_DCT_MLIB 4
  756. #define FF_DCT_ALTIVEC 5
  757. /**
  758. * luminance masking (0-> disabled).
  759. * - encoding: set by user
  760. * - decoding: unused
  761. */
  762. float lumi_masking;
  763. /**
  764. * temporary complexity masking (0-> disabled).
  765. * - encoding: set by user
  766. * - decoding: unused
  767. */
  768. float temporal_cplx_masking;
  769. /**
  770. * spatial complexity masking (0-> disabled).
  771. * - encoding: set by user
  772. * - decoding: unused
  773. */
  774. float spatial_cplx_masking;
  775. /**
  776. * p block masking (0-> disabled).
  777. * - encoding: set by user
  778. * - decoding: unused
  779. */
  780. float p_masking;
  781. /**
  782. * darkness masking (0-> disabled).
  783. * - encoding: set by user
  784. * - decoding: unused
  785. */
  786. float dark_masking;
  787. /* for binary compatibility */
  788. int unused;
  789. /**
  790. * idct algorithm, see FF_IDCT_* below.
  791. * - encoding: set by user
  792. * - decoding: set by user
  793. */
  794. int idct_algo;
  795. #define FF_IDCT_AUTO 0
  796. #define FF_IDCT_INT 1
  797. #define FF_IDCT_SIMPLE 2
  798. #define FF_IDCT_SIMPLEMMX 3
  799. #define FF_IDCT_LIBMPEG2MMX 4
  800. #define FF_IDCT_PS2 5
  801. #define FF_IDCT_MLIB 6
  802. #define FF_IDCT_ARM 7
  803. #define FF_IDCT_ALTIVEC 8
  804. #define FF_IDCT_SH4 9
  805. #define FF_IDCT_SIMPLEARM 10
  806. /**
  807. * slice count.
  808. * - encoding: set by lavc
  809. * - decoding: set by user (or 0)
  810. */
  811. int slice_count;
  812. /**
  813. * slice offsets in the frame in bytes.
  814. * - encoding: set/allocated by lavc
  815. * - decoding: set/allocated by user (or NULL)
  816. */
  817. int *slice_offset;
  818. /**
  819. * error concealment flags.
  820. * - encoding: unused
  821. * - decoding: set by user
  822. */
  823. int error_concealment;
  824. #define FF_EC_GUESS_MVS 1
  825. #define FF_EC_DEBLOCK 2
  826. /**
  827. * dsp_mask could be add used to disable unwanted CPU features
  828. * CPU features (i.e. MMX, SSE. ...)
  829. *
  830. * with FORCE flag you may instead enable given CPU features
  831. * (Dangerous: usable in case of misdetection, improper usage however will
  832. * result into program crash)
  833. */
  834. unsigned dsp_mask;
  835. #define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
  836. /* lower 16 bits - CPU features */
  837. #ifdef HAVE_MMX
  838. #define FF_MM_MMX 0x0001 /* standard MMX */
  839. #define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
  840. #define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
  841. #define FF_MM_SSE 0x0008 /* SSE functions */
  842. #define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
  843. #endif /* HAVE_MMX */
  844. /**
  845. * bits per sample/pixel from the demuxer (needed for huffyuv).
  846. * - encoding: set by lavc
  847. * - decoding: set by user
  848. */
  849. int bits_per_sample;
  850. /**
  851. * prediction method (needed for huffyuv).
  852. * - encoding: set by user
  853. * - decoding: unused
  854. */
  855. int prediction_method;
  856. #define FF_PRED_LEFT 0
  857. #define FF_PRED_PLANE 1
  858. #define FF_PRED_MEDIAN 2
  859. /**
  860. * aspect ratio (0 if unknown).
  861. * - encoding: set by user.
  862. * - decoding: set by lavc.
  863. */
  864. float aspect_ratio;
  865. /**
  866. * the picture in the bitstream.
  867. * - encoding: set by lavc
  868. * - decoding: set by lavc
  869. */
  870. AVFrame *coded_frame;
  871. /**
  872. * debug.
  873. * - encoding: set by user.
  874. * - decoding: set by user.
  875. */
  876. int debug;
  877. #define FF_DEBUG_PICT_INFO 1
  878. #define FF_DEBUG_RC 2
  879. #define FF_DEBUG_BITSTREAM 4
  880. #define FF_DEBUG_MB_TYPE 8
  881. #define FF_DEBUG_QP 16
  882. #define FF_DEBUG_MV 32
  883. #define FF_DEBUG_VIS_MV 0x00000040
  884. #define FF_DEBUG_SKIP 0x00000080
  885. #define FF_DEBUG_STARTCODE 0x00000100
  886. #define FF_DEBUG_PTS 0x00000200
  887. #define FF_DEBUG_ER 0x00000400
  888. #define FF_DEBUG_MMCO 0x00000800
  889. #define FF_DEBUG_BUGS 0x00001000
  890. /**
  891. * error.
  892. * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
  893. * - decoding: unused
  894. */
  895. uint64_t error[4];
  896. /**
  897. * minimum MB quantizer.
  898. * - encoding: set by user.
  899. * - decoding: unused
  900. */
  901. int mb_qmin;
  902. /**
  903. * maximum MB quantizer.
  904. * - encoding: set by user.
  905. * - decoding: unused
  906. */
  907. int mb_qmax;
  908. /**
  909. * motion estimation compare function.
  910. * - encoding: set by user.
  911. * - decoding: unused
  912. */
  913. int me_cmp;
  914. /**
  915. * subpixel motion estimation compare function.
  916. * - encoding: set by user.
  917. * - decoding: unused
  918. */
  919. int me_sub_cmp;
  920. /**
  921. * macroblock compare function (not supported yet).
  922. * - encoding: set by user.
  923. * - decoding: unused
  924. */
  925. int mb_cmp;
  926. #define FF_CMP_SAD 0
  927. #define FF_CMP_SSE 1
  928. #define FF_CMP_SATD 2
  929. #define FF_CMP_DCT 3
  930. #define FF_CMP_PSNR 4
  931. #define FF_CMP_BIT 5
  932. #define FF_CMP_RD 6
  933. #define FF_CMP_ZERO 7
  934. #define FF_CMP_CHROMA 256
  935. /**
  936. * ME diamond size & shape.
  937. * - encoding: set by user.
  938. * - decoding: unused
  939. */
  940. int dia_size;
  941. /**
  942. * amount of previous MV predictors (2a+1 x 2a+1 square).
  943. * - encoding: set by user.
  944. * - decoding: unused
  945. */
  946. int last_predictor_count;
  947. /**
  948. * pre pass for motion estimation.
  949. * - encoding: set by user.
  950. * - decoding: unused
  951. */
  952. int pre_me;
  953. /**
  954. * motion estimation pre pass compare function.
  955. * - encoding: set by user.
  956. * - decoding: unused
  957. */
  958. int me_pre_cmp;
  959. /**
  960. * ME pre pass diamond size & shape.
  961. * - encoding: set by user.
  962. * - decoding: unused
  963. */
  964. int pre_dia_size;
  965. /**
  966. * subpel ME quality.
  967. * - encoding: set by user.
  968. * - decoding: unused
  969. */
  970. int me_subpel_quality;
  971. /**
  972. * callback to negotiate the pixelFormat.
  973. * @param fmt is the list of formats which are supported by the codec,
  974. * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
  975. * the first is allways the native one
  976. * @return the choosen format
  977. * - encoding: unused
  978. * - decoding: set by user, if not set then the native format will always be choosen
  979. */
  980. enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
  981. /**
  982. * DTG active format information (additionnal aspect ratio
  983. * information only used in DVB MPEG2 transport streams). 0 if
  984. * not set.
  985. *
  986. * - encoding: unused.
  987. * - decoding: set by decoder
  988. */
  989. int dtg_active_format;
  990. #define FF_DTG_AFD_SAME 8
  991. #define FF_DTG_AFD_4_3 9
  992. #define FF_DTG_AFD_16_9 10
  993. #define FF_DTG_AFD_14_9 11
  994. #define FF_DTG_AFD_4_3_SP_14_9 13
  995. #define FF_DTG_AFD_16_9_SP_14_9 14
  996. #define FF_DTG_AFD_SP_4_3 15
  997. /**
  998. * Maximum motion estimation search range in subpel units.
  999. * if 0 then no limit
  1000. *
  1001. * - encoding: set by user.
  1002. * - decoding: unused.
  1003. */
  1004. int me_range;
  1005. /**
  1006. * frame_rate_base.
  1007. * for variable fps this is 1
  1008. * - encoding: set by user.
  1009. * - decoding: set by lavc.
  1010. * @todo move this after frame_rate
  1011. */
  1012. int frame_rate_base;
  1013. /**
  1014. * intra quantizer bias.
  1015. * - encoding: set by user.
  1016. * - decoding: unused
  1017. */
  1018. int intra_quant_bias;
  1019. #define FF_DEFAULT_QUANT_BIAS 999999
  1020. /**
  1021. * inter quantizer bias.
  1022. * - encoding: set by user.
  1023. * - decoding: unused
  1024. */
  1025. int inter_quant_bias;
  1026. /**
  1027. * color table ID.
  1028. * - encoding: unused.
  1029. * - decoding: which clrtable should be used for 8bit RGB images
  1030. * table have to be stored somewhere FIXME
  1031. */
  1032. int color_table_id;
  1033. /**
  1034. * internal_buffer count.
  1035. * Dont touch, used by lavc default_get_buffer()
  1036. */
  1037. int internal_buffer_count;
  1038. /**
  1039. * internal_buffers.
  1040. * Dont touch, used by lavc default_get_buffer()
  1041. */
  1042. void *internal_buffer;
  1043. #define FF_QUALITY_SCALE 256
  1044. /**
  1045. * global quality for codecs which cannot change it per frame.
  1046. * this should be proportional to MPEG1/2/4 qscale.
  1047. * - encoding: set by user.
  1048. * - decoding: unused
  1049. */
  1050. int global_quality;
  1051. #define FF_CODER_TYPE_VLC 0
  1052. #define FF_CODER_TYPE_AC 1
  1053. /**
  1054. * coder type
  1055. * - encoding: set by user.
  1056. * - decoding: unused
  1057. */
  1058. int coder_type;
  1059. /**
  1060. * context model
  1061. * - encoding: set by user.
  1062. * - decoding: unused
  1063. */
  1064. int context_model;
  1065. /**
  1066. * slice flags
  1067. * - encoding: unused
  1068. * - decoding: set by user.
  1069. */
  1070. int slice_flags;
  1071. #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
  1072. #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
  1073. #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
  1074. /**
  1075. * XVideo Motion Acceleration
  1076. * - encoding: forbidden
  1077. * - decoding: set by decoder
  1078. */
  1079. int xvmc_acceleration;
  1080. /**
  1081. * macroblock decision mode
  1082. * - encoding: set by user.
  1083. * - decoding: unused
  1084. */
  1085. int mb_decision;
  1086. #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
  1087. #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
  1088. #define FF_MB_DECISION_RD 2 ///< rate distoration
  1089. /**
  1090. * custom intra quantization matrix
  1091. * - encoding: set by user, can be NULL
  1092. * - decoding: set by lavc
  1093. */
  1094. uint16_t *intra_matrix;
  1095. /**
  1096. * custom inter quantization matrix
  1097. * - encoding: set by user, can be NULL
  1098. * - decoding: set by lavc
  1099. */
  1100. uint16_t *inter_matrix;
  1101. /**
  1102. * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
  1103. * this is used to workaround some encoder bugs
  1104. * - encoding: unused
  1105. * - decoding: set by user, will be converted to upper case by lavc during init
  1106. */
  1107. unsigned int stream_codec_tag;
  1108. /**
  1109. * scene change detection threshold.
  1110. * 0 is default, larger means fewer detected scene changes
  1111. * - encoding: set by user.
  1112. * - decoding: unused
  1113. */
  1114. int scenechange_threshold;
  1115. } AVCodecContext;
  1116. /**
  1117. * AVOption.
  1118. */
  1119. typedef struct AVOption {
  1120. /** options' name */
  1121. const char *name; /* if name is NULL, it indicates a link to next */
  1122. /** short English text help or const struct AVOption* subpointer */
  1123. const char *help; // const struct AVOption* sub;
  1124. /** offset to context structure where the parsed value should be stored */
  1125. int offset;
  1126. /** options' type */
  1127. int type;
  1128. #define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
  1129. #define FF_OPT_TYPE_DOUBLE 2 ///< double
  1130. #define FF_OPT_TYPE_INT 3 ///< integer
  1131. #define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
  1132. #define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
  1133. //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
  1134. #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
  1135. #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
  1136. /** min value (min == max -> no limits) */
  1137. double min;
  1138. /** maximum value for double/int */
  1139. double max;
  1140. /** default boo [0,1]l/double/int value */
  1141. double defval;
  1142. /**
  1143. * default string value (with optional semicolon delimited extra option-list
  1144. * i.e. option1;option2;option3
  1145. * defval might select other then first argument as default
  1146. */
  1147. const char *defstr;
  1148. #define FF_OPT_MAX_DEPTH 10
  1149. } AVOption;
  1150. /**
  1151. * Parse option(s) and sets fields in passed structure
  1152. * @param strct structure where the parsed results will be written
  1153. * @param list list with AVOptions
  1154. * @param opts string with options for parsing
  1155. */
  1156. int avoption_parse(void* strct, const AVOption* list, const char* opts);
  1157. /**
  1158. * AVCodec.
  1159. */
  1160. typedef struct AVCodec {
  1161. const char *name;
  1162. enum CodecType type;
  1163. int id;
  1164. int priv_data_size;
  1165. int (*init)(AVCodecContext *);
  1166. int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
  1167. int (*close)(AVCodecContext *);
  1168. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  1169. uint8_t *buf, int buf_size);
  1170. int capabilities;
  1171. const AVOption *options;
  1172. struct AVCodec *next;
  1173. void (*flush)(AVCodecContext *);
  1174. } AVCodec;
  1175. /**
  1176. * four components are given, that's all.
  1177. * the last component is alpha
  1178. */
  1179. typedef struct AVPicture {
  1180. uint8_t *data[4];
  1181. int linesize[4]; ///< number of bytes per line
  1182. } AVPicture;
  1183. /**
  1184. * AVPaletteControl
  1185. * This structure defines a method for communicating palette changes
  1186. * between and demuxer and a decoder.
  1187. */
  1188. typedef struct AVPaletteControl {
  1189. /* demuxer sets this to 1 to indicate the palette has changed;
  1190. * decoder resets to 0 */
  1191. int palette_changed;
  1192. /* 256 3-byte RGB palette entries; the components should be
  1193. * formatted in the buffer as "RGBRGB..." and should be scaled to
  1194. * 8 bits if they originally represented 6-bit VGA palette
  1195. * components */
  1196. unsigned char palette[256 * 3];
  1197. } AVPaletteControl;
  1198. extern AVCodec ac3_encoder;
  1199. extern AVCodec mp2_encoder;
  1200. extern AVCodec mp3lame_encoder;
  1201. extern AVCodec oggvorbis_encoder;
  1202. extern AVCodec mpeg1video_encoder;
  1203. extern AVCodec mpeg2video_encoder;
  1204. extern AVCodec h263_encoder;
  1205. extern AVCodec h263p_encoder;
  1206. extern AVCodec flv_encoder;
  1207. extern AVCodec rv10_encoder;
  1208. extern AVCodec mjpeg_encoder;
  1209. extern AVCodec ljpeg_encoder;
  1210. extern AVCodec mpeg4_encoder;
  1211. extern AVCodec msmpeg4v1_encoder;
  1212. extern AVCodec msmpeg4v2_encoder;
  1213. extern AVCodec msmpeg4v3_encoder;
  1214. extern AVCodec wmv1_encoder;
  1215. extern AVCodec wmv2_encoder;
  1216. extern AVCodec huffyuv_encoder;
  1217. extern AVCodec h264_encoder;
  1218. extern AVCodec asv1_encoder;
  1219. extern AVCodec asv2_encoder;
  1220. extern AVCodec vcr1_encoder;
  1221. extern AVCodec ffv1_encoder;
  1222. extern AVCodec mdec_encoder;
  1223. extern AVCodec h263_decoder;
  1224. extern AVCodec mpeg4_decoder;
  1225. extern AVCodec msmpeg4v1_decoder;
  1226. extern AVCodec msmpeg4v2_decoder;
  1227. extern AVCodec msmpeg4v3_decoder;
  1228. extern AVCodec wmv1_decoder;
  1229. extern AVCodec wmv2_decoder;
  1230. extern AVCodec mpeg1video_decoder;
  1231. extern AVCodec mpeg2video_decoder;
  1232. extern AVCodec mpeg_xvmc_decoder;
  1233. extern AVCodec h263i_decoder;
  1234. extern AVCodec flv_decoder;
  1235. extern AVCodec rv10_decoder;
  1236. extern AVCodec svq1_decoder;
  1237. extern AVCodec svq3_decoder;
  1238. extern AVCodec dvvideo_decoder;
  1239. extern AVCodec dvaudio_decoder;
  1240. extern AVCodec wmav1_decoder;
  1241. extern AVCodec wmav2_decoder;
  1242. extern AVCodec mjpeg_decoder;
  1243. extern AVCodec mjpegb_decoder;
  1244. extern AVCodec mp2_decoder;
  1245. extern AVCodec mp3_decoder;
  1246. extern AVCodec mace3_decoder;
  1247. extern AVCodec mace6_decoder;
  1248. extern AVCodec huffyuv_decoder;
  1249. extern AVCodec oggvorbis_decoder;
  1250. extern AVCodec cyuv_decoder;
  1251. extern AVCodec h264_decoder;
  1252. extern AVCodec indeo3_decoder;
  1253. extern AVCodec vp3_decoder;
  1254. extern AVCodec amr_nb_decoder;
  1255. extern AVCodec amr_nb_encoder;
  1256. extern AVCodec amr_wb_encoder;
  1257. extern AVCodec amr_wb_decoder;
  1258. extern AVCodec aac_decoder;
  1259. extern AVCodec mpeg4aac_decoder;
  1260. extern AVCodec asv1_decoder;
  1261. extern AVCodec asv2_decoder;
  1262. extern AVCodec vcr1_decoder;
  1263. extern AVCodec cljr_decoder;
  1264. extern AVCodec ffv1_decoder;
  1265. extern AVCodec fourxm_decoder;
  1266. extern AVCodec mdec_decoder;
  1267. extern AVCodec roq_decoder;
  1268. extern AVCodec interplay_video_decoder;
  1269. extern AVCodec xan_wc3_decoder;
  1270. extern AVCodec ra_144_decoder;
  1271. extern AVCodec ra_288_decoder;
  1272. extern AVCodec roq_dpcm_decoder;
  1273. extern AVCodec interplay_dpcm_decoder;
  1274. extern AVCodec xan_dpcm_decoder;
  1275. /* pcm codecs */
  1276. #define PCM_CODEC(id, name) \
  1277. extern AVCodec name ## _decoder; \
  1278. extern AVCodec name ## _encoder
  1279. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  1280. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  1281. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  1282. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  1283. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  1284. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  1285. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  1286. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  1287. /* adpcm codecs */
  1288. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  1289. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  1290. PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
  1291. PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
  1292. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  1293. PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
  1294. #undef PCM_CODEC
  1295. /* dummy raw video codec */
  1296. extern AVCodec rawvideo_encoder;
  1297. extern AVCodec rawvideo_decoder;
  1298. /* the following codecs use external GPL libs */
  1299. extern AVCodec ac3_decoder;
  1300. /* resample.c */
  1301. struct ReSampleContext;
  1302. typedef struct ReSampleContext ReSampleContext;
  1303. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  1304. int output_rate, int input_rate);
  1305. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  1306. void audio_resample_close(ReSampleContext *s);
  1307. /* YUV420 format is assumed ! */
  1308. struct ImgReSampleContext;
  1309. typedef struct ImgReSampleContext ImgReSampleContext;
  1310. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  1311. int input_width, int input_height);
  1312. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  1313. int iwidth, int iheight,
  1314. int topBand, int bottomBand,
  1315. int leftBand, int rightBand);
  1316. void img_resample(ImgReSampleContext *s,
  1317. AVPicture *output, AVPicture *input);
  1318. void img_resample_close(ImgReSampleContext *s);
  1319. int avpicture_fill(AVPicture *picture, uint8_t *ptr,
  1320. int pix_fmt, int width, int height);
  1321. int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height,
  1322. unsigned char *dest, int dest_size);
  1323. int avpicture_get_size(int pix_fmt, int width, int height);
  1324. void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
  1325. const char *avcodec_get_pix_fmt_name(int pix_fmt);
  1326. enum PixelFormat avcodec_get_pix_fmt(const char* name);
  1327. #define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
  1328. #define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */
  1329. #define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */
  1330. #define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */
  1331. #define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */
  1332. #define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
  1333. int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
  1334. int has_alpha);
  1335. int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
  1336. int has_alpha, int *loss_ptr);
  1337. #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
  1338. #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
  1339. int img_get_alpha_info(AVPicture *src, int pix_fmt, int width, int height);
  1340. /* convert among pixel formats */
  1341. int img_convert(AVPicture *dst, int dst_pix_fmt,
  1342. AVPicture *src, int pix_fmt,
  1343. int width, int height);
  1344. /* deinterlace a picture */
  1345. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  1346. int pix_fmt, int width, int height);
  1347. /* external high level API */
  1348. extern AVCodec *first_avcodec;
  1349. /* returns LIBAVCODEC_VERSION_INT constant */
  1350. unsigned avcodec_version(void);
  1351. /* returns LIBAVCODEC_BUILD constant */
  1352. unsigned avcodec_build(void);
  1353. void avcodec_init(void);
  1354. void register_avcodec(AVCodec *format);
  1355. AVCodec *avcodec_find_encoder(enum CodecID id);
  1356. AVCodec *avcodec_find_encoder_by_name(const char *name);
  1357. AVCodec *avcodec_find_decoder(enum CodecID id);
  1358. AVCodec *avcodec_find_decoder_by_name(const char *name);
  1359. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  1360. void avcodec_get_context_defaults(AVCodecContext *s);
  1361. AVCodecContext *avcodec_alloc_context(void);
  1362. AVFrame *avcodec_alloc_frame(void);
  1363. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
  1364. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
  1365. void avcodec_default_free_buffers(AVCodecContext *s);
  1366. /**
  1367. * opens / inits the AVCodecContext.
  1368. * not thread save!
  1369. */
  1370. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  1371. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  1372. int *frame_size_ptr,
  1373. uint8_t *buf, int buf_size);
  1374. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  1375. int *got_picture_ptr,
  1376. uint8_t *buf, int buf_size);
  1377. int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
  1378. int *data_size_ptr,
  1379. uint8_t *buf, int buf_size);
  1380. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1381. const short *samples);
  1382. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  1383. const AVFrame *pict);
  1384. int avcodec_close(AVCodecContext *avctx);
  1385. void avcodec_register_all(void);
  1386. void avcodec_flush_buffers(AVCodecContext *avctx);
  1387. /* misc usefull functions */
  1388. /**
  1389. * returns a single letter to describe the picture type
  1390. */
  1391. char av_get_pict_type_char(int pict_type);
  1392. /**
  1393. * reduce a fraction.
  1394. * this is usefull for framerate calculations
  1395. * @param max the maximum allowed for dst_nom & dst_den
  1396. * @return 1 if exact, 0 otherwise
  1397. */
  1398. int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
  1399. /**
  1400. * rescale a 64bit integer.
  1401. * a simple a*b/c isnt possible as it can overflow
  1402. */
  1403. int64_t av_rescale(int64_t a, int b, int c);
  1404. /**
  1405. * Interface for 0.5.0 version
  1406. *
  1407. * do not even think about it's usage for this moment
  1408. */
  1409. typedef struct {
  1410. /// compressed size used from given memory buffer
  1411. int size;
  1412. /// I/P/B frame type
  1413. int frame_type;
  1414. } avc_enc_result_t;
  1415. /**
  1416. * Commands
  1417. * order can't be changed - once it was defined
  1418. */
  1419. typedef enum {
  1420. // general commands
  1421. AVC_OPEN_BY_NAME = 0xACA000,
  1422. AVC_OPEN_BY_CODEC_ID,
  1423. AVC_OPEN_BY_FOURCC,
  1424. AVC_CLOSE,
  1425. AVC_FLUSH,
  1426. // pin - struct { uint8_t* src, uint_t src_size }
  1427. // pout - struct { AVPicture* img, consumed_bytes,
  1428. AVC_DECODE,
  1429. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  1430. // pout - uint_t used_from_dest_size
  1431. AVC_ENCODE,
  1432. // query/get video commands
  1433. AVC_GET_VERSION = 0xACB000,
  1434. AVC_GET_WIDTH,
  1435. AVC_GET_HEIGHT,
  1436. AVC_GET_DELAY,
  1437. AVC_GET_QUANT_TABLE,
  1438. // ...
  1439. // query/get audio commands
  1440. AVC_GET_FRAME_SIZE = 0xABC000,
  1441. // maybe define some simple structure which
  1442. // might be passed to the user - but they can't
  1443. // contain any codec specific parts and these
  1444. // calls are usualy necessary only few times
  1445. // set video commands
  1446. AVC_SET_WIDTH = 0xACD000,
  1447. AVC_SET_HEIGHT,
  1448. // set video encoding commands
  1449. AVC_SET_FRAME_RATE = 0xACD800,
  1450. AVC_SET_QUALITY,
  1451. AVC_SET_HURRY_UP,
  1452. // set audio commands
  1453. AVC_SET_SAMPLE_RATE = 0xACE000,
  1454. AVC_SET_CHANNELS,
  1455. } avc_cmd_t;
  1456. /**
  1457. * \param handle allocated private structure by libavcodec
  1458. * for initialization pass NULL - will be returned pout
  1459. * user is supposed to know nothing about its structure
  1460. * \param cmd type of operation to be performed
  1461. * \param pint input parameter
  1462. * \param pout output parameter
  1463. *
  1464. * \returns command status - eventually for query command it might return
  1465. * integer resulting value
  1466. */
  1467. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  1468. /* memory */
  1469. void *av_malloc(unsigned int size);
  1470. void *av_mallocz(unsigned int size);
  1471. void *av_realloc(void *ptr, unsigned int size);
  1472. void av_free(void *ptr);
  1473. char *av_strdup(const char *s);
  1474. void __av_freep(void **ptr);
  1475. #define av_freep(p) __av_freep((void **)(p))
  1476. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
  1477. /* for static data only */
  1478. /* call av_free_static to release all staticaly allocated tables */
  1479. void av_free_static(void);
  1480. void *__av_mallocz_static(void** location, unsigned int size);
  1481. #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
  1482. #ifdef __cplusplus
  1483. }
  1484. #endif
  1485. #endif /* AVCODEC_H */