Mercurial > mplayer.hg
annotate libmpdemux/stream.c @ 2855:8bb4e195d7d7
*** empty log message ***
author | gabucino |
---|---|
date | Mon, 12 Nov 2001 17:30:49 +0000 |
parents | 98769cea155c |
children | 606bb6943ae9 |
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> |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
9 #include <fcntl.h> |
2322 | 10 #include <signal.h> |
578 | 11 |
1430 | 12 #include "config.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
13 #include "mp_msg.h" |
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
14 #include "help_mp.h" |
578 | 15 |
16 #include "stream.h" | |
17 | |
18 extern int verbose; // defined in mplayer.c | |
1 | 19 |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
20 #ifdef __FreeBSD__ |
2310 | 21 #include "vcd_read_fbsd.h" |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
22 #else |
2310 | 23 #include "vcd_read.h" |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
24 #endif |
1 | 25 |
1595 | 26 #ifdef USE_DVDREAD |
27 int dvd_read_sector(void* d,void* p2); | |
28 void dvd_seek(void* d,off_t pos); | |
29 #endif | |
30 | |
1 | 31 //=================== STREAMER ========================= |
32 | |
33 int stream_fill_buffer(stream_t *s){ | |
34 int len; | |
35 if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } | |
36 switch(s->type){ | |
37 case STREAMTYPE_FILE: | |
692 | 38 case STREAMTYPE_STREAM: |
1 | 39 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; |
40 case STREAMTYPE_VCD: | |
41 #ifdef VCD_CACHE | |
42 len=vcd_cache_read(s->fd,s->buffer);break; | |
43 #else | |
44 len=vcd_read(s->fd,s->buffer);break; | |
45 #endif | |
1595 | 46 #ifdef USE_DVDREAD |
47 case STREAMTYPE_DVD: { | |
48 off_t pos=dvd_read_sector(s->priv,s->buffer); | |
49 if(pos>=0){ | |
50 len=2048; // full sector | |
51 s->pos=2048*pos-len; | |
52 } else len=-1; // error | |
53 break; | |
54 } | |
55 #endif | |
2790 | 56 #ifdef USE_TV |
57 case STREAMTYPE_TV: | |
58 { | |
59 len = 0; | |
60 break; | |
61 } | |
62 #endif | |
1 | 63 default: len=0; |
64 } | |
65 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
66 s->buf_pos=0; | |
67 s->buf_len=len; | |
68 s->pos+=len; | |
69 // printf("[%d]",len);fflush(stdout); | |
70 return len; | |
71 } | |
72 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
73 int stream_seek_long(stream_t *s,off_t pos){ |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
74 off_t newpos; |
1 | 75 |
2144 | 76 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 77 |
78 s->buf_pos=s->buf_len=0; | |
79 | |
80 switch(s->type){ | |
81 case STREAMTYPE_FILE: | |
692 | 82 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
83 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
84 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
85 #else |
492 | 86 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
87 #endif |
1 | 88 case STREAMTYPE_VCD: |
89 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
1595 | 90 case STREAMTYPE_DVD: |
91 newpos=pos/2048; newpos*=2048; break; | |
1 | 92 } |
93 | |
2050 | 94 if(verbose>=3){ |
95 #ifdef _LARGEFILE_SOURCE | |
96 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
97 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
98 #else | |
99 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
100 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
101 #endif | |
102 } | |
103 | |
1 | 104 pos-=newpos; |
105 | |
106 if(newpos==0 || newpos!=s->pos){ | |
107 switch(s->type){ | |
108 case STREAMTYPE_FILE: | |
692 | 109 s->pos=newpos; // real seek |
1 | 110 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
111 break; | |
112 case STREAMTYPE_VCD: | |
692 | 113 s->pos=newpos; // real seek |
1 | 114 #ifdef VCD_CACHE |
115 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
116 #else | |
117 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
118 #endif | |
119 break; | |
1595 | 120 #ifdef USE_DVDREAD |
121 case STREAMTYPE_DVD: | |
122 s->pos=newpos; // real seek | |
123 dvd_seek(s->priv,s->pos/2048); | |
124 break; | |
125 #endif | |
692 | 126 case STREAMTYPE_STREAM: |
127 //s->pos=newpos; // real seek | |
128 if(newpos<s->pos){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
129 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); |
692 | 130 return 1; |
131 } | |
132 while(s->pos<newpos){ | |
133 if(stream_fill_buffer(s)<=0) break; // EOF | |
134 } | |
135 break; | |
2790 | 136 #ifdef USE_TV |
137 case STREAMTYPE_TV: | |
138 s->pos=newpos; /* no sense */ | |
139 break; | |
140 #endif | |
1 | 141 } |
142 // putchar('.');fflush(stdout); | |
143 //} else { | |
144 // putchar('%');fflush(stdout); | |
145 } | |
146 | |
147 stream_fill_buffer(s); | |
1999 | 148 if(pos>=0 && pos<=s->buf_len){ |
1 | 149 s->buf_pos=pos; // byte position in sector |
150 return 1; | |
151 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
152 |
1999 | 153 // if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n"); |
154 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
155 #ifdef _LARGEFILE_SOURCE |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
156 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
|
157 #else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
158 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
|
159 #endif |
1 | 160 return 0; |
161 } | |
162 | |
163 | |
164 void stream_reset(stream_t *s){ | |
165 if(s->eof){ | |
166 s->pos=0; //ftell(f); | |
167 // s->buf_pos=s->buf_len=0; | |
168 s->eof=0; | |
169 } | |
170 //stream_seek(s,0); | |
171 } | |
172 | |
2144 | 173 stream_t* new_memory_stream(unsigned char* data,int len){ |
174 stream_t *s=malloc(sizeof(stream_t)+len); | |
175 s->fd=-1; | |
176 s->type=STREAMTYPE_MEMORY; | |
177 s->buf_pos=0; s->buf_len=len; | |
178 s->start_pos=0; s->end_pos=len; | |
179 stream_reset(s); | |
180 s->pos=len; | |
181 memcpy(s->buffer,data,len); | |
182 return s; | |
183 } | |
184 | |
1 | 185 stream_t* new_stream(int fd,int type){ |
186 stream_t *s=malloc(sizeof(stream_t)); | |
187 s->fd=fd; | |
188 s->type=type; | |
180 | 189 s->buf_pos=s->buf_len=0; |
598 | 190 s->start_pos=s->end_pos=0; |
1642 | 191 s->priv=NULL; |
2322 | 192 s->cache_pid=0; |
1 | 193 stream_reset(s); |
194 return s; | |
195 } | |
196 | |
197 void free_stream(stream_t *s){ | |
2322 | 198 printf("*** free_stream() called ***\n"); |
199 if(s->cache_pid) kill(s->cache_pid,SIGTERM); | |
1642 | 200 if(s->priv) free(s->priv); |
1 | 201 free(s); |
202 } | |
203 |