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