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.

1626 lines
46KB

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