changeset 30074:5cb79ad246f2

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.
author reimar
date Sat, 26 Dec 2009 11:51:19 +0000
parents adc27f8f88c3
children f7628df3079b
files libmpcodecs/mp_image.h libmpcodecs/vd_ffmpeg.c libmpcodecs/vf.c
diffstat 3 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/mp_image.h	Sat Dec 26 11:33:45 2009 +0000
+++ b/libmpcodecs/mp_image.h	Sat Dec 26 11:51:19 2009 +0000
@@ -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 @@
     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);
 }
--- a/libmpcodecs/vd_ffmpeg.c	Sat Dec 26 11:33:45 2009 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Sat Dec 26 11:51:19 2009 +0000
@@ -27,6 +27,10 @@
 
 #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 @@
         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 @@
     }
 #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];
--- a/libmpcodecs/vf.c	Sat Dec 26 11:33:45 2009 +0000
+++ b/libmpcodecs/vf.c	Sat Dec 26 11:51:19 2009 +0000
@@ -322,8 +322,8 @@
     // 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 @@
 	  } 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);