Mercurial > audlegacy
annotate Plugins/Input/wma/libffwma/avio.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 * Unbuffered 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 | |
21 static int default_interrupt_cb(void); | |
22 | |
23 URLProtocol *first_protocol = NULL; | |
24 URLInterruptCB *url_interrupt_cb = default_interrupt_cb; | |
25 | |
26 int register_protocol(URLProtocol *protocol) | |
27 { | |
28 URLProtocol **p; | |
29 p = &first_protocol; | |
30 while (*p != NULL) p = &(*p)->next; | |
31 *p = protocol; | |
32 protocol->next = NULL; | |
33 return 0; | |
34 } | |
35 | |
36 int url_open(URLContext **puc, const char *filename, int flags) | |
37 { | |
38 URLContext *uc; | |
39 URLProtocol *up; | |
40 const char *p; | |
41 char proto_str[128], *q; | |
42 int err; | |
43 | |
44 p = filename; | |
45 q = proto_str; | |
46 while (*p != '\0' && *p != ':') { | |
47 /* protocols can only contain alphabetic chars */ | |
48 if (!isalpha(*p)) | |
49 goto file_proto; | |
50 if ((q - proto_str) < sizeof(proto_str) - 1) | |
51 *q++ = *p; | |
52 p++; | |
53 } | |
54 /* if the protocol has length 1, we consider it is a dos drive */ | |
55 if (*p == '\0' || (q - proto_str) <= 1) { | |
56 file_proto: | |
57 strcpy(proto_str, "file"); | |
58 } else { | |
59 *q = '\0'; | |
60 } | |
61 | |
62 up = first_protocol; | |
63 while (up != NULL) { | |
64 if (!strcmp(proto_str, up->name)) | |
65 goto found; | |
66 up = up->next; | |
67 } | |
68 err = -ENOENT; | |
69 goto fail; | |
70 found: | |
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
|
71 uc = malloc(sizeof(URLContext) + strlen(filename)); |
137 | 72 if (!uc) { |
73 err = -ENOMEM; | |
74 goto fail; | |
75 } | |
76 strcpy(uc->filename, filename); | |
77 uc->prot = up; | |
78 uc->flags = flags; | |
79 uc->is_streamed = 0; /* default = not streamed */ | |
80 uc->max_packet_size = 0; /* default: stream file */ | |
81 err = up->url_open(uc, filename, flags); | |
82 if (err < 0) { | |
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
|
83 free(uc); |
137 | 84 *puc = NULL; |
85 return err; | |
86 } | |
87 *puc = uc; | |
88 return 0; | |
89 fail: | |
90 *puc = NULL; | |
91 return err; | |
92 } | |
93 | |
94 int url_read(URLContext *h, unsigned char *buf, int size) | |
95 { | |
96 int ret; | |
97 if (h->flags & URL_WRONLY) | |
98 return -EIO; | |
99 ret = h->prot->url_read(h, buf, size); | |
100 return ret; | |
101 } | |
102 | |
103 offset_t url_seek(URLContext *h, offset_t pos, int whence) | |
104 { | |
105 offset_t ret; | |
106 | |
107 if (!h->prot->url_seek) | |
108 return -EPIPE; | |
109 ret = h->prot->url_seek(h, pos, whence); | |
110 return ret; | |
111 } | |
112 | |
113 int url_close(URLContext *h) | |
114 { | |
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
|
115 int ret; |
137 | 116 |
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
|
117 ret = h->prot->url_close(h); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
118 free(h); |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
119 |
0bea7509d6ba
[svn] Working WMA support. I never said it would be pretty, neno, I should said it would play.
chainsaw
parents:
210
diff
changeset
|
120 return ret; |
137 | 121 } |
122 | |
123 int url_exist(const char *filename) | |
124 { | |
125 URLContext *h; | |
126 if (url_open(&h, filename, URL_RDONLY) < 0) | |
127 return 0; | |
128 url_close(h); | |
129 return 1; | |
130 } | |
131 | |
132 offset_t url_filesize(URLContext *h) | |
133 { | |
134 offset_t pos, size; | |
135 | |
136 pos = url_seek(h, 0, SEEK_CUR); | |
137 size = url_seek(h, 0, SEEK_END); | |
138 url_seek(h, pos, SEEK_SET); | |
139 return size; | |
140 } | |
141 | |
142 /* | |
143 * Return the maximum packet size associated to packetized file | |
144 * handle. If the file is not packetized (stream like http or file on | |
145 * disk), then 0 is returned. | |
146 * | |
147 * @param h file handle | |
148 * @return maximum packet size in bytes | |
149 */ | |
150 int url_get_max_packet_size(URLContext *h) | |
151 { | |
152 return h->max_packet_size; | |
153 } | |
154 | |
155 void url_get_filename(URLContext *h, char *buf, int buf_size) | |
156 { | |
157 pstrcpy(buf, buf_size, h->filename); | |
158 } | |
159 | |
160 | |
161 static int default_interrupt_cb(void) | |
162 { | |
163 return 0; | |
164 } | |
165 | |
166 /** | |
167 * The callback is called in blocking functions to test regulary if | |
168 * asynchronous interruption is needed. -EINTR is returned in this | |
169 * case by the interrupted function. 'NULL' means no interrupt | |
170 * callback is given. | |
171 */ | |
172 void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) | |
173 { | |
174 if (!interrupt_cb) | |
175 interrupt_cb = default_interrupt_cb; | |
176 url_interrupt_cb = interrupt_cb; | |
177 } |