Leaked source code of windows server 2003
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.

532 lines
15 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: $
  7. * $EndLog$
  8. */
  9. /*****************************************************************************
  10. ** Copyright (c) Digital Equipment Corporation, 1996 **
  11. ** **
  12. ** All Rights Reserved. Unpublished rights reserved under the copyright **
  13. ** laws of the United States. **
  14. ** **
  15. ** The software contained on this media is proprietary to and embodies **
  16. ** the confidential technology of Digital Equipment Corporation. **
  17. ** Possession, use, duplication or dissemination of the software and **
  18. ** media is authorized only pursuant to a valid written license from **
  19. ** Digital Equipment Corporation. **
  20. ** **
  21. ** RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. **
  22. ** Government is subject to restrictions as set forth in Subparagraph **
  23. ** (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. **
  24. ******************************************************************************/
  25. /****************************************************************************
  26. *
  27. * sv_h263.h
  28. * Wei-Lien Hsu
  29. * Date: December 11, 1996
  30. *
  31. ****************************************************************************/
  32. #ifndef _SV_H263_
  33. #define _SV_H263_
  34. #include "SC.h"
  35. #include "h263.h"
  36. /* Scaled IDCT precision */
  37. #define H263_SCALED_IDCT_BITS 20
  38. #define H263_SCALED_IDCT_MULT (1<<H263_SCALED_IDCT_BITS)
  39. /* Some macros */
  40. #define sign(a) ((a) < 0 ? -1 : 1)
  41. #define mnint(a) ((a) < 0 ? (int)(a - 0.5) : (int)(a + 0.5))
  42. #define mshort(a) ((a) < 0.0 ? (short)(a - 0.5) : (short)(a + 0.5))
  43. #define mmax(a, b) ((a) > (b) ? (a) : (b))
  44. #define mmin(a, b) ((a) < (b) ? (a) : (b))
  45. #ifndef INT_MAX
  46. #define INT_MIN (-2147483647 - 1) /* minimum (signed) int value */
  47. #define INT_MAX 2147483647 /* maximum (signed) int value */
  48. #endif
  49. #ifdef WIN32
  50. #ifndef floorf
  51. #define floorf floor
  52. #endif
  53. #endif
  54. #define H263_mfloor(a) ((a) < 0 ? (int)(a - 0.5) : (int)(a))
  55. #define H263_limit(x) \
  56. { \
  57. if (x > 255) x = 255; \
  58. if (x < 0) x = 0; \
  59. }
  60. #define H263_S_CODE
  61. #define H263_NO_VEC 999
  62. #define H263_DEF_OUTPUTNAME "DECOUT"
  63. #define H263_T_YUV 0
  64. #define H263_T_SIF 1
  65. #define H263_T_TGA 2
  66. #define H263_T_PPM 3
  67. #define H263_T_X11 4
  68. #define H263_T_YUV_CONC 5
  69. #define H263_T_WIN 6
  70. /* MBC = DEF_PELS/MB_SIZE, MBR = DEF_LINES/MB_SIZE$*/
  71. /* this is necessary for the max resolution 16CIF */
  72. #define H263_MBC 88
  73. #define H263_MBR 72
  74. #define H263_YES 1
  75. #define H263_NO 0
  76. #define H263_ON 1
  77. #define H263_OFF 0
  78. /************************** H263 Decoder ********************************/
  79. /*
  80. ** Structures used to pass around the H263 decompression information.
  81. ** Part of SvCodecInfo_t structure.
  82. */
  83. typedef struct SvH263DecompressInfo_s {
  84. ScBoolean_t inited; /* was this info initialized yet */
  85. int quality;
  86. /* output */
  87. char *outputname;
  88. int outtype;
  89. /* printf's */
  90. int quiet;
  91. int trace;
  92. char errortext[256];
  93. unsigned int frame_rate;
  94. unsigned int bit_rate; /* encode bitrate */
  95. unsigned char *refframe[3], *oldrefframe[3];
  96. unsigned char *bframe[3], *newframe[3];
  97. unsigned char *edgeframe[3], *edgeframeorig[3];
  98. unsigned char *exnewframe[3];
  99. int MV[2][5][H263_MBR+1][H263_MBC+2];
  100. int modemap[H263_MBR+1][H263_MBC+2];
  101. unsigned char *clp;
  102. int horizontal_size, vertical_size;
  103. int mb_width, mb_height;
  104. int coded_picture_width, coded_picture_height;
  105. int chrom_width, chrom_height, blk_cnt;
  106. int pict_type, newgob;
  107. int mv_outside_frame, syntax_arith_coding;
  108. int adv_pred_mode, pb_frame;
  109. int long_vectors;
  110. int fault, expand;
  111. int verbose;
  112. int refidct;
  113. int matrix_coefficients;
  114. int temp_ref, quant, source_format;
  115. int framenum;
  116. int trd, trb, bscan, bquant;
  117. #if 0
  118. /* bit input */
  119. int infile;
  120. unsigned char rdbfr[2051];
  121. unsigned char *rdptr;
  122. unsigned qword inbfr;
  123. unsigned qword position;
  124. int incnt;
  125. int bitcnt;
  126. #endif
  127. /* block data [12] */
  128. int (*block)[66];
  129. void *dbg; /* debug handle */
  130. } SvH263DecompressInfo_t;
  131. /************************************* H263 Encoder *************************************/
  132. /* If you are not using the included Makefile, or want to override
  133. the Makefile, you can uncomment one or more of the defines
  134. below instead */
  135. /* #define PRINTMV */
  136. /* to print MVs to stdout while coding. */
  137. /* #define PRINTQ */
  138. /* to print the quantizer used during coding */
  139. /* #define FASTIDCT */
  140. /* for a fast single precision IDCT. */
  141. /* #define OFFLINE_RATE_CONTROL */
  142. /* for the rate control optimized for offline encoding. */
  143. /* #define QCIF */
  144. /* to change the coding format uncommment the above line and change to
  145. SQCIF, QCIF, CIF, CIF4, or CIF16 */
  146. /* From config.h */
  147. /* for FAST search */
  148. #define H263_SRCH_RANGE 24
  149. /*************************************************************************/
  150. /* Default modes */
  151. /* see http://www.nta.no/brukere/DVC/h263_options.html */
  152. /* Added by Nuno on 06/27/96 to support prefiltering */
  153. /* use prefiltering as default */
  154. #define H263_DEF_PREFILT_MODE H263_NO
  155. /*************************************************************************/
  156. /* Search windows */
  157. /* default integer pel search seek distance ( also option "-s <n> " ) */
  158. #define H263_DEF_SEEK_DIST 15
  159. /* default integer search window for 8x8 search centered
  160. around 16x16 vector. When it is zero only half pel estimation
  161. around the integer 16x16 vector will be performed */
  162. /* for best performance, keep this small, preferably zero,
  163. but do your own simulations if you want to try something else */
  164. #define H263_DEF_8X8_WIN 0
  165. /* default search window for PB delta vectors */
  166. /* keep this small also */
  167. #define H263_DEF_PBDELTA_WIN 2
  168. /*************************************************************************/
  169. /* Miscellaneous */
  170. /* write repeated reconstructed frames to disk (useful for variable
  171. * framerate, since sequence will be saved at 25 Hz)
  172. * Can be changed at run-time with option "-m" */
  173. #define H263_DEF_WRITE_REPEATED H263_NO
  174. /* write bitstream trace to files trace.intra / trace
  175. * (also option "-t") */
  176. #define H263_DEF_WRITE_TRACE H263_NO
  177. /* start rate control after DEF_START_RATE_CONTROL % of sequence
  178. * has been encoded. Can be changed at run-time with option "-R <n>" */
  179. #define H263_DEF_START_RATE_CONTROL 0
  180. /* headerlength on concatenated 4:1:1 YUV input file
  181. * Can be changed at run-time with option -e <headerlength> */
  182. #define H263_DEF_HEADERLENGTH 0
  183. /* insert sync after each DEF_INSERT_SYNC for increased error robustness
  184. * 0 means do not insert extra syncs */
  185. #define H263_DEF_INSERT_SYNC 0
  186. /*************************************************************************/
  187. /* ME methods */
  188. #define H263_FULL_SEARCH 0
  189. #define H263_TWO_LEVELS_7_1 1
  190. #define H263_TWO_LEVELS_421_1 2
  191. #define H263_TWO_LEVELS_7_polint 3
  192. #define H263_TWO_LEVELS_7_pihp 4
  193. #define H263_FINDHALFPEL 0
  194. #define H263_POLINT 1
  195. #define H263_IDLE 2
  196. #define H263_DCT8BY8 0
  197. #define H263_DCT16COEFF 1
  198. #define H263_DCT4BY4 2
  199. /* prefiltering */
  200. #define H263_GAUSS 1
  201. #define H263_MORPH 2
  202. /* morph.c */
  203. #define H263_DEF_HPME_METHOD H263_FINDHALFPEL
  204. #define H263_DEF_DCT_METHOD H263_DCT8BY8
  205. #define H263_DEF_VSNR 0 /* FALSE */
  206. #define H263_DEF_SOURCE_FORMAT H263_SF_QCIF
  207. /* Added by Nuno to support prefiltering */
  208. #define H263_DEF_PYR_DEPTH 3
  209. #define H263_DEF_PREF_PYR_TYPE H263_GAUSS
  210. #define H263_MAX_PYR_DEPTH 5
  211. #define H263_DEF_STAT_PREF_STATE H263_NO
  212. /* This should not be changed */
  213. #define H263_MB_SIZE 16
  214. /* Parameters from TMN */
  215. #define H263_PREF_NULL_VEC 100
  216. #define H263_PREF_16_VEC 200
  217. #define H263_PREF_PBDELTA_NULL_VEC 50
  218. #define H263_MAX_CALC_QUALITY 0xFFFFFFFF
  219. #define H263_MIN_CALC_QUALITY 0x00000000
  220. /****************************/
  221. /* Motionvector structure */
  222. typedef struct H263_motionvector {
  223. short x; /* Horizontal comp. of mv */
  224. short y; /* Vertical comp. of mv */
  225. short x_half; /* Horizontal half-pel acc. */
  226. short y_half; /* Vertical half-pel acc. */
  227. short min_error; /* Min error for this vector */
  228. short Mode; /* Necessary for adv. pred. mode */
  229. } H263_MotionVector;
  230. /* Point structure */
  231. typedef struct H263_point {
  232. short x;
  233. short y;
  234. } H263_Point;
  235. /* Structure with image data */
  236. typedef struct H263_pict_image {
  237. unsigned char *lum; /* Luminance plane */
  238. unsigned char *Cr; /* Cr plane */
  239. unsigned char *Cb; /* Cb plane */
  240. } H263_PictImage;
  241. /* Added by Nuno on 06/24/96 to support filtering of the prediction error */
  242. typedef struct pred_image {
  243. short *lum; /* Luminance plane */
  244. short *Cr; /* Cr plane */
  245. short *Cb; /* Cb plane */
  246. } PredImage;
  247. /* Group of pictures structure. */
  248. /* Picture structure */
  249. typedef struct H263_pict {
  250. int prev;
  251. int curr;
  252. int TR; /* Time reference */
  253. int bit_rate;
  254. int src_frame_rate;
  255. float target_frame_rate;
  256. int source_format;
  257. int picture_coding_type;
  258. int spare;
  259. int unrestricted_mv_mode;
  260. int PB;
  261. int QUANT;
  262. int DQUANT;
  263. int MB;
  264. int seek_dist; /* Motion vector search window */
  265. int use_gobsync; /* flag for gob_sync */
  266. int MODB; /* B-frame mode */
  267. int BQUANT; /* which quantizer to use for B-MBs in PB-frame */
  268. int TRB; /* Time reference for B-picture */
  269. float QP_mean; /* mean quantizer */
  270. } H263_Pict;
  271. /* Slice structure */
  272. /*
  273. typedef struct H263_slice {
  274. unsigned int vert_pos;
  275. unsigned int quant_scale;
  276. } H263_Slice;
  277. */
  278. /* Macroblock structure */
  279. /*
  280. typedef struct H263_macroblock {
  281. int mb_address;
  282. int macroblock_type;
  283. int skipped;
  284. H263_MotionVector motion;
  285. } H263_Macroblock;
  286. */
  287. /* Structure for macroblock data */
  288. typedef struct mb_structure {
  289. short lum[16][16];
  290. short Cr[8][8];
  291. short Cb[8][8];
  292. } H263_MB_Structure;
  293. /* Added by Nuno on 06/24/96 to support filtering of the prediction error */
  294. typedef struct working_buffer {
  295. short *qcoeff_P; /* P frame coefficient */
  296. unsigned char *ipol_image; /* interpolated image */
  297. } H263_WORKING_BUFFER;
  298. /* Structure for counted bits */
  299. typedef struct H263_bits_counted {
  300. int Y;
  301. int C;
  302. int vec;
  303. int CBPY;
  304. int CBPCM;
  305. int MODB;
  306. int CBPB;
  307. int COD;
  308. int header;
  309. int DQUANT;
  310. int total;
  311. int no_inter;
  312. int no_inter4v;
  313. int no_intra;
  314. /* NB: Remember to change AddBits(), ZeroBits() and AddBitsPicture()
  315. when entries are added here */
  316. } H263_Bits;
  317. /* Structure for data for data from previous macroblock */
  318. /* Structure for average results and virtal buffer data */
  319. typedef struct H263_results {
  320. float SNR_l; /* SNR for luminance */
  321. float SNR_Cr; /* SNR for chrominance */
  322. float SNR_Cb;
  323. float QP_mean; /* Mean quantizer */
  324. } H263_Results;
  325. /**************** RTP *****************/
  326. #define RTP_H263_INTRA_CODED 0x00000001
  327. #define RTP_H263_PB_FRAME 0x00000002
  328. #define RTP_H263_AP 0x00000004
  329. #define RTP_H263_SAC 0x00000008
  330. #define H263_RTP_MODE_A PARAM_FORMATEXT_RTPA
  331. #define H263_RTP_MODE_B PARAM_FORMATEXT_RTPB
  332. #define H263_RTP_MODE_C PARAM_FORMATEXT_RTPC
  333. #define H263_RTP_DEFAULT_MODE RTP_H263_MODE_A
  334. #define H263_RTP_MAX_PACKETS 64*2
  335. typedef struct SvH263BSInfo_s {
  336. unsigned dword dwFlag;
  337. unsigned dword dwBitOffset;
  338. unsigned char Mode;
  339. unsigned char MBA;
  340. unsigned char Quant;
  341. unsigned char GOBN;
  342. char HMV1;
  343. char VMV1;
  344. char HMV2;
  345. char VMV2;
  346. } SvH263BSInfo_t;
  347. typedef struct SvH263BSTrailer_s {
  348. unsigned dword dwVersion;
  349. unsigned dword dwFlags;
  350. unsigned dword dwUniqueCode;
  351. unsigned dword dwCompressedSize;
  352. unsigned dword dwNumberOfPackets;
  353. unsigned char SourceFormat;
  354. unsigned char TR;
  355. unsigned char TRB;
  356. unsigned char DBQ;
  357. } SvH263BSTrailer_t;
  358. typedef struct SvH263RTPInfo_s {
  359. SvH263BSTrailer_t trailer;
  360. SvH263BSInfo_t bsinfo[H263_RTP_MAX_PACKETS];
  361. dword packet_id;
  362. ScBSPosition_t pic_start_position, packet_start_position;
  363. ScBSPosition_t pre_GOB_position, pre_MB_position;
  364. } SvH263RTPInfo_t;
  365. /*
  366. ** Structures used to pass around the H263 compression information.
  367. ** Part of SvCodecInfo_t structure.
  368. */
  369. typedef struct SvH263CompressInfo_s {
  370. ScBoolean_t inited; /* was this info initialized yet */
  371. /* options */
  372. int quality;
  373. unsigned dword calc_quality; /* calculated quality */
  374. int advanced;
  375. int syntax_arith_coding;
  376. int pb_frames;
  377. int unrestricted;
  378. int extbitstream; /* extended bitstream (rtp) */
  379. int packetsize; /* packet size (rtp) */
  380. /* for FAST search */
  381. unsigned char *block_subs2, *srch_area_subs2;
  382. /* Global variables */
  383. int headerlength;
  384. int source_format;
  385. int mb_width;
  386. int mb_height;
  387. int pels;
  388. int cpels;
  389. int lines;
  390. int trace;
  391. int mv_outside_frame;
  392. int long_vectors;
  393. float target_framerate;
  394. int prefilter; /* Added by Nuno on 06/24/96 to support prefiltering */
  395. H263_PictImage *prev_image;
  396. H263_PictImage *curr_image;
  397. H263_PictImage *curr_recon;
  398. H263_PictImage *prev_recon;
  399. /* To support filtering of the prediction error */
  400. H263_PictImage **curr_filtd;
  401. H263_PictImage *curr_clean;
  402. H263_PictImage *curr_selects;
  403. H263_PictImage *B_selects;
  404. /* PB-frame specific */
  405. H263_PictImage *B_recon;
  406. H263_PictImage *B_image;
  407. H263_PictImage **B_filtd;
  408. H263_PictImage *B_clean;
  409. H263_Pict *pic;
  410. H263_WORKING_BUFFER *wk_buffers;
  411. /* for Motion Estimation */
  412. H263_MotionVector *MV[6][H263_MBR+1][H263_MBC+2];
  413. unsigned char PREF_LEVEL[4][3], MOTresh[4];
  414. int PYR_DEPTH, PrefPyrType, H263_StaticPref, PETresh[3];
  415. H263_Bits *bits ;
  416. H263_Bits *total_bits;
  417. H263_Bits *intra_bits ;
  418. H263_Results *res;
  419. H263_Results *total_res;
  420. H263_Results *b_res ;
  421. /* bitrate control */
  422. int buffer_fullness;
  423. int buffer_frames_stored;
  424. int first_loop_finished, start_rate_control;
  425. unsigned char **PreFilterLevel;
  426. int bit_rate;
  427. int total_frames_passed, PPFlag;
  428. int first_frameskip, next_frameskip, chosen_frameskip;
  429. float orig_frameskip;
  430. int frames,bframes,pframes,pdist,bdist;
  431. int distance_to_next_frame;
  432. int QP, QP_init, QPI;
  433. float ref_frame_rate, orig_frame_rate;
  434. float frame_rate, seconds;
  435. int ME_method;
  436. int HPME_method;
  437. int refidct;
  438. int DCT_method;
  439. int vsnr;
  440. int start, end;
  441. int frame_no;
  442. SvH263RTPInfo_t *RTPInfo;
  443. int VARgob[16];
  444. char *seqfilename;
  445. char *streamname;
  446. void *dbg; /* debug handle */
  447. } SvH263CompressInfo_t;
  448. #endif _SV_H263_