... | ... |
@@ -42,8 +42,10 @@ URLProtocol *ffurl_protocol_next(URLProtocol *prev) |
42 | 42 |
static const char *urlcontext_to_name(void *ptr) |
43 | 43 |
{ |
44 | 44 |
URLContext *h = (URLContext *)ptr; |
45 |
- if(h->prot) return h->prot->name; |
|
46 |
- else return "NULL"; |
|
45 |
+ if (h->prot) |
|
46 |
+ return h->prot->name; |
|
47 |
+ else |
|
48 |
+ return "NULL"; |
|
47 | 49 |
} |
48 | 50 |
|
49 | 51 |
static void *urlcontext_child_next(void *obj, void *prev) |
... | ... |
@@ -68,26 +70,25 @@ static const AVClass *urlcontext_child_class_next(const AVClass *prev) |
68 | 68 |
if (p->priv_data_class) |
69 | 69 |
return p->priv_data_class; |
70 | 70 |
return NULL; |
71 |
- |
|
72 | 71 |
} |
73 | 72 |
|
74 |
-static const AVOption options[] = {{NULL}}; |
|
73 |
+static const AVOption options[] = { { NULL } }; |
|
75 | 74 |
const AVClass ffurl_context_class = { |
76 |
- .class_name = "URLContext", |
|
77 |
- .item_name = urlcontext_to_name, |
|
78 |
- .option = options, |
|
79 |
- .version = LIBAVUTIL_VERSION_INT, |
|
80 |
- .child_next = urlcontext_child_next, |
|
75 |
+ .class_name = "URLContext", |
|
76 |
+ .item_name = urlcontext_to_name, |
|
77 |
+ .option = options, |
|
78 |
+ .version = LIBAVUTIL_VERSION_INT, |
|
79 |
+ .child_next = urlcontext_child_next, |
|
81 | 80 |
.child_class_next = urlcontext_child_class_next, |
82 | 81 |
}; |
83 | 82 |
/*@}*/ |
84 | 83 |
|
85 |
- |
|
86 | 84 |
const char *avio_enum_protocols(void **opaque, int output) |
87 | 85 |
{ |
88 | 86 |
URLProtocol *p; |
89 | 87 |
*opaque = ffurl_protocol_next(*opaque); |
90 |
- if (!(p = *opaque)) return NULL; |
|
88 |
+ if (!(p = *opaque)) |
|
89 |
+ return NULL; |
|
91 | 90 |
if ((output && p->url_write) || (!output && p->url_read)) |
92 | 91 |
return p->name; |
93 | 92 |
return avio_enum_protocols(opaque, output); |
... | ... |
@@ -97,20 +98,21 @@ int ffurl_register_protocol(URLProtocol *protocol, int size) |
97 | 97 |
{ |
98 | 98 |
URLProtocol **p; |
99 | 99 |
if (size < sizeof(URLProtocol)) { |
100 |
- URLProtocol* temp = av_mallocz(sizeof(URLProtocol)); |
|
100 |
+ URLProtocol *temp = av_mallocz(sizeof(URLProtocol)); |
|
101 | 101 |
memcpy(temp, protocol, size); |
102 | 102 |
protocol = temp; |
103 | 103 |
} |
104 | 104 |
p = &first_protocol; |
105 |
- while (*p != NULL) p = &(*p)->next; |
|
106 |
- *p = protocol; |
|
105 |
+ while (*p != NULL) |
|
106 |
+ p = &(*p)->next; |
|
107 |
+ *p = protocol; |
|
107 | 108 |
protocol->next = NULL; |
108 | 109 |
return 0; |
109 | 110 |
} |
110 | 111 |
|
111 |
-static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up, |
|
112 |
- const char *filename, int flags, |
|
113 |
- const AVIOInterruptCB *int_cb) |
|
112 |
+static int url_alloc_for_protocol(URLContext **puc, struct URLProtocol *up, |
|
113 |
+ const char *filename, int flags, |
|
114 |
+ const AVIOInterruptCB *int_cb) |
|
114 | 115 |
{ |
115 | 116 |
URLContext *uc; |
116 | 117 |
int err; |
... | ... |
@@ -125,16 +127,16 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up, |
125 | 125 |
goto fail; |
126 | 126 |
} |
127 | 127 |
uc->av_class = &ffurl_context_class; |
128 |
- uc->filename = (char *) &uc[1]; |
|
128 |
+ uc->filename = (char *)&uc[1]; |
|
129 | 129 |
strcpy(uc->filename, filename); |
130 |
- uc->prot = up; |
|
131 |
- uc->flags = flags; |
|
132 |
- uc->is_streamed = 0; /* default = not streamed */ |
|
130 |
+ uc->prot = up; |
|
131 |
+ uc->flags = flags; |
|
132 |
+ uc->is_streamed = 0; /* default = not streamed */ |
|
133 | 133 |
uc->max_packet_size = 0; /* default: stream file */ |
134 | 134 |
if (up->priv_data_size) { |
135 | 135 |
uc->priv_data = av_mallocz(up->priv_data_size); |
136 | 136 |
if (up->priv_data_class) { |
137 |
- *(const AVClass**)uc->priv_data = up->priv_data_class; |
|
137 |
+ *(const AVClass **)uc->priv_data = up->priv_data_class; |
|
138 | 138 |
av_opt_set_defaults(uc->priv_data); |
139 | 139 |
} |
140 | 140 |
} |
... | ... |
@@ -143,7 +145,7 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up, |
143 | 143 |
|
144 | 144 |
*puc = uc; |
145 | 145 |
return 0; |
146 |
- fail: |
|
146 |
+fail: |
|
147 | 147 |
*puc = NULL; |
148 | 148 |
#if CONFIG_NETWORK |
149 | 149 |
if (up->flags & URL_PROTOCOL_FLAG_NETWORK) |
... | ... |
@@ -152,19 +154,22 @@ static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up, |
152 | 152 |
return err; |
153 | 153 |
} |
154 | 154 |
|
155 |
-int ffurl_connect(URLContext* uc, AVDictionary **options) |
|
155 |
+int ffurl_connect(URLContext *uc, AVDictionary **options) |
|
156 | 156 |
{ |
157 | 157 |
int err = |
158 |
- uc->prot->url_open2 ? uc->prot->url_open2(uc, uc->filename, uc->flags, options) : |
|
158 |
+ uc->prot->url_open2 ? uc->prot->url_open2(uc, |
|
159 |
+ uc->filename, |
|
160 |
+ uc->flags, |
|
161 |
+ options) : |
|
159 | 162 |
uc->prot->url_open(uc, uc->filename, uc->flags); |
160 | 163 |
if (err) |
161 | 164 |
return err; |
162 | 165 |
uc->is_connected = 1; |
163 |
- //We must be careful here as ffurl_seek() could be slow, for example for http |
|
164 |
- if( (uc->flags & AVIO_FLAG_WRITE) |
|
165 |
- || !strcmp(uc->prot->name, "file")) |
|
166 |
- if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0) |
|
167 |
- uc->is_streamed= 1; |
|
166 |
+ /* We must be careful here as ffurl_seek() could be slow, |
|
167 |
+ * for example for http */ |
|
168 |
+ if ((uc->flags & AVIO_FLAG_WRITE) || !strcmp(uc->prot->name, "file")) |
|
169 |
+ if (!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0) |
|
170 |
+ uc->is_streamed = 1; |
|
168 | 171 |
return 0; |
169 | 172 |
} |
170 | 173 |
|
... | ... |
@@ -183,7 +188,8 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags, |
183 | 183 |
if (filename[proto_len] != ':' || is_dos_path(filename)) |
184 | 184 |
strcpy(proto_str, "file"); |
185 | 185 |
else |
186 |
- av_strlcpy(proto_str, filename, FFMIN(proto_len+1, sizeof(proto_str))); |
|
186 |
+ av_strlcpy(proto_str, filename, |
|
187 |
+ FFMIN(proto_len + 1, sizeof(proto_str))); |
|
187 | 188 |
|
188 | 189 |
av_strlcpy(proto_nested, proto_str, sizeof(proto_nested)); |
189 | 190 |
if ((ptr = strchr(proto_nested, '+'))) |
... | ... |
@@ -191,10 +197,10 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags, |
191 | 191 |
|
192 | 192 |
while (up = ffurl_protocol_next(up)) { |
193 | 193 |
if (!strcmp(proto_str, up->name)) |
194 |
- return url_alloc_for_protocol (puc, up, filename, flags, int_cb); |
|
194 |
+ return url_alloc_for_protocol(puc, up, filename, flags, int_cb); |
|
195 | 195 |
if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME && |
196 | 196 |
!strcmp(proto_nested, up->name)) |
197 |
- return url_alloc_for_protocol (puc, up, filename, flags, int_cb); |
|
197 |
+ return url_alloc_for_protocol(puc, up, filename, flags, int_cb); |
|
198 | 198 |
} |
199 | 199 |
*puc = NULL; |
200 | 200 |
return AVERROR_PROTOCOL_NOT_FOUND; |
... | ... |
@@ -218,15 +224,18 @@ fail: |
218 | 218 |
return ret; |
219 | 219 |
} |
220 | 220 |
|
221 |
-static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size, int size_min, |
|
222 |
- int (*transfer_func)(URLContext *h, unsigned char *buf, int size)) |
|
221 |
+static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf, |
|
222 |
+ int size, int size_min, |
|
223 |
+ int (*transfer_func)(URLContext *h, |
|
224 |
+ uint8_t *buf, |
|
225 |
+ int size)) |
|
223 | 226 |
{ |
224 | 227 |
int ret, len; |
225 | 228 |
int fast_retries = 5; |
226 | 229 |
|
227 | 230 |
len = 0; |
228 | 231 |
while (len < size_min) { |
229 |
- ret = transfer_func(h, buf+len, size-len); |
|
232 |
+ ret = transfer_func(h, buf + len, size - len); |
|
230 | 233 |
if (ret == AVERROR(EINTR)) |
231 | 234 |
continue; |
232 | 235 |
if (h->flags & AVIO_FLAG_NONBLOCK) |
... | ... |
@@ -240,7 +249,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int |
240 | 240 |
} else if (ret < 1) |
241 | 241 |
return (ret < 0 && ret != AVERROR_EOF) ? ret : len; |
242 | 242 |
if (ret) |
243 |
- fast_retries = FFMAX(fast_retries, 2); |
|
243 |
+ fast_retries = FFMAX(fast_retries, 2); |
|
244 | 244 |
len += ret; |
245 | 245 |
if (ff_check_interrupt(&h->interrupt_callback)) |
246 | 246 |
return AVERROR_EXIT; |
... | ... |
@@ -286,7 +295,8 @@ int64_t ffurl_seek(URLContext *h, int64_t pos, int whence) |
286 | 286 |
int ffurl_close(URLContext *h) |
287 | 287 |
{ |
288 | 288 |
int ret = 0; |
289 |
- if (!h) return 0; /* can happen when ffurl_open fails */ |
|
289 |
+ if (!h) |
|
290 |
+ return 0; /* can happen when ffurl_open fails */ |
|
290 | 291 |
|
291 | 292 |
if (h->is_connected && h->prot->url_close) |
292 | 293 |
ret = h->prot->url_close(h); |
... | ... |
@@ -326,8 +336,8 @@ int64_t ffurl_size(URLContext *h) |
326 | 326 |
{ |
327 | 327 |
int64_t pos, size; |
328 | 328 |
|
329 |
- size= ffurl_seek(h, 0, AVSEEK_SIZE); |
|
330 |
- if(size<0){ |
|
329 |
+ size = ffurl_seek(h, 0, AVSEEK_SIZE); |
|
330 |
+ if (size < 0) { |
|
331 | 331 |
pos = ffurl_seek(h, 0, SEEK_CUR); |
332 | 332 |
if ((size = ffurl_seek(h, -1, SEEK_END)) < 0) |
333 | 333 |
return size; |