diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-08-24 14:58:07 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-09-17 04:58:34 +0200 |
commit | fed02825081bd6441f865c9cfcf50e384b2392f5 (patch) | |
tree | b42f4b433b1652e4ad65bc0b5066fe3e80d5662f /libavformat/options.c | |
parent | dfbf41775cb58a9218a8b39b0dc6fd8de3f1ab35 (diff) |
avformat: Avoid allocation for AVFormatInternal
Do this by allocating AVFormatContext together with the data that is
currently in AVFormatInternal; or rather: Put AVFormatContext at the
beginning of a new structure called FFFormatContext (which encompasses
more than just the internal fields and is a proper context in its own
right, hence the name) and remove AVFormatInternal altogether.
The biggest simplifications occured in avformat_alloc_context(), where
one can now simply call avformat_free_context() in case of errors.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/options.c')
-rw-r--r-- | libavformat/options.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/libavformat/options.c b/libavformat/options.c index dccb6faa73..753aa9b8dc 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -151,46 +151,33 @@ static void io_close_default(AVFormatContext *s, AVIOContext *pb) avio_close(pb); } -static void avformat_get_context_defaults(AVFormatContext *s) +AVFormatContext *avformat_alloc_context(void) { - memset(s, 0, sizeof(AVFormatContext)); + FFFormatContext *const si = av_mallocz(sizeof(*si)); + AVFormatContext *s; - s->av_class = &av_format_context_class; + if (!si) + return NULL; + s = &si->pub; + s->av_class = &av_format_context_class; s->io_open = io_open_default; s->io_close = io_close_default; av_opt_set_defaults(s); -} -AVFormatContext *avformat_alloc_context(void) -{ - AVFormatContext *ic; - AVFormatInternal *internal; - ic = av_malloc(sizeof(AVFormatContext)); - if (!ic) return ic; - - internal = av_mallocz(sizeof(*internal)); - if (!internal) { - av_free(ic); + si->pkt = av_packet_alloc(); + si->parse_pkt = av_packet_alloc(); + if (!si->pkt || !si->parse_pkt) { + avformat_free_context(s); return NULL; } - internal->pkt = av_packet_alloc(); - internal->parse_pkt = av_packet_alloc(); - if (!internal->pkt || !internal->parse_pkt) { - av_packet_free(&internal->pkt); - av_packet_free(&internal->parse_pkt); - av_free(internal); - av_free(ic); - return NULL; - } - avformat_get_context_defaults(ic); - ic->internal = internal; - ic->internal->offset = AV_NOPTS_VALUE; - ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; - ic->internal->shortest_end = AV_NOPTS_VALUE; - return ic; + si->offset = AV_NOPTS_VALUE; + si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + si->shortest_end = AV_NOPTS_VALUE; + + return s; } enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx) |