changeset 31003:00825525514e

Replace memalign(x) (x > 8) by av_malloc() to prevent crashes on systems lacking memalign(), e.g. Win32.
author zuxy
date Tue, 20 Apr 2010 04:33:00 +0000
parents 8eecc5573a65
children 85f2493aac68
files libmpcodecs/mp_image.c libmpcodecs/vd_dmo.c libmpcodecs/vf.c libmpcodecs/vf_noise.c libmpcodecs/vf_screenshot.c libmpcodecs/vf_unsharp.c
diffstat 6 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/mp_image.c	Sat Apr 17 02:19:34 2010 +0000
+++ b/libmpcodecs/mp_image.c	Tue Apr 20 04:33:00 2010 +0000
@@ -30,14 +30,15 @@
 #include "libmpcodecs/mp_image.h"
 
 #include "libvo/fastmemcpy.h"
+#include "libavutil/mem.h"
 
 void mp_image_alloc_planes(mp_image_t *mpi) {
   // IF09 - allocate space for 4. plane delta info - unused
   if (mpi->imgfmt == IMGFMT_IF09) {
-    mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8+
+    mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8+
                             mpi->chroma_width*mpi->chroma_height);
   } else
-    mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8);
+    mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8);
   if (mpi->flags&MP_IMGFLAG_PLANAR) {
     int bpp = IMGFMT_IS_YUVP16(mpi->imgfmt)? 2 : 1;
     // YV12/I420/YVU9/IF09. feel free to add other planar formats here...
@@ -65,7 +66,7 @@
   } else {
     mpi->stride[0]=mpi->width*mpi->bpp/8;
     if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
-      mpi->planes[1] = memalign(64, 1024);
+      mpi->planes[1] = av_malloc(1024);
   }
   mpi->flags|=MP_IMGFLAG_ALLOCATED;
 }
@@ -191,9 +192,9 @@
     if(!mpi) return;
     if(mpi->flags&MP_IMGFLAG_ALLOCATED){
 	/* becouse we allocate the whole image in once */
-	if(mpi->planes[0]) free(mpi->planes[0]);
+	if(mpi->planes[0]) av_free(mpi->planes[0]);
 	if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
-	    free(mpi->planes[1]);
+	    av_free(mpi->planes[1]);
     }
     free(mpi);
 }
--- a/libmpcodecs/vd_dmo.c	Sat Apr 17 02:19:34 2010 +0000
+++ b/libmpcodecs/vd_dmo.c	Tue Apr 20 04:33:00 2010 +0000
@@ -83,7 +83,7 @@
         if (sh->disp_w & 3)
         {
             ctx->stride = ((sh->disp_w * 3) + 3) & ~3;
-            ctx->buffer = memalign(64, ctx->stride * sh->disp_h);
+            ctx->buffer = av_malloc(ctx->stride * sh->disp_h);
         }
     default:
 	DMO_VideoDecoder_SetDestFmt(ctx->decoder,out_fmt&255,0);    // RGB/BGR
@@ -97,6 +97,7 @@
 static void uninit(sh_video_t *sh){
     struct context *ctx = sh->context;
     DMO_VideoDecoder_Destroy(ctx->decoder);
+    av_free(ctx->buffer);
     free(ctx);
     sh->context = NULL;
 }
--- a/libmpcodecs/vf.c	Sat Apr 17 02:19:34 2010 +0000
+++ b/libmpcodecs/vf.c	Tue Apr 20 04:33:00 2010 +0000
@@ -40,6 +40,7 @@
 #include "vf.h"
 
 #include "libvo/fastmemcpy.h"
+#include "libavutil/mem.h"
 
 extern const vf_info_t vf_info_vo;
 extern const vf_info_t vf_info_rectangle;
