[MPlayer-dev-eng] [PATCH] configure & MEMALIGN_HACK

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Fri Jan 7 15:26:53 CET 2005


Hi,
On Fri, Jan 07, 2005 at 03:01:45PM +0100, Björn Sandell wrote:
> On Fri, 7 Jan 2005 12:12:05 +0100
> Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> wrote:
> > On Wed, Jan 05, 2005 at 08:01:42PM +0100, Reimar Döffinger wrote:
> > > On Wed, Jan 05, 2005 at 06:34:45PM +0100, Reimar Döffinger wrote:
> > > > On Tue, Jan 04, 2005 at 09:10:37PM +0100, Björn Sandell wrote:
> > > [...]
> > > > Please try the attached patch. It allocates and frees everything
> > > > that might be used by libavcodec with the av_ function.
> > > > Thanks to elupus on IRC for the hint.
> > > > I'm not an expert on this but I think this is the correct way. Do
> > > > you agree?
> 
> Yep, that's the correct way to solve the problem, but I still don't like
> to have MEMALIGN_HACK defined.

Then make the BSD people support memalign (or something similar).
Everything else just can't work (at least in the long run).

> > > No how did that happen? Here should be the complete patch...
> > 
> > Any comments? I intend to apply tomorrow.
> 
> Seems to work. I got some
> mencoder in free(): error: modified (chunk-) pointer
> right now, so more of the same is needed.

Try the attached patch.
Btw. All those if (var) before av_free(var) aren't needed anymore as
av_free does this check as well. I'll leave them there for now anyway...

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/ve_lavc.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/ve_lavc.c,v
retrieving revision 1.106
diff -u -r1.106 ve_lavc.c
--- libmpcodecs/ve_lavc.c	1 Dec 2004 20:32:05 -0000	1.106
+++ libmpcodecs/ve_lavc.c	7 Jan 2005 14:20:34 -0000
@@ -437,7 +437,7 @@
 	char *tmp;
 
 	lavc_venc_context->intra_matrix =
-	    malloc(sizeof(*lavc_venc_context->intra_matrix)*64);
+	    av_malloc(sizeof(*lavc_venc_context->intra_matrix)*64);
 
 	i = 0;
 	while ((tmp = strsep(&lavc_param_intra_matrix, ",")) && (i < 64))
@@ -449,7 +449,7 @@
 	
 	if (i != 64)
 	{
-	    free(lavc_venc_context->intra_matrix);
+	    av_free(lavc_venc_context->intra_matrix);
 	    lavc_venc_context->intra_matrix = NULL;
 	}
 	else
@@ -460,7 +460,7 @@
 	char *tmp;
 
 	lavc_venc_context->inter_matrix =
-	    malloc(sizeof(*lavc_venc_context->inter_matrix)*64);
+	    av_malloc(sizeof(*lavc_venc_context->inter_matrix)*64);
 
 	i = 0;
 	while ((tmp = strsep(&lavc_param_inter_matrix, ",")) && (i < 64))
@@ -472,7 +472,7 @@
 	
 	if (i != 64)
 	{
-	    free(lavc_venc_context->inter_matrix);
+	    av_free(lavc_venc_context->inter_matrix);
 	    lavc_venc_context->inter_matrix = NULL;
 	}
 	else
@@ -652,7 +652,7 @@
 	size= ftell(stats_file);
 	fseek(stats_file, 0, SEEK_SET);
 	
-	lavc_venc_context->stats_in= malloc(size + 1);
+	lavc_venc_context->stats_in= av_malloc(size + 1);
 	lavc_venc_context->stats_in[size]=0;
 
 	if(fread(lavc_venc_context->stats_in, size, 1, stats_file)<1){
@@ -728,7 +728,7 @@
     }
     
     /* free second pass buffer, its not needed anymore */
-    if(lavc_venc_context->stats_in) free(lavc_venc_context->stats_in);
+    if(lavc_venc_context->stats_in) av_free(lavc_venc_context->stats_in);
     lavc_venc_context->stats_in= NULL;
     if(lavc_venc_context->bits_per_sample)
         mux_v->bih->biBitCount= lavc_venc_context->bits_per_sample;
@@ -908,10 +908,10 @@
 
 #if LIBAVCODEC_BUILD >= 4675
     if (lavc_venc_context->intra_matrix)
-	free(lavc_venc_context->intra_matrix);
+	av_free(lavc_venc_context->intra_matrix);
     lavc_venc_context->intra_matrix = NULL;
     if (lavc_venc_context->inter_matrix)
-	free(lavc_venc_context->inter_matrix);
+	av_free(lavc_venc_context->inter_matrix);
     lavc_venc_context->inter_matrix = NULL;
 #endif
 
@@ -920,10 +920,10 @@
     if(stats_file) fclose(stats_file);
     
     /* free rc_override */
-    if(lavc_venc_context->rc_override) free(lavc_venc_context->rc_override);
+    if(lavc_venc_context->rc_override) av_free(lavc_venc_context->rc_override);
     lavc_venc_context->rc_override= NULL;
 
-    if(vf->priv->context) free(vf->priv->context);
+    if(vf->priv->context) av_free(vf->priv->context);
     vf->priv->context= NULL;
 }
 
