comparison libmpdemux/stream.c @ 15518:9391bf60ccdf

ported dvd:// to the new stream api
author nicodvb
date Thu, 19 May 2005 19:50:39 +0000
parents 5eb4994a691f
children 2c5186ed83b9
comparison
equal deleted inserted replaced
15517:9560b286481c 15518:9391bf60ccdf
35 extern int verbose; // defined in mplayer.c 35 extern int verbose; // defined in mplayer.c
36 void cache_uninit(stream_t *s); // defined in cache2.c 36 void cache_uninit(stream_t *s); // defined in cache2.c
37 37
38 //#include "vcd_read_bincue.h" 38 //#include "vcd_read_bincue.h"
39 39
40 #ifdef USE_DVDREAD
41 int dvd_read_sector(dvd_priv_t *d,unsigned char* data);
42 void dvd_seek(dvd_priv_t *d,int pos);
43 void dvd_close(dvd_priv_t *d);
44 #endif
45
46 #ifdef LIBSMBCLIENT 40 #ifdef LIBSMBCLIENT
47 #include "libsmbclient.h" 41 #include "libsmbclient.h"
48 #endif 42 #endif
49 43
50 #ifdef HAVE_VCD 44 #ifdef HAVE_VCD
62 #ifdef HAVE_FTP 56 #ifdef HAVE_FTP
63 extern stream_info_t stream_info_ftp; 57 extern stream_info_t stream_info_ftp;
64 #endif 58 #endif
65 #ifdef HAVE_VSTREAM 59 #ifdef HAVE_VSTREAM
66 extern stream_info_t stream_info_vstream; 60 extern stream_info_t stream_info_vstream;
61 #endif
62 #ifdef USE_DVDNAV
63 extern stream_info_t stream_info_dvdnav;
67 #endif 64 #endif
68 65
69 extern stream_info_t stream_info_cue; 66 extern stream_info_t stream_info_cue;
70 extern stream_info_t stream_info_null; 67 extern stream_info_t stream_info_null;
71 extern stream_info_t stream_info_file; 68 extern stream_info_t stream_info_file;
69 extern stream_info_t stream_info_dvd;
72 70
73 stream_info_t* auto_open_streams[] = { 71 stream_info_t* auto_open_streams[] = {
74 #ifdef HAVE_VCD 72 #ifdef HAVE_VCD
75 &stream_info_vcd, 73 &stream_info_vcd,
76 #endif 74 #endif
88 #endif 86 #endif
89 #ifdef HAVE_VSTREAM 87 #ifdef HAVE_VSTREAM
90 &stream_info_vstream, 88 &stream_info_vstream,
91 #endif 89 #endif
92 &stream_info_cue, 90 &stream_info_cue,
91 &stream_info_dvd,
92 #ifdef USE_DVDNAV
93 &stream_info_dvdnav;
94 #endif
95
93 &stream_info_null, 96 &stream_info_null,
94 &stream_info_file, 97 &stream_info_file,
95 NULL 98 NULL
96 }; 99 };
97 100
201 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; 204 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
202 } 205 }
203 #else 206 #else
204 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; 207 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
205 #endif 208 #endif
206 #ifdef USE_DVDNAV
207 case STREAMTYPE_DVDNAV: {
208 dvdnav_stream_read((dvdnav_priv_t*)s->priv,s->buffer,&len);
209 if (len==0) return 0; // this was an event, so repeat the read
210 break;
211 }
212 #endif
213 #ifdef USE_DVDREAD
214 case STREAMTYPE_DVD: {
215 off_t pos=dvd_read_sector(s->priv,s->buffer);
216 if(pos>=0){
217 len=2048; // full sector
218 s->pos=2048*pos-len;
219 } else len=-1; // error
220 break;
221 }
222 #endif
223 case STREAMTYPE_DS: 209 case STREAMTYPE_DS:
224 len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE); 210 len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE);
225 break; 211 break;
226 212
227 213
249 #ifdef _LARGEFILE_SOURCE 235 #ifdef _LARGEFILE_SOURCE
250 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; 236 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break;
251 #else 237 #else
252 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; 238 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
253 #endif 239 #endif
254 case STREAMTYPE_DVD:
255 newpos=pos/2048; newpos*=2048; break;
256 default: 240 default:
257 // Round on sector size 241 // Round on sector size
258 if(s->sector_size) 242 if(s->sector_size)
259 newpos=(pos/s->sector_size)*s->sector_size; 243 newpos=(pos/s->sector_size)*s->sector_size;
260 else { // Otherwise on the buffer size 244 else { // Otherwise on the buffer size
274 #else 258 #else
275 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", 259 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n",
276 (unsigned int)s->pos,newpos,pos,s->buf_len); 260 (unsigned int)s->pos,newpos,pos,s->buf_len);
277 #endif 261 #endif
278 } 262 }
279
280 pos-=newpos; 263 pos-=newpos;
281 264
282 if(newpos==0 || newpos!=s->pos){ 265 if(newpos==0 || newpos!=s->pos){
283 switch(s->type){ 266 switch(s->type){
284 #ifdef LIBSMBCLIENT 267 #ifdef LIBSMBCLIENT
285 case STREAMTYPE_SMB: 268 case STREAMTYPE_SMB:
286 s->pos=newpos; // real seek 269 s->pos=newpos; // real seek
287 if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; 270 if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
288 break;
289 #endif
290 #ifdef USE_DVDNAV
291 case STREAMTYPE_DVDNAV: {
292 if (newpos==0) {
293 if (dvdnav_stream_reset((dvdnav_priv_t*)s->priv))
294 s->pos=0;
295 }
296 if(newpos!=s->pos){
297 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek in DVDNAV streams yet!\n");
298 return 1;
299 }
300 break;
301 }
302 #endif
303 #ifdef USE_DVDREAD
304 case STREAMTYPE_DVD:
305 s->pos=newpos; // real seek
306 dvd_seek(s->priv,s->pos/2048);
307 break; 271 break;
308 #endif 272 #endif
309 case STREAMTYPE_STREAM: 273 case STREAMTYPE_STREAM:
310 //s->pos=newpos; // real seek 274 //s->pos=newpos; // real seek
311 // Some streaming protocol allow to seek backward and forward 275 // Some streaming protocol allow to seek backward and forward
426 #ifdef LIBSMBCLIENT 390 #ifdef LIBSMBCLIENT
427 case STREAMTYPE_SMB: 391 case STREAMTYPE_SMB:
428 smbc_close(s->fd); 392 smbc_close(s->fd);
429 break; 393 break;
430 #endif 394 #endif
431
432 #ifdef USE_DVDREAD
433 case STREAMTYPE_DVD:
434 dvd_close(s->priv);
435 #endif
436 default: 395 default:
437 if(s->close) s->close(s); 396 if(s->close) s->close(s);
438 } 397 }
439 if(s->fd>0){ 398 if(s->fd>0){
440 /* on unix we define closesocket to close 399 /* on unix we define closesocket to close