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.

1119 lines
31KB

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