Mercurial > mplayer.hg
annotate stream/stream_file.c @ 37195:ac6c37d85d65 default tip
configure: Fix initialization of variable def_local_aligned_32
It contiained the #define of HAVE_LOCAL_ALIGNED_16 instead
of HAVE_LOCAL_ALIGNED_32.
| author | al |
|---|---|
| date | Sun, 28 Sep 2014 18:38:41 +0000 |
| parents | cb25e73ac822 |
| children |
| rev | line source |
|---|---|
|
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
1 /* |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
2 * This file is part of MPlayer. |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
3 * |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
7 * (at your option) any later version. |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
8 * |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
12 * GNU General Public License for more details. |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
13 * |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29920
diff
changeset
|
17 */ |
| 9794 | 18 |
| 19 #include "config.h" | |
| 20 | |
|
16748
ec02252fbaa6
we need stdio.h for SEEK_SET on mingw, patch by Zuxy <zuxy.meng at gmail.com>
faust3
parents:
15461
diff
changeset
|
21 #include <stdio.h> |
| 9794 | 22 #include <sys/types.h> |
| 23 #include <sys/stat.h> | |
| 24 #include <fcntl.h> | |
| 25 #include <unistd.h> | |
| 33759 | 26 #if HAVE_SETMODE |
| 27 #include <io.h> | |
| 28 #endif | |
|
35868
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
29 #ifdef __MINGW32__ |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
30 #include <windows.h> |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
31 #include <share.h> |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
32 #endif |
| 9794 | 33 |
| 34 #include "mp_msg.h" | |
| 35 #include "stream.h" | |
| 36 #include "help_mp.h" | |
| 17012 | 37 #include "m_option.h" |
| 38 #include "m_struct.h" | |
| 36253 | 39 #include "osdep/osdep.h" |
| 36736 | 40 #include "libmpdemux/demuxer.h" |
| 9794 | 41 |
| 42 static struct stream_priv_s { | |
| 43 char* filename; | |
|
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
44 char *filename2; |
| 9794 | 45 } stream_priv_dflts = { |
| 15452 | 46 NULL, NULL |
| 9794 | 47 }; |
| 48 | |
| 49 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
| 50 /// URL definition | |
| 25242 | 51 static const m_option_t stream_opts_fields[] = { |
|
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
52 {"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
|
53 {"filename", ST_OFF(filename2), CONF_TYPE_STRING, 0, 0 ,0, NULL}, |
| 9794 | 54 { NULL, NULL, 0, 0, 0, 0, NULL } |
| 55 }; | |
| 25691 | 56 static const struct m_struct_st stream_opts = { |
| 9794 | 57 "file", |
| 58 sizeof(struct stream_priv_s), | |
| 59 &stream_priv_dflts, | |
| 60 stream_opts_fields | |
|
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27727
diff
changeset
|
61 }; |
| 9794 | 62 |
| 63 static int fill_buffer(stream_t *s, char* buffer, int max_len){ | |
| 64 int r = read(s->fd,buffer,max_len); | |
|
35018
5f3501f7f4d9
Explicitly signal EOF when reaching the end of a file/pipe.
reimar
parents:
33759
diff
changeset
|
65 // We are certain this is EOF, do not retry |
|
5f3501f7f4d9
Explicitly signal EOF when reaching the end of a file/pipe.
reimar
parents:
33759
diff
changeset
|
66 if (max_len && r == 0) s->eof = 1; |
| 9794 | 67 return (r <= 0) ? -1 : r; |
| 68 } | |
| 69 | |
| 70 static int write_buffer(stream_t *s, char* buffer, int len) { | |
|
32794
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
71 int r; |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
72 int wr = 0; |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
73 while (wr < len) { |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
74 r = write(s->fd,buffer,len); |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
75 if (r <= 0) |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
76 return -1; |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
77 wr += r; |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
78 buffer += r; |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
79 } |
|
77d81e27a176
Fix stream_write_buffer to make sure all requested bytes are written
ranma
parents:
32529
diff
changeset
|
80 return len; |
| 9794 | 81 } |
| 82 | |
|
35885
3389262720da
Fix previous commit, off_t must be replaced by int64_t
reimar
parents:
35881
diff
changeset
|
83 static int seek(stream_t *s, int64_t newpos) { |
| 9794 | 84 s->pos = newpos; |
| 85 if(lseek(s->fd,s->pos,SEEK_SET)<0) { | |
| 86 s->eof=1; | |
| 87 return 0; | |
| 88 } | |
| 89 return 1; | |
| 90 } | |
| 91 | |
|
35885
3389262720da
Fix previous commit, off_t must be replaced by int64_t
reimar
parents:
35881
diff
changeset
|
92 static int seek_forward(stream_t *s, int64_t newpos) { |
| 9794 | 93 if(newpos<s->pos){ |
| 94 mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n"); | |
| 95 return 0; | |
| 96 } | |
| 97 while(s->pos<newpos){ | |
| 12018 | 98 int len=s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE); |
| 99 if(len<=0){ s->eof=1; s->buf_pos=s->buf_len=0; break; } // EOF | |
| 100 s->buf_pos=0; | |
| 101 s->buf_len=len; | |
| 102 s->pos+=len; | |
| 9794 | 103 } |
| 104 return 1; | |
| 105 } | |
| 106 | |
| 21658 | 107 static int control(stream_t *s, int cmd, void *arg) { |
| 108 switch(cmd) { | |
| 109 case STREAM_CTRL_GET_SIZE: { | |
| 110 off_t size; | |
| 111 | |
| 112 size = lseek(s->fd, 0, SEEK_END); | |
| 113 lseek(s->fd, s->pos, SEEK_SET); | |
| 114 if(size != (off_t)-1) { | |
|
35266
ceb148e1fe31
Change STREAM_CTRL_GET_SIZE argument type from off_t to
reimar
parents:
35018
diff
changeset
|
115 *(uint64_t*)arg = size; |
| 21658 | 116 return 1; |
| 117 } | |
| 118 } | |
| 119 } | |
| 24257 | 120 return STREAM_UNSUPPORTED; |
| 21658 | 121 } |
| 122 | |
|
35868
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
123 #ifdef __MINGW32__ |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
124 static int win32_open(const char *fname, int m, int omode) |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
125 { |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
126 int cnt; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
127 int fd = -1; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
128 wchar_t fname_w[MAX_PATH]; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
129 int WINAPI (*mb2wc)(UINT, DWORD, LPCSTR, int, LPWSTR, int) = NULL; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
130 HMODULE kernel32 = GetModuleHandle("Kernel32.dll"); |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
131 if (!kernel32) goto fallback; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
132 mb2wc = GetProcAddress(kernel32, "MultiByteToWideChar"); |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
133 if (!mb2wc) goto fallback; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
134 cnt = mb2wc(CP_UTF8, MB_ERR_INVALID_CHARS, fname, -1, fname_w, sizeof(fname_w) / sizeof(*fname_w)); |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
135 if (cnt <= 0) goto fallback; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
136 fd = _wsopen(fname_w, m, SH_DENYNO, omode); |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
137 if (fd != -1 || (m & O_CREAT)) |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
138 return fd; |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
139 |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
140 fallback: |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
141 return _sopen(fname, m, SH_DENYNO, omode); |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
142 } |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
143 #endif |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
144 |
| 9794 | 145 static int open_f(stream_t *stream,int mode, void* opts, int* file_format) { |
| 146 int f; | |
| 147 mode_t m = 0; | |
|
35885
3389262720da
Fix previous commit, off_t must be replaced by int64_t
reimar
parents:
35881
diff
changeset
|
148 int64_t len; |
|
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
149 unsigned char *filename; |
| 9794 | 150 struct stream_priv_s* p = (struct stream_priv_s*)opts; |
| 151 | |
| 152 if(mode == STREAM_READ) | |
| 153 m = O_RDONLY; | |
| 154 else if(mode == STREAM_WRITE) | |
|
22451
86f7b9cab33b
truncate mencoder's output file if it exists, instead of overwriting just part of it.
lorenm
parents:
21705
diff
changeset
|
155 m = O_RDWR|O_CREAT|O_TRUNC; |
| 9794 | 156 else { |
| 10608 | 157 mp_msg(MSGT_OPEN,MSGL_ERR, "[file] Unknown open mode %d\n",mode); |
| 9794 | 158 m_struct_free(&stream_opts,opts); |
| 24257 | 159 return STREAM_UNSUPPORTED; |
| 9794 | 160 } |
| 161 | |
|
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
162 if(p->filename) |
|
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
163 filename = p->filename; |
|
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
164 else if(p->filename2) |
|
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
165 filename = p->filename2; |
|
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
166 else |
|
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
167 filename = NULL; |
|
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
168 if(!filename) { |
| 9849 | 169 mp_msg(MSGT_OPEN,MSGL_ERR, "[file] No filename\n"); |
| 170 m_struct_free(&stream_opts,opts); | |
| 171 return STREAM_ERROR; | |
| 172 } | |
| 173 | |
|
30608
c05fbacce55f
Replace platform preprocessor check by HAVE_DOS_PATHS.
komh
parents:
30426
diff
changeset
|
174 #if HAVE_DOS_PATHS |
| 26005 | 175 // extract '/' from '/x:/path' |
| 176 if( filename[ 0 ] == '/' && filename[ 1 ] && filename[ 2 ] == ':' ) | |
| 177 filename++; | |
| 178 #endif | |
| 179 | |
| 9794 | 180 m |= O_BINARY; |
| 181 | |
|
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
182 if(!strcmp(filename,"-")){ |
| 9794 | 183 if(mode == STREAM_READ) { |
| 184 // read from stdin | |
| 185 mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN); | |
| 186 f=0; // 0=stdin | |
|
30787
e10ba171be06
Define HAVE_SETMODE conditionally, and use it in stream/stream_file.c instead
komh
parents:
30608
diff
changeset
|
187 #if HAVE_SETMODE |
|
e10ba171be06
Define HAVE_SETMODE conditionally, and use it in stream/stream_file.c instead
komh
parents:
30608
diff
changeset
|
188 setmode(fileno(stdin),O_BINARY); |
| 12921 | 189 #endif |
| 9794 | 190 } else { |
| 191 mp_msg(MSGT_OPEN,MSGL_INFO,"Writing to stdout\n"); | |
| 192 f=1; | |
|
30787
e10ba171be06
Define HAVE_SETMODE conditionally, and use it in stream/stream_file.c instead
komh
parents:
30608
diff
changeset
|
193 #if HAVE_SETMODE |
|
e10ba171be06
Define HAVE_SETMODE conditionally, and use it in stream/stream_file.c instead
komh
parents:
30608
diff
changeset
|
194 setmode(fileno(stdout),O_BINARY); |
| 12921 | 195 #endif |
| 9794 | 196 } |
| 197 } else { | |
|
21705
829b1f30a07f
fix compilation on the most delicious variant of unix (mingw) that lacks S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
nicodvb
parents:
21673
diff
changeset
|
198 mode_t openmode = S_IRUSR|S_IWUSR; |
|
35868
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
199 #ifdef __MINGW32__ |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
200 f = win32_open(filename, m, openmode); |
|
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
201 #else |
|
21705
829b1f30a07f
fix compilation on the most delicious variant of unix (mingw) that lacks S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
nicodvb
parents:
21673
diff
changeset
|
202 openmode |= S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; |
|
35868
3edaed3c1d60
Win32: support file names with characters outside system code-page
reimar
parents:
35266
diff
changeset
|
203 f=open(filename,m, openmode); |
|
21705
829b1f30a07f
fix compilation on the most delicious variant of unix (mingw) that lacks S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
nicodvb
parents:
21673
diff
changeset
|
204 #endif |
| 9794 | 205 if(f<0) { |
|
15461
7c272bfba96f
fixed file:// syntax using newly introduced -string- urlpart
nicodvb
parents:
15452
diff
changeset
|
206 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename); |
| 9794 | 207 m_struct_free(&stream_opts,opts); |
| 9827 | 208 return STREAM_ERROR; |
| 9794 | 209 } |
| 210 } | |
| 211 | |
| 212 len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET); | |
| 12921 | 213 #ifdef __MINGW32__ |
| 31883 | 214 // seeks on stdin incorrectly succeed on MinGW |
| 215 if(f==0) | |
| 216 len = -1; | |
| 217 #endif | |
| 9794 | 218 if(len == -1) { |
|
21656
32c50eb3ff18
in STREAM_WRITE mode open the stream with O_RDWR|O_CREAT, S_IRUSR|S_IWUSR and disable seek_forward for pipes
nicodvb
parents:
19271
diff
changeset
|
219 if(mode == STREAM_READ) stream->seek = seek_forward; |
| 9794 | 220 stream->type = STREAMTYPE_STREAM; // Must be move to STREAMTYPE_FILE |
|
29920
4f740437ed2b
Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents:
29304
diff
changeset
|
221 stream->flags |= MP_STREAM_SEEK_FW; |
| 9794 | 222 } else if(len >= 0) { |
| 223 stream->seek = seek; | |
| 224 stream->end_pos = len; | |
| 225 stream->type = STREAMTYPE_FILE; | |
| 226 } | |
| 227 | |
| 36736 | 228 // support sdp:// also via FFmpeg if live555 was not compiled in |
| 229 if (stream->url && !strncmp(stream->url, "sdp://", 6)) { | |
| 230 *file_format = DEMUXER_TYPE_LAVF; | |
| 231 stream->type = STREAMTYPE_SDP; | |
| 232 stream->flags = STREAM_NON_CACHEABLE; | |
| 233 } | |
| 234 | |
|
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16748
diff
changeset
|
235 mp_msg(MSGT_OPEN,MSGL_V,"[file] File size is %"PRId64" bytes\n", (int64_t)len); |
| 9794 | 236 |
| 237 stream->fd = f; | |
| 238 stream->fill_buffer = fill_buffer; | |
| 239 stream->write_buffer = write_buffer; | |
| 21658 | 240 stream->control = control; |
|
32529
0624fa95a2aa
Make the file protocol read up to 64 kB at once when the cache is used,
reimar
parents:
31883
diff
changeset
|
241 stream->read_chunk = 64*1024; |
| 9794 | 242 |
| 243 m_struct_free(&stream_opts,opts); | |
| 244 return STREAM_OK; | |
| 245 } | |
| 246 | |
| 25211 | 247 const stream_info_t stream_info_file = { |
| 9794 | 248 "File", |
| 249 "file", | |
| 250 "Albeu", | |
| 251 "based on the code from ??? (probably Arpi)", | |
| 252 open_f, | |
| 36736 | 253 { "file", "", "sdp", NULL }, |
| 9794 | 254 &stream_opts, |
| 255 1 // Urls are an option string | |
| 256 }; |
