From: Gregor Jasny <jasny@vidsoft.de>
To: alsa-devel@lists.sourceforge.net
Subject: Mixer Event
Date: Fri, 08 Oct 2004 13:32:12 +0200 [thread overview]
Message-ID: <41667ABC.8080805@vidsoft.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 417 bytes --]
Hi all,
I want to poll a mixer device for events. After setting the callback
handler i get for every channel a callback with mask 4 (I think this is
'add device'). But after waiting at poll() and altering the volume of a
channel I get an error at snd_mixer_poll_descriptors_revents():
snd_mixer_poll_descriptors_revents() POLLNVAL: Operation not permitted
I've attached the source.
Thanks in advance,
-Gregor
[-- Attachment #2: event.c --]
[-- Type: text/x-csrc, Size: 2452 bytes --]
#include <stdlib.h>
#include <stdio.h>
#include <sys/poll.h>
#include <alsa/asoundlib.h>
int
mixer_event (snd_mixer_t *mixer, unsigned int mask, snd_mixer_elem_t *elem)
{
fprintf(stderr, "EVENT! %x %s\n", mask, snd_mixer_selem_get_name(elem) );
return 0;
}
int main (int argc, char *argv[])
{
int count, err, finished;
struct pollfd *fds;
unsigned short revents;
snd_mixer_t *mixer;
if ((err = snd_mixer_open(&mixer, 0)) < 0) {
fprintf(stderr, "snd_open_mixer(): %s\n", snd_strerror(-err));
return -1;
}
if ((err = snd_mixer_attach(mixer, "default")) < 0) {
fprintf(stderr, "snd_mixer_attach(): %s\n", snd_strerror(-err));
return -1;
}
if ((err = snd_mixer_selem_register(mixer, NULL, NULL)) < 0) {
fprintf(stderr, "snd_mixer_selem_register(): %s\n", snd_strerror(-err));
return -1;
}
snd_mixer_set_callback(mixer, mixer_event);
if ((err = snd_mixer_load(mixer)) < 0) {
fprintf(stderr, "snd_mixer_load(): %s\n", snd_strerror(-err));
return -1;
}
if ((count = snd_mixer_poll_descriptors_count(mixer)) < 0) {
fprintf(stderr, "snd_mixer_poll_descriptors_count(): %s\n", snd_strerror(-err));
return -1;
}
fds = calloc( count, sizeof( struct pollfd ) );
if ((err = snd_mixer_poll_descriptors(mixer, fds, count)) < 0) {
fprintf(stderr, "snd_mixer_poll_descriptors(): %s\n", snd_strerror(-err));
return -1;
}
if (err != count) {
fprintf(stderr,"snd_mixer_poll_descriptors(): err != count\n");
return -1;
}
finished = poll(fds, count, -1);
if (finished > 0) {
if (snd_mixer_poll_descriptors_revents( mixer, fds, count, &revents) >= 0) {
if (revents && POLLNVAL) {
fprintf(stderr, "snd_mixer_poll_descriptors_revents() POLLNVAL: %s\n", snd_strerror(-err));
return -1;
}
if (revents && POLLERR) {
fprintf(stderr, "snd_mixer_poll_descriptors_revents() POLLERR: %s\n", snd_strerror(-err));
return -1;
}
if (revents && POLLIN) {
snd_mixer_handle_events (mixer);
}
}
}
free (fds);
if ((err = snd_mixer_close(mixer)) < 0) {
fprintf(stderr, "snd_mixer_close(): %s\n", snd_strerror(-err));
return -1;
}
return 0;
}
next reply other threads:[~2004-10-08 11:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-08 11:32 Gregor Jasny [this message]
2004-10-08 11:44 ` Mixer Event Jaroslav Kysela
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41667ABC.8080805@vidsoft.de \
--to=jasny@vidsoft.de \
--cc=alsa-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.