[MPlayer-dev-eng] [PATCH] fix numerous const issues in libmpcodecs

Rich Felker dalias at aerifal.cx
Thu Oct 18 21:58:34 CEST 2007


MPlayer has LOTS of issues with constant data tables which are not
declared const. While this might or might not have impact on its
memory usage (probably small if any), it's very unclean and makes it
hard to use tools like 'size' to identify modules which are
incorrectly using real global variables instead of per-context data.

The attached patch is the initial work towards fixing the problem in
libmpcodecs. I'm submitting it now for comments before I go to lots
more work, only to have someone bitch about why it's bad.. :) So
please comment now. And if anyone would like to volunteer to finish
the job so I don't have to, I'd be quite happy with that too. :))

Rich
-------------- next part --------------
Index: libmpcodecs/vf_1bpp.c
===================================================================
--- libmpcodecs/vf_1bpp.c	(revision 24811)
+++ libmpcodecs/vf_1bpp.c	(working copy)
@@ -12,7 +12,7 @@
 
 //===========================================================================//
 
-static unsigned int bgr_list[]={
+static const unsigned int bgr_list[]={
     IMGFMT_Y800,
     IMGFMT_Y8,
     IMGFMT_BGR8,
@@ -43,7 +43,7 @@
 static unsigned int find_best(struct vf_instance_s* vf){
     unsigned int best=0;
     int ret;
-    unsigned int* p=bgr_list;
+    unsigned const int* p=bgr_list;
     while(*p){
 	ret=vf->next->query_format(vf->next,*p);
 	mp_msg(MSGT_VFILTER,MSGL_V,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
@@ -74,7 +74,7 @@
     return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
 }
 
-static int bittab[8]={128,64,32,16,8,4,2,1};
+static const int bittab[8]={128,64,32,16,8,4,2,1};
 
 static void convert(mp_image_t *mpi, mp_image_t *dmpi, int value0, int value1,int bpp){
     int y;
@@ -171,7 +171,7 @@
     return 1;
 }
 
-vf_info_t vf_info_1bpp = {
+const vf_info_t vf_info_1bpp = {
     "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
     "1bpp",
     "A'rpi",
Index: libmpcodecs/vf_blackframe.c
===================================================================
--- libmpcodecs/vf_blackframe.c	(revision 24811)
+++ libmpcodecs/vf_blackframe.c	(working copy)
@@ -76,7 +76,7 @@
     int w = mpi->w, h = mpi->h;
     int bthresh = vf->priv->bthresh;
     int bamount = vf->priv->bamount;
-    static const char *picttypes[4] = { "unknown", "I", "P", "B" };
+    static const char *const picttypes[4] = { "unknown", "I", "P", "B" };
 
     for (y=1; y<=h; y++) {
 	    for (x=0; x<w; x++)
@@ -138,7 +138,7 @@
     return 1;
 }
 
-vf_info_t vf_info_blackframe = {
+const vf_info_t vf_info_blackframe = {
     "detects black frames",
     "blackframe",
     "Brian J. Murrell, Julian Hall, Ivo van Poorten",
Index: libmpcodecs/vf_crop.c
===================================================================
--- libmpcodecs/vf_crop.c	(revision 24811)
+++ libmpcodecs/vf_crop.c	(working copy)
@@ -13,10 +13,10 @@
 #include "m_option.h"
 #include "m_struct.h"
 
-static struct vf_priv_s {
+static const struct vf_priv_s {
     int crop_w,crop_h;
     int crop_x,crop_y;
-} const vf_priv_dflt = {
+} vf_priv_dflt = {
   -1,-1,
   -1,-1
 };
@@ -166,7 +166,7 @@
 }
 
 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
-static m_option_t vf_opts_fields[] = {
+static const m_option_t vf_opts_fields[] = {
   {"w", ST_OFF(crop_w), CONF_TYPE_INT, M_OPT_MIN,0 ,0, NULL},
   {"h", ST_OFF(crop_h), CONF_TYPE_INT, M_OPT_MIN,0 ,0, NULL},
   {"x", ST_OFF(crop_x), CONF_TYPE_INT, M_OPT_MIN,-1 ,0, NULL},
@@ -174,14 +174,14 @@
   { NULL, NULL, 0, 0, 0, 0,  NULL }
 };
 
-static m_struct_t vf_opts = {
+static const m_struct_t vf_opts = {
   "crop",
   sizeof(struct vf_priv_s),
   &vf_priv_dflt,
   vf_opts_fields
 };
 
-vf_info_t vf_info_crop = {
+const vf_info_t vf_info_crop = {
     "cropping",
     "crop",
     "A'rpi",
Index: libmpcodecs/vf_ass.c
===================================================================
--- libmpcodecs/vf_ass.c	(revision 24811)
+++ libmpcodecs/vf_ass.c	(working copy)
@@ -51,7 +51,7 @@
 #define rgba2v(c)  ( (( 450*_r(c) - 376*_g(c) -  73*_b(c)) >> 10) + 128 )
 
 
-static struct vf_priv_s {
+static const struct vf_priv_s {
 	int outh, outw;
 
 	unsigned int outfmt;
@@ -64,7 +64,7 @@
 
 	unsigned char* planes[3];
 	unsigned char* dirty_rows;
-} const vf_priv_dflt;
+} vf_priv_dflt;
 
 extern int opt_screen_size_x;
 extern int opt_screen_size_y;
@@ -372,7 +372,7 @@
 		free(vf->priv->dirty_rows);
 }
 
-static unsigned int fmt_list[]={
+static const unsigned int fmt_list[]={
 	IMGFMT_YV12,
 	IMGFMT_I420,
 	IMGFMT_IYUV,
@@ -405,19 +405,19 @@
 }
 
 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
-static m_option_t vf_opts_fields[] = {
+static const m_option_t vf_opts_fields[] = {
 	{"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0 , 0, 1, NULL},
 	{ NULL, NULL, 0, 0, 0, 0,  NULL }
 };
 
-static m_struct_t vf_opts = {
+static const m_struct_t vf_opts = {
 	"ass",
 	sizeof(struct vf_priv_s),
 	&vf_priv_dflt,
 	vf_opts_fields
 };
 
-vf_info_t vf_info_ass = {
+const vf_info_t vf_info_ass = {
 	"Render ASS/SSA subtitles",
 	"ass",
 	"Evgeniy Stepanov",
Index: libmpcodecs/vf_boxblur.c
===================================================================
--- libmpcodecs/vf_boxblur.c	(revision 24811)
+++ libmpcodecs/vf_boxblur.c	(working copy)
@@ -206,7 +206,7 @@
 	return 1;
 }
 
-vf_info_t vf_info_boxblur = {
+const vf_info_t vf_info_boxblur = {
     "box blur",
     "boxblur",
     "Michael Niedermayer",
Index: libmpcodecs/vf_bmovl.c
===================================================================
--- libmpcodecs/vf_bmovl.c	(revision 24811)
+++ libmpcodecs/vf_bmovl.c	(working copy)
@@ -469,7 +469,7 @@
     return TRUE;
 }
 
-vf_info_t vf_info_bmovl = {
+const vf_info_t vf_info_bmovl = {
     "Read bitmaps from a FIFO and display them in window",
     "bmovl",
     "Per Wigren",
Index: libmpcodecs/vf.c
===================================================================
--- libmpcodecs/vf.c	(revision 24811)
+++ libmpcodecs/vf.c	(working copy)
@@ -24,84 +24,84 @@
 #include "libvo/fastmemcpy.h"
 
 extern vf_info_t vf_info_vo;
-extern vf_info_t vf_info_rectangle;
-extern vf_info_t vf_info_bmovl;
-extern vf_info_t vf_info_crop;
-extern vf_info_t vf_info_expand;
-extern vf_info_t vf_info_pp;
-extern vf_info_t vf_info_scale;
-extern vf_info_t vf_info_format;
-extern vf_info_t vf_info_noformat;
-extern vf_info_t vf_info_yuy2;
-extern vf_info_t vf_info_flip;
-extern vf_info_t vf_info_rgb2bgr;
-extern vf_info_t vf_info_rotate;
-extern vf_info_t vf_info_mirror;
-extern vf_info_t vf_info_palette;
-extern vf_info_t vf_info_lavc;
-extern vf_info_t vf_info_zrmjpeg;
-extern vf_info_t vf_info_dvbscale;
-extern vf_info_t vf_info_cropdetect;
-extern vf_info_t vf_info_test;
-extern vf_info_t vf_info_noise;
-extern vf_info_t vf_info_yvu9;
-extern vf_info_t vf_info_lavcdeint;
-extern vf_info_t vf_info_eq;
-extern vf_info_t vf_info_eq2;
-extern vf_info_t vf_info_halfpack;
-extern vf_info_t vf_info_dint;
-extern vf_info_t vf_info_1bpp;
-extern vf_info_t vf_info_2xsai;
-extern vf_info_t vf_info_unsharp;
-extern vf_info_t vf_info_swapuv;
-extern vf_info_t vf_info_il;
-extern vf_info_t vf_info_fil;
-extern vf_info_t vf_info_boxblur;
-extern vf_info_t vf_info_sab;
-extern vf_info_t vf_info_smartblur;
-extern vf_info_t vf_info_perspective;
-extern vf_info_t vf_info_down3dright;
-extern vf_info_t vf_info_field;
-extern vf_info_t vf_info_denoise3d;
-extern vf_info_t vf_info_hqdn3d;
-extern vf_info_t vf_info_detc;
-extern vf_info_t vf_info_telecine;
-extern vf_info_t vf_info_tinterlace;
-extern vf_info_t vf_info_tfields;
-extern vf_info_t vf_info_ivtc;
-extern vf_info_t vf_info_ilpack;
-extern vf_info_t vf_info_dsize;
-extern vf_info_t vf_info_decimate;
-extern vf_info_t vf_info_softpulldown;
-extern vf_info_t vf_info_pullup;
-extern vf_info_t vf_info_filmdint;
-extern vf_info_t vf_info_framestep;
-extern vf_info_t vf_info_tile;
-extern vf_info_t vf_info_delogo;
-extern vf_info_t vf_info_remove_logo;
-extern vf_info_t vf_info_hue;
-extern vf_info_t vf_info_spp;
-extern vf_info_t vf_info_uspp;
-extern vf_info_t vf_info_fspp;
-extern vf_info_t vf_info_pp7;
-extern vf_info_t vf_info_yuvcsp;
-extern vf_info_t vf_info_kerndeint;
-extern vf_info_t vf_info_rgbtest;
-extern vf_info_t vf_info_qp;
-extern vf_info_t vf_info_phase;
-extern vf_info_t vf_info_divtc;
-extern vf_info_t vf_info_harddup;
-extern vf_info_t vf_info_softskip;
-extern vf_info_t vf_info_screenshot;
-extern vf_info_t vf_info_ass;
-extern vf_info_t vf_info_mcdeint;
-extern vf_info_t vf_info_yadif;
-extern vf_info_t vf_info_blackframe;
-extern vf_info_t vf_info_geq;
+extern const vf_info_t vf_info_rectangle;
+extern const vf_info_t vf_info_bmovl;
+extern const vf_info_t vf_info_crop;
+extern const vf_info_t vf_info_expand;
+extern const vf_info_t vf_info_pp;
+extern const vf_info_t vf_info_scale;
+extern const vf_info_t vf_info_format;
+extern const vf_info_t vf_info_noformat;
+extern const vf_info_t vf_info_yuy2;
+extern const vf_info_t vf_info_flip;
+extern const vf_info_t vf_info_rgb2bgr;
+extern const vf_info_t vf_info_rotate;
+extern const vf_info_t vf_info_mirror;
+extern const vf_info_t vf_info_palette;
+extern const vf_info_t vf_info_lavc;
+extern const vf_info_t vf_info_zrmjpeg;
+extern const vf_info_t vf_info_dvbscale;
+extern const vf_info_t vf_info_cropdetect;
+extern const vf_info_t vf_info_test;
+extern const vf_info_t vf_info_noise;
+extern const vf_info_t vf_info_yvu9;
+extern const vf_info_t vf_info_lavcdeint;
+extern const vf_info_t vf_info_eq;
+extern const vf_info_t vf_info_eq2;
+extern const vf_info_t vf_info_halfpack;
+extern const vf_info_t vf_info_dint;
+extern const vf_info_t vf_info_1bpp;
+extern const vf_info_t vf_info_2xsai;
+extern const vf_info_t vf_info_unsharp;
+extern const vf_info_t vf_info_swapuv;
+extern const vf_info_t vf_info_il;
+extern const vf_info_t vf_info_fil;
+extern const vf_info_t vf_info_boxblur;
+extern const vf_info_t vf_info_sab;
+extern const vf_info_t vf_info_smartblur;
+extern const vf_info_t vf_info_perspective;
+extern const vf_info_t vf_info_down3dright;
+extern const vf_info_t vf_info_field;
+extern const vf_info_t vf_info_denoise3d;
+extern const vf_info_t vf_info_hqdn3d;
+extern const vf_info_t vf_info_detc;
+extern const vf_info_t vf_info_telecine;
+extern const vf_info_t vf_info_tinterlace;
+extern const vf_info_t vf_info_tfields;
+extern const vf_info_t vf_info_ivtc;
+extern const vf_info_t vf_info_ilpack;
+extern const vf_info_t vf_info_dsize;
+extern const vf_info_t vf_info_decimate;
+extern const vf_info_t vf_info_softpulldown;
+extern const vf_info_t vf_info_pullup;
+extern const vf_info_t vf_info_filmdint;
+extern const vf_info_t vf_info_framestep;
+extern const vf_info_t vf_info_tile;
+extern const vf_info_t vf_info_delogo;
+extern const vf_info_t vf_info_remove_logo;
+extern const vf_info_t vf_info_hue;
+extern const vf_info_t vf_info_spp;
+extern const vf_info_t vf_info_uspp;
+extern const vf_info_t vf_info_fspp;
+extern const vf_info_t vf_info_pp7;
+extern const vf_info_t vf_info_yuvcsp;
+extern const vf_info_t vf_info_kerndeint;
+extern const vf_info_t vf_info_rgbtest;
+extern const vf_info_t vf_info_qp;
+extern const vf_info_t vf_info_phase;
+extern const vf_info_t vf_info_divtc;
+extern const vf_info_t vf_info_harddup;
+extern const vf_info_t vf_info_softskip;
+extern const vf_info_t vf_info_screenshot;
+extern const vf_info_t vf_info_ass;
+extern const vf_info_t vf_info_mcdeint;
+extern const vf_info_t vf_info_yadif;
+extern const vf_info_t vf_info_blackframe;
+extern const vf_info_t vf_info_geq;
 extern vf_info_t vf_info_ow;
 
 // list of available filters:
-static vf_info_t* filter_list[]={
+static const vf_info_t* const filter_list[]={
     &vf_info_rectangle,
 #ifdef HAVE_POSIX_SELECT
     &vf_info_bmovl,
@@ -198,7 +198,7 @@
 
 // For the vf option
 m_obj_settings_t* vf_settings = NULL;
-m_obj_list_t vf_obj_list = {
+const m_obj_list_t vf_obj_list = {
   (void**)filter_list,
   M_ST_OFF(vf_info_t,name),
   M_ST_OFF(vf_info_t,info),
@@ -428,7 +428,7 @@
   return vf_next_query_format(vf,fmt);
 }
 
-vf_instance_t* vf_open_plugin(vf_info_t** filter_list, vf_instance_t* next, const char *name, char **args){
+vf_instance_t* vf_open_plugin(const vf_info_t* const* filter_list, vf_instance_t* next, const char *name, char **args){
     vf_instance_t* vf;
     int i;
     for(i=0;;i++){
@@ -514,7 +514,7 @@
 
 //============================================================================
 
-unsigned int vf_match_csp(vf_instance_t** vfp,unsigned int* list,unsigned int preferred){
+unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred){
     vf_instance_t* vf=*vfp;
     unsigned int* p;
     unsigned int best=0;
Index: libmpcodecs/vf.h
===================================================================
--- libmpcodecs/vf.h	(revision 24811)
+++ libmpcodecs/vf.h	(working copy)
@@ -9,7 +9,7 @@
     const char *comment;
     int (*open)(struct vf_instance_s* vf,char* args);
     // Ptr to a struct dscribing the options
-    void* opts;
+    const void* opts;
 } vf_info_t;
 
 typedef struct vf_image_context_s {
@@ -25,7 +25,7 @@
 } vf_format_context_t;
 
 typedef struct vf_instance_s {
-    vf_info_t* info;
+    const vf_info_t* info;
     // funcs:
     int (*config)(struct vf_instance_s* vf,
         int width, int height, int d_width, int d_height,
@@ -93,12 +93,12 @@
 void vf_mpi_clear(mp_image_t* mpi,int x0,int y0,int w,int h);
 mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h);
 
-vf_instance_t* vf_open_plugin(vf_info_t** filter_list, vf_instance_t* next, const char *name, char **args);
+vf_instance_t* vf_open_plugin(const vf_info_t* const* filter_list, vf_instance_t* next, const char *name, char **args);
 vf_instance_t* vf_open_filter(vf_instance_t* next, const char *name, char **args);
 vf_instance_t* vf_add_before_vo(vf_instance_t **vf, char *name, char **args);
 vf_instance_t* vf_open_encoder(vf_instance_t* next, const char *name, char *args);
 
-unsigned int vf_match_csp(vf_instance_t** vfp,unsigned int* list,unsigned int preferred);
+unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred);
 void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src);
 void vf_queue_frame(vf_instance_t *vf, int (*)(vf_instance_t *));
 int vf_output_queued_frame(vf_instance_t *vf);
Index: libmpcodecs/vf_2xsai.c
===================================================================
--- libmpcodecs/vf_2xsai.c	(revision 24811)
+++ libmpcodecs/vf_2xsai.c	(working copy)
@@ -16,6 +16,8 @@
 #define uint16 unsigned short
 #define uint8 unsigned char
 
+/* FIXME: these all belong in the context, not as globals! */
+
 static uint32 colorMask = 0xF7DEF7DE;
 static uint32 lowPixelMask = 0x08210821;
 static uint32 qcolorMask = 0xE79CE79C;
Index: m_struct.h
===================================================================
--- m_struct.h	(revision 24625)
+++ m_struct.h	(working copy)
@@ -22,7 +22,7 @@
   /** The p field of the \ref m_option struct must contain the offset
    *  of the member in the struct (use M_ST_OFF macro for this).
    */
-  struct m_option* fields;
+  const struct m_option* fields;
 } m_struct_t;
 
 


More information about the MPlayer-dev-eng mailing list