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.

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