Mercurial > audlegacy
annotate Plugins/Input/wma/libffwma/file.c @ 218:0bea7509d6ba trunk
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
author | chainsaw |
---|---|
date | Mon, 21 Nov 2005 14:59:13 -0800 |
parents | 12004b385a96 |
children | ad1e65c6a854 |
rev | line source |
---|---|
137 | 1 /* |
2 * Buffered file io for ffmpeg system | |
3 * Copyright (c) 2001 Fabrice Bellard | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 #include <fcntl.h> | |
21 #include <unistd.h> | |
22 #include <sys/ioctl.h> | |
23 #include <sys/time.h> | |
24 | |
25 /* standard file protocol */ | |
26 | |
27 static int file_open(URLContext *h, const char *filename, int flags) | |
28 { | |
29 int access; | |
30 int fd; | |
31 | |
32 strstart(filename, "file:", &filename); | |
33 | |
34 if (flags & URL_WRONLY) { | |
35 access = O_CREAT | O_TRUNC | O_WRONLY; | |
36 } else { | |
37 access = O_RDONLY; | |
38 } | |
218
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
39 |
137 | 40 fd = open(filename, access, 0666); |
41 if (fd < 0) | |
42 return -ENOENT; | |
43 h->priv_data = (void *)fd; | |
44 return 0; | |
45 } | |
46 | |
47 static int file_read(URLContext *h, unsigned char *buf, int size) | |
48 { | |
49 int fd = (int)h->priv_data; | |
50 return read(fd, buf, size); | |
51 } | |
52 | |
53 static int file_write(URLContext *h, unsigned char *buf, int size) | |
54 { | |
55 int fd = (int)h->priv_data; | |
56 return write(fd, buf, size); | |
57 } | |
58 | |
59 /* XXX: use llseek */ | |
60 static offset_t file_seek(URLContext *h, offset_t pos, int whence) | |
61 { | |
62 int fd = (int)h->priv_data; | |
63 return lseek(fd, pos, whence); | |
64 } | |
65 | |
66 static int file_close(URLContext *h) | |
67 { | |
68 int fd = (int)h->priv_data; | |
69 return close(fd); | |
70 } | |
71 | |
72 URLProtocol file_protocol = { | |
73 "file", | |
74 file_open, | |
75 file_read, | |
76 file_write, | |
77 file_seek, | |
78 file_close, | |
79 }; | |
80 | |
81 /* pipe protocol */ | |
82 | |
83 static int pipe_open(URLContext *h, const char *filename, int flags) | |
84 { | |
85 int fd; | |
86 | |
87 if (flags & URL_WRONLY) { | |
88 fd = 1; | |
89 } else { | |
90 fd = 0; | |
91 } | |
92 h->priv_data = (void *)fd; | |
93 return 0; | |
94 } | |
95 | |
96 static int pipe_read(URLContext *h, unsigned char *buf, int size) | |
97 { | |
98 int fd = (int)h->priv_data; | |
99 return read(fd, buf, size); | |
100 } | |
101 | |
102 static int pipe_write(URLContext *h, unsigned char *buf, int size) | |
103 { | |
104 int fd = (int)h->priv_data; | |
105 return write(fd, buf, size); | |
106 } | |
107 | |
108 static int pipe_close(URLContext *h) | |
109 { | |
110 return 0; | |
111 } | |
112 | |
113 URLProtocol pipe_protocol = { | |
114 "pipe", | |
115 pipe_open, | |
116 pipe_read, | |
117 pipe_write, | |
118 NULL, | |
119 pipe_close, | |
120 }; |