mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
alsa: refactor some helpers to add/remove a card
This commit is contained in:
parent
9b414b0a9e
commit
69da2ec601
1 changed files with 23 additions and 9 deletions
|
|
@ -101,6 +101,20 @@ static int impl_udev_close(struct impl *this)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct card *add_card(struct impl *this, uint32_t id, struct udev_device *dev)
|
||||||
|
{
|
||||||
|
struct card *card;
|
||||||
|
|
||||||
|
if (this->n_cards >= MAX_CARDS)
|
||||||
|
return NULL;
|
||||||
|
card = &this->cards[this->n_cards++];
|
||||||
|
spa_zero(*card);
|
||||||
|
card->id = id;
|
||||||
|
udev_device_ref(dev);
|
||||||
|
card->dev = dev;
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
static struct card *find_card(struct impl *this, uint32_t id)
|
static struct card *find_card(struct impl *this, uint32_t id)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
@ -111,6 +125,12 @@ static struct card *find_card(struct impl *this, uint32_t id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void remove_card(struct impl *this, struct card *card)
|
||||||
|
{
|
||||||
|
udev_device_unref(card->dev);
|
||||||
|
*card = this->cards[--this->n_cards];
|
||||||
|
}
|
||||||
|
|
||||||
static const char *path_get_card_id(const char *path)
|
static const char *path_get_card_id(const char *path)
|
||||||
{
|
{
|
||||||
const char *e;
|
const char *e;
|
||||||
|
|
@ -378,13 +398,8 @@ static int need_notify(struct impl *this, struct udev_device *dev, uint32_t acti
|
||||||
case ACTION_ADD:
|
case ACTION_ADD:
|
||||||
if (card != NULL)
|
if (card != NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (this->n_cards >= MAX_CARDS)
|
if ((card = add_card(this, id, dev)) == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
card = &this->cards[this->n_cards++];
|
|
||||||
spa_zero(*card);
|
|
||||||
card->id = id;
|
|
||||||
udev_device_ref(dev);
|
|
||||||
card->dev = dev;
|
|
||||||
/** don't notify on add, wait for the next change event */
|
/** don't notify on add, wait for the next change event */
|
||||||
if (!enumerated)
|
if (!enumerated)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -405,8 +420,7 @@ static int need_notify(struct impl *this, struct udev_device *dev, uint32_t acti
|
||||||
if (card == NULL)
|
if (card == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
emited = card->emited;
|
emited = card->emited;
|
||||||
udev_device_unref(card->dev);
|
remove_card(this, card);
|
||||||
*card = this->cards[--this->n_cards];
|
|
||||||
if (!emited)
|
if (!emited)
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue