Mercurial > mplayer.hg
annotate libmpdemux/stream_file.c @ 16032:c5a629a2f33c
Forgotten doxygen comments
author | reimar |
---|---|
date | Wed, 20 Jul 2005 17:14:45 +0000 |
parents | 7c272bfba96f |
children | ec02252fbaa6 |
rev | line source |
---|---|
9794 | 1 |
2 #include "config.h" | |
3 | |
4 #include <sys/types.h> | |
5 #include <sys/stat.h> | |
6 #include <fcntl.h> | |
7 #include <unistd.h> | |
8 | |
9 #include "mp_msg.h" | |
10 #include "stream.h" | |
11 #include "help_mp.h" | |
12 #include "../m_option.h" | |
13 #include "../m_struct.h" | |
14 | |
15 static struct stream_priv_s { | |
16 char* filename; | |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
17 char *filename2; |
9794 | 18 } stream_priv_dflts = { |
15452 | 19 NULL, NULL |
9794 | 20 }; |
21 | |
22 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
23 /// URL definition | |
24 static m_option_t stream_opts_fields[] = { | |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
25 {"string", ST_OFF(filename), CONF_TYPE_STRING, 0, 0 ,0, NULL}, |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
26 {"filename", ST_OFF(filename2), CONF_TYPE_STRING, 0, 0 ,0, NULL}, |
9794 | 27 { NULL, NULL, 0, 0, 0, 0, NULL } |
28 }; | |
29 static struct m_struct_st stream_opts = { | |
30 "file", | |
31 sizeof(struct stream_priv_s), | |
32 &stream_priv_dflts, | |
33 stream_opts_fields | |
34 }; | |
35 | |
36 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
37 int r = read(s->fd,buffer,max_len); | |
38 return (r <= 0) ? -1 : r; | |
39 } | |
40 | |
41 static int write_buffer(stream_t *s, char* buffer, int len) { | |
42 int r = write(s->fd,buffer,len); | |
43 return (r <= 0) ? -1 : r; | |
44 } | |
45 | |
46 static int seek(stream_t *s,off_t newpos) { | |
47 s->pos = newpos; | |
48 if(lseek(s->fd,s->pos,SEEK_SET)<0) { | |
49 s->eof=1; | |
50 return 0; | |
51 } | |
52 return 1; | |
53 } | |
54 | |
55 static int seek_forward(stream_t *s,off_t newpos) { | |
56 if(newpos<s->pos){ | |
57 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); | |
58 return 0; | |
59 } | |
60 while(s->pos<newpos){ | |
12018 | 61 int len=s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE); |
62 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; break; } // EOF | |
63 s->buf_pos=0; | |
64 s->buf_len=len; | |
65 s->pos+=len; | |
9794 | 66 } |
67 return 1; | |
68 } | |
69 | |
70 static int open_f(stream_t *stream,int mode, void* opts, int* file_format) { | |
71 int f; | |
72 mode_t m = 0; | |
73 off_t len; | |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
74 unsigned char *filename; |
9794 | 75 struct stream_priv_s* p = (struct stream_priv_s*)opts; |
76 | |
77 if(mode == STREAM_READ) | |
78 m = O_RDONLY; | |
79 else if(mode == STREAM_WRITE) | |
80 m = O_WRONLY; | |
81 else { | |
10608 | 82 mp_msg(MSGT_OPEN,MSGL_ERR, "[file] Unknown open mode %d\n",mode); |
9794 | 83 m_struct_free(&stream_opts,opts); |
84 return STREAM_UNSUPORTED; | |
85 } | |
86 | |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
87 if(p->filename) |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
88 filename = p->filename; |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
89 else if(p->filename2) |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
90 filename = p->filename2; |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
91 else |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
92 filename = NULL; |
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
93 if(!filename) { |
9849 | 94 mp_msg(MSGT_OPEN,MSGL_ERR, "[file] No filename\n"); |
95 m_struct_free(&stream_opts,opts); | |
96 return STREAM_ERROR; | |
97 } | |
98 | |
9794 | 99 #if defined(__CYGWIN__)|| defined(__MINGW32__) |
100 m |= O_BINARY; | |
101 #endif | |
102 | |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
103 if(!strcmp(filename,"-")){ |
9794 | 104 if(mode == STREAM_READ) { |
105 // read from stdin | |
106 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN); | |
107 f=0; // 0=stdin | |
12921 | 108 #ifdef __MINGW32__ |
109 setmode(fileno(stdin),O_BINARY); | |
110 #endif | |
9794 | 111 } else { |
112 mp_msg(MSGT_OPEN,MSGL_INFO,"Writing to stdout\n"); | |
113 f=1; | |
12921 | 114 #ifdef __MINGW32__ |
115 setmode(fileno(stdout),O_BINARY); | |
116 #endif | |
9794 | 117 } |
118 } else { | |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
119 f=open(filename,m); |
9794 | 120 if(f<0) { |
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
121 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename); |
9794 | 122 m_struct_free(&stream_opts,opts); |
9827 | 123 return STREAM_ERROR; |
9794 | 124 } |
125 } | |
126 | |
127 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET); | |
12921 | 128 #ifdef __MINGW32__ |
129 if(f==0 || len == -1) { | |
130 #else | |
9794 | 131 if(len == -1) { |
12921 | 132 #endif |
9794 | 133 stream->seek = seek_forward; |
134 stream->type = STREAMTYPE_STREAM; // Must be move to STREAMTYPE_FILE | |
135 stream->flags |= STREAM_SEEK_FW; | |
136 } else if(len >= 0) { | |
137 stream->seek = seek; | |
138 stream->end_pos = len; | |
139 stream->type = STREAMTYPE_FILE; | |
140 } | |
141 | |
142 #ifdef _LARGEFILE_SOURCE | |
143 mp_msg(MSGT_OPEN,MSGL_V,"[file] File size is %lld bytes\n", (long long)len); | |
144 #else | |
145 mp_msg(MSGT_OPEN,MSGL_V,"[file] File size is %u bytes\n", (unsigned int)len); | |
146 #endif | |
147 | |
148 stream->fd = f; | |
149 stream->fill_buffer = fill_buffer; | |
150 stream->write_buffer = write_buffer; | |
151 | |
152 m_struct_free(&stream_opts,opts); | |
153 return STREAM_OK; | |
154 } | |
155 | |
156 stream_info_t stream_info_file = { | |
157 "File", | |
158 "file", | |
159 "Albeu", | |
160 "based on the code from ??? (probably Arpi)", | |
161 open_f, | |
162 { "file", "", NULL }, | |
163 &stream_opts, | |
164 1 // Urls are an option string | |
165 }; |