Mercurial > mplayer.hg
annotate stream.c @ 1039:881b949b6c68
avi streaming fixed
author | arpi_esp |
---|---|
date | Wed, 06 Jun 2001 01:39:39 +0000 |
parents | b36fb1ae4b53 |
children | f2516027a346 |
rev | line source |
---|---|
578 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 | |
5 #include <sys/ioctl.h> | |
6 #include <unistd.h> | |
7 | |
8 #include "stream.h" | |
9 | |
10 extern int verbose; // defined in mplayer.c | |
1 | 11 |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
12 #ifdef __FreeBSD__ |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
13 #warning "VCD support under FreeBSD not implemented yet" |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
14 #include "vcd_read_fbsd.c" |
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
15 #else |
1 | 16 #include "vcd_read.c" |
958
162a78d3cc08
FreeBSD support by Vladimir Kushnir vkushnir@Alfacom.net
arpi_esp
parents:
692
diff
changeset
|
17 #endif |
1 | 18 |
19 //=================== STREAMER ========================= | |
20 | |
21 int stream_fill_buffer(stream_t *s){ | |
22 int len; | |
23 if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } | |
24 switch(s->type){ | |
25 case STREAMTYPE_FILE: | |
692 | 26 case STREAMTYPE_STREAM: |
1 | 27 len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break; |
28 case STREAMTYPE_VCD: | |
29 #ifdef VCD_CACHE | |
30 len=vcd_cache_read(s->fd,s->buffer);break; | |
31 #else | |
32 len=vcd_read(s->fd,s->buffer);break; | |
33 #endif | |
34 default: len=0; | |
35 } | |
36 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; return 0; } | |
37 s->buf_pos=0; | |
38 s->buf_len=len; | |
39 s->pos+=len; | |
40 // printf("[%d]",len);fflush(stdout); | |
41 return len; | |
42 } | |
43 | |
578 | 44 int stream_seek_long(stream_t *s,unsigned int pos){ |
1 | 45 unsigned int newpos; |
46 | |
578 | 47 // if(verbose>=3) printf("seek to 0x%X\n",pos); |
1 | 48 |
49 if(verbose>=3){ | |
50 printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", | |
578 | 51 (unsigned int)s->pos,newpos,pos,s->buf_len); |
1 | 52 } |
53 | |
54 s->buf_pos=s->buf_len=0; | |
55 | |
56 switch(s->type){ | |
57 case STREAMTYPE_FILE: | |
692 | 58 case STREAMTYPE_STREAM: |
492 | 59 newpos=pos&(~(STREAM_BUFFER_SIZE-1));break; |
1 | 60 case STREAMTYPE_VCD: |
61 newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break; | |
62 } | |
63 | |
64 pos-=newpos; | |
65 | |
66 if(newpos==0 || newpos!=s->pos){ | |
67 switch(s->type){ | |
68 case STREAMTYPE_FILE: | |
692 | 69 s->pos=newpos; // real seek |
1 | 70 if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1; |
71 break; | |
72 case STREAMTYPE_VCD: | |
692 | 73 s->pos=newpos; // real seek |
1 | 74 #ifdef VCD_CACHE |
75 vcd_cache_seek(s->pos/VCD_SECTOR_DATA); | |
76 #else | |
77 vcd_set_msf(s->pos/VCD_SECTOR_DATA); | |
78 #endif | |
79 break; | |
692 | 80 case STREAMTYPE_STREAM: |
81 //s->pos=newpos; // real seek | |
82 if(newpos<s->pos){ | |
83 printf("Cannot seek backward in linear streams!\n"); | |
84 return 1; | |
85 } | |
86 while(s->pos<newpos){ | |
87 if(stream_fill_buffer(s)<=0) break; // EOF | |
88 } | |
89 break; | |
1 | 90 } |
91 // putchar('.');fflush(stdout); | |
92 //} else { | |
93 // putchar('%');fflush(stdout); | |
94 } | |
95 | |
96 stream_fill_buffer(s); | |
97 if(pos>=0 && pos<s->buf_len){ | |
98 s->buf_pos=pos; // byte position in sector | |
99 return 1; | |
100 } | |
578 | 101 if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%X !\n",pos+newpos); |
1 | 102 return 0; |
103 } | |
104 | |
105 | |
106 void stream_reset(stream_t *s){ | |
107 if(s->eof){ | |
108 s->pos=0; //ftell(f); | |
109 // s->buf_pos=s->buf_len=0; | |
110 s->eof=0; | |
111 } | |
112 //stream_seek(s,0); | |
113 } | |
114 | |
115 stream_t* new_stream(int fd,int type){ | |
116 stream_t *s=malloc(sizeof(stream_t)); | |
117 s->fd=fd; | |
118 s->type=type; | |
180 | 119 s->buf_pos=s->buf_len=0; |
598 | 120 s->start_pos=s->end_pos=0; |
1 | 121 stream_reset(s); |
122 return s; | |
123 } | |
124 | |
125 void free_stream(stream_t *s){ | |
126 free(s); | |
127 } | |
128 | |
129 |