* 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
Unified · Split
| @@ -9,3 +9,7 @@ path when launching 'configure', e.g. '/ffmpegdir/ffmpeg/configure'. · 8 unmodified lines | ||
| 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] · 401 unmodified lines | ||
| 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, · 2568 unmodified lines | ||
| 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) · 1311 unmodified lines | ||
| 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) · 532 unmodified lines | ||
| 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) · 2405 unmodified lines | ||
| 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) · 213 unmodified lines | ||
| 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, · 3426 unmodified lines | ||
| 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) · 333 unmodified lines | ||
| 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 { · 2600 unmodified lines | ||
| 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[]={ · 407 unmodified lines | ||
| 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 @@ · 82 unmodified lines | ||
| 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 @@ · 20 unmodified lines | ||
| 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 @@ · 7 unmodified lines | ||
| 34 | 35 | |
| 35 | 36 | #define REGISTER_PROTOCOL(X,x) { \ |
| 36 | 37 | extern URLProtocol ff_##x##_protocol; \ |
| 37 | − if(CONFIG_##X##_PROTOCOL) av_register_protocol2(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } | |
| 38 | + if(CONFIG_##X##_PROTOCOL) ffurl_register_protocol(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } | |
| 38 | 39 | |
| 39 | 40 | void av_register_all(void) |
| 40 | 41 | { |
| @@ -31,6 +31,7 @@ · 30 unmodified lines | ||
| 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, · 132 unmodified lines | ||
| 169 | 170 | |
| 170 | 171 | if (!in) { |
| 171 | 172 | close_in = 1; |
| 172 | − if ((ret = avio_open(&in, url, URL_RDONLY)) < 0) | |
| 173 | + if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0) | |
| 173 | 174 | return ret; |
| 174 | 175 | } |
| 175 | 176 | |
| @@ -292,7 +293,7 @@ reload: · 116 unmodified lines | ||
| 292 | 293 | |
| 293 | 294 | ret = url_open(&v->input, |
| 294 | 295 | v->segments[v->cur_seq_no - v->start_seq_no]->url, |
| 295 | − URL_RDONLY); | |
| 296 | + AVIO_RDONLY); | |
| 296 | 297 | if (ret < 0) |
| 297 | 298 | return ret; |
| 298 | 299 | } |
| @@ -115,7 +115,7 @@ static int parse_playlist(URLContext *h, const char *url) · 114 unmodified lines | ||
| 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) · 58 unmodified lines | ||
| 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: · 88 unmodified lines | ||
| 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) · 56 unmodified lines | ||
| 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 { · 22 unmodified lines | ||
| 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) · 46 unmodified lines | ||
| 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) · 65 unmodified lines | ||
| 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 · 53 unmodified lines | ||
| 275 | 283 | ret = transfer_func(h, buf+len, size-len); |
| 276 | 284 | if (ret == AVERROR(EINTR)) |
| 277 | 285 | continue; |
| 278 | − if (h->flags & URL_FLAG_NONBLOCK) | |
| 286 | + if (h->flags & AVIO_FLAG_NONBLOCK) | |
| 279 | 287 | return ret; |
| 280 | 288 | if (ret == AVERROR(EAGAIN)) { |
| 281 | 289 | ret = 0; |
| @@ -296,21 +304,21 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int · 14 unmodified lines | ||
| 296 | 304 | |
| 297 | 305 | int ffurl_read(URLContext *h, unsigned char *buf, int size) |
| 298 | 306 | { |
| 299 | − if (h->flags & URL_WRONLY) | |
| 307 | + if (h->flags & AVIO_WRONLY) | |
| 300 | 308 | return AVERROR(EIO); |
| 301 | 309 | return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read); |
| 302 | 310 | } |
| 303 | 311 | |
| 304 | 312 | int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) |
| 305 | 313 | { |
| 306 | − if (h->flags & URL_WRONLY) | |
| 314 | + if (h->flags & AVIO_WRONLY) | |
| 307 | 315 | return AVERROR(EIO); |
| 308 | 316 | return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read); |
| 309 | 317 | } |
| 310 | 318 | |
| 311 | 319 | int ffurl_write(URLContext *h, const unsigned char *buf, int size) |
| 312 | 320 | { |
| 313 | − if (!(h->flags & (URL_WRONLY | URL_RDWR))) | |
| 321 | + if (!(h->flags & (AVIO_WRONLY | AVIO_RDWR))) | |
| 314 | 322 | return AVERROR(EIO); |
| 315 | 323 | /* avoid sending too big packets */ |
| 316 | 324 | if (h->max_packet_size && size > h->max_packet_size) |
| @@ -348,7 +356,7 @@ int ffurl_close(URLContext *h) · 31 unmodified lines | ||
| 348 | 356 | int url_exist(const char *filename) |
| 349 | 357 | { |
| 350 | 358 | URLContext *h; |
| 351 | − if (ffurl_open(&h, filename, URL_RDONLY) < 0) | |
| 359 | + if (ffurl_open(&h, filename, AVIO_RDONLY) < 0) | |
| 352 | 360 | return 0; |
| 353 | 361 | ffurl_close(h); |
| 354 | 362 | return 1; |
| @@ -381,7 +389,7 @@ static int default_interrupt_cb(void) · 26 unmodified lines | ||
| 381 | 389 | return 0; |
| 382 | 390 | } |
| 383 | 391 | |
| 384 | −void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) | |
| 392 | +void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb) | |
| 385 | 393 | { |
| 386 | 394 | if (!interrupt_cb) |
| 387 | 395 | interrupt_cb = default_interrupt_cb; |
| @@ -63,7 +63,6 @@ typedef struct URLPollEntry { · 62 unmodified lines | ||
| 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 { · 21 unmodified lines | ||
| 91 | 90 | * silently ignored. |
| 92 | 91 | */ |
| 93 | 92 | #define URL_FLAG_NONBLOCK 4 |
| 93 | +#endif | |
| 94 | 94 | |
| 95 | 95 | typedef int URLInterruptCB(void); |
| 96 | 96 | |
| @@ -117,6 +117,7 @@ attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_siz · 20 unmodified lines | ||
| 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); · 8 unmodified lines | ||
| 131 | 132 | * in this case by the interrupted function. 'NULL' means no interrupt |
| 132 | 133 | * callback is given. |
| 133 | 134 | */ |
| 134 | −void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); | |
| 135 | +void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb); | |
| 135 | 136 | |
| 136 | 137 | #if FF_API_OLD_AVIO |
| 137 | 138 | /* not implemented */ |
| @@ -162,7 +163,9 @@ typedef struct URLProtocol { · 24 unmodified lines | ||
| 162 | 163 | extern URLProtocol *first_protocol; |
| 163 | 164 | #endif |
| 164 | 165 | |
| 166 | +#if FF_API_OLD_AVIO | |
| 165 | 167 | extern URLInterruptCB *url_interrupt_cb; |
| 168 | +#endif | |
| 166 | 169 | |
| 167 | 170 | /** |
| 168 | 171 | * If protocol is NULL, returns the first registered protocol, |
| @@ -183,12 +186,14 @@ attribute_deprecated int register_protocol(URLProtocol *protocol); · 14 unmodified lines | ||
| 183 | 186 | attribute_deprecated int av_register_protocol(URLProtocol *protocol); |
| 184 | 187 | #endif |
| 185 | 188 | |
| 189 | +#if FF_API_OLD_AVIO | |
| 186 | 190 | /** |
| 187 | 191 | * Register the URLProtocol protocol. |
| 188 | 192 | * |
| 189 | 193 | * @param size the size of the URLProtocol struct referenced |
| 190 | 194 | */ |
| 191 | −int av_register_protocol2(URLProtocol *protocol, int size); | |
| 195 | +attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size); | |
| 196 | +#endif | |
| 192 | 197 | |
| 193 | 198 | #define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ |
| 194 | 199 | |
| @@ -510,6 +515,33 @@ attribute_deprecated static inline int url_is_streamed(AVIOContext *s) · 315 unmodified lines | ||
| 510 | 515 | int url_resetbuf(AVIOContext *s, int flags); |
| 511 | 516 | #endif |
| 512 | 517 | |
| 518 | +/** | |
| 519 | + * @defgroup open_modes URL open modes | |
| 520 | + * The flags argument to avio_open must be one of the following | |
| 521 | + * constants, optionally ORed with other flags. | |
| 522 | + * @{ | |
| 523 | + */ | |
| 524 | +#define AVIO_RDONLY 0 /**< read-only */ | |
| 525 | +#define AVIO_WRONLY 1 /**< write-only */ | |
| 526 | +#define AVIO_RDWR 2 /**< read-write */ | |
| 527 | +/** | |
| 528 | + * @} | |
| 529 | + */ | |
| 530 | + | |
| 531 | +/** | |
| 532 | + * Use non-blocking mode. | |
| 533 | + * If this flag is set, operations on the context will return | |
| 534 | + * AVERROR(EAGAIN) if they can not be performed immediately. | |
| 535 | + * If this flag is not set, operations on the context will never return | |
| 536 | + * AVERROR(EAGAIN). | |
| 537 | + * Note that this flag does not affect the opening/connecting of the | |
| 538 | + * context. Connecting a protocol will always block if necessary (e.g. on | |
| 539 | + * network protocols) but never hang (e.g. on busy devices). | |
| 540 | + * Warning: non-blocking protocols is work-in-progress; this flag may be | |
| 541 | + * silently ignored. | |
| 542 | + */ | |
| 543 | +#define AVIO_FLAG_NONBLOCK 4 | |
| 544 | + | |
| 513 | 545 | /** |
| 514 | 546 | * Create and initialize a AVIOContext for accessing the |
| 515 | 547 | * resource indicated by url. |
| @@ -55,7 +55,7 @@ int ffio_init_context(AVIOContext *s, · 54 unmodified lines | ||
| 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) · 792 unmodified lines | ||
| 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) · 22 unmodified lines | ||
| 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) · 4 unmodified lines | ||
| 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) · 151 unmodified lines | ||
| 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) · 58 unmodified lines | ||
| 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) · 48 unmodified lines | ||
| 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) · 99 unmodified lines | ||
| 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) · 123 unmodified lines | ||
| 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, · 165 unmodified lines | ||
| 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) · 148 unmodified lines | ||
| 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) · 273 unmodified lines | ||
| 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) · 80 unmodified lines | ||
| 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 | } |
| @@ -93,7 +93,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) · 92 unmodified lines | ||
| 93 | 93 | goto fail; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | − if (flags & URL_WRONLY) | |
| 96 | + if (flags & AVIO_WRONLY) | |
| 97 | 97 | RTMP_EnableWrite(r); |
| 98 | 98 | |
| 99 | 99 | if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) { |
| @@ -1333,7 +1333,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) · 1332 unmodified lines | ||
| 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) · 1143 unmodified lines | ||
| 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) · 35 unmodified lines | ||
| 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) · 22 unmodified lines | ||
| 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) · 232 unmodified lines | ||
| 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) · 21 unmodified lines | ||
| 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) · 522 unmodified lines | ||
| 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) · 1721 unmodified lines | ||
| 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 @@ · 21 unmodified lines | ||
| 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() { · 27 unmodified lines | ||
| 55 | 56 | #include <arpa/inet.h> |
| 56 | 57 | #endif |
| 57 | 58 | |
| 59 | +#if HAVE_POLL_H | |
| 60 | +#include <poll.h> | |
| 61 | +#endif | |
| 62 | + | |
| 58 | 63 | int ff_socket_nonblock(int socket, int enable); |
| 59 | 64 | |
| 60 | 65 | static inline int ff_network_init(void) |
| @@ -67,6 +72,15 @@ static inline int ff_network_init(void) · 6 unmodified lines | ||
| 67 | 72 | return 1; |
| 68 | 73 | } |
| 69 | 74 | |
| 75 | +static inline int ff_network_wait_fd(int fd, int write) | |
| 76 | +{ | |
| 77 | + int ev = write ? POLLOUT : POLLIN; | |
| 78 | + struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; | |
| 79 | + int ret; | |
| 80 | + ret = poll(&p, 1, 100); | |
| 81 | + return ret < 0 ? ff_neterrno() : p.revents & ev ? 0 : AVERROR(EAGAIN); | |
| 82 | +} | |
| 83 | + | |
| 70 | 84 | static inline void ff_network_close(void) |
| 71 | 85 | { |
| 72 | 86 | #if HAVE_WINSOCK2_H |
| @@ -492,7 +492,7 @@ int main(int argc, char **argv) · 491 unmodified lines | ||
| 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) · 811 unmodified lines | ||
| 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) · 2 unmodified lines | ||
| 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 | } |
| @@ -145,7 +145,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) · 144 unmodified lines | ||
| 145 | 145 | char path[1024]; |
| 146 | 146 | const char *p; |
| 147 | 147 | |
| 148 | − is_output = (flags & URL_WRONLY); | |
| 148 | + is_output = (flags & AVIO_WRONLY); | |
| 149 | 149 | |
| 150 | 150 | s = av_mallocz(sizeof(RTPContext)); |
| 151 | 151 | if (!s) |
| @@ -1116,14 +1116,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 1115 unmodified lines | ||
| 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, · 139 unmodified lines | ||
| 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: · 120 unmodified lines | ||
| 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: · 14 unmodified lines | ||
| 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: · 36 unmodified lines | ||
| 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) · 340 unmodified lines | ||
| 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, · 49 unmodified lines | ||
| 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, · 84 unmodified lines | ||
| 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) · 145 unmodified lines | ||
| 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) · 5 unmodified lines | ||
| 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 @@ · 18 unmodified lines | ||
| 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) · 9 unmodified lines | ||
| 38 | 40 | struct addrinfo hints, *ai, *cur_ai; |
| 39 | 41 | int port, fd = -1; |
| 40 | 42 | TCPContext *s = NULL; |
| 43 | + int listen_socket = 0; | |
| 44 | + const char *p; | |
| 45 | + char buf[256]; | |
| 41 | 46 | int ret; |
| 42 | 47 | socklen_t optlen; |
| 43 | 48 | char hostname[1024],proto[1024],path[1024]; |
| @@ -48,6 +53,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 4 unmodified lines | ||
| 48 | 53 | if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) |
| 49 | 54 | return AVERROR(EINVAL); |
| 50 | 55 | |
| 56 | + p = strchr(uri, '?'); | |
| 57 | + if (p) { | |
| 58 | + if (av_find_info_tag(buf, sizeof(buf), "listen", p)) | |
| 59 | + listen_socket = 1; | |
| 60 | + } | |
| 51 | 61 | memset(&hints, 0, sizeof(hints)); |
| 52 | 62 | hints.ai_family = AF_UNSPEC; |
| 53 | 63 | hints.ai_socktype = SOCK_STREAM; |
| @@ -66,10 +76,21 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 12 unmodified lines | ||
| 66 | 76 | fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); |
| 67 | 77 | if (fd < 0) |
| 68 | 78 | goto fail; |
| 69 | − ff_socket_nonblock(fd, 1); | |
| 70 | 79 | |
| 80 | + if (listen_socket) { | |
| 81 | + int fd1; | |
| 82 | + ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); | |
| 83 | + listen(fd, 1); | |
| 84 | + fd1 = accept(fd, NULL, NULL); | |
| 85 | + closesocket(fd); | |
| 86 | + fd = fd1; | |
| 87 | + } else { | |
| 71 | 88 | redo: |
| 72 | − ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); | |
| 89 | + ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); | |
| 90 | + } | |
| 91 | + | |
| 92 | + ff_socket_nonblock(fd, 1); | |
| 93 | + | |
| 73 | 94 | if (ret < 0) { |
| 74 | 95 | int timeout=50; |
| 75 | 96 | struct pollfd p = {fd, POLLOUT, 0}; |
| @@ -138,23 +159,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 62 unmodified lines | ||
| 138 | 159 | return ret; |
| 139 | 160 | } |
| 140 | 161 | |
| 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 | 162 | static int tcp_read(URLContext *h, uint8_t *buf, int size) |
| 152 | 163 | { |
| 153 | 164 | TCPContext *s = h->priv_data; |
| 154 | 165 | int ret; |
| 155 | 166 | |
| 156 | − if (!(h->flags & URL_FLAG_NONBLOCK)) { | |
| 157 | − ret = tcp_wait_fd(s->fd, 0); | |
| 167 | + if (!(h->flags & AVIO_FLAG_NONBLOCK)) { | |
| 168 | + ret = ff_network_wait_fd(s->fd, 0); | |
| 158 | 169 | if (ret < 0) |
| 159 | 170 | return ret; |
| 160 | 171 | } |
| @@ -167,8 +178,8 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int size) · 6 unmodified lines | ||
| 167 | 178 | TCPContext *s = h->priv_data; |
| 168 | 179 | int ret; |
| 169 | 180 | |
| 170 | − if (!(h->flags & URL_FLAG_NONBLOCK)) { | |
| 171 | − ret = tcp_wait_fd(s->fd, 1); | |
| 181 | + if (!(h->flags & AVIO_FLAG_NONBLOCK)) { | |
| 182 | + ret = ff_network_wait_fd(s->fd, 1); | |
| 172 | 183 | if (ret < 0) |
| 173 | 184 | return ret; |
| 174 | 185 | } |
| @@ -33,9 +33,7 @@ · 32 unmodified lines | ||
| 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) · 278 unmodified lines | ||
| 320 | 318 | h->is_streamed = 1; |
| 321 | 319 | h->max_packet_size = 1472; |
| 322 | 320 | |
| 323 | − is_output = (flags & URL_WRONLY); | |
| 321 | + is_output = (flags & AVIO_WRONLY); | |
| 324 | 322 | |
| 325 | 323 | s = av_mallocz(sizeof(UDPContext)); |
| 326 | 324 | if (!s) |
| @@ -363,14 +361,14 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 36 unmodified lines | ||
| 363 | 361 | /* XXX: fix av_url_split */ |
| 364 | 362 | if (hostname[0] == '\0' || hostname[0] == '?') { |
| 365 | 363 | /* only accepts null hostname if input */ |
| 366 | − if (flags & URL_WRONLY) | |
| 364 | + if (flags & AVIO_WRONLY) | |
| 367 | 365 | goto fail; |
| 368 | 366 | } else { |
| 369 | 367 | if (ff_udp_set_remote_url(h, uri) < 0) |
| 370 | 368 | goto fail; |
| 371 | 369 | } |
| 372 | 370 | |
| 373 | − if (s->is_multicast && !(h->flags & URL_WRONLY)) | |
| 371 | + if (s->is_multicast && !(h->flags & AVIO_WRONLY)) | |
| 374 | 372 | s->local_port = port; |
| 375 | 373 | udp_fd = udp_socket_create(s, &my_addr, &len); |
| 376 | 374 | if (udp_fd < 0) |
| @@ -387,7 +385,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 10 unmodified lines | ||
| 387 | 385 | |
| 388 | 386 | /* the bind is needed to give a port to the socket now */ |
| 389 | 387 | /* if multicast, try the multicast address bind first */ |
| 390 | − if (s->is_multicast && !(h->flags & URL_WRONLY)) { | |
| 388 | + if (s->is_multicast && !(h->flags & AVIO_WRONLY)) { | |
| 391 | 389 | bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len); |
| 392 | 390 | } |
| 393 | 391 | /* 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) · 6 unmodified lines | ||
| 400 | 398 | s->local_port = udp_port(&my_addr, len); |
| 401 | 399 | |
| 402 | 400 | if (s->is_multicast) { |
| 403 | − if (h->flags & URL_WRONLY) { | |
| 401 | + if (h->flags & AVIO_WRONLY) { | |
| 404 | 402 | /* output */ |
| 405 | 403 | if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) |
| 406 | 404 | goto fail; |
| @@ -447,31 +445,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 40 unmodified lines | ||
| 447 | 445 | static int udp_read(URLContext *h, uint8_t *buf, int size) |
| 448 | 446 | { |
| 449 | 447 | UDPContext *s = h->priv_data; |
| 450 | − struct pollfd p = {s->udp_fd, POLLIN, 0}; | |
| 451 | − int len; | |
| 452 | 448 | int ret; |
| 453 | 449 | |
| 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 | − } | |
| 450 | + if (!(h->flags & AVIO_FLAG_NONBLOCK)) { | |
| 451 | + ret = ff_network_wait_fd(s->udp_fd, 0); | |
| 452 | + if (ret < 0) | |
| 453 | + return ret; | |
| 473 | 454 | } |
| 474 | − return len; | |
| 455 | + ret = recv(s->udp_fd, buf, size, 0); | |
| 456 | + return ret < 0 ? ff_neterrno() : ret; | |
| 475 | 457 | } |
| 476 | 458 | |
| 477 | 459 | 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) · 1 unmodified line | ||
| 479 | 461 | UDPContext *s = h->priv_data; |
| 480 | 462 | int ret; |
| 481 | 463 | |
| 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 | − } | |
| 464 | + if (!(h->flags & AVIO_FLAG_NONBLOCK)) { | |
| 465 | + ret = ff_network_wait_fd(s->udp_fd, 1); | |
| 466 | + if (ret < 0) | |
| 467 | + return ret; | |
| 496 | 468 | } |
| 497 | − return size; | |
| 469 | + | |
| 470 | + if (!s->is_connected) { | |
| 471 | + ret = sendto (s->udp_fd, buf, size, 0, | |
| 472 | + (struct sockaddr *) &s->dest_addr, | |
| 473 | + s->dest_addr_len); | |
| 474 | + } else | |
| 475 | + ret = send(s->udp_fd, buf, size, 0); | |
| 476 | + | |
| 477 | + return ret < 0 ? ff_neterrno() : ret; | |
| 498 | 478 | } |
| 499 | 479 | |
| 500 | 480 | static int udp_close(URLContext *h) |
| 501 | 481 | { |
| 502 | 482 | UDPContext *s = h->priv_data; |
| 503 | 483 | |
| 504 | − if (s->is_multicast && !(h->flags & URL_WRONLY)) | |
| 484 | + if (s->is_multicast && !(h->flags & AVIO_WRONLY)) | |
| 505 | 485 | udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); |
| 506 | 486 | closesocket(s->udp_fd); |
| 507 | 487 | av_free(s); |
| @@ -30,6 +30,8 @@ · 29 unmodified lines | ||
| 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); · 95 unmodified lines | ||
| 131 | 133 | */ |
| 132 | 134 | int ffurl_get_file_handle(URLContext *h); |
| 133 | 135 | |
| 136 | +/** | |
| 137 | + * Register the URLProtocol protocol. | |
| 138 | + * | |
| 139 | + * @param size the size of the URLProtocol struct referenced | |
| 140 | + */ | |
| 141 | +int ffurl_register_protocol(URLProtocol *protocol, int size); | |
| 142 | + | |
| 134 | 143 | #endif //AVFORMAT_URL_H |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | ||
| 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, · 598 unmodified lines | ||
| 636 | 637 | hack needed to handle RTSP/TCP */ |
| 637 | 638 | if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { |
| 638 | 639 | /* if no file needed do not try to open one */ |
| 639 | − if ((err=avio_open(&pb, filename, URL_RDONLY)) < 0) { | |
| 640 | + if ((err=avio_open(&pb, filename, AVIO_RDONLY)) < 0) { | |
| 640 | 641 | goto fail; |
| 641 | 642 | } |
| 642 | 643 | if (buf_size > 0) { |
| @@ -22,12 +22,12 @@ stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 · 21 unmodified lines | ||
| 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 |