Commit 6e8e8431 authored by Andreas Rheinhardt's avatar Andreas Rheinhardt Committed by Michael Niedermayer

avformat/aviobuf: Remove AVIOInternal and one level of indirection

In the Libav commit cae448cf, the opaque of every AVIOContext opened
by ffio_fdopen() (which is used internally by avio_open() and avio_open2())
changed: It was a simple pointer to an URLContext before, but now it was
a structure (namely AVIOInternal) containing a pointer to an URLContext
as its only member. The next commits (namely 8c0ceafb and ec4c4839) added
members to AVIOInternal to allow white-/blacklisting of protocols.

But these two commits were never merged into FFmpeg (they were only
merged as no-ops in 510046c2 and 063b26d3), because FFmpeg chose
a different way to implement this (in 93629735); and so our AVIOInternal
still has exactly one member.

This of course means that it is unnecessary to use AVIOInternal as
opaque as it is just adding a level of indirection (not only pointer
dereference, but also wrapper functions). Therefore this commit
removes AVIOInternal entirely and essentially reverts cae448cf.
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: 's avatarPaul B Mahol <onemda@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 0a275fec
...@@ -42,15 +42,10 @@ ...@@ -42,15 +42,10 @@
*/ */
#define SHORT_SEEK_THRESHOLD 4096 #define SHORT_SEEK_THRESHOLD 4096
typedef struct AVIOInternal {
URLContext *h;
} AVIOInternal;
static void *ff_avio_child_next(void *obj, void *prev) static void *ff_avio_child_next(void *obj, void *prev)
{ {
AVIOContext *s = obj; AVIOContext *s = obj;
AVIOInternal *internal = s->opaque; return prev ? NULL : s->opaque;
return prev ? NULL : internal->h;
} }
static const AVClass *ff_avio_child_class_next(const AVClass *prev) static const AVClass *ff_avio_child_class_next(const AVClass *prev)
...@@ -940,49 +935,8 @@ uint64_t ffio_read_varlen(AVIOContext *bc){ ...@@ -940,49 +935,8 @@ uint64_t ffio_read_varlen(AVIOContext *bc){
return val; return val;
} }
static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
{
AVIOInternal *internal = opaque;
return ffurl_read(internal->h, buf, buf_size);
}
static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
{
AVIOInternal *internal = opaque;
return ffurl_write(internal->h, buf, buf_size);
}
static int64_t io_seek(void *opaque, int64_t offset, int whence)
{
AVIOInternal *internal = opaque;
return ffurl_seek(internal->h, offset, whence);
}
static int io_short_seek(void *opaque)
{
AVIOInternal *internal = opaque;
return ffurl_get_short_seek(internal->h);
}
static int io_read_pause(void *opaque, int pause)
{
AVIOInternal *internal = opaque;
if (!internal->h->prot->url_read_pause)
return AVERROR(ENOSYS);
return internal->h->prot->url_read_pause(internal->h, pause);
}
static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
{
AVIOInternal *internal = opaque;
if (!internal->h->prot->url_read_seek)
return AVERROR(ENOSYS);
return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
}
int ffio_fdopen(AVIOContext **s, URLContext *h) int ffio_fdopen(AVIOContext **s, URLContext *h)
{ {
AVIOInternal *internal = NULL;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
int buffer_size, max_packet_size; int buffer_size, max_packet_size;
...@@ -996,14 +950,10 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) ...@@ -996,14 +950,10 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
if (!buffer) if (!buffer)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
internal = av_mallocz(sizeof(*internal)); *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
if (!internal) (int (*)(void *, uint8_t *, int)) ffurl_read,
goto fail; (int (*)(void *, uint8_t *, int)) ffurl_write,
(int64_t (*)(void *, int64_t, int))ffurl_seek);
internal->h = h;
*s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE,
internal, io_read_packet, io_write_packet, io_seek);
if (!*s) if (!*s)
goto fail; goto fail;
...@@ -1023,30 +973,28 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) ...@@ -1023,30 +973,28 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
(*s)->max_packet_size = max_packet_size; (*s)->max_packet_size = max_packet_size;
(*s)->min_packet_size = h->min_packet_size; (*s)->min_packet_size = h->min_packet_size;
if(h->prot) { if(h->prot) {
(*s)->read_pause = io_read_pause; (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause;
(*s)->read_seek = io_read_seek; (*s)->read_seek =
(int64_t (*)(void *, int, int64_t, int))h->prot->url_read_seek;
if (h->prot->url_read_seek) if (h->prot->url_read_seek)
(*s)->seekable |= AVIO_SEEKABLE_TIME; (*s)->seekable |= AVIO_SEEKABLE_TIME;
} }
(*s)->short_seek_get = io_short_seek; (*s)->short_seek_get = (int (*)(void *))ffurl_get_short_seek;
(*s)->av_class = &ff_avio_class; (*s)->av_class = &ff_avio_class;
return 0; return 0;
fail: fail:
av_freep(&internal);
av_freep(&buffer); av_freep(&buffer);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
URLContext* ffio_geturlcontext(AVIOContext *s) URLContext* ffio_geturlcontext(AVIOContext *s)
{ {
AVIOInternal *internal;
if (!s) if (!s)
return NULL; return NULL;
internal = s->opaque; if (s->opaque && s->read_packet == (int (*)(void *, uint8_t *, int))ffurl_read)
if (internal && s->read_packet == io_read_packet) return s->opaque;
return internal->h;
else else
return NULL; return NULL;
} }
...@@ -1218,17 +1166,15 @@ int avio_open2(AVIOContext **s, const char *filename, int flags, ...@@ -1218,17 +1166,15 @@ int avio_open2(AVIOContext **s, const char *filename, int flags,
int avio_close(AVIOContext *s) int avio_close(AVIOContext *s)
{ {
AVIOInternal *internal;
URLContext *h; URLContext *h;
if (!s) if (!s)
return 0; return 0;
avio_flush(s); avio_flush(s);
internal = s->opaque; h = s->opaque;
h = internal->h; s->opaque = NULL;
av_freep(&s->opaque);
av_freep(&s->buffer); av_freep(&s->buffer);
if (s->write_flag) if (s->write_flag)
av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count); av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
...@@ -1320,8 +1266,7 @@ int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size) ...@@ -1320,8 +1266,7 @@ int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
int avio_accept(AVIOContext *s, AVIOContext **c) int avio_accept(AVIOContext *s, AVIOContext **c)
{ {
int ret; int ret;
AVIOInternal *internal = s->opaque; URLContext *sc = s->opaque;
URLContext *sc = internal->h;
URLContext *cc = NULL; URLContext *cc = NULL;
ret = ffurl_accept(sc, &cc); ret = ffurl_accept(sc, &cc);
if (ret < 0) if (ret < 0)
...@@ -1331,8 +1276,7 @@ int avio_accept(AVIOContext *s, AVIOContext **c) ...@@ -1331,8 +1276,7 @@ int avio_accept(AVIOContext *s, AVIOContext **c)
int avio_handshake(AVIOContext *c) int avio_handshake(AVIOContext *c)
{ {
AVIOInternal *internal = c->opaque; URLContext *cc = c->opaque;
URLContext *cc = internal->h;
return ffurl_handshake(cc); return ffurl_handshake(cc);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment