Mercurial > mplayer.hg
annotate demux_mpg.c @ 1761:827b551bbcab
subdump
author | arpi |
---|---|
date | Wed, 29 Aug 2001 20:15:41 +0000 |
parents | bdc1ec6fe668 |
children | 5216f108cb4f |
rev | line source |
---|---|
1 | 1 // MPG/VOB file parser for DEMUXER v2.5 by A'rpi/ESP-team |
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> |
1430 | 5 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
6 |
1567 | 7 #include "config.h" |
8 #include "mp_msg.h" | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
9 |
594 | 10 #include "config.h" |
11 #include "dvdauth.h" | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
12 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
13 #include "demuxer.h" |
1466 | 14 #include "parse_es.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
15 |
524
9105fc95636c
A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents:
501
diff
changeset
|
16 //#define MAX_PS_PACKETSIZE 2048 |
501 | 17 #define MAX_PS_PACKETSIZE (224*1024) |
18 | |
547 | 19 static int mpeg_pts_error=0; |
20 | |
1 | 21 static unsigned int read_mpeg_timestamp(stream_t *s,int c){ |
22 int d,e; | |
23 unsigned int pts; | |
24 d=stream_read_word(s); | |
25 e=stream_read_word(s); | |
547 | 26 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){ |
27 ++mpeg_pts_error; | |
28 return 0; // invalid pts | |
29 } | |
1 | 30 pts=(((c>>1)&7)<<30)|((d>>1)<<15)|(e>>1); |
1567 | 31 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"{%d}",pts); |
1 | 32 return pts; |
33 } | |
34 | |
35 //static unsigned int packet_start_pos=0; | |
36 | |
1466 | 37 //extern void *new_sh_audio(demuxer_t *demux,int id); |
38 //extern void *new_sh_video(demuxer_t *demux,int id); | |
39 #include "wine/mmreg.h" | |
40 #include "wine/avifmt.h" | |
41 #include "wine/vfw.h" | |
42 | |
43 #include "codec-cfg.h" | |
44 #include "stheader.h" | |
605 | 45 |
1 | 46 static int demux_mpg_read_packet(demuxer_t *demux,int id){ |
47 int d; | |
48 int len; | |
492 | 49 #ifdef HAVE_LIBCSS |
50 int css=0; | |
51 #endif | |
1 | 52 unsigned char c=0; |
53 unsigned int pts=0; | |
54 unsigned int dts=0; | |
55 demux_stream_t *ds=NULL; | |
56 | |
1567 | 57 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_read_packet: %X\n",id); |
1 | 58 |
536 | 59 // if(id==0x1F0){ |
60 // demux->synced=0; // force resync after 0x1F0 | |
61 // return -1; | |
62 //} | |
501 | 63 |
1 | 64 // if(id==0x1BA) packet_start_pos=stream_tell(demux->stream); |
501 | 65 if(id<0x1BC || id>=0x1F0) return -1; |
1 | 66 if(id==0x1BE) return -1; // padding stream |
67 if(id==0x1BF) return -1; // private2 | |
68 | |
69 len=stream_read_word(demux->stream); | |
1567 | 70 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"PACKET len=%d",len); |
536 | 71 // if(len==62480){ demux->synced=0;return -1;} /* :) */ |
501 | 72 if(len==0 || len>MAX_PS_PACKETSIZE){ |
1567 | 73 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS packet len: %d\n",len); |
501 | 74 return -2; // invalid packet !!!!!! |
75 } | |
1 | 76 |
547 | 77 mpeg_pts_error=0; |
78 | |
1 | 79 while(len>0){ // Skip stuFFing bytes |
80 c=stream_read_char(demux->stream);--len; | |
81 if(c!=0xFF)break; | |
82 } | |
83 if((c>>6)==1){ // Read (skip) STD scale & size value | |
84 // printf(" STD_scale=%d",(c>>5)&1); | |
85 d=((c&0x1F)<<8)|stream_read_char(demux->stream); | |
86 len-=2; | |
87 // printf(" STD_size=%d",d); | |
88 c=stream_read_char(demux->stream); | |
89 } | |
90 // Read System-1 stream timestamps: | |
91 if((c>>4)==2){ | |
92 pts=read_mpeg_timestamp(demux->stream,c); | |
93 len-=4; | |
94 } else | |
95 if((c>>4)==3){ | |
96 pts=read_mpeg_timestamp(demux->stream,c); | |
97 c=stream_read_char(demux->stream); | |
98 if((c>>4)!=1) pts=0; //printf("{ERROR4}"); | |
99 dts=read_mpeg_timestamp(demux->stream,c); | |
100 len-=4+1+4; | |
101 } else | |
102 if((c>>6)==2){ | |
103 int pts_flags; | |
104 int hdrlen; | |
105 // System-2 (.VOB) stream: | |
492 | 106 if((c>>4)&3) { |
107 #ifdef HAVE_LIBCSS | |
108 css=1; | |
109 #else | |
1567 | 110 mp_msg(MSGT_DEMUX,MSGL_WARN,"Encrypted VOB file (not compiled with libcss support)! Read file DOCS/DVD\n"); |
492 | 111 #endif |
112 } | |
1 | 113 c=stream_read_char(demux->stream); pts_flags=c>>6; |
114 c=stream_read_char(demux->stream); hdrlen=c; | |
115 len-=2; | |
1567 | 116 mp_dbg(MSGT_DEMUX,MSGL_DBG3," hdrlen=%d (len=%d)",hdrlen,len); |
117 if(hdrlen>len){ mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid header length \n"); return -1;} | |
1 | 118 if(pts_flags==2){ |
119 c=stream_read_char(demux->stream); | |
120 pts=read_mpeg_timestamp(demux->stream,c); | |
121 len-=5;hdrlen-=5; | |
122 } else | |
123 if(pts_flags==3){ | |
124 c=stream_read_char(demux->stream); | |
125 pts=read_mpeg_timestamp(demux->stream,c); | |
126 c=stream_read_char(demux->stream); | |
127 dts=read_mpeg_timestamp(demux->stream,c); | |
128 len-=10;hdrlen-=10; | |
129 } | |
130 len-=hdrlen; | |
131 if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes | |
132 | |
133 //============== DVD Audio sub-stream ====================== | |
134 if(id==0x1BD){ | |
552 | 135 int aid=stream_read_char(demux->stream);--len; |
1 | 136 if(len<3) return -1; // invalid audio packet |
552 | 137 |
138 // AID: | |
139 // 0x20..0x3F subtitle | |
140 // 0x80..0x9F AC3 audio | |
141 // 0xA0..0xBF PCM audio | |
142 | |
143 if((aid & 0xE0) == 0x20){ | |
144 // subtitle: | |
145 aid&=0x1F; | |
426 | 146 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
147 if(!demux->s_streams[aid]){ |
1567 | 148 mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid); |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
149 demux->s_streams[aid]=1; |
552 | 150 } |
151 | |
152 if(demux->sub->id==aid){ | |
153 ds=demux->sub; | |
154 } | |
155 | |
156 } else if((aid & 0xC0) == 0x80) { | |
157 | |
158 // aid=128+(aid&0x7F); | |
159 // aid=0x80..0xBF | |
160 | |
1289 | 161 if(!demux->a_streams[aid]) new_sh_audio(demux,aid); |
552 | 162 if(demux->audio->id==-1) demux->audio->id=aid; |
426 | 163 |
164 if(demux->audio->id==aid){ | |
536 | 165 // int type; |
426 | 166 ds=demux->audio; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
167 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 168 // READ Packet: Skip additional audio header data: |
536 | 169 c=stream_read_char(demux->stream);//type=c; |
170 c=stream_read_char(demux->stream);//type|=c<<8; | |
171 c=stream_read_char(demux->stream);//type|=c<<16; | |
172 // printf("[%06X]",type); | |
1 | 173 len-=3; |
1331
b4457de47804
ds->type removed - using id-based audio format detection in mplayer.c
arpi
parents:
1289
diff
changeset
|
174 if((aid&0xE0)==0xA0 && len>=2){ |
1 | 175 // read PCM header |
176 int head; | |
177 head=stream_read_char(demux->stream); head=c<<8; | |
178 c=stream_read_char(demux->stream); head|=c; len-=2; | |
179 while(len>0 && head!=0x180){ | |
180 head=c<<8; | |
181 c=stream_read_char(demux->stream); | |
182 head|=c;--len; | |
183 } | |
1567 | 184 if(!len) mp_msg(MSGT_DEMUX,MSGL_V,"End of packet while searching for PCM header\n"); |
1 | 185 } |
552 | 186 } // if(demux->audio->id==aid) |
187 | |
1567 | 188 } else mp_msg(MSGT_DEMUX,MSGL_V,"Unknown 0x1BD substream: 0x%02X \n",aid); |
552 | 189 |
190 } //if(id==0x1BD) | |
1 | 191 |
192 } else { | |
539 | 193 if(c!=0x0f){ |
1567 | 194 mp_msg(MSGT_DEMUX,MSGL_V," {ERROR5,c=%d} \n",c); |
539 | 195 return -1; // invalid packet !!!!!! |
196 } | |
1 | 197 } |
1567 | 198 if(mpeg_pts_error) mp_msg(MSGT_DEMUX,MSGL_V," {PTS_err:%d} \n",mpeg_pts_error); |
199 mp_dbg(MSGT_DEMUX,MSGL_DBG3," => len=%d\n",len); | |
1 | 200 |
501 | 201 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size |
202 if(len<=0 || len>MAX_PS_PACKETSIZE){ | |
1567 | 203 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS data len: %d\n",len); |
501 | 204 return -1; // invalid packet !!!!!! |
205 } | |
1 | 206 |
207 if(id>=0x1C0 && id<=0x1DF){ | |
208 // mpeg audio | |
209 int aid=id-0x1C0; | |
1289 | 210 if(!demux->a_streams[aid]) new_sh_audio(demux,aid); |
1 | 211 if(demux->audio->id==-1) demux->audio->id=aid; |
212 if(demux->audio->id==aid){ | |
213 ds=demux->audio; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
214 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 215 } |
216 } else | |
217 if(id>=0x1E0 && id<=0x1EF){ | |
218 // mpeg video | |
219 int aid=id-0x1E0; | |
1289 | 220 if(!demux->v_streams[aid]) new_sh_video(demux,aid); |
1 | 221 if(demux->video->id==-1) demux->video->id=aid; |
426 | 222 if(demux->video->id==aid){ |
223 ds=demux->video; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
224 if(!ds->sh) ds->sh=demux->v_streams[aid]; |
426 | 225 } |
1 | 226 } |
227 | |
228 if(ds){ | |
1567 | 229 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); |
1 | 230 // printf("packet start = 0x%X \n",stream_tell(demux->stream)-packet_start_pos); |
492 | 231 #ifdef HAVE_LIBCSS |
546 | 232 if (css) { |
233 if (descrambling) CSSDescramble(demux->stream->buffer,key_title); else | |
1567 | 234 mp_msg(MSGT_DEMUX,MSGL_WARN,"Encrypted stream but authentication was not requested by you!!\n"); |
546 | 235 } |
492 | 236 #endif |
1735 | 237 ds_read_packet(ds,demux->stream,len,pts/90000.0f,demux->filepos,0); |
554 | 238 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len); |
1 | 239 return 1; |
240 } | |
1567 | 241 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id); |
536 | 242 if(len<=2356) stream_skip(demux->stream,len); |
1 | 243 return 0; |
244 } | |
245 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
246 int num_elementary_packets100=0; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
247 int num_elementary_packets101=0; |
1162 | 248 int num_elementary_packets1B6=0; |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
249 int num_elementary_packetsPES=0; |
1 | 250 |
251 int demux_mpg_es_fill_buffer(demuxer_t *demux){ | |
252 // Elementary video stream | |
253 if(demux->stream->eof) return 0; | |
254 demux->filepos=stream_tell(demux->stream); | |
1735 | 255 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,demux->filepos,0); |
1 | 256 return 1; |
257 } | |
258 | |
259 int demux_mpg_fill_buffer(demuxer_t *demux){ | |
260 unsigned int head=0; | |
261 int skipped=0; | |
262 int max_packs=128; | |
263 int ret=0; | |
264 | |
265 // System stream | |
266 do{ | |
267 demux->filepos=stream_tell(demux->stream); | |
268 head=stream_read_dword(demux->stream); | |
547 | 269 if((head&0xFFFFFF00)!=0x100){ |
270 // sync... | |
271 demux->filepos-=skipped; | |
272 while(1){ | |
536 | 273 int c=stream_read_char(demux->stream); |
274 if(c<0) break; //EOF | |
275 head<<=8; | |
276 if(head!=0x100){ | |
277 head|=c; | |
278 ++skipped; //++demux->filepos; | |
279 continue; | |
280 } | |
281 head|=c; | |
282 break; | |
547 | 283 } |
284 demux->filepos+=skipped; | |
1 | 285 } |
286 if(stream_eof(demux->stream)) break; | |
287 // sure: head=0x000001XX | |
1567 | 288 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"*** head=0x%X\n",head); |
1 | 289 if(demux->synced==0){ |
290 if(head==0x1BA) demux->synced=1; | |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
291 #if 0 |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
292 else if(head>=0x1C0 && head<=0x1EF){ |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
293 demux->synced=2; |
1567 | 294 mp_msg(MSGT_DEMUX,MSGL_V,"Mpeg PES stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos); |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
295 num_elementary_packets100=0; // requires for re-sync! |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
296 num_elementary_packets101=0; // requires for re-sync! |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
297 } |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
298 #endif |
1 | 299 } else |
300 if(demux->synced==1){ | |
929 | 301 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){ |
1 | 302 demux->synced=2; |
1567 | 303 mp_msg(MSGT_DEMUX,MSGL_V,"system stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos); |
536 | 304 num_elementary_packets100=0; // requires for re-sync! |
305 num_elementary_packets101=0; // requires for re-sync! | |
1 | 306 } else demux->synced=0; |
307 } // else | |
308 if(demux->synced==2){ | |
309 ret=demux_mpg_read_packet(demux,head); | |
310 if(!ret) | |
311 if(--max_packs==0){ | |
312 demux->stream->eof=1; | |
1567 | 313 mp_msg(MSGT_DEMUX,MSGL_ERR,"demux: file doesn't contain the selected audio or video stream\n"); |
1 | 314 return 0; |
315 } | |
316 } else { | |
317 if(head>=0x100 && head<0x1B0){ | |
1162 | 318 if(head==0x100) ++num_elementary_packets100; else |
319 if(head==0x101) ++num_elementary_packets101; | |
1567 | 320 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head); |
1162 | 321 } else |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
322 if(head>=0x1C0 && head<0x1F0){ |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
323 ++num_elementary_packetsPES; |
1567 | 324 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... PES packet found: %03X\n",head); |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
325 } else |
1162 | 326 if(head==0x1B6) ++num_elementary_packets1B6; |
1 | 327 #if 1 |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
328 if( ( (num_elementary_packets100>50 && num_elementary_packets101>50) || |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
329 (num_elementary_packetsPES>50) ) && skipped>4000000){ |
1567 | 330 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be ES/PES stream...\n"); |
1 | 331 demux->stream->eof=1; |
332 break; | |
333 } | |
334 #endif | |
335 } | |
336 } while(ret!=1); | |
1567 | 337 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"demux: %d bad bytes skipped\n",skipped); |
1 | 338 if(demux->stream->eof){ |
1567 | 339 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG Stream reached EOF\n"); |
1 | 340 return 0; |
341 } | |
342 return 1; | |
343 } | |
344 | |
1497
ad4d402b3d29
seek.c moved to demuxer.c, stream_reset in new_demuxer()
arpi
parents:
1466
diff
changeset
|
345 //extern off_t seek_to_byte; |
1466 | 346 |
347 void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,int flags){ | |
348 demux_stream_t *d_audio=demuxer->audio; | |
349 demux_stream_t *d_video=demuxer->video; | |
350 sh_audio_t *sh_audio=d_audio->sh; | |
351 sh_video_t *sh_video=d_video->sh; | |
352 | |
353 //================= seek in MPEG ========================== | |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
354 off_t newpos=(flags&1)?demuxer->movi_start:demuxer->filepos; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
355 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
356 if(flags&2){ |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
357 // float seek 0..1 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
358 newpos+=(demuxer->movi_end-demuxer->movi_start)*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
359 } else { |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
360 // time seek (secs) |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
361 if(!sh_video->i_bps) // unspecified or VBR |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
362 newpos+=2324*75*rel_seek_secs; // 174.3 kbyte/sec |
1466 | 363 else |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
364 newpos+=sh_video->i_bps*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
365 } |
1466 | 366 |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
367 if(newpos<demuxer->movi_start) newpos=demuxer->movi_start; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
368 |
1466 | 369 #ifdef _LARGEFILE_SOURCE |
370 newpos&=~((long long)STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
371 #else | |
372 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
373 #endif | |
374 stream_seek(demuxer->stream,newpos); | |
375 | |
376 // re-sync video: | |
377 videobuf_code_len=0; // reset ES stream buffer | |
378 | |
379 ds_fill_buffer(d_video); | |
380 if(sh_audio){ | |
381 ds_fill_buffer(d_audio); | |
382 resync_audio_stream(sh_audio); | |
383 } | |
384 | |
385 while(1){ | |
386 int i; | |
387 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts){ | |
388 float a_pts=d_audio->pts; | |
389 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
390 if(d_video->pts>a_pts){ | |
391 skip_audio_frame(sh_audio); // sync audio | |
392 continue; | |
393 } | |
394 } | |
395 i=sync_video_packet(d_video); | |
396 if(i==0x1B3 || i==0x1B8) break; // found it! | |
397 if(!i || !skip_video_packet(d_video)) break; // EOF? | |
398 } | |
399 | |
400 | |
401 } | |
402 |