63095fd17252bf6bc49fc2ed6087233bbae9ef6a
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
))
63 uc
= av_malloc(sizeof(URLContext
));
68 uc
->is_streamed
= 0; /* default = not streamed */
69 uc
->packet_size
= 1; /* default packet size */
70 err
= up
->url_open(uc
, filename
, flags
);
80 int url_read(URLContext
*h
, unsigned char *buf
, int size
)
83 if (h
->flags
& URL_WRONLY
)
85 ret
= h
->prot
->url_read(h
, buf
, size
);
89 int url_write(URLContext
*h
, unsigned char *buf
, int size
)
92 if (!(h
->flags
& URL_WRONLY
))
94 ret
= h
->prot
->url_write(h
, buf
, size
);
98 offset_t
url_seek(URLContext
*h
, offset_t pos
, int whence
)
102 if (!h
->prot
->url_seek
)
104 ret
= h
->prot
->url_seek(h
, pos
, whence
);
108 int url_close(URLContext
*h
)
112 ret
= h
->prot
->url_close(h
);
117 int url_exist(const char *filename
)
120 if (url_open(&h
, filename
, URL_RDONLY
) < 0)
126 offset_t
url_filesize(URLContext
*h
)
130 pos
= url_seek(h
, 0, SEEK_CUR
);
131 size
= url_seek(h
, 0, SEEK_END
);
132 url_seek(h
, pos
, SEEK_SET
);