16 static struct stream_priv_s
{
19 } stream_priv_dflts
= {
23 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
25 static m_option_t stream_opts_fields
[] = {
26 {"string", ST_OFF(filename
), CONF_TYPE_STRING
, 0, 0 ,0, NULL
},
27 {"filename", ST_OFF(filename2
), CONF_TYPE_STRING
, 0, 0 ,0, NULL
},
28 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
30 static struct m_struct_st stream_opts
= {
32 sizeof(struct stream_priv_s
),
37 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
38 int r
= read(s
->fd
,buffer
,max_len
);
39 return (r
<= 0) ? -1 : r
;
42 static int write_buffer(stream_t
*s
, char* buffer
, int len
) {
43 int r
= write(s
->fd
,buffer
,len
);
44 return (r
<= 0) ? -1 : r
;
47 static int seek(stream_t
*s
,off_t newpos
) {
49 if(lseek(s
->fd
,s
->pos
,SEEK_SET
)<0) {
56 static int seek_forward(stream_t
*s
,off_t newpos
) {
58 mp_msg(MSGT_STREAM
,MSGL_INFO
,"Cannot seek backward in linear streams!\n");
62 int len
=s
->fill_buffer(s
,s
->buffer
,STREAM_BUFFER_SIZE
);
63 if(len
<=0){ s
->eof
=1; s
->buf_pos
=s
->buf_len
=0; break; } // EOF
71 static int control(stream_t
*s
, int cmd
, void *arg
) {
73 case STREAM_CTRL_GET_SIZE
: {
76 size
= lseek(s
->fd
, 0, SEEK_END
);
77 lseek(s
->fd
, s
->pos
, SEEK_SET
);
78 if(size
!= (off_t
)-1) {
79 *((off_t
*)arg
) = size
;
84 return STREAM_UNSUPORTED
;
87 static int open_f(stream_t
*stream
,int mode
, void* opts
, int* file_format
) {
91 unsigned char *filename
;
92 struct stream_priv_s
* p
= (struct stream_priv_s
*)opts
;
94 if(mode
== STREAM_READ
)
96 else if(mode
== STREAM_WRITE
)
99 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[file] Unknown open mode %d\n",mode
);
100 m_struct_free(&stream_opts
,opts
);
101 return STREAM_UNSUPORTED
;
105 filename
= p
->filename
;
106 else if(p
->filename2
)
107 filename
= p
->filename2
;
111 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[file] No filename\n");
112 m_struct_free(&stream_opts
,opts
);
116 #if defined(__CYGWIN__)|| defined(__MINGW32__)
120 if(!strcmp(filename
,"-")){
121 if(mode
== STREAM_READ
) {
123 mp_msg(MSGT_OPEN
,MSGL_INFO
,MSGTR_ReadSTDIN
);
126 setmode(fileno(stdin
),O_BINARY
);
129 mp_msg(MSGT_OPEN
,MSGL_INFO
,"Writing to stdout\n");
132 setmode(fileno(stdout
),O_BINARY
);
136 if(mode
== STREAM_READ
)
139 mode_t openmode
= S_IRUSR
|S_IWUSR
;
141 openmode
|= S_IRGRP
|S_IWGRP
|S_IROTH
|S_IWOTH
;
143 f
=open(filename
,m
, openmode
);
146 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_FileNotFound
,filename
);
147 m_struct_free(&stream_opts
,opts
);
152 len
=lseek(f
,0,SEEK_END
); lseek(f
,0,SEEK_SET
);
154 if(f
==0 || len
== -1) {
158 if(mode
== STREAM_READ
) stream
->seek
= seek_forward
;
159 stream
->type
= STREAMTYPE_STREAM
; // Must be move to STREAMTYPE_FILE
160 stream
->flags
|= STREAM_SEEK_FW
;
161 } else if(len
>= 0) {
163 stream
->end_pos
= len
;
164 stream
->type
= STREAMTYPE_FILE
;
167 mp_msg(MSGT_OPEN
,MSGL_V
,"[file] File size is %"PRId64
" bytes\n", (int64_t)len
);
170 stream
->fill_buffer
= fill_buffer
;
171 stream
->write_buffer
= write_buffer
;
172 stream
->control
= control
;
174 m_struct_free(&stream_opts
,opts
);
178 stream_info_t stream_info_file
= {
182 "based on the code from ??? (probably Arpi)",
184 { "file", "", NULL
},
186 1 // Urls are an option string