Mercurial > mplayer.hg
annotate libmpdemux/stream.c @ 9980:7bd7a1aa605f
darwin ldd support patch by Steven M. Schultz <sms@2BSD.COM>
author | alex |
---|---|
date | Thu, 24 Apr 2003 18:55:43 +0000 |
parents | eabe876ab5e2 |
children | d42177a0da2a |
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> |
9798 | 8 #ifndef __MINGW32__ |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
9 #include <sys/ioctl.h> |
6814 | 10 #include <sys/wait.h> |
9798 | 11 #endif |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
12 #include <fcntl.h> |
2322 | 13 #include <signal.h> |
9794 | 14 #include <strings.h> |
578 | 15 |
1430 | 16 #include "config.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
17 #include "mp_msg.h" |
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
18 #include "help_mp.h" |
9380 | 19 #include "../osdep/shmem.h" |
578 | 20 |
21 #include "stream.h" | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
22 #include "demuxer.h" |
578 | 23 |
9794 | 24 #include "../m_option.h" |
25 #include "../m_struct.h" | |
26 | |
27 | |
578 | 28 extern int verbose; // defined in mplayer.c |
1 | 29 |
8812 | 30 #include "cue_read.h" |
31 | |
32 //#include "vcd_read_bincue.h" | |
8782
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
33 |
1595 | 34 #ifdef USE_DVDREAD |
8344 | 35 int dvd_read_sector(dvd_priv_t *d,unsigned char* data); |
36 void dvd_seek(dvd_priv_t *d,int pos); | |
6814 | 37 void dvd_close(dvd_priv_t *d); |
1595 | 38 #endif |
39 | |
7630
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
40 #ifdef LIBSMBCLIENT |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
41 #include "libsmbclient.h" |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
42 #endif |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
43 |
9886 | 44 #ifdef HAVE_VCD |
45 extern stream_info_t stream_info_vcd; | |
46 #endif | |
9810 | 47 #ifdef HAVE_CDDA |
9801 | 48 extern stream_info_t stream_info_cdda; |
9810 | 49 #endif |
9853 | 50 #ifdef STREAMING |
51 extern stream_info_t stream_info_netstream; | |
52 #endif | |
9901
233802490b0e
Add a null streamv Currently used for tv and mf. Could be used to
albeu
parents:
9886
diff
changeset
|
53 extern stream_info_t stream_info_null; |
9794 | 54 extern stream_info_t stream_info_file; |
55 | |
56 stream_info_t* auto_open_streams[] = { | |
9886 | 57 #ifdef HAVE_VCD |
58 &stream_info_vcd, | |
59 #endif | |
9810 | 60 #ifdef HAVE_CDDA |
9801 | 61 &stream_info_cdda, |
9810 | 62 #endif |
9853 | 63 #ifdef STREAMING |
64 &stream_info_netstream, | |
65 #endif | |
9901
233802490b0e
Add a null streamv Currently used for tv and mf. Could be used to
albeu
parents:
9886
diff
changeset
|
66 &stream_info_null, |
9794 | 67 &stream_info_file, |
68 NULL | |
69 }; | |
70 | |
71 stream_t* open_stream_plugin(stream_info_t* sinfo,char* filename,int mode, | |
72 char** options, int* file_format, int* ret) { | |
73 void* arg = NULL; | |
74 stream_t* s; | |
75 m_struct_t* desc = (m_struct_t*)sinfo->opts; | |
76 | |
77 // Parse options | |
78 if(desc) { | |
79 arg = m_struct_alloc(desc); | |
80 if(sinfo->opts_url) { | |
81 m_option_t url_opt = | |
82 { "stream url", arg , CONF_TYPE_CUSTOM_URL, 0, 0 ,0, sinfo->opts }; | |
83 if(m_option_parse(&url_opt,"stream url",filename,arg,M_CONFIG_FILE) < 0) { | |
84 mp_msg(MSGT_OPEN,MSGL_ERR, "URL parsing failed on url %s\n",filename); | |
85 m_struct_free(desc,arg); | |
86 return NULL; | |
87 } | |
88 } | |
89 if(options) { | |
90 int i; | |
91 for(i = 0 ; options[i] != NULL ; i += 2) { | |
92 mp_msg(MSGT_OPEN,MSGL_DBG2, "Set stream arg %s=%s\n", | |
93 options[i],options[i+1]); | |
94 if(!m_struct_set(desc,arg,options[i],options[i+1])) | |
95 mp_msg(MSGT_OPEN,MSGL_WARN, "Failed to set stream option %s=%s\n", | |
96 options[i],options[i+1]); | |
97 } | |
98 } | |
99 } | |
100 s = new_stream(-2,-2); | |
101 s->url=strdup(filename); | |
102 s->flags |= mode; | |
103 *ret = sinfo->open(s,mode,arg,file_format); | |
104 if((*ret) != STREAM_OK) { | |
105 free(s->url); | |
106 free(s); | |
107 return NULL; | |
108 } | |
109 if(s->type <= -2) | |
110 mp_msg(MSGT_OPEN,MSGL_WARN, "Warning streams need a type !!!!\n"); | |
111 if(s->flags & STREAM_SEEK && !s->seek) | |
112 s->flags &= ~STREAM_SEEK; | |
113 if(s->seek && !(s->flags & STREAM_SEEK)) | |
9853 | 114 s->flags |= STREAM_SEEK; |
9794 | 115 |
116 | |
117 mp_msg(MSGT_OPEN,MSGL_V, "STREAM: [%s] %s\n",sinfo->name,filename); | |
118 mp_msg(MSGT_OPEN,MSGL_V, "STREAM: Description: %s\n",sinfo->info); | |
119 mp_msg(MSGT_OPEN,MSGL_V, "STREAM: Author: %s\n", sinfo->author); | |
120 mp_msg(MSGT_OPEN,MSGL_V, "STREAM: Comment: %s\n", sinfo->comment); | |
121 | |
122 return s; | |
123 } | |
124 | |
125 | |
126 stream_t* open_stream_full(char* filename,int mode, char** options, int* file_format) { | |
127 int i,j,l,r; | |
128 stream_info_t* sinfo; | |
129 stream_t* s; | |
130 | |
131 for(i = 0 ; auto_open_streams[i] ; i++) { | |
132 sinfo = auto_open_streams[i]; | |
133 if(!sinfo->protocols) { | |
134 mp_msg(MSGT_OPEN,MSGL_WARN, "Stream type %s have protocols == NULL, it's a bug\n"); | |
135 continue; | |
136 } | |
137 for(j = 0 ; sinfo->protocols[j] ; j++) { | |
138 l = strlen(sinfo->protocols[j]); | |
139 // l == 0 => Don't do protocol matching (ie network and filenames) | |
140 if((l == 0) || ((strncmp(sinfo->protocols[j],filename,l) == 0) && | |
141 (strncmp("://",filename+l,3) == 0))) { | |
142 *file_format = DEMUXER_TYPE_UNKNOWN; | |
143 s = open_stream_plugin(sinfo,filename,mode,options,file_format,&r); | |
144 if(s) return s; | |
145 if(r != STREAM_UNSUPORTED) { | |
146 mp_msg(MSGT_OPEN,MSGL_ERR, "Failed to open %s\n",filename); | |
147 return NULL; | |
148 } | |
149 break; | |
150 } | |
151 } | |
152 } | |
153 | |
154 mp_msg(MSGT_OPEN,MSGL_ERR, "No stream found to handle url %s\n",filename); | |
155 return NULL; | |
156 } | |
157 | |
1 | 158 //=================== STREAMER ========================= |
159 | |
160 int stream_fill_buffer(stream_t *s){ | |
161 int len; | |
9874
55a43ae66ceb
Oops, I just noticed albeu's revision 1.58 - so I backed out the
rsf
parents:
9873
diff
changeset
|
162 if (/*s->fd == NULL ||*/ s->eof) { s->buf_pos = s->buf_len = 0; return 0; } |
1 | 163 switch(s->type){ |
7630
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
164 #ifdef LIBSMBCLIENT |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
165 case STREAMTYPE_SMB: |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
166 len=smbc_read(s->fd,s->buffer,STREAM_BUFFER_SIZE); |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
167 break; |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
168 #endif |
692 | 169 case STREAMTYPE_STREAM: |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
170 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
171 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
172 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
|
173 } else { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
174 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
|
175 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
176 #else |
1 | 177 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
|
178 #endif |
8782
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
179 case STREAMTYPE_VCDBINCUE: |
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
180 len=cue_vcd_read(s->buffer);break; |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
181 #ifdef USE_DVDNAV |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
182 case STREAMTYPE_DVDNAV: { |
5472 | 183 dvdnav_stream_read((dvdnav_priv_t*)s->priv,s->buffer,&len); |
184 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
|
185 break; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
186 } |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
187 #endif |
1595 | 188 #ifdef USE_DVDREAD |
189 case STREAMTYPE_DVD: { | |
190 off_t pos=dvd_read_sector(s->priv,s->buffer); | |
191 if(pos>=0){ | |
192 len=2048; // full sector | |
193 s->pos=2048*pos-len; | |
194 } else len=-1; // error | |
195 break; | |
196 } | |
197 #endif | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
198 case STREAMTYPE_DS: |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
199 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
|
200 break; |
9610 | 201 |
202 #ifdef HAS_DVBIN_SUPPORT | |
203 case STREAMTYPE_DVB: | |
204 len = dvb_streaming_read(s->fd, s->buffer, STREAM_BUFFER_SIZE, s->priv); | |
205 break; | |
206 #endif | |
207 | |
208 | |
209 | |
9794 | 210 default: |
211 len= s->fill_buffer ? s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE) : 0; | |
1 | 212 } |
213 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
214 s->buf_pos=0; | |
215 s->buf_len=len; | |
216 s->pos+=len; | |
217 // printf("[%d]",len);fflush(stdout); | |
218 return len; | |
219 } | |
220 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
221 int stream_seek_long(stream_t *s,off_t pos){ |
6814 | 222 off_t newpos=0; |
1 | 223 |
2144 | 224 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 225 |
226 s->buf_pos=s->buf_len=0; | |
227 | |
228 switch(s->type){ | |
7630
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
229 case STREAMTYPE_SMB: |
692 | 230 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
231 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
232 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
233 #else |
492 | 234 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
235 #endif |
8782
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
236 case STREAMTYPE_VCDBINCUE: |
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
237 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; |
1595 | 238 case STREAMTYPE_DVD: |
239 newpos=pos/2048; newpos*=2048; break; | |
9794 | 240 default: |
241 // Round on sector size | |
242 if(s->sector_size) | |
243 newpos=(pos/s->sector_size)*s->sector_size; | |
244 else { // Otherwise on the buffer size | |
245 #ifdef _LARGEFILE_SOURCE | |
246 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; | |
247 #else | |
248 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; | |
249 #endif | |
250 } | |
251 break; | |
1 | 252 } |
253 | |
2050 | 254 if(verbose>=3){ |
255 #ifdef _LARGEFILE_SOURCE | |
256 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
257 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
258 #else | |
259 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
260 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
261 #endif | |
262 } | |
263 | |
1 | 264 pos-=newpos; |
265 | |
266 if(newpos==0 || newpos!=s->pos){ | |
267 switch(s->type){ | |
7630
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
268 #ifdef LIBSMBCLIENT |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
269 case STREAMTYPE_SMB: |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
270 s->pos=newpos; // real seek |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
271 if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
272 break; |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
273 #endif |
8782
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
274 case STREAMTYPE_VCDBINCUE: |
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
275 s->pos=newpos; // real seek |
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
276 cue_set_msf(s->pos/VCD_SECTOR_DATA); |
6af7a6595cc9
cdrwin-style bin/cue VCD image support (-vcd <track> -cuefile file.cue)
arpi
parents:
8524
diff
changeset
|
277 break; |
5472 | 278 #ifdef USE_DVDNAV |
279 case STREAMTYPE_DVDNAV: { | |
280 if (newpos==0) { | |
281 if (dvdnav_stream_reset((dvdnav_priv_t*)s->priv)) | |
282 s->pos=0; | |
283 } | |
284 if(newpos!=s->pos){ | |
285 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek in DVDNAV streams yet!\n"); | |
286 return 1; | |
287 } | |
288 break; | |
289 } | |
290 #endif | |
1595 | 291 #ifdef USE_DVDREAD |
292 case STREAMTYPE_DVD: | |
293 s->pos=newpos; // real seek | |
294 dvd_seek(s->priv,s->pos/2048); | |
295 break; | |
296 #endif | |
692 | 297 case STREAMTYPE_STREAM: |
298 //s->pos=newpos; // real seek | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
299 // 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
|
300 // 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
|
301 // doesn't support seeking. |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
302 #ifdef STREAMING |
8929
c5ca1ae42555
check if seeking supported, otherwise fallback to null reading
arpi
parents:
8812
diff
changeset
|
303 if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_seek ) { |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
304 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
|
305 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
|
306 return 1; |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
307 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
308 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
309 #else |
692 | 310 if(newpos<s->pos){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
311 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); |
692 | 312 return 1; |
313 } | |
314 while(s->pos<newpos){ | |
315 if(stream_fill_buffer(s)<=0) break; // EOF | |
316 } | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
317 #endif |
692 | 318 break; |
7408 | 319 default: |
9794 | 320 // This should at the beginning as soon as all streams are converted |
321 if(!s->seek) | |
322 return 0; | |
323 // Now seek | |
324 if(!s->seek(s,newpos)) { | |
325 mp_msg(MSGT_STREAM,MSGL_ERR, "Seek failed\n"); | |
326 return 0; | |
327 } | |
1 | 328 } |
329 // putchar('.');fflush(stdout); | |
330 //} else { | |
331 // putchar('%');fflush(stdout); | |
332 } | |
333 | |
334 stream_fill_buffer(s); | |
1999 | 335 if(pos>=0 && pos<=s->buf_len){ |
1 | 336 s->buf_pos=pos; // byte position in sector |
337 return 1; | |
338 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
339 |
1999 | 340 // if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n"); |
341 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
342 #ifdef _LARGEFILE_SOURCE |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
343 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
|
344 #else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
345 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
|
346 #endif |
1 | 347 return 0; |
348 } | |
349 | |
350 | |
351 void stream_reset(stream_t *s){ | |
352 if(s->eof){ | |
353 s->pos=0; //ftell(f); | |
354 // s->buf_pos=s->buf_len=0; | |
355 s->eof=0; | |
356 } | |
9853 | 357 if(s->control) s->control(s,STREAM_CTRL_RESET,NULL); |
1 | 358 //stream_seek(s,0); |
359 } | |
360 | |
2144 | 361 stream_t* new_memory_stream(unsigned char* data,int len){ |
362 stream_t *s=malloc(sizeof(stream_t)+len); | |
6892
b8e0b1c54940
10000l - didn't clear new stream struct, causing possible sig11 in cache layer
arpi
parents:
6814
diff
changeset
|
363 memset(s,0,sizeof(stream_t)); |
2144 | 364 s->fd=-1; |
365 s->type=STREAMTYPE_MEMORY; | |
366 s->buf_pos=0; s->buf_len=len; | |
367 s->start_pos=0; s->end_pos=len; | |
368 stream_reset(s); | |
369 s->pos=len; | |
370 memcpy(s->buffer,data,len); | |
371 return s; | |
372 } | |
373 | |
1 | 374 stream_t* new_stream(int fd,int type){ |
375 stream_t *s=malloc(sizeof(stream_t)); | |
3291 | 376 if(s==NULL) return NULL; |
377 memset(s,0,sizeof(stream_t)); | |
378 | |
1 | 379 s->fd=fd; |
380 s->type=type; | |
180 | 381 s->buf_pos=s->buf_len=0; |
598 | 382 s->start_pos=s->end_pos=0; |
1642 | 383 s->priv=NULL; |
7407 | 384 s->url=NULL; |
2322 | 385 s->cache_pid=0; |
1 | 386 stream_reset(s); |
387 return s; | |
388 } | |
389 | |
390 void free_stream(stream_t *s){ | |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
5982
diff
changeset
|
391 // printf("\n*** free_stream() called ***\n"); |
9798 | 392 #ifdef USE_STREAM_CACHE |
4893 | 393 if(s->cache_pid) { |
9915 | 394 cache_uninit(s); |
4893 | 395 } |
9798 | 396 #endif |
6479 | 397 switch(s->type) { |
7630
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
398 #ifdef LIBSMBCLIENT |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
399 case STREAMTYPE_SMB: |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
400 smbc_close(s->fd); |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
401 break; |
4c51ce16c4a2
smb:// (samba client) support by Vladimir Moushkov <vlindos_mpdev@abv.bg>
arpi
parents:
7408
diff
changeset
|
402 #endif |
9610 | 403 #ifdef HAS_DVBIN_SUPPORT |
404 case STREAMTYPE_DVB: | |
405 dvbin_close(s->priv); | |
406 break; | |
407 #endif | |
408 | |
6479 | 409 #ifdef USE_DVDREAD |
410 case STREAMTYPE_DVD: | |
411 dvd_close(s->priv); | |
412 #endif | |
9794 | 413 default: |
414 if(s->close) s->close(s); | |
415 } | |
9853 | 416 if(s->fd>0) close(s->fd); |
9794 | 417 // Disabled atm, i don't like that. s->priv can be anything after all |
418 // streams should destroy their priv on close | |
419 //if(s->priv) free(s->priv); | |
420 if(s->url) free(s->url); | |
1 | 421 free(s); |
422 } | |
423 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
424 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
|
425 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
|
426 s->priv = ds; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
427 return s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
428 } |