}
/* open the file */
- if ((err = avio_open(&oc->pb, filename, URL_WRONLY)) < 0) {
+ if ((err = avio_open(&oc->pb, filename, AVIO_WRONLY)) < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
"rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
}
- if (url_open(&h, ctx->filename, URL_WRONLY) < 0)
+ if (url_open(&h, ctx->filename, AVIO_WRONLY) < 0)
goto fail;
c->rtp_handles[stream_index] = h;
max_packet_size = url_get_max_packet_size(h);
}
/* only write the header of the ffm file */
- if (avio_open(&s->pb, feed->feed_filename, URL_WRONLY) < 0) {
+ if (avio_open(&s->pb, feed->feed_filename, AVIO_WRONLY) < 0) {
http_log("Could not open output feed file '%s'\n",
feed->feed_filename);
exit(1);
if (!in) {
close_in = 1;
- if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
+ if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0)
return ret;
}
ret = url_open(&v->input,
v->segments[v->cur_seq_no - v->start_seq_no]->url,
- URL_RDONLY);
+ AVIO_RDONLY);
if (ret < 0)
return ret;
}
char line[1024];
const char *ptr;
- if ((ret = avio_open(&in, url, URL_RDONLY)) < 0)
+ if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0)
return ret;
read_chomp_line(in, line, sizeof(line));
int ret, i;
const char *nested_url;
- if (flags & (URL_WRONLY | URL_RDWR))
+ if (flags & (AVIO_WRONLY | AVIO_RDWR))
return AVERROR(ENOSYS);
s = av_mallocz(sizeof(AppleHTTPContext));
}
url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
av_log(NULL, AV_LOG_DEBUG, "opening %s\n", url);
- ret = ffurl_open(&s->seg_hd, url, URL_RDONLY);
+ ret = ffurl_open(&s->seg_hd, url, AVIO_RDONLY);
if (ret < 0) {
if (url_interrupt_cb())
return AVERROR_EXIT;
return err;
uc->is_connected = 1;
//We must be careful here as ffurl_seek() could be slow, for example for http
- if( (uc->flags & (URL_WRONLY | URL_RDWR))
+ if( (uc->flags & (AVIO_WRONLY | AVIO_RDWR))
|| !strcmp(uc->prot->name, "file"))
if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)
uc->is_streamed= 1;
ret = transfer_func(h, buf+len, size-len);
if (ret == AVERROR(EINTR))
continue;
- if (h->flags & URL_FLAG_NONBLOCK)
+ if (h->flags & AVIO_FLAG_NONBLOCK)
return ret;
if (ret == AVERROR(EAGAIN)) {
ret = 0;
int ffurl_read(URLContext *h, unsigned char *buf, int size)
{
- if (h->flags & URL_WRONLY)
+ if (h->flags & AVIO_WRONLY)
return AVERROR(EIO);
return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
}
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
{
- if (h->flags & URL_WRONLY)
+ if (h->flags & AVIO_WRONLY)
return AVERROR(EIO);
return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
}
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
{
- if (!(h->flags & (URL_WRONLY | URL_RDWR)))
+ if (!(h->flags & (AVIO_WRONLY | AVIO_RDWR)))
return AVERROR(EIO);
/* avoid sending too big packets */
if (h->max_packet_size && size > h->max_packet_size)
int url_exist(const char *filename)
{
URLContext *h;
- if (ffurl_open(&h, filename, URL_RDONLY) < 0)
+ if (ffurl_open(&h, filename, AVIO_RDONLY) < 0)
return 0;
ffurl_close(h);
return 1;
int events;
int revents;
} URLPollEntry;
-#endif
/**
* @defgroup open_modes URL open modes
* silently ignored.
*/
#define URL_FLAG_NONBLOCK 4
+#endif
typedef int URLInterruptCB(void);
#endif
/**
+ * @defgroup open_modes URL open modes
+ * The flags argument to avio_open must be one of the following
+ * constants, optionally ORed with other flags.
+ * @{
+ */
+#define AVIO_RDONLY 0 /**< read-only */
+#define AVIO_WRONLY 1 /**< write-only */
+#define AVIO_RDWR 2 /**< read-write */
+/**
+ * @}
+ */
+
+/**
+ * Use non-blocking mode.
+ * If this flag is set, operations on the context will return
+ * AVERROR(EAGAIN) if they can not be performed immediately.
+ * If this flag is not set, operations on the context will never return
+ * AVERROR(EAGAIN).
+ * Note that this flag does not affect the opening/connecting of the
+ * context. Connecting a protocol will always block if necessary (e.g. on
+ * network protocols) but never hang (e.g. on busy devices).
+ * Warning: non-blocking protocols is work-in-progress; this flag may be
+ * silently ignored.
+ */
+#define AVIO_FLAG_NONBLOCK 4
+
+/**
* Create and initialize a AVIOContext for accessing the
* resource indicated by url.
* @note When the resource indicated by url has been opened in
s->buffer_size = buffer_size;
s->buf_ptr = buffer;
s->opaque = opaque;
- url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY);
+ url_resetbuf(s, write_flag ? AVIO_WRONLY : AVIO_RDONLY);
s->write_packet = write_packet;
s->read_packet = read_packet;
s->seek = seek;
}
if (ffio_init_context(*s, buffer, buffer_size,
- (h->flags & URL_WRONLY || h->flags & URL_RDWR), h,
+ (h->flags & AVIO_WRONLY || h->flags & AVIO_RDWR), h,
ffurl_read, ffurl_write, ffurl_seek) < 0) {
av_free(buffer);
av_freep(s);
s->buffer = buffer;
s->buffer_size = buf_size;
s->buf_ptr = buffer;
- url_resetbuf(s, s->write_flag ? URL_WRONLY : URL_RDONLY);
+ url_resetbuf(s, s->write_flag ? AVIO_WRONLY : AVIO_RDONLY);
return 0;
}
#endif
{
#if FF_API_URL_RESETBUF
- if (flags & URL_RDWR)
+ if (flags & AVIO_RDWR)
return AVERROR(EINVAL);
#else
- assert(flags == URL_WRONLY || flags == URL_RDONLY);
+ assert(flags == AVIO_WRONLY || flags == AVIO_RDONLY);
#endif
- if (flags & URL_WRONLY) {
+ if (flags & AVIO_WRONLY) {
s->buf_end = s->buffer + s->buffer_size;
s->write_flag = 1;
} else {
if(!*s)
return AVERROR(ENOMEM);
ret = ffio_init_context(*s, buf, buf_size,
- (flags & URL_WRONLY || flags & URL_RDWR),
+ (flags & AVIO_WRONLY || flags & AVIO_RDWR),
NULL, NULL, NULL, NULL);
if(ret != 0)
av_freep(s);
av_strstart(filename, "file:", &filename);
- if (flags & URL_RDWR) {
+ if (flags & AVIO_RDWR) {
access = O_CREAT | O_TRUNC | O_RDWR;
- } else if (flags & URL_WRONLY) {
+ } else if (flags & AVIO_WRONLY) {
access = O_CREAT | O_TRUNC | O_WRONLY;
} else {
access = O_RDONLY;
fd = strtol(filename, &final, 10);
if((filename == final) || *final ) {/* No digits found, or something like 10ab */
- if (flags & URL_WRONLY) {
+ if (flags & AVIO_WRONLY) {
fd = 1;
} else {
fd = 0;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
s->hd = NULL;
- err = ffurl_open(&s->hd, buf, URL_RDWR);
+ err = ffurl_open(&s->hd, buf, AVIO_RDWR);
if (err < 0)
goto fail;
port = 80;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
- err = ffurl_open(&hd, buf, URL_RDWR);
+ err = ffurl_open(&hd, buf, AVIO_RDWR);
if (err < 0)
goto fail;
/* send http header */
- post = h->flags & URL_WRONLY;
+ post = h->flags & AVIO_WRONLY;
authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
post ? "POST" : "GET");
HTTPContext *s = h->priv_data;
/* signal end of chunked encoding if used */
- if ((h->flags & URL_WRONLY) && s->chunksize != -1) {
+ if ((h->flags & AVIO_WRONLY) && s->chunksize != -1) {
ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
ret = ret > 0 ? 0 : ret;
}
s->path, s->img_number)<0 && s->img_number > 1)
return AVERROR(EIO);
for(i=0; i<3; i++){
- if (avio_open(&f[i], filename, URL_RDONLY) < 0) {
+ if (avio_open(&f[i], filename, AVIO_RDONLY) < 0) {
if(i==1)
break;
av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename);
return AVERROR(EIO);
}
for(i=0; i<3; i++){
- if (avio_open(&pb[i], filename, URL_WRONLY) < 0) {
+ if (avio_open(&pb[i], filename, AVIO_WRONLY) < 0) {
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename);
return AVERROR(EIO);
}
goto fail;
}
- if (flags & URL_WRONLY)
+ if (flags & AVIO_WRONLY)
RTMP_EnableWrite(r);
if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
&& track->codec_priv.size >= 14
&& track->codec_priv.data != NULL) {
ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,
- URL_RDONLY, NULL, NULL, NULL, NULL);
+ AVIO_RDONLY, NULL, NULL, NULL, NULL);
ff_get_wav_header(&b, st->codec, track->codec_priv.size);
codec_id = st->codec->codec_id;
extradata_offset = FFMIN(track->codec_priv.size, 18);
return -1;
}
- if (flags != URL_WRONLY)
+ if (flags != AVIO_WRONLY)
return AVERROR(EINVAL);
av_md5_init(h->priv_data);
av_strstart(filename, "md5:", &filename);
if (*filename) {
- err = ffurl_open(&out, filename, URL_WRONLY);
+ err = ffurl_open(&out, filename, AVIO_WRONLY);
if (err)
return err;
err = ffurl_write(out, buf, i*2+1);
port = 80; // default mmsh protocol port
ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path);
- if (ffurl_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {
+ if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_RDONLY) < 0) {
return AVERROR(EIO);
}
// close the socket and then reopen it for sending the second play request.
ffurl_close(mms->mms_hd);
memset(headers, 0, sizeof(headers));
- if (ffurl_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) {
+ if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_RDONLY) < 0) {
return AVERROR(EIO);
}
stream_selection = av_mallocz(mms->stream_num * 19 + 1);
// establish tcp connection.
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL);
- err = ffurl_open(&mms->mms_hd, tcpname, URL_RDWR);
+ err = ffurl_open(&mms->mms_hd, tcpname, AVIO_RDWR);
if (err)
goto fail;
av_strlcat(filename, ref->path + l + 1, 1024);
- if (!avio_open(pb, filename, URL_RDONLY))
+ if (!avio_open(pb, filename, AVIO_RDONLY))
return 0;
}
}
/* open the output file, if needed */
if (!(fmt->flags & AVFMT_NOFILE)) {
- if (avio_open(&oc->pb, filename, URL_WRONLY) < 0) {
+ if (avio_open(&oc->pb, filename, AVIO_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
if (!rt)
return AVERROR(ENOMEM);
s->priv_data = rt;
- rt->is_input = !(flags & URL_WRONLY);
+ rt->is_input = !(flags & AVIO_WRONLY);
av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
path, sizeof(path), s->filename);
port = RTMP_DEFAULT_PORT;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
- if (ffurl_open(&rt->stream, buf, URL_RDWR) < 0) {
+ if (ffurl_open(&rt->stream, buf, AVIO_RDWR) < 0) {
av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
goto fail;
}
char path[1024];
const char *p;
- is_output = (flags & URL_WRONLY);
+ is_output = (flags & AVIO_WRONLY);
s = av_mallocz(sizeof(RTPContext));
if (!s)
"?localport=%d", j);
/* we will use two ports per rtp stream (rtp and rtcp) */
j += 2;
- if (ffurl_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0)
+ if (ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_RDWR) == 0)
goto rtp_opened;
}
}
#if 0
/* then try on any port */
- if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) {
+ if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", AVIO_RDONLY) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
port, "?ttl=%d", ttl);
- if (ffurl_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
+ if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_RDWR) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
av_get_random_seed(), av_get_random_seed());
/* GET requests */
- if (ffurl_alloc(&rt->rtsp_hd, httpname, URL_RDONLY) < 0) {
+ if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_RDONLY) < 0) {
err = AVERROR(EIO);
goto fail;
}
}
/* POST requests */
- if (ffurl_alloc(&rt->rtsp_hd_out, httpname, URL_WRONLY) < 0 ) {
+ if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_WRONLY) < 0 ) {
err = AVERROR(EIO);
goto fail;
}
} else {
/* open the tcp connection */
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
- if (ffurl_open(&rt->rtsp_hd, tcpname, URL_RDWR) < 0) {
+ if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_RDWR) < 0) {
err = AVERROR(EIO);
goto fail;
}
namebuf, rtsp_st->sdp_port,
"?localport=%d&ttl=%d", rtsp_st->sdp_port,
rtsp_st->sdp_ttl);
- if (ffurl_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
+ if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_RDWR) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
if (!ff_network_init())
return AVERROR(EIO);
- ret = ffurl_open(&in, s->filename, URL_RDONLY);
+ ret = ffurl_open(&in, s->filename, AVIO_RDONLY);
if (ret)
goto fail;
ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
port);
- ret = ffurl_open(&sap->ann_fd, url, URL_RDONLY);
+ ret = ffurl_open(&sap->ann_fd, url, AVIO_RDONLY);
if (ret)
goto fail;
"?ttl=%d", ttl);
if (!same_port)
base_port += 2;
- ret = ffurl_open(&fd, url, URL_WRONLY);
+ ret = ffurl_open(&fd, url, AVIO_WRONLY);
if (ret) {
ret = AVERROR(EIO);
goto fail;
ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
"?ttl=%d&connect=1", ttl);
- ret = ffurl_open(&sap->ann_fd, url, URL_WRONLY);
+ ret = ffurl_open(&sap->ann_fd, url, AVIO_WRONLY);
if (ret) {
ret = AVERROR(EIO);
goto fail;
TCPContext *s = h->priv_data;
int ret;
- if (!(h->flags & URL_FLAG_NONBLOCK)) {
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
ret = ff_network_wait_fd(s->fd, 0);
if (ret < 0)
return ret;
TCPContext *s = h->priv_data;
int ret;
- if (!(h->flags & URL_FLAG_NONBLOCK)) {
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
ret = ff_network_wait_fd(s->fd, 1);
if (ret < 0)
return ret;
h->is_streamed = 1;
h->max_packet_size = 1472;
- is_output = (flags & URL_WRONLY);
+ is_output = (flags & AVIO_WRONLY);
s = av_mallocz(sizeof(UDPContext));
if (!s)
/* XXX: fix av_url_split */
if (hostname[0] == '\0' || hostname[0] == '?') {
/* only accepts null hostname if input */
- if (flags & URL_WRONLY)
+ if (flags & AVIO_WRONLY)
goto fail;
} else {
if (ff_udp_set_remote_url(h, uri) < 0)
goto fail;
}
- if (s->is_multicast && !(h->flags & URL_WRONLY))
+ if (s->is_multicast && !(h->flags & AVIO_WRONLY))
s->local_port = port;
udp_fd = udp_socket_create(s, &my_addr, &len);
if (udp_fd < 0)
/* the bind is needed to give a port to the socket now */
/* if multicast, try the multicast address bind first */
- if (s->is_multicast && !(h->flags & URL_WRONLY)) {
+ if (s->is_multicast && !(h->flags & AVIO_WRONLY)) {
bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);
}
/* bind to the local address if not multicast or if the multicast
s->local_port = udp_port(&my_addr, len);
if (s->is_multicast) {
- if (h->flags & URL_WRONLY) {
+ if (h->flags & AVIO_WRONLY) {
/* output */
if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
goto fail;
UDPContext *s = h->priv_data;
int ret;
- if (!(h->flags & URL_FLAG_NONBLOCK)) {
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
ret = ff_network_wait_fd(s->udp_fd, 0);
if (ret < 0)
return ret;
UDPContext *s = h->priv_data;
int ret;
- if (!(h->flags & URL_FLAG_NONBLOCK)) {
+ if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
ret = ff_network_wait_fd(s->udp_fd, 1);
if (ret < 0)
return ret;
{
UDPContext *s = h->priv_data;
- if (s->is_multicast && !(h->flags & URL_WRONLY))
+ if (s->is_multicast && !(h->flags & AVIO_WRONLY))
udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
closesocket(s->udp_fd);
av_free(s);
hack needed to handle RTSP/TCP */
if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {
/* if no file needed do not try to open one */
- if ((err=avio_open(&pb, filename, URL_RDONLY)) < 0) {
+ if ((err=avio_open(&pb, filename, AVIO_RDONLY)) < 0) {
goto fail;
}
if (buf_size > 0) {