avformat/avio: Avoid indirection in ffio_fdopen()

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-03-02 19:56:37 +01:00
parent 57e20dd6b6
commit c856e4c546
1 changed files with 21 additions and 19 deletions

View File

@ -408,8 +408,9 @@ fail:
return ret; return ret;
} }
int ffio_fdopen(AVIOContext **s, URLContext *h) int ffio_fdopen(AVIOContext **sp, URLContext *h)
{ {
AVIOContext *s;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
int buffer_size, max_packet_size; int buffer_size, max_packet_size;
@ -428,36 +429,37 @@ int ffio_fdopen(AVIOContext **s, URLContext *h)
if (!buffer) if (!buffer)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
*s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h, *sp = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
ffurl_read2, ffurl_write2, ffurl_seek2); ffurl_read2, ffurl_write2, ffurl_seek2);
if (!*s) { if (!*sp) {
av_freep(&buffer); av_freep(&buffer);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
(*s)->protocol_whitelist = av_strdup(h->protocol_whitelist); s = *sp;
if (!(*s)->protocol_whitelist && h->protocol_whitelist) { s->protocol_whitelist = av_strdup(h->protocol_whitelist);
avio_closep(s); if (!s->protocol_whitelist && h->protocol_whitelist) {
avio_closep(sp);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
(*s)->protocol_blacklist = av_strdup(h->protocol_blacklist); s->protocol_blacklist = av_strdup(h->protocol_blacklist);
if (!(*s)->protocol_blacklist && h->protocol_blacklist) { if (!s->protocol_blacklist && h->protocol_blacklist) {
avio_closep(s); avio_closep(sp);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
(*s)->direct = h->flags & AVIO_FLAG_DIRECT; s->direct = h->flags & AVIO_FLAG_DIRECT;
(*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL; s->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
(*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 = h->prot->url_read_pause; s->read_pause = h->prot->url_read_pause;
(*s)->read_seek = h->prot->url_read_seek; s->read_seek = 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;
} }
((FFIOContext*)(*s))->short_seek_get = ffurl_get_short_seek; ((FFIOContext*)s)->short_seek_get = ffurl_get_short_seek;
(*s)->av_class = &ff_avio_class; s->av_class = &ff_avio_class;
return 0; return 0;
} }