History

Merge remote branch 'qatar/master'

* 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

Michael Niedermayer committed 15 years ago

Commit c88caa52 parents db95e55 a20312537 files · +222 −136Browse files

Unified · Split

37 files
  1. INSTALL +4 −0
  2. doc/protocols.texi +17 −0
  3. ffmpeg.c +3 −3
  4. ffplay.c +2 −2
  5. ffserver.c +2 −2
  6. libavcodec/avcodec.h +1 −1
  7. libavcodec/options.c +2 −0
  8. libavcodec/version.h +3 −0
  9. libavformat/allformats.c +2 −1
  10. libavformat/applehttp.c +3 −2
  11. libavformat/applehttpproto.c +3 −3
  12. libavformat/avio.c +18 −10
  13. libavformat/avio.h +35 −3
  14. libavformat/aviobuf.c +7 −7
  15. libavformat/file.c +3 −3
  16. libavformat/gopher.c +1 −1
  17. libavformat/http.c +3 −3
  18. libavformat/img2.c +2 −2
  19. libavformat/librtmp.c +1 −1
  20. libavformat/matroskadec.c +1 −1
  21. libavformat/matroskaenc.c +6 −3
  22. libavformat/md5proto.c +2 −2
  23. libavformat/mmsh.c +2 −2
  24. libavformat/mmst.c +1 −1
  25. libavformat/mov.c +1 −1
  26. libavformat/network.h +14 −0
  27. libavformat/output-example.c +1 −1
  28. libavformat/rtmpproto.c +2 −2
  29. libavformat/rtpproto.c +1 −1
  30. libavformat/rtsp.c +8 −8
  31. libavformat/sapdec.c +1 −1
  32. libavformat/sapenc.c +2 −2
  33. libavformat/tcp.c +27 −16
  34. libavformat/udp.c +26 −46
  35. libavformat/url.h +9 −0
  36. libavformat/utils.c +2 −1
  37. tests/ref/acodec/pcm +4 −4
