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
33 /* initialize buffer, call once before first getbits or showbits */
35 /* parse system layer, ignore everything we don't need */
45 /* remove system layer byte stuffing */
46 while ((code & 0xffffff00) != 0x100)
47 code = (code<<8) | Get_Byte();
51 case PACK_START_CODE: /* pack header */
52 /* skip pack header (system_clock_reference and mux_rate) */
55 case VIDEO_ELEMENTARY_STREAM:
56 code = Get_Word(); /* packet_length */
57 ld->Rdmax = ld->Rdptr + code;
64 code=Get_Byte(); /* parse PES_header_data_length */
65 ld->Rdptr+=code; /* advance pointer by PES_header_data_length */
66 my_printf("MPEG-2 PES packet\n");
71 /* parse MPEG-1 packet header */
72 while((code=Get_Byte())== 0xFF);
80 my_fprintf("Error in packet header\n");
83 /* skip STD_buffer_scale */
92 my_fprintf("Error in packet header\n");
95 /* skip presentation and decoding time stamps */
100 /* skip presentation time stamps */
105 my_fprintf("Error in packet header\n");
109 case ISO_END_CODE: /* end */
110 /* simulate a buffer full of sequence end codes */
114 ld->Rdbfr[l++] = SEQUENCE_END_CODE>>24;
115 ld->Rdbfr[l++] = SEQUENCE_END_CODE>>16;
116 ld->Rdbfr[l++] = SEQUENCE_END_CODE>>8;
117 ld->Rdbfr[l++] = SEQUENCE_END_CODE&0xff;
119 ld->Rdptr = ld->Rdbfr;
120 ld->Rdmax = ld->Rdbfr + 2048;
123 if(code>=SYSTEM_START_CODE)
125 /* skip system headers and non-video packets*/
131 my_fprintf("Unexpected startcode %08x in system layer\n",code);
141 void Flush_Buffer32()
150 if (System_Stream_Flag && (ld->Rdptr >= ld->Rdmax-4))
154 if (ld->Rdptr >= ld->Rdmax)
156 ld->Bfr |= Get_Byte() << (24 - Incnt);
164 if (ld->Rdptr >= ld->Rdbfr+2048)
166 ld->Bfr |= *ld->Rdptr++ << (24 - Incnt);
178 unsigned int Get_Bits32()
194 return (i<<16) | Get_Word();