Mercurial > mplayer.hg
annotate libmpdemux/stream.c @ 5939:65ee86f5a45f
avid mjpeg support (external huffman table)
author | alex |
---|---|
date | Thu, 02 May 2002 12:24:53 +0000 |
parents | 02576893af2a |
children | b61b22fbcd08 |
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" | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
17 #include "demuxer.h" |
578 | 18 |
19 extern int verbose; // defined in mplayer.c | |
1 | 20 |
3261 | 21 #ifdef HAVE_VCD |
22 | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
23 #ifdef __FreeBSD__ |
2310 | 24 #include "vcd_read_fbsd.h" |
5872 | 25 #elif defined(__NetBSD__) |
26 #include "vcd_read_nbsd.h" | |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
27 #else |
2310 | 28 #include "vcd_read.h" |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
29 #endif |
1 | 30 |
3261 | 31 #endif |
32 | |
1595 | 33 #ifdef USE_DVDREAD |
34 int dvd_read_sector(void* d,void* p2); | |
35 void dvd_seek(void* d,off_t pos); | |
36 #endif | |
37 | |
1 | 38 //=================== STREAMER ========================= |
39 | |
40 int stream_fill_buffer(stream_t *s){ | |
41 int len; | |
42 if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } | |
43 switch(s->type){ | |
44 case STREAMTYPE_FILE: | |
692 | 45 case STREAMTYPE_STREAM: |
4042
d651a7b5d213
STREAMTYPE_PLAYLIST introduced. similar to STREAMTYPE_STREAM but used for playlists. patch by Alban Bedel <albeu@free.fr>
arpi
parents:
3291
diff
changeset
|
46 case STREAMTYPE_PLAYLIST: |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
47 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
48 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
49 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
|
50 } else { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
51 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
|
52 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
53 #else |
1 | 54 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
|
55 #endif |
3261 | 56 #ifdef HAVE_VCD |
1 | 57 case STREAMTYPE_VCD: |
58 #ifdef VCD_CACHE | |
59 len=vcd_cache_read(s->fd,s->buffer);break; | |
60 #else | |
61 len=vcd_read(s->fd,s->buffer);break; | |
62 #endif | |
3261 | 63 #endif |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
64 #ifdef USE_DVDNAV |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
65 case STREAMTYPE_DVDNAV: { |
5472 | 66 dvdnav_stream_read((dvdnav_priv_t*)s->priv,s->buffer,&len); |
67 if (len==0) return 0; // this was an event, so repeat the read | |
5380
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
68 break; |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
69 } |
8a01cde9cf39
DVDnav support patch by David Holm and Kees Cook <mplayer@outflux.net>
arpi
parents:
5133
diff
changeset
|
70 #endif |
1595 | 71 #ifdef USE_DVDREAD |
72 case STREAMTYPE_DVD: { | |
73 off_t pos=dvd_read_sector(s->priv,s->buffer); | |
74 if(pos>=0){ | |
75 len=2048; // full sector | |
76 s->pos=2048*pos-len; | |
77 } else len=-1; // error | |
78 break; | |
79 } | |
80 #endif | |
2790 | 81 #ifdef USE_TV |
82 case STREAMTYPE_TV: | |
83 { | |
84 len = 0; | |
85 break; | |
86 } | |
87 #endif | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
88 case STREAMTYPE_DS: |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
89 len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
90 break; |
1 | 91 default: len=0; |
92 } | |
93 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
94 s->buf_pos=0; | |
95 s->buf_len=len; | |
96 s->pos+=len; | |
97 // printf("[%d]",len);fflush(stdout); | |
98 return len; | |
99 } | |
100 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
101 int stream_seek_long(stream_t *s,off_t pos){ |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
102 off_t newpos; |
1 | 103 |
2144 | 104 // if(verbose>=3) printf("seek_long to 0x%X\n",(unsigned int)pos); |
1 | 105 |
106 s->buf_pos=s->buf_len=0; | |
107 | |
108 switch(s->type){ | |
109 case STREAMTYPE_FILE: | |
692 | 110 case STREAMTYPE_STREAM: |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
111 #ifdef _LARGEFILE_SOURCE |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
112 newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break; |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
113 #else |
492 | 114 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
115 #endif |
1 | 116 case STREAMTYPE_VCD: |
117 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
1595 | 118 case STREAMTYPE_DVD: |
119 newpos=pos/2048; newpos*=2048; break; | |
1 | 120 } |
121 | |
2050 | 122 if(verbose>=3){ |
123 #ifdef _LARGEFILE_SOURCE | |
124 printf("s->pos=%llX newpos=%llX new_bufpos=%llX buflen=%X \n", | |
125 (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len); | |
126 #else | |
127 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
128 (unsigned int)s->pos,newpos,pos,s->buf_len); | |
129 #endif | |
130 } | |
131 | |
1 | 132 pos-=newpos; |
133 | |
134 if(newpos==0 || newpos!=s->pos){ | |
135 switch(s->type){ | |
136 case STREAMTYPE_FILE: | |
692 | 137 s->pos=newpos; // real seek |
1 | 138 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
139 break; | |
3261 | 140 #ifdef HAVE_VCD |
1 | 141 case STREAMTYPE_VCD: |
692 | 142 s->pos=newpos; // real seek |
1 | 143 #ifdef VCD_CACHE |
144 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
145 #else | |
146 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
147 #endif | |
148 break; | |
3261 | 149 #endif |
5472 | 150 #ifdef USE_DVDNAV |
151 case STREAMTYPE_DVDNAV: { | |
152 if (newpos==0) { | |
153 if (dvdnav_stream_reset((dvdnav_priv_t*)s->priv)) | |
154 s->pos=0; | |
155 } | |
156 if(newpos!=s->pos){ | |
157 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek in DVDNAV streams yet!\n"); | |
158 return 1; | |
159 } | |
160 break; | |
161 } | |
162 #endif | |
1595 | 163 #ifdef USE_DVDREAD |
164 case STREAMTYPE_DVD: | |
165 s->pos=newpos; // real seek | |
166 dvd_seek(s->priv,s->pos/2048); | |
167 break; | |
168 #endif | |
692 | 169 case STREAMTYPE_STREAM: |
170 //s->pos=newpos; // real seek | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
171 // 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
|
172 // 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
|
173 // doesn't support seeking. |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
174 #ifdef STREAMING |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
175 if( s->streaming_ctrl!=NULL ) { |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
176 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
|
177 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
|
178 return 1; |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
179 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
180 } |
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
181 #else |
692 | 182 if(newpos<s->pos){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
183 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); |
692 | 184 return 1; |
185 } | |
186 while(s->pos<newpos){ | |
187 if(stream_fill_buffer(s)<=0) break; // EOF | |
188 } | |
3044
606bb6943ae9
Added a network read function call and a seek network function call.
bertrand
parents:
2790
diff
changeset
|
189 #endif |
692 | 190 break; |
2790 | 191 #ifdef USE_TV |
192 case STREAMTYPE_TV: | |
193 s->pos=newpos; /* no sense */ | |
194 break; | |
195 #endif | |
1 | 196 } |
197 // putchar('.');fflush(stdout); | |
198 //} else { | |
199 // putchar('%');fflush(stdout); | |
200 } | |
201 | |
202 stream_fill_buffer(s); | |
1999 | 203 if(pos>=0 && pos<=s->buf_len){ |
1 | 204 s->buf_pos=pos; // byte position in sector |
205 return 1; | |
206 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
207 |
1999 | 208 // if(pos==s->buf_len) printf("XXX Seek to last byte of file -> EOF\n"); |
209 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
1177
diff
changeset
|
210 #ifdef _LARGEFILE_SOURCE |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
211 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
|
212 #else |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1642
diff
changeset
|
213 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
|
214 #endif |
1 | 215 return 0; |
216 } | |
217 | |
218 | |
219 void stream_reset(stream_t *s){ | |
220 if(s->eof){ | |
221 s->pos=0; //ftell(f); | |
222 // s->buf_pos=s->buf_len=0; | |
223 s->eof=0; | |
224 } | |
225 //stream_seek(s,0); | |
226 } | |
227 | |
2144 | 228 stream_t* new_memory_stream(unsigned char* data,int len){ |
229 stream_t *s=malloc(sizeof(stream_t)+len); | |
230 s->fd=-1; | |
231 s->type=STREAMTYPE_MEMORY; | |
232 s->buf_pos=0; s->buf_len=len; | |
233 s->start_pos=0; s->end_pos=len; | |
234 stream_reset(s); | |
235 s->pos=len; | |
236 memcpy(s->buffer,data,len); | |
237 return s; | |
238 } | |
239 | |
1 | 240 stream_t* new_stream(int fd,int type){ |
241 stream_t *s=malloc(sizeof(stream_t)); | |
3291 | 242 if(s==NULL) return NULL; |
243 memset(s,0,sizeof(stream_t)); | |
244 | |
1 | 245 s->fd=fd; |
246 s->type=type; | |
180 | 247 s->buf_pos=s->buf_len=0; |
598 | 248 s->start_pos=s->end_pos=0; |
1642 | 249 s->priv=NULL; |
2322 | 250 s->cache_pid=0; |
1 | 251 stream_reset(s); |
252 return s; | |
253 } | |
254 | |
255 void free_stream(stream_t *s){ | |
4464 | 256 printf("\n*** free_stream() called ***\n"); |
4893 | 257 if(s->cache_pid) { |
258 kill(s->cache_pid,SIGTERM); | |
259 waitpid(s->cache_pid,NULL,0); | |
260 } | |
1642 | 261 if(s->priv) free(s->priv); |
1 | 262 free(s); |
263 } | |
264 | |
5133
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
265 stream_t* new_ds_stream(demux_stream_t *ds) { |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
266 stream_t* s = new_stream(-1,STREAMTYPE_DS); |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
267 s->priv = ds; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
268 return s; |
9841a86d66f9
Initial ogg demuxer. No seeking, a/v sync is broken. Support avi
albeu
parents:
4893
diff
changeset
|
269 } |