Mercurial > mplayer.hg
annotate stream.c @ 2231:440b15b32181
quick fix for movies with a height which is not a multiple of 8
author | michael |
---|---|
date | Wed, 17 Oct 2001 02:04:16 +0000 |
parents | 99f079ff9374 |
children |
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 |
2144 | 68 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 69 |
70 s->buf_pos=s->buf_len=0; | |
71 | |
72 switch(s->type){ | |
73 case STREAMTYPE_FILE: | |
692 | 74 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
75 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
76 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
77 #else |
492 | 78 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
79 #endif |
1 | 80 case STREAMTYPE_VCD: |
81 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
1595 | 82 case STREAMTYPE_DVD: |
83 newpos=pos/2048; newpos*=2048; break; | |
1 | 84 } |
85 | |
2050 | 86 if(verbose>=3){ |
87 #ifdef _LARGEFILE_SOURCE | |
88 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
89 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
90 #else | |
91 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
92 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
93 #endif | |
94 } | |
95 | |
1 | 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 | |
2144 | 160 stream_t* new_memory_stream(unsigned char* data,int len){ |
161 stream_t *s=malloc(sizeof(stream_t)+len); | |
162 s->fd=-1; | |
163 s->type=STREAMTYPE_MEMORY; | |
164 s->buf_pos=0; s->buf_len=len; | |
165 s->start_pos=0; s->end_pos=len; | |
166 stream_reset(s); | |
167 s->pos=len; | |
168 memcpy(s->buffer,data,len); | |
169 return s; | |
170 } | |
171 | |
1 | 172 stream_t* new_stream(int fd,int type){ |
173 stream_t *s=malloc(sizeof(stream_t)); | |
174 s->fd=fd; | |
175 s->type=type; | |
180 | 176 s->buf_pos=s->buf_len=0; |
598 | 177 s->start_pos=s->end_pos=0; |
1642 | 178 s->priv=NULL; |
1 | 179 stream_reset(s); |
180 return s; | |
181 } | |
182 | |
183 void free_stream(stream_t *s){ | |
1642 | 184 if(s->priv) free(s->priv); |
1 | 185 free(s); |
186 } | |
187 | |
188 |