Mercurial > mplayer.hg
annotate libmpdemux/stream.c @ 6830:032137fe69a5
Transform Vobsub subtitles into Subrip text subtitles using GOCR/JOCR.
author | kmkaplan |
---|---|
date | Sun, 28 Jul 2002 16:30:52 +0000 |
parents | 6863033786d1 |
children | b8e0b1c54940 |
rev | line source |
---|---|
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
1 |
1430 | 2 #include <stdio.h> |
3 #include <stdlib.h> | |
4 #include <unistd.h> | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
5 |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
6 #include <sys/types.h> |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
7 #include <sys/stat.h> |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
8 #include <sys/ioctl.h> |
6814 | 9 #include <sys/wait.h> |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
10 #include <fcntl.h> |
2322 | 11 #include <signal.h> |
578 | 12 |
1430 | 13 #include "config.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
14 #include "mp_msg.h" |
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
15 #include "help_mp.h" |
6814 | 16 #include "../linux/shmem.h" |
578 | 17 |
18 #include "stream.h" | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
19 #include "demuxer.h" |
578 | 20 |
21 extern int verbose; // defined in mplayer.c | |
1 | 22 |
3261 | 23 #ifdef HAVE_VCD |
24 | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
25 #ifdef __FreeBSD__ |
2310 | 26 #include "vcd_read_fbsd.h" |
5872 | 27 #elif defined(__NetBSD__) |
28 #include "vcd_read_nbsd.h" | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
29 #else |
2310 | 30 #include "vcd_read.h" |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
31 #endif |
1 | 32 |
3261 | 33 #endif |
34 | |
1595 | 35 #ifdef USE_DVDREAD |
36 int dvd_read_sector(void* d,void* p2); | |
37 void dvd_seek(void* d,off_t pos); | |
6814 | 38 void dvd_close(dvd_priv_t *d); |
1595 | 39 #endif |
40 | |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
41 #ifdef HAVE_CDDA |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
42 int read_cdda(stream_t* s); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
43 void seek_cdda(stream_t* s); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
44 void close_cdda(stream_t* s); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
45 #endif |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
46 |
1 | 47 //=================== STREAMER ========================= |
48 | |
49 int stream_fill_buffer(stream_t *s){ | |
50 int len; | |
51 if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } | |
52 switch(s->type){ | |
53 case STREAMTYPE_FILE: | |
692 | 54 case STREAMTYPE_STREAM: |
4042
d651a7b5d213
STREAMTYPE_PLAYLIST introduced. similar to STREAMTYPE_STREAM but used for playlists. patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3291
diff
changeset
|
55 case STREAMTYPE_PLAYLIST: |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
56 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
57 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
58 len=s->streaming_ctrl->streaming_read(s->fd,s->buffer,STREAM_BUFFER_SIZE, s->streaming_ctrl);break; |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
59 } else { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
60 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
61 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
62 #else |
1 | 63 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
64 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
65 #ifdef HAVE_CDDA |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
66 case STREAMTYPE_CDDA: |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
67 len = read_cdda(s); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
68 break; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
69 #endif |
3261 | 70 #ifdef HAVE_VCD |
1 | 71 case STREAMTYPE_VCD: |
72 #ifdef VCD_CACHE | |
73 len=vcd_cache_read(s->fd,s->buffer);break; | |
74 #else | |
75 len=vcd_read(s->fd,s->buffer);break; | |
76 #endif | |
3261 | 77 #endif |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
78 #ifdef USE_DVDNAV |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
79 case STREAMTYPE_DVDNAV: { |
5472 | 80 dvdnav_stream_read((dvdnav_priv_t*)s->priv,s->buffer,&len); |
81 if (len==0) return 0; // this was an event, so repeat the read | |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
82 break; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
83 } |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
84 #endif |
1595 | 85 #ifdef USE_DVDREAD |
86 case STREAMTYPE_DVD: { | |
87 off_t pos=dvd_read_sector(s->priv,s->buffer); | |
88 if(pos>=0){ | |
89 len=2048; // full sector | |
90 s->pos=2048*pos-len; | |
91 } else len=-1; // error | |
92 break; | |
93 } | |
94 #endif | |
2790 | 95 #ifdef USE_TV |
96 case STREAMTYPE_TV: | |
97 { | |
98 len = 0; | |
99 break; | |
100 } | |
101 #endif | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
102 case STREAMTYPE_DS: |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
103 len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
104 break; |
1 | 105 default: len=0; |
106 } | |
107 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
108 s->buf_pos=0; | |
109 s->buf_len=len; | |
110 s->pos+=len; | |
111 // printf("[%d]",len);fflush(stdout); | |
112 return len; | |
113 } | |
114 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
115 int stream_seek_long(stream_t *s,off_t pos){ |
6814 | 116 off_t newpos=0; |
1 | 117 |
2144 | 118 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 119 |
120 s->buf_pos=s->buf_len=0; | |
121 | |
122 switch(s->type){ | |
123 case STREAMTYPE_FILE: | |
692 | 124 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
125 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
126 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
127 #else |
492 | 128 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
129 #endif |
1 | 130 case STREAMTYPE_VCD: |
131 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
1595 | 132 case STREAMTYPE_DVD: |
133 newpos=pos/2048; newpos*=2048; break; | |
1 | 134 } |
135 | |
2050 | 136 if(verbose>=3){ |
137 #ifdef _LARGEFILE_SOURCE | |
138 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
139 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
140 #else | |
141 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
142 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
143 #endif | |
144 } | |
145 | |
1 | 146 pos-=newpos; |
147 | |
148 if(newpos==0 || newpos!=s->pos){ | |
149 switch(s->type){ | |
150 case STREAMTYPE_FILE: | |
692 | 151 s->pos=newpos; // real seek |
1 | 152 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
153 break; | |
3261 | 154 #ifdef HAVE_VCD |
1 | 155 case STREAMTYPE_VCD: |
692 | 156 s->pos=newpos; // real seek |
1 | 157 #ifdef VCD_CACHE |
158 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
159 #else | |
160 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
161 #endif | |
162 break; | |
3261 | 163 #endif |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
164 #ifdef HAVE_CDDA |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
165 case STREAMTYPE_CDDA: { |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
166 s->pos=newpos; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
167 seek_cdda(s); |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
168 break; |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
169 } |
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
170 #endif |
5472 | 171 #ifdef USE_DVDNAV |
172 case STREAMTYPE_DVDNAV: { | |
173 if (newpos==0) { | |
174 if (dvdnav_stream_reset((dvdnav_priv_t*)s->priv)) | |
175 s->pos=0; | |
176 } | |
177 if(newpos!=s->pos){ | |
178 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek in DVDNAV streams yet!\n"); | |
179 return 1; | |
180 } | |
181 break; | |
182 } | |
183 #endif | |
1595 | 184 #ifdef USE_DVDREAD |
185 case STREAMTYPE_DVD: | |
186 s->pos=newpos; // real seek | |
187 dvd_seek(s->priv,s->pos/2048); | |
188 break; | |
189 #endif | |
692 | 190 case STREAMTYPE_STREAM: |
191 //s->pos=newpos; // real seek | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
192 // Some streaming protocol allow to seek backward and forward |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
193 // A function call that return -1 can tell that the protocol |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
194 // doesn't support seeking. |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
195 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
196 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
197 if( s->streaming_ctrl->streaming_seek( s->fd, pos, s->streaming_ctrl )<0 ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
198 mp_msg(MSGT_STREAM,MSGL_INFO,"Stream not seekable!\n"); |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
199 return 1; |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
200 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
201 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
202 #else |
692 | 203 if(newpos<s->pos){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
204 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); |
692 | 205 return 1; |
206 } | |
207 while(s->pos<newpos){ | |
208 if(stream_fill_buffer(s)<=0) break; // EOF | |
209 } | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
210 #endif |
692 | 211 break; |
2790 | 212 #ifdef USE_TV |
213 case STREAMTYPE_TV: | |
214 s->pos=newpos; /* no sense */ | |
215 break; | |
216 #endif | |
1 | 217 } |
218 // putchar('.');fflush(stdout); | |
219 //} else { | |
220 // putchar('%');fflush(stdout); | |
221 } | |
222 | |
223 stream_fill_buffer(s); | |
1999 | 224 if(pos>=0 && pos<=s->buf_len){ |
1 | 225 s->buf_pos=pos; // byte position in sector |
226 return 1; | |
227 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
228 |
1999 | 229 // if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n"); |
230 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
231 #ifdef _LARGEFILE_SOURCE |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
232 mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%llX !\n",(long long)(pos+newpos)); |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
233 #else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
234 mp_msg(MSGT_STREAM,MSGL_V,"stream_seek: WARNING! Can't seek to 0x%X !\n",(pos+newpos)); |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
235 #endif |
1 | 236 return 0; |
237 } | |
238 | |
239 | |
240 void stream_reset(stream_t *s){ | |
241 if(s->eof){ | |
242 s->pos=0; //ftell(f); | |
243 // s->buf_pos=s->buf_len=0; | |
244 s->eof=0; | |
245 } | |
246 //stream_seek(s,0); | |
247 } | |
248 | |
2144 | 249 stream_t* new_memory_stream(unsigned char* data,int len){ |
250 stream_t *s=malloc(sizeof(stream_t)+len); | |
251 s->fd=-1; | |
252 s->type=STREAMTYPE_MEMORY; | |
253 s->buf_pos=0; s->buf_len=len; | |
254 s->start_pos=0; s->end_pos=len; | |
255 stream_reset(s); | |
256 s->pos=len; | |
257 memcpy(s->buffer,data,len); | |
258 return s; | |
259 } | |
260 | |
1 | 261 stream_t* new_stream(int fd,int type){ |
262 stream_t *s=malloc(sizeof(stream_t)); | |
3291 | 263 if(s==NULL) return NULL; |
264 memset(s,0,sizeof(stream_t)); | |
265 | |
1 | 266 s->fd=fd; |
267 s->type=type; | |
180 | 268 s->buf_pos=s->buf_len=0; |
598 | 269 s->start_pos=s->end_pos=0; |
1642 | 270 s->priv=NULL; |
2322 | 271 s->cache_pid=0; |
1 | 272 stream_reset(s); |
273 return s; | |
274 } | |
275 | |
276 void free_stream(stream_t *s){ | |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
5982
diff
changeset
|
277 // printf("\n*** free_stream() called ***\n"); |
4893 | 278 if(s->cache_pid) { |
5982 | 279 // kill(s->cache_pid,SIGTERM); |
280 kill(s->cache_pid,SIGKILL); | |
4893 | 281 waitpid(s->cache_pid,NULL,0); |
6810 | 282 shmem_free(s->cache_data); |
4893 | 283 } |
6300
c31d15532695
file descriptor leak - found by Marc Espie <espie@nerim.net>
arpi
parents:
6138
diff
changeset
|
284 if(s->fd>0) close(s->fd); |
6479 | 285 switch(s->type) { |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
286 #ifdef HAVE_CDDA |
6479 | 287 case STREAMTYPE_CDDA: |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
288 close_cdda(s); |
6479 | 289 break; |
6384
f0b933918a22
Support for playing audio cds using cdparanoia. Include a raw audio
albeu
parents:
6300
diff
changeset
|
290 #endif |
6479 | 291 #ifdef USE_DVDREAD |
292 case STREAMTYPE_DVD: | |
293 dvd_close(s->priv); | |
294 #endif | |
295 } | |
1642 | 296 if(s->priv) free(s->priv); |
1 | 297 free(s); |
298 } | |
299 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
300 stream_t* new_ds_stream(demux_stream_t *ds) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
301 stream_t* s = new_stream(-1,STREAMTYPE_DS); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
302 s->priv = ds; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
303 return s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
304 } |