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.

1194 lines
32KB

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