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.

1103 lines
30KB

  1. #ifndef AVCODEC_H
  2. #define AVCODEC_H
  3. #include "common.h"
  4. #define LIBAVCODEC_VERSION_INT 0x000406
  5. #define LIBAVCODEC_VERSION "0.4.6"
  6. #define LIBAVCODEC_BUILD 4642
  7. #define LIBAVCODEC_BUILD_STR "4642"
  8. enum CodecID {
  9. CODEC_ID_NONE,
  10. CODEC_ID_MPEG1VIDEO,
  11. CODEC_ID_H263,
  12. CODEC_ID_RV10,
  13. CODEC_ID_MP2,
  14. CODEC_ID_MP3LAME,
  15. CODEC_ID_VORBIS,
  16. CODEC_ID_AC3,
  17. CODEC_ID_MJPEG,
  18. CODEC_ID_MJPEGB,
  19. CODEC_ID_MPEG4,
  20. CODEC_ID_RAWVIDEO,
  21. CODEC_ID_MSMPEG4V1,
  22. CODEC_ID_MSMPEG4V2,
  23. CODEC_ID_MSMPEG4V3,
  24. CODEC_ID_WMV1,
  25. CODEC_ID_WMV2,
  26. CODEC_ID_H263P,
  27. CODEC_ID_H263I,
  28. CODEC_ID_SVQ1,
  29. CODEC_ID_DVVIDEO,
  30. CODEC_ID_DVAUDIO,
  31. CODEC_ID_WMAV1,
  32. CODEC_ID_WMAV2,
  33. CODEC_ID_MACE3,
  34. CODEC_ID_MACE6,
  35. CODEC_ID_HUFFYUV,
  36. /* various pcm "codecs" */
  37. CODEC_ID_PCM_S16LE,
  38. CODEC_ID_PCM_S16BE,
  39. CODEC_ID_PCM_U16LE,
  40. CODEC_ID_PCM_U16BE,
  41. CODEC_ID_PCM_S8,
  42. CODEC_ID_PCM_U8,
  43. CODEC_ID_PCM_MULAW,
  44. CODEC_ID_PCM_ALAW,
  45. /* various adpcm codecs */
  46. CODEC_ID_ADPCM_IMA_QT,
  47. CODEC_ID_ADPCM_IMA_WAV,
  48. CODEC_ID_ADPCM_MS,
  49. };
  50. enum CodecType {
  51. CODEC_TYPE_UNKNOWN = -1,
  52. CODEC_TYPE_VIDEO,
  53. CODEC_TYPE_AUDIO,
  54. };
  55. enum PixelFormat {
  56. PIX_FMT_ANY = -1,
  57. PIX_FMT_YUV420P,
  58. PIX_FMT_YUV422,
  59. PIX_FMT_RGB24,
  60. PIX_FMT_BGR24,
  61. PIX_FMT_YUV422P,
  62. PIX_FMT_YUV444P,
  63. PIX_FMT_RGBA32,
  64. PIX_FMT_BGRA32,
  65. PIX_FMT_YUV410P,
  66. PIX_FMT_YUV411P,
  67. PIX_FMT_RGB565,
  68. PIX_FMT_RGB555,
  69. // PIX_FMT_RGB5551,
  70. PIX_FMT_BGR565,
  71. PIX_FMT_BGR555,
  72. // PIX_FMT_GBR565,
  73. // PIX_FMT_GBR555
  74. };
  75. /* currently unused, may be used if 24/32 bits samples ever supported */
  76. enum SampleFormat {
  77. SAMPLE_FMT_S16 = 0, /* signed 16 bits */
  78. };
  79. /* in bytes */
  80. #define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
  81. /**
  82. * Required number of zero bytes at the end of the input bitstream for decoding.
  83. * to avoid overreading (and possibly segfaulting)
  84. */
  85. #define FF_INPUT_BUFFER_PADDING_SIZE 8
  86. /* motion estimation type, EPZS by default */
  87. enum Motion_Est_ID {
  88. ME_ZERO = 1,
  89. ME_FULL,
  90. ME_LOG,
  91. ME_PHODS,
  92. ME_EPZS,
  93. ME_X1
  94. };
  95. typedef struct RcOverride{
  96. int start_frame;
  97. int end_frame;
  98. int qscale; // if this is 0 then quality_factor will be used instead
  99. float quality_factor;
  100. } RcOverride;
  101. /* only for ME compatiblity with old apps */
  102. extern int motion_estimation_method;
  103. /* ME algos sorted by quality */
  104. static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
  105. ME_X1, ME_EPZS, ME_FULL };
  106. #define FF_MAX_B_FRAMES 4
  107. /* encoding support
  108. these flags can be passed in AVCodecContext.flags before initing
  109. Note: note not everything is supported yet
  110. */
  111. #define CODEC_FLAG_HQ 0x0001 /* brute force MB-type decission mode (slow) */
  112. #define CODEC_FLAG_QSCALE 0x0002 /* use fixed qscale */
  113. #define CODEC_FLAG_4MV 0x0004 /* 4 MV per MB allowed */
  114. #define CODEC_FLAG_QPEL 0x0010 /* use qpel MC */
  115. #define CODEC_FLAG_GMC 0x0020 /* use GMC */
  116. #define CODEC_FLAG_PART 0x0080 /* use data partitioning */
  117. /* parent program gurantees that the input for b-frame containing streams is not written to
  118. for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
  119. #define CODEC_FLAG_INPUT_PRESERVED 0x0100
  120. #define CODEC_FLAG_PASS1 0x0200 /* use internal 2pass ratecontrol in first pass mode */
  121. #define CODEC_FLAG_PASS2 0x0400 /* use internal 2pass ratecontrol in second pass mode */
  122. #define CODEC_FLAG_EXTERN_HUFF 0x1000 /* use external huffman table (for mjpeg) */
  123. #define CODEC_FLAG_GRAY 0x2000 /* only decode/encode grayscale */
  124. #define CODEC_FLAG_EMU_EDGE 0x4000/* dont draw edges */
  125. #define CODEC_FLAG_TRUNCATED 0x00010000 /* input bitstream might be truncated at a random location instead
  126. of only at frame boundaries */
  127. #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 /* normalize adaptive quantization */
  128. #define CODEC_FLAG_INTERLACED_DCT 0x00040000 /* use interlaced dct */
  129. #define CODEC_FLAG_LOW_DELAY 0x00080000 /* force low delay / will fail on b frames */
  130. #define CODEC_FLAG_ALT_SCAN 0x00100000 /* use alternate scan */
  131. /* codec capabilities */
  132. #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 /* decoder can use draw_horiz_band callback */
  133. #define CODEC_CAP_DR1 0x0002 /* direct rendering method 1 */
  134. /* if 'parse_only' field is true, then avcodec_parse_frame() can be
  135. used */
  136. #define CODEC_CAP_PARSE_ONLY 0x0004
  137. #define CODEC_CAP_TRUNCATED 0x0008
  138. #define FRAME_RATE_BASE 10000
  139. #define FF_COMMON_PICTURE \
  140. uint8_t *data[4];\
  141. int linesize[4];\
  142. /**\
  143. * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer
  144. * this isnt used by lavc unless the default get/release_buffer() is used\
  145. * encoding: \
  146. * decoding: \
  147. */\
  148. uint8_t *base[4];\
  149. /**\
  150. * 1 -> keyframe, 0-> not\
  151. * encoding: set by lavc\
  152. * decoding: set by lavc\
  153. */\
  154. int key_frame;\
  155. \
  156. /**\
  157. * picture type of the frame, see ?_TYPE below\
  158. * encoding: set by lavc for coded_picture (and set by user for input)\
  159. * decoding: set by lavc\
  160. */\
  161. int pict_type;\
  162. \
  163. /**\
  164. * presentation timestamp in micro seconds (time when frame should be shown to user)\
  165. * if 0 then the frame_rate will be used as reference\
  166. * encoding: MUST be set by user\
  167. * decoding: set by lavc\
  168. */\
  169. long long int pts;\
  170. \
  171. /**\
  172. * picture number in bitstream order.\
  173. * encoding: set by\
  174. * decoding: set by lavc\
  175. */\
  176. int coded_picture_number;\
  177. /**\
  178. * encoding: set by\
  179. * decoding: set by lavc\
  180. * picture number in display order.\
  181. */\
  182. int display_picture_number;\
  183. \
  184. /**\
  185. * quality (between 1 (good) and 31 (bad)) \
  186. * encoding: set by lavc for coded_picture (and set by user for input)\
  187. * decoding: set by lavc\
  188. */\
  189. float quality; \
  190. \
  191. /**\
  192. * buffer age (1->was last buffer and dint change, 2->..., ...).\
  193. * set to something large if the buffer has not been used yet \
  194. * encoding: unused\
  195. * decoding: MUST be set by get_buffer()\
  196. */\
  197. int age;\
  198. \
  199. /**\
  200. * is this picture used as reference\
  201. * encoding: unused\
  202. * decoding: set by lavc (before get_buffer() call))\
  203. */\
  204. int reference;\
  205. \
  206. /**\
  207. * QP table\
  208. * encoding: unused\
  209. * decoding: set by lavc\
  210. */\
  211. int8_t *qscale_table;\
  212. /**\
  213. * QP store stride\
  214. * encoding: unused\
  215. * decoding: set by lavc\
  216. */\
  217. int qstride;\
  218. \
  219. /**\
  220. * mbskip_table[mb]>=1 if MB didnt change\
  221. * stride= mb_width = (width+15)>>4\
  222. * encoding: unused\
  223. * decoding: set by lavc\
  224. */\
  225. uint8_t *mbskip_table;\
  226. \
  227. /**\
  228. * for some private data of the user\
  229. * encoding: unused\
  230. * decoding: set by user\
  231. */\
  232. void *opaque;\
  233. /* FIXME: these should have FF_ */
  234. #define I_TYPE 1 // Intra
  235. #define P_TYPE 2 // Predicted
  236. #define B_TYPE 3 // Bi-dir predicted
  237. #define S_TYPE 4 // S(GMC)-VOP MPEG4
  238. typedef struct AVVideoFrame {
  239. FF_COMMON_PICTURE
  240. } AVVideoFrame;
  241. typedef struct AVCodecContext {
  242. /**
  243. * the average bitrate
  244. * encoding: set by user. unused for constant quantizer encoding
  245. * decoding: set by lavc. 0 or some bitrate if this info is available in the stream
  246. */
  247. int bit_rate;
  248. /**
  249. * number of bits the bitstream is allowed to diverge from the reference
  250. * the reference can be CBR (for CBR pass1) or VBR (for pass2)
  251. * encoding: set by user. unused for constant quantizer encoding
  252. * decoding: unused
  253. */
  254. int bit_rate_tolerance;
  255. /**
  256. * CODEC_FLAG_*
  257. * encoding: set by user.
  258. * decoding: set by user.
  259. */
  260. int flags;
  261. /**
  262. * some codecs needs additionnal format info. It is stored here
  263. * encoding: set by user.
  264. * decoding: set by lavc. (FIXME is this ok?)
  265. */
  266. int sub_id;
  267. /**
  268. * motion estimation algorithm used for video coding
  269. * encoding: MUST be set by user.
  270. * decoding: unused
  271. */
  272. int me_method;
  273. /**
  274. * some codecs need / can use extra-data like huffman tables
  275. * mjpeg: huffman tables
  276. * rv10: additional flags
  277. * mpeg4: global headers (they can be in the bitstream or here)
  278. * encoding: set/allocated/freed by lavc.
  279. * decoding: set/allocated/freed by user.
  280. */
  281. void *extradata;
  282. int extradata_size;
  283. /* video only */
  284. /**
  285. * frames per sec multiplied by FRAME_RATE_BASE
  286. * for variable fps this is the precission, so if the timestamps
  287. * can be specified in msec precssion then this is 1000*FRAME_RATE_BASE
  288. * encoding: MUST be set by user
  289. * decoding: set by lavc. 0 or the frame_rate if available
  290. */
  291. int frame_rate;
  292. /**
  293. * encoding: MUST be set by user.
  294. * decoding: set by user, some codecs might override / change it during playback
  295. */
  296. int width, height;
  297. #define FF_ASPECT_SQUARE 1
  298. #define FF_ASPECT_4_3_625 2
  299. #define FF_ASPECT_4_3_525 3
  300. #define FF_ASPECT_16_9_625 4
  301. #define FF_ASPECT_16_9_525 5
  302. #define FF_ASPECT_EXTENDED 15
  303. /**
  304. * the number of pictures in a group of pitures, or 0 for intra_only
  305. * encoding: set by user.
  306. * decoding: unused
  307. */
  308. int gop_size;
  309. /**
  310. * pixel format, see PIX_FMT_xxx
  311. * encoding: unused
  312. * decoding: set by lavc.
  313. */
  314. enum PixelFormat pix_fmt;
  315. int repeat_pict; /* when decoding, this signal how much the picture */
  316. /* must be delayed. */
  317. /* extra_delay = (repeat_pict / 2) * (1/fps) */
  318. /**
  319. * if non NULL, 'draw_horiz_band' is called by the libavcodec
  320. * decoder to draw an horizontal band. It improve cache usage. Not
  321. * all codecs can do that. You must check the codec capabilities
  322. * before
  323. * encoding: unused
  324. * decoding: set by user.
  325. */
  326. void (*draw_horiz_band)(struct AVCodecContext *s,
  327. UINT8 **src_ptr, int linesize,
  328. int y, int width, int height);
  329. /* audio only */
  330. int sample_rate; /* samples per sec */
  331. int channels;
  332. int sample_fmt; /* sample format, currenly unused */
  333. /* the following data should not be initialized */
  334. int frame_size; /* in samples, initialized when calling 'init' */
  335. int frame_number; /* audio or video frame number */
  336. int real_pict_num; /* returns the real picture number of
  337. previous encoded frame */
  338. /**
  339. * 1 -> keyframe, 0-> not (this if for audio only, for video, AVVideoFrame.key_frame should be used)
  340. * encoding: set by lavc (for the outputed bitstream, not the input frame)
  341. * decoding: set by lavc (for the decoded bitstream, not the displayed frame)
  342. */
  343. int key_frame;
  344. /**
  345. * number of frames the decoded output will be delayed relative to
  346. * the encoded input
  347. * encoding: set by lavc.
  348. * decoding: unused
  349. */
  350. int delay;
  351. /* encoding parameters */
  352. float qcompress; /* amount of qscale change between easy & hard scenes (0.0-1.0)*/
  353. float qblur; /* amount of qscale smoothing over time (0.0-1.0) */
  354. /**
  355. * minimum quantizer
  356. * encoding: set by user.
  357. * decoding: unused
  358. */
  359. int qmin;
  360. /**
  361. * maximum quantizer
  362. * encoding: set by user.
  363. * decoding: unused
  364. */
  365. int qmax;
  366. /**
  367. * maximum quantizer difference etween frames
  368. * encoding: set by user.
  369. * decoding: unused
  370. */
  371. int max_qdiff;
  372. /**
  373. * maximum number of b frames between non b frames
  374. * note: the output will be delayed by max_b_frames+1 relative to the input
  375. * encoding: set by user.
  376. * decoding: unused
  377. */
  378. int max_b_frames;
  379. /**
  380. * qscale factor between ip and b frames
  381. * encoding: set by user.
  382. * decoding: unused
  383. */
  384. float b_quant_factor;
  385. /** obsolete FIXME remove */
  386. int rc_strategy;
  387. int b_frame_strategy;
  388. /**
  389. * encoding: unused
  390. * decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
  391. */
  392. int hurry_up;
  393. struct AVCodec *codec;
  394. void *priv_data;
  395. /* The following data is for RTP friendly coding */
  396. /* By now only H.263/H.263+/MPEG4 coder honours this */
  397. int rtp_mode; /* 1 for activate RTP friendly-mode */
  398. /* highers numbers represent more error-prone */
  399. /* enviroments, by now just "1" exist */
  400. int rtp_payload_size; /* The size of the RTP payload, the coder will */
  401. /* do it's best to deliver a chunk with size */
  402. /* below rtp_payload_size, the chunk will start */
  403. /* with a start code on some codecs like H.263 */
  404. /* This doesn't take account of any particular */
  405. /* headers inside the transmited RTP payload */
  406. /* The RTP callcack: This function is called */
  407. /* every time the encoder as a packet to send */
  408. /* Depends on the encoder if the data starts */
  409. /* with a Start Code (it should) H.263 does */
  410. void (*rtp_callback)(void *data, int size, int packet_number);
  411. /**
  412. * if you set get_psnr to 1 then after encoding you will have the
  413. * PSNR on psnr_y/cb/cr
  414. * encoding: set by user (1-> on, 0-> off)
  415. * decoding: unused
  416. */
  417. int get_psnr;
  418. float psnr_y;
  419. float psnr_cb;
  420. float psnr_cr;
  421. /* statistics, used for 2-pass encoding */
  422. int mv_bits;
  423. int header_bits;
  424. int i_tex_bits;
  425. int p_tex_bits;
  426. int i_count;
  427. int p_count;
  428. int skip_count;
  429. int misc_bits;
  430. /**
  431. * number of bits used for the previously encoded frame
  432. * encoding: set by lavc
  433. * decoding: - for audio - bits_per_sample
  434. */
  435. int frame_bits;
  436. /**
  437. * private data of the user, can be used to carry app specific stuff
  438. * encoding: set by user
  439. * decoding: set by user
  440. */
  441. void *opaque;
  442. char codec_name[32];
  443. enum CodecType codec_type; /* see CODEC_TYPE_xxx */
  444. enum CodecID codec_id; /* see CODEC_ID_xxx */
  445. unsigned int codec_tag; /* codec tag, only used if unknown codec */
  446. /**
  447. * workaround bugs in encoders which sometimes cannot be detected automatically
  448. * encoding: unused
  449. * decoding: set by user
  450. */
  451. int workaround_bugs;
  452. #define FF_BUG_AUTODETECT 1 //autodetection
  453. #define FF_BUG_OLD_MSMPEG4 2
  454. #define FF_BUG_XVID_ILACE 4
  455. #define FF_BUG_UMP4 8
  456. #define FF_BUG_NO_PADDING 16
  457. #define FF_BUG_AC_VLC 32
  458. #define FF_BUG_QPEL_CHROMA 64
  459. //#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
  460. /**
  461. * encoding: set by user
  462. * decoding: unused
  463. */
  464. int luma_elim_threshold;
  465. /**
  466. * encoding: set by user
  467. * decoding: unused
  468. */
  469. int chroma_elim_threshold;
  470. /**
  471. * strictly follow the std (MPEG4, ...)
  472. * encoding: set by user
  473. * decoding: unused
  474. */
  475. int strict_std_compliance;
  476. /**
  477. * qscale offset between ip and b frames
  478. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  479. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  480. * encoding: set by user.
  481. * decoding: unused
  482. */
  483. float b_quant_offset;
  484. /**
  485. * error resilience higher values will detect more errors but may missdetect
  486. * some more or less valid parts as errors
  487. * encoding: unused
  488. * decoding: set by user
  489. */
  490. int error_resilience;
  491. #define FF_ER_CAREFULL 1
  492. #define FF_ER_COMPLIANT 2
  493. #define FF_ER_AGGRESSIVE 3
  494. #define FF_ER_VERY_AGGRESSIVE 4
  495. /**
  496. * called at the beginning of each frame to get a buffer for it.
  497. * if pic.reference is set then the frame will be read later by lavc
  498. * encoding: unused
  499. * decoding: set by lavc, user can override
  500. */
  501. int (*get_buffer)(struct AVCodecContext *c, AVVideoFrame *pic);
  502. /**
  503. * called to release buffers which where allocated with get_buffer.
  504. * a released buffer can be reused in get_buffer()
  505. * pic.data[*] must be set to NULL
  506. * encoding: unused
  507. * decoding: set by lavc, user can override
  508. */
  509. void (*release_buffer)(struct AVCodecContext *c, AVVideoFrame *pic);
  510. /**
  511. * is 1 if the decoded stream contains b frames, 0 otherwise
  512. * encoding: unused
  513. * decoding: set by lavc
  514. */
  515. int has_b_frames;
  516. int block_align; /* used by some WAV based audio codecs */
  517. int parse_only; /* decoding only: if true, only parsing is done
  518. (function avcodec_parse_frame()). The frame
  519. data is returned. Only MPEG codecs support this now. */
  520. /**
  521. * 0-> h263 quant 1-> mpeg quant
  522. * encoding: set by user.
  523. * decoding: unused
  524. */
  525. int mpeg_quant;
  526. /**
  527. * pass1 encoding statistics output buffer
  528. * encoding: set by lavc
  529. * decoding: unused
  530. */
  531. char *stats_out; /* encoding statistics output buffer */
  532. /**
  533. * pass2 encoding statistics input buffer.
  534. * concatenated stuff from stats_out of pass1 should be placed here
  535. * encoding: allocated/set/freed by user
  536. * decoding: unused
  537. */
  538. char *stats_in;
  539. /**
  540. * ratecontrol qmin qmax limiting method
  541. * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
  542. * encoding: set by user.
  543. * decoding: unused
  544. */
  545. float rc_qsquish;
  546. float rc_qmod_amp;
  547. int rc_qmod_freq;
  548. /**
  549. * ratecontrol override, see RcOverride
  550. * encoding: allocated/set/freed by user.
  551. * decoding: unused
  552. */
  553. RcOverride *rc_override;
  554. int rc_override_count;
  555. /**
  556. * rate control equation
  557. * encoding: set by user
  558. * decoding: unused
  559. */
  560. char *rc_eq;
  561. /**
  562. * maximum bitrate
  563. * encoding: set by user.
  564. * decoding: unused
  565. */
  566. int rc_max_rate;
  567. /**
  568. * minimum bitrate
  569. * encoding: set by user.
  570. * decoding: unused
  571. */
  572. int rc_min_rate;
  573. /**
  574. * decoder bitstream buffer size
  575. * encoding: set by user.
  576. * decoding: unused
  577. */
  578. int rc_buffer_size;
  579. float rc_buffer_aggressivity;
  580. /**
  581. * qscale factor between p and i frames
  582. * encoding: set by user.
  583. * decoding: unused
  584. */
  585. float i_quant_factor;
  586. /**
  587. * qscale offset between p and i frames
  588. * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
  589. * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
  590. * encoding: set by user.
  591. * decoding: unused
  592. */
  593. float i_quant_offset;
  594. /**
  595. * initial complexity for pass1 ratecontrol
  596. * encoding: set by user.
  597. * decoding: unused
  598. */
  599. float rc_initial_cplx;
  600. /**
  601. * dct algorithm, see FF_DCT_* below
  602. * encoding: set by user
  603. * decoding: unused
  604. */
  605. int dct_algo;
  606. #define FF_DCT_AUTO 0
  607. #define FF_DCT_FASTINT 1
  608. #define FF_DCT_INT 2
  609. #define FF_DCT_MMX 3
  610. #define FF_DCT_MLIB 4
  611. #define FF_DCT_ALTIVEC 5
  612. /**
  613. * luminance masking (0-> disabled)
  614. * encoding: set by user
  615. * decoding: unused
  616. */
  617. float lumi_masking;
  618. /**
  619. * temporary complexity masking (0-> disabled)
  620. * encoding: set by user
  621. * decoding: unused
  622. */
  623. float temporal_cplx_masking;
  624. /**
  625. * spatial complexity masking (0-> disabled)
  626. * encoding: set by user
  627. * decoding: unused
  628. */
  629. float spatial_cplx_masking;
  630. /**
  631. * p block masking (0-> disabled)
  632. * encoding: set by user
  633. * decoding: unused
  634. */
  635. float p_masking;
  636. /**
  637. * darkness masking (0-> disabled)
  638. * encoding: set by user
  639. * decoding: unused
  640. */
  641. float dark_masking;
  642. /**
  643. * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A')
  644. * this is used to workaround some encoder bugs
  645. * encoding: unused
  646. * decoding: set by user, will be converted to upper case by lavc during init
  647. */
  648. int fourcc;
  649. /**
  650. * idct algorithm, see FF_IDCT_* below
  651. * encoding: set by user
  652. * decoding: set by user
  653. */
  654. int idct_algo;
  655. #define FF_IDCT_AUTO 0
  656. #define FF_IDCT_INT 1
  657. #define FF_IDCT_SIMPLE 2
  658. #define FF_IDCT_SIMPLEMMX 3
  659. #define FF_IDCT_LIBMPEG2MMX 4
  660. #define FF_IDCT_PS2 5
  661. #define FF_IDCT_MLIB 6
  662. #define FF_IDCT_ARM 7
  663. #define FF_IDCT_ALTIVEC 8
  664. /**
  665. * slice count
  666. * encoding: set by lavc
  667. * decoding: set by user (or 0)
  668. */
  669. int slice_count;
  670. /**
  671. * slice offsets in the frame in bytes
  672. * encoding: set/allocated by lavc
  673. * decoding: set/allocated by user (or NULL)
  674. */
  675. int *slice_offset;
  676. /**
  677. * error concealment flags
  678. * encoding: unused
  679. * decoding: set by user
  680. */
  681. int error_concealment;
  682. #define FF_EC_GUESS_MVS 1
  683. #define FF_EC_DEBLOCK 2
  684. /**
  685. * dsp_mask could be used to disable unwanted
  686. * CPU features (i.e. MMX, SSE. ...)
  687. */
  688. unsigned dsp_mask;
  689. /**
  690. * bits per sample/pixel from the demuxer (needed for huffyuv)
  691. * encoding: set by lavc
  692. * decoding: set by user
  693. */
  694. int bits_per_sample;
  695. /**
  696. * prediction method (needed for huffyuv)
  697. * encoding: set by user
  698. * decoding: unused
  699. */
  700. int prediction_method;
  701. #define FF_PRED_LEFT 0
  702. #define FF_PRED_PLANE 1
  703. #define FF_PRED_MEDIAN 2
  704. /**
  705. * aspect ratio. (0 if unknown)
  706. * encoding: set by user.
  707. * decoding: set by lavc.
  708. */
  709. float aspect_ratio;
  710. /**
  711. * the picture in the bitstream
  712. * encoding: set by lavc
  713. * decoding: set by lavc
  714. */
  715. AVVideoFrame *coded_picture;
  716. /**
  717. * debug
  718. * encoding: set by user.
  719. * decoding: set by user.
  720. */
  721. int debug;
  722. #define FF_DEBUG_PICT_INFO 1
  723. #define FF_DEBUG_RC 2
  724. #define FF_DEBUG_BITSTREAM 4
  725. #define FF_DEBUG_MB_TYPE 8
  726. #define FF_DEBUG_QP 16
  727. #define FF_DEBUG_MV 32
  728. #define FF_DEBUG_VIS_MV 64
  729. } AVCodecContext;
  730. typedef struct AVCodec {
  731. const char *name;
  732. int type;
  733. int id;
  734. int priv_data_size;
  735. int (*init)(AVCodecContext *);
  736. int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data);
  737. int (*close)(AVCodecContext *);
  738. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
  739. UINT8 *buf, int buf_size);
  740. int capabilities;
  741. struct AVCodec *next;
  742. } AVCodec;
  743. /**
  744. * four components are given, that's all.
  745. * the last component is alpha
  746. */
  747. typedef struct AVPicture {
  748. UINT8 *data[4];
  749. int linesize[4];
  750. } AVPicture;
  751. extern AVCodec ac3_encoder;
  752. extern AVCodec mp2_encoder;
  753. extern AVCodec mp3lame_encoder;
  754. extern AVCodec oggvorbis_encoder;
  755. extern AVCodec mpeg1video_encoder;
  756. extern AVCodec h263_encoder;
  757. extern AVCodec h263p_encoder;
  758. extern AVCodec rv10_encoder;
  759. extern AVCodec mjpeg_encoder;
  760. extern AVCodec mpeg4_encoder;
  761. extern AVCodec msmpeg4v1_encoder;
  762. extern AVCodec msmpeg4v2_encoder;
  763. extern AVCodec msmpeg4v3_encoder;
  764. extern AVCodec wmv1_encoder;
  765. extern AVCodec wmv2_encoder;
  766. extern AVCodec huffyuv_encoder;
  767. extern AVCodec h263_decoder;
  768. extern AVCodec mpeg4_decoder;
  769. extern AVCodec msmpeg4v1_decoder;
  770. extern AVCodec msmpeg4v2_decoder;
  771. extern AVCodec msmpeg4v3_decoder;
  772. extern AVCodec wmv1_decoder;
  773. extern AVCodec wmv2_decoder;
  774. extern AVCodec mpeg_decoder;
  775. extern AVCodec h263i_decoder;
  776. extern AVCodec rv10_decoder;
  777. extern AVCodec svq1_decoder;
  778. extern AVCodec dvvideo_decoder;
  779. extern AVCodec dvaudio_decoder;
  780. extern AVCodec wmav1_decoder;
  781. extern AVCodec wmav2_decoder;
  782. extern AVCodec mjpeg_decoder;
  783. extern AVCodec mjpegb_decoder;
  784. extern AVCodec mp2_decoder;
  785. extern AVCodec mp3_decoder;
  786. extern AVCodec mace3_decoder;
  787. extern AVCodec mace6_decoder;
  788. extern AVCodec huffyuv_decoder;
  789. extern AVCodec oggvorbis_decoder;
  790. /* pcm codecs */
  791. #define PCM_CODEC(id, name) \
  792. extern AVCodec name ## _decoder; \
  793. extern AVCodec name ## _encoder
  794. PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
  795. PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
  796. PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
  797. PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
  798. PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
  799. PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
  800. PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
  801. PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
  802. /* adpcm codecs */
  803. PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
  804. PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
  805. PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
  806. #undef PCM_CODEC
  807. /* dummy raw video codec */
  808. extern AVCodec rawvideo_codec;
  809. /* the following codecs use external GPL libs */
  810. extern AVCodec ac3_decoder;
  811. /* resample.c */
  812. struct ReSampleContext;
  813. typedef struct ReSampleContext ReSampleContext;
  814. ReSampleContext *audio_resample_init(int output_channels, int input_channels,
  815. int output_rate, int input_rate);
  816. int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
  817. void audio_resample_close(ReSampleContext *s);
  818. /* YUV420 format is assumed ! */
  819. struct ImgReSampleContext;
  820. typedef struct ImgReSampleContext ImgReSampleContext;
  821. ImgReSampleContext *img_resample_init(int output_width, int output_height,
  822. int input_width, int input_height);
  823. ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
  824. int iwidth, int iheight,
  825. int topBand, int bottomBand,
  826. int leftBand, int rightBand);
  827. void img_resample(ImgReSampleContext *s,
  828. AVPicture *output, AVPicture *input);
  829. void img_resample_close(ImgReSampleContext *s);
  830. void avpicture_fill(AVPicture *picture, UINT8 *ptr,
  831. int pix_fmt, int width, int height);
  832. int avpicture_get_size(int pix_fmt, int width, int height);
  833. void avcodec_get_chroma_sub_sample(int fmt, int *h_shift, int *v_shift);
  834. /* convert among pixel formats */
  835. int img_convert(AVPicture *dst, int dst_pix_fmt,
  836. AVPicture *src, int pix_fmt,
  837. int width, int height);
  838. /* deinterlace a picture */
  839. int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
  840. int pix_fmt, int width, int height);
  841. /* external high level API */
  842. extern AVCodec *first_avcodec;
  843. /* returns LIBAVCODEC_VERSION_INT constant */
  844. unsigned avcodec_version(void);
  845. /* returns LIBAVCODEC_BUILD constant */
  846. unsigned avcodec_build(void);
  847. void avcodec_init(void);
  848. void avcodec_set_bit_exact(void);
  849. void register_avcodec(AVCodec *format);
  850. AVCodec *avcodec_find_encoder(enum CodecID id);
  851. AVCodec *avcodec_find_encoder_by_name(const char *name);
  852. AVCodec *avcodec_find_decoder(enum CodecID id);
  853. AVCodec *avcodec_find_decoder_by_name(const char *name);
  854. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
  855. void avcodec_get_context_defaults(AVCodecContext *s);
  856. AVCodecContext *avcodec_alloc_context(void);
  857. AVVideoFrame *avcodec_alloc_picture(void);
  858. int avcodec_default_get_buffer(AVCodecContext *s, AVVideoFrame *pic);
  859. void avcodec_default_release_buffer(AVCodecContext *s, AVVideoFrame *pic);
  860. int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
  861. int avcodec_decode_audio(AVCodecContext *avctx, INT16 *samples,
  862. int *frame_size_ptr,
  863. UINT8 *buf, int buf_size);
  864. int avcodec_decode_video(AVCodecContext *avctx, AVVideoFrame *picture,
  865. int *got_picture_ptr,
  866. UINT8 *buf, int buf_size);
  867. int avcodec_parse_frame(AVCodecContext *avctx, UINT8 **pdata,
  868. int *data_size_ptr,
  869. UINT8 *buf, int buf_size);
  870. int avcodec_encode_audio(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  871. const short *samples);
  872. int avcodec_encode_video(AVCodecContext *avctx, UINT8 *buf, int buf_size,
  873. const AVVideoFrame *pict);
  874. int avcodec_close(AVCodecContext *avctx);
  875. void avcodec_register_all(void);
  876. void avcodec_flush_buffers(AVCodecContext *avctx);
  877. /**
  878. * Interface for 0.5.0 version
  879. *
  880. * do not even think about it's usage for this moment
  881. */
  882. typedef struct {
  883. // compressed size used from given memory buffer
  884. int size;
  885. /// I/P/B frame type
  886. int frame_type;
  887. } avc_enc_result_t;
  888. /**
  889. * Commands
  890. * order can't be changed - once it was defined
  891. */
  892. typedef enum {
  893. // general commands
  894. AVC_OPEN_BY_NAME = 0xACA000,
  895. AVC_OPEN_BY_CODEC_ID,
  896. AVC_OPEN_BY_FOURCC,
  897. AVC_CLOSE,
  898. AVC_FLUSH,
  899. // pin - struct { uint8_t* src, uint_t src_size }
  900. // pout - struct { AVPicture* img, consumed_bytes,
  901. AVC_DECODE,
  902. // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
  903. // pout - uint_t used_from_dest_size
  904. AVC_ENCODE,
  905. // query/get video commands
  906. AVC_GET_VERSION = 0xACB000,
  907. AVC_GET_WIDTH,
  908. AVC_GET_HEIGHT,
  909. AVC_GET_DELAY,
  910. AVC_GET_QUANT_TABLE,
  911. // ...
  912. // query/get audio commands
  913. AVC_GET_FRAME_SIZE = 0xABC000,
  914. // maybe define some simple structure which
  915. // might be passed to the user - but they can't
  916. // contain any codec specific parts and these
  917. // calls are usualy necessary only few times
  918. // set video commands
  919. AVC_SET_WIDTH = 0xACD000,
  920. AVC_SET_HEIGHT,
  921. // set video encoding commands
  922. AVC_SET_FRAME_RATE = 0xACD800,
  923. AVC_SET_QUALITY,
  924. AVC_SET_HURRY_UP,
  925. // set audio commands
  926. AVC_SET_SAMPLE_RATE = 0xACE000,
  927. AVC_SET_CHANNELS,
  928. } avc_cmd_t;
  929. /**
  930. * \param handle allocated private structure by libavcodec
  931. * for initialization pass NULL - will be returned pout
  932. * user is supposed to know nothing about its structure
  933. * \param cmd type of operation to be performed
  934. * \param pint input parameter
  935. * \param pout output parameter
  936. *
  937. * \returns command status - eventually for query command it might return
  938. * integer resulting value
  939. */
  940. int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
  941. /* memory */
  942. void *av_malloc(unsigned int size);
  943. void *av_mallocz(unsigned int size);
  944. void av_free(void *ptr);
  945. void __av_freep(void **ptr);
  946. #define av_freep(p) __av_freep((void **)(p))
  947. /* for static data only */
  948. /* call av_free_static to release all staticaly allocated tables */
  949. void av_free_static();
  950. void *__av_mallocz_static(void** location, unsigned int size);
  951. #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
  952. #endif /* AVCODEC_H */