Encapsulated hwdep. Converted all enums to type safety

This commit is contained in:
Abramo Bagnara 2001-02-05 15:44:42 +00:00
parent a83b209df2
commit 5bf23ae9a1
32 changed files with 510 additions and 268 deletions

View file

@ -218,14 +218,7 @@ int snd_pcm_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
int snd_pcm_unlink(snd_pcm_t *pcm)
{
int fd;
switch (pcm->type) {
case SND_PCM_TYPE_HW:
case SND_PCM_TYPE_MULTI:
fd = snd_pcm_poll_descriptor(pcm);
break;
default:
return -ENOSYS;
}
fd = snd_pcm_link_descriptor(pcm);
if (ioctl(fd, SNDRV_PCM_IOCTL_UNLINK) < 0) {
SYSERR("SNDRV_PCM_IOCTL_UNLINK failed");
return -errno;
@ -409,7 +402,7 @@ snd_pcm_format_t snd_pcm_format_value(const char* name)
return format;
}
}
return SND_PCM_FORMAT_NONE;
return SND_PCM_FORMAT_UNKNOWN;
}
const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)

View file

@ -600,7 +600,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name,
char *sname = NULL;
int err;
snd_pcm_t *spcm;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);
if (strcmp(n->id, "comment") == 0)
@ -625,7 +625,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown sformat");
return -EINVAL;
}
@ -643,7 +643,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name,
ERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("sformat is not defined");
return -EINVAL;
}

View file

@ -473,7 +473,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, char *name,
char *sname = NULL;
int err;
snd_pcm_t *spcm;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);
if (strcmp(n->id, "comment") == 0)
@ -498,7 +498,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, char *name,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown sformat");
return -EINVAL;
}
@ -516,7 +516,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, char *name,
ERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("sformat is not defined");
return -EINVAL;
}

View file

@ -371,7 +371,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, char *name,
char *sname = NULL;
int err;
snd_pcm_t *spcm;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);
if (strcmp(n->id, "comment") == 0)
@ -396,7 +396,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, char *name,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown sformat %s", f);
return err;
}
@ -413,7 +413,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, char *name,
ERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("sformat is not defined");
return -EINVAL;
}

View file

@ -26,7 +26,7 @@
#define bswap_16 swab16
#define bswap_32 swab32
#define bswap_64 swab64
#define SND_PCM_FORMAT_NONE (-1)
#define SND_PCM_FORMAT_UNKNOWN (-1)
#define snd_enum_to_int(v) (v)
#define snd_int_to_enum(v) (v)
#else
@ -442,7 +442,7 @@ snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_end
width = 3;
break;
default:
return SND_PCM_FORMAT_NONE;
return SND_PCM_FORMAT_UNKNOWN;
}
return snd_int_to_enum(((int(*)[2][2])linear_formats)[width][!!unsignd][!!big_endian]);
}

View file

@ -488,7 +488,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, char *name,
char *sname = NULL;
int err;
snd_pcm_t *spcm;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);
if (strcmp(n->id, "comment") == 0)
@ -513,7 +513,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, char *name,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown sformat");
return -EINVAL;
}
@ -531,7 +531,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, char *name,
ERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("sformat is not defined");
return -EINVAL;
}

View file

