avformat: introduce AVFormatContext io_close2 which returns an int

Otherwise there is no way to detect an error returned by avio_close() because
ff_format_io_close cannot get the return value.

Checking the return value of the close function is important in order to check
if all data was successfully written and the underlying close() operation was
successful.

It can also be useful even for read mode because it can return any pending
AVIOContext error, so the user don't have to manually check AVIOContext->error.

In order to still support if the user overrides io_close, the generic code only
uses io_close2 if io_close is either NULL or the default io_close callback.

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Marton Balint
2021-11-30 00:38:30 +01:00
parent 8d66a07d65
commit 64834bb86a
11 changed files with 50 additions and 9 deletions

View File

@@ -1831,11 +1831,22 @@ int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **op
return 0;
}
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb)
{
if (*pb)
s->io_close(s, *pb);
avio_close(pb);
}
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
{
int ret = 0;
if (*pb) {
if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
ret = s->io_close2(s, *pb);
else
s->io_close(s, *pb);
}
*pb = NULL;
return ret;
}
int ff_is_http_proto(const char *filename) {