forked from enlightenment/enlightenment
mixer: factorise get/free channels info and names
E_Mixer_Channel_Info allocated in subsystems, then freed in generic functions in e_mod_mixer.c
This commit is contained in:
parent
03b9522b04
commit
640b339a80
|
@ -203,54 +203,6 @@ _cb_channel_selected(void *data)
|
|||
_populate_channel_editor(app);
|
||||
}
|
||||
|
||||
static int
|
||||
_channel_info_cmp(const void *data_a, const void *data_b)
|
||||
{
|
||||
const E_Mixer_Channel_Info *a = data_a, *b = data_b;
|
||||
|
||||
if (a->has_capture < b->has_capture)
|
||||
return -1;
|
||||
else if (a->has_capture > b->has_capture)
|
||||
return 1;
|
||||
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
static Eina_List *
|
||||
_channels_info_new(E_Mixer_System *sys)
|
||||
{
|
||||
Eina_List *channels, *channels_infos, *l;
|
||||
|
||||
channels = e_mod_mixer_channels_get(sys);
|
||||
channels_infos = NULL;
|
||||
for (l = channels; l; l = l->next)
|
||||
{
|
||||
E_Mixer_Channel_Info *info;
|
||||
|
||||
info = malloc(sizeof(*info));
|
||||
info->id = l->data;
|
||||
info->name = e_mod_mixer_channel_name_get(sys, info->id);
|
||||
info->has_capture = e_mod_mixer_capture_get(sys, info->id);
|
||||
|
||||
channels_infos = eina_list_append(channels_infos, info);
|
||||
}
|
||||
e_mod_mixer_channels_free(channels);
|
||||
|
||||
return eina_list_sort(channels_infos, -1, _channel_info_cmp);
|
||||
}
|
||||
|
||||
static void
|
||||
_channels_info_free(Eina_List *list)
|
||||
{
|
||||
E_Mixer_Channel_Info *info;
|
||||
|
||||
EINA_LIST_FREE(list, info)
|
||||
{
|
||||
eina_stringshare_del(info->name);
|
||||
free(info);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_cb_system_update(void *data, E_Mixer_System *sys __UNUSED__)
|
||||
{
|
||||
|
@ -289,8 +241,8 @@ _populate_channels(E_Mixer_App_Dialog_Data *app)
|
|||
app->channel_name = e_mod_mixer_channel_default_name_get(app->sys);
|
||||
|
||||
if (app->channels_infos)
|
||||
_channels_info_free(app->channels_infos);
|
||||
app->channels_infos = _channels_info_new(app->sys);
|
||||
e_mod_mixer_channels_info_free(app->channels_infos);
|
||||
app->channels_infos = e_mod_mixer_channels_info_get(app->sys);
|
||||
|
||||
if (app->channels_infos)
|
||||
{
|
||||
|
@ -490,7 +442,7 @@ _mixer_app_dialog_del(E_Dialog *dialog, E_Mixer_App_Dialog_Data *app)
|
|||
if (app->cards)
|
||||
e_mod_mixer_cards_free(app->cards);
|
||||
if (app->channels_infos)
|
||||
_channels_info_free(app->channels_infos);
|
||||
e_mod_mixer_channels_info_free(app->channels_infos);
|
||||
e_mod_mixer_del(app->sys);
|
||||
|
||||
e_util_defer_object_del(E_OBJECT(dialog));
|
||||
|
|
|
@ -136,7 +136,7 @@ _free_data(E_Config_Dialog *dialog, E_Config_Dialog_Data *cfdata)
|
|||
eina_stringshare_del(card);
|
||||
|
||||
if (cfdata->channels_names)
|
||||
e_mod_mixer_channels_free(cfdata->channels_names);
|
||||
e_mod_mixer_channels_names_free(cfdata->channels_names);
|
||||
if (cfdata->cards)
|
||||
e_mod_mixer_cards_free(cfdata->cards);
|
||||
|
||||
|
@ -293,7 +293,7 @@ _card_change(void *data, Evas_Object *obj, void *event __UNUSED__)
|
|||
|
||||
eina_stringshare_del(cfdata->card);
|
||||
|
||||
e_mod_mixer_channels_free(cfdata->channels_names);
|
||||
e_mod_mixer_channels_names_free(cfdata->channels_names);
|
||||
|
||||
eina_stringshare_del(cfdata->channel_name);
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ E_Mixer_Cb e_mod_mixer_channel_get_by_name;
|
|||
E_Mixer_Cb e_mod_mixer_channel_name_get;
|
||||
E_Mixer_Cb e_mod_mixer_channel_del;
|
||||
E_Mixer_Cb e_mod_mixer_channel_free;
|
||||
E_Mixer_Cb e_mod_mixer_channels_free;
|
||||
E_Mixer_Cb e_mod_mixer_channels_get;
|
||||
E_Mixer_Cb e_mod_mixer_channels_names_get;
|
||||
E_Mixer_Cb e_mod_mixer_card_name_get;
|
||||
|
@ -39,7 +38,6 @@ e_mixer_default_setup(void)
|
|||
e_mod_mixer_channel_get_by_name = (void *)e_mixer_system_get_channel_by_name;
|
||||
e_mod_mixer_channel_name_get = (void *)e_mixer_system_get_channel_name;
|
||||
e_mod_mixer_channel_del = (void *)e_mixer_system_channel_del;
|
||||
e_mod_mixer_channels_free = (void *)e_mixer_system_free_channels;
|
||||
e_mod_mixer_channels_get = (void *)e_mixer_system_get_channels;
|
||||
e_mod_mixer_channels_names_get = (void *)e_mixer_system_get_channels_names;
|
||||
e_mod_mixer_card_name_get = (void *)e_mixer_system_get_card_name;
|
||||
|
@ -65,7 +63,6 @@ e_mixer_pulse_setup()
|
|||
e_mod_mixer_channel_get_by_name = (void *)e_mixer_pulse_get_channel_by_name;
|
||||
e_mod_mixer_channel_name_get = (void *)e_mixer_pulse_get_channel_name;
|
||||
e_mod_mixer_channel_del = (void *)e_mixer_pulse_channel_del;
|
||||
e_mod_mixer_channels_free = (void *)e_mixer_pulse_free_channels;
|
||||
e_mod_mixer_channels_get = (void *)e_mixer_pulse_get_channels;
|
||||
e_mod_mixer_channels_names_get = (void *)e_mixer_pulse_get_channels_names;
|
||||
e_mod_mixer_card_name_get = (void *)e_mixer_pulse_get_card_name;
|
||||
|
@ -75,3 +72,41 @@ e_mixer_pulse_setup()
|
|||
_mixer_using_default = EINA_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
_channel_info_cmp(const void *data_a, const void *data_b)
|
||||
{
|
||||
const E_Mixer_Channel_Info *a = data_a, *b = data_b;
|
||||
|
||||
if (a->has_capture < b->has_capture)
|
||||
return -1;
|
||||
else if (a->has_capture > b->has_capture)
|
||||
return 1;
|
||||
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
Eina_List *
|
||||
e_mod_mixer_channels_info_get(E_Mixer_System *sys)
|
||||
{
|
||||
return eina_list_sort(e_mod_mixer_channels_get(sys), -1, _channel_info_cmp);
|
||||
}
|
||||
|
||||
void
|
||||
e_mod_mixer_channels_info_free(Eina_List *list)
|
||||
{
|
||||
E_Mixer_Channel_Info *info;
|
||||
|
||||
EINA_LIST_FREE(list, info)
|
||||
{
|
||||
eina_stringshare_del(info->name);
|
||||
free(info);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
e_mod_mixer_channels_names_free(Eina_List *list)
|
||||
{
|
||||
const char *str;
|
||||
EINA_LIST_FREE(list, str)
|
||||
eina_stringshare_del(str);
|
||||
}
|
||||
|
|
|
@ -45,14 +45,16 @@ extern E_Mixer_Cb e_mod_mixer_channel_get_by_name;
|
|||
extern E_Mixer_Cb e_mod_mixer_channel_name_get;
|
||||
extern E_Mixer_Cb e_mod_mixer_channel_del;
|
||||
extern E_Mixer_Cb e_mod_mixer_channel_free;
|
||||
extern E_Mixer_Cb e_mod_mixer_channels_free;
|
||||
extern E_Mixer_Cb e_mod_mixer_channels_get;
|
||||
extern E_Mixer_Cb e_mod_mixer_channels_names_get;
|
||||
extern E_Mixer_Cb e_mod_mixer_card_name_get;
|
||||
extern E_Mixer_Cb e_mod_mixer_cards_get;
|
||||
extern E_Mixer_Cb e_mod_mixer_cards_free;
|
||||
extern E_Mixer_Cb e_mod_mixer_card_default_get;
|
||||
|
||||
Eina_List *e_mod_mixer_channels_info_get(E_Mixer_System *sys);
|
||||
void e_mod_mixer_channels_info_free(Eina_List*);
|
||||
void e_mod_mixer_channels_names_free(Eina_List*);
|
||||
|
||||
void e_mixer_default_setup(void);
|
||||
void e_mixer_pulse_setup();
|
||||
|
||||
|
@ -69,9 +71,7 @@ const char *e_mixer_system_get_card_name(const char *card);
|
|||
const char *e_mixer_system_get_channel_name(E_Mixer_System *self, E_Mixer_Channel *channel);
|
||||
|
||||
Eina_List *e_mixer_system_get_channels(E_Mixer_System *self);
|
||||
void e_mixer_system_free_channels(Eina_List *channels);
|
||||
Eina_List *e_mixer_system_get_channels_names(E_Mixer_System *self);
|
||||
void e_mixer_system_free_channels_names(Eina_List *channels_names);
|
||||
|
||||
const char *e_mixer_system_get_default_channel_name(E_Mixer_System *self);
|
||||
E_Mixer_Channel *e_mixer_system_get_channel_by_name(E_Mixer_System *self, const char *name);
|
||||
|
@ -102,9 +102,7 @@ const char *e_mixer_pulse_get_card_name(const char *card);
|
|||
const char *e_mixer_pulse_get_channel_name(E_Mixer_System *self, E_Mixer_Channel *channel);
|
||||
|
||||
Eina_List *e_mixer_pulse_get_channels(E_Mixer_System *self);
|
||||
void e_mixer_pulse_free_channels(Eina_List *channels);
|
||||
Eina_List *e_mixer_pulse_get_channels_names(E_Mixer_System *self);
|
||||
void e_mixer_pulse_free_channels_names(Eina_List *channels_names);
|
||||
|
||||
const char *e_mixer_pulse_get_default_channel_name(E_Mixer_System *self);
|
||||
E_Mixer_Channel *e_mixer_pulse_get_channel_by_name(E_Mixer_System *self, const char *name);
|
||||
|
|
|
@ -321,18 +321,19 @@ e_mixer_system_get_channels(E_Mixer_System *self)
|
|||
(!snd_mixer_selem_has_playback_volume(elem)))
|
||||
continue;
|
||||
|
||||
channels = eina_list_append(channels, elem);
|
||||
E_Mixer_Channel_Info *ch_info;
|
||||
|
||||
ch_info = malloc(sizeof(*ch_info));
|
||||
ch_info->id = elem;
|
||||
ch_info->name = eina_stringshare_add(snd_mixer_selem_get_name(elem));
|
||||
ch_info->has_capture = snd_mixer_selem_has_capture_switch(elem) || snd_mixer_selem_has_capture_volume(elem);
|
||||
|
||||
channels = eina_list_append(channels, ch_info);
|
||||
}
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
void
|
||||
e_mixer_system_free_channels(Eina_List *channels)
|
||||
{
|
||||
eina_list_free(channels);
|
||||
}
|
||||
|
||||
Eina_List *
|
||||
e_mixer_system_get_channels_names(E_Mixer_System *self)
|
||||
{
|
||||
|
@ -363,15 +364,6 @@ e_mixer_system_get_channels_names(E_Mixer_System *self)
|
|||
return channels;
|
||||
}
|
||||
|
||||
void
|
||||
e_mixer_system_free_channels_names(Eina_List *channels_names)
|
||||
{
|
||||
const char *channel;
|
||||
|
||||
EINA_LIST_FREE(channels_names, channel)
|
||||
eina_stringshare_del(channel);
|
||||
}
|
||||
|
||||
const char *
|
||||
e_mixer_system_get_default_channel_name(E_Mixer_System *self)
|
||||
{
|
||||
|
|
|
@ -67,13 +67,14 @@ e_mixer_system_get_card_name(const char *card)
|
|||
Eina_List *
|
||||
e_mixer_system_get_channels(E_Mixer_System *self __UNUSED__)
|
||||
{
|
||||
return eina_list_append(NULL, (void *)-2);
|
||||
}
|
||||
E_Mixer_Channel_Info *ch_info;
|
||||
|
||||
void
|
||||
e_mixer_system_free_channels(Eina_List *channels)
|
||||
{
|
||||
eina_list_free(channels);
|
||||
ch_info = malloc(sizeof(*ch_info));
|
||||
ch_info->id = (void*)-2;
|
||||
ch_info->name = eina_stringshare_ref(_name);
|
||||
ch_info->has_capture = 0;
|
||||
|
||||
return eina_list_append(NULL, ch_info);
|
||||
}
|
||||
|
||||
Eina_List *
|
||||
|
@ -81,13 +82,7 @@ e_mixer_system_get_channels_names(E_Mixer_System *self __UNUSED__)
|
|||
{
|
||||
_e_mixer_dummy_set();
|
||||
|
||||
return eina_list_append(NULL, _name);
|
||||
}
|
||||
|
||||
void
|
||||
e_mixer_system_free_channels_names(Eina_List *channels_names)
|
||||
{
|
||||
eina_list_free(channels_names);
|
||||
return eina_list_append(NULL, eina_stringshare_ref(_name));
|
||||
}
|
||||
|
||||
const char *
|
||||
|
|
|
@ -477,13 +477,14 @@ e_mixer_pulse_get_card_name(const char *card)
|
|||
Eina_List *
|
||||
e_mixer_pulse_get_channels(E_Mixer_System *self EINA_UNUSED)
|
||||
{
|
||||
return eina_list_append(NULL, (void *)(1));
|
||||
}
|
||||
E_Mixer_Channel_Info *ch_info;
|
||||
|
||||
void
|
||||
e_mixer_pulse_free_channels(Eina_List *channels)
|
||||
{
|
||||
eina_list_free(channels);
|
||||
ch_info = malloc(sizeof(*ch_info));
|
||||
ch_info->id = (void*)1;
|
||||
ch_info->name = eina_stringshare_ref(_name);
|
||||
ch_info->has_capture = 0;
|
||||
|
||||
return eina_list_append(NULL, ch_info);
|
||||
}
|
||||
|
||||
Eina_List *
|
||||
|
@ -492,14 +493,6 @@ e_mixer_pulse_get_channels_names(E_Mixer_System *self EINA_UNUSED)
|
|||
return eina_list_append(NULL, eina_stringshare_ref(_name));
|
||||
}
|
||||
|
||||
void
|
||||
e_mixer_pulse_free_channels_names(Eina_List *channels_names)
|
||||
{
|
||||
const char *str;
|
||||
EINA_LIST_FREE(channels_names, str)
|
||||
eina_stringshare_del(str);
|
||||
}
|
||||
|
||||
const char *
|
||||
e_mixer_pulse_get_default_channel_name(E_Mixer_System *self EINA_UNUSED)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue