All of lore.kernel.org
 help / color / mirror / Atom feed
* Mixer Event
@ 2004-10-08 11:32 Gregor Jasny
  2004-10-08 11:44 ` Jaroslav Kysela
  0 siblings, 1 reply; 2+ messages in thread
From: Gregor Jasny @ 2004-10-08 11:32 UTC (permalink / raw)
  To: alsa-devel

[-- 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;
}

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

end of thread, other threads:[~2004-10-08 11:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-08 11:32 Mixer Event Gregor Jasny
2004-10-08 11:44 ` Jaroslav Kysela

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.