Skip to contentSkip to conversation

Mixer Event

DISCUSSION Gregor Jasny 2 participants 2 messages Oct 8, 2004

lore
Share & tools
lore
#0 lore raw

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

#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;
}
#1 lore raw
Quoted 10 lines · Gregor Jasny

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.

'revents && POLLNVAL' should be 'revents & POLLNVAL'

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl