1 /* systems.c, systems-specific routines */
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
6 * Disclaimer of Warranty
8 * These software programs are available to the user without any license fee or
9 * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
10 * any and all warranties, whether express, implied, or statuary, including any
11 * implied warranties or merchantability or of fitness for a particular
12 * purpose. In no event shall the copyright-holder be liable for any
13 * incidental, punitive, or consequential damages of any kind whatsoever
14 * arising from the use of these programs.
16 * This disclaimer of warranty extends to the user of these programs and user's
17 * customers, employees, agents, transferees, successors, and assigns.
19 * The MPEG Software Simulation Group does not represent or warrant that the
20 * programs furnished hereunder are free of infringement of any third-party
23 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24 * are subject to royalty fees to patent holders. Many of these patents are
25 * general enough such that they are unavoidable regardless of implementation
36 /* initialize buffer, call once before first getbits or showbits */
38 /* parse system layer, ignore everything we don't need */
48 /* remove system layer byte stuffing */
49 while ((code & 0xffffff00) != 0x100)
50 code = (code<<8) | Get_Byte();
54 case PACK_START_CODE: /* pack header */
55 /* skip pack header (system_clock_reference and mux_rate) */
58 case VIDEO_ELEMENTARY_STREAM:
59 code = Get_Word(); /* packet_length */
60 ld->Rdmax = ld->Rdptr + code;
67 code=Get_Byte(); /* parse PES_header_data_length */
68 ld->Rdptr+=code; /* advance pointer by PES_header_data_length */
69 printf("MPEG-2 PES packet\n");
74 /* parse MPEG-1 packet header */
75 while((code=Get_Byte())== 0xFF);
83 fprintf(stderr,"Error in packet header\n");
86 /* skip STD_buffer_scale */
95 fprintf(stderr,"Error in packet header\n");
98 /* skip presentation and decoding time stamps */
103 /* skip presentation time stamps */
108 fprintf(stderr,"Error in packet header\n");
112 case ISO_END_CODE: /* end */
113 /* simulate a buffer full of sequence end codes */
117 ld->Rdbfr[l++] = SEQUENCE_END_CODE>>24;
118 ld->Rdbfr[l++] = SEQUENCE_END_CODE>>16;
119 ld->Rdbfr[l++] = SEQUENCE_END_CODE>>8;
120 ld->Rdbfr[l++] = SEQUENCE_END_CODE&0xff;
122 ld->Rdptr = ld->Rdbfr;
123 ld->Rdmax = ld->Rdbfr + 2048;
126 if(code>=SYSTEM_START_CODE)
128 /* skip system headers and non-video packets*/
134 fprintf(stderr,"Unexpected startcode %08x in system layer\n",code);
144 void Flush_Buffer32()
153 if (System_Stream_Flag && (ld->Rdptr >= ld->Rdmax-4))
157 if (ld->Rdptr >= ld->Rdmax)
159 ld->Bfr |= Get_Byte() << (24 - Incnt);
167 if (ld->Rdptr >= ld->Rdbfr+2048)
169 ld->Bfr |= *ld->Rdptr++ << (24 - Incnt);
181 unsigned int Get_Bits32()
197 return (i<<16) | Get_Word();