annotate libmpdemux/demux_mpg.c @ 11757:a9dd06d780b8

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