2 * Unbuffered io for ffmpeg system
3 * Copyright (c) 2001 Fabrice Bellard
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.
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.
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
21 URLProtocol *first_protocol = NULL;
23 int register_protocol(URLProtocol *protocol)
27 while (*p != NULL) p = &(*p)->next;
29 protocol->next = NULL;
33 int url_open(URLContext **puc, const char *filename, int flags)
38 char proto_str[128], *q;
43 while (*p != '\0' && *p != ':') {
44 if ((q - proto_str) < sizeof(proto_str) - 1)
48 /* if the protocol has length 1, we consider it is a dos drive */
49 if (*p == '\0' || (q - proto_str) <= 1) {
50 strcpy(proto_str, "file");
57 if (!strcmp(proto_str, up->name))
64 uc = av_malloc(sizeof(URLContext) + strlen(filename));
69 strcpy(uc->filename, filename);
72 uc->is_streamed = 0; /* default = not streamed */
73 uc->max_packet_size = 0; /* default: stream file */
74 err = up->url_open(uc, filename, flags);
87 int url_read(URLContext *h, unsigned char *buf, int size)
90 if (h->flags & URL_WRONLY)
92 ret = h->prot->url_read(h, buf, size);
96 int url_write(URLContext *h, unsigned char *buf, int size)
99 if (!(h->flags & (URL_WRONLY | URL_RDWR)))
101 /* avoid sending too big packets */
102 if (h->max_packet_size && size > h->max_packet_size)
104 ret = h->prot->url_write(h, buf, size);
108 offset_t url_seek(URLContext *h, offset_t pos, int whence)
112 if (!h->prot->url_seek)
114 ret = h->prot->url_seek(h, pos, whence);
118 int url_close(URLContext *h)
122 ret = h->prot->url_close(h);
127 int url_exist(const char *filename)
130 if (url_open(&h, filename, URL_RDONLY) < 0)
136 offset_t url_filesize(URLContext *h)
140 pos = url_seek(h, 0, SEEK_CUR);
141 size = url_seek(h, 0, SEEK_END);
142 url_seek(h, pos, SEEK_SET);
147 * Return the maximum packet size associated to packetized file
148 * handle. If the file is not packetized (stream like http or file on
149 * disk), then 0 is returned.
151 * @param h file handle
152 * @return maximum packet size in bytes
154 int url_get_max_packet_size(URLContext *h)
156 return h->max_packet_size;
159 void url_get_filename(URLContext *h, char *buf, int buf_size)
161 pstrcpy(buf, buf_size, h->filename);