diff options
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) |