[FFmpeg-devel] [PATCH] avformat/avio: add opaque_close() to AVIOContext
Michael Niedermayer
michaelni at gmx.at
Sun Jun 8 22:48:42 CEST 2014
Also use it instead of directly calling ffurl_close() from avio_close(p)()
This allows avio_close(p)() to be saftely called on custom avio contexts
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavformat/avio.h | 7 +++++++
libavformat/aviobuf.c | 9 ++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 4004b6f..441e971 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -153,6 +153,13 @@ typedef struct AVIOContext {
* This field is internal to libavformat and access from outside is not allowed.
*/
int orig_buffer_size;
+
+ /**
+ * opaque pointer destructor.
+ * Used only internally currently but may be made accessible in the future
+ * This field is internal to libavformat and access from outside is not allowed.
+ */
+ int (*opaque_close)(void *opaque);
} AVIOContext;
/* unbuffered I/O */
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 738459e..26b4068 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -755,6 +755,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
av_free(buffer);
return AVERROR(ENOMEM);
}
+ (*s)->opaque_close = ffurl_close;
(*s)->direct = h->flags & AVIO_FLAG_DIRECT;
(*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
(*s)->max_packet_size = max_packet_size;
@@ -890,20 +891,22 @@ int avio_open2(AVIOContext **s, const char *filename, int flags,
int avio_close(AVIOContext *s)
{
- URLContext *h;
+ int ret = 0;
if (!s)
return 0;
avio_flush(s);
- h = s->opaque;
+ if (s->opaque_close)
+ ret = s->opaque_close(s->opaque);
+
av_freep(&s->buffer);
if (s->write_flag)
av_log(s, AV_LOG_DEBUG, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
else
av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
av_free(s);
- return ffurl_close(h);
+ return ret;
}
int avio_closep(AVIOContext **s)
--
1.7.9.5
More information about the ffmpeg-devel
mailing list