annotate demux_mpg.c @ 1316:40083e7ad5ce

Disable 3dnow when mmx is disabled.
author atmos4
date Fri, 13 Jul 2001 19:49:15 +0000
parents 3f490fad9bdf
children b4457de47804
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
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
3 #include <stdio.h>
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
4 #include <stdlib.h>
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
5
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
6 extern int verbose; // defined in mplayer.c
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
7
594
dc093ff7b86e Encrypted DVD playback works again ;-)
lgb
parents: 587
diff changeset
8 #include "config.h"
dc093ff7b86e Encrypted DVD playback works again ;-)
lgb
parents: 587
diff changeset
9 #include "dvdauth.h"
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
10 #include "stream.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
11 #include "demuxer.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
12
524
9105fc95636c A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents: 501
diff changeset
13 //#define MAX_PS_PACKETSIZE 2048
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
14 #define MAX_PS_PACKETSIZE (224*1024)
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
15
554
d8b3c80604e3 dvd sub parser move dto mplayer.c
arpi_esp
parents: 552
diff changeset
16 //static void parse_dvdsub(unsigned char *buf,int len){
d8b3c80604e3 dvd sub parser move dto mplayer.c
arpi_esp
parents: 552
diff changeset
17 // printf("\rDVDsub packet: %d \n",len);
d8b3c80604e3 dvd sub parser move dto mplayer.c
arpi_esp
parents: 552
diff changeset
18 //}
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
19
547
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
20 static int mpeg_pts_error=0;
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
21
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 static unsigned int read_mpeg_timestamp(stream_t *s,int c){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 int d,e;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 unsigned int pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 d=stream_read_word(s);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 e=stream_read_word(s);
547
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
27 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
28 ++mpeg_pts_error;
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
29 return 0; // invalid pts
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
30 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 pts=(((c>>1)&7)<<30)|((d>>1)<<15)|(e>>1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 if(verbose>=3) printf("{%d}",pts);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 return pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
36 //static char dvdaudio_table[256];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 //static unsigned int packet_start_pos=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1162
diff changeset
39 extern void *new_sh_audio(demuxer_t *demux,int id);
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1162
diff changeset
40 extern void *new_sh_video(demuxer_t *demux,int id);
605
abd7391a31e3 warnings killed
szabii
parents: 594
diff changeset
41
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 static int demux_mpg_read_packet(demuxer_t *demux,int id){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 int d;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 int len;
492
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
45 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
46 int css=0;
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
47 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 unsigned char c=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 unsigned int pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 unsigned int dts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 demux_stream_t *ds=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 if(verbose>=3) printf("demux_read_packet: %X\n",id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
55 // if(id==0x1F0){
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
56 // demux->synced=0; // force resync after 0x1F0
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
57 // return -1;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
58 //}
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
59
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 // 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
61 if(id<0x1BC || id>=0x1F0) return -1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 if(id==0x1BE) return -1; // padding stream
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 if(id==0x1BF) return -1; // private2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 len=stream_read_word(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 if(verbose>=3) printf("PACKET len=%d",len);
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
67 // if(len==62480){ demux->synced=0;return -1;} /* :) */
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
68 // 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
69 if(len==0 || len>MAX_PS_PACKETSIZE){
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
70 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
71 return -2; // invalid packet !!!!!!
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
72 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73
547
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
74 mpeg_pts_error=0;
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
75
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 while(len>0){ // Skip stuFFing bytes
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 c=stream_read_char(demux->stream);--len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 if(c!=0xFF)break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 if((c>>6)==1){ // Read (skip) STD scale & size value
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 // printf(" STD_scale=%d",(c>>5)&1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 d=((c&0x1F)<<8)|stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 len-=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 // printf(" STD_size=%d",d);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 // Read System-1 stream timestamps:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 if((c>>4)==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 len-=4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 if((c>>4)==3){
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 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 if((c>>4)!=1) pts=0; //printf("{ERROR4}");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 dts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 len-=4+1+4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 if((c>>6)==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 int pts_flags;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 int hdrlen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 // System-2 (.VOB) stream:
492
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
103 if((c>>4)&3) {
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
104 #ifdef HAVE_LIBCSS
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
105 css=1;
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
106 #else
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
107 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
108 #endif
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
109 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 c=stream_read_char(demux->stream); pts_flags=c>>6;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 c=stream_read_char(demux->stream); hdrlen=c;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 len-=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 if(verbose>=3) printf(" hdrlen=%d (len=%d)",hdrlen,len);
242
18e5c0f63947 fix: packet longer than 4096 bytes
arpi_esp
parents: 1
diff changeset
114 if(hdrlen>len){ printf("demux_mpg: invalid header length \n"); return -1;}
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 if(pts_flags==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 len-=5;hdrlen-=5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 if(pts_flags==3){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 pts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 dts=read_mpeg_timestamp(demux->stream,c);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 len-=10;hdrlen-=10;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 len-=hdrlen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 //============== DVD Audio sub-stream ======================
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 if(id==0x1BD){
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
132 int aid=stream_read_char(demux->stream);--len;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 if(len<3) return -1; // invalid audio packet
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
134
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
135 // AID:
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
136 // 0x20..0x3F subtitle
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
137 // 0x80..0x9F AC3 audio
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
138 // 0xA0..0xBF PCM audio
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
139
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
140 if((aid & 0xE0) == 0x20){
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
141 // subtitle:
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
142 aid&=0x1F;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
143
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
144 if(!demux->s_streams[aid]){
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
145 printf("==> Found subtitle: %d\n",aid);
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
146 demux->s_streams[aid]=1;
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
147 // new_sh_audio(aid);
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
148 }
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
149
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
150 //if(demux->audio->id==-1) demux->audio->id=aid; // autodetect :)
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
151 if(demux->sub->id==aid){
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
152 ds=demux->sub;
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
153 }
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
154
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
155 } else if((aid & 0xC0) == 0x80) {
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
156
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
157 // aid=128+(aid&0x7F);
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
158 // aid=0x80..0xBF
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
159
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1162
diff changeset
160 if(!demux->a_streams[aid]) new_sh_audio(demux,aid);
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
161 if(demux->audio->id==-1) demux->audio->id=aid;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
162
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
163 if(demux->audio->id==aid){
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
164 // int type;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
165 ds=demux->audio;
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
166 if(!ds->sh) ds->sh=demux->a_streams[aid];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 // READ Packet: Skip additional audio header data:
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
168 c=stream_read_char(demux->stream);//type=c;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
169 c=stream_read_char(demux->stream);//type|=c<<8;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
170 c=stream_read_char(demux->stream);//type|=c<<16;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
171 // printf("[%06X]",type);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 len-=3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 if(ds->type==-1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 // autodetect type
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
175 ds->type=((aid&0xE0)==0xA0)?2:3;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 if(ds->type==2 && len>=2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 // read PCM header
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 int head;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 head=stream_read_char(demux->stream); head=c<<8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 c=stream_read_char(demux->stream); head|=c; len-=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 while(len>0 && head!=0x180){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 head=c<<8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 c=stream_read_char(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 head|=c;--len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 if(!len) printf("End of packet while searching for PCM header\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 }
552
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
189 } // if(demux->audio->id==aid)
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
190
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
191 } else printf("Unknown 0x1BD substream: 0x%02X \n",aid);
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
192
c2a449f90087 dvd sub support reading
arpi_esp
parents: 547
diff changeset
193 } //if(id==0x1BD)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 } else {
539
48f0c6f0519f dumb bug here too :)
arpi_esp
parents: 536
diff changeset
196 if(c!=0x0f){
541
b382156bff40 Embarrassing messages while playing DVD are moved to verbose level 1
lgb
parents: 539
diff changeset
197 if (verbose>=1) printf(" {ERROR5,c=%d} \n",c);
539
48f0c6f0519f dumb bug here too :)
arpi_esp
parents: 536
diff changeset
198 return -1; // invalid packet !!!!!!
48f0c6f0519f dumb bug here too :)
arpi_esp
parents: 536
diff changeset
199 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 }
547
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
201 if(mpeg_pts_error) printf(" {PTS_err:%d} \n",mpeg_pts_error);
242
18e5c0f63947 fix: packet longer than 4096 bytes
arpi_esp
parents: 1
diff changeset
202 if(verbose>=3) printf(" => len=%d\n",len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203
501
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
204 // 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
205 if(len<=0 || len>MAX_PS_PACKETSIZE){
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
206 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
207 return -1; // invalid packet !!!!!!
bfc86f5a5ba7 PES supported again, VOB 0x1F0 problems fixed
arpi_esp
parents: 494
diff changeset
208 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 if(id>=0x1C0 && id<=0x1DF){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 // mpeg audio
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 int aid=id-0x1C0;
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1162
diff changeset
213 if(!demux->a_streams[aid]) new_sh_audio(demux,aid);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 if(demux->audio->id==-1) demux->audio->id=aid;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 if(demux->audio->id==aid){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 ds=demux->audio;
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
217 if(!ds->sh) ds->sh=demux->a_streams[aid];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 if(ds->type==-1) ds->type=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 if(id>=0x1E0 && id<=0x1EF){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 // mpeg video
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 int aid=id-0x1E0;
1289
3f490fad9bdf some code clanup (first step to libdemuxer)
arpi
parents: 1162
diff changeset
224 if(!demux->v_streams[aid]) new_sh_video(demux,aid);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 if(demux->video->id==-1) demux->video->id=aid;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
226 if(demux->video->id==aid){
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
227 ds=demux->video;
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
228 if(!ds->sh) ds->sh=demux->v_streams[aid];
426
26e513f392b2 new stream selection code
arpi_esp
parents: 397
diff changeset
229 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 if(ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 if(verbose>=2) printf("DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 // 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
235 #ifdef HAVE_LIBCSS
546
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 541
diff changeset
236 if (css) {
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 541
diff changeset
237 if (descrambling) CSSDescramble(demux->stream->buffer,key_title); else
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 541
diff changeset
238 printf("Encrypted stream but authentication was not requested by you!!\n");
22ed5f5821e2 command line requested DVD key support for Arpi :)
lgb
parents: 541
diff changeset
239 }
492
888a85621f50 preliminary DVD support using libcss
lgb
parents: 426
diff changeset
240 #endif
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 929
diff changeset
241 ds_read_packet(ds,demux->stream,len,pts/90000.0f,0,0);
554
d8b3c80604e3 dvd sub parser move dto mplayer.c
arpi_esp
parents: 552
diff changeset
242 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 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
246 if(len<=2356) stream_skip(demux->stream,len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
250 int num_elementary_packets100=0;
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 554
diff changeset
251 int num_elementary_packets101=0;
1162
11e49d541f11 packet 0x1B6 (mpeg4 stream) detection
arpi_esp
parents: 979
diff changeset
252 int num_elementary_packets1B6=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 int demux_mpg_es_fill_buffer(demuxer_t *demux){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 //if(demux->type==DEMUXER_TYPE_MPEG_ES)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 // Elementary video stream
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 if(demux->stream->eof) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 demux->filepos=stream_tell(demux->stream);
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 929
diff changeset
259 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,0,0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 int demux_mpg_fill_buffer(demuxer_t *demux){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 unsigned int head=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 int skipped=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 int max_packs=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 // System stream
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 head=stream_read_dword(demux->stream);
547
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
273 if((head&0xFFFFFF00)!=0x100){
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
274 // sync...
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
275 demux->filepos-=skipped;
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
276 while(1){
536
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
277 int c=stream_read_char(demux->stream);
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
278 if(c<0) break; //EOF
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
279 head<<=8;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
280 if(head!=0x100){
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
281 head|=c;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
282 ++skipped; //++demux->filepos;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
283 continue;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
284 }
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
285 head|=c;
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
286 break;
547
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
287 }
3e46eab9f782 small bugfix in the new optimized head sync code
arpi_esp
parents: 546
diff changeset
288 demux->filepos+=skipped;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 if(stream_eof(demux->stream)) break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 // sure: head=0x000001XX
524
9105fc95636c A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents: 501
diff changeset
292 if(verbose>=4) printf("*** head=0x%X\n",head);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 if(demux->synced==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 if(head==0x1BA) demux->synced=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 if(demux->synced==1){
929
6dedc7cb0146 accept 1BD packets for PS stream sync
arpi_esp
parents: 605
diff changeset
297 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 demux->synced=2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 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
300 num_elementary_packets100=0; // requires for re-sync!
3c9b3ce721f0 PES vs. VOB problem... yet another solution
arpi_esp
parents: 524
diff changeset
301 num_elementary_packets101=0; // requires for re-sync!
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 } else demux->synced=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 } // else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 if(demux->synced==2){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 ret=demux_mpg_read_packet(demux,head);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 if(!ret)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 if(--max_packs==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 printf("demux: file doesn't contain the selected audio or video stream\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 if(head>=0x100 && head<0x1B0){
1162
11e49d541f11 packet 0x1B6 (mpeg4 stream) detection
arpi_esp
parents: 979
diff changeset
314 if(head==0x100) ++num_elementary_packets100; else
11e49d541f11 packet 0x1B6 (mpeg4 stream) detection
arpi_esp
parents: 979
diff changeset
315 if(head==0x101) ++num_elementary_packets101;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 if(verbose>=3) printf("Opps... elementary video packet found: %03X\n",head);
1162
11e49d541f11 packet 0x1B6 (mpeg4 stream) detection
arpi_esp
parents: 979
diff changeset
317 } else
11e49d541f11 packet 0x1B6 (mpeg4 stream) detection
arpi_esp
parents: 979
diff changeset
318 if(head==0x1B6) ++num_elementary_packets1B6;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 if(num_elementary_packets100>50 && num_elementary_packets101>50
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 && skipped>4000000){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 if(verbose) printf("sync_mpeg_ps: seems to be ES stream...\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 if(verbose>=2) printf("demux: %d bad bytes skipped\n",skipped);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 if(demux->stream->eof){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 if(verbose>=2) printf("MPEG Stream reached EOF\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336