Mercurial > mplayer.hg
annotate libmpdemux/demux_mpg.c @ 10080:312eb2923169
Made the decoder honor the aspect ratio set by the container (if it was set at all).
author | mosu |
---|---|
date | Tue, 06 May 2003 15:28:01 +0000 |
parents | 39b68c2664ec |
children | bbf3898360e7 |
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" | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
9 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
10 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
11 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
12 #include "demuxer.h" |
1466 | 13 #include "parse_es.h" |
2338 | 14 #include "stheader.h" |
4711 | 15 #include "mp3_hdr.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
16 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2338
diff
changeset
|
17 #include "dvdauth.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2338
diff
changeset
|
18 |
524
9105fc95636c
A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents:
501
diff
changeset
|
19 //#define MAX_PS_PACKETSIZE 2048 |
501 | 20 #define MAX_PS_PACKETSIZE (224*1024) |
21 | |
547 | 22 static int mpeg_pts_error=0; |
23 | |
1 | 24 static unsigned int read_mpeg_timestamp(stream_t *s,int c){ |
25 int d,e; | |
26 unsigned int pts; | |
27 d=stream_read_word(s); | |
28 e=stream_read_word(s); | |
547 | 29 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){ |
30 ++mpeg_pts_error; | |
31 return 0; // invalid pts | |
32 } | |
1 | 33 pts=(((c>>1)&7)<<30)|((d>>1)<<15)|(e>>1); |
1567 | 34 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"{%d}",pts); |
1 | 35 return pts; |
36 } | |
37 | |
38 static int demux_mpg_read_packet(demuxer_t *demux,int id){ | |
39 int d; | |
40 int len; | |
492 | 41 #ifdef HAVE_LIBCSS |
42 int css=0; | |
43 #endif | |
1 | 44 unsigned char c=0; |
45 unsigned int pts=0; | |
46 unsigned int dts=0; | |
47 demux_stream_t *ds=NULL; | |
48 | |
1567 | 49 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_read_packet: %X\n",id); |
1 | 50 |
536 | 51 // if(id==0x1F0){ |
52 // demux->synced=0; // force resync after 0x1F0 | |
53 // return -1; | |
54 //} | |
501 | 55 |
1 | 56 // if(id==0x1BA) packet_start_pos=stream_tell(demux->stream); |
501 | 57 if(id<0x1BC || id>=0x1F0) return -1; |
1 | 58 if(id==0x1BE) return -1; // padding stream |
59 if(id==0x1BF) return -1; // private2 | |
60 | |
61 len=stream_read_word(demux->stream); | |
1567 | 62 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"PACKET len=%d",len); |
536 | 63 // if(len==62480){ demux->synced=0;return -1;} /* :) */ |
501 | 64 if(len==0 || len>MAX_PS_PACKETSIZE){ |
1567 | 65 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS packet len: %d\n",len); |
501 | 66 return -2; // invalid packet !!!!!! |
67 } | |
1 | 68 |
547 | 69 mpeg_pts_error=0; |
70 | |
1 | 71 while(len>0){ // Skip stuFFing bytes |
72 c=stream_read_char(demux->stream);--len; | |
73 if(c!=0xFF)break; | |
74 } | |
75 if((c>>6)==1){ // Read (skip) STD scale & size value | |
76 // printf(" STD_scale=%d",(c>>5)&1); | |
77 d=((c&0x1F)<<8)|stream_read_char(demux->stream); | |
78 len-=2; | |
79 // printf(" STD_size=%d",d); | |
80 c=stream_read_char(demux->stream); | |
81 } | |
82 // Read System-1 stream timestamps: | |
83 if((c>>4)==2){ | |
84 pts=read_mpeg_timestamp(demux->stream,c); | |
85 len-=4; | |
86 } else | |
87 if((c>>4)==3){ | |
88 pts=read_mpeg_timestamp(demux->stream,c); | |
89 c=stream_read_char(demux->stream); | |
90 if((c>>4)!=1) pts=0; //printf("{ERROR4}"); | |
91 dts=read_mpeg_timestamp(demux->stream,c); | |
92 len-=4+1+4; | |
93 } else | |
94 if((c>>6)==2){ | |
95 int pts_flags; | |
96 int hdrlen; | |
97 // System-2 (.VOB) stream: | |
492 | 98 if((c>>4)&3) { |
99 #ifdef HAVE_LIBCSS | |
100 css=1; | |
101 #else | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
102 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_EncryptedVOB); |
492 | 103 #endif |
104 } | |
1 | 105 c=stream_read_char(demux->stream); pts_flags=c>>6; |
106 c=stream_read_char(demux->stream); hdrlen=c; | |
107 len-=2; | |
1567 | 108 mp_dbg(MSGT_DEMUX,MSGL_DBG3," hdrlen=%d (len=%d)",hdrlen,len); |
109 if(hdrlen>len){ mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid header length \n"); return -1;} | |
7671 | 110 if(pts_flags==2 && hdrlen>=5){ |
1 | 111 c=stream_read_char(demux->stream); |
112 pts=read_mpeg_timestamp(demux->stream,c); | |
113 len-=5;hdrlen-=5; | |
114 } else | |
7671 | 115 if(pts_flags==3 && hdrlen>=10){ |
1 | 116 c=stream_read_char(demux->stream); |
117 pts=read_mpeg_timestamp(demux->stream,c); | |
118 c=stream_read_char(demux->stream); | |
119 dts=read_mpeg_timestamp(demux->stream,c); | |
120 len-=10;hdrlen-=10; | |
121 } | |
122 len-=hdrlen; | |
123 if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes | |
124 | |
125 //============== DVD Audio sub-stream ====================== | |
126 if(id==0x1BD){ | |
552 | 127 int aid=stream_read_char(demux->stream);--len; |
1 | 128 if(len<3) return -1; // invalid audio packet |
552 | 129 |
130 // AID: | |
131 // 0x20..0x3F subtitle | |
132 // 0x80..0x9F AC3 audio | |
133 // 0xA0..0xBF PCM audio | |
134 | |
135 if((aid & 0xE0) == 0x20){ | |
136 // subtitle: | |
137 aid&=0x1F; | |
426 | 138 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
139 if(!demux->s_streams[aid]){ |
1567 | 140 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
|
141 demux->s_streams[aid]=1; |
552 | 142 } |
143 | |
144 if(demux->sub->id==aid){ | |
145 ds=demux->sub; | |
146 } | |
147 | |
3955 | 148 } else if((aid & 0xC0) == 0x80 || (aid & 0xE0) == 0x00) { |
552 | 149 |
150 // aid=128+(aid&0x7F); | |
151 // aid=0x80..0xBF | |
152 | |
1289 | 153 if(!demux->a_streams[aid]) new_sh_audio(demux,aid); |
552 | 154 if(demux->audio->id==-1) demux->audio->id=aid; |
426 | 155 |
156 if(demux->audio->id==aid){ | |
7671 | 157 int type; |
426 | 158 ds=demux->audio; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
159 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 160 // READ Packet: Skip additional audio header data: |
7671 | 161 c=stream_read_char(demux->stream);//num of frames |
162 type=stream_read_char(demux->stream);//startpos hi | |
163 type=(type<<8)|stream_read_char(demux->stream);//startpos lo | |
164 // printf("\r[%02X][%04X]",c,type); | |
1 | 165 len-=3; |
7671 | 166 if((aid&0xE0)==0xA0 && len>=3){ |
167 unsigned char* hdr; | |
168 // save audio header as codecdata! | |
169 if(!((sh_audio_t*)(ds->sh))->codecdata_len){ | |
170 ((sh_audio_t*)(ds->sh))->codecdata=malloc(3); | |
171 ((sh_audio_t*)(ds->sh))->codecdata_len=3; | |
172 } | |
173 hdr=((sh_audio_t*)(ds->sh))->codecdata; | |
174 // read LPCM header: | |
175 // emphasis[1], mute[1], rvd[1], frame number[5]: | |
176 hdr[0]=stream_read_char(demux->stream); | |
177 // printf(" [%01X:%02d]",c>>5,c&31); | |
178 // quantization[2],freq[2],rvd[1],channels[3] | |
179 hdr[1]=stream_read_char(demux->stream); | |
180 // printf("[%01X:%01X] ",c>>4,c&15); | |
181 // dynamic range control (0x80=off): | |
182 hdr[2]=stream_read_char(demux->stream); | |
183 // printf("[%02X] ",c); | |
184 len-=3; | |
185 if(len<=0) mp_msg(MSGT_DEMUX,MSGL_V,"End of packet while searching for PCM header\n"); | |
1 | 186 } |
7671 | 187 // printf(" \n"); |
552 | 188 } // if(demux->audio->id==aid) |
189 | |
1567 | 190 } else mp_msg(MSGT_DEMUX,MSGL_V,"Unknown 0x1BD substream: 0x%02X \n",aid); |
552 | 191 |
192 } //if(id==0x1BD) | |
1 | 193 |
194 } else { | |
539 | 195 if(c!=0x0f){ |
1567 | 196 mp_msg(MSGT_DEMUX,MSGL_V," {ERROR5,c=%d} \n",c); |
539 | 197 return -1; // invalid packet !!!!!! |
198 } | |
1 | 199 } |
1567 | 200 if(mpeg_pts_error) mp_msg(MSGT_DEMUX,MSGL_V," {PTS_err:%d} \n",mpeg_pts_error); |
201 mp_dbg(MSGT_DEMUX,MSGL_DBG3," => len=%d\n",len); | |
1 | 202 |
501 | 203 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size |
204 if(len<=0 || len>MAX_PS_PACKETSIZE){ | |
1567 | 205 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS data len: %d\n",len); |
501 | 206 return -1; // invalid packet !!!!!! |
207 } | |
1 | 208 |
209 if(id>=0x1C0 && id<=0x1DF){ | |
210 // mpeg audio | |
211 int aid=id-0x1C0; | |
1289 | 212 if(!demux->a_streams[aid]) new_sh_audio(demux,aid); |
1 | 213 if(demux->audio->id==-1) demux->audio->id=aid; |
214 if(demux->audio->id==aid){ | |
215 ds=demux->audio; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
216 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 217 } |
218 } else | |
219 if(id>=0x1E0 && id<=0x1EF){ | |
220 // mpeg video | |
221 int aid=id-0x1E0; | |
1289 | 222 if(!demux->v_streams[aid]) new_sh_video(demux,aid); |
1 | 223 if(demux->video->id==-1) demux->video->id=aid; |
426 | 224 if(demux->video->id==aid){ |
225 ds=demux->video; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
226 if(!ds->sh) ds->sh=demux->v_streams[aid]; |
426 | 227 } |
1 | 228 } |
229 | |
230 if(ds){ | |
1567 | 231 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); |
1 | 232 // printf("packet start = 0x%X \n",stream_tell(demux->stream)-packet_start_pos); |
492 | 233 #ifdef HAVE_LIBCSS |
546 | 234 if (css) { |
3975
04b2227ab75a
Return of the 'Old-style-DVD-support', with dynamic loading (using libdl) so
lgb
parents:
3955
diff
changeset
|
235 if (descrambling) dvd_css_descramble(demux->stream->buffer,key_title); else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
236 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_EncryptedVOBauth); |
546 | 237 } |
492 | 238 #endif |
1735 | 239 ds_read_packet(ds,demux->stream,len,pts/90000.0f,demux->filepos,0); |
554 | 240 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len); |
1 | 241 return 1; |
242 } | |
1567 | 243 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id); |
536 | 244 if(len<=2356) stream_skip(demux->stream,len); |
1 | 245 return 0; |
246 } | |
247 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
248 int num_elementary_packets100=0; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
249 int num_elementary_packets101=0; |
9069
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
250 int num_elementary_packets12x=0; |
1162 | 251 int num_elementary_packets1B6=0; |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
252 int num_elementary_packetsPES=0; |
9824 | 253 int num_h264_slice=0; //combined slice |
254 int num_h264_dpa=0; //DPA Slice | |
255 int num_h264_dpb=0; //DPB Slice | |
256 int num_h264_dpc=0; //DPC Slice | |
257 int num_h264_idr=0; //IDR Slice | |
258 int num_h264_sps=0; | |
259 int num_h264_pps=0; | |
260 | |
4711 | 261 int num_mp3audio_packets=0; |
1 | 262 |
263 int demux_mpg_es_fill_buffer(demuxer_t *demux){ | |
264 // Elementary video stream | |
265 if(demux->stream->eof) return 0; | |
266 demux->filepos=stream_tell(demux->stream); | |
1735 | 267 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,demux->filepos,0); |
1 | 268 return 1; |
269 } | |
270 | |
271 int demux_mpg_fill_buffer(demuxer_t *demux){ | |
272 unsigned int head=0; | |
273 int skipped=0; | |
5570
3a8d8c51355a
max_packs increased for some dvd with too many audio/sub
arpi
parents:
4711
diff
changeset
|
274 int max_packs=256; // 512kbyte |
1 | 275 int ret=0; |
276 | |
277 // System stream | |
278 do{ | |
279 demux->filepos=stream_tell(demux->stream); | |
280 head=stream_read_dword(demux->stream); | |
547 | 281 if((head&0xFFFFFF00)!=0x100){ |
282 // sync... | |
283 demux->filepos-=skipped; | |
284 while(1){ | |
536 | 285 int c=stream_read_char(demux->stream); |
286 if(c<0) break; //EOF | |
287 head<<=8; | |
288 if(head!=0x100){ | |
289 head|=c; | |
4711 | 290 if(mp_check_mp3_header(head)) ++num_mp3audio_packets; |
536 | 291 ++skipped; //++demux->filepos; |
292 continue; | |
293 } | |
294 head|=c; | |
295 break; | |
547 | 296 } |
297 demux->filepos+=skipped; | |
1 | 298 } |
299 if(stream_eof(demux->stream)) break; | |
300 // sure: head=0x000001XX | |
1567 | 301 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"*** head=0x%X\n",head); |
1 | 302 if(demux->synced==0){ |
3770 | 303 if(head==0x1BA) demux->synced=1; //else |
304 // if(head==0x1BD || (head>=0x1C0 && head<=0x1EF)) demux->synced=3; // PES? | |
1 | 305 } else |
306 if(demux->synced==1){ | |
929 | 307 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){ |
1 | 308 demux->synced=2; |
1567 | 309 mp_msg(MSGT_DEMUX,MSGL_V,"system stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos); |
536 | 310 num_elementary_packets100=0; // requires for re-sync! |
311 num_elementary_packets101=0; // requires for re-sync! | |
1 | 312 } else demux->synced=0; |
313 } // else | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
314 if(demux->synced>=2){ |
1 | 315 ret=demux_mpg_read_packet(demux,head); |
316 if(!ret) | |
317 if(--max_packs==0){ | |
318 demux->stream->eof=1; | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
319 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream); |
1 | 320 return 0; |
321 } | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
322 if(demux->synced==3) demux->synced=(ret==1)?2:0; // PES detect |
1 | 323 } else { |
324 if(head>=0x100 && head<0x1B0){ | |
1162 | 325 if(head==0x100) ++num_elementary_packets100; else |
9069
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
326 if(head==0x101) ++num_elementary_packets101; else |
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
327 if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x; |
9824 | 328 |
329 if((head&~0x60) == 0x101) ++num_h264_slice; else | |
330 if((head&~0x60) == 0x102) ++num_h264_dpa; else | |
331 if((head&~0x60) == 0x103) ++num_h264_dpb; else | |
332 if((head&~0x60) == 0x104) ++num_h264_dpc; else | |
333 if((head&~0x60) == 0x105 && head != 0x105) ++num_h264_idr; else | |
334 if((head&~0x60) == 0x107 && head != 0x107) ++num_h264_sps; else | |
335 if((head&~0x60) == 0x108 && head != 0x108) ++num_h264_pps; | |
336 | |
1567 | 337 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head); |
1162 | 338 } else |
4711 | 339 if((head>=0x1C0 && head<0x1F0) || head==0x1BD){ |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
340 ++num_elementary_packetsPES; |
1567 | 341 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
|
342 } else |
1162 | 343 if(head==0x1B6) ++num_elementary_packets1B6; |
1 | 344 #if 1 |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
345 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
|
346 (num_elementary_packetsPES>50) ) && skipped>4000000){ |
1567 | 347 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be ES/PES stream...\n"); |
1 | 348 demux->stream->eof=1; |
349 break; | |
350 } | |
4711 | 351 if(num_mp3audio_packets>100 && num_elementary_packets100<10){ |
352 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be MP3 stream...\n"); | |
353 demux->stream->eof=1; | |
354 break; | |
355 } | |
1 | 356 #endif |
357 } | |
358 } while(ret!=1); | |
1567 | 359 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"demux: %d bad bytes skipped\n",skipped); |
1 | 360 if(demux->stream->eof){ |
1567 | 361 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG Stream reached EOF\n"); |
1 | 362 return 0; |
363 } | |
364 return 1; | |
365 } | |
366 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
367 extern void resync_audio_stream(sh_audio_t *sh_audio); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
368 extern void skip_audio_frame(sh_audio_t *sh_audio); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
369 |
1466 | 370 void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
371 demux_stream_t *d_audio=demuxer->audio; | |
372 demux_stream_t *d_video=demuxer->video; | |
373 sh_audio_t *sh_audio=d_audio->sh; | |
374 sh_video_t *sh_video=d_video->sh; | |
375 | |
376 //================= seek in MPEG ========================== | |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
377 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
|
378 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
379 if(flags&2){ |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
380 // float seek 0..1 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
381 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
|
382 } else { |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
383 // time seek (secs) |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
384 if(!sh_video->i_bps) // unspecified or VBR |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
385 newpos+=2324*75*rel_seek_secs; // 174.3 kbyte/sec |
1466 | 386 else |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
387 newpos+=sh_video->i_bps*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
388 } |
1466 | 389 |
4391
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
390 if(newpos<demuxer->movi_start){ |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
391 if(demuxer->stream->type!=STREAMTYPE_VCD) demuxer->movi_start=0; // for VCD |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
392 if(newpos<demuxer->movi_start) newpos=demuxer->movi_start; |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
393 } |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
394 |
1466 | 395 #ifdef _LARGEFILE_SOURCE |
396 newpos&=~((long long)STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
397 #else | |
398 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
399 #endif | |
400 stream_seek(demuxer->stream,newpos); | |
401 | |
402 // re-sync video: | |
403 videobuf_code_len=0; // reset ES stream buffer | |
404 | |
405 ds_fill_buffer(d_video); | |
406 if(sh_audio){ | |
407 ds_fill_buffer(d_audio); | |
408 resync_audio_stream(sh_audio); | |
409 } | |
410 | |
411 while(1){ | |
412 int i; | |
413 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts){ | |
414 float a_pts=d_audio->pts; | |
415 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
416 if(d_video->pts>a_pts){ | |
417 skip_audio_frame(sh_audio); // sync audio | |
418 continue; | |
419 } | |
420 } | |
421 i=sync_video_packet(d_video); | |
422 if(i==0x1B3 || i==0x1B8) break; // found it! | |
423 if(!i || !skip_video_packet(d_video)) break; // EOF? | |
424 } | |
425 } | |
426 | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
427 int demux_mpg_control(demuxer_t *demuxer,int cmd, void *arg){ |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
8208
diff
changeset
|
428 /* demux_stream_t *d_audio=demuxer->audio;*/ |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
429 demux_stream_t *d_video=demuxer->video; |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
8208
diff
changeset
|
430 /* sh_audio_t *sh_audio=d_audio->sh;*/ |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
431 sh_video_t *sh_video=d_video->sh; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
432 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
433 switch(cmd) { |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
434 case DEMUXER_CTRL_GET_TIME_LENGTH: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
435 if(!sh_video->i_bps) // unspecified or VBR |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
436 return DEMUXER_CTRL_DONTKNOW; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
437 *((unsigned long *)arg)=(demuxer->movi_end-demuxer->movi_start)/sh_video->i_bps; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
438 return DEMUXER_CTRL_GUESS; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
439 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
440 case DEMUXER_CTRL_GET_PERCENT_POS: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
441 if (demuxer->movi_end==demuxer->movi_start) |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
442 return DEMUXER_CTRL_DONTKNOW; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
443 *((int *)arg)=(int)((demuxer->filepos-demuxer->movi_start)/((demuxer->movi_end-demuxer->movi_start)/100)); |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
444 return DEMUXER_CTRL_OK; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
445 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
446 default: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
447 return DEMUXER_CTRL_NOTIMPL; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
448 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
449 } |