OLD | NEW |
1 /* | 1 /* |
2 * Unbuffered io for ffmpeg system | 2 * Unbuffered io for ffmpeg system |
3 * Copyright (c) 2001 Fabrice Bellard | 3 * Copyright (c) 2001 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * FFmpeg is distributed in the hope that it will be useful, | 12 * FFmpeg is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | 15 * Lesser General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Lesser General Public | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with FFmpeg; if not, write to the Free Software | 18 * License along with FFmpeg; if not, write to the Free Software |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | 20 */ |
21 | 21 |
22 /* needed for usleep() */ | 22 /* needed for usleep() */ |
23 #define _XOPEN_SOURCE 600 | 23 #define _XOPEN_SOURCE 600 |
24 #include <unistd.h> | 24 #include <unistd.h> |
25 #include "libavutil/avstring.h" | 25 #include "libavutil/avstring.h" |
26 #include "libavcodec/opt.h" | 26 #include "libavcodec/opt.h" |
27 #include "os_support.h" | 27 #include "os_support.h" |
28 #include "avformat.h" | 28 #include "avformat.h" |
| 29 #if CONFIG_NETWORK |
| 30 #include "network.h" |
| 31 #endif |
29 | 32 |
30 #if LIBAVFORMAT_VERSION_MAJOR >= 53 | 33 #if LIBAVFORMAT_VERSION_MAJOR >= 53 |
31 /** @name Logging context. */ | 34 /** @name Logging context. */ |
32 /*@{*/ | 35 /*@{*/ |
33 static const char *urlcontext_to_name(void *ptr) | 36 static const char *urlcontext_to_name(void *ptr) |
34 { | 37 { |
35 URLContext *h = (URLContext *)ptr; | 38 URLContext *h = (URLContext *)ptr; |
36 if(h->prot) return h->prot->name; | 39 if(h->prot) return h->prot->name; |
37 else return "NULL"; | 40 else return "NULL"; |
38 } | 41 } |
(...skipping 30 matching lines...) Expand all Loading... |
69 return av_register_protocol(protocol); | 72 return av_register_protocol(protocol); |
70 } | 73 } |
71 #endif | 74 #endif |
72 | 75 |
73 int url_open_protocol (URLContext **puc, struct URLProtocol *up, | 76 int url_open_protocol (URLContext **puc, struct URLProtocol *up, |
74 const char *filename, int flags) | 77 const char *filename, int flags) |
75 { | 78 { |
76 URLContext *uc; | 79 URLContext *uc; |
77 int err; | 80 int err; |
78 | 81 |
| 82 #if CONFIG_NETWORK |
| 83 if (!ff_network_init()) |
| 84 return AVERROR(EIO); |
| 85 #endif |
79 uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1); | 86 uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1); |
80 if (!uc) { | 87 if (!uc) { |
81 err = AVERROR(ENOMEM); | 88 err = AVERROR(ENOMEM); |
82 goto fail; | 89 goto fail; |
83 } | 90 } |
84 #if LIBAVFORMAT_VERSION_MAJOR >= 53 | 91 #if LIBAVFORMAT_VERSION_MAJOR >= 53 |
85 uc->av_class = &urlcontext_class; | 92 uc->av_class = &urlcontext_class; |
86 #endif | 93 #endif |
87 uc->filename = (char *) &uc[1]; | 94 uc->filename = (char *) &uc[1]; |
88 strcpy(uc->filename, filename); | 95 strcpy(uc->filename, filename); |
89 uc->prot = up; | 96 uc->prot = up; |
90 uc->flags = flags; | 97 uc->flags = flags; |
91 uc->is_streamed = 0; /* default = not streamed */ | 98 uc->is_streamed = 0; /* default = not streamed */ |
92 uc->max_packet_size = 0; /* default: stream file */ | 99 uc->max_packet_size = 0; /* default: stream file */ |
93 err = up->url_open(uc, filename, flags); | 100 err = up->url_open(uc, filename, flags); |
94 if (err < 0) { | 101 if (err < 0) { |
95 av_free(uc); | 102 av_free(uc); |
96 *puc = NULL; | 103 goto fail; |
97 return err; | |
98 } | 104 } |
99 | 105 |
100 //We must be careful here as url_seek() could be slow, for example for http | 106 //We must be careful here as url_seek() could be slow, for example for http |
101 if( (flags & (URL_WRONLY | URL_RDWR)) | 107 if( (flags & (URL_WRONLY | URL_RDWR)) |
102 || !strcmp(up->name, "file")) | 108 || !strcmp(up->name, "file")) |
103 if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0) | 109 if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0) |
104 uc->is_streamed= 1; | 110 uc->is_streamed= 1; |
105 *puc = uc; | 111 *puc = uc; |
106 return 0; | 112 return 0; |
107 fail: | 113 fail: |
108 *puc = NULL; | 114 *puc = NULL; |
| 115 #if CONFIG_NETWORK |
| 116 ff_network_close(); |
| 117 #endif |
109 return err; | 118 return err; |
110 } | 119 } |
111 | 120 |
112 int url_open(URLContext **puc, const char *filename, int flags) | 121 int url_open(URLContext **puc, const char *filename, int flags) |
113 { | 122 { |
114 URLProtocol *up; | 123 URLProtocol *up; |
115 const char *p; | 124 const char *p; |
116 char proto_str[128], *q; | 125 char proto_str[128], *q; |
117 | 126 |
118 p = filename; | 127 p = filename; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return ret; | 206 return ret; |
198 } | 207 } |
199 | 208 |
200 int url_close(URLContext *h) | 209 int url_close(URLContext *h) |
201 { | 210 { |
202 int ret = 0; | 211 int ret = 0; |
203 if (!h) return 0; /* can happen when url_open fails */ | 212 if (!h) return 0; /* can happen when url_open fails */ |
204 | 213 |
205 if (h->prot->url_close) | 214 if (h->prot->url_close) |
206 ret = h->prot->url_close(h); | 215 ret = h->prot->url_close(h); |
| 216 #if CONFIG_NETWORK |
| 217 ff_network_close(); |
| 218 #endif |
207 av_free(h); | 219 av_free(h); |
208 return ret; | 220 return ret; |
209 } | 221 } |
210 | 222 |
211 int url_exist(const char *filename) | 223 int url_exist(const char *filename) |
212 { | 224 { |
213 URLContext *h; | 225 URLContext *h; |
214 if (url_open(&h, filename, URL_RDONLY) < 0) | 226 if (url_open(&h, filename, URL_RDONLY) < 0) |
215 return 0; | 227 return 0; |
216 url_close(h); | 228 url_close(h); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return h->prot->url_read_pause(h, pause); | 281 return h->prot->url_read_pause(h, pause); |
270 } | 282 } |
271 | 283 |
272 int64_t av_url_read_seek(URLContext *h, | 284 int64_t av_url_read_seek(URLContext *h, |
273 int stream_index, int64_t timestamp, int flags) | 285 int stream_index, int64_t timestamp, int flags) |
274 { | 286 { |
275 if (!h->prot->url_read_seek) | 287 if (!h->prot->url_read_seek) |
276 return AVERROR(ENOSYS); | 288 return AVERROR(ENOSYS); |
277 return h->prot->url_read_seek(h, stream_index, timestamp, flags); | 289 return h->prot->url_read_seek(h, stream_index, timestamp, flags); |
278 } | 290 } |
OLD | NEW |