1 #ifndef MPLAYER_STREAM_H
2 #define MPLAYER_STREAM_H
10 #define STREAMTYPE_DUMMY -1 // for placeholders, when the actual reading is handled in the demuxer
11 #define STREAMTYPE_FILE 0 // read from seekable file
12 #define STREAMTYPE_VCD 1 // raw mode-2 CDROM reading, 2324 bytes/sector
13 #define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for net/stdin)
14 #define STREAMTYPE_DVD 3 // libdvdread
15 #define STREAMTYPE_MEMORY 4 // read data from memory area
16 #define STREAMTYPE_PLAYLIST 6 // FIXME!!! same as STREAMTYPE_FILE now
17 #define STREAMTYPE_DS 8 // read from a demuxer stream
18 #define STREAMTYPE_DVDNAV 9 // we cannot safely "seek" in this...
19 #define STREAMTYPE_CDDA 10 // raw audio CD reader
20 #define STREAMTYPE_SMB 11 // smb:// url, using libsmbclient (samba)
21 #define STREAMTYPE_VCDBINCUE 12 // vcd directly from bin/cue files
22 #define STREAMTYPE_DVB 13
23 #define STREAMTYPE_VSTREAM 14
24 #define STREAMTYPE_SDP 15
25 #define STREAMTYPE_PVR 16
26 #define STREAMTYPE_TV 17
27 #define STREAMTYPE_MF 18
28 #define STREAMTYPE_RADIO 19
30 #define STREAM_BUFFER_SIZE 2048
32 #define VCD_SECTOR_SIZE 2352
33 #define VCD_SECTOR_OFFS 24
34 #define VCD_SECTOR_DATA 2324
36 /// atm it will always use mode == STREAM_READ
37 /// streams that use the new api should check the mode at open
39 #define STREAM_WRITE 1
40 /// Seek flags, if not mannualy set and s->seek isn't NULL
41 /// MP_STREAM_SEEK is automaticly set
42 #define MP_STREAM_SEEK_BW 2
43 #define MP_STREAM_SEEK_FW 4
44 #define MP_STREAM_SEEK (MP_STREAM_SEEK_BW|MP_STREAM_SEEK_FW)
45 /** This is a HACK for live555 that does not respect the
46 separation between stream an demuxer and thus is not
47 actually a stream cache can not be used */
48 #define STREAM_NON_CACHEABLE 8
50 //////////// Open return code
51 #define STREAM_REDIRECTED -2
52 /// This can't open the requested protocol (used by stream wich have a
53 /// * protocol when they don't know the requested protocol)
54 #define STREAM_UNSUPPORTED -1
55 #define STREAM_ERROR 0
58 #define MAX_STREAM_PROTOCOLS 10
60 #define STREAM_CTRL_RESET 0
61 #define STREAM_CTRL_GET_TIME_LENGTH 1
62 #define STREAM_CTRL_SEEK_TO_CHAPTER 2
63 #define STREAM_CTRL_GET_CURRENT_CHAPTER 3
64 #define STREAM_CTRL_GET_NUM_CHAPTERS 4
65 #define STREAM_CTRL_GET_CURRENT_TIME 5
66 #define STREAM_CTRL_SEEK_TO_TIME 6
67 #define STREAM_CTRL_GET_SIZE 7
68 #define STREAM_CTRL_GET_ASPECT_RATIO 8
69 #define STREAM_CTRL_GET_NUM_ANGLES 9
70 #define STREAM_CTRL_GET_ANGLE 10
71 #define STREAM_CTRL_SET_ANGLE 11
79 typedef struct stream_info_st
{
84 /// mode isn't used atm (ie always READ) but it shouldn't be ignored
85 /// opts is at least in it's defaults settings and may have been
86 /// altered by url parsing if enabled and the options string parsing.
87 int (*open
)(struct stream_st
* st
, int mode
, void* opts
, int* file_format
);
88 const char* protocols
[MAX_STREAM_PROTOCOLS
];
90 int opts_url
; /* If this is 1 we will parse the url as an option string
91 * too. Otherwise options are only parsed from the
92 * options string given to open_stream_plugin */
95 typedef struct stream_st
{
97 int (*fill_buffer
)(struct stream_st
*s
, char* buffer
, int max_len
);
99 int (*write_buffer
)(struct stream_st
*s
, char* buffer
, int len
);
101 int (*seek
)(struct stream_st
*s
,off_t pos
);
103 // Will be later used to let streams like dvd and cdda report
104 // their structure (ie tracks, chapters, etc)
105 int (*control
)(struct stream_st
*s
,int cmd
,void* arg
);
107 void (*close
)(struct stream_st
*s
);
109 int fd
; // file descriptor, see man open(2)
110 int type
; // see STREAMTYPE_*
112 int sector_size
; // sector size (seek will be aligned on this size if non 0)
113 unsigned int buf_pos
,buf_len
;
114 off_t pos
,start_pos
,end_pos
;
116 int mode
; //STREAM_READ or STREAM_WRITE
117 unsigned int cache_pid
;
119 void* priv
; // used for DVD, TV, RTSP etc
120 char* url
; // strdup() of filename/url
121 #ifdef CONFIG_NETWORK
122 streaming_ctrl_t
*streaming_ctrl
;
124 unsigned char buffer
[STREAM_BUFFER_SIZE
>VCD_SECTOR_SIZE
?STREAM_BUFFER_SIZE
:VCD_SECTOR_SIZE
];
127 #ifdef CONFIG_STREAM_CACHE
128 int stream_enable_cache(stream_t
*stream
,int size
,int min
,int prefill
);
129 int cache_stream_fill_buffer(stream_t
*s
);
130 int cache_stream_seek_long(stream_t
*s
,off_t pos
);
132 // no cache, define wrappers:
133 int stream_fill_buffer(stream_t
*s
);
134 int stream_seek_long(stream_t
*s
,off_t pos
);
135 #define cache_stream_fill_buffer(x) stream_fill_buffer(x)
136 #define cache_stream_seek_long(x,y) stream_seek_long(x,y)
137 #define stream_enable_cache(x,y,z,w) 1
139 void fixup_network_stream_cache(stream_t
*stream
);
140 int stream_write_buffer(stream_t
*s
, unsigned char *buf
, int len
);
142 inline static int stream_read_char(stream_t
*s
){
143 return (s
->buf_pos
<s
->buf_len
)?s
->buffer
[s
->buf_pos
++]:
144 (cache_stream_fill_buffer(s
)?s
->buffer
[s
->buf_pos
++]:-256);
145 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
146 // stream_fill_buffer(s);
147 // if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++];
151 inline static unsigned int stream_read_word(stream_t
*s
){
153 x
=stream_read_char(s
);
154 y
=stream_read_char(s
);
158 inline static unsigned int stream_read_dword(stream_t
*s
){
160 y
=stream_read_char(s
);
161 y
=(y
<<8)|stream_read_char(s
);
162 y
=(y
<<8)|stream_read_char(s
);
163 y
=(y
<<8)|stream_read_char(s
);
167 #define stream_read_fourcc stream_read_dword_le
169 inline static unsigned int stream_read_word_le(stream_t
*s
){
171 x
=stream_read_char(s
);
172 y
=stream_read_char(s
);
176 inline static unsigned int stream_read_dword_le(stream_t
*s
){
178 y
=stream_read_char(s
);
179 y
|=stream_read_char(s
)<<8;
180 y
|=stream_read_char(s
)<<16;
181 y
|=stream_read_char(s
)<<24;
185 inline static uint64_t stream_read_qword(stream_t
*s
){
187 y
= 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
);
191 y
=(y
<<8)|stream_read_char(s
);
192 y
=(y
<<8)|stream_read_char(s
);
193 y
=(y
<<8)|stream_read_char(s
);
194 y
=(y
<<8)|stream_read_char(s
);
198 inline static uint64_t stream_read_qword_le(stream_t
*s
){
200 y
= stream_read_dword_le(s
);
201 y
|=(uint64_t)stream_read_dword_le(s
)<<32;
205 inline static unsigned int stream_read_int24(stream_t
*s
){
207 y
= stream_read_char(s
);
208 y
=(y
<<8)|stream_read_char(s
);
209 y
=(y
<<8)|stream_read_char(s
);
213 inline static int stream_read(stream_t
*s
,char* mem
,int total
){
217 x
=s
->buf_len
-s
->buf_pos
;
219 if(!cache_stream_fill_buffer(s
)) return total
-len
; // EOF
220 x
=s
->buf_len
-s
->buf_pos
;
222 if(s
->buf_pos
>s
->buf_len
) mp_msg(MSGT_DEMUX
, MSGL_WARN
, "stream_read: WARNING! s->buf_pos>s->buf_len\n");
224 memcpy(mem
,&s
->buffer
[s
->buf_pos
],x
);
225 s
->buf_pos
+=x
; mem
+=x
; len
-=x
;
230 inline static unsigned char* stream_read_line(stream_t
*s
,unsigned char* mem
, int max
) {
232 unsigned char* end
,*ptr
= mem
;
234 len
= s
->buf_len
-s
->buf_pos
;
235 // try to fill the buffer
237 (!cache_stream_fill_buffer(s
) ||
238 (len
= s
->buf_len
-s
->buf_pos
) <= 0)) break;
239 end
= (unsigned char*) memchr((void*)(s
->buffer
+s
->buf_pos
),'\n',len
);
240 if(end
) len
= end
- (s
->buffer
+s
->buf_pos
) + 1;
241 if(len
> 0 && max
> 1) {
242 int l
= len
> max
-1 ? max
-1 : len
;
243 memcpy(ptr
,s
->buffer
+s
->buf_pos
,l
);
249 if(s
->eof
&& ptr
== mem
) return NULL
;
250 if(max
> 0) ptr
[0] = 0;
255 inline static int stream_eof(stream_t
*s
){
259 inline static off_t
stream_tell(stream_t
*s
){
260 return s
->pos
+s
->buf_pos
-s
->buf_len
;
263 inline static int stream_seek(stream_t
*s
,off_t pos
){
265 mp_dbg(MSGT_DEMUX
, MSGL_DBG3
, "seek to 0x%qX\n",(long long)pos
);
268 off_t x
=pos
-(s
->pos
-s
->buf_len
);
271 // putchar('*');fflush(stdout);
276 return cache_stream_seek_long(s
,pos
);
279 inline static int stream_skip(stream_t
*s
,off_t len
){
280 if( (len
<0 && (s
->flags
& MP_STREAM_SEEK_BW
)) || (len
>2*STREAM_BUFFER_SIZE
&& (s
->flags
& MP_STREAM_SEEK_FW
)) ) {
281 // negative or big skip!
282 return stream_seek(s
,stream_tell(s
)+len
);
285 int x
=s
->buf_len
-s
->buf_pos
;
287 if(!cache_stream_fill_buffer(s
)) return 0; // EOF
288 x
=s
->buf_len
-s
->buf_pos
;
291 //memcpy(mem,&s->buf[s->buf_pos],x);
292 s
->buf_pos
+=x
; len
-=x
;
297 void stream_reset(stream_t
*s
);
298 int stream_control(stream_t
*s
, int cmd
, void *arg
);
299 stream_t
* new_stream(int fd
,int type
);
300 void free_stream(stream_t
*s
);
301 stream_t
* new_memory_stream(unsigned char* data
,int len
);
302 stream_t
* open_stream(char* filename
,char** options
,int* file_format
);
303 stream_t
* open_stream_full(char* filename
,int mode
, char** options
, int* file_format
);
304 stream_t
* open_output_stream(char* filename
,char** options
);
305 /// Set the callback to be used by libstream to check for user
306 /// interruption during long blocking operations (cache filling, etc).
307 void stream_set_interrupt_callback(int (*cb
)(int));
308 /// Call the interrupt checking callback if there is one.
309 int stream_check_interrupt(int time
);
311 extern int dvd_title
;
312 extern int dvd_chapter
;
313 extern int dvd_last_chapter
;
314 extern int dvd_angle
;
316 extern char * audio_stream
;
319 int id
; // 0 - 31 mpeg; 128 - 159 ac3; 160 - 191 pcm
325 #endif /* MPLAYER_STREAM_H */