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