Mercurial > mplayer.hg
annotate stream.c @ 1414:68e8cd978708
-fsmode range extended
author | arpi |
---|---|
date | Sun, 29 Jul 2001 16:31:37 +0000 |
parents | f2516027a346 |
children | a90d889eb649 |
rev | line source |
---|---|
578 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 | |
5 #include <sys/ioctl.h> | |
6 #include <unistd.h> | |
7 | |
8 #include "stream.h" | |
9 | |
10 extern int verbose; // defined in mplayer.c | |
1 | 11 |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
12 #ifdef __FreeBSD__ |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
13 #include "vcd_read_fbsd.c" |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
14 #else |
1 | 15 #include "vcd_read.c" |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
16 #endif |
1 | 17 |
18 //=================== STREAMER ========================= | |
19 | |
20 int stream_fill_buffer(stream_t *s){ | |
21 int len; | |
22 if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } | |
23 switch(s->type){ | |
24 case STREAMTYPE_FILE: | |
692 | 25 case STREAMTYPE_STREAM: |
1 | 26 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; |
27 case STREAMTYPE_VCD: | |
28 #ifdef VCD_CACHE | |
29 len=vcd_cache_read(s->fd,s->buffer);break; | |
30 #else | |
31 len=vcd_read(s->fd,s->buffer);break; | |
32 #endif | |
33 default: len=0; | |
34 } | |
35 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
36 s->buf_pos=0; | |
37 s->buf_len=len; | |
38 s->pos+=len; | |
39 // printf("[%d]",len);fflush(stdout); | |
40 return len; | |
41 } | |
42 | |
578 | 43 int stream_seek_long(stream_t *s,unsigned int pos){ |
1 | 44 unsigned int newpos; |
45 | |
578 | 46 // if(verbose>=3) printf("seek to 0x%X\n",pos); |
1 | 47 |
48 if(verbose>=3){ | |
49 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
578 | 50 (unsigned int)s->pos,newpos,pos,s->buf_len); |
1 | 51 } |
52 | |
53 s->buf_pos=s->buf_len=0; | |
54 | |
55 switch(s->type){ | |
56 case STREAMTYPE_FILE: | |
692 | 57 case STREAMTYPE_STREAM: |
492 | 58 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1 | 59 case STREAMTYPE_VCD: |
60 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
61 } | |
62 | |
63 pos-=newpos; | |
64 | |
65 if(newpos==0 || newpos!=s->pos){ | |
66 switch(s->type){ | |
67 case STREAMTYPE_FILE: | |
692 | 68 s->pos=newpos; // real seek |
1 | 69 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
70 break; | |
71 case STREAMTYPE_VCD: | |
692 | 72 s->pos=newpos; // real seek |
1 | 73 #ifdef VCD_CACHE |
74 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
75 #else | |
76 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
77 #endif | |
78 break; | |
692 | 79 case STREAMTYPE_STREAM: |
80 //s->pos=newpos; // real seek | |
81 if(newpos<s->pos){ | |
82 printf("Cannot seek backward in linear streams!\n"); | |
83 return 1; | |
84 } | |
85 while(s->pos<newpos){ | |
86 if(stream_fill_buffer(s)<=0) break; // EOF | |
87 } | |
88 break; | |
1 | 89 } |
90 // putchar('.');fflush(stdout); | |
91 //} else { | |
92 // putchar('%');fflush(stdout); | |
93 } | |
94 | |
95 stream_fill_buffer(s); | |
96 if(pos>=0 && pos<s->buf_len){ | |
97 s->buf_pos=pos; // byte position in sector | |
98 return 1; | |
99 } | |
578 | 100 if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%X !\n",pos+newpos); |
1 | 101 return 0; |
102 } | |
103 | |
104 | |
105 void stream_reset(stream_t *s){ | |
106 if(s->eof){ | |
107 s->pos=0; //ftell(f); | |
108 // s->buf_pos=s->buf_len=0; | |
109 s->eof=0; | |
110 } | |
111 //stream_seek(s,0); | |
112 } | |
113 | |
114 stream_t* new_stream(int fd,int type){ | |
115 stream_t *s=malloc(sizeof(stream_t)); | |
116 s->fd=fd; | |
117 s->type=type; | |
180 | 118 s->buf_pos=s->buf_len=0; |
598 | 119 s->start_pos=s->end_pos=0; |
1 | 120 stream_reset(s); |
121 return s; | |
122 } | |
123 | |
124 void free_stream(stream_t *s){ | |
125 free(s); | |
126 } | |
127 | |
128 |