Mercurial > mplayer.hg
annotate stream.h @ 1232:d32b58d5740f
in-progress polish docs for mplayer. please be gentle.
author | eyck |
---|---|
date | Tue, 26 Jun 2001 19:48:50 +0000 |
parents | 8c83e3ff26cc |
children | a90d889eb649 |
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) |
578 | 9 |
10 #define VCD_SECTOR_SIZE 2352 | |
11 #define VCD_SECTOR_OFFS 24 | |
12 #define VCD_SECTOR_DATA 2324 | |
13 | |
14 int vcd_seek_to_track(int fd,int track); | |
15 void vcd_read_toc(int fd); | |
16 | |
17 #ifdef VCD_CACHE | |
18 void vcd_cache_init(int s); | |
19 #endif | |
20 | |
21 typedef struct { | |
22 int fd; | |
23 long pos; | |
24 int eof; | |
25 int type; // 0=file 1=VCD | |
26 unsigned int buf_pos,buf_len; | |
598 | 27 long start_pos,end_pos; |
583 | 28 unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE]; |
578 | 29 } stream_t; |
30 | |
31 int stream_fill_buffer(stream_t *s); | |
32 int stream_seek_long(stream_t *s,unsigned int pos); | |
33 | |
34 inline static int stream_read_char(stream_t *s){ | |
35 return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]: | |
36 (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); | |
37 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; | |
38 // stream_fill_buffer(s); | |
39 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; | |
40 // return 0; // EOF | |
41 } | |
42 | |
43 inline static unsigned int stream_read_word(stream_t *s){ | |
44 int x,y; | |
45 x=stream_read_char(s); | |
46 y=stream_read_char(s); | |
47 return (x<<8)|y; | |
48 } | |
49 | |
50 inline static unsigned int stream_read_dword(stream_t *s){ | |
51 unsigned int y; | |
52 y=stream_read_char(s); | |
53 y=(y<<8)|stream_read_char(s); | |
54 y=(y<<8)|stream_read_char(s); | |
55 y=(y<<8)|stream_read_char(s); | |
56 return y; | |
57 } | |
58 | |
59 inline static unsigned int stream_read_word_le(stream_t *s){ | |
60 int x,y; | |
61 x=stream_read_char(s); | |
62 y=stream_read_char(s); | |
63 return (y<<8)|x; | |
64 } | |
65 | |
66 inline static unsigned int stream_read_dword_le(stream_t *s){ | |
67 unsigned int y; | |
68 y=stream_read_char(s); | |
69 y|=stream_read_char(s)<<8; | |
70 y|=stream_read_char(s)<<16; | |
71 y|=stream_read_char(s)<<24; | |
72 return y; | |
73 } | |
74 | |
75 inline static void stream_read(stream_t *s,char* mem,int len){ | |
76 while(len>0){ | |
77 int x; | |
78 x=s->buf_len-s->buf_pos; | |
79 if(x==0){ | |
80 if(!stream_fill_buffer(s)) return; // EOF | |
81 x=s->buf_len-s->buf_pos; | |
82 } | |
83 if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n"); | |
84 if(x>len) x=len; | |
85 memcpy(mem,&s->buffer[s->buf_pos],x); | |
86 s->buf_pos+=x; mem+=x; len-=x; | |
87 } | |
88 } | |
89 | |
90 inline static int stream_eof(stream_t *s){ | |
91 return s->eof; | |
92 } | |
93 | |
94 inline static int stream_tell(stream_t *s){ | |
95 return s->pos+s->buf_pos-s->buf_len; | |
96 } | |
97 | |
98 inline static int stream_seek(stream_t *s,unsigned int pos){ | |
99 | |
100 // if(verbose>=3) printf("seek to 0x%X\n",pos); | |
101 | |
102 if(pos<s->pos){ | |
103 int x=pos-(s->pos-s->buf_len); | |
104 if(x>=0){ | |
105 s->buf_pos=x; | |
106 // putchar('*');fflush(stdout); | |
107 return 1; | |
108 } | |
109 } | |
110 | |
111 return stream_seek_long(s,pos); | |
112 } | |
113 | |
114 inline static void stream_skip(stream_t *s,int len){ | |
692 | 115 if(len<0 || (len>2*STREAM_BUFFER_SIZE && s->type!=STREAMTYPE_STREAM)){ |
578 | 116 // negative or big skip! |
117 stream_seek(s,stream_tell(s)+len); | |
118 return; | |
119 } | |
120 while(len>0){ | |
121 int x=s->buf_len-s->buf_pos; | |
122 if(x==0){ | |
123 if(!stream_fill_buffer(s)) return; // EOF | |
124 x=s->buf_len-s->buf_pos; | |
125 } | |
126 if(x>len) x=len; | |
127 //memcpy(mem,&s->buf[s->buf_pos],x); | |
128 s->buf_pos+=x; len-=x; | |
129 } | |
130 } | |
131 | |
132 void stream_reset(stream_t *s); | |
133 stream_t* new_stream(int fd,int type); | |
134 void free_stream(stream_t *s); | |
135 | |
998
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
136 |
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
137 #endif // __STREAM_H |