Skip to content

Commit

Permalink
avio: remove AVIO_* access symbols in favor of new AVIO_FLAG_* symbols
Browse files Browse the repository at this point in the history
Make AVIO_FLAG_ access constants work as flags, and in particular fix
the behavior of functions (such as avio_check()) which expect them to
be flags rather than modes.

This breaks API.
  • Loading branch information
Stefano Sabatini authored and elenril committed Apr 19, 2011
1 parent 490a022 commit 59d9694
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 66 deletions.
2 changes: 1 addition & 1 deletion ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@ static void opt_output_file(const char *filename)
}

/* open the file */
if ((err = avio_open(&oc->pb, filename, AVIO_WRONLY)) < 0) {
if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions ffserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3422,7 +3422,7 @@ static int rtp_new_av_stream(HTTPContext *c,
"rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
}

if (url_open(&h, ctx->filename, AVIO_WRONLY) < 0)
if (url_open(&h, ctx->filename, AVIO_FLAG_WRITE) < 0)
goto fail;
c->rtp_handles[stream_index] = h;
max_packet_size = url_get_max_packet_size(h);
Expand Down Expand Up @@ -3762,7 +3762,7 @@ static void build_feed_streams(void)
}

/* only write the header of the ffm file */
if (avio_open(&s->pb, feed->feed_filename, AVIO_WRONLY) < 0) {
if (avio_open(&s->pb, feed->feed_filename, AVIO_FLAG_WRITE) < 0) {
http_log("Could not open output feed file '%s'\n",
feed->feed_filename);
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions libavformat/applehttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,

if (!in) {
close_in = 1;
if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0)
if ((ret = avio_open(&in, url, AVIO_FLAG_READ)) < 0)
return ret;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)

ret = ffurl_open(&v->input,
v->segments[v->cur_seq_no - v->start_seq_no]->url,
AVIO_RDONLY);
AVIO_FLAG_READ);
if (ret < 0)
return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions libavformat/applehttpproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static int parse_playlist(URLContext *h, const char *url)
char line[1024];
const char *ptr;

if ((ret = avio_open(&in, url, AVIO_RDONLY)) < 0)
if ((ret = avio_open(&in, url, AVIO_FLAG_READ)) < 0)
return ret;

read_chomp_line(in, line, sizeof(line));
Expand Down Expand Up @@ -180,7 +180,7 @@ static int applehttp_open(URLContext *h, const char *uri, int flags)
int ret, i;
const char *nested_url;

if (flags & (AVIO_WRONLY | AVIO_RDWR))
if (flags & AVIO_FLAG_WRITE)
return AVERROR(ENOSYS);

