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
92) Then type 'make' to build FFmpeg. GNU Make 3.81 or later is required.92) Then type 'make' to build FFmpeg. GNU Make 3.81 or later is required.
10 10
113) Type 'make install' to install all binaries and libraries you built.113) Type 'make install' to install all binaries and libraries you built.
12
13NOTICE
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
402 402
403Trasmission Control Protocol.403Trasmission Control Protocol.
404 404
405The required syntax for a TCP url is:
406@example
407tcp://@var{hostname}:@var{port}[?@var{options}]
408@end example
409
410@table @option
411
412@item listen
413Listen for an incoming connection
414
415@example
416ffmpeg -i @var{input} -f @var{format} tcp://@var{hostname}:@var{port}?listen
417ffplay tcp://@var{hostname}:@var{port}
418@end example
419
420@end table
421
405@section udp422@section udp
406 423
407User Datagram Protocol.424User Datagram Protocol.
ffmpeg.c+3−3
@@ -2569,7 +2569,7 @@ static int transcode(AVFormatContext **output_files, · 2568 unmodified lines
2569 if (!using_stdin) {2569 if (!using_stdin) {
2570 if(verbose >= 0)2570 if(verbose >= 0)
2571 fprintf(stderr, "Press [q] to stop encoding\n");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 term_init();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 /* open the file */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 print_error(filename, err);3891 print_error(filename, err);
3892 ffmpeg_exit(1);3892 ffmpeg_exit(1);
3893 }3893 }
@@ -4426,7 +4426,7 @@ int main(int argc, char **argv) · 532 unmodified lines
4426 4426
4427#if HAVE_ISATTY4427#if HAVE_ISATTY
4428 if(isatty(STDIN_FILENO))4428 if(isatty(STDIN_FILENO))
4429 url_set_interrupt_cb(decode_interrupt_cb);4429 avio_set_interrupt_cb(decode_interrupt_cb);
4430#endif4430#endif
4431 4431
4432 init_opts();4432 init_opts();
ffplay.c+2−2
@@ -2406,7 +2406,7 @@ static int decode_thread(void *arg) · 2405 unmodified lines
2406 is->subtitle_stream = -1;2406 is->subtitle_stream = -1;
2407 2407
2408 global_video_state = is;2408 global_video_state = is;
2409 url_set_interrupt_cb(decode_interrupt_cb);2409 avio_set_interrupt_cb(decode_interrupt_cb);
2410 2410
2411 memset(ap, 0, sizeof(*ap));2411 memset(ap, 0, sizeof(*ap));
2412 2412
@@ -2626,7 +2626,7 @@ static int decode_thread(void *arg) · 213 unmodified lines
2626 av_close_input_file(is->ic);2626 av_close_input_file(is->ic);
2627 is->ic = NULL; /* safety */2627 is->ic = NULL; /* safety */
2628 }2628 }
2629 url_set_interrupt_cb(NULL);2629 avio_set_interrupt_cb(NULL);
2630 2630
2631 if (ret != 0) {2631 if (ret != 0) {
2632 SDL_Event event;2632 SDL_Event event;
ffserver.c+2−2
@@ -3427,7 +3427,7 @@ static int rtp_new_av_stream(HTTPContext *c, · 3426 unmodified lines
3427 "rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));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 goto fail;3431 goto fail;
3432 c->rtp_handles[stream_index] = h;3432 c->rtp_handles[stream_index] = h;
3433 max_packet_size = url_get_max_packet_size(h);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 /* only write the header of the ffm file */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 http_log("Could not open output feed file '%s'\n",3771 http_log("Could not open output feed file '%s'\n",
3772 feed->feed_filename);3772 feed->feed_filename);
3773 exit(1);3773 exit(1);
libavcodec/avcodec.h+1−1
@@ -2601,7 +2601,7 @@ typedef struct AVCodecContext { · 2600 unmodified lines
2601 */2601 */
2602 int64_t timecode_frame_start;2602 int64_t timecode_frame_start;
2603 2603
2604#if LIBAVCODEC_VERSION_MAJOR < 532604#if FF_API_REQUEST_CHANNELS
2605 /**2605 /**
2606 * Decoder should decode to this many channels if it can (0 for default)2606 * Decoder should decode to this many channels if it can (0 for default)
2607 * - encoding: unused2607 * - encoding: unused
libavcodec/options.c+2−0
@@ -408,7 +408,9 @@ static const AVOption options[]={ · 407 unmodified lines
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},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{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},409{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
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"},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{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D},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{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D},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{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},415{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"},
414{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MBTREE, INT_MIN, INT_MAX, V|E, "flags2"},416{"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
83#ifndef FF_API_ANTIALIAS_ALGO83#ifndef FF_API_ANTIALIAS_ALGO
84#define FF_API_ANTIALIAS_ALGO (LIBAVCODEC_VERSION_MAJOR < 54)84#define FF_API_ANTIALIAS_ALGO (LIBAVCODEC_VERSION_MAJOR < 54)
85#endif85#endif
86#ifndef FF_API_REQUEST_CHANNELS
87#define FF_API_REQUEST_CHANNELS (LIBAVCODEC_VERSION_MAJOR < 53)
88#endif
86 89
87#endif /* AVCODEC_VERSION_H */90#endif /* AVCODEC_VERSION_H */
libavformat/allformats.c+2−1
@@ -21,6 +21,7 @@ · 20 unmodified lines
21#include "avformat.h"21#include "avformat.h"
22#include "rtp.h"22#include "rtp.h"
23#include "rdt.h"23#include "rdt.h"
24#include "url.h"
24 25
25#define REGISTER_MUXER(X,x) { \26#define REGISTER_MUXER(X,x) { \
26 extern AVOutputFormat ff_##x##_muxer; \27 extern AVOutputFormat ff_##x##_muxer; \
@@ -34,7 +35,7 @@ · 7 unmodified lines
34 35
35#define REGISTER_PROTOCOL(X,x) { \36#define REGISTER_PROTOCOL(X,x) { \
36 extern URLProtocol ff_##x##_protocol; \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
39void av_register_all(void)40void av_register_all(void)
40{41{
libavformat/applehttp.c+3−2
@@ -31,6 +31,7 @@ · 30 unmodified lines
31#include "internal.h"31#include "internal.h"
32#include <unistd.h>32#include <unistd.h>
33#include "avio_internal.h"33#include "avio_internal.h"
34#include "url.h"
34 35
35#define INITIAL_BUFFER_SIZE 3276836#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 if (!in) {171 if (!in) {
171 close_in = 1;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 return ret;174 return ret;
174 }175 }
175 176
@@ -292,7 +293,7 @@ reload: · 116 unmodified lines
292 293
293 ret = url_open(&v->input,294 ret = url_open(&v->input,
294 v->segments[v->cur_seq_no - v->start_seq_no]->url,295 v->segments[v->cur_seq_no - v->start_seq_no]->url,
295 URL_RDONLY);296 AVIO_RDONLY);
296 if (ret < 0)297 if (ret < 0)
297 return ret;298 return ret;
298 }299 }
libavformat/applehttpproto.c+3−3
@@ -115,7 +115,7 @@ static int parse_playlist(URLContext *h, const char *url) · 114 unmodified lines
115 char line[1024];115 char line[1024];
116 const char *ptr;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 return ret;119 return ret;
120 120
121 read_chomp_line(in, line, sizeof(line));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 int ret, i;180 int ret, i;
181 const char *nested_url;181 const char *nested_url;
182 182
183 if (flags & (URL_WRONLY | URL_RDWR))183 if (flags & (AVIO_WRONLY | AVIO_RDWR))
184 return AVERROR(ENOSYS);184 return AVERROR(ENOSYS);
185 185
186 s = av_mallocz(sizeof(AppleHTTPContext));186 s = av_mallocz(sizeof(AppleHTTPContext));
@@ -275,7 +275,7 @@ retry: · 88 unmodified lines
275 }275 }
276 url = s->segments[s->cur_seq_no - s->start_seq_no]->url,276 url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
277 av_log(NULL, AV_LOG_DEBUG, "opening %s\n", url);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 if (ret < 0) {279 if (ret < 0) {
280 if (url_interrupt_cb())280 if (url_interrupt_cb())
281 return AVERROR_EXIT;281 return AVERROR_EXIT;
libavformat/avio.c+18−10
@@ -57,7 +57,7 @@ URLProtocol *av_protocol_next(URLProtocol *p) · 56 unmodified lines
57 else return first_protocol;57 else return first_protocol;
58}58}
59 59
60int av_register_protocol2(URLProtocol *protocol, int size)60int ffurl_register_protocol(URLProtocol *protocol, int size)
61{61{
62 URLProtocol **p;62 URLProtocol **p;
63 if (size < sizeof(URLProtocol)) {63 if (size < sizeof(URLProtocol)) {
@@ -86,12 +86,12 @@ struct URLProtocol_compat { · 22 unmodified lines
86 86
87int av_register_protocol(URLProtocol *protocol)87int 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
92int register_protocol(URLProtocol *protocol)92int 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#endif96#endif
97 97
@@ -144,7 +144,7 @@ int ffurl_connect(URLContext* uc) · 46 unmodified lines
144 return err;144 return err;
145 uc->is_connected = 1;145 uc->is_connected = 1;
146 //We must be careful here as ffurl_seek() could be slow, for example for http146 //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 || !strcmp(uc->prot->name, "file"))148 || !strcmp(uc->prot->name, "file"))
149 if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)149 if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)
150 uc->is_streamed= 1;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 av_strlcpy(buf, h->filename, buf_size);217 av_strlcpy(buf, h->filename, buf_size);
218}218}
219void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)
220{
221 avio_set_interrupt_cb(interrupt_cb);
222}
223int av_register_protocol2(URLProtocol *protocol, int size)
224{
225 return ffurl_register_protocol(protocol, size);
226}
219#endif227#endif
220 228
221#define URL_SCHEME_CHARS \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 ret = transfer_func(h, buf+len, size-len);283 ret = transfer_func(h, buf+len, size-len);
276 if (ret == AVERROR(EINTR))284 if (ret == AVERROR(EINTR))
277 continue;285 continue;
278 if (h->flags & URL_FLAG_NONBLOCK)286 if (h->flags & AVIO_FLAG_NONBLOCK)
279 return ret;287 return ret;
280 if (ret == AVERROR(EAGAIN)) {288 if (ret == AVERROR(EAGAIN)) {
281 ret = 0;289 ret = 0;
@@ -296,21 +304,21 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int · 14 unmodified lines
296 304
297int ffurl_read(URLContext *h, unsigned char *buf, int size)305int ffurl_read(URLContext *h, unsigned char *buf, int size)
298{306{
299 if (h->flags & URL_WRONLY)307 if (h->flags & AVIO_WRONLY)
300 return AVERROR(EIO);308 return AVERROR(EIO);
301 return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);309 return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
302}310}
303 311
304int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)312int 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 return AVERROR(EIO);315 return AVERROR(EIO);
308 return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);316 return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
309}317}
310 318
311int ffurl_write(URLContext *h, const unsigned char *buf, int size)319int 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 return AVERROR(EIO);322 return AVERROR(EIO);
315 /* avoid sending too big packets */323 /* avoid sending too big packets */
316 if (h->max_packet_size && size > h->max_packet_size)324 if (h->max_packet_size && size > h->max_packet_size)
@@ -348,7 +356,7 @@ int ffurl_close(URLContext *h) · 31 unmodified lines
348int url_exist(const char *filename)356int url_exist(const char *filename)
349{357{
350 URLContext *h;358 URLContext *h;
351 if (ffurl_open(&h, filename, URL_RDONLY) < 0)359 if (ffurl_open(&h, filename, AVIO_RDONLY) < 0)
352 return 0;360 return 0;
353 ffurl_close(h);361 ffurl_close(h);
354 return 1;362 return 1;
@@ -381,7 +389,7 @@ static int default_interrupt_cb(void) · 26 unmodified lines
381 return 0;389 return 0;
382}390}
383 391
384void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)392void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb)
385{393{
386 if (!interrupt_cb)394 if (!interrupt_cb)
387 interrupt_cb = default_interrupt_cb;395 interrupt_cb = default_interrupt_cb;
libavformat/avio.h+35−3
@@ -63,7 +63,6 @@ typedef struct URLPollEntry { · 62 unmodified lines
63 int events;63 int events;
64 int revents;64 int revents;
65} URLPollEntry;65} URLPollEntry;
66#endif
67 66
68/**67/**
69 * @defgroup open_modes URL open modes68 * @defgroup open_modes URL open modes
@@ -91,6 +90,7 @@ typedef struct URLPollEntry { · 21 unmodified lines
91 * silently ignored.90 * silently ignored.
92 */91 */
93#define URL_FLAG_NONBLOCK 492#define URL_FLAG_NONBLOCK 4
93#endif
94 94
95typedef int URLInterruptCB(void);95typedef 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
117attribute_deprecated int av_url_read_pause(URLContext *h, int pause);117attribute_deprecated int av_url_read_pause(URLContext *h, int pause);
118attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index,118attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index,
119 int64_t timestamp, int flags);119 int64_t timestamp, int flags);
120attribute_deprecated void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
120#endif121#endif
121 122
122/**123/**
@@ -131,7 +132,7 @@ int url_exist(const char *url); · 8 unmodified lines
131 * in this case by the interrupted function. 'NULL' means no interrupt132 * in this case by the interrupted function. 'NULL' means no interrupt
132 * callback is given.133 * callback is given.
133 */134 */
134void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);135void avio_set_interrupt_cb(URLInterruptCB *interrupt_cb);
135 136
136#if FF_API_OLD_AVIO137#if FF_API_OLD_AVIO
137/* not implemented */138/* not implemented */
@@ -162,7 +163,9 @@ typedef struct URLProtocol { · 24 unmodified lines
162extern URLProtocol *first_protocol;163extern URLProtocol *first_protocol;
163#endif164#endif
164 165
166#if FF_API_OLD_AVIO
165extern URLInterruptCB *url_interrupt_cb;167extern URLInterruptCB *url_interrupt_cb;
168#endif
166 169
167/**170/**
168 * If protocol is NULL, returns the first registered protocol,171 * If protocol is NULL, returns the first registered protocol,
@@ -183,12 +186,14 @@ attribute_deprecated int register_protocol(URLProtocol *protocol); · 14 unmodified lines
183attribute_deprecated int av_register_protocol(URLProtocol *protocol);186attribute_deprecated int av_register_protocol(URLProtocol *protocol);
184#endif187#endif
185 188
189#if FF_API_OLD_AVIO
186/**190/**
187 * Register the URLProtocol protocol.191 * Register the URLProtocol protocol.
188 *192 *
189 * @param size the size of the URLProtocol struct referenced193 * @param size the size of the URLProtocol struct referenced
190 */194 */
191int av_register_protocol2(URLProtocol *protocol, int size);195attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size);
196#endif
192 197
193#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */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
510int url_resetbuf(AVIOContext *s, int flags);515int url_resetbuf(AVIOContext *s, int flags);
511#endif516#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 * Create and initialize a AVIOContext for accessing the546 * Create and initialize a AVIOContext for accessing the
515 * resource indicated by url.547 * resource indicated by url.
libavformat/aviobuf.c+7−7
@@ -55,7 +55,7 @@ int ffio_init_context(AVIOContext *s, · 54 unmodified lines
55 s->buffer_size = buffer_size;55 s->buffer_size = buffer_size;
56 s->buf_ptr = buffer;56 s->buf_ptr = buffer;
57 s->opaque = opaque;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 s->write_packet = write_packet;59 s->write_packet = write_packet;
60 s->read_packet = read_packet;60 s->read_packet = read_packet;
61 s->seek = seek;61 s->seek = seek;
@@ -854,7 +854,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) · 792 unmodified lines
854 }854 }
855 855
856 if (ffio_init_context(*s, buffer, buffer_size,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 ffurl_read, ffurl_write, ffurl_seek) < 0) {858 ffurl_read, ffurl_write, ffurl_seek) < 0) {
859 av_free(buffer);859 av_free(buffer);
860 av_freep(s);860 av_freep(s);
@@ -883,7 +883,7 @@ int ffio_set_buf_size(AVIOContext *s, int buf_size) · 22 unmodified lines
883 s->buffer = buffer;883 s->buffer = buffer;
884 s->buffer_size = buf_size;884 s->buffer_size = buf_size;
885 s->buf_ptr = buffer;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 return 0;887 return 0;
888}888}
889 889
@@ -894,13 +894,13 @@ static int url_resetbuf(AVIOContext *s, int flags) · 4 unmodified lines
894#endif894#endif
895{895{
896#if FF_API_URL_RESETBUF896#if FF_API_URL_RESETBUF
897 if (flags & URL_RDWR)897 if (flags & AVIO_RDWR)
898 return AVERROR(EINVAL);898 return AVERROR(EINVAL);
899#else899#else
900 assert(flags == URL_WRONLY || flags == URL_RDONLY);900 assert(flags == AVIO_WRONLY || flags == AVIO_RDONLY);
901#endif901#endif
902 902
903 if (flags & URL_WRONLY) {903 if (flags & AVIO_WRONLY) {
904 s->buf_end = s->buffer + s->buffer_size;904 s->buf_end = s->buffer + s->buffer_size;
905 s->write_flag = 1;905 s->write_flag = 1;
906 } else {906 } else {
@@ -1058,7 +1058,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags) · 151 unmodified lines
1058 if(!*s)1058 if(!*s)
1059 return AVERROR(ENOMEM);1059 return AVERROR(ENOMEM);
1060 ret = ffio_init_context(*s, buf, buf_size,1060 ret = ffio_init_context(*s, buf, buf_size,
1061 (flags & URL_WRONLY || flags & URL_RDWR),1061 (flags & AVIO_WRONLY || flags & AVIO_RDWR),
1062 NULL, NULL, NULL, NULL);1062 NULL, NULL, NULL, NULL);
1063 if(ret != 0)1063 if(ret != 0)
1064 av_freep(s);1064 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
59 59
60 av_strstart(filename, "file:", &filename);60 av_strstart(filename, "file:", &filename);
61 61
62 if (flags & URL_RDWR) {62 if (flags & AVIO_RDWR) {
63 access = O_CREAT | O_TRUNC | O_RDWR;63 access = O_CREAT | O_TRUNC | O_RDWR;
64 } else if (flags & URL_WRONLY) {64 } else if (flags & AVIO_WRONLY) {
65 access = O_CREAT | O_TRUNC | O_WRONLY;65 access = O_CREAT | O_TRUNC | O_WRONLY;
66 } else {66 } else {
67 access = O_RDONLY;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 fd = strtol(filename, &final, 10);117 fd = strtol(filename, &final, 10);
118 if((filename == final) || *final ) {/* No digits found, or something like 10ab */118 if((filename == final) || *final ) {/* No digits found, or something like 10ab */
119 if (flags & URL_WRONLY) {119 if (flags & AVIO_WRONLY) {
120 fd = 1;120 fd = 1;
121 } else {121 } else {
122 fd = 0;122 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
100 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);100 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
101 101
102 s->hd = NULL;102 s->hd = NULL;
103 err = ffurl_open(&s->hd, buf, URL_RDWR);103 err = ffurl_open(&s->hd, buf, AVIO_RDWR);
104 if (err < 0)104 if (err < 0)
105 goto fail;105 goto fail;
106 106
libavformat/http.c+3−3
@@ -124,7 +124,7 @@ static int http_open_cnx(URLContext *h) · 123 unmodified lines
124 port = 80;124 port = 80;
125 125
126 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);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 if (err < 0)128 if (err < 0)
129 goto fail;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 /* send http header */298 /* send http header */
299 post = h->flags & URL_WRONLY;299 post = h->flags & AVIO_WRONLY;
300 authstr = ff_http_auth_create_response(&s->auth_state, auth, path,300 authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
301 post ? "POST" : "GET");301 post ? "POST" : "GET");
302 302
@@ -451,7 +451,7 @@ static int http_close(URLContext *h) · 148 unmodified lines
451 HTTPContext *s = h->priv_data;451 HTTPContext *s = h->priv_data;
452 452
453 /* signal end of chunked encoding if used */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 ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);455 ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
456 ret = ret > 0 ? 0 : ret;456 ret = ret > 0 ? 0 : ret;
457 }457 }
libavformat/img2.c+2−2
@@ -274,7 +274,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt) · 273 unmodified lines
274 s->path, s->img_number)<0 && s->img_number > 1)274 s->path, s->img_number)<0 && s->img_number > 1)
275 return AVERROR(EIO);275 return AVERROR(EIO);
276 for(i=0; i<3; i++){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 if(i==1)278 if(i==1)
279 break;279 break;
280 av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename);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 return AVERROR(EIO);361 return AVERROR(EIO);
362 }362 }
363 for(i=0; i<3; i++){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 av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename);365 av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename);
366 return AVERROR(EIO);366 return AVERROR(EIO);
367 }367 }
libavformat/librtmp.c+1−1
@@ -93,7 +93,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) · 92 unmodified lines
93 goto fail;93 goto fail;
94 }94 }
95 95
96 if (flags & URL_WRONLY)96 if (flags & AVIO_WRONLY)
97 RTMP_EnableWrite(r);97 RTMP_EnableWrite(r);
98 98
99 if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {99 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
1333 && track->codec_priv.size >= 141333 && track->codec_priv.size >= 14
1334 && track->codec_priv.data != NULL) {1334 && track->codec_priv.data != NULL) {
1335 ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,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 ff_get_wav_header(&b, st->codec, track->codec_priv.size);1337 ff_get_wav_header(&b, st->codec, track->codec_priv.size);
1338 codec_id = st->codec->codec_id;1338 codec_id = st->codec->codec_id;
1339 extradata_offset = FFMIN(track->codec_priv.size, 18);1339 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
1144 }1144 }
1145 1145
1146 if (pb->seekable) {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 mkv_write_seekhead(pb, mkv->main_seekhead);1154 mkv_write_seekhead(pb, mkv->main_seekhead);
1152 1155
1153 // update the duration1156 // 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
36 return -1;36 return -1;
37 }37 }
38 38
39 if (flags != URL_WRONLY)39 if (flags != AVIO_WRONLY)
40 return AVERROR(EINVAL);40 return AVERROR(EINVAL);
41 41
42 av_md5_init(h->priv_data);42 av_md5_init(h->priv_data);
@@ -65,7 +65,7 @@ static int md5_close(URLContext *h) · 22 unmodified lines
65 av_strstart(filename, "md5:", &filename);65 av_strstart(filename, "md5:", &filename);
66 66
67 if (*filename) {67 if (*filename) {
68 err = ffurl_open(&out, filename, URL_WRONLY);68 err = ffurl_open(&out, filename, AVIO_WRONLY);
69 if (err)69 if (err)
70 return err;70 return err;
71 err = ffurl_write(out, buf, i*2+1);71 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
233 port = 80; // default mmsh protocol port233 port = 80; // default mmsh protocol port
234 ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path);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 return AVERROR(EIO);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 // close the socket and then reopen it for sending the second play request.261 // close the socket and then reopen it for sending the second play request.
262 ffurl_close(mms->mms_hd);262 ffurl_close(mms->mms_hd);
263 memset(headers, 0, sizeof(headers));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 return AVERROR(EIO);265 return AVERROR(EIO);
266 }266 }
267 stream_selection = av_mallocz(mms->stream_num * 19 + 1);267 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
523 523
524 // establish tcp connection.524 // establish tcp connection.
525 ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL);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 if (err)527 if (err)
528 goto fail;528 goto fail;
529 529
libavformat/mov.c+1−1
@@ -1722,7 +1722,7 @@ static int mov_open_dref(AVIOContext **pb, char *src, MOVDref *ref) · 1721 unmodified lines
1722 1722
1723 av_strlcat(filename, ref->path + l + 1, 1024);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 return 0;1726 return 0;
1727 }1727 }
1728 }1728 }
libavformat/network.h+14−0
@@ -22,6 +22,7 @@ · 21 unmodified lines
22#define AVFORMAT_NETWORK_H22#define AVFORMAT_NETWORK_H
23 23
24#include "config.h"24#include "config.h"
25#include "os_support.h"
25 26
26#if HAVE_WINSOCK2_H27#if HAVE_WINSOCK2_H
27#include <winsock2.h>28#include <winsock2.h>
@@ -55,6 +56,10 @@ static inline int ff_neterrno() { · 27 unmodified lines
55#include <arpa/inet.h>56#include <arpa/inet.h>
56#endif57#endif
57 58
59#if HAVE_POLL_H
60#include <poll.h>
61#endif
62
58int ff_socket_nonblock(int socket, int enable);63int ff_socket_nonblock(int socket, int enable);
59 64
60static inline int ff_network_init(void)65static inline int ff_network_init(void)
@@ -67,6 +72,15 @@ static inline int ff_network_init(void) · 6 unmodified lines
67 return 1;72 return 1;
68}73}
69 74
75static 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
70static inline void ff_network_close(void)84static inline void ff_network_close(void)
71{85{
72#if HAVE_WINSOCK2_H86#if HAVE_WINSOCK2_H
libavformat/output-example.c+1−1
@@ -492,7 +492,7 @@ int main(int argc, char **argv) · 491 unmodified lines
492 492
493 /* open the output file, if needed */493 /* open the output file, if needed */
494 if (!(fmt->flags & AVFMT_NOFILE)) {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 fprintf(stderr, "Could not open '%s'\n", filename);496 fprintf(stderr, "Could not open '%s'\n", filename);
497 exit(1);497 exit(1);
498 }498 }
libavformat/rtmpproto.c+2−2
@@ -812,7 +812,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) · 811 unmodified lines
812 if (!rt)812 if (!rt)
813 return AVERROR(ENOMEM);813 return AVERROR(ENOMEM);
814 s->priv_data = rt;814 s->priv_data = rt;
815 rt->is_input = !(flags & URL_WRONLY);815 rt->is_input = !(flags & AVIO_WRONLY);
816 816
817 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,817 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
818 path, sizeof(path), s->filename);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 port = RTMP_DEFAULT_PORT;821 port = RTMP_DEFAULT_PORT;
822 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);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 av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);825 av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
826 goto fail;826 goto fail;
827 }827 }
libavformat/rtpproto.c+1−1
@@ -145,7 +145,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) · 144 unmodified lines
145 char path[1024];145 char path[1024];
146 const char *p;146 const char *p;
147 147
148 is_output = (flags & URL_WRONLY);148 is_output = (flags & AVIO_WRONLY);
149 149
150 s = av_mallocz(sizeof(RTPContext));150 s = av_mallocz(sizeof(RTPContext));
151 if (!s)151 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
1116 "?localport=%d", j);1116 "?localport=%d", j);
1117 /* we will use two ports per rtp stream (rtp and rtcp) */1117 /* we will use two ports per rtp stream (rtp and rtcp) */
1118 j += 2;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 goto rtp_opened;1120 goto rtp_opened;
1121 }1121 }
1122 }1122 }
1123 1123
1124#if 01124#if 0
1125 /* then try on any port */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 err = AVERROR_INVALIDDATA;1127 err = AVERROR_INVALIDDATA;
1128 goto fail;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 namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);1269 namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
1270 ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,1270 ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
1271 port, "?ttl=%d", ttl);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 err = AVERROR_INVALIDDATA;1273 err = AVERROR_INVALIDDATA;
1274 goto fail;1274 goto fail;
1275 }1275 }
@@ -1396,7 +1396,7 @@ redirect: · 120 unmodified lines
1396 av_get_random_seed(), av_get_random_seed());1396 av_get_random_seed(), av_get_random_seed());
1397 1397
1398 /* GET requests */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 err = AVERROR(EIO);1400 err = AVERROR(EIO);
1401 goto fail;1401 goto fail;
1402 }1402 }
@@ -1417,7 +1417,7 @@ redirect: · 14 unmodified lines
1417 }1417 }
1418 1418
1419 /* POST requests */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 err = AVERROR(EIO);1421 err = AVERROR(EIO);
1422 goto fail;1422 goto fail;
1423 }1423 }
@@ -1460,7 +1460,7 @@ redirect: · 36 unmodified lines
1460 } else {1460 } else {
1461 /* open the tcp connection */1461 /* open the tcp connection */
1462 ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);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 err = AVERROR(EIO);1464 err = AVERROR(EIO);
1465 goto fail;1465 goto fail;
1466 }1466 }
@@ -1807,7 +1807,7 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap) · 340 unmodified lines
1807 namebuf, rtsp_st->sdp_port,1807 namebuf, rtsp_st->sdp_port,
1808 "?localport=%d&ttl=%d", rtsp_st->sdp_port,1808 "?localport=%d&ttl=%d", rtsp_st->sdp_port,
1809 rtsp_st->sdp_ttl);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 err = AVERROR_INVALIDDATA;1811 err = AVERROR_INVALIDDATA;
1812 goto fail;1812 goto fail;
1813 }1813 }
@@ -1863,7 +1863,7 @@ static int rtp_read_header(AVFormatContext *s, · 49 unmodified lines
1863 if (!ff_network_init())1863 if (!ff_network_init())
1864 return AVERROR(EIO);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 if (ret)1867 if (ret)
1868 goto fail;1868 goto fail;
1869 1869
libavformat/sapdec.c+1−1
@@ -85,7 +85,7 @@ static int sap_read_header(AVFormatContext *s, · 84 unmodified lines
85 85
86 ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",86 ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
87 port);87 port);
88 ret = ffurl_open(&sap->ann_fd, url, URL_RDONLY);88 ret = ffurl_open(&sap->ann_fd, url, AVIO_RDONLY);
89 if (ret)89 if (ret)
90 goto fail;90 goto fail;
91 91
libavformat/sapenc.c+2−2
@@ -146,7 +146,7 @@ static int sap_write_header(AVFormatContext *s) · 145 unmodified lines
146 "?ttl=%d", ttl);146 "?ttl=%d", ttl);
147 if (!same_port)147 if (!same_port)
148 base_port += 2;148 base_port += 2;
149 ret = ffurl_open(&fd, url, URL_WRONLY);149 ret = ffurl_open(&fd, url, AVIO_WRONLY);
150 if (ret) {150 if (ret) {
151 ret = AVERROR(EIO);151 ret = AVERROR(EIO);
152 goto fail;152 goto fail;
@@ -158,7 +158,7 @@ static int sap_write_header(AVFormatContext *s) · 5 unmodified lines
158 158
159 ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,159 ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
160 "?ttl=%d&connect=1", ttl);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 if (ret) {162 if (ret) {
163 ret = AVERROR(EIO);163 ret = AVERROR(EIO);
164 goto fail;164 goto fail;
libavformat/tcp.c+27−16
@@ -19,10 +19,12 @@ · 18 unmodified lines
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */20 */
21#include "avformat.h"21#include "avformat.h"
22#include "libavutil/parseutils.h"
22#include <unistd.h>23#include <unistd.h>
23#include "internal.h"24#include "internal.h"
24#include "network.h"25#include "network.h"
25#include "os_support.h"26#include "os_support.h"
27#include "url.h"
26#if HAVE_POLL_H28#if HAVE_POLL_H
27#include <poll.h>29#include <poll.h>
28#endif30#endif
@@ -38,6 +40,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 9 unmodified lines
38 struct addrinfo hints, *ai, *cur_ai;40 struct addrinfo hints, *ai, *cur_ai;
39 int port, fd = -1;41 int port, fd = -1;
40 TCPContext *s = NULL;42 TCPContext *s = NULL;
43 int listen_socket = 0;
44 const char *p;
45 char buf[256];
41 int ret;46 int ret;
42 socklen_t optlen;47 socklen_t optlen;
43 char hostname[1024],proto[1024],path[1024];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 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536)53 if (strcmp(proto,"tcp") || port <= 0 || port >= 65536)
49 return AVERROR(EINVAL);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 memset(&hints, 0, sizeof(hints));61 memset(&hints, 0, sizeof(hints));
52 hints.ai_family = AF_UNSPEC;62 hints.ai_family = AF_UNSPEC;
53 hints.ai_socktype = SOCK_STREAM;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 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);76 fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
67 if (fd < 0)77 if (fd < 0)
68 goto fail;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 redo: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 if (ret < 0) {94 if (ret < 0) {
74 int timeout=50;95 int timeout=50;
75 struct pollfd p = {fd, POLLOUT, 0};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 return ret;159 return ret;
139}160}
140 161
141static 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
151static int tcp_read(URLContext *h, uint8_t *buf, int size)162static int tcp_read(URLContext *h, uint8_t *buf, int size)
152{163{
153 TCPContext *s = h->priv_data;164 TCPContext *s = h->priv_data;
154 int ret;165 int ret;
155 166
156 if (!(h->flags & URL_FLAG_NONBLOCK)) {167 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
157 ret = tcp_wait_fd(s->fd, 0);168 ret = ff_network_wait_fd(s->fd, 0);
158 if (ret < 0)169 if (ret < 0)
159 return ret;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 TCPContext *s = h->priv_data;178 TCPContext *s = h->priv_data;
168 int ret;179 int ret;
169 180
170 if (!(h->flags & URL_FLAG_NONBLOCK)) {181 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
171 ret = tcp_wait_fd(s->fd, 1);182 ret = ff_network_wait_fd(s->fd, 1);
172 if (ret < 0)183 if (ret < 0)
173 return ret;184 return ret;
174 }185 }
libavformat/udp.c+26−46
@@ -33,9 +33,7 @@ · 32 unmodified lines
33#include "internal.h"33#include "internal.h"
34#include "network.h"34#include "network.h"
35#include "os_support.h"35#include "os_support.h"
36#if HAVE_POLL_H36#include "url.h"
37#include <poll.h>
38#endif
39#include <sys/time.h>37#include <sys/time.h>
40 38
41#ifndef IPV6_ADD_MEMBERSHIP39#ifndef IPV6_ADD_MEMBERSHIP
@@ -320,7 +318,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 278 unmodified lines
320 h->is_streamed = 1;318 h->is_streamed = 1;
321 h->max_packet_size = 1472;319 h->max_packet_size = 1472;
322 320
323 is_output = (flags & URL_WRONLY);321 is_output = (flags & AVIO_WRONLY);
324 322
325 s = av_mallocz(sizeof(UDPContext));323 s = av_mallocz(sizeof(UDPContext));
326 if (!s)324 if (!s)
@@ -363,14 +361,14 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 36 unmodified lines
363 /* XXX: fix av_url_split */361 /* XXX: fix av_url_split */
364 if (hostname[0] == '\0' || hostname[0] == '?') {362 if (hostname[0] == '\0' || hostname[0] == '?') {
365 /* only accepts null hostname if input */363 /* only accepts null hostname if input */
366 if (flags & URL_WRONLY)364 if (flags & AVIO_WRONLY)
367 goto fail;365 goto fail;
368 } else {366 } else {
369 if (ff_udp_set_remote_url(h, uri) < 0)367 if (ff_udp_set_remote_url(h, uri) < 0)
370 goto fail;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 s->local_port = port;372 s->local_port = port;
375 udp_fd = udp_socket_create(s, &my_addr, &len);373 udp_fd = udp_socket_create(s, &my_addr, &len);
376 if (udp_fd < 0)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 /* the bind is needed to give a port to the socket now */386 /* the bind is needed to give a port to the socket now */
389 /* if multicast, try the multicast address bind first */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 bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);389 bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);
392 }390 }
393 /* bind to the local address if not multicast or if the multicast391 /* 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 s->local_port = udp_port(&my_addr, len);398 s->local_port = udp_port(&my_addr, len);
401 399
402 if (s->is_multicast) {400 if (s->is_multicast) {
403 if (h->flags & URL_WRONLY) {401 if (h->flags & AVIO_WRONLY) {
404 /* output */402 /* output */
405 if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)403 if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
406 goto fail;404 goto fail;
@@ -447,31 +445,15 @@ static int udp_open(URLContext *h, const char *uri, int flags) · 40 unmodified lines
447static int udp_read(URLContext *h, uint8_t *buf, int size)445static int udp_read(URLContext *h, uint8_t *buf, int size)
448{446{
449 UDPContext *s = h->priv_data;447 UDPContext *s = h->priv_data;
450 struct pollfd p = {s->udp_fd, POLLIN, 0};
451 int len;
452 int ret;448 int ret;
453 449
454 for(;;) {450 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
455 if (url_interrupt_cb())451 ret = ff_network_wait_fd(s->udp_fd, 0);
456 return AVERROR_EXIT;452 if (ret < 0)
457 ret = poll(&p, 1, 100);453 return ret;
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 }
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
477static int udp_write(URLContext *h, const uint8_t *buf, int size)459static 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 UDPContext *s = h->priv_data;461 UDPContext *s = h->priv_data;
480 int ret;462 int ret;
481 463
482 for(;;) {464 if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
483 if (!s->is_connected) {465 ret = ff_network_wait_fd(s->udp_fd, 1);
484 ret = sendto (s->udp_fd, buf, size, 0,466 if (ret < 0)
485 (struct sockaddr *) &s->dest_addr,467 return ret;
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 }
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
500static int udp_close(URLContext *h)480static int udp_close(URLContext *h)
501{481{
502 UDPContext *s = h->priv_data;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 udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);485 udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
506 closesocket(s->udp_fd);486 closesocket(s->udp_fd);
507 av_free(s);487 av_free(s);
libavformat/url.h+9−0
@@ -30,6 +30,8 @@ · 29 unmodified lines
30 30
31#if !FF_API_OLD_AVIO31#if !FF_API_OLD_AVIO
32#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */32#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */
33
34extern URLInterruptCB *url_interrupt_cb;
33#endif35#endif
34 36
35/**37/**
@@ -131,4 +133,11 @@ int64_t ffurl_size(URLContext *h); · 95 unmodified lines
131 */133 */
132int ffurl_get_file_handle(URLContext *h);134int 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 */
141int ffurl_register_protocol(URLProtocol *protocol, int size);
142
134#endif //AVFORMAT_URL_H143#endif //AVFORMAT_URL_H
libavformat/utils.c+2−1
@@ -32,6 +32,7 @@ · 31 unmodified lines
32#include "libavutil/avstring.h"32#include "libavutil/avstring.h"
33#include "riff.h"33#include "riff.h"
34#include "audiointerleave.h"34#include "audiointerleave.h"
35#include "url.h"
35#include <sys/time.h>36#include <sys/time.h>
36#include <time.h>37#include <time.h>
37#include <strings.h>38#include <strings.h>
@@ -636,7 +637,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, · 598 unmodified lines
636 hack needed to handle RTSP/TCP */637 hack needed to handle RTSP/TCP */
637 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {638 if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {
638 /* if no file needed do not try to open one */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 goto fail;641 goto fail;
641 }642 }
642 if (buf_size > 0) {643 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
221058444 ./tests/data/acodec/pcm_s16le.wav221058444 ./tests/data/acodec/pcm_s16le.wav
2395e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav2395e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
24stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 105840024stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
25352a6bcf51d0f3ca4bf27c423a3d4d14 *./tests/data/acodec/pcm_s16be.mkv25af717ca95eaca310772eb1238c745d1b *./tests/data/acodec/pcm_s16be.mkv
26 1060650 ./tests/data/acodec/pcm_s16be.mkv261060638 ./tests/data/acodec/pcm_s16be.mkv
2795e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav2795e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
28stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 105840028stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
292c089d83b2699c02c9358415e00a9707 *./tests/data/acodec/pcm_s16le.mkv29c4f51bf32fad2f7af8ea5beedb56168b *./tests/data/acodec/pcm_s16le.mkv
30 1060650 ./tests/data/acodec/pcm_s16le.mkv301060638 ./tests/data/acodec/pcm_s16le.mkv
3195e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav3195e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav
32stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 105840032stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400
3307ffe7ffb78f3648b6524debdde5aec1 *./tests/data/acodec/pcm_s24be.mov3307ffe7ffb78f3648b6524debdde5aec1 *./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