mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-02 09:01:48 -05:00
Coding style...
This commit is contained in:
parent
2605e4d7dd
commit
a741225e6e
6 changed files with 1345 additions and 1223 deletions
626
src/pcm/pcm.c
626
src/pcm/pcm.c
|
|
@ -30,381 +30,413 @@
|
|||
|
||||
#define SND_FILE_PCM "/dev/snd/pcm%i%i"
|
||||
#define SND_PCM_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 1 )
|
||||
|
||||
|
||||
typedef struct {
|
||||
int card;
|
||||
int device;
|
||||
int fd;
|
||||
int card;
|
||||
int device;
|
||||
int fd;
|
||||
} snd_pcm_t;
|
||||
|
||||
int snd_pcm_open( void **handle, int card, int device, int mode )
|
||||
{
|
||||
int fd, ver;
|
||||
char filename[32];
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
*handle = NULL;
|
||||
if ( card < 0 || card >= SND_CARDS ) return -EINVAL;
|
||||
sprintf( filename, SND_FILE_PCM, card, device );
|
||||
if ( (fd = open( filename, mode )) < 0 ) return -errno;
|
||||
if ( ioctl( fd, SND_PCM_IOCTL_PVERSION, &ver ) < 0 ) {
|
||||
close( fd );
|
||||
return -errno;
|
||||
}
|
||||
if ( SND_PROTOCOL_UNCOMPATIBLE( ver, SND_PCM_VERSION_MAX ) ) {
|
||||
close( fd );
|
||||
return -SND_ERROR_UNCOMPATIBLE_VERSION;
|
||||
}
|
||||
pcm = (snd_pcm_t *)calloc( 1, sizeof( snd_pcm_t ) );
|
||||
if ( pcm == NULL ) {
|
||||
close( fd );
|
||||
return -ENOMEM;
|
||||
}
|
||||
pcm -> card = card;
|
||||
pcm -> device = device;
|
||||
pcm -> fd = fd;
|
||||
*handle = pcm;
|
||||
return 0;
|
||||
int snd_pcm_open(void **handle, int card, int device, int mode)
|
||||
{
|
||||
int fd, ver;
|
||||
char filename[32];
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
*handle = NULL;
|
||||
if (card < 0 || card >= SND_CARDS)
|
||||
return -EINVAL;
|
||||
sprintf(filename, SND_FILE_PCM, card, device);
|
||||
if ((fd = open(filename, mode)) < 0)
|
||||
return -errno;
|
||||
if (ioctl(fd, SND_PCM_IOCTL_PVERSION, &ver) < 0) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
if (SND_PROTOCOL_UNCOMPATIBLE(ver, SND_PCM_VERSION_MAX)) {
|
||||
close(fd);
|
||||
return -SND_ERROR_UNCOMPATIBLE_VERSION;
|
||||
}
|
||||
pcm = (snd_pcm_t *) calloc(1, sizeof(snd_pcm_t));
|
||||
if (pcm == NULL) {
|
||||
close(fd);
|
||||
return -ENOMEM;
|
||||
}
|
||||
pcm->card = card;
|
||||
pcm->device = device;
|
||||
pcm->fd = fd;
|
||||
*handle = pcm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_close( void *handle )
|
||||
int snd_pcm_close(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
int res;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
res = close( pcm -> fd ) < 0 ? -errno : 0;
|
||||
free( pcm );
|
||||
return res;
|
||||
snd_pcm_t *pcm;
|
||||
int res;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
res = close(pcm->fd) < 0 ? -errno : 0;
|
||||
free(pcm);
|
||||
return res;
|
||||
}
|
||||
|
||||
int snd_pcm_file_descriptor( void *handle )
|
||||
int snd_pcm_file_descriptor(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
return pcm -> fd;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
return pcm->fd;
|
||||
}
|
||||
|
||||
int snd_pcm_block_mode( void *handle, int enable )
|
||||
int snd_pcm_block_mode(void *handle, int enable)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
long flags;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( fcntl( pcm -> fd, F_GETFL, &flags ) < 0 )
|
||||
return -errno;
|
||||
if ( enable )
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
if ( fcntl( pcm -> fd, F_SETFL, &flags ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
long flags;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (fcntl(pcm->fd, F_GETFL, &flags) < 0)
|
||||
return -errno;
|
||||
if (enable)
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
if (fcntl(pcm->fd, F_SETFL, &flags) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_info( void *handle, snd_pcm_info_t *info )
|
||||
int snd_pcm_info(void *handle, snd_pcm_info_t * info)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_INFO, info ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_info( void *handle, snd_pcm_playback_info_t *info )
|
||||
int snd_pcm_playback_info(void *handle, snd_pcm_playback_info_t * info)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_INFO, info ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_info( void *handle, snd_pcm_record_info_t *info )
|
||||
int snd_pcm_record_info(void *handle, snd_pcm_record_info_t * info)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_INFO, info ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_switches( void *handle )
|
||||
int snd_pcm_playback_switches(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
int result;
|
||||
snd_pcm_t *pcm;
|
||||
int result;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PSWITCHES, &result ) < 0 )
|
||||
return -errno;
|
||||
return result;
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCHES, &result) < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_switch( void *handle, const char *switch_id )
|
||||
int snd_pcm_playback_switch(void *handle, const char *switch_id)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_switch_t uswitch;
|
||||
int idx, switches, err;
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_switch_t uswitch;
|
||||
int idx, switches, err;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
/* bellow implementation isn't optimized for speed */
|
||||
/* info about switches should be cached in the snd_mixer_t structure */
|
||||
if ( (switches = snd_pcm_playback_switches( handle )) < 0 )
|
||||
return switches;
|
||||
for ( idx = 0; idx < switches; idx++ ) {
|
||||
if ( (err = snd_pcm_playback_switch_read( handle, idx, &uswitch )) < 0 )
|
||||
return err;
|
||||
if ( !strncmp( switch_id, uswitch.name, sizeof( uswitch.name ) ) )
|
||||
return idx;
|
||||
}
|
||||
return -EINVAL;
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
/* bellow implementation isn't optimized for speed */
|
||||
/* info about switches should be cached in the snd_mixer_t structure */
|
||||
if ((switches = snd_pcm_playback_switches(handle)) < 0)
|
||||
return switches;
|
||||
for (idx = 0; idx < switches; idx++) {
|
||||
if ((err = snd_pcm_playback_switch_read(handle, idx, &uswitch)) < 0)
|
||||
return err;
|
||||
if (!strncmp(switch_id, uswitch.name, sizeof(uswitch.name)))
|
||||
return idx;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_switch_read( void *handle, int switchn, snd_pcm_switch_t *data )
|
||||
int snd_pcm_playback_switch_read(void *handle, int switchn, snd_pcm_switch_t * data)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
data -> switchn = switchn;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PSWITCH_READ, data ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_switch_write( void *handle, int switchn, snd_pcm_switch_t *data )
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
data -> switchn = switchn;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PSWITCH_WRITE, data ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_switches( void *handle )
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
int result;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RSWITCHES, &result ) < 0 )
|
||||
return -errno;
|
||||
return result;
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
data->switchn = switchn;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_READ, data) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_switch( void *handle, const char *switch_id )
|
||||
int snd_pcm_playback_switch_write(void *handle, int switchn, snd_pcm_switch_t * data)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_switch_t uswitch;
|
||||
int idx, switches, err;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
/* bellow implementation isn't optimized for speed */
|
||||
/* info about switches should be cached in the snd_mixer_t structure */
|
||||
if ( (switches = snd_pcm_record_switches( handle )) < 0 )
|
||||
return switches;
|
||||
for ( idx = 0; idx < switches; idx++ ) {
|
||||
if ( (err = snd_pcm_record_switch_read( handle, idx, &uswitch )) < 0 )
|
||||
return err;
|
||||
if ( !strncmp( switch_id, uswitch.name, sizeof( uswitch.name ) ) )
|
||||
return idx;
|
||||
}
|
||||
return -EINVAL;
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
data->switchn = switchn;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_WRITE, data) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_switch_read( void *handle, int switchn, snd_pcm_switch_t *data )
|
||||
int snd_pcm_record_switches(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_t *pcm;
|
||||
int result;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
data -> switchn = switchn;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RSWITCH_READ, data ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_switch_write( void *handle, int switchn, snd_pcm_switch_t *data )
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
data -> switchn = switchn;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RSWITCH_WRITE, data ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_format( void *handle, snd_pcm_format_t *format )
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_FORMAT, format ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCHES, &result) < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
|
||||
int snd_pcm_record_format( void *handle, snd_pcm_format_t *format )
|
||||
int snd_pcm_record_switch(void *handle, const char *switch_id)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_FORMAT, format ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_switch_t uswitch;
|
||||
int idx, switches, err;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
/* bellow implementation isn't optimized for speed */
|
||||
/* info about switches should be cached in the snd_mixer_t structure */
|
||||
if ((switches = snd_pcm_record_switches(handle)) < 0)
|
||||
return switches;
|
||||
for (idx = 0; idx < switches; idx++) {
|
||||
if ((err = snd_pcm_record_switch_read(handle, idx, &uswitch)) < 0)
|
||||
return err;
|
||||
if (!strncmp(switch_id, uswitch.name, sizeof(uswitch.name)))
|
||||
return idx;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_params( void *handle, snd_pcm_playback_params_t *params )
|
||||
int snd_pcm_record_switch_read(void *handle, int switchn, snd_pcm_switch_t * data)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_PARAMS, params ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
data->switchn = switchn;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_READ, data) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_params( void *handle, snd_pcm_record_params_t *params )
|
||||
int snd_pcm_record_switch_write(void *handle, int switchn, snd_pcm_switch_t * data)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_PARAMS, params ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
data->switchn = switchn;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_WRITE, data) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_status( void *handle, snd_pcm_playback_status_t *status )
|
||||
int snd_pcm_playback_format(void *handle, snd_pcm_format_t * format)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_STATUS, status ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_FORMAT, format) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_status( void *handle, snd_pcm_record_status_t *status )
|
||||
int snd_pcm_record_format(void *handle, snd_pcm_format_t * format)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_STATUS, status ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_FORMAT, format) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_drain_playback( void *handle )
|
||||
int snd_pcm_playback_params(void *handle, snd_pcm_playback_params_t * params)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_DRAIN_PLAYBACK ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_PARAMS, params) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_flush_playback( void *handle )
|
||||
int snd_pcm_record_params(void *handle, snd_pcm_record_params_t * params)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_FLUSH_PLAYBACK ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_PARAMS, params) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_flush_record( void *handle )
|
||||
int snd_pcm_playback_status(void *handle, snd_pcm_playback_status_t * status)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_FLUSH_RECORD ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_STATUS, status) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_pause( void *handle, int enable )
|
||||
int snd_pcm_record_status(void *handle, snd_pcm_record_status_t * status)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_PAUSE, &enable ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_STATUS, status) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_time( void *handle, int enable )
|
||||
int snd_pcm_drain_playback(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_PLAYBACK_TIME, &enable ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_DRAIN_PLAYBACK) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_time( void *handle, int enable )
|
||||
int snd_pcm_flush_playback(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
if ( ioctl( pcm -> fd, SND_PCM_IOCTL_RECORD_TIME, &enable ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_FLUSH_PLAYBACK) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t snd_pcm_write( void *handle, const void *buffer, size_t size )
|
||||
int snd_pcm_flush_record(void *handle)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
ssize_t result;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
result = write( pcm -> fd, buffer, size );
|
||||
if ( result < 0 ) return -errno;
|
||||
return result;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_FLUSH_RECORD) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t snd_pcm_read( void *handle, void *buffer, size_t size )
|
||||
int snd_pcm_playback_pause(void *handle, int enable)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
ssize_t result;
|
||||
|
||||
pcm = (snd_pcm_t *)handle;
|
||||
if ( !pcm ) return -EINVAL;
|
||||
result = read( pcm -> fd, buffer, size );
|
||||
if ( result < 0 ) return -errno;
|
||||
return result;
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_PAUSE, &enable) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_playback_time(void *handle, int enable)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_PLAYBACK_TIME, &enable) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_record_time(void *handle, int enable)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
if (ioctl(pcm->fd, SND_PCM_IOCTL_RECORD_TIME, &enable) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t snd_pcm_write(void *handle, const void *buffer, size_t size)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
ssize_t result;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
result = write(pcm->fd, buffer, size);
|
||||
if (result < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
|
||||
ssize_t snd_pcm_read(void *handle, void *buffer, size_t size)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
ssize_t result;
|
||||
|
||||
pcm = (snd_pcm_t *) handle;
|
||||
if (!pcm)
|
||||
return -EINVAL;
|
||||
result = read(pcm->fd, buffer, size);
|
||||
if (result < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,114 +30,123 @@
|
|||
|
||||
#define SND_FILE_PCM_LB "/proc/asound/%i/pcm%i%s"
|
||||
#define SND_PCM_LB_VERSION_MAX SND_PROTOCOL_VERSION( 1, 0, 0 )
|
||||
|
||||
|
||||
typedef struct {
|
||||
int card;
|
||||
int device;
|
||||
int fd;
|
||||
int card;
|
||||
int device;
|
||||
int fd;
|
||||
} snd_pcm_loopback_t;
|
||||
|
||||
int snd_pcm_loopback_open( void **handle, int card, int device, int mode )
|
||||
{
|
||||
int fd, ver;
|
||||
char filename[32];
|
||||
snd_pcm_loopback_t *lb;
|
||||
|
||||
*handle = NULL;
|
||||
if ( card < 0 || card >= SND_CARDS ) return -EINVAL;
|
||||
sprintf( filename, SND_FILE_PCM_LB, card, device,
|
||||
mode == SND_PCM_LB_OPEN_RECORD ? "r" : "p" );
|
||||
if ( (fd = open( filename, mode )) < 0 ) return -errno;
|
||||
if ( ioctl( fd, SND_PCM_IOCTL_PVERSION, &ver ) < 0 ) {
|
||||
close( fd );
|
||||
return -errno;
|
||||
}
|
||||
if ( SND_PROTOCOL_UNCOMPATIBLE( ver, SND_PCM_LB_VERSION_MAX ) ) {
|
||||
close( fd );
|
||||
return -SND_ERROR_UNCOMPATIBLE_VERSION;
|
||||
}
|
||||
lb = (snd_pcm_loopback_t *)calloc( 1, sizeof( snd_pcm_loopback_t ) );
|
||||
if ( lb == NULL ) {
|
||||
close( fd );
|
||||
return -ENOMEM;
|
||||
}
|
||||
lb -> card = card;
|
||||
lb -> device = device;
|
||||
lb -> fd = fd;
|
||||
*handle = lb;
|
||||
return 0;
|
||||
int snd_pcm_loopback_open(void **handle, int card, int device, int mode)
|
||||
{
|
||||
int fd, ver;
|
||||
char filename[32];
|
||||
snd_pcm_loopback_t *lb;
|
||||
|
||||
*handle = NULL;
|
||||
if (card < 0 || card >= SND_CARDS)
|
||||
return -EINVAL;
|
||||
sprintf(filename, SND_FILE_PCM_LB, card, device,
|
||||
mode == SND_PCM_LB_OPEN_RECORD ? "r" : "p");
|
||||
if ((fd = open(filename, mode)) < 0)
|
||||
return -errno;
|
||||
if (ioctl(fd, SND_PCM_IOCTL_PVERSION, &ver) < 0) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
if (SND_PROTOCOL_UNCOMPATIBLE(ver, SND_PCM_LB_VERSION_MAX)) {
|
||||
close(fd);
|
||||
return -SND_ERROR_UNCOMPATIBLE_VERSION;
|
||||
}
|
||||
lb = (snd_pcm_loopback_t *) calloc(1, sizeof(snd_pcm_loopback_t));
|
||||
if (lb == NULL) {
|
||||
close(fd);
|
||||
return -ENOMEM;
|
||||
}
|
||||
lb->card = card;
|
||||
lb->device = device;
|
||||
lb->fd = fd;
|
||||
*handle = lb;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_loopback_close( void *handle )
|
||||
int snd_pcm_loopback_close(void *handle)
|
||||
{
|
||||
snd_pcm_loopback_t *lb;
|
||||
int res;
|
||||
|
||||
lb = (snd_pcm_loopback_t *)handle;
|
||||
if ( !lb ) return -EINVAL;
|
||||
res = close( lb -> fd ) < 0 ? -errno : 0;
|
||||
free( lb );
|
||||
return res;
|
||||
snd_pcm_loopback_t *lb;
|
||||
int res;
|
||||
|
||||
lb = (snd_pcm_loopback_t *) handle;
|
||||
if (!lb)
|
||||
return -EINVAL;
|
||||
res = close(lb->fd) < 0 ? -errno : 0;
|
||||
free(lb);
|
||||
return res;
|
||||
}
|
||||
|
||||
int snd_pcm_loopback_file_descriptor( void *handle )
|
||||
int snd_pcm_loopback_file_descriptor(void *handle)
|
||||
{
|
||||
snd_pcm_loopback_t *lb;
|
||||
|
||||
lb = (snd_pcm_loopback_t *)handle;
|
||||
if ( !lb ) return -EINVAL;
|
||||
return lb -> fd;
|
||||
snd_pcm_loopback_t *lb;
|
||||
|
||||
lb = (snd_pcm_loopback_t *) handle;
|
||||
if (!lb)
|
||||
return -EINVAL;
|
||||
return lb->fd;
|
||||
}
|
||||
|
||||
int snd_pcm_loopback_block_mode( void *handle, int enable )
|
||||
int snd_pcm_loopback_block_mode(void *handle, int enable)
|
||||
{
|
||||
snd_pcm_loopback_t *lb;
|
||||
long flags;
|
||||
|
||||
lb = (snd_pcm_loopback_t *)handle;
|
||||
if ( !lb ) return -EINVAL;
|
||||
if ( fcntl( lb -> fd, F_GETFL, &flags ) < 0 )
|
||||
return -errno;
|
||||
if ( enable )
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
if ( fcntl( lb -> fd, F_SETFL, &flags ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_loopback_t *lb;
|
||||
long flags;
|
||||
|
||||
lb = (snd_pcm_loopback_t *) handle;
|
||||
if (!lb)
|
||||
return -EINVAL;
|
||||
if (fcntl(lb->fd, F_GETFL, &flags) < 0)
|
||||
return -errno;
|
||||
if (enable)
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
if (fcntl(lb->fd, F_SETFL, &flags) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_loopback_stream_mode( void *handle, int mode )
|
||||
int snd_pcm_loopback_stream_mode(void *handle, int mode)
|
||||
{
|
||||
snd_pcm_loopback_t *lb;
|
||||
long lmode = mode;
|
||||
|
||||
lb = (snd_pcm_loopback_t *)handle;
|
||||
if ( !lb ) return -EINVAL;
|
||||
if ( ioctl( lb -> fd, SND_PCM_LB_IOCTL_STREAM_MODE, &lmode ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_loopback_t *lb;
|
||||
long lmode = mode;
|
||||
|
||||
lb = (snd_pcm_loopback_t *) handle;
|
||||
if (!lb)
|
||||
return -EINVAL;
|
||||
if (ioctl(lb->fd, SND_PCM_LB_IOCTL_STREAM_MODE, &lmode) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_pcm_loopback_format( void *handle, snd_pcm_format_t *format )
|
||||
int snd_pcm_loopback_format(void *handle, snd_pcm_format_t * format)
|
||||
{
|
||||
snd_pcm_loopback_t *lb;
|
||||
|
||||
lb = (snd_pcm_loopback_t *)handle;
|
||||
if ( !lb ) return -EINVAL;
|
||||
if ( ioctl( lb -> fd, SND_PCM_LB_IOCTL_FORMAT, format ) < 0 )
|
||||
return -errno;
|
||||
return 0;
|
||||
snd_pcm_loopback_t *lb;
|
||||
|
||||
lb = (snd_pcm_loopback_t *) handle;
|
||||
if (!lb)
|
||||
return -EINVAL;
|
||||
if (ioctl(lb->fd, SND_PCM_LB_IOCTL_FORMAT, format) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t snd_pcm_loopback_read( void *handle, void *buffer, size_t size )
|
||||
ssize_t snd_pcm_loopback_read(void *handle, void *buffer, size_t size)
|
||||
{
|
||||
snd_pcm_loopback_t *lb;
|
||||
ssize_t result;
|
||||
|
||||
lb = (snd_pcm_loopback_t *)handle;
|
||||
if ( !lb ) return -EINVAL;
|
||||
result = read( lb -> fd, buffer, size );
|
||||
if ( result < 0 ) return -errno;
|
||||
return result;
|
||||
snd_pcm_loopback_t *lb;
|
||||
ssize_t result;
|
||||
|
||||
lb = (snd_pcm_loopback_t *) handle;
|
||||
if (!lb)
|
||||
return -EINVAL;
|
||||
result = read(lb->fd, buffer, size);
|
||||
if (result < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue