Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Copyright (c) 1995 The Regents of the University of California. |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Permission to use, copy, modify, and distribute this software and its |
||
6 | * documentation for any purpose, without fee, and without written agreement is |
||
7 | * hereby granted, provided that the above copyright notice and the following |
||
8 | * two paragraphs appear in all copies of this software. |
||
9 | * |
||
10 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR |
||
11 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
||
12 | * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |
||
13 | * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
14 | * |
||
15 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
||
16 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
||
17 | * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
||
18 | * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO |
||
19 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
||
20 | */ |
||
21 | |||
22 | /* |
||
23 | * Portions of this software Copyright (c) 1995 Brown University. |
||
24 | * All rights reserved. |
||
25 | * |
||
26 | * Permission to use, copy, modify, and distribute this software and its |
||
27 | * documentation for any purpose, without fee, and without written agreement |
||
28 | * is hereby granted, provided that the above copyright notice and the |
||
29 | * following two paragraphs appear in all copies of this software. |
||
30 | * |
||
31 | * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR |
||
32 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
||
33 | * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN |
||
34 | * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
35 | * |
||
36 | * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT |
||
37 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
||
38 | * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" |
||
39 | * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, |
||
40 | * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
||
41 | */ |
||
42 | |||
43 | #ifndef MPEG_LIB_VIDEO_HEADER |
||
44 | #define MPEG_LIB_VIDEO_HEADER |
||
45 | #include <stdio.h> |
||
46 | |||
47 | #ifdef USEX |
||
48 | #include <X11/Xlib.h> |
||
49 | #include <X11/Xutil.h> |
||
50 | |||
51 | #ifdef SH_MEM |
||
52 | #include <sys/ipc.h> |
||
53 | #include <sys/shm.h> |
||
54 | #include <X11/extensions/XShm.h> |
||
55 | #endif |
||
56 | #endif |
||
57 | |||
58 | /* |
||
59 | Changes to make the code reentrant: |
||
60 | deglobalized: ditherFlags, totNumFrames, realTimeStart, matched_depth, |
||
61 | filename, ditherType, curBits, ReconPMBlock statics, stream id |
||
62 | variables, Parse_done, swap, seekValue, input, EOF_flag, ReadPacket |
||
63 | statics, sys_layer, curVidStream, curVidStream, jmb_buf env (removed) |
||
64 | X globals now in xinfo: ditherType, visual, depth (also name), hints, |
||
65 | owncmFlag, et al |
||
66 | now const: scan |
||
67 | film_has_ended instead of FilmState |
||
68 | Additional changes: |
||
69 | if DISABLE_DITHER defined, don't compile dithering code |
||
70 | -lsh@cs.brown.edu (Loring Holden) |
||
71 | */ |
||
72 | |||
73 | /* X11/xmd.h correctly defines INT32, etc */ |
||
74 | #ifndef XMD_H |
||
75 | typedef int INT32; |
||
76 | typedef short INT16; |
||
77 | typedef char INT8; |
||
78 | #endif |
||
79 | typedef unsigned int UINT32; |
||
80 | typedef unsigned short UINT16; |
||
81 | typedef unsigned char UINT8; |
||
82 | |||
83 | /* Define Parsing error codes. */ |
||
84 | |||
85 | #define SKIP_PICTURE (-10) |
||
86 | #define SKIP_TO_START_CODE (-1) |
||
87 | #define PARSE_OK 1 |
||
88 | |||
89 | /* Define BOOLEAN, TRUE, and FALSE. */ |
||
90 | |||
91 | #define BOOLEAN int |
||
92 | #define TRUE 1 |
||
93 | #define FALSE 0 |
||
94 | |||
95 | /* Set ring buffer size. */ |
||
96 | |||
97 | #define RING_BUF_SIZE 5 |
||
98 | |||
99 | /* Macros for picture code type. */ |
||
100 | |||
101 | #define I_TYPE 1 |
||
102 | #define P_TYPE 2 |
||
103 | #define B_TYPE 3 |
||
104 | #define D_TYPE 4 |
||
105 | |||
106 | /* Start codes. */ |
||
107 | |||
108 | #define SEQ_END_CODE 0x000001b7 |
||
109 | #define SEQ_START_CODE 0x000001b3 |
||
110 | #define GOP_START_CODE 0x000001b8 |
||
111 | #define PICTURE_START_CODE 0x00000100 |
||
112 | #define SLICE_MIN_START_CODE 0x00000101 |
||
113 | #define SLICE_MAX_START_CODE 0x000001af |
||
114 | #define EXT_START_CODE 0x000001b5 |
||
115 | #define USER_START_CODE 0x000001b2 |
||
116 | #define SEQUENCE_ERROR_CODE 0x000001b4 |
||
117 | |||
118 | /* Number of macroblocks to process in one call to mpegVidRsrc. */ |
||
119 | |||
120 | #define MB_QUANTUM 100 |
||
121 | |||
122 | /* Macros used with macroblock address decoding. */ |
||
123 | |||
124 | #define MB_STUFFING 34 |
||
125 | #define MB_ESCAPE 35 |
||
126 | |||
127 | /* Lock flags for pict images. */ |
||
128 | |||
129 | #define DISPLAY_LOCK 0x01 |
||
130 | #define PAST_LOCK 0x02 |
||
131 | #define FUTURE_LOCK 0x04 |
||
132 | |||
133 | #define HYBRID_DITHER 0 |
||
134 | #define HYBRID2_DITHER 1 |
||
135 | #define FS4_DITHER 2 |
||
136 | #define FS2_DITHER 3 |
||
137 | #define FS2FAST_DITHER 4 |
||
138 | #define Twox2_DITHER 5 |
||
139 | #define GRAY_DITHER 6 |
||
140 | #define FULL_COLOR_DITHER 7 |
||
141 | #define NO_DITHER 8 |
||
142 | #define ORDERED_DITHER 9 |
||
143 | #define MONO_DITHER 10 |
||
144 | #define MONO_THRESHOLD 11 |
||
145 | #define ORDERED2_DITHER 12 |
||
146 | #define MBORDERED_DITHER 13 |
||
147 | #define GRAY256_DITHER 14 |
||
148 | #define PPM_DITHER 15 |
||
149 | #define FULL_COLOR2_DITHER 16 |
||
150 | #define GRAY2_DITHER 17 |
||
151 | #define GRAY2562_DITHER 18 |
||
152 | |||
153 | // MG |
||
154 | #define HALF_COLOR_DITHER 19 |
||
155 | |||
156 | #ifdef DISABLE_DITHER |
||
157 | #define IS_2x2_DITHER(a) (0) |
||
158 | #else |
||
159 | #define IS_2x2_DITHER(a) ((a) == Twox2_DITHER || (a) == FULL_COLOR2_DITHER || (a) == GRAY2_DITHER || (a) == (GRAY2562_DITHER)) |
||
160 | #endif |
||
161 | |||
162 | /* External declaration of row,col to zig zag conversion matrix. */ |
||
163 | |||
164 | /* Brown - changed to const int because it is a help variable */ |
||
165 | extern const int scan[][8]; |
||
166 | |||
167 | /* Temporary definition of time stamp structure. */ |
||
168 | |||
169 | typedef int TimeStamp; |
||
170 | |||
171 | /* Structure with reconstructed pixel values. */ |
||
172 | |||
173 | typedef struct pict_image { |
||
174 | unsigned char *luminance; /* Luminance plane. */ |
||
175 | unsigned char *Cr; /* Cr plane. */ |
||
176 | unsigned char *Cb; /* Cb plane. */ |
||
177 | unsigned char *display; /* Display plane. */ |
||
178 | int locked; /* Lock flag. */ |
||
179 | TimeStamp show_time; /* Presentation time. */ |
||
180 | |||
181 | #ifdef SH_MEM |
||
182 | XShmSegmentInfo shminfo; /* Segment info. */ |
||
183 | XImage *ximage; /* Ximage struct. */ |
||
184 | #endif |
||
185 | |||
186 | } PictImage; |
||
187 | |||
188 | /* Group of pictures structure. */ |
||
189 | |||
190 | typedef struct GoP { |
||
191 | BOOLEAN drop_flag; /* Flag indicating dropped frame. */ |
||
192 | unsigned int tc_hours; /* Hour component of time code. */ |
||
193 | unsigned int tc_minutes; /* Minute component of time code. */ |
||
194 | unsigned int tc_seconds; /* Second component of time code. */ |
||
195 | unsigned int tc_pictures; /* Picture counter of time code. */ |
||
196 | BOOLEAN closed_gop; /* Indicates no pred. vectors to |
||
197 | previous group of pictures. */ |
||
198 | BOOLEAN broken_link; /* B frame unable to be decoded. */ |
||
199 | char *ext_data; /* Extension data. */ |
||
200 | char *user_data; /* User data. */ |
||
201 | } GoP; |
||
202 | |||
203 | /* Picture structure. */ |
||
204 | |||
205 | typedef struct pict { |
||
206 | unsigned int temp_ref; /* Temporal reference. */ |
||
207 | unsigned int code_type; /* Frame type: P, B, I */ |
||
208 | unsigned int vbv_delay; /* Buffer delay. */ |
||
209 | BOOLEAN full_pel_forw_vector; /* Forw. vectors specified in full |
||
210 | pixel values flag. */ |
||
211 | unsigned int forw_r_size; /* Used for vector decoding. */ |
||
212 | unsigned int forw_f; /* Used for vector decoding. */ |
||
213 | BOOLEAN full_pel_back_vector; /* Back vectors specified in full |
||
214 | pixel values flag. */ |
||
215 | unsigned int back_r_size; /* Used in decoding. */ |
||
216 | unsigned int back_f; /* Used in decoding. */ |
||
217 | char *extra_info; /* Extra bit picture info. */ |
||
218 | char *ext_data; /* Extension data. */ |
||
219 | char *user_data; /* User data. */ |
||
220 | } Pict; |
||
221 | |||
222 | /* Slice structure. */ |
||
223 | |||
224 | typedef struct slice { |
||
225 | unsigned int vert_pos; /* Vertical position of slice. */ |
||
226 | unsigned int quant_scale; /* Quantization scale. */ |
||
227 | char *extra_info; /* Extra bit slice info. */ |
||
228 | } Slice; |
||
229 | |||
230 | /* Macroblock structure. */ |
||
231 | |||
232 | typedef struct macroblock { |
||
233 | int mb_address; /* Macroblock address. */ |
||
234 | int past_mb_addr; /* Previous mblock address. */ |
||
235 | int motion_h_forw_code; /* Forw. horiz. motion vector code. */ |
||
236 | unsigned int motion_h_forw_r; /* Used in decoding vectors. */ |
||
237 | int motion_v_forw_code; /* Forw. vert. motion vector code. */ |
||
238 | unsigned int motion_v_forw_r; /* Used in decdoinge vectors. */ |
||
239 | int motion_h_back_code; /* Back horiz. motion vector code. */ |
||
240 | unsigned int motion_h_back_r; /* Used in decoding vectors. */ |
||
241 | int motion_v_back_code; /* Back vert. motion vector code. */ |
||
242 | unsigned int motion_v_back_r; /* Used in decoding vectors. */ |
||
243 | unsigned int cbp; /* Coded block pattern. */ |
||
244 | BOOLEAN mb_intra; /* Intracoded mblock flag. */ |
||
245 | BOOLEAN bpict_past_forw; /* Past B frame forw. vector flag. */ |
||
246 | BOOLEAN bpict_past_back; /* Past B frame back vector flag. */ |
||
247 | int past_intra_addr; /* Addr of last intracoded mblock. */ |
||
248 | int recon_right_for_prev; /* Past right forw. vector. */ |
||
249 | int recon_down_for_prev; /* Past down forw. vector. */ |
||
250 | int recon_right_back_prev; /* Past right back vector. */ |
||
251 | int recon_down_back_prev; /* Past down back vector. */ |
||
252 | } Macroblock; |
||
253 | |||
254 | /* Block structure. */ |
||
255 | |||
256 | typedef struct block { |
||
257 | short int dct_recon[8][8]; /* Reconstructed dct coeff matrix. */ |
||
258 | short int dct_dc_y_past; /* Past lum. dc dct coefficient. */ |
||
259 | short int dct_dc_cr_past; /* Past cr dc dct coefficient. */ |
||
260 | short int dct_dc_cb_past; /* Past cb dc dct coefficient. */ |
||
261 | } Block; |
||
262 | |||
263 | /* Video stream structure. */ |
||
264 | |||
265 | typedef struct vid_stream { |
||
266 | unsigned int h_size; /* Horiz. size in pixels. */ |
||
267 | unsigned int v_size; /* Vert. size in pixels. */ |
||
268 | unsigned int mb_height; /* Vert. size in mblocks. */ |
||
269 | unsigned int mb_width; /* Horiz. size in mblocks. */ |
||
270 | unsigned char aspect_ratio; /* Code for aspect ratio. */ |
||
271 | unsigned char picture_rate; /* Code for picture rate. */ |
||
272 | unsigned int bit_rate; /* Bit rate. */ |
||
273 | unsigned int vbv_buffer_size; /* Minimum buffer size. */ |
||
274 | BOOLEAN const_param_flag; /* Contrained parameter flag. */ |
||
275 | unsigned char intra_quant_matrix[8][8]; /* Quantization matrix for |
||
276 | intracoded frames. */ |
||
277 | unsigned char non_intra_quant_matrix[8][8]; /* Quanitization matrix for |
||
278 | non intracoded frames. */ |
||
279 | char *ext_data; /* Extension data. */ |
||
280 | char *user_data; /* User data. */ |
||
281 | GoP group; /* Current group of pict. */ |
||
282 | Pict picture; /* Current picture. */ |
||
283 | Slice slice; /* Current slice. */ |
||
284 | Macroblock mblock; /* Current macroblock. */ |
||
285 | Block block; /* Current block. */ |
||
286 | int state; /* State of decoding. */ |
||
287 | int bit_offset; /* Bit offset in stream. */ |
||
288 | unsigned int *buffer; /* Pointer to next byte in |
||
289 | buffer. */ |
||
290 | int buf_length; /* Length of remaining buffer.*/ |
||
291 | unsigned int *buf_start; /* Pointer to buffer start. */ |
||
292 | /* Brown - beginning of added variables that used to be static or global */ |
||
293 | int max_buf_length; /* Max length of buffer. */ |
||
294 | int film_has_ended; /* Boolean - film has ended */ |
||
295 | int sys_layer; /* -1 uninitialized, |
||
296 | |||
297 | 1 syslayer */ |
||
298 | unsigned int num_left; /* from ReadPacket - leftover */ |
||
299 | unsigned int leftover_bytes; /* from ReadPacket - leftover */ |
||
300 | int EOF_flag; /* stream is EOF */ |
||
301 | FILE *input; /* stream comes from here */ |
||
302 | long seekValue; /* 0 no seeking |
||
303 | >0 do a seek, |
||
304 | <0 already has done seek */ |
||
305 | BOOLEAN swap; /* from ReadFile */ |
||
306 | BOOLEAN Parse_done; /* from read_sys */ |
||
307 | int gAudioStreamID; |
||
308 | int gVideoStreamID; |
||
309 | int gReservedStreamID; |
||
310 | int right_for,down_for; /* From ReconPMBlock, video.c */ |
||
311 | int right_half_for, down_half_for; |
||
312 | unsigned int curBits; /* current bits */ |
||
313 | int matched_depth; /* depth of displayed movie */ |
||
314 | char *filename; /* Name of stream filename */ |
||
315 | int ditherType; /* What type of dithering */ |
||
316 | char *ditherFlags; /* flags for MB Ordered dither*/ |
||
317 | int totNumFrames; /* Total Number of Frames */ |
||
318 | double realTimeStart; /* When did the movie start? */ |
||
319 | /* Brown - end of added variables */ |
||
320 | PictImage *past; /* Past predictive frame. */ |
||
321 | PictImage *future; /* Future predictive frame. */ |
||
322 | PictImage *current; /* Current frame. */ |
||
323 | PictImage *ring[RING_BUF_SIZE]; /* Ring buffer of frames. */ |
||
324 | /* x,y size of PPM output file */ |
||
325 | int ppm_width, ppm_height, ppm_modulus; |
||
326 | } VidStream; |
||
327 | |||
328 | typedef struct { |
||
329 | /* XImage *ximage;*/ |
||
330 | /* Colormap cmap;*/ |
||
331 | /* Window window;*/ |
||
332 | /* GC gc; |
||
333 | Display *display;*/ |
||
334 | int owncmFlag; |
||
335 | /* XSizeHints hints;*/ |
||
336 | /* Visual *visual;*/ |
||
337 | int depth; |
||
338 | char *name; |
||
339 | int ditherType; |
||
340 | /* Window ExistingWindow;*/ |
||
341 | } XInfo; |
||
342 | |||
343 | /* Declaration of global display pointer. */ |
||
344 | |||
345 | #if SH_MEM |
||
346 | /* Shared memory flag. */ |
||
347 | extern int shmemFlag; |
||
348 | #endif |
||
349 | |||
350 | /* Quiet mode flag. */ |
||
351 | extern int quietFlag; |
||
352 | |||
353 | /* Flag controlling the "Press return" prompt */ |
||
354 | extern int requireKeypressFlag; |
||
355 | |||
356 | /* Flag controlling speed vs. quality */ |
||
357 | extern int qualityFlag; |
||
358 | |||
359 | /* Gamma correction stuff */ |
||
360 | extern int gammaCorrectFlag; |
||
361 | extern double gammaCorrect; |
||
362 | |||
363 | /* Chroma correction stuff */ |
||
364 | extern int chromaCorrectFlag; |
||
365 | extern double chromaCorrect; |
||
366 | |||
367 | /* Definition of Contant integer scale factor. */ |
||
368 | |||
369 | #define CONST_BITS 13 |
||
370 | |||
371 | /* Misc DCT definitions */ |
||
372 | #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ |
||
373 | #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ |
||
374 | |||
375 | #define GLOBAL /* a function referenced thru EXTERNs */ |
||
376 | |||
377 | typedef short DCTELEM; |
||
378 | typedef DCTELEM DCTBLOCK[DCTSIZE2]; |
||
379 | |||
380 | |||
381 | #ifdef SH_MEM |
||
382 | extern int gXErrorFlag; |
||
383 | #endif |
||
384 | |||
385 | extern int loopFlag; |
||
386 | extern int noDisplayFlag; |
||
387 | extern int partialFlag, startFrame, endFrame; |
||
388 | |||
389 | #ifdef ANALYSIS |
||
390 | extern unsigned int bitCount; |
||
391 | extern int showEachFlag; |
||
392 | extern unsigned int cacheHit[8][8]; |
||
393 | extern unsigned int cacheMiss[8][8]; |
||
394 | #endif |
||
395 | |||
396 | #if !defined(__MIPSEL__) && (defined(MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__mipsel) || defined(__mipsel__)) |
||
397 | #define __MIPSEL__ 1 |
||
398 | #endif |
||
399 | |||
400 | #if !defined(__MIPSEB__) && (defined(MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || defined(__mipseb) || defined(__mipseb__)) |
||
401 | #define __MIPSEB__ 1 |
||
402 | #endif |
||
403 | |||
404 | #if !defined(__SPARC__) && (defined(SPARC) || defined(__SPARC) || defined(__SPARC__) || defined(__sparc) || defined(__sparc__)) |
||
405 | #define __SPARC__ 1 |
||
406 | #endif |
||
407 | |||
408 | #if !defined(__alpha__) && (defined(ALPHA) || defined(__ALPHA) || defined(__ALPHA__) || defined(__alpha)) |
||
409 | #define __alpha__ 1 |
||
410 | #endif |
||
411 | |||
412 | #if !defined(__680x0__) && (defined(__680x0) || defined(__680x0__)) |
||
413 | #define __680x0__ 1 |
||
414 | #endif |
||
415 | |||
416 | #if !defined(__AIX__) && (defined(AIX) || defined(_AIX) || defined(__AIX) || defined(__AIX__)) |
||
417 | #define __AIX__ 1 |
||
418 | #endif |
||
419 | |||
420 | #if !defined(__RS6000__) && (defined(__AIX__) || defined(RS6000) || defined(_RS6000) || defined(__RS6000) || defined(__RS6000__)) |
||
421 | #define __RS6000__ 1 |
||
422 | #endif |
||
423 | |||
424 | #if !defined(__HPUX__) && (defined(HPUX) || defined(_HPUX) || defined(__HPUX) || defined(__HPUX__)) |
||
425 | #define __HPUX__ 1 |
||
426 | #endif |
||
427 | #if !defined(__HPUX__) && (defined(hpux) || defined(_hpux) || defined(__hpux) || defined(__hpux__)) |
||
428 | #define __HPUX__ 1 |
||
429 | #endif |
||
430 | |||
431 | #if !defined(__VAX__) && (defined(VAX) || defined (__VAX)) |
||
432 | #define __VAX__ 1 |
||
433 | #endif |
||
434 | |||
435 | #if !defined(__SCO__) && (defined(SCO) || defined(__SCO) || defined(sco) || defined(__sco__)) |
||
436 | #define __SCO__ 1 |
||
437 | #endif |
||
438 | |||
439 | #if defined(__i386__) || defined(__VAX__) || defined(__MIPSEL__) || defined(__alpha__) || defined(__SCO__) |
||
440 | #undef BIG_ENDIAN_ARCHITECTURE |
||
441 | #define LITTLE_ENDIAN_ARCHITECTURE 1 |
||
442 | #endif |
||
443 | |||
444 | #if defined(__RS6000__) || defined(__SPARC__) || defined(__680x0__) || defined(__HPUX__) || defined(__MIPSEB__) || defined(convex) || defined(__convex__) |
||
445 | #undef LITTLE_ENDIAN_ARCHITECTURE |
||
446 | #define BIG_ENDIAN_ARCHITECTURE 1 |
||
447 | #endif |
||
448 | |||
449 | #if !defined(LITTLE_ENDIAN_ARCHITECTURE) && !defined(BIG_ENDIAN_ARCHITECTURE) |
||
450 | Error: Unknown endianism of architecture |
||
451 | #endif |
||
452 | |||
453 | #ifdef __alpha__ |
||
454 | #define SIXTYFOUR_BIT |
||
455 | #endif |
||
456 | #endif /* video.h already included */ |