s = av_mallocz(sizeof(AppleHTTPContext));
Expand Down Expand Up @@ -275,7 +275,7 @@ static int applehttp_read(URLContext *h, uint8_t *buf, int size)
}
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, AVIO_RDONLY);
ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ);
if (ret < 0) {
if (url_interrupt_cb())
return AVERROR_EXIT;
Expand Down
10 changes: 5 additions & 5 deletions libavformat/avio.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int ffurl_connect(URLContext* uc)
return err;
uc->is_connected = 1;
//We must be careful here as ffurl_seek() could be slow, for example for http
if( (uc->flags & (AVIO_WRONLY | AVIO_RDWR))
if( (uc->flags & AVIO_FLAG_WRITE)
|| !strcmp(uc->prot->name, "file"))
if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)
uc->is_streamed= 1;
Expand Down Expand Up @@ -289,21 +289,21 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int

int ffurl_read(URLContext *h, unsigned char *buf, int size)
{
if (h->flags & AVIO_WRONLY)
if (h->flags & AVIO_FLAG_WRITE)
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 & AVIO_WRONLY)
if (h->flags & AVIO_FLAG_WRITE)
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 & (AVIO_WRONLY | AVIO_RDWR)))
if (!(h->flags & AVIO_FLAG_WRITE))
return AVERROR(EIO);
/* avoid sending too big packets */
if (h->max_packet_size && size > h->max_packet_size)
Expand Down Expand Up @@ -342,7 +342,7 @@ int ffurl_close(URLContext *h)
int url_exist(const char *filename)
{
URLContext *h;
if (ffurl_open(&h, filename, AVIO_RDONLY) < 0)
if (ffurl_open(&h, filename, AVIO_FLAG_READ) < 0)
return 0;
ffurl_close(h);
return 1;
Expand Down
8 changes: 4 additions & 4 deletions libavformat/avio.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ attribute_deprecated int url_exist(const char *url);
#endif // FF_API_OLD_AVIO

/**
* Return AVIO_* access flags corresponding to the access permissions
* Return AVIO_FLAG_* access flags corresponding to the access permissions
* of the resource in url, or a negative value corresponding to an
* AVERROR code in case of failure. The returned access flags are
* masked by the value in flags.
Expand Down Expand Up @@ -527,9 +527,9 @@ int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen);
* constants, optionally ORed with other flags.
* @{
*/
#define AVIO_RDONLY 1 /**< read-only */
#define AVIO_WRONLY 2 /**< write-only */
#define AVIO_RDWR 4 /**< read-write */
#define AVIO_FLAG_READ 1 /**< read-only */
#define AVIO_FLAG_WRITE 2 /**< write-only */
#define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE) /**< read-write pseudo flag */
/**
* @}
*/
Expand Down
12 changes: 6 additions & 6 deletions libavformat/aviobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int ffio_init_context(AVIOContext *s,
s->buffer_size = buffer_size;
s->buf_ptr = buffer;
s->opaque = opaque;
url_resetbuf(s, write_flag ? AVIO_WRONLY : AVIO_RDONLY);
url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
s->write_packet = write_packet;
s->read_packet = read_packet;
s->seek = seek;
Expand Down Expand Up @@ -843,7 +843,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
}

if (ffio_init_context(*s, buffer, buffer_size,
(h->flags & AVIO_WRONLY || h->flags & AVIO_RDWR), h,
h->flags & AVIO_FLAG_WRITE, h,
ffurl_read, ffurl_write, ffurl_seek) < 0) {
av_free(buffer);
av_freep(s);
Expand Down Expand Up @@ -872,15 +872,15 @@ int ffio_set_buf_size(AVIOContext *s, int buf_size)
s->buffer = buffer;
s->buffer_size = buf_size;
s->buf_ptr = buffer;
url_resetbuf(s, s->write_flag ? AVIO_WRONLY : AVIO_RDONLY);
url_resetbuf(s, s->write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
return 0;
}

static int url_resetbuf(AVIOContext *s, int flags)
{
assert(flags == AVIO_WRONLY || flags == AVIO_RDONLY);
assert(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ);

if (flags & AVIO_WRONLY) {
if (flags & AVIO_FLAG_WRITE) {
s->buf_end = s->buffer + s->buffer_size;
s->write_flag = 1;
} else {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags)
if(!*s)
return AVERROR(ENOMEM);
ret = ffio_init_context(*s, buf, buf_size,
(flags & AVIO_WRONLY || flags & AVIO_RDWR),
flags & AVIO_FLAG_WRITE,
NULL, NULL, NULL, NULL);
if(ret != 0)
av_freep(s);
Expand Down
11 changes: 5 additions & 6 deletions libavformat/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ static int file_open(URLContext *h, const char *filename, int flags)

av_strstart(filename, "file:", &filename);

if (flags & AVIO_RDWR) {
if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) {
access = O_CREAT | O_TRUNC | O_RDWR;
} else if (flags & AVIO_WRONLY) {
} else if (flags & AVIO_FLAG_WRITE) {
access = O_CREAT | O_TRUNC | O_WRONLY;
} else {
access = O_RDONLY;
Expand Down Expand Up @@ -102,9 +102,8 @@ static int file_check(URLContext *h, int mask)
if (ret < 0)
return AVERROR(errno);

ret |= st.st_mode&S_IRUSR ? mask&AVIO_RDONLY : 0;
ret |= st.st_mode&S_IWUSR ? mask&AVIO_WRONLY : 0;
ret |= st.st_mode&S_IWUSR && st.st_mode&S_IRUSR ? mask&AVIO_RDWR : 0;
ret |= st.st_mode&S_IRUSR ? mask&AVIO_FLAG_READ : 0;
ret |= st.st_mode&S_IWUSR ? mask&AVIO_FLAG_WRITE : 0;

return ret;
}
Expand Down Expand Up @@ -132,7 +131,7 @@ static int pipe_open(URLContext *h, const char *filename, int flags)

fd = strtol(filename, &final, 10);
if((filename == final) || *final ) {/* No digits found, or something like 10ab */
if (flags & AVIO_WRONLY) {
if (flags & AVIO_FLAG_WRITE) {
fd = 1;
} else {
fd = 0;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/gopher.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags)
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);

s->hd = NULL;
err = ffurl_open(&s->hd, buf, AVIO_RDWR);
err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE);
if (err < 0)
goto fail;

Expand Down
6 changes: 3 additions & 3 deletions libavformat/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int http_open_cnx(URLContext *h)
port = 80;

ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
err = ffurl_open(&hd, buf, AVIO_RDWR);
err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE);
if (err < 0)
goto fail;

Expand Down Expand Up @@ -296,7 +296,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,


/* send http header */
post = h->flags & AVIO_WRONLY;
post = h->flags & AVIO_FLAG_WRITE;
authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
post ? "POST" : "GET");

Expand Down Expand Up @@ -451,7 +451,7 @@ static int http_close(URLContext *h)
HTTPContext *s = h->priv_data;

/* signal end of chunked encoding if used */
if ((h->flags & AVIO_WRONLY) && s->chunksize != -1) {
if ((h->flags & AVIO_FLAG_WRITE) && s->chunksize != -1) {
ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
ret = ret > 0 ? 0 : ret;
}
Expand Down
4 changes: 2 additions & 2 deletions libavformat/img2.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
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, AVIO_RDONLY) < 0) {
if (avio_open(&f[i], filename, AVIO_FLAG_READ) < 0) {
if(i==1)
break;
av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename);
Expand Down Expand Up @@ -362,7 +362,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EIO);
}
for(i=0; i<3; i++){
if (avio_open(&pb[i], filename, AVIO_WRONLY) < 0) {
if (avio_open(&pb[i], filename, AVIO_FLAG_WRITE) < 0) {
av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename);
return AVERROR(EIO);
}
Expand Down
2 changes: 1 addition & 1 deletion libavformat/librtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
goto fail;
}

