mirror of
https://gitee.com/openharmony/third_party_alsa-lib
synced 2025-02-17 07:11:00 +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) {
|
while (l < u) {
|
||||||
idx = (l + u) / 2;
|
idx = (l + u) / 2;
|
||||||
c = hctl->compare((snd_hctl_elem_t *) id, hctl->pelems[idx]);
|
c = hctl->compare((snd_hctl_elem_t *) id, hctl->pelems[idx]);
|
||||||
if (c < 0)
|
if (c > 0)
|
||||||
u = idx;
|
u = idx;
|
||||||
else if (c > 0)
|
else if (c < 0)
|
||||||
l = idx + 1;
|
l = idx + 1;
|
||||||
else
|
else
|
||||||
break;
|
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,
|
memmove(hctl->pelems + idx + 1,
|
||||||
hctl->pelems + idx,
|
hctl->pelems + idx,
|
||||||
hctl->count - idx);
|
(hctl->count - idx) * sizeof(snd_hctl_elem_t *));
|
||||||
|
hctl->pelems[idx] = elem;
|
||||||
}
|
}
|
||||||
hctl->count++;
|
hctl->count++;
|
||||||
return snd_hctl_throw_event(hctl, SND_CTL_EVENT_ADD, elem);
|
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--;
|
hctl->count--;
|
||||||
m = hctl->count - idx;
|
m = hctl->count - idx;
|
||||||
if (m > 0)
|
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)
|
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) {
|
while (l < u) {
|
||||||
idx = (l + u) / 2;
|
idx = (l + u) / 2;
|
||||||
c = mixer->compare(elem, mixer->pelems[idx]);
|
c = mixer->compare(elem, mixer->pelems[idx]);
|
||||||
if (c < 0)
|
if (c > 0)
|
||||||
u = idx;
|
u = idx;
|
||||||
else if (c > 0)
|
else if (c < 0)
|
||||||
l = idx + 1;
|
l = idx + 1;
|
||||||
else
|
else
|
||||||
break;
|
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,
|
memmove(mixer->pelems + idx + 1,
|
||||||
mixer->pelems + idx,
|
mixer->pelems + idx,
|
||||||
mixer->count - idx);
|
(mixer->count - idx) * sizeof(snd_mixer_elem_t *));
|
||||||
|
mixer->pelems[idx] = elem;
|
||||||
}
|
}
|
||||||
mixer->count++;
|
mixer->count++;
|
||||||
return snd_mixer_throw_event(mixer, SND_CTL_EVENT_ADD, elem);
|
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;
|
int err, idx, dir;
|
||||||
unsigned int m;
|
unsigned int m;
|
||||||
assert(elem);
|
assert(elem);
|
||||||
|
assert(mixer->count);
|
||||||
idx = _snd_mixer_find_elem(mixer, elem, &dir);
|
idx = _snd_mixer_find_elem(mixer, elem, &dir);
|
||||||
if (dir != 0)
|
if (dir != 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
err = snd_mixer_elem_throw_event(elem, SND_CTL_EVENT_REMOVE);
|
err = snd_mixer_elem_throw_event(elem, SND_CTL_EVENT_REMOVE);
|
||||||
list_del(&elem->list);
|
list_del(&elem->list);
|
||||||
|
if (elem->private_free)
|
||||||
|
elem->private_free(elem);
|
||||||
free(elem);
|
free(elem);
|
||||||
mixer->count--;
|
mixer->count--;
|
||||||
m = mixer->count - idx;
|
m = mixer->count - idx;
|
||||||
if (m > 0)
|
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;
|
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)
|
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;
|
snd_mixer_t *mixer = class->mixer;
|
||||||
list_for_each(pos, next, &mixer->elems) {
|
for (k = mixer->count; k > 0; k--) {
|
||||||
snd_mixer_elem_t *e;
|
e = mixer->pelems[k-1];
|
||||||
e = list_entry(pos, snd_mixer_elem_t, list);
|
if (e->class == class)
|
||||||
if (e->class == class && e->private_free)
|
snd_mixer_elem_remove(e);
|
||||||
e->private_free(e);
|
|
||||||
snd_mixer_elem_remove(e);
|
|
||||||
}
|
}
|
||||||
if (class->private_free)
|
if (class->private_free)
|
||||||
class->private_free(class);
|
class->private_free(class);
|
||||||
@ -380,6 +385,7 @@ int snd_mixer_close(snd_mixer_t *mixer)
|
|||||||
snd_mixer_class_unregister(c);
|
snd_mixer_class_unregister(c);
|
||||||
}
|
}
|
||||||
assert(list_empty(&mixer->elems));
|
assert(list_empty(&mixer->elems));
|
||||||
|
assert(mixer->count == 0);
|
||||||
if (mixer->pelems) {
|
if (mixer->pelems) {
|
||||||
free(mixer->pelems);
|
free(mixer->pelems);
|
||||||
mixer->pelems = NULL;
|
mixer->pelems = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user