Index: libmpcodecs/ad_ffmpeg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/ad_ffmpeg.c,v
retrieving revision 1.16
diff -u -r1.16 ad_ffmpeg.c
--- libmpcodecs/ad_ffmpeg.c	21 Sep 2004 20:34:46 -0000	1.16
+++ libmpcodecs/ad_ffmpeg.c	5 Jan 2005 17:32:35 -0000
@@ -72,7 +72,7 @@
 
     /* alloc extra data */
     if (sh_audio->wf && sh_audio->wf->cbSize > 0) {
-        lavc_context->extradata = malloc(sh_audio->wf->cbSize);
+        lavc_context->extradata = av_malloc(sh_audio->wf->cbSize);
         lavc_context->extradata_size = sh_audio->wf->cbSize;
         memcpy(lavc_context->extradata, (char *)sh_audio->wf + sizeof(WAVEFORMATEX), 
                lavc_context->extradata_size);
@@ -121,8 +121,8 @@
     if (avcodec_close(lavc_context) < 0)
 	mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec);
     if (lavc_context->extradata)
-        free(lavc_context->extradata);
-    free(lavc_context);
+        av_free(lavc_context->extradata);
+    av_free(lavc_context);
 }
 
 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
Index: libmpcodecs/vd_ffmpeg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vd_ffmpeg.c,v
retrieving revision 1.139
diff -u -r1.139 vd_ffmpeg.c
--- libmpcodecs/vd_ffmpeg.c	17 Dec 2004 07:34:23 -0000	1.139
+++ libmpcodecs/vd_ffmpeg.c	5 Jan 2005 17:33:08 -0000
@@ -281,7 +281,7 @@
     {
 	avctx->flags |= CODEC_FLAG_EXTERN_HUFF;
 	avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER);
-	avctx->extradata = malloc(avctx->extradata_size);
+	avctx->extradata = av_malloc(avctx->extradata_size);
 	memcpy(avctx->extradata, sh->bih+sizeof(BITMAPINFOHEADER),
 	    avctx->extradata_size);
 
@@ -303,7 +303,7 @@
        || sh->format == mmioFOURCC('R', 'V', '4', '0')
        ){
         avctx->extradata_size= 8;
-        avctx->extradata = malloc(avctx->extradata_size);
+        avctx->extradata = av_malloc(avctx->extradata_size);
         if(sh->bih->biSize!=sizeof(*sh->bih)+8){
             /* only 1 packet per frame & sub_id from fourcc */
 	    ((uint32_t*)avctx->extradata)[0] = 0;
@@ -338,7 +338,7 @@
          ))
     {
 	avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER);
-	avctx->extradata = malloc(avctx->extradata_size);
+	avctx->extradata = av_malloc(avctx->extradata_size);
 	memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size);
     }
     /* Pass palette to codec */
@@ -359,7 +359,7 @@
     if (sh->ImageDesc &&
 	 sh->format == mmioFOURCC('S','V','Q','3')){
 	avctx->extradata_size = (*(int*)sh->ImageDesc) - sizeof(int);
-	avctx->extradata = malloc(avctx->extradata_size);
+	avctx->extradata = av_malloc(avctx->extradata_size);
 	memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size);
     }
     
@@ -396,21 +396,21 @@
     	    mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec);
 
     if (avctx->extradata_size)
-	free(avctx->extradata);
+	av_free(avctx->extradata);
     avctx->extradata=NULL;
 #if LIBAVCODEC_BUILD >= 4689
     if (avctx->palctrl)
-	    free(avctx->palctrl);
+	    av_free(avctx->palctrl);
     avctx->palctrl=NULL;
 #endif
     if(avctx->slice_offset!=NULL) 
-        free(avctx->slice_offset);
+        av_free(avctx->slice_offset);
     avctx->slice_offset=NULL;
 
     if (avctx)
-	free(avctx);
+	av_free(avctx);
     if (ctx->pic)
-	free(ctx->pic);
+	av_free(ctx->pic);
     if (ctx)
 	free(ctx);
 }
@@ -601,7 +601,7 @@
 #if LIBAVCODEC_BUILD >= 4689
 	// Palette support: libavcodec copies palette to *data[1]
 	if (mpi->bpp == 8)
-		mpi->planes[1] = malloc(AVPALETTE_SIZE);
+		mpi->planes[1] = av_malloc(AVPALETTE_SIZE);
 #endif
 
     pic->data[0]= mpi->planes[0];
@@ -678,7 +678,7 @@
 
 	// Palette support: free palette buffer allocated in get_buffer
 	if ( mpi && (mpi->bpp == 8) && (mpi->planes[1] != NULL))
-		free(mpi->planes[1]);
+		av_free(mpi->planes[1]);
 
 #if LIBAVCODEC_BUILD >= 4644
     if(pic->type!=FF_BUFFER_TYPE_USER){
@@ -751,7 +751,7 @@
         dp_hdr_t *hdr= (dp_hdr_t*)data;
 
         if(avctx->slice_offset==NULL) 
-            avctx->slice_offset= malloc(sizeof(int)*1000);
+            avctx->slice_offset= av_malloc(sizeof(int)*1000);
         
 //        for(i=0; i<25; i++) printf("%02X ", ((uint8_t*)data)[i]);
         


More information about the MPlayer-dev-eng mailing list