[MPlayer-cvslog] r30116 - in trunk/libmpcodecs: mp_image.h vd_ffmpeg.c vf.c

reimar subversion at mplayerhq.hu
Sat Dec 26 12:51:19 CET 2009


Author: reimar
Date: Sat Dec 26 12:51:19 2009
New Revision: 30116

Log:
Support mp_image with allocated palette.
Fixes playback and a memory leak for FFmpeg codecs which use reget_buffer
with paletted data, e.g. cdgraphics.

Modified:
   trunk/libmpcodecs/mp_image.h
   trunk/libmpcodecs/vd_ffmpeg.c
   trunk/libmpcodecs/vf.c

Modified: trunk/libmpcodecs/mp_image.h
==============================================================================
--- trunk/libmpcodecs/mp_image.h	Sat Dec 26 12:33:45 2009	(r30115)
+++ trunk/libmpcodecs/mp_image.h	Sat Dec 26 12:51:19 2009	(r30116)
@@ -38,7 +38,7 @@
 #define MP_IMGFLAG_YUV 0x200
 // set if it's swapped (BGR or YVU) plane/byteorder
 #define MP_IMGFLAG_SWAPPED 0x400
-// using palette for RGB data
+// set if you want memory for palette allocated and managed by vf_get_image etc.
 #define MP_IMGFLAG_RGB_PALETTE 0x800
 
 #define MP_IMGFLAGMASK_COLORS 0xF00
@@ -223,6 +223,8 @@ static inline void free_mp_image(mp_imag
     if(mpi->flags&MP_IMGFLAG_ALLOCATED){
 	/* becouse we allocate the whole image in once */
 	if(mpi->planes[0]) free(mpi->planes[0]);
+	if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
+	    free(mpi->planes[1]);
     }
     free(mpi);
 }

Modified: trunk/libmpcodecs/vd_ffmpeg.c
==============================================================================
--- trunk/libmpcodecs/vd_ffmpeg.c	Sat Dec 26 12:33:45 2009	(r30115)
+++ trunk/libmpcodecs/vd_ffmpeg.c	Sat Dec 26 12:51:19 2009	(r30116)
@@ -27,6 +27,10 @@ LIBVD_EXTERN(ffmpeg)
 
 #include "libavcodec/avcodec.h"
 
+#if AVPALETTE_SIZE > 1024
+#error palette too large, adapt libmpcodecs/vf.c:vf_get_image
+#endif
+
 #if CONFIG_XVMC
 #include "libavcodec/xvmc.h"
 #endif
@@ -593,6 +597,8 @@ static int get_buffer(AVCodecContext *av
         mp_msg(MSGT_DECVIDEO, MSGL_DBG2, type== MP_IMGTYPE_IPB ? "using IPB\n" : "using IP\n");
     }
 
+    if (ctx->best_csp == IMGFMT_RGB8 || ctx->best_csp == IMGFMT_BGR8)
+        flags |= MP_IMGFLAG_RGB_PALETTE;
     mpi= mpcodecs_get_image(sh, type, flags, width, height);
     if (!mpi) return -1;
 
@@ -630,10 +636,6 @@ static int get_buffer(AVCodecContext *av
     }
 #endif
 
-    // Palette support: libavcodec copies palette to *data[1]
-    if (mpi->bpp == 8)
-        mpi->planes[1] = av_malloc(AVPALETTE_SIZE);
-
     pic->data[0]= mpi->planes[0];
     pic->data[1]= mpi->planes[1];
     pic->data[2]= mpi->planes[2];

Modified: trunk/libmpcodecs/vf.c
==============================================================================
--- trunk/libmpcodecs/vf.c	Sat Dec 26 12:33:45 2009	(r30115)
+++ trunk/libmpcodecs/vf.c	Sat Dec 26 12:51:19 2009	(r30116)
@@ -322,8 +322,8 @@ mp_image_t* vf_get_image(vf_instance_t* 
     // keep buffer allocation status & color flags only:
 //    mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT);
     mpi->flags&=MP_IMGFLAG_ALLOCATED|MP_IMGFLAG_TYPE_DISPLAYED|MP_IMGFLAGMASK_COLORS;
-    // accept restrictions & draw_slice flags only:
-    mpi->flags|=mp_imgflag&(MP_IMGFLAGMASK_RESTRICTIONS|MP_IMGFLAG_DRAW_CALLBACK);
+    // accept restrictions, draw_slice and palette flags only:
+    mpi->flags|=mp_imgflag&(MP_IMGFLAGMASK_RESTRICTIONS|MP_IMGFLAG_DRAW_CALLBACK|MP_IMGFLAG_RGB_PALETTE);
     if(!vf->draw_slice) mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
     if(mpi->width!=w2 || mpi->height!=h){
 //	printf("vf.c: MPI parameters changed!  %dx%d -> %dx%d   \n", mpi->width,mpi->height,w2,h);
@@ -406,6 +406,8 @@ mp_image_t* vf_get_image(vf_instance_t* 
 	  } else {
 	      //if(!mpi->stride[0])
 	      mpi->stride[0]=mpi->width*mpi->bpp/8;
+	      if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
+	          mpi->planes[1] = memalign(64, 1024);
 	  }
 //	  printf("clearing img!\n");
 	  vf_mpi_clear(mpi,0,0,mpi->width,mpi->height);


More information about the MPlayer-cvslog mailing list