if (flags & AVIO_WRONLY)
if (flags & AVIO_FLAG_WRITE)
RTMP_EnableWrite(r);

if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
Expand Down
2 changes: 1 addition & 1 deletion libavformat/matroskadec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap)
&& track->codec_priv.data != NULL) {
int ret;
ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,
AVIO_RDONLY, NULL, NULL, NULL, NULL);
AVIO_FLAG_READ, NULL, NULL, NULL, NULL);
ret = ff_get_wav_header(&b, st->codec, track->codec_priv.size);
if (ret < 0)
return ret;
Expand Down
4 changes: 2 additions & 2 deletions libavformat/md5proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int md5_open(URLContext *h, const char *filename, int flags)
return -1;
}

if (flags != AVIO_WRONLY)
if (!flags & AVIO_FLAG_WRITE)
return AVERROR(EINVAL);

av_md5_init(h->priv_data);
Expand Down Expand Up @@ -65,7 +65,7 @@ static int md5_close(URLContext *h)
av_strstart(filename, "md5:", &filename);

if (*filename) {
err = ffurl_open(&out, filename, AVIO_WRONLY);
err = ffurl_open(&out, filename, AVIO_FLAG_WRITE);
if (err)
return err;
err = ffurl_write(out, buf, i*2+1);
Expand Down
4 changes: 2 additions & 2 deletions libavformat/mmsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
port = 80; // default mmsh protocol port
ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path);

if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_RDONLY) < 0) {
if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ) < 0) {
return AVERROR(EIO);
}

Expand Down Expand Up @@ -261,7 +261,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
// 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, AVIO_RDONLY) < 0) {
if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ) < 0) {
return AVERROR(EIO);
}
stream_selection = av_mallocz(mms->stream_num * 19 + 1);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/mmst.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ static int mms_open(URLContext *h, const char *uri, int flags)

// establish tcp connection.
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL);
err = ffurl_open(&mms->mms_hd, tcpname, AVIO_RDWR);
err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE);
if (err)
goto fail;

Expand Down
2 changes: 1 addition & 1 deletion libavformat/mov.c
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,7 @@ static int mov_open_dref(AVIOContext **pb, char *src, MOVDref *ref)

av_strlcat(filename, ref->path + l + 1, 1024);

if (!avio_open(pb, filename, AVIO_RDONLY))
if (!avio_open(pb, filename, AVIO_FLAG_READ))
return 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libavformat/output-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ int main(int argc, char **argv)

/* open the output file, if needed */
if (!(fmt->flags & AVFMT_NOFILE)) {
if (avio_open(&oc->pb, filename, AVIO_WRONLY) < 0) {
if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
exit(1);
}
Expand Down
6 changes: 3 additions & 3 deletions libavformat/rtmpproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
if (!rt)
return AVERROR(ENOMEM);
s->priv_data = rt;
rt->is_input = !(flags & AVIO_WRONLY);
rt->is_input = !(flags & AVIO_FLAG_WRITE);

av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
path, sizeof(path), s->filename);
Expand All @@ -814,8 +814,8 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
port = RTMP_DEFAULT_PORT;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);

if (ffurl_open(&rt->stream, buf, AVIO_RDWR) < 0) {
av_log(s, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE) < 0) {
av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
goto fail;
}

Expand Down
2 changes: 1 addition & 1 deletion libavformat/rtpproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
char path[1024];
const char *p;

is_output = (flags & AVIO_WRONLY);
is_output = (flags & AVIO_FLAG_WRITE);

s = av_mallocz(sizeof(RTPContext));
if (!s)
Expand Down
Loading

0 comments on commit 59d9694

Please sign in to comment.