annotate libmpdemux/stream.h @ 2790:98769cea155c

added tv subsystem
author alex
date Fri, 09 Nov 2001 23:46:06 +0000
parents 66837325b929
children bc6cb25ad067
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
3
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
4 #define STREAM_BUFFER_SIZE 2048
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
5
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
6 #define STREAMTYPE_FILE 0
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
7 #define STREAMTYPE_VCD 1
692
14a2f35921a0 allow playing from stdin
arpi_esp
parents: 598
diff changeset
8 #define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for stdin)
1594
dbb3496efe01 new type: DVD
arpi
parents: 1491
diff changeset
9 #define STREAMTYPE_DVD 3
2144
99f079ff9374 new_memory_stream() added
arpi
parents: 1594
diff changeset
10 #define STREAMTYPE_MEMORY 4
2790
98769cea155c added tv subsystem
alex
parents: 2555
diff changeset
11 #define STREAMTYPE_TV 5
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
12
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
13 #define VCD_SECTOR_SIZE 2352
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
14 #define VCD_SECTOR_OFFS 24
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
15 #define VCD_SECTOR_DATA 2324
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
16
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
17 int vcd_seek_to_track(int fd,int track);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
18 void vcd_read_toc(int fd);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
19
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
20 #ifdef VCD_CACHE
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
21 void vcd_cache_init(int s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
22 #endif
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
23
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
24 typedef struct {
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
25 int fd;
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
26 off_t pos;
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
27 int eof;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
28 int type; // 0=file 1=VCD
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
29 unsigned int buf_pos,buf_len;
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
30 off_t start_pos,end_pos;
2322
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
31 unsigned int cache_pid;
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
32 void* cache_data;
2144
99f079ff9374 new_memory_stream() added
arpi
parents: 1594
diff changeset
33 void* priv; // used for DVD
583
da08ded03883 silly bug fixed - badly allocated stream buffer
arpi_esp
parents: 578
diff changeset
34 unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE];
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
35 } stream_t;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
36
2322
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
37 #ifdef USE_STREAM_CACHE
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
38 void stream_enable_cache(stream_t *s,int size);
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
39 #else
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
40 // no cache
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
41 #define cache_stream_fill_buffer(x) stream_fill_buffer(x)
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
42 #define cache_stream_seek_long(x,y) stream_seek_long(x,y)
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
43 #define stream_enable_cache(x,y)
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
44 #endif
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
45
2322
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
46 int cache_stream_fill_buffer(stream_t *s);
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
47 int cache_stream_seek_long(stream_t *s,off_t pos);
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
48
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
49 inline static int stream_read_char(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
50 return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]:
2322
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
51 (cache_stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256);
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
52 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
53 // stream_fill_buffer(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
54 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
55 // return 0; // EOF
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
56 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
57
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
58 inline static unsigned int stream_read_word(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
59 int x,y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
60 x=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
61 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
62 return (x<<8)|y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
63 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
64
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
65 inline static unsigned int stream_read_dword(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
66 unsigned int y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
67 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
68 y=(y<<8)|stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
69 y=(y<<8)|stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
70 y=(y<<8)|stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
71 return y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
72 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
73
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
74 inline static unsigned int stream_read_word_le(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
75 int x,y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
76 x=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
77 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
78 return (y<<8)|x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
79 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
80
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
81 inline static unsigned int stream_read_dword_le(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
82 unsigned int y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
83 y=stream_read_char(s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
84 y|=stream_read_char(s)<<8;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
85 y|=stream_read_char(s)<<16;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
86 y|=stream_read_char(s)<<24;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
87 return y;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
88 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
89
2347
f6a10f4b6119 stream_read() now returns no. of bytes readed
arpi
parents: 2322
diff changeset
90 inline static int stream_read(stream_t *s,char* mem,int total){
f6a10f4b6119 stream_read() now returns no. of bytes readed
arpi
parents: 2322
diff changeset
91 int len=total;
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
92 while(len>0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
93 int x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
94 x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
95 if(x==0){
2347
f6a10f4b6119 stream_read() now returns no. of bytes readed
arpi
parents: 2322
diff changeset
96 if(!cache_stream_fill_buffer(s)) return total-len; // EOF
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
97 x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
98 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
99 if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n");
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
100 if(x>len) x=len;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
101 memcpy(mem,&s->buffer[s->buf_pos],x);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
102 s->buf_pos+=x; mem+=x; len-=x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
103 }
2347
f6a10f4b6119 stream_read() now returns no. of bytes readed
arpi
parents: 2322
diff changeset
104 return total;
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
105 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
106
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
107 inline static int stream_eof(stream_t *s){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
108 return s->eof;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
109 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
110
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
111 inline static off_t stream_tell(stream_t *s){
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
112 return s->pos+s->buf_pos-s->buf_len;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
113 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
114
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
115 inline static int stream_seek(stream_t *s,off_t pos){
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
116
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
117 // if(verbose>=3) printf("seek to 0x%qX\n",(long long)pos);
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
118
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
119 if(pos<s->pos){
1428
a90d889eb649 largefile patch by Stephen Davies <steve@daviesfam.org>
arpi
parents: 998
diff changeset
120 off_t x=pos-(s->pos-s->buf_len);
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
121 if(x>=0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
122 s->buf_pos=x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
123 // putchar('*');fflush(stdout);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
124 return 1;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
125 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
126 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
127
2322
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
128 return cache_stream_seek_long(s,pos);
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
129 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
130
1491
41e82ba06d1b return type of stream_seek changed void->int
arpi
parents: 1428
diff changeset
131 inline static int stream_skip(stream_t *s,int len){
692
14a2f35921a0 allow playing from stdin
arpi_esp
parents: 598
diff changeset
132 if(len<0 || (len>2*STREAM_BUFFER_SIZE && s->type!=STREAMTYPE_STREAM)){
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
133 // negative or big skip!
1491
41e82ba06d1b return type of stream_seek changed void->int
arpi
parents: 1428
diff changeset
134 return stream_seek(s,stream_tell(s)+len);
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
135 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
136 while(len>0){
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
137 int x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
138 if(x==0){
2322
e22ec6fce385 cache2 support
arpi
parents: 2310
diff changeset
139 if(!cache_stream_fill_buffer(s)) return 0; // EOF
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
140 x=s->buf_len-s->buf_pos;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
141 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
142 if(x>len) x=len;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
143 //memcpy(mem,&s->buf[s->buf_pos],x);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
144 s->buf_pos+=x; len-=x;
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
145 }
1491
41e82ba06d1b return type of stream_seek changed void->int
arpi
parents: 1428
diff changeset
146 return 1;
578
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
147 }
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
148
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
149 void stream_reset(stream_t *s);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
150 stream_t* new_stream(int fd,int type);
c2377cd0069f something moved to brand new stream.h
arpi_esp
parents:
diff changeset
151 void free_stream(stream_t *s);
2144
99f079ff9374 new_memory_stream() added
arpi
parents: 1594
diff changeset
152 stream_t* new_memory_stream(unsigned char* data,int len);
2555
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
153 stream_t* open_stream(char* filename,int vcd_track,int* file_format);
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
154
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
155 //#ifdef USE_DVDREAD
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
156 extern int dvd_title;
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
157 extern int dvd_chapter;
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
158 extern int dvd_angle;
66837325b929 config.h cleanup, few things added to steram/demuxer headers
arpi
parents: 2347
diff changeset
159 //#endif
998
8c83e3ff26cc Added ifndef to prevent multiple header file inclusion.
bertrand
parents: 692
diff changeset
160
8c83e3ff26cc Added ifndef to prevent multiple header file inclusion.
bertrand
parents: 692
diff changeset
161 #endif // __STREAM_H