@ -132,7 +132,7 @@ static snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format, const
}
/* Fall through */
default:
return SND_PCM_FORMAT_NONE;
return SND_PCM_FORMAT_UNKNOWN;
}
}
@ -144,7 +144,7 @@ static snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format, const
if (snd_pcm_format_mask_test(format_mask, f))
return f;
}
return SND_PCM_FORMAT_NONE;
return SND_PCM_FORMAT_UNKNOWN;
}
w = snd_pcm_format_width(format);
u = snd_pcm_format_unsigned(format);
@ -158,7 +158,7 @@ static snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format, const
for (sgn = 0; sgn < 2; ++sgn) {
snd_pcm_format_t f;
f = snd_pcm_build_linear_format(w1, u1, e1);
assert(f != SND_PCM_FORMAT_NONE);
assert(f != SND_PCM_FORMAT_UNKNOWN);
if (snd_pcm_format_mask_test(format_mask, f))
return f;
u1 = !u1;
@ -172,7 +172,7 @@ static snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format, const
dw = -8;
}
}
return SND_PCM_FORMAT_NONE;
return SND_PCM_FORMAT_UNKNOWN;
}
#define SND_PCM_FMTBIT_PLUG (SND_PCM_FMTBIT_LINEAR | \
@ -401,9 +401,8 @@ static int snd_pcm_plug_hw_refine_cprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_
static int snd_pcm_plug_hw_refine_sprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *sparams)
{
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_t *slave = plug->req_slave;
return snd_pcm_hw_params_any(slave, sparams);
_snd_pcm_hw_params_any(sparams);
return 0;
}
static int snd_pcm_plug_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
@ -436,7 +435,7 @@ static int snd_pcm_plug_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *p
f = format;
else {
f = snd_pcm_plug_slave_format(format, sformat_mask);
if (f == SND_PCM_FORMAT_NONE)
if (f == SND_PCM_FORMAT_UNKNOWN)
continue;
}
snd_pcm_format_mask_set(&sfmt_mask, f);
@ -496,7 +495,7 @@ static int snd_pcm_plug_hw_refine_cchange(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
f = format;
else {
f = snd_pcm_plug_slave_format(format, sformat_mask);
if (f == SND_PCM_FORMAT_NONE)
if (f == SND_PCM_FORMAT_UNKNOWN)
continue;
}
snd_pcm_format_mask_set(&fmt_mask, format);

View file

@ -258,7 +258,7 @@ static int snd_pcm_rate_hw_refine_sprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t *
_snd_pcm_hw_params_any(sparams);
_snd_pcm_hw_param_set_mask(sparams, SND_PCM_HW_PARAM_ACCESS,
&saccess_mask);
if (rate->sformat != SND_PCM_FORMAT_NONE) {
if (rate->sformat != SND_PCM_FORMAT_UNKNOWN) {
_snd_pcm_hw_params_set_format(sparams, rate->sformat);
_snd_pcm_hw_params_set_subformat(sparams, SND_PCM_SUBFORMAT_STD);
}
@ -277,7 +277,7 @@ static int snd_pcm_rate_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *p
unsigned int links = (SND_PCM_HW_PARBIT_CHANNELS |
SND_PCM_HW_PARBIT_PERIOD_TIME |
SND_PCM_HW_PARBIT_TICK_TIME);
if (rate->sformat == SND_PCM_FORMAT_NONE)
if (rate->sformat == SND_PCM_FORMAT_UNKNOWN)
links |= (SND_PCM_HW_PARBIT_FORMAT |
SND_PCM_HW_PARBIT_SUBFORMAT |
SND_PCM_HW_PARBIT_SAMPLE_BITS |
@ -307,7 +307,7 @@ static int snd_pcm_rate_hw_refine_cchange(snd_pcm_t *pcm, snd_pcm_hw_params_t *p
unsigned int links = (SND_PCM_HW_PARBIT_CHANNELS |
SND_PCM_HW_PARBIT_PERIOD_TIME |
SND_PCM_HW_PARBIT_TICK_TIME);
if (rate->sformat == SND_PCM_FORMAT_NONE)
if (rate->sformat == SND_PCM_FORMAT_UNKNOWN)
links |= (SND_PCM_HW_PARBIT_FORMAT |
SND_PCM_HW_PARBIT_SUBFORMAT |
SND_PCM_HW_PARBIT_SAMPLE_BITS |
@ -542,7 +542,7 @@ snd_pcm_sframes_t snd_pcm_rate_slave_frames(snd_pcm_t *pcm, snd_pcm_sframes_t fr
static void snd_pcm_rate_dump(snd_pcm_t *pcm, snd_output_t *out)
{
snd_pcm_rate_t *rate = pcm->private;
if (rate->sformat == SND_PCM_FORMAT_NONE)
if (rate->sformat == SND_PCM_FORMAT_UNKNOWN)
snd_output_printf(out, "Rate conversion PCM (%d)\n",
rate->srate);
else
@ -577,7 +577,7 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, char *name, snd_pcm_format_t sformat, in
snd_pcm_t *pcm;
snd_pcm_rate_t *rate;
assert(pcmp && slave);
if (sformat != SND_PCM_FORMAT_NONE &&
if (sformat != SND_PCM_FORMAT_UNKNOWN &&
snd_pcm_format_linear(sformat) != 1)
return -EINVAL;
rate = calloc(1, sizeof(snd_pcm_rate_t));
@ -625,7 +625,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, char *name,
char *sname = NULL;
int err;
snd_pcm_t *spcm;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
long srate = -1;
snd_config_foreach(i, conf) {
snd_config_t *n = snd_config_entry(i);
@ -651,7 +651,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, char *name,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown sformat");
return -EINVAL;
}

View file

@ -465,7 +465,7 @@ static int snd_pcm_route_hw_refine_sprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t
_snd_pcm_hw_params_any(sparams);
_snd_pcm_hw_param_set_mask(sparams, SND_PCM_HW_PARAM_ACCESS,
&saccess_mask);
if (route->sformat != SND_PCM_FORMAT_NONE) {
if (route->sformat != SND_PCM_FORMAT_UNKNOWN) {
_snd_pcm_hw_params_set_format(sparams, route->sformat);
_snd_pcm_hw_params_set_subformat(sparams, SND_PCM_SUBFORMAT_STD);
}
@ -488,7 +488,7 @@ static int snd_pcm_route_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *
SND_PCM_HW_PARBIT_BUFFER_SIZE |
SND_PCM_HW_PARBIT_BUFFER_TIME |
SND_PCM_HW_PARBIT_TICK_TIME);
if (route->sformat == SND_PCM_FORMAT_NONE)
if (route->sformat == SND_PCM_FORMAT_UNKNOWN)
links |= (SND_PCM_HW_PARBIT_FORMAT |
SND_PCM_HW_PARBIT_SUBFORMAT |
SND_PCM_HW_PARBIT_SAMPLE_BITS);
@ -512,7 +512,7 @@ static int snd_pcm_route_hw_refine_cchange(snd_pcm_t *pcm, snd_pcm_hw_params_t *
SND_PCM_HW_PARBIT_BUFFER_SIZE |
SND_PCM_HW_PARBIT_BUFFER_TIME |
SND_PCM_HW_PARBIT_TICK_TIME);
if (route->sformat == SND_PCM_FORMAT_NONE)
if (route->sformat == SND_PCM_FORMAT_UNKNOWN)
links |= (SND_PCM_HW_PARBIT_FORMAT |
SND_PCM_HW_PARBIT_SUBFORMAT |
SND_PCM_HW_PARBIT_SAMPLE_BITS);
@ -642,7 +642,7 @@ static void snd_pcm_route_dump(snd_pcm_t *pcm, snd_output_t *out)
{
snd_pcm_route_t *route = pcm->private;
unsigned int dst;
if (route->sformat == SND_PCM_FORMAT_NONE)
if (route->sformat == SND_PCM_FORMAT_UNKNOWN)
snd_output_printf(out, "Route conversion PCM\n");
else
snd_output_printf(out, "Route conversion PCM (sformat=%s)\n",
@ -774,7 +774,7 @@ int snd_pcm_route_open(snd_pcm_t **pcmp, char *name,
snd_pcm_route_t *route;
int err;
assert(pcmp && slave && ttable);
if (sformat != SND_PCM_FORMAT_NONE &&
if (sformat != SND_PCM_FORMAT_UNKNOWN &&
snd_pcm_format_linear(sformat) != 1)
return -EINVAL;
route = calloc(1, sizeof(snd_pcm_route_t));
@ -886,7 +886,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, char *name,
char *sname = NULL;
int err;
snd_pcm_t *spcm;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
long schannels = -1;
snd_config_t *tt = NULL;
snd_pcm_route_ttable_entry_t ttable[MAX_CHANNELS*MAX_CHANNELS];
@ -915,7 +915,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, char *name,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown sformat");
return -EINVAL;
}

View file

@ -469,7 +469,7 @@ static int snd_pcm_share_hw_refine_cprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t
share->channels_count, 0);
if (err < 0)
return err;
if (slave->format != SND_PCM_FORMAT_NONE) {
if (slave->format != SND_PCM_FORMAT_UNKNOWN) {
err = _snd_pcm_hw_params_set_format(params, slave->format);
if (err < 0)
return err;
@ -1371,7 +1371,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf,
unsigned int channels_count = 0;
long schannels_count = -1;
unsigned int schannel_max = 0;
snd_pcm_format_t sformat = SND_PCM_FORMAT_NONE;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
long srate = -1;
snd_config_foreach(i, conf) {
@ -1398,7 +1398,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf,
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_NONE) {
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
ERR("Unknown format %s", f);
return -EINVAL;
}