home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / VideoStreamV1.0 / Source / mpegDecodeSrc / video.h < prev   
Encoding:
C/C++ Source or Header  |  1995-06-12  |  10.0 KB  |  241 lines

  1. /*
  2.  * Copyright (c) 1992 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. #include <stdio.h>
  22. #include <setjmp.h>
  23.  
  24. /* Define Parsing error codes. */
  25.  
  26. #define SKIP_PICTURE -10
  27. #define SKIP_TO_START_CODE -1
  28. #define PARSE_OK 1
  29.  
  30. /* Define BOOLEAN, TRUE, and FALSE. */
  31.  
  32. #define BOOLEAN int
  33. #define TRUE 1
  34. #define FALSE 0
  35.  
  36. /* Set ring buffer size. */
  37.  
  38. #define RING_BUF_SIZE 5
  39.  
  40. /* Macros for picture code type. */
  41.  
  42. #define I_TYPE 1
  43. #define P_TYPE 2
  44. #define B_TYPE 3
  45.  
  46. /* Start codes. */
  47.  
  48. #define SEQ_END_CODE 0x000001b7
  49. #define SEQ_START_CODE 0x000001b3
  50. #define GOP_START_CODE 0x000001b8
  51. #define PICTURE_START_CODE 0x00000100
  52. #define SLICE_MIN_START_CODE 0x00000101
  53. #define SLICE_MAX_START_CODE 0x000001af
  54. #define EXT_START_CODE 0x000001b5
  55. #define USER_START_CODE 0x000001b2
  56.  
  57. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  58.  
  59. #define MB_QUANTUM 100
  60.  
  61. /* Macros used with macroblock address decoding. */
  62.  
  63. #define MB_STUFFING 34
  64. #define MB_ESCAPE 35
  65.  
  66. /* Lock flags for pict images. */
  67.  
  68. #define DISPLAY_LOCK 0x01
  69. #define PAST_LOCK 0x02
  70. #define FUTURE_LOCK 0x04
  71.  
  72. /* External declaration of row,col to zig zag conversion matrix. */
  73.  
  74. extern int scan[][8];
  75.  
  76. /* Temporary definition of time stamp structure. */
  77.  
  78. typedef int TimeStamp;
  79.  
  80. /* Structure with reconstructed pixel values. */
  81.  
  82. typedef struct pict_image {
  83.   unsigned char *luminance;              /* Luminance plane.   */
  84.   unsigned char *Cr;                     /* Cr plane.          */
  85.   unsigned char *Cb;                     /* Cb plane.          */
  86.   unsigned char *display;                /* Display plane.     */
  87.   int locked;                            /* Lock flag.         */
  88.   TimeStamp show_time;                   /* Presentation time. */
  89. } PictImage;
  90.  
  91. /* Group of pictures structure. */
  92.  
  93. typedef struct GoP {
  94.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  95.   unsigned int tc_hours;                 /* Hour component of time code.   */
  96.   unsigned int tc_minutes;               /* Minute component of time code. */
  97.   unsigned int tc_seconds;               /* Second component of time code. */
  98.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  99.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to previous group of pictures. */
  100.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  101.   char *ext_data;                        /* Extension data.                */
  102.   char *user_data;                       /* User data.                     */
  103. } GoP;
  104.  
  105. /* Picture structure. */
  106.  
  107. typedef struct pict {
  108.   unsigned int temp_ref;                 /* Temporal reference.             */
  109.   unsigned int code_type;                /* Frame type: P, B, I             */
  110.   unsigned int vbv_delay;                /* Buffer delay.                   */
  111.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full pixel values flag. */
  112.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  113.   unsigned int forw_f;                   /* Used for vector decoding.       */
  114.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full pixel values flag. */
  115.   unsigned int back_r_size;              /* Used in decoding.               */
  116.   unsigned int back_f;                   /* Used in decoding.               */
  117.   char *extra_info;                      /* Extra bit picture info.         */
  118.   char *ext_data;                        /* Extension data.                 */
  119.   char *user_data;                       /* User data.                      */
  120. } Pict;
  121.  
  122. /* Slice structure. */
  123.  
  124. typedef struct slice {
  125.   unsigned int vert_pos;                 /* Vertical position of slice. */
  126.   unsigned int quant_scale;              /* Quantization scale.         */
  127.   char *extra_info;                      /* Extra bit slice info.       */
  128. } Slice;
  129.  
  130. /* Macroblock structure. */
  131.  
  132. typedef struct macroblock {
  133.   int mb_address;                        /* Macroblock address.              */
  134.   int past_mb_addr;                      /* Previous mblock address.         */
  135.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  136.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  137.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  138.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  139.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  140.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  141.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  142.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  143.   unsigned int cbp;                      /* Coded block pattern.             */
  144.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  145.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  146.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  147.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  148.   int recon_right_for_prev;              /* Past right forw. vector.         */
  149.   int recon_down_for_prev;               /* Past down forw. vector.          */
  150.   int recon_right_back_prev;             /* Past right back vector.          */
  151.   int recon_down_back_prev;              /* Past down back vector.           */
  152. } Macroblock;
  153.  
  154. /* Block structure. */
  155.  
  156. typedef struct block {
  157.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  158.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  159.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  160.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  161. } Block;
  162.  
  163. /* Video stream structure. */
  164.  
  165. typedef struct vid_stream {
  166.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  167.   unsigned int v_size;                         /* Vert. size in pixels.      */
  168.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  169.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  170.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  171.   unsigned char picture_rate;                  /* Code for picture rate.     */
  172.   unsigned int bit_rate;                       /* Bit rate.                  */
  173.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  174.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  175.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for intracoded frames. */
  176.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for non intracoded frames. */
  177.   char *ext_data;                              /* Extension data.            */
  178.   char *user_data;                             /* User data.                 */
  179.   GoP group;                                   /* Current group of pict.     */
  180.   Pict picture;                                /* Current picture.           */
  181.   Slice slice;                                 /* Current slice.             */
  182.   Macroblock mblock;                           /* Current macroblock.        */
  183.   Block block;                                 /* Current block.             */
  184.   int state;                                   /* State of decoding.         */
  185.   int bit_offset;                              /* Bit offset in stream.      */
  186.   unsigned int *buffer;                        /* Pointer to next byte in buffer. */
  187.   int buf_length;                              /* Length of remaining buffer.*/
  188.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  189.   int max_buf_length;                          /* Max lenght of buffer.      */
  190.   PictImage *past;                             /* Past predictive frame.     */
  191.   PictImage *future;                           /* Future predictive frame.   */
  192.   PictImage *current;                          /* Current frame.             */
  193.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  194. } VidStream;   
  195.  
  196. /* Declaration of global pointer to current video stream. */
  197.  
  198. extern VidStream *curVidStream;
  199.  
  200. /* Declarataion of global display pointer. */
  201.  
  202. typedef struct {
  203.     int foo;  /* a dummy struct */
  204. } Display;
  205. extern Display *display;
  206.  
  207. /* Declaration of functions. */
  208.  
  209. extern void correct_underflow();
  210. extern void DecodeMBAddrInc();
  211. extern void DecodeMBTypeI();
  212. extern void DecodeMBTypeP();
  213. extern void DecodeMBTypeB();
  214. extern void DecodeCBP();
  215. extern void DecodeMotionVectors();
  216. extern void ComputeForwVector();
  217. extern void ComputeBackVector();
  218. extern int ParseReconBlock();
  219. extern int ParseAwayBlock();
  220. extern void j_rev_dct();
  221. extern void ToggleBFlag();
  222. extern void TogglePFlag();
  223. extern void DoDitherImage();
  224. extern void ExecuteDisplay();
  225. extern int get_more_data();
  226. extern void init_tables();
  227.  
  228. extern void InitColorDither();
  229. extern void ColorDitherImage();
  230. extern void DestroyVidStream();
  231. extern void DestroyPictImage();
  232. extern void decodeDCTCoeffFirst();
  233. extern void decodeDCTCoeffNext();
  234.  
  235. extern double realTimeStart;
  236. extern double ReadSysClock();
  237. extern int totNumFrames;
  238. extern int loopFlag;
  239. extern jmp_buf env;
  240.  
  241.