All of lore.kernel.org
 help / color / mirror / Atom feed
* snd_ctl_card_info_t type does not resolve on ubuntu 11.10?
@ 2011-11-15 13:10 Borg Onion
  2011-11-15 14:33 ` Clemens Ladisch
  0 siblings, 1 reply; 2+ messages in thread
From: Borg Onion @ 2011-11-15 13:10 UTC (permalink / raw)
  To: alsa-devel

Hello,

Starting to write an ALSA app and trying to just list sound card info.  The
type "snd_ctl_card_info_t" doesn't seem to resolve by just including
<alsa/asoundlib.h>.  This type is needed for me to
call snd_ctl_card_info().  OS is Ubuntu 11.10 with libasound2-dev
installed.  What am I doing wrong?  Code is below:

#include <stdio.h>
#include <alsa/asoundlib.h>

void print_card_info(snd_ctl_card_info_t info)
{
        printf("Card #=%d, id=%s, driver=%s, name=%s, longname=%s,
mixername=%s, components=%s\n",
                info.card, info.id, info.driver, info.name, info.longname,
info.mixername, info.components);
}

int main(int argc, char **argv)
{
        int card = -1;
        char cardascii[3];
        char *name, *longname;
        snd_ctl_t *handle;
        snd_ctl_card_info_t info;

        while (snd_card_next(&card) >= 0) {
                if (card < 0) {
                        printf("No more cards!\n");
                        break;
                }
                printf("Card %d\n", card);
                if (snd_card_get_name(card, &name))
                {
                        printf("Error getting card %d's name, skipping\n",
card);
                        continue;
                }
                printf("Name = %s\n", name);
                if (snd_card_get_longname(card, &longname))
                {
                        printf("Error getting card %d's long name,
skipping\n", card);
                        continue;
                }
                printf("Long name = %s\n", longname);
                snprintf(cardascii, sizeof(cardascii), "%d", card);
                if (snd_ctl_open(&handle, cardascii, 0))
                {
                        printf("Error opening card #%d, skipping\n", card);
                        continue;
                }
                if (snd_ctl_card_info(handle, &info))
                {
                        printf("Error getting info for card #%d,
skipping\n", card);
                        snd_ctl_close(handle);
                        continue;
                }
                print_card_info(info);
                snd_ctl_close(handle);
        }

        return 0;
}

$ make
mkdir .deps
cc -O2 -std=gnu99 -Wall -Wextra -pedantic -g   -c -DPREFIX=\"/usr/local\"
-Wp,-MD,.deps/list.d -o list.o list.c
list.c:4:42: error: parameter 1 (âinfoâ) has incomplete type
list.c: In function âprint_card_infoâ:
list.c:4:42: warning: unused parameter âinfoâ [-Wunused-parameter]
list.c: In function âmainâ:
list.c:16:22: error: storage size of âinfoâ isnât known
list.c:16:22: warning: unused variable âinfoâ [-Wunused-variable]
list.c:10:14: warning: unused parameter âargcâ [-Wunused-parameter]
list.c:10:27: warning: unused parameter âargvâ [-Wunused-parameter]
make: *** [list.o] Error 1

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: snd_ctl_card_info_t type does not resolve on ubuntu 11.10?
  2011-11-15 13:10 snd_ctl_card_info_t type does not resolve on ubuntu 11.10? Borg Onion
@ 2011-11-15 14:33 ` Clemens Ladisch
  0 siblings, 0 replies; 2+ messages in thread
From: Clemens Ladisch @ 2011-11-15 14:33 UTC (permalink / raw)
  To: Borg Onion; +Cc: alsa-devel

Borg Onion wrote:
> The type "snd_ctl_card_info_t" doesn't seem to resolve by just
> including <alsa/asoundlib.h>.

This structure is not defined to prevent applications from
depending on its binary layout.

Do it like this:
	snd_ctl_card_info_t *info;

	error = snd_ctl_card_info_malloc(&info);
	...
	snd_ctl_card_info(handle, &info);
	...
	snd_ctl_card_info_free(info);

or use alloca instead of malloc/free.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-15 14:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-15 13:10 snd_ctl_card_info_t type does not resolve on ubuntu 11.10? Borg Onion
2011-11-15 14:33 ` Clemens Ladisch

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.