Added snd_timer_async() function.

More updates to pcm_dmix.c .
This commit is contained in:
Jaroslav Kysela 2003-02-06 19:15:53 +00:00
parent 7c5e5f5728
commit 757785fece
5 changed files with 125 additions and 32 deletions

View file

@ -73,6 +73,7 @@ This example shows opening a timer device and reading of timer events.
#include <string.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <signal.h>
#include <sys/ioctl.h>
#include "timer_local.h"
@ -350,6 +351,27 @@ int snd_timer_nonblock(snd_timer_t *timer, int nonblock)
return 0;
}
#ifndef DOC_HIDDEN
/**
* \brief set async mode
* \param timer timer handle
* \param sig Signal to raise: < 0 disable, 0 default (SIGIO)
* \param pid Process ID to signal: 0 current
* \return 0 on success otherwise a negative error code
*
* A signal is raised every period.
*/
int snd_timer(snd_timer_t *timer, int sig, pid_t pid)
{
assert(timer);
if (sig == 0)
sig = SIGIO;
if (pid == 0)
pid = getpid();
return timer->ops->async(timer, sig, pid);
}
#endif
/**
* \brief get size of the snd_timer_info_t structure in bytes
* \return size of the snd_timer_info_t structure in bytes

View file

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define __USE_GNU
#include <fcntl.h>
#include <sys/ioctl.h>
#include "timer_local.h"
@ -61,6 +62,38 @@ static int snd_timer_hw_nonblock(snd_timer_t *timer, int nonblock)
return 0;
}
static int snd_timer_hw_async(snd_timer_t *timer, int sig, pid_t pid)
{
long flags;
int fd;
assert(timer);
fd = timer->poll_fd;
if ((flags = fcntl(fd, F_GETFL)) < 0) {
SYSERR("F_GETFL failed");
return -errno;
}
if (sig >= 0)
flags |= O_ASYNC;
else
flags &= ~O_ASYNC;
if (fcntl(fd, F_SETFL, flags) < 0) {
SYSERR("F_SETFL for O_ASYNC failed");
return -errno;
}
if (sig < 0)
return 0;
if (fcntl(fd, F_SETSIG, (long)sig) < 0) {
SYSERR("F_SETSIG failed");
return -errno;
}
if (fcntl(fd, F_SETOWN, (long)pid) < 0) {
SYSERR("F_SETOWN failed");
return -errno;
}
return 0;
}
static int snd_timer_hw_info(snd_timer_t *handle, snd_timer_info_t * info)
{
snd_timer_t *tmr;
@ -148,15 +181,16 @@ static ssize_t snd_timer_hw_read(snd_timer_t *handle, void *buffer, size_t size)
}
static snd_timer_ops_t snd_timer_hw_ops = {
close: snd_timer_hw_close,
nonblock: snd_timer_hw_nonblock,
info: snd_timer_hw_info,
params: snd_timer_hw_params,
status: snd_timer_hw_status,
rt_start: snd_timer_hw_start,
rt_stop: snd_timer_hw_stop,
rt_continue: snd_timer_hw_continue,
read: snd_timer_hw_read,
.close = snd_timer_hw_close,
.nonblock = snd_timer_hw_nonblock,
.async = snd_timer_hw_async,
.info = snd_timer_hw_info,
.params = snd_timer_hw_params,
.status = snd_timer_hw_status,
.rt_start = snd_timer_hw_start,
.rt_stop = snd_timer_hw_stop,
.rt_continue = snd_timer_hw_continue,
.read = snd_timer_hw_read,
};
int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int dev_sclass, int card, int device, int subdevice, int mode)

View file

@ -27,6 +27,7 @@
typedef struct {
int (*close)(snd_timer_t *timer);
int (*nonblock)(snd_timer_t *timer, int nonblock);
int (*async)(snd_timer_t *timer, int sig, pid_t pid);
int (*info)(snd_timer_t *timer, snd_timer_info_t *info);
int (*params)(snd_timer_t *timer, snd_timer_params_t *params);
int (*status)(snd_timer_t *timer, snd_timer_status_t *status);
@ -62,3 +63,5 @@ struct _snd_timer_query {
};
int snd_timer_query_hw_open(snd_timer_query_t **handle, const char *name, int mode);
int snd_timer_async(snd_timer_t *timer, int sig, pid_t pid);