Mercurial > mplayer.hg
annotate libmpdemux/stream.c @ 2450:f51307170f69
MIPS support by oliver.schoenbrunner@jku.at
author | arpi |
---|---|
date | Wed, 24 Oct 2001 14:02:19 +0000 |
parents | e22ec6fce385 |
children | 98769cea155c |
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 | |
1 | 56 default: len=0; |
57 } | |
58 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
59 s->buf_pos=0; | |
60 s->buf_len=len; | |
61 s->pos+=len; | |
62 // printf("[%d]",len);fflush(stdout); | |
63 return len; | |
64 } | |
65 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
66 int stream_seek_long(stream_t *s,off_t pos){ |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
67 off_t newpos; |
1 | 68 |
2144 | 69 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 70 |
71 s->buf_pos=s->buf_len=0; | |
72 | |
73 switch(s->type){ | |
74 case STREAMTYPE_FILE: | |
692 | 75 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
76 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
77 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
78 #else |
492 | 79 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
80 #endif |
1 | 81 case STREAMTYPE_VCD: |
82 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
1595 | 83 case STREAMTYPE_DVD: |
84 newpos=pos/2048; newpos*=2048; break; | |
1 | 85 } |
86 | |
2050 | 87 if(verbose>=3){ |
88 #ifdef _LARGEFILE_SOURCE | |
89 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
90 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
91 #else | |
92 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
93 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
94 #endif | |
95 } | |
96 | |
1 | 97 pos-=newpos; |
98 | |
99 if(newpos==0 || newpos!=s->pos){ | |
100 switch(s->type){ | |
101 case STREAMTYPE_FILE: | |
692 | 102 s->pos=newpos; // real seek |
1 | 103 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
104 break; | |
105 case STREAMTYPE_VCD: | |
692 | 106 s->pos=newpos; // real seek |
1 | 107 #ifdef VCD_CACHE |
108 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
109 #else | |
110 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
111 #endif | |
112 break; | |
1595 | 113 #ifdef USE_DVDREAD |
114 case STREAMTYPE_DVD: | |
115 s->pos=newpos; // real seek | |
116 dvd_seek(s->priv,s->pos/2048); | |
117 break; | |
118 #endif | |
692 | 119 case STREAMTYPE_STREAM: |
120 //s->pos=newpos; // real seek | |
121 if(newpos<s->pos){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
122 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); |
692 | 123 return 1; |
124 } | |
125 while(s->pos<newpos){ | |
126 if(stream_fill_buffer(s)<=0) break; // EOF | |
127 } | |
128 break; | |
1 | 129 } |
130 // putchar('.');fflush(stdout); | |
131 //} else { | |
132 // putchar('%');fflush(stdout); | |
133 } | |
134 | |
135 stream_fill_buffer(s); | |
1999 | 136 if(pos>=0 && pos<=s->buf_len){ |
1 | 137 s->buf_pos=pos; // byte position in sector |
138 return 1; | |
139 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
140 |
1999 | 141 // if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n"); |
142 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
143 #ifdef _LARGEFILE_SOURCE |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
144 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
|
145 #else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
146 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
|
147 #endif |
1 | 148 return 0; |
149 } | |
150 | |
151 | |
152 void stream_reset(stream_t *s){ | |
153 if(s->eof){ | |
154 s->pos=0; //ftell(f); | |
155 // s->buf_pos=s->buf_len=0; | |
156 s->eof=0; | |
157 } | |
158 //stream_seek(s,0); | |
159 } | |
160 | |
2144 | 161 stream_t* new_memory_stream(unsigned char* data,int len){ |
162 stream_t *s=malloc(sizeof(stream_t)+len); | |
163 s->fd=-1; | |
164 s->type=STREAMTYPE_MEMORY; | |
165 s->buf_pos=0; s->buf_len=len; | |
166 s->start_pos=0; s->end_pos=len; | |
167 stream_reset(s); | |
168 s->pos=len; | |
169 memcpy(s->buffer,data,len); | |
170 return s; | |
171 } | |
172 | |
1 | 173 stream_t* new_stream(int fd,int type){ |
174 stream_t *s=malloc(sizeof(stream_t)); | |
175 s->fd=fd; | |
176 s->type=type; | |
180 | 177 s->buf_pos=s->buf_len=0; |
598 | 178 s->start_pos=s->end_pos=0; |
1642 | 179 s->priv=NULL; |
2322 | 180 s->cache_pid=0; |
1 | 181 stream_reset(s); |
182 return s; | |
183 } | |
184 | |
185 void free_stream(stream_t *s){ | |
2322 | 186 printf("*** free_stream() called ***\n"); |
187 if(s->cache_pid) kill(s->cache_pid,SIGTERM); | |
1642 | 188 if(s->priv) free(s->priv); |
1 | 189 free(s); |
190 } | |
191 |