Merge "Consistent allocation of vpx_codec_alg_priv_t."

This commit is contained in:
Dmitry Kovalev 2014-09-03 19:41:28 -07:00 committed by Gerrit Code Review
commit 3820f568da
4 changed files with 31 additions and 33 deletions

View File

@ -14,6 +14,7 @@
#include "vpx/vpx_codec.h" #include "vpx/vpx_codec.h"
#include "vpx/internal/vpx_codec_internal.h" #include "vpx/internal/vpx_codec_internal.h"
#include "vpx_version.h" #include "vpx_version.h"
#include "vpx_mem/vpx_mem.h"
#include "vp8/encoder/onyx_int.h" #include "vp8/encoder/onyx_int.h"
#include "vpx/vp8cx.h" #include "vpx/vp8cx.h"
#include "vp8/encoder/firstpass.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_priv_enc_mr_cfg_t *mr_cfg)
{ {
vpx_codec_err_t res = VPX_CODEC_OK; vpx_codec_err_t res = VPX_CODEC_OK;
struct vpx_codec_alg_priv *priv;
vp8_rtcd(); vp8_rtcd();
if (!ctx->priv) 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) 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 = (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; ctx->priv->init_flags = ctx->init_flags;
if (ctx->config.enc) 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); free(ctx->cx_data);
vp8_remove_compressor(&ctx->cpi); vp8_remove_compressor(&ctx->cpi);
free(ctx); vpx_free(ctx);
return VPX_CODEC_OK; return VPX_CODEC_OK;
} }

View File

@ -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) static void vp8_init_ctx(vpx_codec_ctx_t *ctx)
{ {
vpx_codec_alg_priv_t *priv = vpx_codec_alg_priv_t *priv =
(vpx_codec_alg_priv_t *)vpx_memalign(8, sizeof(*priv)); (vpx_codec_alg_priv_t *)vpx_calloc(1, sizeof(*priv));
vpx_memset(priv, 0, sizeof(*priv));
ctx->priv = (vpx_codec_priv_t *)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; ctx->priv->init_flags = ctx->init_flags;
priv->si.sz = sizeof(priv->si); priv->si.sz = sizeof(priv->si);

View File

@ -665,34 +665,33 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
(void)data; (void)data;
if (ctx->priv == NULL) { if (ctx->priv == NULL) {
vpx_codec_alg_priv_t *const alg_priv = calloc(1, sizeof(*alg_priv)); vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv));
if (priv == NULL)
if (alg_priv == NULL)
return VPX_CODEC_MEM_ERROR; return VPX_CODEC_MEM_ERROR;
ctx->priv = (vpx_codec_priv_t *)alg_priv; ctx->priv = (vpx_codec_priv_t *)priv;
ctx->priv->sz = sizeof(vpx_codec_alg_priv_t); ctx->priv->sz = sizeof(*priv);
ctx->priv->init_flags = ctx->init_flags; ctx->priv->init_flags = ctx->init_flags;
ctx->priv->enc.total_encoders = 1; ctx->priv->enc.total_encoders = 1;
if (ctx->config.enc) { if (ctx->config.enc) {
// Update the reference to the config structure to an internal copy. // Update the reference to the config structure to an internal copy.
alg_priv->cfg = *ctx->config.enc; priv->cfg = *ctx->config.enc;
ctx->config.enc = &alg_priv->cfg; ctx->config.enc = &priv->cfg;
} }
alg_priv->extra_cfg = default_extra_cfg; priv->extra_cfg = default_extra_cfg;
vp9_initialize_enc(); 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) { if (res == VPX_CODEC_OK) {
set_encoder_config(&alg_priv->oxcf, &alg_priv->cfg, &alg_priv->extra_cfg); set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg);
alg_priv->cpi = vp9_create_compressor(&alg_priv->oxcf); priv->cpi = vp9_create_compressor(&priv->oxcf);
if (alg_priv->cpi == NULL) if (priv->cpi == NULL)
res = VPX_CODEC_MEM_ERROR; res = VPX_CODEC_MEM_ERROR;
else else
alg_priv->cpi->output_pkt_list = &alg_priv->pkt_list.head; priv->cpi->output_pkt_list = &priv->pkt_list.head;
} }
} }
@ -702,7 +701,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) { static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) {
free(ctx->cx_data); free(ctx->cx_data);
vp9_remove_compressor(ctx->cpi); vp9_remove_compressor(ctx->cpi);
free(ctx); vpx_free(ctx);
return VPX_CODEC_OK; return VPX_CODEC_OK;
} }

View File

@ -58,25 +58,23 @@ static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx,
(void)data; (void)data;
if (!ctx->priv) { if (!ctx->priv) {
vpx_codec_alg_priv_t *const alg_priv = vpx_memalign(32, sizeof(*alg_priv)); vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv));
if (alg_priv == NULL) if (priv == NULL)
return VPX_CODEC_MEM_ERROR; return VPX_CODEC_MEM_ERROR;
vp9_zero(*alg_priv); ctx->priv = (vpx_codec_priv_t *)priv;
ctx->priv->sz = sizeof(*priv);
ctx->priv = (vpx_codec_priv_t *)alg_priv;
ctx->priv->sz = sizeof(*alg_priv);
ctx->priv->init_flags = ctx->init_flags; ctx->priv->init_flags = ctx->init_flags;
alg_priv->si.sz = sizeof(alg_priv->si); priv->si.sz = sizeof(priv->si);
alg_priv->flushed = 0; priv->flushed = 0;
alg_priv->frame_parallel_decode = priv->frame_parallel_decode =
(ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING); (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) { if (ctx->config.dec) {
alg_priv->cfg = *ctx->config.dec; priv->cfg = *ctx->config.dec;
ctx->config.dec = &alg_priv->cfg; ctx->config.dec = &priv->cfg;
} }
} }