* qatar/master:
proto: include os_support.h in network.h
matroskaenc: don't write an empty Cues element.
lavc: add a FF_API_REQUEST_CHANNELS deprecation macro
avio: move extern url_interrupt_cb declaration from avio.h to url.h
avio: make av_register_protocol2 internal.
avio: avio_ prefix for url_set_interrupt_cb.
avio: AVIO_ prefixes for URL_ open flags.
proto: introduce listen option in tcp
doc: clarify configure features
proto: factor ff_network_wait_fd and use it on udp
Conflicts:
ffmpeg.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -9,3 +9,7 @@ path when launching 'configure', e.g. '/ffmpegdir/ffmpeg/configure'. |
9 | 9 |
2) Then type 'make' to build FFmpeg. GNU Make 3.81 or later is required. |
10 | 10 |
|
11 | 11 |
3) Type 'make install' to install all binaries and libraries you built. |
12 |
+ |
|
13 |
+NOTICE |
|
14 |
+ |
|
15 |
+ - Non system dependencies (e.g. libx264, libvpx) are disabled by default. |
... | ... |
@@ -402,6 +402,23 @@ ffplay sap://[ff0e::2:7ffe] |
402 | 402 |
|
403 | 403 |
Trasmission Control Protocol. |
404 | 404 |
|
405 |
+The required syntax for a TCP url is: |
|
406 |
+@example |
|
407 |
+tcp://@var{hostname}:@var{port}[?@var{options}] |
|
408 |
+@end example |
|
409 |
+ |
|
410 |
+@table @option |
|
411 |
+ |
|
412 |
+@item listen |
|
413 |
+Listen for an incoming connection |
|
414 |
+ |
|
415 |
+@example |
|
416 |
+ffmpeg -i @var{input} -f @var{format} tcp://@var{hostname}:@var{port}?listen |
|
417 |
+ffplay tcp://@var{hostname}:@var{port} |
|
418 |
+@end example |
|
419 |
+ |
|
420 |
+@end table |
|
421 |
+ |
|
405 | 422 |
@section udp |
406 | 423 |
|
407 | 424 |
User Datagram Protocol. |
... | ... |
@@ -2569,7 +2569,7 @@ static int transcode(AVFormatContext **output_files, |
2569 | 2569 |
if (!using_stdin) { |
2570 | 2570 |
if(verbose >= 0) |
2571 | 2571 |
fprintf(stderr, "Press [q] to stop encoding\n"); |
2572 |
- url_set_interrupt_cb(decode_interrupt_cb); |
|
2572 |
+ avio_set_interrupt_cb(decode_interrupt_cb); |
|
2573 | 2573 |
} |
2574 | 2574 |
term_init(); |
2575 | 2575 |
|
... | ... |
@@ -3887,7 +3887,7 @@ static void opt_output_file(const char *filename) |
3887 | 3887 |
} |
3888 | 3888 |
|
3889 | 3889 |
/* open the file */ |
3890 |
- if ((err = avio_open(&oc->pb, filename, URL_WRONLY)) < 0) { |
|
3890 |
+ if ((err = avio_open(&oc->pb, filename, AVIO_WRONLY)) < 0) { |
|
3891 | 3891 |
print_error(filename, err); |
3892 | 3892 |
ffmpeg_exit(1); |
3893 | 3893 |
} |
... | ... |
@@ -4426,7 +4426,7 @@ int main(int argc, char **argv) |
4426 | 4426 |
|
4427 | 4427 |
#if HAVE_ISATTY |
4428 | 4428 |
if(isatty(STDIN_FILENO)) |
4429 |
- url_set_interrupt_cb(decode_interrupt_cb); |
|
4429 |
+ avio_set_interrupt_cb(decode_interrupt_cb); |
|
4430 | 4430 |
#endif |
4431 | 4431 |
|
4432 | 4432 |
init_opts(); |
... | ... |
@@ -2406,7 +2406,7 @@ static int decode_thread(void *arg) |
2406 | 2406 |
is->subtitle_stream = -1; |
2407 | 2407 |
|
2408 | 2408 |
global_video_state = is; |
2409 |
- url_set_interrupt_cb(decode_interrupt_cb); |
|
2409 |
+ avio_set_interrupt_cb(decode_interrupt_cb); |
|
2410 | 2410 |
|
2411 | 2411 |
memset(ap, 0, sizeof(*ap)); |
2412 | 2412 |
|
... | ... |
@@ -2626,7 +2626,7 @@ static int decode_thread(void *arg) |
2626 | 2626 |
av_close_input_file(is->ic); |
2627 | 2627 |
is->ic = NULL; /* safety */ |
2628 | 2628 |
} |
2629 |
- url_set_interrupt_cb(NULL); |
|
2629 |
+ avio_set_interrupt_cb(NULL); |
|
2630 | 2630 |
|
2631 | 2631 |
if (ret != 0) { |
2632 | 2632 |
SDL_Event event; |
... | ... |
@@ -3427,7 +3427,7 @@ static int rtp_new_av_stream(HTTPContext *c, |
3427 | 3427 |
"rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port)); |
3428 | 3428 |
} |
3429 | 3429 |
|
3430 |
- if (url_open(&h, ctx->filename, URL_WRONLY) < 0) |
|
3430 |
+ if (url_open(&h, ctx->filename, AVIO_WRONLY) < 0) |
|
3431 | 3431 |
goto fail; |
3432 | 3432 |
c->rtp_handles[stream_index] = h; |
3433 | 3433 |
max_packet_size = url_get_max_packet_size(h); |
... | ... |
@@ -3767,7 +3767,7 @@ static void build_feed_streams(void) |
3767 | 3767 |
} |
3768 | 3768 |
|
3769 | 3769 |
/* only write the header of the ffm file */ |
3770 |
- if (avio_open(&s->pb, feed->feed_filename, URL_WRONLY) < 0) { |
|
3770 |
+ if (avio_open(&s->pb, feed->feed_filename, AVIO_WRONLY) < 0) { |
|
3771 | 3771 |
http_log("Could not open output feed file '%s'\n", |
3772 | 3772 |
feed->feed_filename); |
3773 | 3773 |
exit(1); |
... | ... |
@@ -2601,7 +2601,7 @@ typedef struct AVCodecContext { |
2601 | 2601 |
*/ |
2602 | 2602 |
int64_t timecode_frame_start; |
2603 | 2603 |
|
2604 |
-#if LIBAVCODEC_VERSION_MAJOR < 53 |
|
2604 |
+#if FF_API_REQUEST_CHANNELS |
|
2605 | 2605 |
/** |
2606 | 2606 |
* Decoder should decode to this many channels if it can (0 for default) |
2607 | 2607 |
* - encoding: unused |
... | ... |
@@ -408,7 +408,9 @@ static const AVOption options[]={ |
408 | 408 |
{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT64, 0, 0, INT64_MAX, V|E}, |
409 | 409 |
{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"}, |
410 | 410 |
{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"}, |
411 |
+#if FF_API_REQUEST_CHANNELS |
|
411 | 412 |
{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D}, |
413 |
+#endif |
|
412 | 414 |
{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D}, |
413 | 415 |
{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"}, |
414 | 416 |
{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MBTREE, INT_MIN, INT_MAX, V|E, "flags2"}, |
... | ... |
@@ -83,5 +83,8 @@ |
83 | 83 |
#ifndef FF_API_ANTIALIAS_ALGO |
84 | 84 |
#define FF_API_ANTIALIAS_ALGO (LIBAVCODEC_VERSION_MAJOR < 54) |
85 | 85 |
#endif |
86 |
+#ifndef FF_API_REQUEST_CHANNELS |
|
87 |
+#define FF_API_REQUEST_CHANNELS (LIBAVCODEC_VERSION_MAJOR < 53) |
|
88 |
+#endif |
|
86 | 89 |
|
87 | 90 |
#endif /* AVCODEC_VERSION_H */ |
... | ... |
@@ -21,6 +21,7 @@ |
21 | 21 |
#include "avformat.h" |
22 | 22 |
#include "rtp.h" |
23 | 23 |
#include "rdt.h" |
24 |
+#include "url.h" |
|
24 | 25 |
|
25 | 26 |
#define REGISTER_MUXER(X,x) { \ |
26 | 27 |
extern AVOutputFormat ff_##x##_muxer; \ |
... | ... |
@@ -34,7 +35,7 @@ |
34 | 34 |
|
35 | 35 |
#define REGISTER_PROTOCOL(X,x) { \ |
36 | 36 |
extern URLProtocol ff_##x##_protocol; \ |
37 |
- if(CONFIG_##X##_PROTOCOL) av_register_protocol2(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } |
|
37 |
+ if(CONFIG_##X##_PROTOCOL) ffurl_register_protocol(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } |
|
38 | 38 |
|
39 | 39 |
void av_register_all(void) |
40 | 40 |
{ |
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
#include "internal.h" |
32 | 32 |
#include <unistd.h> |
33 | 33 |
#include "avio_internal.h" |
34 |
+#include "url.h" |
|
34 | 35 |
|
35 | 36 |
#define INITIAL_BUFFER_SIZE 32768 |
36 | 37 |
|
... | ... |
@@ -169,7 +170,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url, |
169 | 169 |
|
170 | 170 |
if (!in) { |
171 | 171 |
close_in = 1; |
172 |
- if ((ret = avio_open(&in, url, URL_RDONLY)) < 0) |
|
172 |
+ if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0) |
|
173 | 173 |
return ret; |
174 | 174 |
} |
175 | 175 |
|
... | ... |
@@ -292,7 +293,7 @@ reload: |
292 | 292 |
|
293 | 293 |
ret = url_open(&v->input, |
294 | 294 |
v->segments[v->cur_seq_no - v->start_seq_no]->url, |
295 |
- URL_RDONLY); |
|
295 |
+ AVIO_RDONLY); |
|
296 | 296 |
if (ret < 0) |
297 | 297 |
return ret; |
298 | 298 |
} |
... | ... |
@@ -115,7 +115,7 @@ static int parse_playlist(URLContext *h, const char *url) |
115 | 115 |
char line[1024]; |
116 | 116 |
const char *ptr; |
117 | 117 |
|
118 |
- if ((ret = avio_open(&in, url, URL_RDONLY)) < 0) |
|
118 |
+ if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0) |
|
119 | 119 |
return ret; |
120 | 120 |
|
121 | 121 |
read_chomp_line(in, line, sizeof(line)); |
... | ... |
@@ -180,7 +180,7 @@ static int applehttp_open(URLContext *h, const char *uri, int flags) |
180 | 180 |
int ret, i; |
181 | 181 |
const char *nested_url; |
182 | 182 |
|
183 |
- if (flags & (URL_WRONLY | URL_RDWR)) |
|
183 |
+ if (flags & (AVIO_WRONLY | AVIO_RDWR)) |
|
184 | 184 |
return AVERROR(ENOSYS); |
185 | 185 |
|
186 | 186 |
s = av_mallocz(sizeof(AppleHTTPContext)); |
... | ... |
@@ -275,7 +275,7 @@ retry: |
275 | 275 |
} |
276 | 276 |
url = s->segments[s->cur_seq_no - s->start_seq_no]->url, |
277 | 277 |
av_log(NULL, AV_LOG_DEBUG, "opening %s\n", url); |
278 |
- ret = ffurl_open(&s->seg_hd, url, URL_RDONLY); |
|
278 |
+ ret = ffurl_open(&s->seg_hd, url, AVIO_RDONLY); |
|
279 | 279 |
if (ret < 0) { |
280 | 280 |
if (url_interrupt_cb()) |
281 | 281 |
return AVERROR_EXIT; |
... | ... |
@@ -57,7 +57,7 @@ URLProtocol *av_protocol_next(URLProtocol *p) |
57 | 57 |
else return first_protocol; |
58 | 58 |
} |
59 | 59 |
|
60 |
-int av_register_protocol2(URLProtocol *protocol, int size) |
|
60 |
+int ffurl_register_protocol(URLProtocol *protocol, int size) |
|
61 | 61 |
{ |
62 | 62 |
URLProtocol **p; |
63 | 63 |
if (size < sizeof(URLProtocol)) { |
... | ... |
@@ -86,12 +86,12 @@ struct URLProtocol_compat { |
86 | 86 |
|
87 | 87 |
int av_register_protocol(URLProtocol *protocol) |
88 | 88 |
{ |
89 |
- return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat)); |
|
89 |
+ return ffurl_register_protocol(protocol, sizeof(struct URLProtocol_compat)); |
|
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
int register_protocol(URLProtocol *protocol) |
93 | 93 |
{ |
94 |
- return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat)); |
|
94 |
+ return ffurl_register_protocol(protocol, sizeof(struct URLProtocol_compat)); |
|
95 | 95 |
} |
96 | 96 |
#endif |
97 | 97 |
|
... | ... |
@@ -144,7 +144,7 @@ int ffurl_connect(URLContext* uc) |
144 | 144 |
return err; |
145 | 145 |
uc->is_connected = 1; |
146 | 146 |
//We must be careful here as ffurl_seek() could be slow, for example for http |
147 |
- if( (uc->flags & (URL_WRONLY | URL_RDWR)) |
|
147 |
+ if( (uc->flags & (AVIO_WRONLY | AVIO_RDWR)) |
|
148 | 148 |
|| !strcmp(uc->prot->name, "file")) |
149 | 149 |
if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0) |
150 | 150 |
uc->is_streamed= 1; |
... | ... |
@@ -216,6 +216,14 @@ void url_get_filename(URLContext *h, char *buf, int buf_size) |
216 | 216 |
{ |
217 | 217 |
av_strlcpy(buf, h->filename, buf_size); |
218 | 218 |
} |
219 |
+void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) |
|
220 |
+{ |
|
221 |
+ avio_set_interrupt_cb(interrupt_cb); |
|
222 |
+} |
|
223 |
+int av_register_protocol2(URLProtocol *protocol, int size) |
|
224 |
+{ |
|
225 |
+ return ffurl_register_protocol(protocol, size); |
|
226 |
+} |
|
219 | 227 |
#endif |
220 | 228 |
|
221 | 229 |
#define URL_SCHEME_CHARS \ |
... | ... |
@@ -275,7 +283,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int |
275 | 275 |
ret = transfer_func(h, buf+len, size-len); |
276 | 276 |
if (ret == AVERROR(EINTR)) |
277 | 277 |
continue; |
278 |
- if (h->flags & URL_FLAG_NONBLOCK) |
|
278 |
+ if (h->flags & AVIO_FLAG_NONBLOCK) |
|
279 | 279 |
return ret; |
280 | 280 |
if (ret == AVERROR(EAGAIN)) { |
281 | 281 |
ret = 0; |
... | ... |
@@ -296,21 +304,21 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int |
296 | 296 |
|
297 | 297 |
int ffurl_read(URLContext *h, unsigned char *buf, int size) |
298 | 298 |
{ |
299 |
- if (h->flags & URL_WRONLY) |
|
299 |
+ if (h->flags & AVIO_WRONLY) |
|
300 | 300 |
return AVERROR(EIO); |
301 | 301 |
return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read); |
302 | 302 |
} |
303 | 303 |
|
304 | 304 |
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) |
305 | 305 |
{ |
306 |
- if (h->flags & URL_WRONLY) |
|
306 |
+ if (h->flags & AVIO_WRONLY) |
|
307 | 307 |
return AVERROR(EIO); |
308 | 308 |
return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read); |
309 | 309 |
} |
310 | 310 |
|
311 | 311 |
int ffurl_write(URLContext *h, const unsigned char *buf, int size) |
312 | 312 |
{ |
313 |
- if (!(h->flags & (URL_WRONLY | URL_RDWR))) |
|
313 |
+ if (!(h->flags & (AVIO_WRONLY | AVIO_RDWR))) |
|
314 | 314 |
return AVERROR(EIO); |
315 | 315 |
/* avoid sending too big packets */ |
316 | 316 |
if (h->max_packet_size && size > h->max_packet_size) |
... | ... |
@@ -348,7 +356,7 @@ int ffurl_close(URLContext *h) |
348 | 348 |
int url_exist(const char *filename) |
349 | 349 |
{ |
350 | 350 |
URLContext *h; |
351 |
- if (ffurl_open(&h, filename, URL_RDONLY) < 0) |
|
351 |
+ if (ffurl_open(&h, filename, AVIO_RDONLY) < 0) |
|
352 | 352 |
return 0; |
353 | 353 |
ffurl_close(h); |
354 | 354 |
return 1; |
... | ... |
@@ -381,7 +389,7 @@ static int default_interrupt_cb(void) |
381 | 381 |
return 0; |
382 | 382 |
} |
383 | 383 |
|
384 |
-void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) |
|
384 |
+void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb) |
|
385 | 385 |
{ |
386 | 386 |
if (!interrupt_cb) |
387 | 387 |
interrupt_cb = default_interrupt_cb; |
... | ... |
@@ -63,7 +63,6 @@ typedef struct URLPollEntry { |
63 | 63 |
int events; |
64 | 64 |
int revents; |
65 | 65 |
} URLPollEntry; |
66 |
-#endif |
|
67 | 66 |
|
68 | 67 |
/** |
69 | 68 |
* @defgroup open_modes URL open modes |
... | ... |
@@ -91,6 +90,7 @@ typedef struct URLPollEntry { |
91 | 91 |
* silently ignored. |
92 | 92 |
*/ |
93 | 93 |
#define URL_FLAG_NONBLOCK 4 |
94 |
+#endif |
|
94 | 95 |
|
95 | 96 |
typedef int URLInterruptCB(void); |
96 | 97 |
|
... | ... |
@@ -117,6 +117,7 @@ attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_siz |
117 | 117 |
attribute_deprecated int av_url_read_pause(URLContext *h, int pause); |
118 | 118 |
attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index, |
119 | 119 |
int64_t timestamp, int flags); |
120 |
+attribute_deprecated void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); |
|
120 | 121 |
#endif |
121 | 122 |
|
122 | 123 |
/** |
... | ... |
@@ -131,7 +132,7 @@ int url_exist(const char *url); |
131 | 131 |
* in this case by the interrupted function. 'NULL' means no interrupt |
132 | 132 |
* callback is given. |
133 | 133 |
*/ |
134 |
-void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); |
|
134 |
+void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb); |
|
135 | 135 |
|
136 | 136 |
#if FF_API_OLD_AVIO |
137 | 137 |
/* not implemented */ |
... | ... |
@@ -162,7 +163,9 @@ typedef struct URLProtocol { |
162 | 162 |
extern URLProtocol *first_protocol; |
163 | 163 |
#endif |
164 | 164 |
|
165 |
+#if FF_API_OLD_AVIO |
|
165 | 166 |
extern URLInterruptCB *url_interrupt_cb; |
167 |
+#endif |
|
166 | 168 |
|
167 | 169 |
/** |
168 | 170 |
* If protocol is NULL, returns the first registered protocol, |
... | ... |
@@ -183,12 +186,14 @@ attribute_deprecated int register_protocol(URLProtocol *protocol); |
183 | 183 |
attribute_deprecated int av_register_protocol(URLProtocol *protocol); |
184 | 184 |
#endif |
185 | 185 |
|
186 |
+#if FF_API_OLD_AVIO |
|
186 | 187 |
/** |
187 | 188 |
* Register the URLProtocol protocol. |
188 | 189 |
* |
189 | 190 |
* @param size the size of the URLProtocol struct referenced |
190 | 191 |
*/ |
191 |
-int av_register_protocol2(URLProtocol *protocol, int size); |
|
192 |
+attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size); |
|
193 |
+#endif |
|
192 | 194 |
|
193 | 195 |
#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ |
194 | 196 |
|
... | ... |
@@ -511,6 +516,33 @@ int url_resetbuf(AVIOContext *s, int flags); |
511 | 511 |
#endif |
512 | 512 |
|
513 | 513 |
/** |
514 |
+ * @defgroup open_modes URL open modes |
|
515 |
+ * The flags argument to avio_open must be one of the following |
|
516 |
+ * constants, optionally ORed with other flags. |
|
517 |
+ * @{ |
|
518 |
+ */ |
|
519 |
+#define AVIO_RDONLY 0 /**< read-only */ |
|
520 |
+#define AVIO_WRONLY 1 /**< write-only */ |
|
521 |
+#define AVIO_RDWR 2 /**< read-write */ |
|
522 |
+/** |
|
523 |
+ * @} |
|
524 |
+ */ |
|
525 |
+ |
|
526 |
+/** |
|
527 |
+ * Use non-blocking mode. |
|
528 |
+ * If this flag is set, operations on the context will return |
|
529 |
+ * AVERROR(EAGAIN) if they can not be performed immediately. |
|
530 |
+ * If this flag is not set, operations on the context will never return |
|
531 |
+ * AVERROR(EAGAIN). |
|
532 |
+ * Note that this flag does not affect the opening/connecting of the |
|
533 |
+ * context. Connecting a protocol will always block if necessary (e.g. on |
|
534 |
+ * network protocols) but never hang (e.g. on busy devices). |
|
535 |
+ * Warning: non-blocking protocols is work-in-progress; this flag may be |
|
536 |
+ * silently ignored. |
|
537 |
+ */ |
|
538 |
+#define AVIO_FLAG_NONBLOCK 4 |
|
539 |
+ |
|
540 |
+/** |
|
514 | 541 |
* Create and initialize a AVIOContext for accessing the |
515 | 542 |
* resource indicated by url. |
516 | 543 |
* @note When the resource indicated by url has been opened in |
... | ... |
@@ -55,7 +55,7 @@ int ffio_init_context(AVIOContext *s, |
55 | 55 |
s->buffer_size = buffer_size; |
56 | 56 |
s->buf_ptr = buffer; |
57 | 57 |
s->opaque = opaque; |
58 |
- url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY); |
|
58 |
+ url_resetbuf(s, write_flag ? AVIO_WRONLY : AVIO_RDONLY); |
|
59 | 59 |
s->write_packet = write_packet; |
60 | 60 |
s->read_packet = read_packet; |
61 | 61 |
s->seek = seek; |
... | ... |
@@ -854,7 +854,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) |
854 | 854 |
} |
855 | 855 |
|
856 | 856 |
if (ffio_init_context(*s, buffer, buffer_size, |
857 |
- (h->flags & URL_WRONLY || h->flags & URL_RDWR), h, |
|
857 |
+ (h->flags & AVIO_WRONLY || h->flags & AVIO_RDWR), h, |
|
858 | 858 |
ffurl_read, ffurl_write, ffurl_seek) < 0) { |
859 | 859 |
av_free(buffer); |
860 | 860 |
av_freep(s); |
... | ... |
@@ -883,7 +883,7 @@ int ffio_set_buf_size(AVIOContext *s, int buf_size) |
883 | 883 |
s->buffer = buffer; |
884 | 884 |
s->buffer_size = buf_size; |
885 | 885 |
s->buf_ptr = buffer; |
886 |
- url_resetbuf(s, s->write_flag ? URL_WRONLY : URL_RDONLY); |
|
886 |
+ url_resetbuf(s, s->write_flag ? AVIO_WRONLY : AVIO_RDONLY); |
|
887 | 887 |
return 0; |
888 | 888 |
} |
889 | 889 |
|
... | ... |
@@ -894,13 +894,13 @@ static int url_resetbuf(AVIOContext *s, int flags) |
894 | 894 |
#endif |
895 | 895 |
{ |
896 | 896 |
#if FF_API_URL_RESETBUF |
897 |
- if (flags & URL_RDWR) |
|
897 |
+ if (flags & AVIO_RDWR) |
|
898 | 898 |
return AVERROR(EINVAL); |
899 | 899 |
#else |
900 |
- assert(flags == URL_WRONLY || flags == URL_RDONLY); |
|
900 |
+ assert(flags == AVIO_WRONLY || flags == AVIO_RDONLY); |
|
901 | 901 |
#endif |
902 | 902 |
|
903 |
- if (flags & URL_WRONLY) { |
|
903 |
+ if (flags & AVIO_WRONLY) { |
|
904 | 904 |
s->buf_end = s->buffer + s->buffer_size; |
905 | 905 |
s->write_flag = 1; |
906 | 906 |
} else { |
... | ... |
@@ -1058,7 +1058,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags) |
1058 | 1058 |
if(!*s) |
1059 | 1059 |
return AVERROR(ENOMEM); |
1060 | 1060 |
ret = ffio_init_context(*s, buf, buf_size, |
1061 |
- (flags & URL_WRONLY || flags & URL_RDWR), |
|
1061 |
+ (flags & AVIO_WRONLY || flags & AVIO_RDWR), |
|
1062 | 1062 |
NULL, NULL, NULL, NULL); |
1063 | 1063 |
if(ret != 0) |
1064 | 1064 |
av_freep(s); |
... | ... |
@@ -59,9 +59,9 @@ static int file_open(URLContext *h, const char *filename, int flags) |
59 | 59 |
|
60 | 60 |
av_strstart(filename, "file:", &filename); |
61 | 61 |
|
62 |
- if (flags & URL_RDWR) { |
|
62 |
+ if (flags & AVIO_RDWR) { |
|
63 | 63 |
access = O_CREAT | O_TRUNC | O_RDWR; |
64 |
- } else if (flags & URL_WRONLY) { |
|
64 |
+ } else if (flags & AVIO_WRONLY) { |
|
65 | 65 |
access = O_CREAT | O_TRUNC | O_WRONLY; |
66 | 66 |
} else { |
67 | 67 |
access = O_RDONLY; |
... | ... |
@@ -116,7 +116,7 @@ static int pipe_open(URLContext *h, const char *filename, int flags) |
116 | 116 |
|
117 | 117 |
fd = strtol(filename, &final, 10); |
118 | 118 |
if((filename == final) || *final ) {/* No digits found, or something like 10ab */ |
119 |
- if (flags & URL_WRONLY) { |
|
119 |
+ if (flags & AVIO_WRONLY) { |
|
120 | 120 |
fd = 1; |
121 | 121 |
} else { |
122 | 122 |
fd = 0; |
... | ... |
@@ -100,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags) |
100 | 100 |
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); |
101 | 101 |
|
102 | 102 |
s->hd = NULL; |
103 |
- err = ffurl_open(&s->hd, buf, URL_RDWR); |
|
103 |
+ err = ffurl_open(&s->hd, buf, AVIO_RDWR); |
|
104 | 104 |
if (err < 0) |
105 | 105 |
goto fail; |
106 | 106 |
|
... | ... |
@@ -124,7 +124,7 @@ static int http_open_cnx(URLContext *h) |
124 | 124 |
port = 80; |
125 | 125 |
|
126 | 126 |
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); |
127 |
- err = ffurl_open(&hd, buf, URL_RDWR); |
|
127 |
+ err = ffurl_open(&hd, buf, AVIO_RDWR); |
|
128 | 128 |
if (err < 0) |
129 | 129 |
goto fail; |
130 | 130 |
|
... | ... |
@@ -296,7 +296,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, |
296 | 296 |
|
297 | 297 |
|
298 | 298 |
/* send http header */ |
299 |
- post = h->flags & URL_WRONLY; |
|
299 |
+ post = h->flags & AVIO_WRONLY; |
|
300 | 300 |
authstr = ff_http_auth_create_response(&s->auth_state, auth, path, |
301 | 301 |
post ? "POST" : "GET"); |
302 | 302 |
|
... | ... |
@@ -451,7 +451,7 @@ static int http_close(URLContext *h) |
451 | 451 |
HTTPContext *s = h->priv_data; |
452 | 452 |
|
453 | 453 |
/* signal end of chunked encoding if used */ |
454 |
- if ((h->flags & URL_WRONLY) && s->chunksize != -1) { |
|
454 |
+ if ((h->flags & AVIO_WRONLY) && s->chunksize != -1) { |
|
455 | 455 |
ret = ffurl_write(s->hd, footer, sizeof(footer) - 1); |
456 | 456 |
ret = ret > 0 ? 0 : ret; |
457 | 457 |
} |
... | ... |
@@ -274,7 +274,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt) |
274 | 274 |
s->path, s->img_number)<0 && s->img_number > 1) |
275 | 275 |
return AVERROR(EIO); |
276 | 276 |
for(i=0; i<3; i++){ |
277 |
- if (avio_open(&f[i], filename, URL_RDONLY) < 0) { |
|
277 |
+ if (avio_open(&f[i], filename, AVIO_RDONLY) < 0) { |
|
278 | 278 |
if(i==1) |
279 | 279 |
break; |
280 | 280 |
av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename); |
... | ... |
@@ -361,7 +361,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) |
361 | 361 |
return AVERROR(EIO); |
362 | 362 |
} |
363 | 363 |
for(i=0; i<3; i++){ |
364 |
- if (avio_open(&pb[i], filename, URL_WRONLY) < 0) { |
|
364 |
+ if (avio_open(&pb[i], filename, AVIO_WRONLY) < 0) { |
|
365 | 365 |
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename); |
366 | 366 |
return AVERROR(EIO); |
367 | 367 |
} |
... | ... |
@@ -1333,7 +1333,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) |
1333 | 1333 |
&& track->codec_priv.size >= 14 |
1334 | 1334 |
&& track->codec_priv.data != NULL) { |
1335 | 1335 |
ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, |
1336 |
- URL_RDONLY, NULL, NULL, NULL, NULL); |
|
1336 |
+ AVIO_RDONLY, NULL, NULL, NULL, NULL); |
|
1337 | 1337 |
ff_get_wav_header(&b, st->codec, track->codec_priv.size); |
1338 | 1338 |
codec_id = st->codec->codec_id; |
1339 | 1339 |
extradata_offset = FFMIN(track->codec_priv.size, 18); |
... | ... |
@@ -1144,10 +1144,13 @@ static int mkv_write_trailer(AVFormatContext *s) |
1144 | 1144 |
} |
1145 | 1145 |
|
1146 | 1146 |
if (pb->seekable) { |
1147 |
- cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams); |
|
1147 |
+ if (mkv->cues->num_entries) { |
|
1148 |
+ cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams); |
|
1149 |
+ |
|
1150 |
+ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES, cuespos); |
|
1151 |
+ if (ret < 0) return ret; |
|
1152 |
+ } |
|
1148 | 1153 |
|
1149 |
- ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES , cuespos); |
|
1150 |
- if (ret < 0) return ret; |
|
1151 | 1154 |
mkv_write_seekhead(pb, mkv->main_seekhead); |
1152 | 1155 |
|
1153 | 1156 |
// update the duration |
... | ... |
@@ -36,7 +36,7 @@ static int md5_open(URLContext *h, const char *filename, int flags) |
36 | 36 |
return -1; |
37 | 37 |
} |
38 | 38 |
|
39 |
- if (flags != URL_WRONLY) |
|
39 |
+ if (flags != AVIO_WRONLY) |
|
40 | 40 |
return AVERROR(EINVAL); |
41 | 41 |
|
42 | 42 |
av_md5_init(h->priv_data); |
... | ... |
@@ -65,7 +65,7 @@ static int md5_close(URLContext *h) |
65 | 65 |
av_strstart(filename, "md5:", &filename); |
66 | 66 |
|
67 | 67 |
if (*filename) { |
68 |
- err = ffurl_open(&out, filename, URL_WRONLY); |
|
68 |
+ err = ffurl_open(&out, filename, AVIO_WRONLY); |
|
69 | 69 |
if (err) |
70 | 70 |
return err; |
71 | 71 |
err = ffurl_write(out, buf, i*2+1); |
... | ... |
@@ -233,7 +233,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) |
233 | 233 |
port = 80; // default mmsh protocol port |
234 | 234 |
ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path); |
235 | 235 |
|
236 |
- if (ffurl_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { |
|
236 |
+ if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_RDONLY) < 0) { |
|
237 | 237 |
return AVERROR(EIO); |
238 | 238 |
} |
239 | 239 |
|
... | ... |
@@ -261,7 +261,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) |
261 | 261 |
// close the socket and then reopen it for sending the second play request. |
262 | 262 |
ffurl_close(mms->mms_hd); |
263 | 263 |
memset(headers, 0, sizeof(headers)); |
264 |
- if (ffurl_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { |
|
264 |
+ if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_RDONLY) < 0) { |
|
265 | 265 |
return AVERROR(EIO); |
266 | 266 |
} |
267 | 267 |
stream_selection = av_mallocz(mms->stream_num * 19 + 1); |
... | ... |
@@ -523,7 +523,7 @@ static int mms_open(URLContext *h, const char *uri, int flags) |
523 | 523 |
|
524 | 524 |
// establish tcp connection. |
525 | 525 |
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL); |
526 |
- err = ffurl_open(&mms->mms_hd, tcpname, URL_RDWR); |
|
526 |
+ err = ffurl_open(&mms->mms_hd, tcpname, AVIO_RDWR); |
|
527 | 527 |
if (err) |
528 | 528 |
goto fail; |
529 | 529 |
|
... | ... |
@@ -1722,7 +1722,7 @@ static int mov_open_dref(AVIOContext **pb, char *src, MOVDref *ref) |
1722 | 1722 |
|
1723 | 1723 |
av_strlcat(filename, ref->path + l + 1, 1024); |
1724 | 1724 |
|
1725 |
- if (!avio_open(pb, filename, URL_RDONLY)) |
|
1725 |
+ if (!avio_open(pb, filename, AVIO_RDONLY)) |
|
1726 | 1726 |
return 0; |
1727 | 1727 |
} |
1728 | 1728 |
} |
... | ... |
@@ -22,6 +22,7 @@ |
22 | 22 |
#define AVFORMAT_NETWORK_H |
23 | 23 |
|
24 | 24 |
#include "config.h" |
25 |
+#include "os_support.h" |
|
25 | 26 |
|
26 | 27 |
#if HAVE_WINSOCK2_H |
27 | 28 |
#include <winsock2.h> |
... | ... |
@@ -55,6 +56,10 @@ static inline int ff_neterrno() { |
55 | 55 |
#include <arpa/inet.h> |
56 | 56 |
#endif |
57 | 57 |
|
58 |
+#if HAVE_POLL_H |
|
59 |
+#include <poll.h> |
|
60 |
+#endif |
|
61 |
+ |
|
58 | 62 |
int ff_socket_nonblock(int socket, int enable); |
59 | 63 |
|
60 | 64 |
static inline int ff_network_init(void) |
... | ... |
@@ -67,6 +72,15 @@ static inline int ff_network_init(void) |
67 | 67 |
return 1; |
68 | 68 |
} |
69 | 69 |
|
70 |
+static inline int ff_network_wait_fd(int fd, int write) |
|
71 |
+{ |
|
72 |
+ int ev = write ? POLLOUT : POLLIN; |
|
73 |
+ struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; |
|
74 |
+ int ret; |
|
75 |
+ ret = poll(&p, 1, 100); |
|
76 |
+ return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN); |
|
77 |
+} |
|
78 |
+ |
|
70 | 79 |
static inline void ff_network_close(void) |
71 | 80 |
{ |
72 | 81 |
#if HAVE_WINSOCK2_H |
... | ... |
@@ -492,7 +492,7 @@ int main(int argc, char **argv) |
492 | 492 |
|
493 | 493 |
/* open the output file, if needed */ |
494 | 494 |
if (!(fmt->flags & AVFMT_NOFILE)) { |
495 |
- if (avio_open(&oc->pb, filename, URL_WRONLY) < 0) { |
|
495 |
+ if (avio_open(&oc->pb, filename, AVIO_WRONLY) < 0) { |
|
496 | 496 |
fprintf(stderr, "Could not open '%s'\n", filename); |
497 | 497 |
exit(1); |
498 | 498 |
} |
... | ... |
@@ -812,7 +812,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) |
812 | 812 |
if (!rt) |
813 | 813 |
return AVERROR(ENOMEM); |
814 | 814 |
s->priv_data = rt; |
815 |
- rt->is_input = !(flags & URL_WRONLY); |
|
815 |
+ rt->is_input = !(flags & AVIO_WRONLY); |
|
816 | 816 |
|
817 | 817 |
av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, |
818 | 818 |
path, sizeof(path), s->filename); |
... | ... |
@@ -821,7 +821,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) |
821 | 821 |
port = RTMP_DEFAULT_PORT; |
822 | 822 |
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); |
823 | 823 |
|
824 |
- if (ffurl_open(&rt->stream, buf, URL_RDWR) < 0) { |
|
824 |
+ if (ffurl_open(&rt->stream, buf, AVIO_RDWR) < 0) { |
|
825 | 825 |
av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf); |
826 | 826 |
goto fail; |
827 | 827 |
} |
... | ... |
@@ -1116,14 +1116,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, |
1116 | 1116 |
"?localport=%d", j); |
1117 | 1117 |
/* we will use two ports per rtp stream (rtp and rtcp) */ |
1118 | 1118 |
j += 2; |
1119 |
- if (ffurl_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) |
|
1119 |
+ if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_RDWR) == 0) |
|
1120 | 1120 |
goto rtp_opened; |
1121 | 1121 |
} |
1122 | 1122 |
} |
1123 | 1123 |
|
1124 | 1124 |
#if 0 |
1125 | 1125 |
/* then try on any port */ |
1126 |
- if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { |
|
1126 |
+ if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", AVIO_RDONLY) < 0) { |
|
1127 | 1127 |
err = AVERROR_INVALIDDATA; |
1128 | 1128 |
goto fail; |
1129 | 1129 |
} |
... | ... |
@@ -1269,7 +1269,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, |
1269 | 1269 |
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); |
1270 | 1270 |
ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, |
1271 | 1271 |
port, "?ttl=%d", ttl); |
1272 |
- if (ffurl_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { |
|
1272 |
+ if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_RDWR) < 0) { |
|
1273 | 1273 |
err = AVERROR_INVALIDDATA; |
1274 | 1274 |
goto fail; |
1275 | 1275 |
} |
... | ... |
@@ -1396,7 +1396,7 @@ redirect: |
1396 | 1396 |
av_get_random_seed(), av_get_random_seed()); |
1397 | 1397 |
|
1398 | 1398 |
/* GET requests */ |
1399 |
- if (ffurl_alloc(&rt->rtsp_hd, httpname, URL_RDONLY) < 0) { |
|
1399 |
+ if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_RDONLY) < 0) { |
|
1400 | 1400 |
err = AVERROR(EIO); |
1401 | 1401 |
goto fail; |
1402 | 1402 |
} |
... | ... |
@@ -1417,7 +1417,7 @@ redirect: |
1417 | 1417 |
} |
1418 | 1418 |
|
1419 | 1419 |
/* POST requests */ |
1420 |
- if (ffurl_alloc(&rt->rtsp_hd_out, httpname, URL_WRONLY) < 0 ) { |
|
1420 |
+ if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_WRONLY) < 0 ) { |
|
1421 | 1421 |
err = AVERROR(EIO); |
1422 | 1422 |
goto fail; |
1423 | 1423 |
} |
... | ... |
@@ -1460,7 +1460,7 @@ redirect: |
1460 | 1460 |
} else { |
1461 | 1461 |
/* open the tcp connection */ |
1462 | 1462 |
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL); |
1463 |
- if (ffurl_open(&rt->rtsp_hd, tcpname, URL_RDWR) < 0) { |
|
1463 |
+ if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_RDWR) < 0) { |
|
1464 | 1464 |
err = AVERROR(EIO); |
1465 | 1465 |
goto fail; |
1466 | 1466 |
} |
... | ... |
@@ -1807,7 +1807,7 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap) |
1807 | 1807 |
namebuf, rtsp_st->sdp_port, |
1808 | 1808 |
"?localport=%d&ttl=%d", rtsp_st->sdp_port, |
1809 | 1809 |
rtsp_st->sdp_ttl); |
1810 |
- if (ffurl_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { |
|
1810 |
+ if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_RDWR) < 0) { |
|
1811 | 1811 |
err = AVERROR_INVALIDDATA; |
1812 | 1812 |
goto fail; |
1813 | 1813 |
} |
... | ... |
@@ -1863,7 +1863,7 @@ static int rtp_read_header(AVFormatContext *s, |
1863 | 1863 |
if (!ff_network_init()) |
1864 | 1864 |
return AVERROR(EIO); |
1865 | 1865 |
|
1866 |
- ret = ffurl_open(&in, s->filename, URL_RDONLY); |
|
1866 |
+ ret = ffurl_open(&in, s->filename, AVIO_RDONLY); |
|
1867 | 1867 |
if (ret) |
1868 | 1868 |
goto fail; |
1869 | 1869 |
|
... | ... |
@@ -85,7 +85,7 @@ static int sap_read_header(AVFormatContext *s, |
85 | 85 |
|
86 | 86 |
ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d", |
87 | 87 |
port); |
88 |
- ret = ffurl_open(&sap->ann_fd, url, URL_RDONLY); |
|
88 |
+ ret = ffurl_open(&sap->ann_fd, url, AVIO_RDONLY); |
|
89 | 89 |
if (ret) |
90 | 90 |
goto fail; |
91 | 91 |
|
... | ... |
@@ -146,7 +146,7 @@ static int sap_write_header(AVFormatContext *s) |
146 | 146 |
"?ttl=%d", ttl); |
147 | 147 |
if (!same_port) |
148 | 148 |
base_port += 2; |
149 |
- ret = ffurl_open(&fd, url, URL_WRONLY); |
|
149 |
+ ret = ffurl_open(&fd, url, AVIO_WRONLY); |
|
150 | 150 |
if (ret) { |
151 | 151 |
ret = AVERROR(EIO); |
152 | 152 |
goto fail; |
... | ... |
@@ -158,7 +158,7 @@ static int sap_write_header(AVFormatContext *s) |
158 | 158 |
|
159 | 159 |
ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port, |
160 | 160 |
"?ttl=%d&connect=1", ttl); |
161 |
- ret = ffurl_open(&sap->ann_fd, url, URL_WRONLY); |
|
161 |
+ ret = ffurl_open(&sap->ann_fd, url, AVIO_WRONLY); |
|
162 | 162 |
if (ret) { |
163 | 163 |
ret = AVERROR(EIO); |
164 | 164 |
goto fail; |
... | ... |
@@ -19,10 +19,12 @@ |
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
#include "avformat.h" |
22 |
+#include "libavutil/parseutils.h" |
|
22 | 23 |
#include <unistd.h> |
23 | 24 |
#include "internal.h" |
24 | 25 |
#include "network.h" |
25 | 26 |
#include "os_support.h" |
27 |
+#include "url.h" |
|
26 | 28 |
#if HAVE_POLL_H |
27 | 29 |
#include <poll.h> |
28 | 30 |
#endif |
... | ... |
@@ -38,6 +40,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) |
38 | 38 |
struct addrinfo hints, *ai, *cur_ai; |
39 | 39 |
int port, fd = -1; |
40 | 40 |
TCPContext *s = NULL; |
41 |
+ int listen_socket = 0; |
|
42 |
+ const char *p; |
|
43 |
+ char buf[256]; |
|
41 | 44 |
int ret; |
42 | 45 |
socklen_t optlen; |
43 | 46 |
char hostname[1024],proto[1024],path[1024]; |
... | ... |
@@ -48,6 +53,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags) |
48 | 48 |
if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) |
49 | 49 |
return AVERROR(EINVAL); |
50 | 50 |
|
51 |
+ p = strchr(uri, '?'); |
|
52 |
+ if (p) { |
|
53 |
+ if (av_find_info_tag(buf, sizeof(buf), "listen", p)) |
|
54 |
+ listen_socket = 1; |
|
55 |
+ } |
|
51 | 56 |
memset(&hints, 0, sizeof(hints)); |
52 | 57 |
hints.ai_family = AF_UNSPEC; |
53 | 58 |
hints.ai_socktype = SOCK_STREAM; |
... | ... |
@@ -66,10 +76,21 @@ static int tcp_open(URLContext *h, const char *uri, int flags) |
66 | 66 |
fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); |
67 | 67 |
if (fd < 0) |
68 | 68 |
goto fail; |
69 |
- ff_socket_nonblock(fd, 1); |
|
70 | 69 |
|
70 |
+ if (listen_socket) { |
|
71 |
+ int fd1; |
|
72 |
+ ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); |
|
73 |
+ listen(fd, 1); |
|
74 |
+ fd1 = accept(fd, NULL, NULL); |
|
75 |
+ closesocket(fd); |
|
76 |
+ fd = fd1; |
|
77 |
+ } else { |
|
71 | 78 |
redo: |
72 |
- ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); |
|
79 |
+ ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); |
|
80 |
+ } |
|
81 |
+ |
|
82 |
+ ff_socket_nonblock(fd, 1); |
|
83 |
+ |
|
73 | 84 |
if (ret < 0) { |
74 | 85 |
int timeout=50; |
75 | 86 |
struct pollfd p = {fd, POLLOUT, 0}; |
... | ... |
@@ -138,23 +159,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags) |
138 | 138 |
return ret; |
139 | 139 |
} |
140 | 140 |
|
141 |
-static int tcp_wait_fd(int fd, int write) |
|
142 |
-{ |
|
143 |
- int ev = write ? POLLOUT : POLLIN; |
|
144 |
- struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; |
|
145 |
- int ret; |
|
146 |
- |
|
147 |
- ret = poll(&p, 1, 100); |
|
148 |
- return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN); |
|
149 |
-} |
|
150 |
- |
|
151 | 141 |
static int tcp_read(URLContext *h, uint8_t *buf, int size) |
152 | 142 |
{ |
153 | 143 |
TCPContext *s = h->priv_data; |
154 | 144 |
int ret; |
155 | 145 |
|
156 |
- if (!(h->flags & URL_FLAG_NONBLOCK)) { |
|
157 |
- ret = tcp_wait_fd(s->fd, 0); |
|
146 |
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { |
|
147 |
+ ret = ff_network_wait_fd(s->fd, 0); |
|
158 | 148 |
if (ret < 0) |
159 | 149 |
return ret; |
160 | 150 |
} |
... | ... |
@@ -167,8 +178,8 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int size) |
167 | 167 |
TCPContext *s = h->priv_data; |
168 | 168 |
int ret; |
169 | 169 |
|
170 |
- if (!(h->flags & URL_FLAG_NONBLOCK)) { |
|
171 |
- ret = tcp_wait_fd(s->fd, 1); |
|
170 |
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { |
|
171 |
+ ret = ff_network_wait_fd(s->fd, 1); |
|
172 | 172 |
if (ret < 0) |
173 | 173 |
return ret; |
174 | 174 |
} |
... | ... |
@@ -33,9 +33,7 @@ |
33 | 33 |
#include "internal.h" |
34 | 34 |
#include "network.h" |
35 | 35 |
#include "os_support.h" |
36 |
-#if HAVE_POLL_H |
|
37 |
-#include <poll.h> |
|
38 |
-#endif |
|
36 |
+#include "url.h" |
|
39 | 37 |
#include <sys/time.h> |
40 | 38 |
|
41 | 39 |
#ifndef IPV6_ADD_MEMBERSHIP |
... | ... |
@@ -320,7 +318,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) |
320 | 320 |
h->is_streamed = 1; |
321 | 321 |
h->max_packet_size = 1472; |
322 | 322 |
|
323 |
- is_output = (flags & URL_WRONLY); |
|
323 |
+ is_output = (flags & AVIO_WRONLY); |
|
324 | 324 |
|
325 | 325 |
s = av_mallocz(sizeof(UDPContext)); |
326 | 326 |
if (!s) |
... | ... |
@@ -363,14 +361,14 @@ static int udp_open(URLContext *h, const char *uri, int flags) |
363 | 363 |
/* XXX: fix av_url_split */ |
364 | 364 |
if (hostname[0] == '\0' || hostname[0] == '?') { |
365 | 365 |
/* only accepts null hostname if input */ |
366 |
- if (flags & URL_WRONLY) |
|
366 |
+ if (flags & AVIO_WRONLY) |
|
367 | 367 |
goto fail; |
368 | 368 |
} else { |
369 | 369 |
if (ff_udp_set_remote_url(h, uri) < 0) |
370 | 370 |
goto fail; |
371 | 371 |
} |
372 | 372 |
|
373 |
- if (s->is_multicast && !(h->flags & URL_WRONLY)) |
|
373 |
+ if (s->is_multicast && !(h->flags & AVIO_WRONLY)) |
|
374 | 374 |
s->local_port = port; |
375 | 375 |
udp_fd = udp_socket_create(s, &my_addr, &len); |
376 | 376 |
if (udp_fd < 0) |
... | ... |
@@ -387,7 +385,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) |
387 | 387 |
|
388 | 388 |
/* the bind is needed to give a port to the socket now */ |
389 | 389 |
/* if multicast, try the multicast address bind first */ |
390 |
- if (s->is_multicast && !(h->flags & URL_WRONLY)) { |
|
390 |
+ if (s->is_multicast && !(h->flags & AVIO_WRONLY)) { |
|
391 | 391 |
bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len); |
392 | 392 |
} |
393 | 393 |
/* bind to the local address if not multicast or if the multicast |
... | ... |
@@ -400,7 +398,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) |
400 | 400 |
s->local_port = udp_port(&my_addr, len); |
401 | 401 |
|
402 | 402 |
if (s->is_multicast) { |
403 |
- if (h->flags & URL_WRONLY) { |
|
403 |
+ if (h->flags & AVIO_WRONLY) { |
|
404 | 404 |
/* output */ |
405 | 405 |
if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) |
406 | 406 |
goto fail; |
... | ... |
@@ -447,31 +445,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) |
447 | 447 |
static int udp_read(URLContext *h, uint8_t *buf, int size) |
448 | 448 |
{ |
449 | 449 |
UDPContext *s = h->priv_data; |
450 |
- struct pollfd p = {s->udp_fd, POLLIN, 0}; |
|
451 |
- int len; |
|
452 | 450 |
int ret; |
453 | 451 |
|
454 |
- for(;;) { |
|
455 |
- if (url_interrupt_cb()) |
|
456 |
- return AVERROR_EXIT; |
|
457 |
- ret = poll(&p, 1, 100); |
|
458 |
- if (ret < 0) { |
|
459 |
- if (ff_neterrno() == AVERROR(EINTR)) |
|
460 |
- continue; |
|
461 |
- return AVERROR(EIO); |
|
462 |
- } |
|
463 |
- if (!(ret == 1 && p.revents & POLLIN)) |
|
464 |
- continue; |
|
465 |
- len = recv(s->udp_fd, buf, size, 0); |
|
466 |
- if (len < 0) { |
|
467 |
- if (ff_neterrno() != AVERROR(EAGAIN) && |
|
468 |
- ff_neterrno() != AVERROR(EINTR)) |
|
469 |
- return AVERROR(EIO); |
|
470 |
- } else { |
|
471 |
- break; |
|
472 |
- } |
|
452 |
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { |
|
453 |
+ ret = ff_network_wait_fd(s->udp_fd, 0); |
|
454 |
+ if (ret < 0) |
|
455 |
+ return ret; |
|
473 | 456 |
} |
474 |
- return len; |
|
457 |
+ ret = recv(s->udp_fd, buf, size, 0); |
|
458 |
+ return ret < 0 ? ff_neterrno() : ret; |
|
475 | 459 |
} |
476 | 460 |
|
477 | 461 |
static int udp_write(URLContext *h, const uint8_t *buf, int size) |
... | ... |
@@ -479,29 +461,27 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size) |
479 | 479 |
UDPContext *s = h->priv_data; |
480 | 480 |
int ret; |
481 | 481 |
|
482 |
- for(;;) { |
|
483 |
- if (!s->is_connected) { |
|
484 |
- ret = sendto (s->udp_fd, buf, size, 0, |
|
485 |
- (struct sockaddr *) &s->dest_addr, |
|
486 |
- s->dest_addr_len); |
|
487 |
- } else |
|
488 |
- ret = send(s->udp_fd, buf, size, 0); |
|
489 |
- if (ret < 0) { |
|
490 |
- if (ff_neterrno() != AVERROR(EINTR) && |
|
491 |
- ff_neterrno() != AVERROR(EAGAIN)) |
|
492 |
- return ff_neterrno(); |
|
493 |
- } else { |
|
494 |
- break; |
|
495 |
- } |
|
482 |
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { |
|
483 |
+ ret = ff_network_wait_fd(s->udp_fd, 1); |
|
484 |
+ if (ret < 0) |
|
485 |
+ return ret; |
|
496 | 486 |
} |
497 |
- return size; |
|
487 |
+ |
|
488 |
+ if (!s->is_connected) { |
|
489 |
+ ret = sendto (s->udp_fd, buf, size, 0, |
|
490 |
+ (struct sockaddr *) &s->dest_addr, |
|
491 |
+ s->dest_addr_len); |
|
492 |
+ } else |
|
493 |
+ ret = send(s->udp_fd, buf, size, 0); |
|
494 |
+ |
|
495 |
+ return ret < 0 ? ff_neterrno() : ret; |
|
498 | 496 |
} |
499 | 497 |
|
500 | 498 |
static int udp_close(URLContext *h) |
501 | 499 |
{ |
502 | 500 |
UDPContext *s = h->priv_data; |
503 | 501 |
|
504 |
- if (s->is_multicast && !(h->flags & URL_WRONLY)) |
|
502 |
+ if (s->is_multicast && !(h->flags & AVIO_WRONLY)) |
|
505 | 503 |
udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); |
506 | 504 |
closesocket(s->udp_fd); |
507 | 505 |
av_free(s); |
... | ... |
@@ -30,6 +30,8 @@ |
30 | 30 |
|
31 | 31 |
#if !FF_API_OLD_AVIO |
32 | 32 |
#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ |
33 |
+ |
|
34 |
+extern URLInterruptCB *url_interrupt_cb; |
|
33 | 35 |
#endif |
34 | 36 |
|
35 | 37 |
/** |
... | ... |
@@ -131,4 +133,11 @@ int64_t ffurl_size(URLContext *h); |
131 | 131 |
*/ |
132 | 132 |
int ffurl_get_file_handle(URLContext *h); |
133 | 133 |
|
134 |
+/** |
|
135 |
+ * Register the URLProtocol protocol. |
|
136 |
+ * |
|
137 |
+ * @param size the size of the URLProtocol struct referenced |
|
138 |
+ */ |
|
139 |
+int ffurl_register_protocol(URLProtocol *protocol, int size); |
|
140 |
+ |
|
134 | 141 |
#endif //AVFORMAT_URL_H |
... | ... |
@@ -32,6 +32,7 @@ |
32 | 32 |
#include "libavutil/avstring.h" |
33 | 33 |
#include "riff.h" |
34 | 34 |
#include "audiointerleave.h" |
35 |
+#include "url.h" |
|
35 | 36 |
#include <sys/time.h> |
36 | 37 |
#include <time.h> |
37 | 38 |
#include <strings.h> |
... | ... |
@@ -636,7 +637,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, |
636 | 636 |
hack needed to handle RTSP/TCP */ |
637 | 637 |
if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { |
638 | 638 |
/* if no file needed do not try to open one */ |
639 |
- if ((err=avio_open(&pb, filename, URL_RDONLY)) < 0) { |
|
639 |
+ if ((err=avio_open(&pb, filename, AVIO_RDONLY)) < 0) { |
|
640 | 640 |
goto fail; |
641 | 641 |
} |
642 | 642 |
if (buf_size > 0) { |
... | ... |
@@ -22,12 +22,12 @@ stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 |
22 | 22 |
1058444 ./tests/data/acodec/pcm_s16le.wav |
23 | 23 |
95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav |
24 | 24 |
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 |
25 |
-352a6bcf51d0f3ca4bf27c423a3d4d14 *./tests/data/acodec/pcm_s16be.mkv |
|
26 |
- 1060650 ./tests/data/acodec/pcm_s16be.mkv |
|
25 |
+af717ca95eaca310772eb1238c745d1b *./tests/data/acodec/pcm_s16be.mkv |
|
26 |
+1060638 ./tests/data/acodec/pcm_s16be.mkv |
|
27 | 27 |
95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav |
28 | 28 |
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 |
29 |
-2c089d83b2699c02c9358415e00a9707 *./tests/data/acodec/pcm_s16le.mkv |
|
30 |
- 1060650 ./tests/data/acodec/pcm_s16le.mkv |
|
29 |
+c4f51bf32fad2f7af8ea5beedb56168b *./tests/data/acodec/pcm_s16le.mkv |
|
30 |
+1060638 ./tests/data/acodec/pcm_s16le.mkv |
|
31 | 31 |
95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav |
32 | 32 |
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 |
33 | 33 |
07ffe7ffb78f3648b6524debdde5aec1 *./tests/data/acodec/pcm_s24be.mov |