1 #ifndef MPLAYER_STREAM_H
2 #define MPLAYER_STREAM_H
9 #define STREAMTYPE_DUMMY -1 // for placeholders, when the actual reading is handled in the demuxer
10 #define STREAMTYPE_FILE 0 // read from seekable file
11 #define STREAMTYPE_VCD 1 // raw mode-2 CDROM reading, 2324 bytes/sector
12 #define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for net/stdin)
13 #define STREAMTYPE_DVD 3 // libdvdread
14 #define STREAMTYPE_MEMORY 4 // read data from memory area
15 #define STREAMTYPE_PLAYLIST 6 // FIXME!!! same as STREAMTYPE_FILE now
16 #define STREAMTYPE_DS 8 // read from a demuxer stream
17 #define STREAMTYPE_DVDNAV 9 // we cannot safely "seek" in this...
18 #define STREAMTYPE_CDDA 10 // raw audio CD reader
19 #define STREAMTYPE_SMB 11 // smb:// url, using libsmbclient (samba)
20 #define STREAMTYPE_VCDBINCUE 12 // vcd directly from bin/cue files
21 #define STREAMTYPE_DVB 13
22 #define STREAMTYPE_VSTREAM 14
23 #define STREAMTYPE_SDP 15
24 #define STREAMTYPE_PVR 16
25 #define STREAMTYPE_TV 17
26 #define STREAMTYPE_MF 18
27 #define STREAMTYPE_RADIO 19
29 #define STREAM_BUFFER_SIZE 2048
31 #define VCD_SECTOR_SIZE 2352
32 #define VCD_SECTOR_OFFS 24
33 #define VCD_SECTOR_DATA 2324
35 /// atm it will always use mode == STREAM_READ
36 /// streams that use the new api should check the mode at open
38 #define STREAM_WRITE 1
39 /// Seek flags, if not mannualy set and s->seek isn't NULL
40 /// STREAM_SEEK is automaticly set
41 #define STREAM_SEEK_BW 2
42 #define STREAM_SEEK_FW 4
43 #define STREAM_SEEK (STREAM_SEEK_BW|STREAM_SEEK_FW)
45 //////////// Open return code
46 #define STREAM_REDIRECTED -2
47 /// This can't open the requested protocol (used by stream wich have a
48 /// * protocol when they don't know the requested protocol)
49 #define STREAM_UNSUPPORTED -1
50 #define STREAM_ERROR 0
53 #define MAX_STREAM_PROTOCOLS 10
55 #define STREAM_CTRL_RESET 0
56 #define STREAM_CTRL_GET_TIME_LENGTH 1
57 #define STREAM_CTRL_SEEK_TO_CHAPTER 2
58 #define STREAM_CTRL_GET_CURRENT_CHAPTER 3
59 #define STREAM_CTRL_GET_NUM_CHAPTERS 4
60 #define STREAM_CTRL_GET_CURRENT_TIME 5
61 #define STREAM_CTRL_SEEK_TO_TIME 6
62 #define STREAM_CTRL_GET_SIZE 7
63 #define STREAM_CTRL_GET_ASPECT_RATIO 8
64 #define STREAM_CTRL_GET_NUM_ANGLES 9
65 #define STREAM_CTRL_GET_ANGLE 10
66 #define STREAM_CTRL_SET_ANGLE 11
74 typedef struct stream_info_st
{
79 /// mode isn't used atm (ie always READ) but it shouldn't be ignored
80 /// opts is at least in it's defaults settings and may have been
81 /// altered by url parsing if enabled and the options string parsing.
82 int (*open
)(struct stream
* st
, int mode
, void* opts
, int* file_format
);
83 const char* protocols
[MAX_STREAM_PROTOCOLS
];
85 int opts_url
; /* If this is 1 we will parse the url as an option string
86 * too. Otherwise options are only parsed from the
87 * options string given to open_stream_plugin */
90 typedef struct stream
{
92 int (*fill_buffer
)(struct stream
*s
, char* buffer
, int max_len
);
94 int (*write_buffer
)(struct stream
*s
, char* buffer
, int len
);
96 int (*seek
)(struct stream
*s
,off_t pos
);
98 // Will be later used to let streams like dvd and cdda report
99 // their structure (ie tracks, chapters, etc)
100 int (*control
)(struct stream
*s
,int cmd
,void* arg
);
102 void (*close
)(struct stream
*s
);
104 int fd
; // file descriptor, see man open(2)
105 int type
; // see STREAMTYPE_*
107 int sector_size
; // sector size (seek will be aligned on this size if non 0)
108 unsigned int buf_pos
,buf_len
;
109 off_t pos
,start_pos
,end_pos
;
111 int mode
; //STREAM_READ or STREAM_WRITE
112 unsigned int cache_pid
;
114 void* priv
; // used for DVD, TV, RTSP etc
115 char* url
; // strdup() of filename/url
117 #ifdef CONFIG_NETWORK
118 streaming_ctrl_t
*streaming_ctrl
;
120 unsigned char buffer
[STREAM_BUFFER_SIZE
>VCD_SECTOR_SIZE
?STREAM_BUFFER_SIZE
:VCD_SECTOR_SIZE
];
123 int stream_fill_buffer(stream_t
*s
);
124 int stream_seek_long(stream_t
*s
,off_t pos
);
125 #ifdef CONFIG_STREAM_CACHE
126 int stream_enable_cache(stream_t
*stream
,int size
,int min
,int prefill
);
127 int cache_stream_fill_buffer(stream_t
*s
);
128 int cache_stream_seek_long(stream_t
*s
,off_t pos
);
130 // no cache, define wrappers:
131 #define cache_stream_fill_buffer(x) stream_fill_buffer(x)
132 #define cache_stream_seek_long(x,y) stream_seek_long(x,y)
133 #define stream_enable_cache(x,y,z,w) 1
135 void fixup_network_stream_cache(stream_t
*stream
);
136 int stream_write_buffer(stream_t
*s
, unsigned char *buf
, int len
);
138 inline static int stream_read_char(stream_t
*s
){
139 return (s
->buf_pos
<s
->buf_len
)?s
->buffer
[s
->buf_pos
++]:
140 (cache_stream_fill_buffer(s
)?s
->buffer
[s
->buf_pos
++]:-256);
141 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
142 // stream_fill_buffer(s);
143 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
147 inline static unsigned int stream_read_word(stream_t
*s
){
149 x
=stream_read_char(s
);
150 y
=stream_read_char(s
);
154 inline static unsigned int stream_read_dword(stream_t
*s
){
156 y
=stream_read_char(s
);
157 y
=(y
<<8)|stream_read_char(s
);
158 y
=(y
<<8)|stream_read_char(s
);
159 y
=(y
<<8)|stream_read_char(s
);
163 #define stream_read_fourcc stream_read_dword_le
165 inline static unsigned int stream_read_word_le(stream_t
*s
){
167 x
=stream_read_char(s
);
168 y
=stream_read_char(s
);
172 inline static unsigned int stream_read_dword_le(stream_t
*s
){
174 y
=stream_read_char(s
);
175 y
|=stream_read_char(s
)<<8;
176 y
|=stream_read_char(s
)<<16;
177 y
|=stream_read_char(s
)<<24;
181 inline static uint64_t stream_read_qword(stream_t
*s
){
183 y
= stream_read_char(s
);
184 y
=(y
<<8)|stream_read_char(s
);
185 y
=(y
<<8)|stream_read_char(s
);
186 y
=(y
<<8)|stream_read_char(s
);
187 y
=(y
<<8)|stream_read_char(s
);
188 y
=(y
<<8)|stream_read_char(s
);
189 y
=(y
<<8)|stream_read_char(s
);
190 y
=(y
<<8)|stream_read_char(s
);
194 inline static uint64_t stream_read_qword_le(stream_t
*s
){
196 y
= stream_read_dword_le(s
);
197 y
|=(uint64_t)stream_read_dword_le(s
)<<32;
201 inline static unsigned int stream_read_int24(stream_t
*s
){
203 y
= stream_read_char(s
);
204 y
=(y
<<8)|stream_read_char(s
);
205 y
=(y
<<8)|stream_read_char(s
);
209 inline static int stream_read(stream_t
*s
,char* mem
,int total
){
213 x
=s
->buf_len
-s
->buf_pos
;
215 if(!cache_stream_fill_buffer(s
)) return total
-len
; // EOF
216 x
=s
->buf_len
-s
->buf_pos
;
218 if(s
->buf_pos
>s
->buf_len
) mp_msg(MSGT_DEMUX
, MSGL_WARN
, "stream_read: WARNING! s->buf_pos>s->buf_len\n");
220 memcpy(mem
,&s
->buffer
[s
->buf_pos
],x
);
221 s
->buf_pos
+=x
; mem
+=x
; len
-=x
;
226 inline static unsigned char* stream_read_line(stream_t
*s
,unsigned char* mem
, int max
) {
228 unsigned char* end
,*ptr
= mem
;;
230 len
= s
->buf_len
-s
->buf_pos
;
231 // try to fill the buffer
233 (!cache_stream_fill_buffer(s
) ||
234 (len
= s
->buf_len
-s
->buf_pos
) <= 0)) break;
235 end
= (unsigned char*) memchr((void*)(s
->buffer
+s
->buf_pos
),'\n',len
);
236 if(end
) len
= end
- (s
->buffer
+s
->buf_pos
) + 1;
237 if(len
> 0 && max
> 1) {
238 int l
= len
> max
-1 ? max
-1 : len
;
239 memcpy(ptr
,s
->buffer
+s
->buf_pos
,l
);
245 if(s
->eof
&& ptr
== mem
) return NULL
;
246 if(max
> 0) ptr
[0] = 0;
251 inline static int stream_eof(stream_t
*s
){
255 inline static off_t
stream_tell(stream_t
*s
){
256 return s
->pos
+s
->buf_pos
-s
->buf_len
;
259 inline static int stream_seek(stream_t
*s
,off_t pos
){
261 mp_dbg(MSGT_DEMUX
, MSGL_DBG3
, "seek to 0x%qX\n",(long long)pos
);
264 off_t x
=pos
-(s
->pos
-s
->buf_len
);
267 // putchar('*');fflush(stdout);
272 return cache_stream_seek_long(s
,pos
);
275 inline static int stream_skip(stream_t
*s
,off_t len
){
276 if( (len
<0 && (s
->flags
& STREAM_SEEK_BW
)) || (len
>2*STREAM_BUFFER_SIZE
&& (s
->flags
& STREAM_SEEK_FW
)) ) {
277 // negative or big skip!
278 return stream_seek(s
,stream_tell(s
)+len
);
281 int x
=s
->buf_len
-s
->buf_pos
;
283 if(!cache_stream_fill_buffer(s
)) return 0; // EOF
284 x
=s
->buf_len
-s
->buf_pos
;
287 //memcpy(mem,&s->buf[s->buf_pos],x);
288 s
->buf_pos
+=x
; len
-=x
;
294 void stream_reset(stream_t
*s
);
295 int stream_control(stream_t
*s
, int cmd
, void *arg
);
296 stream_t
* new_stream(int fd
,int type
);
297 void free_stream(stream_t
*s
);
298 stream_t
* new_memory_stream(unsigned char* data
,int len
);
299 stream_t
* open_stream(char* filename
, struct MPOpts
*options
,int* file_format
);
300 stream_t
* open_stream_full(char* filename
,int mode
, struct MPOpts
*options
, int* file_format
);
301 stream_t
* open_output_stream(char* filename
,struct MPOpts
*options
);
302 /// Set the callback to be used by libstream to check for user
303 /// interruption during long blocking operations (cache filling, etc).
305 void stream_set_interrupt_callback(int (*cb
)(struct input_ctx
*, int),
306 struct input_ctx
*ctx
);
307 /// Call the interrupt checking callback if there is one.
308 int stream_check_interrupt(int time
);
310 extern int dvd_title
;
311 extern int dvd_chapter
;
312 extern int dvd_last_chapter
;
313 extern int dvd_angle
;
315 extern char * audio_stream
;
318 int id
; // 0 - 31 mpeg; 128 - 159 ac3; 160 - 191 pcm
324 #endif /* MPLAYER_STREAM_H */