2002-01-12 10:52:42 +00:00
|
|
|
/**
|
|
|
|
|
* \file pcm/pcm_hw.c
|
|
|
|
|
* \ingroup PCM_Plugins
|
2002-01-13 11:11:42 +00:00
|
|
|
* \brief PCM HW Plugin Interface
|
2002-01-12 10:52:42 +00:00
|
|
|
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
|
|
|
* \author Jaroslav Kysela <perex@suse.cz>
|
|
|
|
|
* \date 2000-2001
|
|
|
|
|
*/
|
2000-05-08 18:53:38 +00:00
|
|
|
/*
|
|
|
|
|
* PCM - Hardware
|
|
|
|
|
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
2000-05-08 18:53:38 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2000-05-08 18:53:38 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2000-05-08 18:53:38 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2001-12-30 09:22:54 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-05-08 18:53:38 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2002-04-23 15:51:29 +00:00
|
|
|
#include <stddef.h>
|
2000-05-08 18:53:38 +00:00
|
|
|
#include <unistd.h>
|
2000-10-11 12:37:27 +00:00
|
|
|
#include <signal.h>
|
2000-05-08 18:53:38 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <sys/mman.h>
|
2000-10-14 19:43:14 +00:00
|
|
|
#include <sys/shm.h>
|
2000-05-08 18:53:38 +00:00
|
|
|
#include "pcm_local.h"
|
2000-11-20 20:10:46 +00:00
|
|
|
#include "../control/control_local.h"
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2002-03-11 13:18:46 +00:00
|
|
|
//#define DEBUG_RW /* use to debug readi/writei/readn/writen */
|
|
|
|
|
//#define DEBUG_MMAP /* debug mmap_commit */
|
|
|
|
|
|
2001-10-24 14:14:11 +00:00
|
|
|
#ifndef PIC
|
|
|
|
|
/* entry for static linking */
|
|
|
|
|
const char *_snd_module_pcm_hw = "";
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-01-12 10:52:42 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
|
|
|
|
|
2000-10-11 12:37:27 +00:00
|
|
|
#ifndef F_SETSIG
|
|
|
|
|
#define F_SETSIG 10
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-06-26 02:04:11 +00:00
|
|
|
/*
|
|
|
|
|
* Compatibility
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct sndrv_pcm_hw_params_old {
|
|
|
|
|
unsigned int flags;
|
|
|
|
|
unsigned int masks[SNDRV_PCM_HW_PARAM_SUBFORMAT -
|
|
|
|
|
SNDRV_PCM_HW_PARAM_ACCESS + 1];
|
|
|
|
|
struct sndrv_interval intervals[SNDRV_PCM_HW_PARAM_TICK_TIME -
|
|
|
|
|
SNDRV_PCM_HW_PARAM_SAMPLE_BITS + 1];
|
|
|
|
|
unsigned int rmask;
|
|
|
|
|
unsigned int cmask;
|
|
|
|
|
unsigned int info;
|
|
|
|
|
unsigned int msbits;
|
|
|
|
|
unsigned int rate_num;
|
|
|
|
|
unsigned int rate_den;
|
|
|
|
|
sndrv_pcm_uframes_t fifo_size;
|
|
|
|
|
unsigned char reserved[64];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define SND_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct sndrv_pcm_hw_params_old)
|
|
|
|
|
#define SND_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct sndrv_pcm_hw_params_old)
|
|
|
|
|
|
|
|
|
|
static int use_old_hw_params_ioctl(int fd, unsigned int cmd, snd_pcm_hw_params_t *params);
|
2002-10-11 18:39:24 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_avail_update(snd_pcm_t *pcm);
|
2002-06-26 02:04:11 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2000-06-01 21:58:25 +00:00
|
|
|
typedef struct {
|
2002-02-21 08:45:19 +00:00
|
|
|
int version;
|
2000-06-01 21:58:25 +00:00
|
|
|
int fd;
|
2000-07-17 15:33:29 +00:00
|
|
|
int card, device, subdevice;
|
2001-12-11 15:07:10 +00:00
|
|
|
int mmap_emulation;
|
2004-05-22 10:14:32 +00:00
|
|
|
int sync_ptr_ioctl;
|
2002-04-23 15:51:29 +00:00
|
|
|
volatile struct sndrv_pcm_mmap_status * mmap_status;
|
2001-01-30 16:51:26 +00:00
|
|
|
struct sndrv_pcm_mmap_control *mmap_control;
|
2004-05-22 10:14:32 +00:00
|
|
|
struct sndrv_pcm_sync_ptr *sync_ptr;
|
2001-12-11 15:07:10 +00:00
|
|
|
int shadow_appl_ptr: 1,
|
|
|
|
|
avail_update_flag: 1,
|
|
|
|
|
mmap_shm: 1;
|
2001-12-08 21:00:21 +00:00
|
|
|
snd_pcm_uframes_t appl_ptr;
|
2000-06-01 21:58:25 +00:00
|
|
|
} snd_pcm_hw_t;
|
|
|
|
|
|
2001-01-29 14:27:53 +00:00
|
|
|
#define SNDRV_FILE_PCM_STREAM_PLAYBACK "/dev/snd/pcmC%iD%ip"
|
|
|
|
|
#define SNDRV_FILE_PCM_STREAM_CAPTURE "/dev/snd/pcmC%iD%ic"
|
2004-03-05 08:05:21 +00:00
|
|
|
#define SNDRV_PCM_VERSION_MAX SNDRV_PROTOCOL_VERSION(2, 0, 5)
|
2001-12-08 21:00:21 +00:00
|
|
|
|
|
|
|
|
/* update appl_ptr with driver */
|
|
|
|
|
#define UPDATE_SHADOW_PTR(hw) \
|
|
|
|
|
do { if (hw->shadow_appl_ptr && !hw->avail_update_flag) \
|
|
|
|
|
hw->appl_ptr = hw->mmap_control->appl_ptr; } while (0)
|
2002-02-21 15:01:34 +00:00
|
|
|
#define FAST_PCM_STATE(hw) \
|
|
|
|
|
((enum sndrv_pcm_state) (hw)->mmap_status->state)
|
2003-02-28 17:23:28 +00:00
|
|
|
#define FAST_PCM_TSTAMP(hw) \
|
|
|
|
|
((hw)->mmap_status->tstamp)
|
2002-01-12 10:52:42 +00:00
|
|
|
#endif /* DOC_HIDDEN */
|
|
|
|
|
|
2003-02-28 17:23:28 +00:00
|
|
|
struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm)
|
|
|
|
|
{
|
2003-03-01 20:32:02 +00:00
|
|
|
struct timespec res;
|
2003-02-28 17:23:28 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-03-01 20:32:02 +00:00
|
|
|
res = FAST_PCM_TSTAMP(hw);
|
|
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 5) > hw->version)
|
|
|
|
|
res.tv_nsec *= 1000L;
|
|
|
|
|
return res;
|
2003-02-28 17:23:28 +00:00
|
|
|
}
|
|
|
|
|
|
2004-05-22 10:14:32 +00:00
|
|
|
static int sync_ptr1(snd_pcm_hw_t *hw, unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
hw->sync_ptr->flags = flags;
|
|
|
|
|
err = ioctl((hw)->fd, SNDRV_PCM_IOCTL_SYNC_PTR, (hw)->sync_ptr);
|
|
|
|
|
if (err < 0) {
|
2004-09-28 10:54:05 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_SYNC_PTR failed");
|
2004-05-22 10:14:32 +00:00
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int sync_ptr(snd_pcm_hw_t *hw, unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
return hw->sync_ptr ? sync_ptr1(hw, flags) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_hw_nonblock(snd_pcm_t *pcm, int nonblock)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
|
|
|
|
long flags;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2000-10-11 12:37:27 +00:00
|
|
|
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("F_GETFL failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
if (nonblock)
|
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
|
else
|
|
|
|
|
flags &= ~O_NONBLOCK;
|
2000-10-11 12:37:27 +00:00
|
|
|
if (fcntl(fd, F_SETFL, flags) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("F_SETFL for O_NONBLOCK failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_hw_async(snd_pcm_t *pcm, int sig, pid_t pid)
|
|
|
|
|
{
|
|
|
|
|
long flags;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2000-10-11 12:37:27 +00:00
|
|
|
|
|
|
|
|
if ((flags = fcntl(fd, F_GETFL)) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("F_GETFL failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
|
|
|
|
if (sig >= 0)
|
|
|
|
|
flags |= O_ASYNC;
|
|
|
|
|
else
|
|
|
|
|
flags &= ~O_ASYNC;
|
|
|
|
|
if (fcntl(fd, F_SETFL, flags) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("F_SETFL for O_ASYNC failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
|
|
|
|
if (sig < 0)
|
|
|
|
|
return 0;
|
2001-10-18 12:33:45 +00:00
|
|
|
if (fcntl(fd, F_SETSIG, (long)sig) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("F_SETSIG failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2001-10-18 12:33:45 +00:00
|
|
|
if (fcntl(fd, F_SETOWN, (long)pid) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("F_SETOWN failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-21 20:44:10 +00:00
|
|
|
static int snd_pcm_hw_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, info) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_INFO failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-26 02:04:11 +00:00
|
|
|
static inline int hw_refine_call(snd_pcm_hw_t *pcm_hw, snd_pcm_hw_params_t *params)
|
|
|
|
|
{
|
|
|
|
|
/* check for new hw_params structure; it's available from 2.0.2 version of PCM API */
|
|
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 2) <= pcm_hw->version)
|
|
|
|
|
return ioctl(pcm_hw->fd, SNDRV_PCM_IOCTL_HW_REFINE, params);
|
|
|
|
|
return use_old_hw_params_ioctl(pcm_hw->fd, SND_PCM_IOCTL_HW_REFINE_OLD, params);
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-21 20:44:10 +00:00
|
|
|
static int snd_pcm_hw_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
2000-07-01 10:38:29 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2001-12-11 15:07:10 +00:00
|
|
|
if (hw->mmap_emulation) {
|
|
|
|
|
int err = 0;
|
|
|
|
|
snd_pcm_access_mask_t oldmask = *snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS);
|
2002-06-26 02:04:11 +00:00
|
|
|
snd_pcm_access_mask_t mask;
|
2001-12-11 15:07:10 +00:00
|
|
|
const snd_mask_t *pmask;
|
|
|
|
|
|
2002-06-26 02:04:11 +00:00
|
|
|
snd_mask_empty(&mask);
|
|
|
|
|
if (hw_refine_call(hw, params) < 0)
|
2001-12-11 15:07:10 +00:00
|
|
|
err = -errno;
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_hw_params_t new = *params;
|
|
|
|
|
|
2003-02-08 09:26:43 +00:00
|
|
|
if (!(params->rmask & (1<<SND_PCM_HW_PARAM_ACCESS)))
|
|
|
|
|
return err;
|
2001-12-11 15:07:10 +00:00
|
|
|
if (snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_MMAP_INTERLEAVED) &&
|
|
|
|
|
!snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_RW_INTERLEAVED))
|
|
|
|
|
snd_pcm_access_mask_set(&mask, SND_PCM_ACCESS_RW_INTERLEAVED);
|
|
|
|
|
if (snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED) &&
|
|
|
|
|
!snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_RW_NONINTERLEAVED))
|
|
|
|
|
snd_pcm_access_mask_set(&mask, SND_PCM_ACCESS_RW_NONINTERLEAVED);
|
|
|
|
|
if (snd_pcm_access_mask_empty(&mask))
|
|
|
|
|
return err;
|
|
|
|
|
pmask = snd_pcm_hw_param_get_mask(&new, SND_PCM_HW_PARAM_ACCESS);
|
2002-06-26 02:04:11 +00:00
|
|
|
*(snd_mask_t *)pmask = mask;
|
|
|
|
|
if (hw_refine_call(hw, &new) < 0)
|
2001-12-11 15:07:10 +00:00
|
|
|
return -errno;
|
|
|
|
|
*params = new;
|
|
|
|
|
}
|
|
|
|
|
pmask = snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS);
|
|
|
|
|
if (snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_MMAP_INTERLEAVED) ||
|
|
|
|
|
snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED) ||
|
|
|
|
|
snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_MMAP_COMPLEX))
|
|
|
|
|
return 0;
|
|
|
|
|
if (snd_pcm_access_mask_test(&mask, SND_PCM_ACCESS_RW_INTERLEAVED)) {
|
|
|
|
|
if (snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_RW_INTERLEAVED))
|
|
|
|
|
snd_pcm_access_mask_set((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_MMAP_INTERLEAVED);
|
|
|
|
|
snd_pcm_access_mask_reset((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_RW_INTERLEAVED);
|
2003-02-08 09:26:43 +00:00
|
|
|
params->cmask |= 1<<SND_PCM_HW_PARAM_ACCESS;
|
2001-12-11 15:07:10 +00:00
|
|
|
}
|
|
|
|
|
if (snd_pcm_access_mask_test(&mask, SND_PCM_ACCESS_RW_NONINTERLEAVED)) {
|
|
|
|
|
if (snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_RW_NONINTERLEAVED))
|
|
|
|
|
snd_pcm_access_mask_set((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
|
|
|
|
|
snd_pcm_access_mask_reset((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_RW_NONINTERLEAVED);
|
2003-02-08 09:26:43 +00:00
|
|
|
params->cmask |= 1<<SND_PCM_HW_PARAM_ACCESS;
|
2001-12-11 15:07:10 +00:00
|
|
|
}
|
|
|
|
|
if (snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_MMAP_INTERLEAVED)) {
|
|
|
|
|
if (snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_RW_INTERLEAVED)) {
|
2003-02-08 09:26:43 +00:00
|
|
|
if (snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_RW_INTERLEAVED)) {
|
2001-12-11 15:07:10 +00:00
|
|
|
snd_pcm_access_mask_set((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_MMAP_INTERLEAVED);
|
2003-02-08 09:26:43 +00:00
|
|
|
params->cmask |= 1<<SND_PCM_HW_PARAM_ACCESS;
|
|
|
|
|
}
|
2001-12-11 15:07:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED)) {
|
|
|
|
|
if (snd_pcm_access_mask_test(&oldmask, SND_PCM_ACCESS_RW_NONINTERLEAVED)) {
|
2003-02-08 09:26:43 +00:00
|
|
|
if (snd_pcm_access_mask_test(pmask, SND_PCM_ACCESS_RW_NONINTERLEAVED)) {
|
2001-12-11 15:07:10 +00:00
|
|
|
snd_pcm_access_mask_set((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
|
2003-02-08 09:26:43 +00:00
|
|
|
params->cmask |= 1<<SND_PCM_HW_PARAM_ACCESS;
|
|
|
|
|
}
|
2001-12-11 15:07:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-06-26 02:04:11 +00:00
|
|
|
if (hw_refine_call(hw, params) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
// SYSMSG("SNDRV_PCM_IOCTL_HW_REFINE failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2001-12-11 15:07:10 +00:00
|
|
|
}
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2001-12-11 15:07:10 +00:00
|
|
|
|
2000-07-01 10:38:29 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-26 02:04:11 +00:00
|
|
|
static inline int hw_params_call(snd_pcm_hw_t *pcm_hw, snd_pcm_hw_params_t *params)
|
|
|
|
|
{
|
|
|
|
|
/* check for new hw_params structure; it's available from 2.0.2 version of PCM API */
|
|
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 2) <= pcm_hw->version)
|
|
|
|
|
return ioctl(pcm_hw->fd, SNDRV_PCM_IOCTL_HW_PARAMS, params);
|
|
|
|
|
return use_old_hw_params_ioctl(pcm_hw->fd, SND_PCM_IOCTL_HW_PARAMS_OLD, params);
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-20 20:10:46 +00:00
|
|
|
static int snd_pcm_hw_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2001-12-11 15:07:10 +00:00
|
|
|
if (hw->mmap_emulation) {
|
|
|
|
|
snd_pcm_hw_params_t old = *params;
|
2002-06-26 02:04:11 +00:00
|
|
|
if (hw_params_call(hw, params) < 0) {
|
2002-09-09 19:47:50 +00:00
|
|
|
snd_pcm_access_t access;
|
2001-12-11 15:07:10 +00:00
|
|
|
snd_pcm_access_mask_t oldmask;
|
|
|
|
|
const snd_mask_t *pmask;
|
|
|
|
|
|
|
|
|
|
*params = old;
|
|
|
|
|
pmask = snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS);
|
|
|
|
|
oldmask = *(snd_pcm_access_mask_t *)pmask;
|
2002-09-17 12:33:05 +00:00
|
|
|
if (INTERNAL(snd_pcm_hw_params_get_access)(params, &access) < 0)
|
2002-09-09 19:47:50 +00:00
|
|
|
goto _err;
|
|
|
|
|
switch (access) {
|
2001-12-11 15:07:10 +00:00
|
|
|
case SND_PCM_ACCESS_MMAP_INTERLEAVED:
|
|
|
|
|
snd_pcm_access_mask_reset((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_MMAP_INTERLEAVED);
|
|
|
|
|
snd_pcm_access_mask_set((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_RW_INTERLEAVED);
|
|
|
|
|
break;
|
|
|
|
|
case SND_PCM_ACCESS_MMAP_NONINTERLEAVED:
|
|
|
|
|
snd_pcm_access_mask_reset((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED);
|
|
|
|
|
snd_pcm_access_mask_set((snd_pcm_access_mask_t *)pmask, SND_PCM_ACCESS_RW_NONINTERLEAVED);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
goto _err;
|
|
|
|
|
}
|
2002-06-26 02:04:11 +00:00
|
|
|
if (hw_params_call(hw, params) < 0)
|
2001-12-11 15:07:10 +00:00
|
|
|
goto _err;
|
|
|
|
|
hw->mmap_shm = 1;
|
|
|
|
|
*(snd_pcm_access_mask_t *)pmask = oldmask;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-06-26 02:04:11 +00:00
|
|
|
if (hw_params_call(hw, params) < 0) {
|
2001-12-11 15:07:10 +00:00
|
|
|
_err:
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_HW_PARAMS failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2001-12-11 15:07:10 +00:00
|
|
|
}
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2004-05-22 10:14:32 +00:00
|
|
|
err = sync_ptr(hw, 0);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2001-12-08 21:00:21 +00:00
|
|
|
if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
|
2001-12-11 15:07:10 +00:00
|
|
|
if (hw->mmap_shm) {
|
2001-12-08 21:00:21 +00:00
|
|
|
hw->shadow_appl_ptr = 1;
|
|
|
|
|
hw->appl_ptr = 0;
|
2002-04-23 15:51:29 +00:00
|
|
|
snd_pcm_set_appl_ptr(pcm, &hw->appl_ptr, -1, 0);
|
2001-12-08 21:00:21 +00:00
|
|
|
} else {
|
|
|
|
|
hw->shadow_appl_ptr = 0;
|
2002-04-23 15:51:29 +00:00
|
|
|
snd_pcm_set_appl_ptr(pcm, &hw->mmap_control->appl_ptr, hw->fd, SNDRV_PCM_MMAP_OFFSET_CONTROL);
|
2001-12-08 21:00:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-19 13:10:50 +00:00
|
|
|
static int snd_pcm_hw_hw_free(snd_pcm_t *pcm)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_HW_FREE) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_HW_FREE failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2001-01-19 13:10:50 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-20 20:10:46 +00:00
|
|
|
static int snd_pcm_hw_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-04-19 21:18:23 +00:00
|
|
|
if ((snd_pcm_tstamp_t) params->tstamp_mode == pcm->tstamp_mode &&
|
2001-01-15 11:06:53 +00:00
|
|
|
params->period_step == pcm->period_step &&
|
|
|
|
|
params->sleep_min == pcm->sleep_min &&
|
2000-12-29 15:00:53 +00:00
|
|
|
params->xfer_align == pcm->xfer_align &&
|
2001-04-19 21:18:23 +00:00
|
|
|
params->start_threshold == pcm->start_threshold &&
|
|
|
|
|
params->stop_threshold == pcm->stop_threshold &&
|
2000-12-29 15:00:53 +00:00
|
|
|
params->silence_threshold == pcm->silence_threshold &&
|
|
|
|
|
params->silence_size == pcm->silence_size) {
|
|
|
|
|
hw->mmap_control->avail_min = params->avail_min;
|
2004-05-22 10:14:32 +00:00
|
|
|
return sync_ptr(hw, 0);
|
2000-12-29 15:00:53 +00:00
|
|
|
}
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_SW_PARAMS, params) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_SW_PARAMS failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2004-05-22 10:14:32 +00:00
|
|
|
hw->mmap_control->avail_min = params->avail_min;
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-20 20:10:46 +00:00
|
|
|
static int snd_pcm_hw_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t * info)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2001-01-31 17:26:56 +00:00
|
|
|
struct sndrv_pcm_channel_info i;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-01-31 17:26:56 +00:00
|
|
|
i.channel = info->channel;
|
|
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_CHANNEL_INFO, &i) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_CHANNEL_INFO failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2001-01-31 17:26:56 +00:00
|
|
|
info->channel = i.channel;
|
2001-12-11 15:07:10 +00:00
|
|
|
if (!hw->mmap_shm) {
|
2000-11-20 20:10:46 +00:00
|
|
|
info->addr = 0;
|
2001-01-31 17:26:56 +00:00
|
|
|
info->first = i.first;
|
|
|
|
|
info->step = i.step;
|
2000-11-20 20:10:46 +00:00
|
|
|
info->type = SND_PCM_AREA_MMAP;
|
|
|
|
|
info->u.mmap.fd = fd;
|
2001-01-31 17:26:56 +00:00
|
|
|
info->u.mmap.offset = i.offset;
|
2000-10-14 10:31:34 +00:00
|
|
|
return 0;
|
2000-10-07 16:59:48 +00:00
|
|
|
}
|
2003-04-23 12:41:55 +00:00
|
|
|
return snd_pcm_channel_info_shm(pcm, info, -1);
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_hw_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_STATUS, status) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_STATUS failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2003-03-01 20:32:02 +00:00
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 5) > hw->version) {
|
|
|
|
|
status->tstamp.tv_nsec *= 1000L;
|
|
|
|
|
status->trigger_tstamp.tv_nsec *= 1000L;
|
|
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-02-04 17:03:17 +00:00
|
|
|
static snd_pcm_state_t snd_pcm_hw_state(snd_pcm_t *pcm)
|
2000-05-09 10:46:43 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2004-05-24 18:44:04 +00:00
|
|
|
int err = sync_ptr(hw, 0);
|
2004-05-22 10:14:32 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2001-02-04 17:03:17 +00:00
|
|
|
return (snd_pcm_state_t) hw->mmap_status->state;
|
2000-06-01 21:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
static int snd_pcm_hw_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
|
2000-06-01 21:58:25 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2004-05-22 10:14:32 +00:00
|
|
|
if (hw->sync_ptr) {
|
|
|
|
|
err = sync_ptr1(hw, SNDRV_PCM_SYNC_PTR_HWSYNC);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
switch (FAST_PCM_STATE(hw)) {
|
|
|
|
|
case SNDRV_PCM_STATE_RUNNING:
|
|
|
|
|
case SNDRV_PCM_STATE_DRAINING:
|
|
|
|
|
case SNDRV_PCM_STATE_PAUSED:
|
|
|
|
|
case SNDRV_PCM_STATE_PREPARED:
|
|
|
|
|
case SNDRV_PCM_STATE_SUSPENDED:
|
|
|
|
|
break;
|
|
|
|
|
case SNDRV_PCM_STATE_XRUN:
|
|
|
|
|
return -EPIPE;
|
|
|
|
|
default:
|
|
|
|
|
return -EBADFD;
|
|
|
|
|
}
|
|
|
|
|
if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
|
|
|
|
|
*delayp = snd_pcm_mmap_playback_hw_avail(pcm);
|
|
|
|
|
else
|
|
|
|
|
*delayp = snd_pcm_mmap_capture_avail(pcm);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_DELAY, delayp) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_DELAY failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
return 0;
|
2000-05-09 10:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
2002-10-12 11:49:53 +00:00
|
|
|
static int snd_pcm_hw_hwsync(snd_pcm_t *pcm)
|
2002-10-11 18:39:24 +00:00
|
|
|
{
|
|
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2002-10-11 18:39:24 +00:00
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 3) <= hw->version) {
|
2004-05-22 10:14:32 +00:00
|
|
|
if (hw->sync_ptr) {
|
|
|
|
|
err = sync_ptr1(hw, SNDRV_PCM_SYNC_PTR_HWSYNC);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
} else {
|
|
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_HWSYNC) < 0) {
|
|
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_HWSYNC failed");
|
2004-05-22 10:14:32 +00:00
|
|
|
return err;
|
|
|
|
|
}
|
2002-10-11 18:39:24 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
snd_pcm_sframes_t delay;
|
|
|
|
|
int err = snd_pcm_hw_delay(pcm, &delay);
|
|
|
|
|
if (err < 0) {
|
2004-05-22 10:14:32 +00:00
|
|
|
switch (FAST_PCM_STATE(hw)) {
|
2002-10-12 11:49:53 +00:00
|
|
|
case SND_PCM_STATE_PREPARED:
|
|
|
|
|
case SND_PCM_STATE_SUSPENDED:
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2002-10-11 18:39:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_hw_prepare(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_PREPARE) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_PREPARE failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2004-11-16 15:05:49 +00:00
|
|
|
return sync_ptr(hw, SNDRV_PCM_SYNC_PTR_APPL);
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-24 17:08:03 +00:00
|
|
|
static int snd_pcm_hw_reset(snd_pcm_t *pcm)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_RESET) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_RESET failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-11-24 17:08:03 +00:00
|
|
|
}
|
2004-11-16 15:05:49 +00:00
|
|
|
return sync_ptr(hw, SNDRV_PCM_SYNC_PTR_APPL);
|
2000-11-24 17:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static int snd_pcm_hw_start(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2000-11-22 14:27:37 +00:00
|
|
|
#if 0
|
2000-11-20 20:10:46 +00:00
|
|
|
assert(pcm->stream != SND_PCM_STREAM_PLAYBACK ||
|
|
|
|
|
snd_pcm_mmap_playback_hw_avail(pcm) > 0);
|
2000-11-22 14:27:37 +00:00
|
|
|
#endif
|
2005-05-13 14:14:10 +00:00
|
|
|
sync_ptr(hw, 0);
|
2003-02-23 19:48:08 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_START) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_START failed");
|
2001-11-24 11:32:42 +00:00
|
|
|
#if 0
|
2003-02-23 20:00:07 +00:00
|
|
|
if (err == -EBADFD)
|
2001-11-24 11:32:42 +00:00
|
|
|
SNDERR("PCM state = %s", snd_pcm_state_name(snd_pcm_hw_state(pcm)));
|
|
|
|
|
#endif
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-02 06:59:59 +00:00
|
|
|
static int snd_pcm_hw_drop(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2003-02-23 19:48:08 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_DROP) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_DROP failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-29 20:49:18 +00:00
|
|
|
static int snd_pcm_hw_drain(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2003-02-23 19:48:08 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_DRAIN) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_DRAIN failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_hw_pause(snd_pcm_t *pcm, int enable)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2003-02-23 19:48:08 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_PAUSE, enable) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_PAUSE failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
2000-05-29 19:53:30 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2003-02-23 19:48:08 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_REWIND, &frames) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_REWIND failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-09-26 09:46:05 +00:00
|
|
|
}
|
2001-04-02 16:35:31 +00:00
|
|
|
return frames;
|
2000-05-29 19:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-22 17:19:02 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
|
|
|
|
{
|
|
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2003-02-23 19:48:08 +00:00
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 4) <= hw->version) {
|
2003-03-01 20:32:02 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_FORWARD, &frames) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_FORWARD failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2003-02-23 19:48:08 +00:00
|
|
|
}
|
|
|
|
|
return frames;
|
|
|
|
|
} else {
|
|
|
|
|
snd_pcm_sframes_t avail;
|
|
|
|
|
|
2004-05-22 10:14:32 +00:00
|
|
|
err = sync_ptr(hw, SNDRV_PCM_SYNC_PTR_HWSYNC);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2003-02-23 19:48:08 +00:00
|
|
|
switch (FAST_PCM_STATE(hw)) {
|
|
|
|
|
case SNDRV_PCM_STATE_RUNNING:
|
|
|
|
|
case SNDRV_PCM_STATE_DRAINING:
|
|
|
|
|
case SNDRV_PCM_STATE_PAUSED:
|
|
|
|
|
case SNDRV_PCM_STATE_PREPARED:
|
|
|
|
|
break;
|
|
|
|
|
case SNDRV_PCM_STATE_XRUN:
|
|
|
|
|
return -EPIPE;
|
|
|
|
|
default:
|
|
|
|
|
return -EBADFD;
|
|
|
|
|
}
|
|
|
|
|
avail = snd_pcm_mmap_avail(pcm);
|
|
|
|
|
if (avail < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
if (frames > (snd_pcm_uframes_t)avail)
|
|
|
|
|
frames = avail;
|
|
|
|
|
snd_pcm_mmap_appl_forward(pcm, frames);
|
2004-05-22 10:14:32 +00:00
|
|
|
err = sync_ptr(hw, 0);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2003-02-23 19:48:08 +00:00
|
|
|
return frames;
|
2003-02-22 17:19:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-26 13:57:04 +00:00
|
|
|
static int snd_pcm_hw_resume(snd_pcm_t *pcm)
|
|
|
|
|
{
|
|
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int fd = hw->fd, err;
|
2001-09-26 13:57:04 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_RESUME) < 0) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_RESUME failed");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2001-09-26 13:57:04 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-20 18:37:13 +00:00
|
|
|
static int snd_pcm_hw_link_fd(snd_pcm_t *pcm, int *fds, int count, int (**failed)(snd_pcm_t *, int))
|
2005-01-20 15:07:51 +00:00
|
|
|
{
|
|
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
|
|
|
|
|
2005-01-20 18:37:13 +00:00
|
|
|
if (count < 1)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
*failed = NULL;
|
|
|
|
|
fds[0] = hw->fd;
|
|
|
|
|
return 1;
|
2005-01-20 15:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_hw_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
|
|
|
|
|
{
|
|
|
|
|
snd_pcm_hw_t *hw = pcm1->private_data;
|
2005-01-20 18:37:13 +00:00
|
|
|
int fds[16];
|
|
|
|
|
int (*failed)(snd_pcm_t *, int) = NULL;
|
|
|
|
|
int count = _snd_pcm_link_descriptors(pcm2, fds, 16, &failed);
|
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
|
|
if (count < 0)
|
|
|
|
|
return count;
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
|
if (fds[i] < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_LINK, fds[i]) < 0) {
|
|
|
|
|
if (failed != NULL) {
|
|
|
|
|
err = failed(pcm2, fds[i]);
|
|
|
|
|
} else {
|
|
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_LINK failed");
|
|
|
|
|
err = -errno;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-01-20 15:07:51 +00:00
|
|
|
}
|
2005-01-20 18:37:13 +00:00
|
|
|
return err;
|
2005-01-20 15:07:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_hw_unlink(snd_pcm_t *pcm)
|
|
|
|
|
{
|
|
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
|
|
|
|
|
|
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_UNLINK) < 0) {
|
|
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_UNLINK failed");
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2004-05-22 10:14:32 +00:00
|
|
|
int err;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2000-06-21 14:59:20 +00:00
|
|
|
int fd = hw->fd;
|
2001-01-30 16:51:26 +00:00
|
|
|
struct sndrv_xferi xferi;
|
2000-09-24 09:57:26 +00:00
|
|
|
xferi.buf = (char*) buffer;
|
|
|
|
|
xferi.frames = size;
|
2005-02-24 20:57:56 +00:00
|
|
|
xferi.result = 0; /* make valgrind happy */
|
2004-05-22 10:14:32 +00:00
|
|
|
err = ioctl(fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &xferi);
|
|
|
|
|
err = err >= 0 ? sync_ptr(hw, SNDRV_PCM_SYNC_PTR_APPL) : -errno;
|
2002-03-11 13:18:46 +00:00
|
|
|
#ifdef DEBUG_RW
|
2004-05-22 10:14:32 +00:00
|
|
|
fprintf(stderr, "hw_writei: frames = %li, xferi.result = %li, err = %i\n", size, xferi.result, err);
|
2002-03-11 13:18:46 +00:00
|
|
|
#endif
|
2004-05-22 10:14:32 +00:00
|
|
|
if (err < 0)
|
2004-04-15 12:22:26 +00:00
|
|
|
return snd_pcm_check_error(pcm, err);
|
2000-09-25 17:17:38 +00:00
|
|
|
return xferi.result;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2004-05-22 10:14:32 +00:00
|
|
|
int err;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2000-06-21 14:59:20 +00:00
|
|
|
int fd = hw->fd;
|
2001-01-30 16:51:26 +00:00
|
|
|
struct sndrv_xfern xfern;
|
2005-02-24 20:57:56 +00:00
|
|
|
memset(&xfern, 0, sizeof(xfern)); /* make valgrind happy */
|
2000-09-24 09:57:26 +00:00
|
|
|
xfern.bufs = bufs;
|
|
|
|
|
xfern.frames = size;
|
2004-05-22 10:14:32 +00:00
|
|
|
err = ioctl(fd, SNDRV_PCM_IOCTL_WRITEN_FRAMES, &xfern);
|
|
|
|
|
err = err >= 0 ? sync_ptr(hw, SNDRV_PCM_SYNC_PTR_APPL) : -errno;
|
2002-03-11 13:18:46 +00:00
|
|
|
#ifdef DEBUG_RW
|
2004-05-22 10:14:32 +00:00
|
|
|
fprintf(stderr, "hw_writen: frames = %li, result = %li, err = %i\n", size, xfern.result, err);
|
2002-03-11 13:18:46 +00:00
|
|
|
#endif
|
2004-05-22 10:14:32 +00:00
|
|
|
if (err < 0)
|
2004-04-15 12:22:26 +00:00
|
|
|
return snd_pcm_check_error(pcm, err);
|
2000-09-25 17:17:38 +00:00
|
|
|
return xfern.result;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2004-05-22 10:14:32 +00:00
|
|
|
int err;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2000-06-21 14:59:20 +00:00
|
|
|
int fd = hw->fd;
|
2001-01-30 16:51:26 +00:00
|
|
|
struct sndrv_xferi xferi;
|
2000-09-24 09:57:26 +00:00
|
|
|
xferi.buf = buffer;
|
|
|
|
|
xferi.frames = size;
|
2005-02-24 20:57:56 +00:00
|
|
|
xferi.result = 0; /* make valgrind happy */
|
2004-05-22 10:14:32 +00:00
|
|
|
err = ioctl(fd, SNDRV_PCM_IOCTL_READI_FRAMES, &xferi);
|
|
|
|
|
err = err >= 0 ? sync_ptr(hw, SNDRV_PCM_SYNC_PTR_APPL) : -errno;
|
2002-03-11 13:18:46 +00:00
|
|
|
#ifdef DEBUG_RW
|
2004-05-22 10:14:32 +00:00
|
|
|
fprintf(stderr, "hw_readi: frames = %li, result = %li, err = %i\n", size, xferi.result, err);
|
2002-03-11 13:18:46 +00:00
|
|
|
#endif
|
2004-05-22 10:14:32 +00:00
|
|
|
if (err < 0)
|
2004-04-15 12:22:26 +00:00
|
|
|
return snd_pcm_check_error(pcm, err);
|
2001-12-08 21:00:21 +00:00
|
|
|
UPDATE_SHADOW_PTR(hw);
|
2000-09-25 17:17:38 +00:00
|
|
|
return xferi.result;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-29 17:50:28 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2004-05-22 10:14:32 +00:00
|
|
|
int err;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2000-06-21 14:59:20 +00:00
|
|
|
int fd = hw->fd;
|
2001-01-30 16:51:26 +00:00
|
|
|
struct sndrv_xfern xfern;
|
2005-02-24 20:57:56 +00:00
|
|
|
memset(&xfern, 0, sizeof(xfern)); /* make valgrind happy */
|
2000-09-24 09:57:26 +00:00
|
|
|
xfern.bufs = bufs;
|
|
|
|
|
xfern.frames = size;
|
2004-05-22 10:14:32 +00:00
|
|
|
err = ioctl(fd, SNDRV_PCM_IOCTL_READN_FRAMES, &xfern);
|
|
|
|
|
err = err >= 0 ? sync_ptr(hw, SNDRV_PCM_SYNC_PTR_APPL) : -errno;
|
2002-03-11 13:18:46 +00:00
|
|
|
#ifdef DEBUG_RW
|
2004-05-22 10:14:32 +00:00
|
|
|
fprintf(stderr, "hw_readn: frames = %li, result = %li, err = %i\n", size, xfern.result, err);
|
2002-03-11 13:18:46 +00:00
|
|
|
#endif
|
2004-05-22 10:14:32 +00:00
|
|
|
if (err < 0)
|
2004-04-15 12:22:26 +00:00
|
|
|
return snd_pcm_check_error(pcm, err);
|
2001-12-08 21:00:21 +00:00
|
|
|
UPDATE_SHADOW_PTR(hw);
|
2000-09-25 17:17:38 +00:00
|
|
|
return xfern.result;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static int snd_pcm_hw_mmap_status(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2004-05-22 10:14:32 +00:00
|
|
|
struct sndrv_pcm_sync_ptr sync_ptr;
|
2000-08-31 11:21:05 +00:00
|
|
|
void *ptr;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2004-05-22 10:14:32 +00:00
|
|
|
ptr = MAP_FAILED;
|
|
|
|
|
if (hw->sync_ptr_ioctl == 0)
|
|
|
|
|
ptr = mmap(NULL, page_align(sizeof(struct sndrv_pcm_mmap_status)),
|
|
|
|
|
PROT_READ, MAP_FILE|MAP_SHARED,
|
|
|
|
|
hw->fd, SNDRV_PCM_MMAP_OFFSET_STATUS);
|
2000-10-11 12:37:27 +00:00
|
|
|
if (ptr == MAP_FAILED || ptr == NULL) {
|
2004-05-22 10:14:32 +00:00
|
|
|
memset(&sync_ptr, 0, sizeof(sync_ptr));
|
|
|
|
|
sync_ptr.c.control.appl_ptr = 0;
|
|
|
|
|
sync_ptr.c.control.avail_min = 1;
|
|
|
|
|
err = ioctl(hw->fd, SNDRV_PCM_IOCTL_SYNC_PTR, &sync_ptr);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_SYNC_PTR failed");
|
2004-05-22 10:14:32 +00:00
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
hw->sync_ptr = calloc(1, sizeof(struct sndrv_pcm_sync_ptr));
|
|
|
|
|
if (hw->sync_ptr == NULL)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
hw->mmap_status = &hw->sync_ptr->s.status;
|
|
|
|
|
hw->mmap_control = &hw->sync_ptr->c.control;
|
|
|
|
|
hw->sync_ptr_ioctl = 1;
|
|
|
|
|
} else {
|
|
|
|
|
hw->mmap_status = ptr;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2002-04-23 15:51:29 +00:00
|
|
|
snd_pcm_set_hw_ptr(pcm, &hw->mmap_status->hw_ptr, hw->fd, SNDRV_PCM_MMAP_OFFSET_STATUS + offsetof(struct sndrv_pcm_mmap_status, hw_ptr));
|
2000-06-10 12:39:51 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static int snd_pcm_hw_mmap_control(snd_pcm_t *pcm)
|
2000-06-10 12:39:51 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2000-08-31 11:21:05 +00:00
|
|
|
void *ptr;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2004-05-22 10:14:32 +00:00
|
|
|
if (hw->sync_ptr == NULL) {
|
|
|
|
|
ptr = mmap(NULL, page_align(sizeof(struct sndrv_pcm_mmap_control)),
|
|
|
|
|
PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
|
|
|
|
|
hw->fd, SNDRV_PCM_MMAP_OFFSET_CONTROL);
|
|
|
|
|
if (ptr == MAP_FAILED || ptr == NULL) {
|
|
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("control mmap failed");
|
2004-05-22 10:14:32 +00:00
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
hw->mmap_control = ptr;
|
|
|
|
|
} else {
|
|
|
|
|
hw->mmap_control->avail_min = 1;
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2002-04-23 15:51:29 +00:00
|
|
|
snd_pcm_set_appl_ptr(pcm, &hw->mmap_control->appl_ptr, hw->fd, SNDRV_PCM_MMAP_OFFSET_CONTROL);
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static int snd_pcm_hw_munmap_status(snd_pcm_t *pcm)
|
2000-06-10 12:39:51 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2004-05-22 10:14:32 +00:00
|
|
|
if (hw->sync_ptr_ioctl) {
|
|
|
|
|
if (hw->sync_ptr) {
|
|
|
|
|
free(hw->sync_ptr);
|
|
|
|
|
hw->sync_ptr = NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (munmap((void*)hw->mmap_status, page_align(sizeof(*hw->mmap_status))) < 0) {
|
|
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("status munmap failed");
|
2004-05-22 10:14:32 +00:00
|
|
|
return err;
|
|
|
|
|
}
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-06-10 12:39:51 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static int snd_pcm_hw_munmap_control(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2004-05-22 10:14:32 +00:00
|
|
|
if (hw->sync_ptr_ioctl) {
|
|
|
|
|
if (hw->sync_ptr) {
|
|
|
|
|
free(hw->sync_ptr);
|
|
|
|
|
hw->sync_ptr = NULL;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (munmap(hw->mmap_control, page_align(sizeof(*hw->mmap_control))) < 0) {
|
|
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("control munmap failed");
|
2004-05-22 10:14:32 +00:00
|
|
|
return err;
|
|
|
|
|
}
|
2000-10-11 12:37:27 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-23 12:41:55 +00:00
|
|
|
static int snd_pcm_hw_mmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
2000-11-20 20:10:46 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-23 12:41:55 +00:00
|
|
|
static int snd_pcm_hw_munmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-14 10:31:34 +00:00
|
|
|
static int snd_pcm_hw_close(snd_pcm_t *pcm)
|
2000-09-24 09:57:26 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2003-02-23 20:00:07 +00:00
|
|
|
int err;
|
2000-11-20 20:10:46 +00:00
|
|
|
if (close(hw->fd)) {
|
2003-02-23 20:00:07 +00:00
|
|
|
err = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("close failed\n");
|
2003-02-23 20:00:07 +00:00
|
|
|
return err;
|
2000-10-14 10:31:34 +00:00
|
|
|
}
|
|
|
|
|
snd_pcm_hw_munmap_status(pcm);
|
|
|
|
|
snd_pcm_hw_munmap_control(pcm);
|
2000-11-20 20:10:46 +00:00
|
|
|
free(hw);
|
2000-10-14 10:31:34 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-21 15:01:34 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_mmap_commit(snd_pcm_t *pcm,
|
2003-02-22 17:53:01 +00:00
|
|
|
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
2002-02-21 15:01:34 +00:00
|
|
|
snd_pcm_uframes_t size)
|
2000-10-14 10:31:34 +00:00
|
|
|
{
|
2001-12-11 15:07:10 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2002-02-21 15:01:34 +00:00
|
|
|
|
2001-12-11 15:07:10 +00:00
|
|
|
if (hw->mmap_shm) {
|
2001-12-08 21:00:21 +00:00
|
|
|
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
2002-02-21 15:01:34 +00:00
|
|
|
snd_pcm_sframes_t result = 0, res;
|
2001-12-11 15:07:10 +00:00
|
|
|
|
|
|
|
|
do {
|
2001-12-08 21:00:21 +00:00
|
|
|
res = snd_pcm_write_mmap(pcm, size);
|
|
|
|
|
if (res < 0)
|
2002-02-21 15:01:34 +00:00
|
|
|
return result > 0 ? result : res;
|
2001-12-08 21:00:21 +00:00
|
|
|
size -= res;
|
2002-02-21 15:01:34 +00:00
|
|
|
result += res;
|
2001-12-08 21:00:21 +00:00
|
|
|
} while (size > 0);
|
2002-02-21 15:01:34 +00:00
|
|
|
return result;
|
2001-12-08 21:00:21 +00:00
|
|
|
} else {
|
|
|
|
|
assert(hw->shadow_appl_ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_mmap_appl_forward(pcm, size);
|
2002-03-11 13:18:46 +00:00
|
|
|
#ifdef DEBUG_MMAP
|
2003-05-04 20:07:30 +00:00
|
|
|
fprintf(stderr, "appl_forward: hw_ptr = %li, appl_ptr = %li, size = %li\n", *pcm->hw.ptr, *pcm->appl.ptr, size);
|
2002-03-11 13:18:46 +00:00
|
|
|
#endif
|
2002-02-21 15:01:34 +00:00
|
|
|
return size;
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-15 11:06:53 +00:00
|
|
|
static snd_pcm_sframes_t snd_pcm_hw_avail_update(snd_pcm_t *pcm)
|
2000-09-24 09:57:26 +00:00
|
|
|
{
|
2001-12-11 15:07:10 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2001-01-15 11:06:53 +00:00
|
|
|
snd_pcm_uframes_t avail;
|
2004-11-16 16:03:01 +00:00
|
|
|
|
|
|
|
|
sync_ptr(hw, 0);
|
2000-10-05 10:26:07 +00:00
|
|
|
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
|
|
|
|
avail = snd_pcm_mmap_playback_avail(pcm);
|
|
|
|
|
} else {
|
|
|
|
|
avail = snd_pcm_mmap_capture_avail(pcm);
|
2001-12-11 15:07:10 +00:00
|
|
|
if (avail > 0 && hw->mmap_shm) {
|
2001-12-08 21:00:21 +00:00
|
|
|
snd_pcm_sframes_t err;
|
|
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
|
|
|
|
hw->avail_update_flag = 1;
|
2000-10-05 10:26:07 +00:00
|
|
|
err = snd_pcm_read_mmap(pcm, avail);
|
2001-12-08 21:00:21 +00:00
|
|
|
hw->avail_update_flag = 0;
|
2000-10-05 10:26:07 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2004-12-21 14:11:00 +00:00
|
|
|
if ((snd_pcm_uframes_t)err != avail)
|
|
|
|
|
SNDMSG("short read %ld for avail %ld", err, avail);
|
2000-09-24 09:57:26 +00:00
|
|
|
return err;
|
2000-10-05 10:26:07 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
2002-02-21 15:01:34 +00:00
|
|
|
switch (FAST_PCM_STATE(hw)) {
|
|
|
|
|
case SNDRV_PCM_STATE_RUNNING:
|
|
|
|
|
if (avail >= pcm->stop_threshold) {
|
|
|
|
|
/* SNDRV_PCM_IOCTL_XRUN ioctl has been implemented since PCM kernel API 2.0.1 */
|
|
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 1) <= hw->version) {
|
2003-03-01 20:32:02 +00:00
|
|
|
if (ioctl(hw->fd, SNDRV_PCM_IOCTL_XRUN) < 0)
|
2002-02-21 15:01:34 +00:00
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
/* everything is ok, state == SND_PCM_STATE_XRUN at the moment */
|
|
|
|
|
return -EPIPE;
|
2002-02-21 08:45:19 +00:00
|
|
|
}
|
2002-02-22 07:51:43 +00:00
|
|
|
break;
|
2002-02-21 15:01:34 +00:00
|
|
|
case SNDRV_PCM_STATE_XRUN:
|
2000-10-07 16:59:48 +00:00
|
|
|
return -EPIPE;
|
2002-02-21 15:01:34 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
2002-02-21 08:45:19 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
return avail;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-17 11:00:32 +00:00
|
|
|
static void snd_pcm_hw_dump(snd_pcm_t *pcm, snd_output_t *out)
|
2000-07-17 15:33:29 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_hw_t *hw = pcm->private_data;
|
2001-03-29 17:50:28 +00:00
|
|
|
char *name;
|
2001-02-14 09:36:00 +00:00
|
|
|
int err = snd_card_get_name(hw->card, &name);
|
2004-12-21 14:11:00 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
SNDERR("cannot get card name");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-01-17 11:00:32 +00:00
|
|
|
snd_output_printf(out, "Hardware PCM card %d '%s' device %d subdevice %d\n",
|
2001-02-14 09:36:00 +00:00
|
|
|
hw->card, name, hw->device, hw->subdevice);
|
2000-07-17 15:33:29 +00:00
|
|
|
free(name);
|
2000-11-20 20:10:46 +00:00
|
|
|
if (pcm->setup) {
|
2001-01-17 11:00:32 +00:00
|
|
|
snd_output_printf(out, "\nIts setup is:\n");
|
|
|
|
|
snd_pcm_dump_setup(pcm, out);
|
2000-07-17 15:33:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-12 10:52:42 +00:00
|
|
|
static snd_pcm_ops_t snd_pcm_hw_ops = {
|
2003-07-25 17:02:00 +00:00
|
|
|
.close = snd_pcm_hw_close,
|
|
|
|
|
.info = snd_pcm_hw_info,
|
|
|
|
|
.hw_refine = snd_pcm_hw_hw_refine,
|
|
|
|
|
.hw_params = snd_pcm_hw_hw_params,
|
|
|
|
|
.hw_free = snd_pcm_hw_hw_free,
|
|
|
|
|
.sw_params = snd_pcm_hw_sw_params,
|
|
|
|
|
.channel_info = snd_pcm_hw_channel_info,
|
|
|
|
|
.dump = snd_pcm_hw_dump,
|
|
|
|
|
.nonblock = snd_pcm_hw_nonblock,
|
|
|
|
|
.async = snd_pcm_hw_async,
|
|
|
|
|
.mmap = snd_pcm_hw_mmap,
|
|
|
|
|
.munmap = snd_pcm_hw_munmap,
|
2000-07-19 17:21:15 +00:00
|
|
|
};
|
|
|
|
|
|
2002-01-12 10:52:42 +00:00
|
|
|
static snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = {
|
2003-07-25 17:02:00 +00:00
|
|
|
.status = snd_pcm_hw_status,
|
|
|
|
|
.state = snd_pcm_hw_state,
|
|
|
|
|
.hwsync = snd_pcm_hw_hwsync,
|
|
|
|
|
.delay = snd_pcm_hw_delay,
|
|
|
|
|
.prepare = snd_pcm_hw_prepare,
|
|
|
|
|
.reset = snd_pcm_hw_reset,
|
|
|
|
|
.start = snd_pcm_hw_start,
|
|
|
|
|
.drop = snd_pcm_hw_drop,
|
|
|
|
|
.drain = snd_pcm_hw_drain,
|
|
|
|
|
.pause = snd_pcm_hw_pause,
|
|
|
|
|
.rewind = snd_pcm_hw_rewind,
|
|
|
|
|
.forward = snd_pcm_hw_forward,
|
|
|
|
|
.resume = snd_pcm_hw_resume,
|
2005-01-20 15:07:51 +00:00
|
|
|
.link_fd = snd_pcm_hw_link_fd,
|
|
|
|
|
.link = snd_pcm_hw_link,
|
|
|
|
|
.unlink = snd_pcm_hw_unlink,
|
2003-07-25 17:02:00 +00:00
|
|
|
.writei = snd_pcm_hw_writei,
|
|
|
|
|
.writen = snd_pcm_hw_writen,
|
|
|
|
|
.readi = snd_pcm_hw_readi,
|
|
|
|
|
.readn = snd_pcm_hw_readn,
|
|
|
|
|
.avail_update = snd_pcm_hw_avail_update,
|
|
|
|
|
.mmap_commit = snd_pcm_hw_mmap_commit,
|
2005-05-23 09:03:16 +00:00
|
|
|
.poll_descriptors = NULL,
|
|
|
|
|
.poll_descriptors_count = NULL,
|
|
|
|
|
.poll_revents = NULL,
|
2000-05-08 18:53:38 +00:00
|
|
|
};
|
|
|
|
|
|
2003-02-04 13:33:44 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Creates a new hw PCM
|
|
|
|
|
* \param pcmp Returns created PCM handle
|
|
|
|
|
* \param name Name of PCM
|
|
|
|
|
* \param fd File descriptor
|
|
|
|
|
* \retval zero on success otherwise a negative error code
|
|
|
|
|
* \warning Using of this function might be dangerous in the sense
|
|
|
|
|
* of compatibility reasons. The prototype might be freely
|
|
|
|
|
* changed in future.
|
|
|
|
|
*/
|
|
|
|
|
int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name,
|
2004-05-22 10:14:32 +00:00
|
|
|
int fd, int mmap_emulation, int sync_ptr_ioctl)
|
2003-02-04 13:33:44 +00:00
|
|
|
{
|
|
|
|
|
int ver;
|
|
|
|
|
long fmode;
|
|
|
|
|
int mode;
|
|
|
|
|
snd_pcm_t *pcm = NULL;
|
|
|
|
|
snd_pcm_hw_t *hw = NULL;
|
|
|
|
|
snd_pcm_info_t info;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
assert(pcmp);
|
|
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info) < 0) {
|
2003-02-04 16:40:47 +00:00
|
|
|
ret = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_INFO failed");
|
2003-02-04 16:40:47 +00:00
|
|
|
close(fd);
|
|
|
|
|
return ret;
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-04 20:07:30 +00:00
|
|
|
if ((fmode = fcntl(fd, F_GETFL)) < 0) {
|
2003-02-04 16:40:47 +00:00
|
|
|
ret = -errno;
|
|
|
|
|
close(fd);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2003-02-04 13:33:44 +00:00
|
|
|
mode = 0;
|
|
|
|
|
if (fmode & O_NONBLOCK)
|
|
|
|
|
mode |= SND_PCM_NONBLOCK;
|
|
|
|
|
if (fmode & O_ASYNC)
|
|
|
|
|
mode |= SND_PCM_ASYNC;
|
|
|
|
|
|
2003-02-05 11:00:16 +00:00
|
|
|
#if 0
|
|
|
|
|
/*
|
|
|
|
|
* this is bogus, an application have to care about open filedescriptors
|
|
|
|
|
*/
|
2003-02-04 13:33:44 +00:00
|
|
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
|
|
|
|
|
ret = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("fcntl FD_CLOEXEC failed");
|
2003-02-04 16:40:47 +00:00
|
|
|
close(fd);
|
|
|
|
|
return ret;
|
2003-02-04 13:33:44 +00:00
|
|
|
}
|
2003-02-05 11:00:16 +00:00
|
|
|
#endif
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_PVERSION, &ver) < 0) {
|
2003-02-04 16:40:47 +00:00
|
|
|
ret = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_PVERSION failed");
|
2003-02-04 16:40:47 +00:00
|
|
|
close(fd);
|
|
|
|
|
return ret;
|
2003-02-04 13:33:44 +00:00
|
|
|
}
|
|
|
|
|
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_PCM_VERSION_MAX))
|
|
|
|
|
return -SND_ERROR_INCOMPATIBLE_VERSION;
|
2003-03-01 20:32:02 +00:00
|
|
|
|
|
|
|
|
if (SNDRV_PROTOCOL_VERSION(2, 0, 5) <= ver) {
|
|
|
|
|
int on = 1;
|
|
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_TSTAMP, &on) < 0) {
|
|
|
|
|
ret = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SNDMSG("TSTAMP failed\n");
|
2003-03-01 20:32:02 +00:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
hw = calloc(1, sizeof(snd_pcm_hw_t));
|
2003-02-04 16:40:47 +00:00
|
|
|
if (!hw) {
|
|
|
|
|
close(fd);
|
2003-02-04 13:33:44 +00:00
|
|
|
return -ENOMEM;
|
2003-02-04 16:40:47 +00:00
|
|
|
}
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
hw->version = ver;
|
|
|
|
|
hw->card = info.card;
|
|
|
|
|
hw->device = info.device;
|
|
|
|
|
hw->subdevice = info.subdevice;
|
|
|
|
|
hw->fd = fd;
|
|
|
|
|
hw->mmap_emulation = mmap_emulation;
|
2004-05-22 10:14:32 +00:00
|
|
|
hw->sync_ptr_ioctl = sync_ptr_ioctl;
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
ret = snd_pcm_new(&pcm, SND_PCM_TYPE_HW, name, info.stream, mode);
|
2003-02-04 16:40:47 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
|
free(hw);
|
|
|
|
|
close(fd);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
pcm->ops = &snd_pcm_hw_ops;
|
|
|
|
|
pcm->fast_ops = &snd_pcm_hw_fast_ops;
|
|
|
|
|
pcm->private_data = hw;
|
|
|
|
|
pcm->poll_fd = fd;
|
2003-02-11 18:14:43 +00:00
|
|
|
pcm->poll_events = info.stream == SND_PCM_STREAM_PLAYBACK ? POLLOUT : POLLIN;
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
*pcmp = pcm;
|
|
|
|
|
|
|
|
|
|
ret = snd_pcm_hw_mmap_status(pcm);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
snd_pcm_close(pcm);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
ret = snd_pcm_hw_mmap_control(pcm);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
snd_pcm_close(pcm);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-12 10:52:42 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Creates a new hw PCM
|
|
|
|
|
* \param pcmp Returns created PCM handle
|
|
|
|
|
* \param name Name of PCM
|
|
|
|
|
* \param card Number of card
|
|
|
|
|
* \param device Number of device
|
|
|
|
|
* \param subdevice Number of subdevice
|
|
|
|
|
* \param stream PCM Stream
|
|
|
|
|
* \param mode PCM Mode
|
2004-05-22 10:14:32 +00:00
|
|
|
* \param mmap_emulation Emulate mmap access using standard r/w access
|
|
|
|
|
* \param sync_ptr_ioctl Use SYNC_PTR ioctl rather than mmap for control structures
|
2002-01-12 10:52:42 +00:00
|
|
|
* \retval zero on success otherwise a negative error code
|
|
|
|
|
* \warning Using of this function might be dangerous in the sense
|
|
|
|
|
* of compatibility reasons. The prototype might be freely
|
|
|
|
|
* changed in future.
|
|
|
|
|
*/
|
2001-12-11 15:07:10 +00:00
|
|
|
int snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
|
|
|
|
int card, int device, int subdevice,
|
|
|
|
|
snd_pcm_stream_t stream, int mode,
|
2004-05-22 10:14:32 +00:00
|
|
|
int mmap_emulation, int sync_ptr_ioctl)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
|
|
|
|
char filename[32];
|
2001-03-29 17:50:28 +00:00
|
|
|
const char *filefmt;
|
2003-02-04 13:33:44 +00:00
|
|
|
int ret = 0, fd = -1;
|
2000-05-08 18:53:38 +00:00
|
|
|
int attempt = 0;
|
2000-06-21 14:59:20 +00:00
|
|
|
snd_pcm_info_t info;
|
|
|
|
|
int fmode;
|
|
|
|
|
snd_ctl_t *ctl;
|
|
|
|
|
|
2000-10-14 10:31:34 +00:00
|
|
|
assert(pcmp);
|
2000-06-21 14:59:20 +00:00
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
if ((ret = snd_ctl_hw_open(&ctl, NULL, card, 0)) < 0)
|
2000-06-21 14:59:20 +00:00
|
|
|
return ret;
|
|
|
|
|
|
2001-07-11 14:09:01 +00:00
|
|
|
switch (stream) {
|
2000-05-27 16:52:17 +00:00
|
|
|
case SND_PCM_STREAM_PLAYBACK:
|
2001-01-29 14:27:53 +00:00
|
|
|
filefmt = SNDRV_FILE_PCM_STREAM_PLAYBACK;
|
2000-05-08 18:53:38 +00:00
|
|
|
break;
|
2000-05-27 16:52:17 +00:00
|
|
|
case SND_PCM_STREAM_CAPTURE:
|
2001-01-29 14:27:53 +00:00
|
|
|
filefmt = SNDRV_FILE_PCM_STREAM_CAPTURE;
|
2000-05-08 18:53:38 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2004-12-21 14:11:00 +00:00
|
|
|
SNDERR("invalid stream %d", stream);
|
|
|
|
|
return -EINVAL;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
sprintf(filename, filefmt, card, device);
|
|
|
|
|
|
|
|
|
|
__again:
|
2000-10-30 12:15:18 +00:00
|
|
|
if (attempt++ > 3) {
|
2000-11-22 14:27:37 +00:00
|
|
|
ret = -EBUSY;
|
|
|
|
|
goto _err;
|
2000-10-30 12:15:18 +00:00
|
|
|
}
|
|
|
|
|
ret = snd_ctl_pcm_prefer_subdevice(ctl, subdevice);
|
2000-11-22 14:27:37 +00:00
|
|
|
if (ret < 0)
|
|
|
|
|
goto _err;
|
2000-06-21 14:59:20 +00:00
|
|
|
fmode = O_RDWR;
|
|
|
|
|
if (mode & SND_PCM_NONBLOCK)
|
|
|
|
|
fmode |= O_NONBLOCK;
|
2000-10-11 12:37:27 +00:00
|
|
|
if (mode & SND_PCM_ASYNC)
|
|
|
|
|
fmode |= O_ASYNC;
|
2005-02-11 16:35:24 +00:00
|
|
|
fd = snd_open_device(filename, fmode);
|
2005-01-26 10:50:28 +00:00
|
|
|
if (fd < 0) {
|
2000-11-22 14:27:37 +00:00
|
|
|
ret = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("open %s failed", filename);
|
2000-11-22 14:27:37 +00:00
|
|
|
goto _err;
|
2000-10-15 14:15:30 +00:00
|
|
|
}
|
2000-05-08 18:53:38 +00:00
|
|
|
if (subdevice >= 0) {
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
2001-01-29 14:27:53 +00:00
|
|
|
if (ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info) < 0) {
|
2000-06-21 14:59:20 +00:00
|
|
|
ret = -errno;
|
2004-12-21 14:11:00 +00:00
|
|
|
SYSMSG("SNDRV_PCM_IOCTL_INFO failed");
|
2000-10-14 10:31:34 +00:00
|
|
|
goto _err;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
2001-01-15 11:06:53 +00:00
|
|
|
if (info.subdevice != (unsigned int) subdevice) {
|
2000-05-08 18:53:38 +00:00
|
|
|
close(fd);
|
|
|
|
|
goto __again;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-11-22 14:27:37 +00:00
|
|
|
snd_ctl_close(ctl);
|
2004-05-22 10:14:32 +00:00
|
|
|
return snd_pcm_hw_open_fd(pcmp, name, fd, mmap_emulation, sync_ptr_ioctl);
|
2003-02-04 13:33:44 +00:00
|
|
|
|
|
|
|
|
_err:
|
2000-10-30 12:15:18 +00:00
|
|
|
snd_ctl_close(ctl);
|
2000-06-21 14:59:20 +00:00
|
|
|
return ret;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2002-01-12 10:52:42 +00:00
|
|
|
/*! \page pcm_plugins
|
|
|
|
|
|
|
|
|
|
\section pcm_plugins_hw Plugin: hw
|
|
|
|
|
|
|
|
|
|
This plugin communicates directly with the ALSA kernel driver. It is a raw
|
|
|
|
|
communication without any conversions. The emulation of mmap access can be
|
2002-01-22 14:27:25 +00:00
|
|
|
optionally enabled, but expect worse latency in the case.
|
2002-01-12 10:52:42 +00:00
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
pcm.name {
|
|
|
|
|
type hw # Kernel PCM
|
|
|
|
|
card INT/STR # Card name (string) or number (integer)
|
|
|
|
|
[device INT] # Device number (default 0)
|
|
|
|
|
[subdevice INT] # Subdevice number (default -1: first available)
|
|
|
|
|
[mmap_emulation BOOL] # Enable mmap emulation for ro/wo devices
|
2004-05-22 10:14:32 +00:00
|
|
|
[sync_ptr_ioctl BOOL] # Use SYNC_PTR ioctl rather than the direct mmap access for control structures
|
2002-01-12 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
\subsection pcm_plugins_hw_funcref Function reference
|
|
|
|
|
|
|
|
|
|
<UL>
|
|
|
|
|
<LI>snd_pcm_hw_open()
|
|
|
|
|
<LI>_snd_pcm_hw_open()
|
|
|
|
|
</UL>
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Creates a new hw PCM
|
|
|
|
|
* \param pcmp Returns created PCM handle
|
|
|
|
|
* \param name Name of PCM
|
|
|
|
|
* \param root Root configuration node
|
|
|
|
|
* \param conf Configuration node with hw PCM description
|
|
|
|
|
* \param stream PCM Stream
|
|
|
|
|
* \param mode PCM Mode
|
|
|
|
|
* \warning Using of this function might be dangerous in the sense
|
|
|
|
|
* of compatibility reasons. The prototype might be freely
|
|
|
|
|
* changed in future.
|
|
|
|
|
*/
|
2001-06-11 13:35:48 +00:00
|
|
|
int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
|
|
|
|
snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf,
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_stream_t stream, int mode)
|
2000-09-24 09:57:26 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_iterator_t i, next;
|
2000-09-24 09:57:26 +00:00
|
|
|
long card = -1, device = 0, subdevice = -1;
|
2001-02-06 23:48:10 +00:00
|
|
|
const char *str;
|
2004-05-22 10:14:32 +00:00
|
|
|
int err, mmap_emulation = 0, sync_ptr_ioctl = 0;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_for_each(i, next, conf) {
|
2001-02-07 11:34:33 +00:00
|
|
|
snd_config_t *n = snd_config_iterator_entry(i);
|
2001-11-19 08:14:21 +00:00
|
|
|
const char *id;
|
|
|
|
|
if (snd_config_get_id(n, &id) < 0)
|
|
|
|
|
continue;
|
2001-06-04 18:04:18 +00:00
|
|
|
if (snd_pcm_conf_generic_id(id))
|
2000-09-24 09:57:26 +00:00
|
|
|
continue;
|
2001-02-07 11:34:33 +00:00
|
|
|
if (strcmp(id, "card") == 0) {
|
|
|
|
|
err = snd_config_get_integer(n, &card);
|
2000-09-24 09:57:26 +00:00
|
|
|
if (err < 0) {
|
2001-02-07 11:34:33 +00:00
|
|
|
err = snd_config_get_string(n, &str);
|
2000-11-30 09:40:50 +00:00
|
|
|
if (err < 0) {
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Invalid type for %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return -EINVAL;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
card = snd_card_get_index(str);
|
2000-11-30 09:40:50 +00:00
|
|
|
if (card < 0) {
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Invalid value for %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return card;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2001-02-07 11:34:33 +00:00
|
|
|
if (strcmp(id, "device") == 0) {
|
|
|
|
|
err = snd_config_get_integer(n, &device);
|
2000-11-30 09:40:50 +00:00
|
|
|
if (err < 0) {
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Invalid type for %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return err;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2001-02-07 11:34:33 +00:00
|
|
|
if (strcmp(id, "subdevice") == 0) {
|
|
|
|
|
err = snd_config_get_integer(n, &subdevice);
|
2000-11-30 09:40:50 +00:00
|
|
|
if (err < 0) {
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Invalid type for %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return err;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2001-12-11 15:07:10 +00:00
|
|
|
if (strcmp(id, "mmap_emulation") == 0) {
|
|
|
|
|
err = snd_config_get_bool(n);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
continue;
|
|
|
|
|
mmap_emulation = err;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2004-05-22 10:14:32 +00:00
|
|
|
if (strcmp(id, "sync_ptr_ioctl") == 0) {
|
|
|
|
|
err = snd_config_get_bool(n);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
continue;
|
|
|
|
|
sync_ptr_ioctl = err;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Unknown field %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2000-11-30 09:40:50 +00:00
|
|
|
if (card < 0) {
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("card is not defined");
|
2000-09-24 09:57:26 +00:00
|
|
|
return -EINVAL;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2004-05-22 10:14:32 +00:00
|
|
|
return snd_pcm_hw_open(pcmp, name, card, device, subdevice, stream, mode, mmap_emulation, sync_ptr_ioctl);
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
2002-01-12 10:52:42 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
2001-10-24 14:14:11 +00:00
|
|
|
SND_DLSYM_BUILD_VERSION(_snd_pcm_hw_open, SND_PCM_DLSYM_VERSION);
|
2002-01-12 10:52:42 +00:00
|
|
|
#endif
|
2002-06-26 02:04:11 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* To be removed helpers, but keep binary compatibility at the time
|
|
|
|
|
*/
|
|
|
|
|
|
2002-09-19 16:12:13 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
2002-06-26 02:04:11 +00:00
|
|
|
#define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
|
|
|
|
|
#define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
|
2002-09-19 16:12:13 +00:00
|
|
|
#endif
|
2002-06-26 02:04:11 +00:00
|
|
|
|
|
|
|
|
static void snd_pcm_hw_convert_from_old_params(snd_pcm_hw_params_t *params,
|
|
|
|
|
struct sndrv_pcm_hw_params_old *oparams)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
memset(params, 0, sizeof(*params));
|
|
|
|
|
params->flags = oparams->flags;
|
|
|
|
|
for (i = 0; i < sizeof(oparams->masks) / sizeof(unsigned int); i++)
|
|
|
|
|
params->masks[i].bits[0] = oparams->masks[i];
|
|
|
|
|
memcpy(params->intervals, oparams->intervals, sizeof(oparams->intervals));
|
|
|
|
|
params->rmask = __OLD_TO_NEW_MASK(oparams->rmask);
|
|
|
|
|
params->cmask = __OLD_TO_NEW_MASK(oparams->cmask);
|
|
|
|
|
params->info = oparams->info;
|
|
|
|
|
params->msbits = oparams->msbits;
|
|
|
|
|
params->rate_num = oparams->rate_num;
|
|
|
|
|
params->rate_den = oparams->rate_den;
|
|
|
|
|
params->fifo_size = oparams->fifo_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void snd_pcm_hw_convert_to_old_params(struct sndrv_pcm_hw_params_old *oparams,
|
|
|
|
|
snd_pcm_hw_params_t *params,
|
|
|
|
|
unsigned int *cmask)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
|
|
memset(oparams, 0, sizeof(*oparams));
|
|
|
|
|
oparams->flags = params->flags;
|
|
|
|
|
for (i = 0; i < sizeof(oparams->masks) / sizeof(unsigned int); i++) {
|
|
|
|
|
oparams->masks[i] = params->masks[i].bits[0];
|
|
|
|
|
for (j = 1; j < sizeof(params->masks[i].bits) / sizeof(unsigned int); j++)
|
|
|
|
|
if (params->masks[i].bits[j]) {
|
|
|
|
|
*cmask |= 1 << i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memcpy(oparams->intervals, params->intervals, sizeof(oparams->intervals));
|
|
|
|
|
oparams->rmask = __NEW_TO_OLD_MASK(params->rmask);
|
|
|
|
|
oparams->cmask = __NEW_TO_OLD_MASK(params->cmask);
|
|
|
|
|
oparams->info = params->info;
|
|
|
|
|
oparams->msbits = params->msbits;
|
|
|
|
|
oparams->rate_num = params->rate_num;
|
|
|
|
|
oparams->rate_den = params->rate_den;
|
|
|
|
|
oparams->fifo_size = params->fifo_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int use_old_hw_params_ioctl(int fd, unsigned int cmd, snd_pcm_hw_params_t *params)
|
|
|
|
|
{
|
|
|
|
|
struct sndrv_pcm_hw_params_old oparams;
|
|
|
|
|
unsigned int cmask = 0;
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
snd_pcm_hw_convert_to_old_params(&oparams, params, &cmask);
|
|
|
|
|
res = ioctl(fd, cmd, &oparams);
|
|
|
|
|
snd_pcm_hw_convert_from_old_params(params, &oparams);
|
|
|
|
|
params->cmask |= cmask;
|
|
|
|
|
return res;
|
|
|
|
|
}
|