From b08fab8808a56eb37b5029f94ec6ffea0365cf70 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Tue, 2 Sep 2014 18:26:53 -0700 Subject: [PATCH] Consistent allocation of vpx_codec_alg_priv_t. Change-Id: I5a03496de035fbcf31e4527cd25fcae4627a57a0 --- vp8/vp8_cx_iface.c | 10 ++++++---- vp8/vp8_dx_iface.c | 5 ++--- vp9/vp9_cx_iface.c | 27 +++++++++++++-------------- vp9/vp9_dx_iface.c | 22 ++++++++++------------ 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/vp8/vp8_cx_iface.c b/vp8/vp8_cx_iface.c index 4237efc7e..fc8c4078f 100644 --- a/vp8/vp8_cx_iface.c +++ b/vp8/vp8_cx_iface.c @@ -14,6 +14,7 @@ #include "vpx/vpx_codec.h" #include "vpx/internal/vpx_codec_internal.h" #include "vpx_version.h" +#include "vpx_mem/vpx_mem.h" #include "vp8/encoder/onyx_int.h" #include "vpx/vp8cx.h" #include "vp8/encoder/firstpass.h" @@ -619,13 +620,14 @@ static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx, vpx_codec_priv_enc_mr_cfg_t *mr_cfg) { vpx_codec_err_t res = VPX_CODEC_OK; - struct vpx_codec_alg_priv *priv; + vp8_rtcd(); if (!ctx->priv) { - priv = calloc(1, sizeof(struct vpx_codec_alg_priv)); + struct vpx_codec_alg_priv *priv = + (struct vpx_codec_alg_priv *)vpx_calloc(1, sizeof(*priv)); if (!priv) { @@ -633,7 +635,7 @@ static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx, } ctx->priv = (vpx_codec_priv_t *)priv; - ctx->priv->sz = sizeof(struct vpx_codec_alg_priv); + ctx->priv->sz = sizeof(*priv); ctx->priv->init_flags = ctx->init_flags; if (ctx->config.enc) @@ -692,7 +694,7 @@ static vpx_codec_err_t vp8e_destroy(vpx_codec_alg_priv_t *ctx) free(ctx->cx_data); vp8_remove_compressor(&ctx->cpi); - free(ctx); + vpx_free(ctx); return VPX_CODEC_OK; } diff --git a/vp8/vp8_dx_iface.c b/vp8/vp8_dx_iface.c index 282032055..6d9ecc0c8 100644 --- a/vp8/vp8_dx_iface.c +++ b/vp8/vp8_dx_iface.c @@ -81,11 +81,10 @@ static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_ static void vp8_init_ctx(vpx_codec_ctx_t *ctx) { vpx_codec_alg_priv_t *priv = - (vpx_codec_alg_priv_t *)vpx_memalign(8, sizeof(*priv)); - vpx_memset(priv, 0, sizeof(*priv)); + (vpx_codec_alg_priv_t *)vpx_calloc(1, sizeof(*priv)); ctx->priv = (vpx_codec_priv_t *)priv; - ctx->priv->sz = sizeof(*ctx->priv); + ctx->priv->sz = sizeof(*priv); ctx->priv->init_flags = ctx->init_flags; priv->si.sz = sizeof(priv->si); diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index f49eb5803..79d19f887 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -654,34 +654,33 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, (void)data; if (ctx->priv == NULL) { - vpx_codec_alg_priv_t *const alg_priv = calloc(1, sizeof(*alg_priv)); - - if (alg_priv == NULL) + vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv)); + if (priv == NULL) return VPX_CODEC_MEM_ERROR; - ctx->priv = (vpx_codec_priv_t *)alg_priv; - ctx->priv->sz = sizeof(vpx_codec_alg_priv_t); + ctx->priv = (vpx_codec_priv_t *)priv; + ctx->priv->sz = sizeof(*priv); ctx->priv->init_flags = ctx->init_flags; ctx->priv->enc.total_encoders = 1; if (ctx->config.enc) { // Update the reference to the config structure to an internal copy. - alg_priv->cfg = *ctx->config.enc; - ctx->config.enc = &alg_priv->cfg; + priv->cfg = *ctx->config.enc; + ctx->config.enc = &priv->cfg; } - alg_priv->extra_cfg = default_extra_cfg; + priv->extra_cfg = default_extra_cfg; vp9_initialize_enc(); - res = validate_config(alg_priv, &alg_priv->cfg, &alg_priv->extra_cfg); + res = validate_config(priv, &priv->cfg, &priv->extra_cfg); if (res == VPX_CODEC_OK) { - set_encoder_config(&alg_priv->oxcf, &alg_priv->cfg, &alg_priv->extra_cfg); - alg_priv->cpi = vp9_create_compressor(&alg_priv->oxcf); - if (alg_priv->cpi == NULL) + set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg); + priv->cpi = vp9_create_compressor(&priv->oxcf); + if (priv->cpi == NULL) res = VPX_CODEC_MEM_ERROR; else - alg_priv->cpi->output_pkt_list = &alg_priv->pkt_list.head; + priv->cpi->output_pkt_list = &priv->pkt_list.head; } } @@ -691,7 +690,7 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx, static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) { free(ctx->cx_data); vp9_remove_compressor(ctx->cpi); - free(ctx); + vpx_free(ctx); return VPX_CODEC_OK; } diff --git a/vp9/vp9_dx_iface.c b/vp9/vp9_dx_iface.c index bcc64a5d6..b0fb28253 100644 --- a/vp9/vp9_dx_iface.c +++ b/vp9/vp9_dx_iface.c @@ -58,25 +58,23 @@ static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx, (void)data; if (!ctx->priv) { - vpx_codec_alg_priv_t *const alg_priv = vpx_memalign(32, sizeof(*alg_priv)); - if (alg_priv == NULL) + vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv)); + if (priv == NULL) return VPX_CODEC_MEM_ERROR; - vp9_zero(*alg_priv); - - ctx->priv = (vpx_codec_priv_t *)alg_priv; - ctx->priv->sz = sizeof(*alg_priv); + ctx->priv = (vpx_codec_priv_t *)priv; + ctx->priv->sz = sizeof(*priv); ctx->priv->init_flags = ctx->init_flags; - alg_priv->si.sz = sizeof(alg_priv->si); - alg_priv->flushed = 0; - alg_priv->frame_parallel_decode = + priv->si.sz = sizeof(priv->si); + priv->flushed = 0; + priv->frame_parallel_decode = (ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING); - alg_priv->frame_parallel_decode = 0; // Disable for now + priv->frame_parallel_decode = 0; // Disable for now if (ctx->config.dec) { - alg_priv->cfg = *ctx->config.dec; - ctx->config.dec = &alg_priv->cfg; + priv->cfg = *ctx->config.dec; + ctx->config.dec = &priv->cfg; } }