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