annotate stream.h @ 601:2d3a4339bb5a

warnings killed
author szabii
date Mon, 23 Apr 2001 22:51:13 +0000
parents c7117e17e20b
children 14a2f35921a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
1
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
2 #define STREAM_BUFFER_SIZE 2048
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
3
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
4 #define STREAMTYPE_FILE 0
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
5 #define STREAMTYPE_VCD 1
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
6
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
7 #define VCD_SECTOR_SIZE 2352
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
8 #define VCD_SECTOR_OFFS 24
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
9 #define VCD_SECTOR_DATA 2324
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
10
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
11 int vcd_seek_to_track(int fd,int track);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
12 void vcd_read_toc(int fd);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
13
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
14 #ifdef VCD_CACHE
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
15 void vcd_cache_init(int s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
16 #endif
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
17
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
18 typedef struct {
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
19 int fd;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
20 long pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
21 int eof;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
22 int type; // 0=file 1=VCD
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
23 unsigned int buf_pos,buf_len;
598
c7117e17e20b OSD seekbar fixed for mpeg/VCD
arpi_esp
parents: 583
diff changeset
24 long start_pos,end_pos;
583
da08ded03883 silly bug fixed - badly allocated stream buffer
arpi_esp
parents: 578
diff changeset
25 unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE];
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
26 } stream_t;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
27
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
28 int stream_fill_buffer(stream_t *s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
29 int stream_seek_long(stream_t *s,unsigned int pos);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
30
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
31 inline static int stream_read_char(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
32 return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]:
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
33 (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
34 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
35 // stream_fill_buffer(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
36 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
37 // return 0; // EOF
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
38 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
39
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
40 inline static unsigned int stream_read_word(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
41 int x,y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
42 x=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
43 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
44 return (x<<8)|y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
45 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
46
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
47 inline static unsigned int stream_read_dword(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
48 unsigned int y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
49 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
50 y=(y<<8)|stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
51 y=(y<<8)|stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
52 y=(y<<8)|stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
53 return y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
54 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
55
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
56 inline static unsigned int stream_read_word_le(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
57 int x,y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
58 x=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
59 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
60 return (y<<8)|x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
61 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
62
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
63 inline static unsigned int stream_read_dword_le(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
64 unsigned int y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
65 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
66 y|=stream_read_char(s)<<8;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
67 y|=stream_read_char(s)<<16;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
68 y|=stream_read_char(s)<<24;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
69 return y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
70 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
71
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
72 inline static void stream_read(stream_t *s,char* mem,int len){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
73 while(len>0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
74 int x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
75 x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
76 if(x==0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
77 if(!stream_fill_buffer(s)) return; // EOF
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
78 x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
79 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
80 if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n");
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
81 if(x>len) x=len;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
82 memcpy(mem,&s->buffer[s->buf_pos],x);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
83 s->buf_pos+=x; mem+=x; len-=x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
84 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
85 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
86
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
87 inline static int stream_eof(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
88 return s->eof;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
89 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
90
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
91 inline static int stream_tell(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
92 return s->pos+s->buf_pos-s->buf_len;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
93 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
94
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
95 inline static int stream_seek(stream_t *s,unsigned int pos){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
96
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
97 // if(verbose>=3) printf("seek to 0x%X\n",pos);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
98
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
99 if(pos<s->pos){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
100 int x=pos-(s->pos-s->buf_len);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
101 if(x>=0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
102 s->buf_pos=x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
103 // putchar('*');fflush(stdout);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
104 return 1;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
105 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
106 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
107
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
108 return stream_seek_long(s,pos);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
109 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
110
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
111 inline static void stream_skip(stream_t *s,int len){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
112 if(len<0 || len>2*STREAM_BUFFER_SIZE){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
113 // negative or big skip!
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
114 stream_seek(s,stream_tell(s)+len);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
115 return;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
116 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
117 while(len>0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
118 int x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
119 if(x==0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
120 if(!stream_fill_buffer(s)) return; // EOF
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
121 x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
122 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
123 if(x>len) x=len;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
124 //memcpy(mem,&s->buf[s->buf_pos],x);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
125 s->buf_pos+=x; len-=x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
126 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
127 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
128
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
129 void stream_reset(stream_t *s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
130 stream_t* new_stream(int fd,int type);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
131 void free_stream(stream_t *s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
132