@@ -350,7 +351,7 @@
 	if(mpi->flags&MP_IMGFLAG_ALLOCATED){
 	    if(mpi->width<w2 || mpi->height<h){
 		// need to re-allocate buffer memory:
-		free(mpi->planes[0]);
+		av_free(mpi->planes[0]);
 		mpi->flags&=~MP_IMGFLAG_ALLOCATED;
 		mp_msg(MSGT_VFILTER,MSGL_V,"vf.c: have to REALLOCATE buffer memory :(\n");
 	    }
--- a/libmpcodecs/vf_noise.c	Sat Apr 17 02:19:34 2010 +0000
+++ b/libmpcodecs/vf_noise.c	Tue Apr 20 04:33:00 2010 +0000
@@ -36,6 +36,7 @@
 #include "mp_image.h"
 #include "vf.h"
 #include "libvo/fastmemcpy.h"
+#include "libavutil/mem.h"
 
 #define MAX_NOISE 4096
 #define MAX_SHIFT 1024
@@ -80,7 +81,7 @@
 	int uniform= fp->uniform;
 	int averaged= fp->averaged;
 	int pattern= fp->pattern;
-	int8_t *noise= memalign(16, MAX_NOISE*sizeof(int8_t));
+	int8_t *noise= av_malloc(MAX_NOISE*sizeof(int8_t));
 	int i, j;
 
 	srand(123457);
@@ -369,10 +370,10 @@
 static void uninit(struct vf_instance *vf){
 	if(!vf->priv) return;
 
-	if(vf->priv->chromaParam.noise) free(vf->priv->chromaParam.noise);
+	if(vf->priv->chromaParam.noise) av_free(vf->priv->chromaParam.noise);
 	vf->priv->chromaParam.noise= NULL;
 
-	if(vf->priv->lumaParam.noise) free(vf->priv->lumaParam.noise);
+	if(vf->priv->lumaParam.noise) av_free(vf->priv->lumaParam.noise);
 	vf->priv->lumaParam.noise= NULL;
 
 	free(vf->priv);
--- a/libmpcodecs/vf_screenshot.c	Sat Apr 17 02:19:34 2010 +0000
+++ b/libmpcodecs/vf_screenshot.c	Tue Apr 20 04:33:00 2010 +0000
@@ -131,7 +131,7 @@
 
     dst_stride[0] = priv->stride;
     if (!priv->buffer)
-        priv->buffer = memalign(16, dst_stride[0]*priv->dh);
+        priv->buffer = av_malloc(dst_stride[0]*priv->dh);
 
     dst[0] = priv->buffer;
     sws_scale(priv->ctx, mpi->planes, mpi->stride, 0, priv->dh, dst, dst_stride);
@@ -144,7 +144,7 @@
     if (vf->priv->shot) {
         vf->priv->store_slices = 1;
         if (!vf->priv->buffer)
-            vf->priv->buffer = memalign(16, vf->priv->stride*vf->priv->dh);
+            vf->priv->buffer = av_malloc(vf->priv->stride*vf->priv->dh);
     }
 
 }
@@ -277,7 +277,7 @@
     avcodec_close(vf->priv->avctx);
     av_freep(&vf->priv->avctx);
     if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
-    if (vf->priv->buffer) free(vf->priv->buffer);
+    if (vf->priv->buffer) av_free(vf->priv->buffer);
     free(vf->priv->outbuffer);
     free(vf->priv);
 }
--- a/libmpcodecs/vf_unsharp.c	Sat Apr 17 02:19:34 2010 +0000
+++ b/libmpcodecs/vf_unsharp.c	Tue Apr 20 04:33:00 2010 +0000
@@ -143,7 +143,7 @@
     stepsX = fp->msizeX/2;
     stepsY = fp->msizeY/2;
     for( z=0; z<2*stepsY; z++ )
-	fp->SC[z] = memalign( 16, sizeof(*(fp->SC[z])) * (width+2*stepsX) );
+	fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX));
 
     fp = &vf->priv->chromaParam;
     effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen";
@@ -152,7 +152,7 @@
     stepsX = fp->msizeX/2;
     stepsY = fp->msizeY/2;
     for( z=0; z<2*stepsY; z++ )
-	fp->SC[z] = memalign( 16, sizeof(*(fp->SC[z])) * (width+2*stepsX) );
+	fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX));
 
     return vf_next_config( vf, width, height, d_width, d_height, flags, outfmt );
 }
@@ -212,12 +212,12 @@
 
     fp = &vf->priv->lumaParam;
     for( z=0; z<sizeof(fp->SC)/sizeof(fp->SC[0]); z++ ) {
-	if( fp->SC[z] ) free( fp->SC[z] );
+	if( fp->SC[z] ) av_free( fp->SC[z] );
 	fp->SC[z] = NULL;
     }
     fp = &vf->priv->chromaParam;
     for( z=0; z<sizeof(fp->SC)/sizeof(fp->SC[0]); z++ ) {
-	if( fp->SC[z] ) free( fp->SC[z] );
+	if( fp->SC[z] ) av_free( fp->SC[z] );
 	fp->SC[z] = NULL;
     }