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