Commit d53bf1b3 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Repack module_config_t

Also do not save garbage, especially pointers, in the plugin cache.
parent acc457d1
...@@ -55,32 +55,39 @@ typedef int (*vlc_string_list_cb)(vlc_object_t *, const char *, ...@@ -55,32 +55,39 @@ typedef int (*vlc_string_list_cb)(vlc_object_t *, const char *,
struct module_config_t struct module_config_t
{ {
char *psz_type; /* Configuration subtype */ union
char *psz_name; /* Option name */ {
char *psz_text; /* Short comment on the configuration option */ struct
char *psz_longtext; /* Long comment on the configuration option */ {
uint8_t i_type; /* Configuration type */
char i_short; /* Optional short option name */
unsigned b_advanced:1; /* Advanced option */
unsigned b_internal:1; /* Hidden from prefs and help */
unsigned b_unsaveable:1; /* Not stored in configuration */
unsigned b_safe:1; /* Safe in web plugins and playlists */
unsigned b_removed:1; /* Deprecated */
};
uint32_t flags;
};
char *psz_type; /* Configuration subtype */
char *psz_name; /* Option name */
char *psz_text; /* Short comment on the configuration option */
char *psz_longtext; /* Long comment on the configuration option */
module_value_t value; /* Option value */ module_value_t value; /* Option value */
module_value_t orig; module_value_t orig;
module_value_t min; module_value_t min;
module_value_t max; module_value_t max;
/* Values list */ /* Values list */
char ** ppsz_list; /* List of possible values for the option */ uint16_t list_count; /* Options list size */
int *pi_list; /* Idem for integers */ union
char **ppsz_list_text; /* Friendly names for list values */ {
int i_list; /* Options list size */ char **psz; /* List of possible values for the option */
vlc_string_list_cb pf_update_list; int *i;
uint8_t i_type; /* Configuration type */ vlc_string_list_cb psz_cb;
char i_short; /* Optional short option name */ } list;
char **list_text; /* Friendly names for list values */
/* Misc */
unsigned b_advanced:1; /* Flag to indicate an advanced option */
unsigned b_internal:1; /* Flag to indicate option is not to be shown */
unsigned b_unsaveable:1; /* Config should not be saved */
unsigned b_safe:1; /* Safe to use in web plugins and playlists */
/* Deprecated */
bool b_removed;
}; };
/***************************************************************************** /*****************************************************************************
......
...@@ -93,10 +93,10 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, ...@@ -93,10 +93,10 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
p_control = new ModuleListConfigControl( p_this, p_item, parent, true ); p_control = new ModuleListConfigControl( p_this, p_item, parent, true );
break; break;
case CONFIG_ITEM_STRING: case CONFIG_ITEM_STRING:
if( !p_item->i_list ) if( p_item->list_count )
p_control = new StringConfigControl( p_this, p_item, parent, false );
else
p_control = new StringListConfigControl( p_this, p_item, parent ); p_control = new StringListConfigControl( p_this, p_item, parent );
else
p_control = new StringConfigControl( p_this, p_item, parent, false );
break; break;
case CONFIG_ITEM_PASSWORD: case CONFIG_ITEM_PASSWORD:
p_control = new StringConfigControl( p_this, p_item, parent, true ); p_control = new StringConfigControl( p_this, p_item, parent, true );
...@@ -105,7 +105,7 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this, ...@@ -105,7 +105,7 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
p_control = new ColorConfigControl( p_this, p_item, parent ); p_control = new ColorConfigControl( p_this, p_item, parent );
break; break;
case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_INTEGER:
if( p_item->i_list ) if( p_item->list_count )
p_control = new IntegerListConfigControl( p_this, p_item, parent, false ); p_control = new IntegerListConfigControl( p_this, p_item, parent, false );
else if( p_item->min.i || p_item->max.i ) else if( p_item->min.i || p_item->max.i )
p_control = new IntegerRangeConfigControl( p_this, p_item, parent ); p_control = new IntegerRangeConfigControl( p_this, p_item, parent );
......
...@@ -81,6 +81,7 @@ audio_output_t *aout_New( vlc_object_t * p_parent ) ...@@ -81,6 +81,7 @@ audio_output_t *aout_New( vlc_object_t * p_parent )
* Persistent audio output variables * Persistent audio output variables
*/ */
vlc_value_t val, text; vlc_value_t val, text;
module_config_t *cfg;
char *str; char *str;
var_Create (aout, "volume", VLC_VAR_FLOAT); var_Create (aout, "volume", VLC_VAR_FLOAT);
...@@ -142,18 +143,14 @@ audio_output_t *aout_New( vlc_object_t * p_parent ) ...@@ -142,18 +143,14 @@ audio_output_t *aout_New( vlc_object_t * p_parent )
val.psz_string = (char*)""; val.psz_string = (char*)"";
text.psz_string = _("Disable"); text.psz_string = _("Disable");
var_Change (aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text); var_Change (aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text);
{ cfg = config_FindConfig (VLC_OBJECT(aout), "equalizer-preset");
module_config_t *cfg = config_FindConfig (VLC_OBJECT(aout), if (likely(cfg != NULL))
"equalizer-preset"); for (unsigned i = 0; i < cfg->list_count; i++)
if (cfg != NULL) {
for (int i = 0; i < cfg->i_list; i++) val.psz_string = cfg->list.psz[i];
{ text.psz_string = vlc_gettext(cfg->list_text[i]);
val.psz_string = (char *)cfg->ppsz_list[i]; var_Change (aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text);
text.psz_string = (char *)cfg->ppsz_list_text[i]; }
var_Change (aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text);
}
}
var_Create (aout, "audio-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT); var_Create (aout, "audio-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
text.psz_string = _("Audio filters"); text.psz_string = _("Audio filters");
...@@ -170,19 +167,15 @@ audio_output_t *aout_New( vlc_object_t * p_parent ) ...@@ -170,19 +167,15 @@ audio_output_t *aout_New( vlc_object_t * p_parent )
VLC_VAR_STRING | VLC_VAR_DOINHERIT ); VLC_VAR_STRING | VLC_VAR_DOINHERIT );
text.psz_string = _("Replay gain"); text.psz_string = _("Replay gain");
var_Change (aout, "audio-replay-gain-mode", VLC_VAR_SETTEXT, &text, NULL); var_Change (aout, "audio-replay-gain-mode", VLC_VAR_SETTEXT, &text, NULL);
{ cfg = config_FindConfig (VLC_OBJECT(aout), "audio-replay-gain-mode");
module_config_t *cfg = config_FindConfig (VLC_OBJECT(aout), if (likely(cfg != NULL))
"audio-replay-gain-mode"); for (unsigned i = 0; i < cfg->list_count; i++)
if( cfg != NULL ) {
for (int i = 0; i < cfg->i_list; i++) val.psz_string = cfg->list.psz[i];
{ text.psz_string = vlc_gettext(cfg->list_text[i]);
val.psz_string = (char *)cfg->ppsz_list[i]; var_Change (aout, "audio-replay-gain-mode", VLC_VAR_ADDCHOICE,
text.psz_string = (char *)cfg->ppsz_list_text[i];
var_Change (aout, "audio-replay-gain-mode", VLC_VAR_ADDCHOICE,
&val, &text); &val, &text);
} }
}
return aout; return aout;
} }
......
...@@ -352,7 +352,7 @@ ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name, ...@@ -352,7 +352,7 @@ ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name,
return -1; return -1;
} }
size_t count = cfg->i_list; size_t count = cfg->list_count;
if (count == 0) if (count == 0)
return 0; return 0;
...@@ -363,8 +363,9 @@ ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name, ...@@ -363,8 +363,9 @@ ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name,
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
vals[i] = cfg->pi_list[i]; vals[i] = cfg->list.i[i];
txts[i] = strdup (cfg->ppsz_list_text[i]); /* FIXME: use module_gettext() instead */
txts[i] = strdup (vlc_gettext (cfg->list_text[i]));
if (unlikely(txts[i] == NULL)) if (unlikely(txts[i] == NULL))
abort (); abort ();
} }
...@@ -397,12 +398,13 @@ ssize_t config_GetPszChoices (vlc_object_t *obj, const char *name, ...@@ -397,12 +398,13 @@ ssize_t config_GetPszChoices (vlc_object_t *obj, const char *name,
return -1; return -1;
} }
if (cfg->pf_update_list != NULL) size_t count = cfg->list_count;
return cfg->pf_update_list (obj, name, values, texts);
size_t count = cfg->i_list;
if (count == 0) if (count == 0)
return 0; {
if (cfg->list.psz_cb == NULL)
return 0;
return cfg->list.psz_cb(obj, name, values, texts);
}
char **vals = malloc (sizeof (*vals) * count); char **vals = malloc (sizeof (*vals) * count);
char **txts = malloc (sizeof (*txts) * count); char **txts = malloc (sizeof (*txts) * count);
...@@ -411,8 +413,9 @@ ssize_t config_GetPszChoices (vlc_object_t *obj, const char *name, ...@@ -411,8 +413,9 @@ ssize_t config_GetPszChoices (vlc_object_t *obj, const char *name,
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
vals[i] = strdup (cfg->ppsz_list[i]); vals[i] = strdup (cfg->list.psz[i]);
txts[i] = strdup (cfg->ppsz_list_text[i]); /* FIXME: use module_gettext() instead */
txts[i] = strdup (vlc_gettext(cfg->list_text[i]));
if (unlikely(vals[i] == NULL || txts[i] == NULL)) if (unlikely(vals[i] == NULL || txts[i] == NULL))
abort (); abort ();
} }
...@@ -535,17 +538,19 @@ void config_Free (module_config_t *config, size_t confsize) ...@@ -535,17 +538,19 @@ void config_Free (module_config_t *config, size_t confsize)
{ {
free (p_item->value.psz); free (p_item->value.psz);
free (p_item->orig.psz); free (p_item->orig.psz);
if (p_item->list_count)
{
for (size_t i = 0; i < p_item->list_count; i++)
free (p_item->list.psz[i]);
free (p_item->list.psz);
}
} }
else
free (p_item->list.i);
if( p_item->ppsz_list ) for (size_t i = 0; i < p_item->list_count; i++)
for (int i = 0; i < p_item->i_list; i++) free (p_item->list_text[i]);
free( p_item->ppsz_list[i] ); free (p_item->list_text);
if( p_item->ppsz_list_text )
for (int i = 0; i < p_item->i_list; i++)
free( p_item->ppsz_list_text[i] );
free( p_item->ppsz_list );
free( p_item->ppsz_list_text );
free( p_item->pi_list );
} }
free (config); free (config);
......
...@@ -448,15 +448,15 @@ static void Usage (vlc_object_t *p_this, char const *psz_search) ...@@ -448,15 +448,15 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
psz_type = _("string"); psz_type = _("string");
psz_ket = ">"; psz_ket = ">";
if( p_item->ppsz_list ) if( p_item->list_count )
{ {
psz_bra = OPTION_VALUE_SEP "{"; psz_bra = OPTION_VALUE_SEP "{";
psz_type = psz_buffer; psz_type = psz_buffer;
psz_buffer[0] = '\0'; psz_buffer[0] = '\0';
for( i = 0; i < p_item->i_list; i++ ) for( i = 0; i < p_item->list_count; i++ )
{ {
if( i ) strcat( psz_buffer, "," ); if( i ) strcat( psz_buffer, "," );
strcat( psz_buffer, p_item->ppsz_list[i] ); strcat( psz_buffer, p_item->list.psz[i] );
} }
psz_ket = "}"; psz_ket = "}";
} }
...@@ -476,17 +476,17 @@ static void Usage (vlc_object_t *p_this, char const *psz_search) ...@@ -476,17 +476,17 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
psz_type = psz_buffer; psz_type = psz_buffer;
} }
if( p_item->i_list ) if( p_item->list_count )
{ {
psz_bra = OPTION_VALUE_SEP "{"; psz_bra = OPTION_VALUE_SEP "{";
psz_type = psz_buffer; psz_type = psz_buffer;
psz_buffer[0] = '\0'; psz_buffer[0] = '\0';
for( i = 0; i < p_item->i_list; i++ ) for( i = 0; i < p_item->list_count; i++ )
{ {
if( i ) strcat( psz_buffer, ", " ); if( i ) strcat( psz_buffer, ", " );
sprintf( psz_buffer + strlen(psz_buffer), "%i (%s)", sprintf( psz_buffer + strlen(psz_buffer), "%i (%s)",
p_item->pi_list[i], p_item->list.i[i],
module_gettext( p_parser, p_item->ppsz_list_text[i] ) ); module_gettext( p_parser, p_item->list_text[i] ) );
} }
psz_ket = "}"; psz_ket = "}";
} }
......
...@@ -489,7 +489,8 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath, ...@@ -489,7 +489,8 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
/* For now we force loading if the module's config contains callbacks. /* For now we force loading if the module's config contains callbacks.
* Could be optimized by adding an API call.*/ * Could be optimized by adding an API call.*/
for (size_t n = module->confsize, i = 0; i < n; i++) for (size_t n = module->confsize, i = 0; i < n; i++)
if (module->p_config[i].pf_update_list != NULL) if (module->p_config[i].list_count == 0
&& module->p_config[i].list.psz_cb != NULL)
{ {
/* !unloadable not allowed for plugins with callbacks */ /* !unloadable not allowed for plugins with callbacks */
vlc_module_destroy (module); vlc_module_destroy (module);
......
This diff is collapsed.
...@@ -377,6 +377,8 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...) ...@@ -377,6 +377,8 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
{ {
size_t len = va_arg (ap, size_t); size_t len = va_arg (ap, size_t);
assert (item->list_count == 0); /* cannot replace choices */
assert (item->list.psz_cb == NULL);
/* Copy values */ /* Copy values */
if (IsConfigIntegerType (item->i_type)) if (IsConfigIntegerType (item->i_type))
{ {
...@@ -388,7 +390,7 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...) ...@@ -388,7 +390,7 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
memcpy (dst, src, sizeof (int) * len); memcpy (dst, src, sizeof (int) * len);
dst[len] = 0; dst[len] = 0;
} }
item->pi_list = dst; item->list.i = dst;
} }
else else
if (IsConfigStringType (item->i_type)) if (IsConfigStringType (item->i_type))
...@@ -402,7 +404,7 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...) ...@@ -402,7 +404,7 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
dst[i] = src[i] ? strdup (src[i]) : NULL; dst[i] = src[i] ? strdup (src[i]) : NULL;
dst[len] = NULL; dst[len] = NULL;
} }
item->ppsz_list = dst; item->list.psz = dst;
} }
else else
break; break;
...@@ -416,13 +418,13 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...) ...@@ -416,13 +418,13 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
dtext[i] = text[i] ? strdup (text[i]) : NULL; dtext[i] = text[i] ? strdup (text[i]) : NULL;
dtext[len] = NULL; dtext[len] = NULL;
} }
item->ppsz_list_text = dtext; item->list_text = dtext;
item->i_list = len; item->list_count = len;
break; break;
} }
case VLC_CONFIG_LIST_CB: case VLC_CONFIG_LIST_CB:
item->pf_update_list = va_arg (ap, vlc_string_list_cb); item->list.psz_cb = va_arg (ap, vlc_string_list_cb);
break; break;
default: default:
......
...@@ -182,11 +182,12 @@ void vout_InitInterlacingSupport(vout_thread_t *vout, bool is_interlaced) ...@@ -182,11 +182,12 @@ void vout_InitInterlacingSupport(vout_thread_t *vout, bool is_interlaced)
const module_config_t *optd = config_FindConfig(VLC_OBJECT(vout), "deinterlace"); const module_config_t *optd = config_FindConfig(VLC_OBJECT(vout), "deinterlace");
var_Change(vout, "deinterlace", VLC_VAR_CLEARCHOICES, NULL, NULL); var_Change(vout, "deinterlace", VLC_VAR_CLEARCHOICES, NULL, NULL);
for (int i = 0; optd && i < optd->i_list; i++) { if (likely(optd != NULL))
val.i_int = optd->pi_list[i]; for (unsigned i = 0; i < optd->list_count; i++) {
text.psz_string = (char*)vlc_gettext(optd->ppsz_list_text[i]); val.i_int = optd->list.i[i];
var_Change(vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text); text.psz_string = vlc_gettext(optd->list_text[i]);
} var_Change(vout, "deinterlace", VLC_VAR_ADDCHOICE, &val, &text);
}
var_AddCallback(vout, "deinterlace", DeinterlaceCallback, NULL); var_AddCallback(vout, "deinterlace", DeinterlaceCallback, NULL);
/* */ /* */
var_Create(vout, "deinterlace-mode", VLC_VAR_STRING | VLC_VAR_DOINHERIT | VLC_VAR_HASCHOICE); var_Create(vout, "deinterlace-mode", VLC_VAR_STRING | VLC_VAR_DOINHERIT | VLC_VAR_HASCHOICE);
...@@ -197,14 +198,16 @@ void vout_InitInterlacingSupport(vout_thread_t *vout, bool is_interlaced) ...@@ -197,14 +198,16 @@ void vout_InitInterlacingSupport(vout_thread_t *vout, bool is_interlaced)
const module_config_t *optm = config_FindConfig(VLC_OBJECT(vout), "deinterlace-mode"); const module_config_t *optm = config_FindConfig(VLC_OBJECT(vout), "deinterlace-mode");
var_Change(vout, "deinterlace-mode", VLC_VAR_CLEARCHOICES, NULL, NULL); var_Change(vout, "deinterlace-mode", VLC_VAR_CLEARCHOICES, NULL, NULL);
for (int i = 0; optm && i < optm->i_list; i++) { if (likely(optm != NULL))
if (!DeinterlaceIsModeValid(optm->ppsz_list[i])) for (unsigned i = 0; i < optm->list_count; i++) {
continue; if (!DeinterlaceIsModeValid(optm->list.psz[i]))
continue;
val.psz_string = optm->ppsz_list[i];
text.psz_string = (char*)vlc_gettext(optm->ppsz_list_text[i]); val.psz_string = optm->list.psz[i];
var_Change(vout, "deinterlace-mode", VLC_VAR_ADDCHOICE, &val, &text); text.psz_string = vlc_gettext(optm->list_text[i]);
} var_Change(vout, "deinterlace-mode", VLC_VAR_ADDCHOICE,
&val, &text);
}
var_AddCallback(vout, "deinterlace-mode", DeinterlaceCallback, NULL); var_AddCallback(vout, "deinterlace-mode", DeinterlaceCallback, NULL);
/* */ /* */
var_Create(vout, "deinterlace-needed", VLC_VAR_BOOL); var_Create(vout, "deinterlace-needed", VLC_VAR_BOOL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment