Mercurial > mplayer.hg
annotate libmpdemux/stream.c @ 3241:71075e783b04
fixed xanim detection (also present on non-x86 too - look at xanim homepage) and added tv into _inputmodules
author | alex |
---|---|
date | Sat, 01 Dec 2001 14:41:54 +0000 |
parents | 606bb6943ae9 |
children | caac174877b7 |
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: |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
39 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
40 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
41 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
|
42 } else { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
43 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
|
44 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
45 #else |
1 | 46 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
|
47 #endif |
1 | 48 case STREAMTYPE_VCD: |
49 #ifdef VCD_CACHE | |
50 len=vcd_cache_read(s->fd,s->buffer);break; | |
51 #else | |
52 len=vcd_read(s->fd,s->buffer);break; | |
53 #endif | |
1595 | 54 #ifdef USE_DVDREAD |
55 case STREAMTYPE_DVD: { | |
56 off_t pos=dvd_read_sector(s->priv,s->buffer); | |
57 if(pos>=0){ | |
58 len=2048; // full sector | |
59 s->pos=2048*pos-len; | |
60 } else len=-1; // error | |
61 break; | |
62 } | |
63 #endif | |
2790 | 64 #ifdef USE_TV |
65 case STREAMTYPE_TV: | |
66 { | |
67 len = 0; | |
68 break; | |
69 } | |
70 #endif | |
1 | 71 default: len=0; |
72 } | |
73 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
74 s->buf_pos=0; | |
75 s->buf_len=len; | |
76 s->pos+=len; | |
77 // printf("[%d]",len);fflush(stdout); | |
78 return len; | |
79 } | |
80 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
81 int stream_seek_long(stream_t *s,off_t pos){ |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
82 off_t newpos; |
1 | 83 |
2144 | 84 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 85 |
86 s->buf_pos=s->buf_len=0; | |
87 | |
88 switch(s->type){ | |
89 case STREAMTYPE_FILE: | |
692 | 90 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
91 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
92 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
93 #else |
492 | 94 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
95 #endif |
1 | 96 case STREAMTYPE_VCD: |
97 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
1595 | 98 case STREAMTYPE_DVD: |
99 newpos=pos/2048; newpos*=2048; break; | |
1 | 100 } |
101 | |
2050 | 102 if(verbose>=3){ |
103 #ifdef _LARGEFILE_SOURCE | |
104 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
105 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
106 #else | |
107 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
108 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
109 #endif | |
110 } | |
111 | |
1 | 112 pos-=newpos; |
113 | |
114 if(newpos==0 || newpos!=s->pos){ | |
115 switch(s->type){ | |
116 case STREAMTYPE_FILE: | |
692 | 117 s->pos=newpos; // real seek |
1 | 118 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
119 break; | |
120 case STREAMTYPE_VCD: | |
692 | 121 s->pos=newpos; // real seek |
1 | 122 #ifdef VCD_CACHE |
123 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
124 #else | |
125 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
126 #endif | |
127 break; | |
1595 | 128 #ifdef USE_DVDREAD |
129 case STREAMTYPE_DVD: | |
130 s->pos=newpos; // real seek | |
131 dvd_seek(s->priv,s->pos/2048); | |
132 break; | |
133 #endif | |
692 | 134 case STREAMTYPE_STREAM: |
135 //s->pos=newpos; // real seek | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
136 // 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
|
137 // 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
|
138 // doesn't support seeking. |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
139 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
140 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
141 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
|
142 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
|
143 return 1; |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
144 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
145 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
146 #else |
692 | 147 if(newpos<s->pos){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
148 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); |
692 | 149 return 1; |
150 } | |
151 while(s->pos<newpos){ | |
152 if(stream_fill_buffer(s)<=0) break; // EOF | |
153 } | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
154 #endif |
692 | 155 break; |
2790 | 156 #ifdef USE_TV |
157 case STREAMTYPE_TV: | |
158 s->pos=newpos; /* no sense */ | |
159 break; | |
160 #endif | |
1 | 161 } |
162 // putchar('.');fflush(stdout); | |
163 //} else { | |
164 // putchar('%');fflush(stdout); | |
165 } | |
166 | |
167 stream_fill_buffer(s); | |
1999 | 168 if(pos>=0 && pos<=s->buf_len){ |
1 | 169 s->buf_pos=pos; // byte position in sector |
170 return 1; | |
171 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
172 |
1999 | 173 // if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n"); |
174 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
175 #ifdef _LARGEFILE_SOURCE |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
176 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
|
177 #else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
178 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
|
179 #endif |
1 | 180 return 0; |
181 } | |
182 | |
183 | |
184 void stream_reset(stream_t *s){ | |
185 if(s->eof){ | |
186 s->pos=0; //ftell(f); | |
187 // s->buf_pos=s->buf_len=0; | |
188 s->eof=0; | |
189 } | |
190 //stream_seek(s,0); | |
191 } | |
192 | |
2144 | 193 stream_t* new_memory_stream(unsigned char* data,int len){ |
194 stream_t *s=malloc(sizeof(stream_t)+len); | |
195 s->fd=-1; | |
196 s->type=STREAMTYPE_MEMORY; | |
197 s->buf_pos=0; s->buf_len=len; | |
198 s->start_pos=0; s->end_pos=len; | |
199 stream_reset(s); | |
200 s->pos=len; | |
201 memcpy(s->buffer,data,len); | |
202 return s; | |
203 } | |
204 | |
1 | 205 stream_t* new_stream(int fd,int type){ |
206 stream_t *s=malloc(sizeof(stream_t)); | |
207 s->fd=fd; | |
208 s->type=type; | |
180 | 209 s->buf_pos=s->buf_len=0; |
598 | 210 s->start_pos=s->end_pos=0; |
1642 | 211 s->priv=NULL; |
2322 | 212 s->cache_pid=0; |
1 | 213 stream_reset(s); |
214 return s; | |
215 } | |
216 | |
217 void free_stream(stream_t *s){ | |
2322 | 218 printf("*** free_stream() called ***\n"); |
219 if(s->cache_pid) kill(s->cache_pid,SIGTERM); | |
1642 | 220 if(s->priv) free(s->priv); |
1 | 221 free(s); |
222 } | |
223 |