Merge "Handle mem allocation failure in vp8e_init"

This commit is contained in:
Johann 2011-02-25 06:55:10 -08:00 committed by Code Review
commit 1fae7018a8

View File

@ -492,57 +492,67 @@ static vpx_codec_err_t vp8e_init(vpx_codec_ctx_t *ctx)
{ {
priv = calloc(1, sizeof(struct vpx_codec_alg_priv)); priv = calloc(1, sizeof(struct vpx_codec_alg_priv));
if (priv) if (!priv)
{ {
ctx->priv = &priv->base; return VPX_CODEC_MEM_ERROR;
ctx->priv->sz = sizeof(*ctx->priv); }
ctx->priv->iface = ctx->iface;
ctx->priv->alg_priv = priv;
ctx->priv->init_flags = ctx->init_flags;
if (ctx->config.enc) ctx->priv = &priv->base;
{ ctx->priv->sz = sizeof(*ctx->priv);
/* Update the reference to the config structure to an ctx->priv->iface = ctx->iface;
* internal copy. ctx->priv->alg_priv = priv;
*/ ctx->priv->init_flags = ctx->init_flags;
ctx->priv->alg_priv->cfg = *ctx->config.enc;
ctx->config.enc = &ctx->priv->alg_priv->cfg;
}
cfg = &ctx->priv->alg_priv->cfg; if (ctx->config.enc)
{
/* Select the extra vp6 configuration table based on the current /* Update the reference to the config structure to an
* usage value. If the current usage value isn't found, use the * internal copy.
* values for usage case 0.
*/ */
for (i = 0; ctx->priv->alg_priv->cfg = *ctx->config.enc;
extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; ctx->config.enc = &ctx->priv->alg_priv->cfg;
i++); }
priv->vp8_cfg = extracfg_map[i].cfg; cfg = &ctx->priv->alg_priv->cfg;
priv->vp8_cfg.pkt_list = &priv->pkt_list.head;
priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 2; /* Select the extra vp6 configuration table based on the current
* usage value. If the current usage value isn't found, use the
* values for usage case 0.
*/
for (i = 0;
extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage;
i++);
if (priv->cx_data_sz < 4096) priv->cx_data_sz = 4096; priv->vp8_cfg = extracfg_map[i].cfg;
priv->vp8_cfg.pkt_list = &priv->pkt_list.head;
priv->cx_data = malloc(priv->cx_data_sz); priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 2;
priv->deprecated_mode = NO_MODE_SET;
vp8_initialize(); if (priv->cx_data_sz < 4096) priv->cx_data_sz = 4096;
res = validate_config(priv, &priv->cfg, &priv->vp8_cfg); priv->cx_data = malloc(priv->cx_data_sz);
if (!res) if (!priv->cx_data)
{ {
set_vp8e_config(&ctx->priv->alg_priv->oxcf, ctx->priv->alg_priv->cfg, ctx->priv->alg_priv->vp8_cfg); return VPX_CODEC_MEM_ERROR;
optr = vp8_create_compressor(&ctx->priv->alg_priv->oxcf); }
if (!optr) priv->deprecated_mode = NO_MODE_SET;
res = VPX_CODEC_MEM_ERROR;
else vp8_initialize();
ctx->priv->alg_priv->cpi = optr;
} res = validate_config(priv, &priv->cfg, &priv->vp8_cfg);
if (!res)
{
set_vp8e_config(&ctx->priv->alg_priv->oxcf,
ctx->priv->alg_priv->cfg,
ctx->priv->alg_priv->vp8_cfg);
optr = vp8_create_compressor(&ctx->priv->alg_priv->oxcf);
if (!optr)
res = VPX_CODEC_MEM_ERROR;
else
ctx->priv->alg_priv->cpi = optr;
} }
} }