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