home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v5 / amipeg / source / video.h < prev   
C/C++ Source or Header  |  1977-12-31  |  10KB  |  243 lines

  1.  
  2. #include <stdio.h>
  3. #include <setjmp.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. typedef int INT32;
  8. typedef short INT16;
  9. typedef char INT8;
  10. typedef unsigned int UINT32;
  11. typedef unsigned short UINT16;
  12. typedef unsigned char UINT8;
  13.  
  14. /* Define Parsing error codes. */
  15.  
  16. #define SKIP_PICTURE -10
  17. #define SKIP_TO_START_CODE -1
  18. #define PARSE_OK 1
  19.  
  20. /* Define BOOLEAN, TRUE, and FALSE. */
  21.  
  22. #define BOOLEAN int
  23. #define TRUE 1
  24. #define FALSE 0
  25.  
  26. /* Set ring buffer size. */
  27.  
  28. #define RING_BUF_SIZE 5
  29.  
  30. /* Macros for picture code type. */
  31.  
  32. #define I_TYPE 1
  33. #define P_TYPE 2
  34. #define B_TYPE 3
  35.  
  36. /* Start codes. */
  37.  
  38. #define SEQ_END_CODE 0x000001b7
  39. #define SEQ_START_CODE 0x000001b3
  40. #define GOP_START_CODE 0x000001b8
  41. #define PICTURE_START_CODE 0x00000100
  42. #define SLICE_MIN_START_CODE 0x00000101
  43. #define SLICE_MAX_START_CODE 0x000001af
  44. #define EXT_START_CODE 0x000001b5
  45. #define USER_START_CODE 0x000001b2
  46.  
  47. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  48.  
  49. #define MB_QUANTUM 100
  50.  
  51. /* Macros used with macroblock address decoding. */
  52.  
  53. #define MB_STUFFING 34
  54. #define MB_ESCAPE 35
  55.  
  56. /* Lock flags for pict images. */
  57.  
  58. #define DISPLAY_LOCK 0x01
  59. #define PAST_LOCK 0x02
  60. #define FUTURE_LOCK 0x04
  61.  
  62. #define GRAY_DITHER 6
  63. #define FULL_COLOR_DITHER 7
  64. #define CYBERGFX_DITHER 8
  65. #define CYBERGFXGRAY_DITHER 9
  66. #define NO_DITHER 10
  67.  
  68. /* Temporary definition of time stamp structure. */
  69.  
  70. typedef int TimeStamp;
  71.  
  72. /* Structure with reconstructed pixel values. */
  73.  
  74. typedef struct pict_image {
  75.   unsigned char *luminance;              /* Luminance plane.   */
  76.   unsigned char *Cr;                     /* Cr plane.          */
  77.   unsigned char *Cb;                     /* Cb plane.          */
  78.   unsigned char *display;                /* Display plane.     */
  79.   int locked;                            /* Lock flag.         */
  80.   TimeStamp show_time;                   /* Presentation time. */
  81. } PictImage;
  82.  
  83. /* Group of pictures structure. */
  84.  
  85. typedef struct GoP {
  86.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  87.   unsigned int tc_hours;                 /* Hour component of time code.   */
  88.   unsigned int tc_minutes;               /* Minute component of time code. */
  89.   unsigned int tc_seconds;               /* Second component of time code. */
  90.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  91.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  92.                         previous group of pictures.    */
  93.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  94.   char *ext_data;                        /* Extension data.                */
  95.   char *user_data;                       /* User data.                     */
  96. } GoP;
  97.  
  98. /* Picture structure. */
  99.  
  100. typedef struct pict {
  101.   unsigned int temp_ref;                 /* Temporal reference.             */
  102.   unsigned int code_type;                /* Frame type: P, B, I             */
  103.   unsigned int vbv_delay;                /* Buffer delay.                   */
  104.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  105.                         pixel values flag.              */
  106.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  107.   unsigned int forw_f;                   /* Used for vector decoding.       */
  108.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  109.                         pixel values flag.              */
  110.   unsigned int back_r_size;              /* Used in decoding.               */
  111.   unsigned int back_f;                   /* Used in decoding.               */
  112.   char *extra_info;                      /* Extra bit picture info.         */
  113.   char *ext_data;                        /* Extension data.                 */
  114.   char *user_data;                       /* User data.                      */
  115. } Pict;
  116.  
  117. /* Slice structure. */
  118.  
  119. typedef struct slice {
  120.   unsigned int vert_pos;                 /* Vertical position of slice. */
  121.   unsigned int quant_scale;              /* Quantization scale.         */
  122.   char *extra_info;                      /* Extra bit slice info.       */
  123. } Slice;
  124.  
  125. /* Macroblock structure. */
  126.  
  127. typedef struct macroblock {
  128.   int mb_address;                        /* Macroblock address.              */
  129.   int past_mb_addr;                      /* Previous mblock address.         */
  130.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  131.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  132.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  133.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  134.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  135.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  136.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  137.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  138.   unsigned int cbp;                      /* Coded block pattern.             */
  139.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  140.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  141.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  142.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  143.   int recon_right_for_prev;              /* Past right forw. vector.         */
  144.   int recon_down_for_prev;               /* Past down forw. vector.          */
  145.   int recon_right_back_prev;             /* Past right back vector.          */
  146.   int recon_down_back_prev;              /* Past down back vector.           */
  147. } Macroblock;
  148.  
  149. /* Block structure. */
  150.  
  151. typedef struct block {
  152.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  153.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  154.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  155.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  156. } Block;
  157.  
  158. /* Video stream structure. */
  159.  
  160. typedef struct vid_stream {
  161.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  162.   unsigned int v_size;                         /* Vert. size in pixels.      */
  163.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  164.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  165.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  166.   unsigned char picture_rate;                  /* Code for picture rate.     */
  167.   unsigned int bit_rate;                       /* Bit rate.                  */
  168.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  169.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  170. #if 0
  171.   unsigned char intra_quant_matrix[8*8];       /* Quantization matrix for
  172.                           intracoded frames.         */
  173.   unsigned char non_intra_quant_matrix[8*8];   /* Quanitization matrix for 
  174.                           non intracoded frames.     */
  175. #endif
  176.   char *ext_data;                              /* Extension data.            */
  177.   char *user_data;                             /* User data.                 */
  178.   GoP group;                                   /* Current group of pict.     */
  179.   Pict picture;                                /* Current picture.           */
  180.   Slice slice;                                 /* Current slice.             */
  181.   Macroblock mblock;                           /* Current macroblock.        */
  182.   Block block;                                 /* Current block.             */
  183.   int state;                                   /* State of decoding.         */
  184.   int bit_offset;                              /* Bit offset in stream.      */
  185.   unsigned int *buffer;                        /* Pointer to next byte in
  186.                           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.  
  195.   unsigned short *intra_quant_matrix_ptr[32];        /* Quantization matrix for intracoded frames.
  196.                                The zero entry is for security reason only.     */
  197.  
  198.   BOOLEAN non_intra_default;                /* default non_intra matrix is all 16 */
  199.   unsigned short *non_intra_quant_matrix_ptr[32];    /* Quantization matrix for non intracoded frames.*/
  200.  
  201.   BOOLEAN display_is_initialized;        /* Resize display still to be done */
  202. } VidStream;   
  203.  
  204. /* Declaration of global pointer to current video stream. */
  205.  
  206. extern VidStream *curVidStream;
  207.  
  208. /* Quiet mode flag. */
  209. extern int quietFlag;
  210.  
  211. /* Definition of Contant integer scale factor. */
  212.  
  213. #define CONST_BITS 13
  214.  
  215. /* Misc DCT definitions */
  216. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  217. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  218.  
  219. typedef short DCTELEM;
  220. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  221.  
  222.  
  223. extern double realTimeStart;
  224. extern int totNumFrames;
  225. extern int loopFlag;
  226. extern int noDisplayFlag;
  227. extern jmp_buf env;
  228.  
  229. #ifdef ANALYSIS
  230. extern unsigned int bitCount;
  231. extern int showEachFlag;
  232. extern unsigned int cacheHit[8][8];
  233. extern unsigned int cacheMiss[8][8];
  234. #endif
  235.  
  236.  
  237. /* Video rates table (taken from mpeg_play 2.3) */
  238. /* Cheat on Vid rates, round to 30, and use 30 if illegal value 
  239.    Except for 9, where Xing means 15, and given their popularity, we'll
  240.    be nice and do it */
  241. static int VidRateNum[16]={30, 24, 24, 25, 30, 30, 50, 60, 
  242.                          60, 15, 30, 30, 30, 30, 30, 30};
  243.