annotate demux_mpg.c @ 542:7eaec864e3d2

doesn't include fastmemcpy.h when SDL_NOXV is defined. (otherwise MPlayer crashes in fastmemcpy.h, needs to be FIXED!)
author atmosfear
date Fri, 20 Apr 2001 09:06:49 +0000
parents b382156bff40
children 22ed5f5821e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // MPG/VOB file parser for DEMUXER v2.5 by A'rpi/ESP-team
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
524
9105fc95636c A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents: 501
diff changeset
3 //#define MAX_PS_PACKETSIZE 2048
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
4 #define MAX_PS_PACKETSIZE (224*1024)
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
5
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 static unsigned int read_mpeg_timestamp(stream_t *s,int c){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 int d,e;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 unsigned int pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 d=stream_read_word(s);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 e=stream_read_word(s);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ) return 0; // invalid pts
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 pts=(((c>>1)&7)<<30)|((d>>1)<<15)|(e>>1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 if(verbose>=3) printf("{%d}",pts);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 return pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
17 //static char dvdaudio_table[256];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 //static unsigned int packet_start_pos=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 static int demux_mpg_read_packet(demuxer_t *demux,int id){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 int d;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 int len;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
23 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
24 int css=0;
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
25 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 unsigned char c=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 unsigned int pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 unsigned int dts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 demux_stream_t *ds=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 if(verbose>=3) printf("demux_read_packet: %X\n",id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
33 // if(id==0x1F0){
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
34 // demux->synced=0; // force resync after 0x1F0
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
35 // return -1;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
36 //}
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
37
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 // if(id==0x1BA) packet_start_pos=stream_tell(demux->stream);
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
39 if(id<0x1BC || id>=0x1F0) return -1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 if(id==0x1BE) return -1; // padding stream
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 if(id==0x1BF) return -1; // private2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 len=stream_read_word(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 if(verbose>=3) printf("PACKET len=%d",len);
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
45 // if(len==62480){ demux->synced=0;return -1;} /* :) */
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
46 // if(len==0 || len>MAX_PS_PACKETSIZE) return -2; // invalid packet !!!!!!
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
47 if(len==0 || len>MAX_PS_PACKETSIZE){
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
48 if(verbose>=2) printf("Invalid PS packet len: %d\n",len);
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
49 return -2; // invalid packet !!!!!!
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
50 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 while(len>0){ // Skip stuFFing bytes
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 c=stream_read_char(demux->stream);--len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 if(c!=0xFF)break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 if((c>>6)==1){ // Read (skip) STD scale & size value
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 // printf(" STD_scale=%d",(c>>5)&1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 d=((c&0x1F)<<8)|stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 len-=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 // printf(" STD_size=%d",d);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 // Read System-1 stream timestamps:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 if((c>>4)==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 len-=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 if((c>>4)==3){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 if((c>>4)!=1) pts=0; //printf("{ERROR4}");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 dts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 len-=4+1+4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 if((c>>6)==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 int pts_flags;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 int hdrlen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 // System-2 (.VOB) stream:
492
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
79 if((c>>4)&3) {
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
80 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
81 css=1;
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
82 #else
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
83 printf("Encrypted VOB file (not compiled with libcss support)! Read file DOCS/DVD\n");
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
84 #endif
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
85 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 c=stream_read_char(demux->stream); pts_flags=c>>6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 c=stream_read_char(demux->stream); hdrlen=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 len-=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 if(verbose>=3) printf(" hdrlen=%d (len=%d)",hdrlen,len);
242
18e5c0f63947 fix: packet longer than 4096 bytes
arpi_esp
parents: 1
diff changeset
90 if(hdrlen>len){ printf("demux_mpg: invalid header length \n"); return -1;}
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 if(pts_flags==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 len-=5;hdrlen-=5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 if(pts_flags==3){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 dts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 len-=10;hdrlen-=10;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 len-=hdrlen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 //============== DVD Audio sub-stream ======================
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 if(id==0x1BD){
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
108 int aid=128+(stream_read_char(demux->stream)&0x7F);--len;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 if(len<3) return -1; // invalid audio packet
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
110
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
111 if(!avi_header.a_streams[aid]) new_sh_audio(aid);
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
112 if(demux->audio->id==-1) demux->audio->id=aid;
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
113
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
114 if(demux->audio->id==aid){
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
115 // int type;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
116 ds=demux->audio;
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
117 if(!ds->sh) ds->sh=avi_header.a_streams[aid];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 // READ Packet: Skip additional audio header data:
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
119 c=stream_read_char(demux->stream);//type=c;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
120 c=stream_read_char(demux->stream);//type|=c<<8;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
121 c=stream_read_char(demux->stream);//type|=c<<16;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
122 // printf("[%06X]",type);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 len-=3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 if(ds->type==-1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 // autodetect type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 ds->type=((aid&0x70)==0x20)?2:3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 if(ds->type==2 && len>=2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 // read PCM header
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 int head;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 head=stream_read_char(demux->stream); head=c<<8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 c=stream_read_char(demux->stream); head|=c; len-=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 while(len>0 && head!=0x180){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 head=c<<8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 head|=c;--len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 if(!len) printf("End of packet while searching for PCM header\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 } else {
539
48f0c6f0519f dumb bug here too :)
arpi_esp
parents: 536
diff changeset
144 if(c!=0x0f){
541
b382156bff40 Embarrassing messages while playing DVD are moved to verbose level 1
lgb
parents: 539
diff changeset
145 if (verbose>=1) printf(" {ERROR5,c=%d} \n",c);
539
48f0c6f0519f dumb bug here too :)
arpi_esp
parents: 536
diff changeset
146 return -1; // invalid packet !!!!!!
48f0c6f0519f dumb bug here too :)
arpi_esp
parents: 536
diff changeset
147 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 }
242
18e5c0f63947 fix: packet longer than 4096 bytes
arpi_esp
parents: 1
diff changeset
149 if(verbose>=3) printf(" => len=%d\n",len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
151 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
152 if(len<=0 || len>MAX_PS_PACKETSIZE){
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
153 if(verbose>=2) printf("Invalid PS data len: %d\n",len);
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
154 return -1; // invalid packet !!!!!!
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
155 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 if(id>=0x1C0 && id<=0x1DF){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 // mpeg audio
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 int aid=id-0x1C0;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
160 if(!avi_header.a_streams[aid]) new_sh_audio(aid);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 if(demux->audio->id==-1) demux->audio->id=aid;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 if(demux->audio->id==aid){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 ds=demux->audio;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
164 if(!ds->sh) ds->sh=avi_header.a_streams[aid];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 if(ds->type==-1) ds->type=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 if(id>=0x1E0 && id<=0x1EF){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 // mpeg video
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 int aid=id-0x1E0;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
171 if(!avi_header.v_streams[aid]) new_sh_video(aid);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 if(demux->video->id==-1) demux->video->id=aid;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
173 if(demux->video->id==aid){
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
174 ds=demux->video;
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
175 if(!ds->sh) ds->sh=avi_header.v_streams[aid];
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
176 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 if(ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 if(verbose>=2) printf("DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 // printf("packet start = 0x%X \n",stream_tell(demux->stream)-packet_start_pos);
492
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
182 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
183 if (css) CSSDescramble(demux->stream->buffer,key_title);
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
184 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 ds_read_packet(ds,demux->stream,len,pts/90000.0f,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 if(verbose>=2) printf("DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id);
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
189 if(len<=2356) stream_skip(demux->stream,len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 static int num_elementary_packets100=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 static int num_elementary_packets101=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 int demux_mpg_es_fill_buffer(demuxer_t *demux){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 //if(demux->type==DEMUXER_TYPE_MPEG_ES)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 // Elementary video stream
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 if(demux->stream->eof) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 demux->filepos=stream_tell(demux->stream);
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
201 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 int demux_mpg_fill_buffer(demuxer_t *demux){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 unsigned int head=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 int skipped=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 int max_packs=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 // System stream
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 head=stream_read_dword(demux->stream);
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
215 demux->filepos-=skipped;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
216 while(1){
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
217 int c=stream_read_char(demux->stream);
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
218 if(c<0) break; //EOF
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
219 head<<=8;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
220 if(head!=0x100){
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
221 head|=c;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
222 ++skipped; //++demux->filepos;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
223 continue;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
224 }
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
225 head|=c;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
226 break;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 }
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
228 demux->filepos+=skipped;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 if(stream_eof(demux->stream)) break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 // sure: head=0x000001XX
524
9105fc95636c A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents: 501
diff changeset
231 if(verbose>=4) printf("*** head=0x%X\n",head);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 if(demux->synced==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 if(head==0x1BA) demux->synced=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 if(demux->synced==1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 if(head==0x1BB || (head>=0x1C0 && head<=0x1EF)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 demux->synced=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 if(verbose) printf("system stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos);
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
239 num_elementary_packets100=0; // requires for re-sync!
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
240 num_elementary_packets101=0; // requires for re-sync!
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 } else demux->synced=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 } // else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 if(demux->synced==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 ret=demux_mpg_read_packet(demux,head);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 if(!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 if(--max_packs==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 printf("demux: file doesn't contain the selected audio or video stream\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 if(head>=0x100 && head<0x1B0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 if(head==0x100)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 ++num_elementary_packets100;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 if(head==0x101) ++num_elementary_packets101;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 if(verbose>=3) printf("Opps... elementary video packet found: %03X\n",head);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 if(num_elementary_packets100>50 && num_elementary_packets101>50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 && skipped>4000000){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 if(verbose) printf("sync_mpeg_ps: seems to be ES stream...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 if(verbose>=2) printf("demux: %d bad bytes skipped\n",skipped);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 if(demux->stream->eof){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 if(verbose>=2) printf("MPEG Stream reached EOF\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276