shithub: libvpx

Download patch

ref: b08fab8808a56eb37b5029f94ec6ffea0365cf70
parent: 0ecc75c81986a277d2e8e387117edfc21cb2fed0
author: Dmitry Kovalev <[email protected]>
date: Tue Sep 2 14:26:53 EDT 2014

Consistent allocation of vpx_codec_alg_priv_t.

Change-Id: I5a03496de035fbcf31e4527cd25fcae4627a57a0

--- 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 @@
                                  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 @@
         }
 
         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 @@
 
     free(ctx->cx_data);
     vp8_remove_compressor(&ctx->cpi);
-    free(ctx);
+    vpx_free(ctx);
     return VPX_CODEC_OK;
 }
 
--- a/vp8/vp8_dx_iface.c
+++ b/vp8/vp8_dx_iface.c
@@ -81,11 +81,10 @@
 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);
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -654,34 +654,33 @@
   (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_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;
 }
 
--- a/vp9/vp9_dx_iface.c
+++ b/vp9/vp9_dx_iface.c
@@ -58,25 +58,23 @@
   (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;
     }
   }