Mercurial > mplayer.hg
annotate libmpdemux/stream.h @ 2380:c1f71b8190d1
fix error reporting bug
author | szabi |
---|---|
date | Mon, 22 Oct 2001 20:22:25 +0000 |
parents | f6a10f4b6119 |
children | 66837325b929 |
rev | line source |
---|---|
998
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
1 #ifndef __STREAM_H |
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
2 #define __STREAM_H |
578 | 3 |
4 #define STREAM_BUFFER_SIZE 2048 | |
5 | |
6 #define STREAMTYPE_FILE 0 | |
7 #define STREAMTYPE_VCD 1 | |
692 | 8 #define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for stdin) |
1594 | 9 #define STREAMTYPE_DVD 3 |
2144 | 10 #define STREAMTYPE_MEMORY 4 |
578 | 11 |
12 #define VCD_SECTOR_SIZE 2352 | |
13 #define VCD_SECTOR_OFFS 24 | |
14 #define VCD_SECTOR_DATA 2324 | |
15 | |
16 int vcd_seek_to_track(int fd,int track); | |
17 void vcd_read_toc(int fd); | |
18 | |
19 #ifdef VCD_CACHE | |
20 void vcd_cache_init(int s); | |
21 #endif | |
22 | |
23 typedef struct { | |
24 int fd; | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
25 off_t pos; |
578 | 26 int eof; |
27 int type; // 0=file 1=VCD | |
28 unsigned int buf_pos,buf_len; | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
29 off_t start_pos,end_pos; |
2322 | 30 unsigned int cache_pid; |
31 void* cache_data; | |
2144 | 32 void* priv; // used for DVD |
583 | 33 unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE]; |
578 | 34 } stream_t; |
35 | |
2322 | 36 #ifdef USE_STREAM_CACHE |
37 void stream_enable_cache(stream_t *s,int size); | |
38 #else | |
39 // no cache | |
40 #define cache_stream_fill_buffer(x) stream_fill_buffer(x) | |
41 #define cache_stream_seek_long(x,y) stream_seek_long(x,y) | |
42 #define stream_enable_cache(x,y) | |
43 #endif | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
44 |
2322 | 45 int cache_stream_fill_buffer(stream_t *s); |
46 int cache_stream_seek_long(stream_t *s,off_t pos); | |
578 | 47 |
48 inline static int stream_read_char(stream_t *s){ | |
49 return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]: | |
2322 | 50 (cache_stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); |
578 | 51 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; |
52 // stream_fill_buffer(s); | |
53 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; | |
54 // return 0; // EOF | |
55 } | |
56 | |
57 inline static unsigned int stream_read_word(stream_t *s){ | |
58 int x,y; | |
59 x=stream_read_char(s); | |
60 y=stream_read_char(s); | |
61 return (x<<8)|y; | |
62 } | |
63 | |
64 inline static unsigned int stream_read_dword(stream_t *s){ | |
65 unsigned int y; | |
66 y=stream_read_char(s); | |
67 y=(y<<8)|stream_read_char(s); | |
68 y=(y<<8)|stream_read_char(s); | |
69 y=(y<<8)|stream_read_char(s); | |
70 return y; | |
71 } | |
72 | |
73 inline static unsigned int stream_read_word_le(stream_t *s){ | |
74 int x,y; | |
75 x=stream_read_char(s); | |
76 y=stream_read_char(s); | |
77 return (y<<8)|x; | |
78 } | |
79 | |
80 inline static unsigned int stream_read_dword_le(stream_t *s){ | |
81 unsigned int y; | |
82 y=stream_read_char(s); | |
83 y|=stream_read_char(s)<<8; | |
84 y|=stream_read_char(s)<<16; | |
85 y|=stream_read_char(s)<<24; | |
86 return y; | |
87 } | |
88 | |
2347 | 89 inline static int stream_read(stream_t *s,char* mem,int total){ |
90 int len=total; | |
578 | 91 while(len>0){ |
92 int x; | |
93 x=s->buf_len-s->buf_pos; | |
94 if(x==0){ | |
2347 | 95 if(!cache_stream_fill_buffer(s)) return total-len; // EOF |
578 | 96 x=s->buf_len-s->buf_pos; |
97 } | |
98 if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n"); | |
99 if(x>len) x=len; | |
100 memcpy(mem,&s->buffer[s->buf_pos],x); | |
101 s->buf_pos+=x; mem+=x; len-=x; | |
102 } | |
2347 | 103 return total; |
578 | 104 } |
105 | |
106 inline static int stream_eof(stream_t *s){ | |
107 return s->eof; | |
108 } | |
109 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
110 inline static off_t stream_tell(stream_t *s){ |
578 | 111 return s->pos+s->buf_pos-s->buf_len; |
112 } | |
113 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
114 inline static int stream_seek(stream_t *s,off_t pos){ |
578 | 115 |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
116 // if(verbose>=3) printf("seek to 0x%qX\n",(long long)pos); |
578 | 117 |
118 if(pos<s->pos){ | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
119 off_t x=pos-(s->pos-s->buf_len); |
578 | 120 if(x>=0){ |
121 s->buf_pos=x; | |
122 // putchar('*');fflush(stdout); | |
123 return 1; | |
124 } | |
125 } | |
126 | |
2322 | 127 return cache_stream_seek_long(s,pos); |
578 | 128 } |
129 | |
1491 | 130 inline static int stream_skip(stream_t *s,int len){ |
692 | 131 if(len<0 || (len>2*STREAM_BUFFER_SIZE && s->type!=STREAMTYPE_STREAM)){ |
578 | 132 // negative or big skip! |
1491 | 133 return stream_seek(s,stream_tell(s)+len); |
578 | 134 } |
135 while(len>0){ | |
136 int x=s->buf_len-s->buf_pos; | |
137 if(x==0){ | |
2322 | 138 if(!cache_stream_fill_buffer(s)) return 0; // EOF |
578 | 139 x=s->buf_len-s->buf_pos; |
140 } | |
141 if(x>len) x=len; | |
142 //memcpy(mem,&s->buf[s->buf_pos],x); | |
143 s->buf_pos+=x; len-=x; | |
144 } | |
1491 | 145 return 1; |
578 | 146 } |
147 | |
148 void stream_reset(stream_t *s); | |
149 stream_t* new_stream(int fd,int type); | |
150 void free_stream(stream_t *s); | |
2144 | 151 stream_t* new_memory_stream(unsigned char* data,int len); |
998
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
152 |
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
153 #endif // __STREAM_H |