Mercurial > mplayer.hg
annotate stream.h @ 1459:622c504f36ef
printf stuff moved seek.c->mplayer.c, resetting drop_frame_cnt after seek
author | arpi |
---|---|
date | Tue, 07 Aug 2001 16:03:30 +0000 |
parents | a90d889eb649 |
children | 41e82ba06d1b |
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; | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
23 off_t pos; |
578 | 24 int eof; |
25 int type; // 0=file 1=VCD | |
26 unsigned int buf_pos,buf_len; | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
27 off_t 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); | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
32 |
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
33 int stream_seek_long(stream_t *s,off_t pos); |
578 | 34 |
35 inline static int stream_read_char(stream_t *s){ | |
36 return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]: | |
37 (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); | |
38 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; | |
39 // stream_fill_buffer(s); | |
40 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; | |
41 // return 0; // EOF | |
42 } | |
43 | |
44 inline static unsigned int stream_read_word(stream_t *s){ | |
45 int x,y; | |
46 x=stream_read_char(s); | |
47 y=stream_read_char(s); | |
48 return (x<<8)|y; | |
49 } | |
50 | |
51 inline static unsigned int stream_read_dword(stream_t *s){ | |
52 unsigned int y; | |
53 y=stream_read_char(s); | |
54 y=(y<<8)|stream_read_char(s); | |
55 y=(y<<8)|stream_read_char(s); | |
56 y=(y<<8)|stream_read_char(s); | |
57 return y; | |
58 } | |
59 | |
60 inline static unsigned int stream_read_word_le(stream_t *s){ | |
61 int x,y; | |
62 x=stream_read_char(s); | |
63 y=stream_read_char(s); | |
64 return (y<<8)|x; | |
65 } | |
66 | |
67 inline static unsigned int stream_read_dword_le(stream_t *s){ | |
68 unsigned int y; | |
69 y=stream_read_char(s); | |
70 y|=stream_read_char(s)<<8; | |
71 y|=stream_read_char(s)<<16; | |
72 y|=stream_read_char(s)<<24; | |
73 return y; | |
74 } | |
75 | |
76 inline static void stream_read(stream_t *s,char* mem,int len){ | |
77 while(len>0){ | |
78 int x; | |
79 x=s->buf_len-s->buf_pos; | |
80 if(x==0){ | |
81 if(!stream_fill_buffer(s)) return; // EOF | |
82 x=s->buf_len-s->buf_pos; | |
83 } | |
84 if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n"); | |
85 if(x>len) x=len; | |
86 memcpy(mem,&s->buffer[s->buf_pos],x); | |
87 s->buf_pos+=x; mem+=x; len-=x; | |
88 } | |
89 } | |
90 | |
91 inline static int stream_eof(stream_t *s){ | |
92 return s->eof; | |
93 } | |
94 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
95 inline static off_t stream_tell(stream_t *s){ |
578 | 96 return s->pos+s->buf_pos-s->buf_len; |
97 } | |
98 | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
99 inline static int stream_seek(stream_t *s,off_t pos){ |
578 | 100 |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
101 // if(verbose>=3) printf("seek to 0x%qX\n",(long long)pos); |
578 | 102 |
103 if(pos<s->pos){ | |
1428
a90d889eb649
largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents:
998
diff
changeset
|
104 off_t x=pos-(s->pos-s->buf_len); |
578 | 105 if(x>=0){ |
106 s->buf_pos=x; | |
107 // putchar('*');fflush(stdout); | |
108 return 1; | |
109 } | |
110 } | |
111 | |
112 return stream_seek_long(s,pos); | |
113 } | |
114 | |
115 inline static void stream_skip(stream_t *s,int len){ | |
692 | 116 if(len<0 || (len>2*STREAM_BUFFER_SIZE && s->type!=STREAMTYPE_STREAM)){ |
578 | 117 // negative or big skip! |
118 stream_seek(s,stream_tell(s)+len); | |
119 return; | |
120 } | |
121 while(len>0){ | |
122 int x=s->buf_len-s->buf_pos; | |
123 if(x==0){ | |
124 if(!stream_fill_buffer(s)) return; // EOF | |
125 x=s->buf_len-s->buf_pos; | |
126 } | |
127 if(x>len) x=len; | |
128 //memcpy(mem,&s->buf[s->buf_pos],x); | |
129 s->buf_pos+=x; len-=x; | |
130 } | |
131 } | |
132 | |
133 void stream_reset(stream_t *s); | |
134 stream_t* new_stream(int fd,int type); | |
135 void free_stream(stream_t *s); | |
136 | |
998
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
137 |
8c83e3ff26cc
Added ifndef to prevent multiple header file inclusion.
bertrand
parents:
692
diff
changeset
|
138 #endif // __STREAM_H |