mirror of
https://gitee.com/openharmony/third_party_alsa-lib
synced 2024-11-23 15:39:58 +00:00
More bugfixes (sort, compare, mixer, hcontrol).
This commit is contained in:
parent
515d1a6415
commit
a86efa083c
@ -99,9 +99,9 @@ static int _snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id, in
|
||||
while (l < u) {
|
||||
idx = (l + u) / 2;
|
||||
c = hctl->compare((snd_hctl_elem_t *) id, hctl->pelems[idx]);
|
||||
if (c < 0)
|
||||
if (c > 0)
|
||||
u = idx;
|
||||
else if (c > 0)
|
||||
else if (c < 0)
|
||||
l = idx + 1;
|
||||
else
|
||||
break;
|
||||
@ -154,7 +154,8 @@ static int snd_hctl_elem_add(snd_hctl_t *hctl, snd_hctl_elem_t *elem)
|
||||
}
|
||||
memmove(hctl->pelems + idx + 1,
|
||||
hctl->pelems + idx,
|
||||
hctl->count - idx);
|
||||
(hctl->count - idx) * sizeof(snd_hctl_elem_t *));
|
||||
hctl->pelems[idx] = elem;
|
||||
}
|
||||
hctl->count++;
|
||||
return snd_hctl_throw_event(hctl, SND_CTL_EVENT_ADD, elem);
|
||||
@ -170,7 +171,9 @@ static void snd_hctl_elem_remove(snd_hctl_t *hctl, unsigned int idx)
|
||||
hctl->count--;
|
||||
m = hctl->count - idx;
|
||||
if (m > 0)
|
||||
memmove(hctl->pelems + idx, hctl->pelems + idx + 1, m);
|
||||
memmove(hctl->pelems + idx,
|
||||
hctl->pelems + idx + 1,
|
||||
m * sizeof(snd_hctl_elem_t *));
|
||||
}
|
||||
|
||||
int snd_hctl_free(snd_hctl_t *hctl)
|
||||
|
@ -233,9 +233,9 @@ static int _snd_mixer_find_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem, int
|
||||
while (l < u) {
|
||||
idx = (l + u) / 2;
|
||||
c = mixer->compare(elem, mixer->pelems[idx]);
|
||||
if (c < 0)
|
||||
if (c > 0)
|
||||
u = idx;
|
||||
else if (c > 0)
|
||||
else if (c < 0)
|
||||
l = idx + 1;
|
||||
else
|
||||
break;
|
||||
@ -274,7 +274,8 @@ int snd_mixer_elem_add(snd_mixer_elem_t *elem, snd_mixer_class_t *class)
|
||||
}
|
||||
memmove(mixer->pelems + idx + 1,
|
||||
mixer->pelems + idx,
|
||||
mixer->count - idx);
|
||||
(mixer->count - idx) * sizeof(snd_mixer_elem_t *));
|
||||
mixer->pelems[idx] = elem;
|
||||
}
|
||||
mixer->count++;
|
||||
return snd_mixer_throw_event(mixer, SND_CTL_EVENT_ADD, elem);
|
||||
@ -286,16 +287,21 @@ int snd_mixer_elem_remove(snd_mixer_elem_t *elem)
|
||||
int err, idx, dir;
|
||||
unsigned int m;
|
||||
assert(elem);
|
||||
assert(mixer->count);
|
||||
idx = _snd_mixer_find_elem(mixer, elem, &dir);
|
||||
if (dir != 0)
|
||||
return -EINVAL;
|
||||
err = snd_mixer_elem_throw_event(elem, SND_CTL_EVENT_REMOVE);
|
||||
list_del(&elem->list);
|
||||
if (elem->private_free)
|
||||
elem->private_free(elem);
|
||||
free(elem);
|
||||
mixer->count--;
|
||||
m = mixer->count - idx;
|
||||
if (m > 0)
|
||||
memmove(mixer->pelems + idx, mixer->pelems + idx + 1, m);
|
||||
memmove(mixer->pelems + idx,
|
||||
mixer->pelems + idx + 1,
|
||||
m * sizeof(snd_mixer_elem_t *));
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -330,14 +336,13 @@ int snd_mixer_class_register(snd_mixer_class_t *class, snd_mixer_t *mixer)
|
||||
|
||||
int snd_mixer_class_unregister(snd_mixer_class_t *class)
|
||||
{
|
||||
struct list_head *pos, *next;
|
||||
unsigned int k;
|
||||
snd_mixer_elem_t *e;
|
||||
snd_mixer_t *mixer = class->mixer;
|
||||
list_for_each(pos, next, &mixer->elems) {
|
||||
snd_mixer_elem_t *e;
|
||||
e = list_entry(pos, snd_mixer_elem_t, list);
|
||||
if (e->class == class && e->private_free)
|
||||
e->private_free(e);
|
||||
snd_mixer_elem_remove(e);
|
||||
for (k = mixer->count; k > 0; k--) {
|
||||
e = mixer->pelems[k-1];
|
||||
if (e->class == class)
|
||||
snd_mixer_elem_remove(e);
|
||||
}
|
||||
if (class->private_free)
|
||||
class->private_free(class);
|
||||
@ -380,6 +385,7 @@ int snd_mixer_close(snd_mixer_t *mixer)
|
||||
snd_mixer_class_unregister(c);
|
||||
}
|
||||
assert(list_empty(&mixer->elems));
|
||||
assert(mixer->count == 0);
|
||||
if (mixer->pelems) {
|
||||
free(mixer->pelems);
|
||||
mixer->pelems = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user