diff options
author | Mark Thompson <sw@jkqxz.net> | 2017-11-09 01:03:57 +0000 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2018-02-20 22:04:12 +0000 |
commit | 2651352988212531038326c44754ece1728c4a3b (patch) | |
tree | 0a881dcc977760e4181e7018028d790806b72c15 /libavcodec/cbs.c | |
parent | cc1c94dacd0642ac1a6cad45deb65071f127d91a (diff) | |
download | ffmpeg-2651352988212531038326c44754ece1728c4a3b.tar.gz |
cbs: Allocate the context inside the init function
... instead of making callers allocate it themselves. This is more
consistent with other APIs in libav.
Diffstat (limited to 'libavcodec/cbs.c')
-rw-r--r-- | libavcodec/cbs.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 3baa31a4dd..fd9baa2997 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -39,9 +39,10 @@ static const CodedBitstreamType *cbs_type_table[] = { #endif }; -int ff_cbs_init(CodedBitstreamContext *ctx, +int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx) { + CodedBitstreamContext *ctx; const CodedBitstreamType *type; int i; @@ -55,27 +56,40 @@ int ff_cbs_init(CodedBitstreamContext *ctx, if (!type) return AVERROR(EINVAL); + ctx = av_mallocz(sizeof(*ctx)); + if (!ctx) + return AVERROR(ENOMEM); + ctx->log_ctx = log_ctx; ctx->codec = type; ctx->priv_data = av_mallocz(ctx->codec->priv_data_size); - if (!ctx->priv_data) + if (!ctx->priv_data) { + av_freep(&ctx); return AVERROR(ENOMEM); + } ctx->decompose_unit_types = NULL; ctx->trace_enable = 0; ctx->trace_level = AV_LOG_TRACE; + *ctx_ptr = ctx; return 0; } -void ff_cbs_close(CodedBitstreamContext *ctx) +void ff_cbs_close(CodedBitstreamContext **ctx_ptr) { + CodedBitstreamContext *ctx = *ctx_ptr; + + if (!ctx) + return; + if (ctx->codec && ctx->codec->close) ctx->codec->close(ctx); av_freep(&ctx->priv_data); + av_freep(ctx_ptr); } static void cbs_unit_uninit(CodedBitstreamContext *ctx, |