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