INSTALL+4−0
@@ -9,3 +9,7 @@ path when launching 'configure', e.g. '/ffmpegdir/ffmpeg/configure'. · 8 unmodified lines
99 2) Then type 'make' to build FFmpeg. GNU Make 3.81 or later is required.
1010
1111 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.
doc/protocols.texi+17−0
@@ -402,6 +402,23 @@ ffplay sap://[ff0e::2:7ffe] · 401 unmodified lines
402402
403403 Trasmission Control Protocol.
404404
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+
405422 @section udp
406423
407424 User Datagram Protocol.
ffmpeg.c+3−3
@@ -2569,7 +2569,7 @@ static int transcode(AVFormatContext **output_files, · 2568 unmodified lines
25692569 if (!using_stdin) {
25702570 if(verbose >= 0)
25712571 fprintf(stderr, "Press [q] to stop encoding\n");
2572− url_set_interrupt_cb(decode_interrupt_cb);
2572+ avio_set_interrupt_cb(decode_interrupt_cb);
25732573 }
25742574 term_init();
25752575
@@ -3887,7 +3887,7 @@ static void opt_output_file(const char *filename) · 1311 unmodified lines
38873887 }
38883888
38893889 /* 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) {
38913891 print_error(filename, err);
38923892 ffmpeg_exit(1);
38933893 }
@@ -4426,7 +4426,7 @@ int main(int argc, char **argv) · 532 unmodified lines
44264426
44274427 #if HAVE_ISATTY
44284428 if(isatty(STDIN_FILENO))
4429− url_set_interrupt_cb(decode_interrupt_cb);
4429+ avio_set_interrupt_cb(decode_interrupt_cb);
44304430 #endif
44314431
44324432 init_opts();
ffplay.c+2−2
@@ -2406,7 +2406,7 @@ static int decode_thread(void *arg) · 2405 unmodified lines
24062406 is->subtitle_stream = -1;
24072407
24082408 global_video_state = is;
2409− url_set_interrupt_cb(decode_interrupt_cb);
2409+ avio_set_interrupt_cb(decode_interrupt_cb);
24102410
24112411 memset(ap, 0, sizeof(*ap));
24122412
@@ -2626,7 +2626,7 @@ static int decode_thread(void *arg) · 213 unmodified lines
26262626 av_close_input_file(is->ic);
26272627 is->ic = NULL; /* safety */
26282628 }
2629− url_set_interrupt_cb(NULL);
2629+ avio_set_interrupt_cb(NULL);
26302630
26312631 if (ret != 0) {
26322632 SDL_Event event;
ffserver.c+2−2
@@ -3427,7 +3427,7 @@ static int rtp_new_av_stream(HTTPContext *c, · 3426 unmodified lines
34273427 "rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
34283428 }
34293429
3430− if (url_open(&h, ctx->filename, URL_WRONLY) < 0)
3430+ if (url_open(&h, ctx->filename, AVIO_WRONLY) < 0)
34313431 goto fail;
34323432 c->rtp_handles[stream_index] = h;
34333433 max_packet_size = url_get_max_packet_size(h);
@@ -3767,7 +3767,7 @@ static void build_feed_streams(void) · 333 unmodified lines
37673767 }
37683768
37693769 /* 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) {
37713771 http_log("Could not open output feed file '%s'\n",
37723772 feed->feed_filename);
37733773 exit(1);
libavcodec/avcodec.h+1−1
@@ -2601,7 +2601,7 @@ typedef struct AVCodecContext { · 2600 unmodified lines
26012601 */
26022602 int64_t timecode_frame_start;
26032603
2604−#if LIBAVCODEC_VERSION_MAJOR < 53
2604+#if FF_API_REQUEST_CHANNELS
26052605 /**
26062606 * Decoder should decode to this many channels if it can (0 for default)
26072607 * - encoding: unused
libavcodec/options.c+2−0
@@ -408,7 +408,9 @@ static const AVOption options[]={ · 407 unmodified lines
408408 {"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},
409409 {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
410410 {"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
411412 {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},
413+#endif
412414 {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D},
413415 {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},
414416 {"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MBTREE, INT_MIN, INT_MAX, V|E, "flags2"},
libavcodec/version.h+3−0
@@ -83,5 +83,8 @@ · 82 unmodified lines
8383 #ifndef FF_API_ANTIALIAS_ALGO
8484 #define FF_API_ANTIALIAS_ALGO (LIBAVCODEC_VERSION_MAJOR < 54)
8585 #endif
86+#ifndef FF_API_REQUEST_CHANNELS
87+#define FF_API_REQUEST_CHANNELS (LIBAVCODEC_VERSION_MAJOR < 53)
88+#endif
8689
8790 #endif /* AVCODEC_VERSION_H */
libavformat/allformats.c+2−1
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include "avformat.h"
2222 #include "rtp.h"
2323 #include "rdt.h"
24+#include "url.h"
2425
2526 #define REGISTER_MUXER(X,x) { \
2627 extern AVOutputFormat ff_##x##_muxer; \
@@ -34,7 +35,7 @@ · 7 unmodified lines
3435
3536 #define REGISTER_PROTOCOL(X,x) { \
3637 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)); }
3839
3940 void av_register_all(void)
4041 {
libavformat/applehttp.c+3−2
@@ -31,6 +31,7 @@ · 30 unmodified lines
3131 #include "internal.h"
3232 #include <unistd.h>
3333 #include "avio_internal.h"
34+#include "url.h"
3435
3536 #define INITIAL_BUFFER_SIZE 32768
3637
@@ -169,7 +170,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url, · 132 unmodified lines
169170
170171 if (!in) {
171172 close_in = 1;
172− if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
173+ if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0)
173174 return ret;
174175 }
175176
@@ -292,7 +293,7 @@ reload: · 116 unmodified lines
292293
293294 ret = url_open(&v->input,
294295 v->segments[v->cur_seq_no - v->start_seq_no]->url,
295− URL_RDONLY);
296+ AVIO_RDONLY);
296297 if (ret < 0)
297298 return ret;
298299 }
libavformat/applehttpproto.c+3−3
@@ -115,7 +115,7 @@ static int parse_playlist(URLContext *h, const char *url) · 114 unmodified lines
115115 char line[1024];
116116 const char *ptr;
117117
118− if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
118+ if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0)
119119 return ret;
120120
121121 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
180180 int ret, i;
181181 const char *nested_url;
182182
183− if (flags & (URL_WRONLY | URL_RDWR))
183+ if (flags & (AVIO_WRONLY | AVIO_RDWR))
184184 return AVERROR(ENOSYS);
185185
186186 s = av_mallocz(sizeof(AppleHTTPContext));
@@ -275,7 +275,7 @@ retry: · 88 unmodified lines
275275 }
276276 url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
277277 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);
279279 if (ret < 0) {
280280 if (url_interrupt_cb())
281281 return AVERROR_EXIT;
libavformat/avio.c+18−10
@@ -57,7 +57,7 @@ URLProtocol *av_protocol_next(URLProtocol *p) · 56 unmodified lines
5757 else return first_protocol;
5858 }
5959
60−int av_register_protocol2(URLProtocol *protocol, int size)
60+int ffurl_register_protocol(URLProtocol *protocol, int size)
6161 {
6262 URLProtocol **p;
6363 if (size < sizeof(URLProtocol)) {
@@ -86,12 +86,12 @@ struct URLProtocol_compat { · 22 unmodified lines
8686
8787 int av_register_protocol(URLProtocol *protocol)
8888 {
89− return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat));
89+ return ffurl_register_protocol(protocol, sizeof(struct URLProtocol_compat));
9090 }
9191
9292 int register_protocol(URLProtocol *protocol)
9393 {
94− return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat));
94+ return ffurl_register_protocol(protocol, sizeof(struct URLProtocol_compat));
9595 }
9696 #endif
9797
@@ -144,7 +144,7 @@ int ffurl_connect(URLContext* uc) · 46 unmodified lines
144144 return err;
145145 uc->is_connected = 1;
146146 //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))
148148 || !strcmp(uc->prot->name, "file"))
149149 if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)
150150 uc->is_streamed= 1;
@@ -216,6 +216,14 @@ void url_get_filename(URLContext *h, char *buf, int buf_size) · 65 unmodified lines
216216 {
217217 av_strlcpy(buf, h->filename, buf_size);
218218 }
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+}
219227 #endif
220228
221229 #define URL_SCHEME_CHARS \
@@ -275,7 +283,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int · 53 unmodified lines
275283 ret = transfer_func(h, buf+len, size-len);
276284 if (ret == AVERROR(EINTR))
277285 continue;
278− if (h->flags & URL_FLAG_NONBLOCK)
286+ if (h->flags & AVIO_FLAG_NONBLOCK)
279287 return ret;
280288 if (ret == AVERROR(EAGAIN)) {
281289 ret = 0;
@@ -296,21 +304,21 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int · 14 unmodified lines
296304
297305 int ffurl_read(URLContext *h, unsigned char *buf, int size)
298306 {
299− if (h->flags & URL_WRONLY)
307+ if (h->flags & AVIO_WRONLY)
300308 return AVERROR(EIO);
301309 return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
302310 }
303311
304312 int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
305313 {
306− if (h->flags & URL_WRONLY)
314+ if (h->flags & AVIO_WRONLY)
307315 return AVERROR(EIO);
308316 return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
309317 }
310318
311319 int ffurl_write(URLContext *h, const unsigned char *buf, int size)
312320 {
313− if (!(h->flags & (URL_WRONLY | URL_RDWR)))
321+ if (!(h->flags & (AVIO_WRONLY | AVIO_RDWR)))
314322 return AVERROR(EIO);
315323 /* avoid sending too big packets */
316324 if (h->max_packet_size && size > h->max_packet_size)
@@ -348,7 +356,7 @@ int ffurl_close(URLContext *h) · 31 unmodified lines
348356 int url_exist(const char *filename)
349357 {
350358 URLContext *h;
351− if (ffurl_open(&h, filename, URL_RDONLY) < 0)
359+ if (ffurl_open(&h, filename, AVIO_RDONLY) < 0)
352360 return 0;
353361 ffurl_close(h);
354362 return 1;
@@ -381,7 +389,7 @@ static int default_interrupt_cb(void) · 26 unmodified lines
381389 return 0;
382390 }
383391
384−void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)
392+void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb)
385393 {
386394 if (!interrupt_cb)
387395 interrupt_cb = default_interrupt_cb;
libavformat/avio.h+35−3
@@ -63,7 +63,6 @@ typedef struct URLPollEntry { · 62 unmodified lines
6363 int events;
6464 int revents;
6565 } URLPollEntry;
66−#endif
6766
6867 /**
6968 * @defgroup open_modes URL open modes
@@ -91,6 +90,7 @@ typedef struct URLPollEntry { · 21 unmodified lines
9190 * silently ignored.
9291 */
9392 #define URL_FLAG_NONBLOCK 4
93+#endif
9494
9595 typedef int URLInterruptCB(void);
9696
@@ -117,6 +117,7 @@ attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_siz · 20 unmodified lines
117117 attribute_deprecated int av_url_read_pause(URLContext *h, int pause);
118118 attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index,
119119 int64_t timestamp, int flags);
120+attribute_deprecated void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
120121 #endif
121122
122123 /**
@@ -131,7 +132,7 @@ int url_exist(const char *url); · 8 unmodified lines
131132 * in this case by the interrupted function. 'NULL' means no interrupt
132133 * callback is given.
133134 */
134−void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
135+void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb);
135136
136137 #if FF_API_OLD_AVIO
137138 /* not implemented */
@@ -162,7 +163,9 @@ typedef struct URLProtocol { · 24 unmodified lines
162163 extern URLProtocol *first_protocol;
163164 #endif
164165
166+#if FF_API_OLD_AVIO
165167 extern URLInterruptCB *url_interrupt_cb;
168+#endif
166169
167170 /**
168171 * If protocol is NULL, returns the first registered protocol,
@@ -183,12 +186,14 @@ attribute_deprecated int register_protocol(URLProtocol *protocol); · 14 unmodified lines
183186 attribute_deprecated int av_register_protocol(URLProtocol *protocol);
184187 #endif
185188
189+#if FF_API_OLD_AVIO
186190 /**
187191 * Register the URLProtocol protocol.
188192 *
189193 * @param size the size of the URLProtocol struct referenced
190194 */
191−int av_register_protocol2(URLProtocol *protocol, int size);
195+attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size);
196+#endif
192197
193198 #define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */
194199
@@ -510,6 +515,33 @@ attribute_deprecated static inline int url_is_streamed(AVIOContext *s) · 315 unmodified lines
510515 int url_resetbuf(AVIOContext *s, int flags);
511516 #endif
512517
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+
513545 /**
514546 * Create and initialize a AVIOContext for accessing the
515547 * resource indicated by url.
libavformat/aviobuf.c+7−7
@@ -55,7 +55,7 @@ int ffio_init_context(AVIOContext *s, · 54 unmodified lines
5555 s->buffer_size = buffer_size;
5656 s->buf_ptr = buffer;
5757 s->opaque = opaque;
58− url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY);
58+ url_resetbuf(s, write_flag ? AVIO_WRONLY : AVIO_RDONLY);
5959 s->write_packet = write_packet;
6060 s->read_packet = read_packet;
6161 s->seek = seek;
@@ -854,7 +854,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) · 792 unmodified lines
854854 }
855855
856856 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,
858858 ffurl_read, ffurl_write, ffurl_seek) < 0) {
859859 av_free(buffer);
860860 av_freep(s);
@@ -883,7 +883,7 @@ int ffio_set_buf_size(AVIOContext *s, int buf_size) · 22 unmodified lines
883883 s->buffer = buffer;
884884 s->buffer_size = buf_size;
885885 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);
887887 return 0;
888888 }
889889
@@ -894,13 +894,13 @@ static int url_resetbuf(AVIOContext *s, int flags) · 4 unmodified lines
894894 #endif
895895 {
896896 #if FF_API_URL_RESETBUF
897− if (flags & URL_RDWR)
897+ if (flags & AVIO_RDWR)
898898 return AVERROR(EINVAL);
899899 #else
900− assert(flags == URL_WRONLY || flags == URL_RDONLY);
900+ assert(flags == AVIO_WRONLY || flags == AVIO_RDONLY);
901901 #endif
902902
903− if (flags & URL_WRONLY) {
903+ if (flags & AVIO_WRONLY) {
904904 s->buf_end = s->buffer + s->buffer_size;
905905 s->write_flag = 1;
906906 } else {
@@ -1058,7 +1058,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags) · 151 unmodified lines
10581058 if(!*s)
10591059 return AVERROR(ENOMEM);
10601060 ret = ffio_init_context(*s, buf, buf_size,
1061− (flags & URL_WRONLY || flags & URL_RDWR),
1061+ (flags & AVIO_WRONLY || flags & AVIO_RDWR),
10621062 NULL, NULL, NULL, NULL);
10631063 if(ret != 0)
10641064 av_freep(s);
libavformat/file.c+3−3
@@ -59,9 +59,9 @@ static int file_open(URLContext *h, const char *filename, int flags) · 58 unmodified lines
5959
6060 av_strstart(filename, "file:", &filename);
6161
62− if (flags & URL_RDWR) {
62+ if (flags & AVIO_RDWR) {
6363 access = O_CREAT | O_TRUNC | O_RDWR;
64− } else if (flags & URL_WRONLY) {
64+ } else if (flags & AVIO_WRONLY) {
6565 access = O_CREAT | O_TRUNC | O_WRONLY;
6666 } else {
6767 access = O_RDONLY;
@@ -116,7 +116,7 @@ static int pipe_open(URLContext *h, const char *filename, int flags) · 48 unmodified lines
116116
117117 fd = strtol(filename, &final, 10);
118118 if((filename == final) || *final ) {/* No digits found, or something like 10ab */
119− if (flags & URL_WRONLY) {
119+ if (flags & AVIO_WRONLY) {
120120 fd = 1;
121121 } else {
122122 fd = 0;
libavformat/gopher.c+1−1
@@ -100,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags) · 99 unmodified lines
100100 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
101101
102102 s->hd = NULL;
103− err = ffurl_open(&s->hd, buf, URL_RDWR);
103+ err = ffurl_open(&s->hd, buf, AVIO_RDWR);
104104 if (err < 0)
105105 goto fail;
106106
libavformat/http.c+3−3
@@ -124,7 +124,7 @@ static int http_open_cnx(URLContext *h) · 123 unmodified lines
124124 port = 80;
125125
126126 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);
128128 if (err < 0)
129129 goto fail;
130130
@@ -296,7 +296,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, · 165 unmodified lines
296296
297297
298298 /* send http header */
299− post = h->flags & URL_WRONLY;
299+ post = h->flags & AVIO_WRONLY;
300300 authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
301301 post ? "POST" : "GET");
302302
@@ -451,7 +451,7 @@ static int http_close(URLContext *h) · 148 unmodified lines
451451 HTTPContext *s = h->priv_data;
452452
453453 /* 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) {
455455 ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
456456 ret = ret > 0 ? 0 : ret;
457457 }
libavformat/img2.c+2−2
@@ -274,7 +274,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt) · 273 unmodified lines
274274 s->path, s->img_number)<0 && s->img_number > 1)
275275 return AVERROR(EIO);
276276 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) {
278278 if(i==1)
279279 break;
280280 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
361361 return AVERROR(EIO);
362362 }
363363 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) {
365365 av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename);
366366 return AVERROR(EIO);
367367 }
libavformat/librtmp.c+1−1
@@ -93,7 +93,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) · 92 unmodified lines
9393 goto fail;
9494 }
9595
96− if (flags & URL_WRONLY)
96+ if (flags & AVIO_WRONLY)
9797 RTMP_EnableWrite(r);
9898
9999 if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
libavformat/matroskadec.c+1−1
@@ -1333,7 +1333,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) · 1332 unmodified lines
13331333 && track->codec_priv.size >= 14
13341334 && track->codec_priv.data != NULL) {
13351335 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);
13371337 ff_get_wav_header(&b, st->codec, track->codec_priv.size);
13381338 codec_id = st->codec->codec_id;
13391339 extradata_offset = FFMIN(track->codec_priv.size, 18);
libavformat/matroskaenc.c+6−3
@@ -1144,10 +1144,13 @@ static int mkv_write_trailer(AVFormatContext *s) · 1143 unmodified lines
11441144 }
11451145
11461146 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+ }
11481153
1149− ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES , cuespos);
1150− if (ret < 0) return ret;
11511154 mkv_write_seekhead(pb, mkv->main_seekhead);
11521155
11531156 // update the duration
libavformat/md5proto.c+2−2
@@ -36,7 +36,7 @@ static int md5_open(URLContext *h, const char *filename, int flags) · 35 unmodified lines
3636 return -1;
3737 }
3838
39− if (flags != URL_WRONLY)
39+ if (flags != AVIO_WRONLY)
4040 return AVERROR(EINVAL);
4141
4242 av_md5_init(h->priv_data);
@@ -65,7 +65,7 @@ static int md5_close(URLContext *h) · 22 unmodified lines
6565 av_strstart(filename, "md5:", &filename);
6666
6767 if (*filename) {
68− err = ffurl_open(&out, filename, URL_WRONLY);
68+ err = ffurl_open(&out, filename, AVIO_WRONLY);
6969 if (err)
7070 return err;
7171 err = ffurl_write(out, buf, i*2+1);
libavformat/mmsh.c+2−2
@@ -233,7 +233,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) · 232 unmodified lines
233233 port = 80; // default mmsh protocol port
234234 ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path);
235235
236− if (ffurl_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {
236+ if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_RDONLY) < 0) {
237237 return AVERROR(EIO);
238238 }
239239
@@ -261,7 +261,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) · 21 unmodified lines
261261 // close the socket and then reopen it for sending the second play request.
262262 ffurl_close(mms->mms_hd);
263263 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) {
265265 return AVERROR(EIO);
266266 }
267267 stream_selection = av_mallocz(mms->stream_num * 19 + 1);
libavformat/mmst.c+1−1
@@ -523,7 +523,7 @@ static int mms_open(URLContext *h, const char *uri, int flags) · 522 unmodified lines
523523
524524 // establish tcp connection.
525525 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);
527527 if (err)
528528 goto fail;
529529
libavformat/mov.c+1−1
@@ -1722,7 +1722,7 @@ static int mov_open_dref(AVIOContext **pb, char *src, MOVDref *ref) · 1721 unmodified lines
17221722
17231723 av_strlcat(filename, ref->path + l + 1, 1024);
17241724
1725− if (!avio_open(pb, filename, URL_RDONLY))
1725+ if (!avio_open(pb, filename, AVIO_RDONLY))
17261726 return 0;
17271727 }
17281728 }
libavformat/network.h+14−0
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #define AVFORMAT_NETWORK_H
2323
2424 #include "config.h"
25+#include "os_support.h"
2526
2627 #if HAVE_WINSOCK2_H
2728 #include <winsock2.h>
@@ -55,6 +56,10 @@ static inline int ff_neterrno() { · 27 unmodified lines
5556 #include <arpa/inet.h>
5657 #endif
5758
59+#if HAVE_POLL_H
60+#include <poll.h>
61+#endif
62+
5863 int ff_socket_nonblock(int socket, int enable);
5964
6065 static inline int ff_network_init(void)
@@ -67,6 +72,15 @@ static inline int ff_network_init(void) · 6 unmodified lines
6772 return 1;
6873 }
6974
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+
7084 static inline void ff_network_close(void)
7185 {
7286 #if HAVE_WINSOCK2_H
libavformat/output-example.c+1−1
@@ -492,7 +492,7 @@ int main(int argc, char **argv) · 491 unmodified lines
492492
493493 /* open the output file, if needed */
494494 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) {
496496 fprintf(stderr, "Could not open '%s'\n", filename);
497497 exit(1);
498498 }
libavformat/rtmpproto.c+2−2
@@ -812,7 +812,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) · 811 unmodified lines
812812 if (!rt)
813813 return AVERROR(ENOMEM);
814814 s->priv_data = rt;
815− rt->is_input = !(flags & URL_WRONLY);
815+ rt->is_input = !(flags & AVIO_WRONLY);
816816
817817 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
818818 path, sizeof(path), s->filename);
@@ -821,7 +821,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) · 2 unmodified lines
821821 port = RTMP_DEFAULT_PORT;
822822 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
823823
824− if (ffurl_open(&rt->stream, buf, URL_RDWR) < 0) {
824+ if (ffurl_open(&rt->stream, buf, AVIO_RDWR) < 0) {
825825 av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
826826 goto fail;
827827 }
libavformat/rtpproto.c+1−1
@@ -145,7 +145,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) · 144 unmodified lines
145145 char path[1024];
146146 const char *p;
147147
148− is_output = (flags & URL_WRONLY);
148+ is_output = (flags & AVIO_WRONLY);
149149
150150 s = av_mallocz(sizeof(RTPContext));
151151 if (!s)
libavformat/rtsp.c+8−8
@@ -1116,14 +1116,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 1115 unmodified lines
11161116 "?localport=%d", j);
11171117 /* we will use two ports per rtp stream (rtp and rtcp) */
11181118 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)
11201120 goto rtp_opened;
11211121 }
11221122 }
11231123
11241124 #if 0
11251125 /* 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) {
11271127 err = AVERROR_INVALIDDATA;
11281128 goto fail;
11291129 }
@@ -1269,7 +1269,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, · 139 unmodified lines
12691269 namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
12701270 ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
12711271 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) {
12731273 err = AVERROR_INVALIDDATA;
12741274 goto fail;
12751275 }
@@ -1396,7 +1396,7 @@ redirect: · 120 unmodified lines
13961396 av_get_random_seed(), av_get_random_seed());
13971397
13981398 /* GET requests */
1399− if (ffurl_alloc(&rt->rtsp_hd, httpname, URL_RDONLY) < 0) {
1399+ if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_RDONLY) < 0) {
14001400 err = AVERROR(EIO);
14011401 goto fail;
14021402 }
@@ -1417,7 +1417,7 @@ redirect: · 14 unmodified lines
14171417 }
14181418
14191419 /* 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 ) {
14211421 err = AVERROR(EIO);
14221422 goto fail;
14231423 }
@@ -1460,7 +1460,7 @@ redirect: · 36 unmodified lines
14601460 } else {
14611461 /* open the tcp connection */
14621462 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) {
14641464 err = AVERROR(EIO);
14651465 goto fail;
14661466 }
@@ -1807,7 +1807,7 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap) · 340 unmodified lines
18071807 namebuf, rtsp_st->sdp_port,
18081808 "?localport=%d&ttl=%d", rtsp_st->sdp_port,
18091809 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) {
18111811 err = AVERROR_INVALIDDATA;
18121812 goto fail;
18131813 }
@@ -1863,7 +1863,7 @@ static int rtp_read_header(AVFormatContext *s, · 49 unmodified lines
18631863 if (!ff_network_init())
18641864 return AVERROR(EIO);
18651865
1866− ret = ffurl_open(&in, s->filename, URL_RDONLY);
1866+ ret = ffurl_open(&in, s->filename, AVIO_RDONLY);
18671867 if (ret)
18681868 goto fail;
18691869
libavformat/sapdec.c+1−1
@@ -85,7 +85,7 @@ static int sap_read_header(AVFormatContext *s, · 84 unmodified lines
8585
8686 ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
8787 port);
88− ret = ffurl_open(&sap->ann_fd, url, URL_RDONLY);
88+ ret = ffurl_open(&sap->ann_fd, url, AVIO_RDONLY);
8989 if (ret)
9090 goto fail;
9191
libavformat/sapenc.c+2−2
@@ -146,7 +146,7 @@ static int sap_write_header(AVFormatContext *s) · 145 unmodified lines
146146 "?ttl=%d", ttl);
147147 if (!same_port)
148148 base_port += 2;
149− ret = ffurl_open(&fd, url, URL_WRONLY);
149+ ret = ffurl_open(&fd, url, AVIO_WRONLY);
150150 if (ret) {
151151 ret = AVERROR(EIO);
152152 goto fail;
@@ -158,7 +158,7 @@ static int sap_write_header(AVFormatContext *s) · 5 unmodified lines
158158
159159 ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
160160 "?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);
162162 if (ret) {
163163 ret = AVERROR(EIO);
164164 goto fail;
libavformat/tcp.c+27−16
@@ -19,10 +19,12 @@ · 18 unmodified lines
1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2020 */
2121 #include "avformat.h"
22+#include "libavutil/parseutils.h"
2223 #include <unistd.h>
2324 #include "internal.h"
2425 #include "network.h"
2526 #include "os_support.h"
27+#include "url.h"
2628 #if HAVE_POLL_H
2729 #include <poll.h>
2830 #endif
@@ -38,6 +40,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 9 unmodified lines
3840 struct addrinfo hints, *ai, *cur_ai;
3941 int port, fd = -1;
4042 TCPContext *s = NULL;
43+ int listen_socket = 0;
44+ const char *p;
45+ char buf[256];
4146 int ret;
4247 socklen_t optlen;
4348 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
4853 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536)
4954 return AVERROR(EINVAL);
5055
56+ p = strchr(uri, '?');
57+ if (p) {
58+ if (av_find_info_tag(buf, sizeof(buf), "listen", p))
59+ listen_socket = 1;
60+ }
5161 memset(&hints, 0, sizeof(hints));
5262 hints.ai_family = AF_UNSPEC;
5363 hints.ai_socktype = SOCK_STREAM;
@@ -66,10 +76,21 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 12 unmodified lines
6676 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
6777 if (fd < 0)
6878 goto fail;
69− ff_socket_nonblock(fd, 1);
7079
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 {
7188 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+
7394 if (ret < 0) {
7495 int timeout=50;
7596 struct pollfd p = {fd, POLLOUT, 0};
@@ -138,23 +159,13 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 62 unmodified lines
138159 return ret;
139160 }
140161
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−
151162 static int tcp_read(URLContext *h, uint8_t *buf, int size)
152163 {
153164 TCPContext *s = h->priv_data;
154165 int ret;
155166
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);
158169 if (ret < 0)
159170 return ret;
160171 }
@@ -167,8 +178,8 @@ static int tcp_write(URLContext *h, const uint8_t *buf, int size) · 6 unmodified lines
167178 TCPContext *s = h->priv_data;
168179 int ret;
169180
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);
172183 if (ret < 0)
173184 return ret;
174185 }
libavformat/udp.c+26−46
@@ -33,9 +33,7 @@ · 32 unmodified lines
3333 #include "internal.h"
3434 #include "network.h"
3535 #include "os_support.h"
36−#if HAVE_POLL_H
37−#include <poll.h>
38−#endif
36+#include "url.h"
3937 #include <sys/time.h>
4038
4139 #ifndef IPV6_ADD_MEMBERSHIP
@@ -320,7 +318,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 278 unmodified lines
320318 h->is_streamed = 1;
321319 h->max_packet_size = 1472;
322320
323− is_output = (flags & URL_WRONLY);
321+ is_output = (flags & AVIO_WRONLY);
324322
325323 s = av_mallocz(sizeof(UDPContext));
326324 if (!s)
@@ -363,14 +361,14 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 36 unmodified lines
363361 /* XXX: fix av_url_split */
364362 if (hostname[0] == '\0' || hostname[0] == '?') {
365363 /* only accepts null hostname if input */
366− if (flags & URL_WRONLY)
364+ if (flags & AVIO_WRONLY)
367365 goto fail;
368366 } else {
369367 if (ff_udp_set_remote_url(h, uri) < 0)
370368 goto fail;
371369 }
372370
373− if (s->is_multicast && !(h->flags & URL_WRONLY))
371+ if (s->is_multicast && !(h->flags & AVIO_WRONLY))
374372 s->local_port = port;
375373 udp_fd = udp_socket_create(s, &my_addr, &len);
376374 if (udp_fd < 0)
@@ -387,7 +385,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 10 unmodified lines
387385
388386 /* the bind is needed to give a port to the socket now */
389387 /* 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)) {
391389 bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);
392390 }
393391 /* 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
400398 s->local_port = udp_port(&my_addr, len);
401399
402400 if (s->is_multicast) {
403− if (h->flags & URL_WRONLY) {
401+ if (h->flags & AVIO_WRONLY) {
404402 /* output */
405403 if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
406404 goto fail;
@@ -447,31 +445,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 40 unmodified lines
447445 static int udp_read(URLContext *h, uint8_t *buf, int size)
448446 {
449447 UDPContext *s = h->priv_data;
450− struct pollfd p = {s->udp_fd, POLLIN, 0};
451− int len;
452448 int ret;
453449
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;
473454 }
474− return len;
455+ ret = recv(s->udp_fd, buf, size, 0);
456+ return ret < 0 ? ff_neterrno() : ret;
475457 }
476458
477459 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
479461 UDPContext *s = h->priv_data;
480462 int ret;
481463
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;
496468 }
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;
498478 }
499479
500480 static int udp_close(URLContext *h)
501481 {
502482 UDPContext *s = h->priv_data;
503483
504− if (s->is_multicast && !(h->flags & URL_WRONLY))
484+ if (s->is_multicast && !(h->flags & AVIO_WRONLY))
505485 udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
506486 closesocket(s->udp_fd);
507487 av_free(s);
libavformat/url.h+9−0
@@ -30,6 +30,8 @@ · 29 unmodified lines
3030
3131 #if !FF_API_OLD_AVIO
3232 #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;
3335 #endif
3436
3537 /**
@@ -131,4 +133,11 @@ int64_t ffurl_size(URLContext *h); · 95 unmodified lines
131133 */
132134 int ffurl_get_file_handle(URLContext *h);
133135
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+
134143 #endif //AVFORMAT_URL_H
libavformat/utils.c+2−1
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 #include "libavutil/avstring.h"
3333 #include "riff.h"
3434 #include "audiointerleave.h"
35+#include "url.h"
3536 #include <sys/time.h>
3637 #include <time.h>
3738 #include <strings.h>
@@ -636,7 +637,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, · 598 unmodified lines
636637 hack needed to handle RTSP/TCP */
637638 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {
638639 /* 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) {
640641 goto fail;
641642 }
642643 if (buf_size > 0) {
tests/ref/acodec/pcm+4−4
@@ -22,12 +22,12 @@ stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 · 21 unmodified lines
2222 1058444 ./tests/data/acodec/pcm_s16le.wav
2323 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
2424 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
2727 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
2828 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
3131 95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
3232 stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
3333 07ffe7ffb78f3648b6524debdde5aec1 *./tests/data/acodec/pcm_s24be.mov

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t