PCM: Introduce snd_pcm_chmap_t and snd_pcm_chmap_query_t

Instead of passing ambiguous integer array, define snd_pcm_chmap_t and
snd_pcm_chmap_query_t so that user can understand more easily which
element is for what.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2012-09-04 17:26:43 +02:00
parent 48c2c90f19
commit 9c1a0ce72d
15 changed files with 102 additions and 84 deletions

View file

@ -512,10 +512,23 @@ enum snd_pcm_chmap_position {
#define SND_CHMAP_PHASE_INVERSE (0x01 << 16) /* the channel is phase inverted */ #define SND_CHMAP_PHASE_INVERSE (0x01 << 16) /* the channel is phase inverted */
#define SND_CHMAP_DRIVER_SPEC (0x02 << 16) /* non-standard channel value */ #define SND_CHMAP_DRIVER_SPEC (0x02 << 16) /* non-standard channel value */
int **snd_pcm_query_chmaps(snd_pcm_t *pcm); /** the channel map header */
void snd_pcm_free_chmaps(int **maps); typedef struct snd_pcm_chmap {
int *snd_pcm_get_chmap(snd_pcm_t *pcm); unsigned int channels;
int snd_pcm_set_chmap(snd_pcm_t *pcm, const int *map); unsigned int pos[0];
} snd_pcm_chmap_t;
/** the header of array items returned from snd_pcm_query_chmaps() */
typedef struct snd_pcm_chmap_query {
enum snd_pcm_chmap_type type;
snd_pcm_chmap_t map;
} snd_pcm_chmap_query_t;
snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm);
void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps);
snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm);
int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);
//int snd_pcm_mixer_element(snd_pcm_t *pcm, snd_mixer_t *mixer, snd_mixer_elem_t **elem); //int snd_pcm_mixer_element(snd_pcm_t *pcm, snd_mixer_t *mixer, snd_mixer_elem_t **elem);

View file

@ -154,15 +154,15 @@ struct snd_pcm_extplug_callback {
/** /**
* query the channel maps; optional; since v1.0.2 * query the channel maps; optional; since v1.0.2
*/ */
int **(*query_chmaps)(snd_pcm_extplug_t *ext); snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_extplug_t *ext);
/** /**
* get the channel map; optional; since v1.0.2 * get the channel map; optional; since v1.0.2
*/ */
int *(*get_chmap)(snd_pcm_extplug_t *ext); snd_pcm_chmap_t *(*get_chmap)(snd_pcm_extplug_t *ext);
/** /**
* set the channel map; optional; since v1.0.2 * set the channel map; optional; since v1.0.2
*/ */
int (*set_chmap)(snd_pcm_extplug_t *ext, const int *map); int (*set_chmap)(snd_pcm_extplug_t *ext, const snd_pcm_chmap_t *map);
}; };

View file

@ -192,15 +192,15 @@ struct snd_pcm_ioplug_callback {
/** /**
* query the channel maps; optional; since v1.0.2 * query the channel maps; optional; since v1.0.2
*/ */
int **(*query_chmaps)(snd_pcm_ioplug_t *io); snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_ioplug_t *io);
/** /**
* get the channel map; optional; since v1.0.2 * get the channel map; optional; since v1.0.2
*/ */
int *(*get_chmap)(snd_pcm_ioplug_t *io); snd_pcm_chmap_t *(*get_chmap)(snd_pcm_ioplug_t *io);
/** /**
* set the channel map; optional; since v1.0.2 * set the channel map; optional; since v1.0.2
*/ */
int (*set_chmap)(snd_pcm_ioplug_t *io, const int *map); int (*set_chmap)(snd_pcm_ioplug_t *io, const snd_pcm_chmap_t *map);
}; };

View file

@ -7310,7 +7310,7 @@ OBSOLETE1(snd_pcm_sw_params_get_silence_size, ALSA_0.9, ALSA_0.9.0rc4);
* integer array, beginning with the channel map type, followed by the * integer array, beginning with the channel map type, followed by the
* number of channels, and the position of each channel. * number of channels, and the position of each channel.
*/ */
int **snd_pcm_query_chmaps(snd_pcm_t *pcm) snd_pcm_chmap_query_t **snd_pcm_query_chmaps(snd_pcm_t *pcm)
{ {
if (!pcm->ops->query_chmaps) if (!pcm->ops->query_chmaps)
return NULL; return NULL;
@ -7321,9 +7321,9 @@ int **snd_pcm_query_chmaps(snd_pcm_t *pcm)
* \!brief Release the channel map array allocated via #snd_pcm_query_chmaps * \!brief Release the channel map array allocated via #snd_pcm_query_chmaps
* \param maps the array pointer to release * \param maps the array pointer to release
*/ */
void snd_pcm_free_chmaps(int **maps) void snd_pcm_free_chmaps(snd_pcm_chmap_query_t **maps)
{ {
int **p; snd_pcm_chmap_query_t **p = maps;
if (!maps) if (!maps)
return; return;
for (p = maps; *p; p++) for (p = maps; *p; p++)
@ -7336,7 +7336,7 @@ void snd_pcm_free_chmaps(int **maps)
* \param pcm PCM instance * \param pcm PCM instance
* \return the current channel map, or NULL if error * \return the current channel map, or NULL if error
*/ */
int *snd_pcm_get_chmap(snd_pcm_t *pcm) snd_pcm_chmap_t *snd_pcm_get_chmap(snd_pcm_t *pcm)
{ {
if (!pcm->ops->get_chmap) if (!pcm->ops->get_chmap)
return NULL; return NULL;
@ -7349,7 +7349,7 @@ int *snd_pcm_get_chmap(snd_pcm_t *pcm)
* \param map the channel map to write * \param map the channel map to write
* \return zero if succeeded, or a negative error code * \return zero if succeeded, or a negative error code
*/ */
int snd_pcm_set_chmap(snd_pcm_t *pcm, const int *map) int snd_pcm_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
if (!pcm->ops->set_chmap) if (!pcm->ops->set_chmap)
return -ENXIO; return -ENXIO;

View file

@ -789,19 +789,19 @@ int snd_pcm_direct_munmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
return 0; return 0;
} }
int **snd_pcm_direct_query_chmaps(snd_pcm_t *pcm) snd_pcm_chmap_query_t **snd_pcm_direct_query_chmaps(snd_pcm_t *pcm)
{ {
snd_pcm_direct_t *dmix = pcm->private_data; snd_pcm_direct_t *dmix = pcm->private_data;
return snd_pcm_query_chmaps(dmix->spcm); return snd_pcm_query_chmaps(dmix->spcm);
} }
int *snd_pcm_direct_get_chmap(snd_pcm_t *pcm) snd_pcm_chmap_t *snd_pcm_direct_get_chmap(snd_pcm_t *pcm)
{ {
snd_pcm_direct_t *dmix = pcm->private_data; snd_pcm_direct_t *dmix = pcm->private_data;
return snd_pcm_get_chmap(dmix->spcm); return snd_pcm_get_chmap(dmix->spcm);
} }
int snd_pcm_direct_set_chmap(snd_pcm_t *pcm, const int *map) int snd_pcm_direct_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
snd_pcm_direct_t *dmix = pcm->private_data; snd_pcm_direct_t *dmix = pcm->private_data;
return snd_pcm_set_chmap(dmix->spcm, map); return snd_pcm_set_chmap(dmix->spcm, map);

View file

@ -296,9 +296,9 @@ void snd_pcm_direct_clear_timer_queue(snd_pcm_direct_t *dmix);
int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix); int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix);
int snd_pcm_direct_open_secondary_client(snd_pcm_t **spcmp, snd_pcm_direct_t *dmix, const char *client_name); int snd_pcm_direct_open_secondary_client(snd_pcm_t **spcmp, snd_pcm_direct_t *dmix, const char *client_name);
int **snd_pcm_direct_query_chmaps(snd_pcm_t *pcm); snd_pcm_chmap_query_t **snd_pcm_direct_query_chmaps(snd_pcm_t *pcm);
int *snd_pcm_direct_get_chmap(snd_pcm_t *pcm); snd_pcm_chmap_t *snd_pcm_direct_get_chmap(snd_pcm_t *pcm);
int snd_pcm_direct_set_chmap(snd_pcm_t *pcm, const int *map); int snd_pcm_direct_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);
int snd_timer_async(snd_timer_t *timer, int sig, pid_t pid); int snd_timer_async(snd_timer_t *timer, int sig, pid_t pid);
struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm); struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm);

View file

@ -425,7 +425,7 @@ static int snd_pcm_extplug_close(snd_pcm_t *pcm)
return 0; return 0;
} }
static int **snd_pcm_extplug_query_chmaps(snd_pcm_t *pcm) static snd_pcm_chmap_query_t **snd_pcm_extplug_query_chmaps(snd_pcm_t *pcm)
{ {
extplug_priv_t *ext = pcm->private_data; extplug_priv_t *ext = pcm->private_data;
@ -435,7 +435,7 @@ static int **snd_pcm_extplug_query_chmaps(snd_pcm_t *pcm)
return snd_pcm_generic_query_chmaps(pcm); return snd_pcm_generic_query_chmaps(pcm);
} }
static int *snd_pcm_extplug_get_chmap(snd_pcm_t *pcm) static snd_pcm_chmap_t *snd_pcm_extplug_get_chmap(snd_pcm_t *pcm)
{ {
extplug_priv_t *ext = pcm->private_data; extplug_priv_t *ext = pcm->private_data;
@ -445,7 +445,7 @@ static int *snd_pcm_extplug_get_chmap(snd_pcm_t *pcm)
return snd_pcm_generic_get_chmap(pcm); return snd_pcm_generic_get_chmap(pcm);
} }
static int snd_pcm_extplug_set_chmap(snd_pcm_t *pcm, const int *map) static int snd_pcm_extplug_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
extplug_priv_t *ext = pcm->private_data; extplug_priv_t *ext = pcm->private_data;

View file

@ -323,19 +323,19 @@ int snd_pcm_generic_munmap(snd_pcm_t *pcm)
return 0; return 0;
} }
int **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm) snd_pcm_chmap_query_t **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm)
{ {
snd_pcm_generic_t *generic = pcm->private_data; snd_pcm_generic_t *generic = pcm->private_data;
return snd_pcm_query_chmaps(generic->slave); return snd_pcm_query_chmaps(generic->slave);
} }
int *snd_pcm_generic_get_chmap(snd_pcm_t *pcm) snd_pcm_chmap_t *snd_pcm_generic_get_chmap(snd_pcm_t *pcm)
{ {
snd_pcm_generic_t *generic = pcm->private_data; snd_pcm_generic_t *generic = pcm->private_data;
return snd_pcm_get_chmap(generic->slave); return snd_pcm_get_chmap(generic->slave);
} }
int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const int *map) int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
snd_pcm_generic_t *generic = pcm->private_data; snd_pcm_generic_t *generic = pcm->private_data;
return snd_pcm_set_chmap(generic->slave, map); return snd_pcm_set_chmap(generic->slave, map);

View file

@ -155,8 +155,8 @@ int snd_pcm_generic_real_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
snd_htimestamp_t *tstamp); snd_htimestamp_t *tstamp);
int snd_pcm_generic_mmap(snd_pcm_t *pcm); int snd_pcm_generic_mmap(snd_pcm_t *pcm);
int snd_pcm_generic_munmap(snd_pcm_t *pcm); int snd_pcm_generic_munmap(snd_pcm_t *pcm);
int **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm); snd_pcm_chmap_query_t **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm);
int *snd_pcm_generic_get_chmap(snd_pcm_t *pcm); snd_pcm_chmap_t *snd_pcm_generic_get_chmap(snd_pcm_t *pcm);
int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const int *map); int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);

View file

@ -1045,13 +1045,13 @@ static void chmap_caps_set_error(snd_pcm_hw_t *hw, int type)
hw->chmap_caps |= (1 << (type + 8)); hw->chmap_caps |= (1 << (type + 8));
} }
static int **snd_pcm_hw_query_chmaps(snd_pcm_t *pcm) static snd_pcm_chmap_query_t **snd_pcm_hw_query_chmaps(snd_pcm_t *pcm)
{ {
snd_pcm_hw_t *hw = pcm->private_data; snd_pcm_hw_t *hw = pcm->private_data;
snd_ctl_t *ctl; snd_ctl_t *ctl;
snd_ctl_elem_id_t *id; snd_ctl_elem_id_t *id;
unsigned int tlv[256], *start; unsigned int tlv[256], *start;
int **map; snd_pcm_chmap_query_t **map;
int i, ret, nums; int i, ret, nums;
if (!chmap_caps(hw, CHMAP_CTL_QUERY)) if (!chmap_caps(hw, CHMAP_CTL_QUERY))
@ -1108,9 +1108,9 @@ static int **snd_pcm_hw_query_chmaps(snd_pcm_t *pcm)
snd_pcm_free_chmaps(map); snd_pcm_free_chmaps(map);
return NULL; return NULL;
} }
map[i][0] = start[0] - 0x100; map[i]->type = start[0] - 0x100;
map[i][1] = start[1] / 4; map[i]->map.channels = start[1] / 4;
memcpy(map[i] + 2, start + 2, start[1]); memcpy(map[i]->map.pos, start + 2, start[1]);
start += start[1] / 4 + 2; start += start[1] / 4 + 2;
} }
chmap_caps_set_ok(hw, CHMAP_CTL_QUERY); chmap_caps_set_ok(hw, CHMAP_CTL_QUERY);
@ -1121,10 +1121,10 @@ static int **snd_pcm_hw_query_chmaps(snd_pcm_t *pcm)
return NULL; return NULL;
} }
static int *snd_pcm_hw_get_chmap(snd_pcm_t *pcm) static snd_pcm_chmap_t *snd_pcm_hw_get_chmap(snd_pcm_t *pcm)
{ {
snd_pcm_hw_t *hw = pcm->private_data; snd_pcm_hw_t *hw = pcm->private_data;
int *map; snd_pcm_chmap_t *map;
snd_ctl_t *ctl; snd_ctl_t *ctl;
snd_ctl_elem_id_t *id; snd_ctl_elem_id_t *id;
snd_ctl_elem_value_t *val; snd_ctl_elem_value_t *val;
@ -1150,7 +1150,7 @@ static int *snd_pcm_hw_get_chmap(snd_pcm_t *pcm)
map = malloc(pcm->channels + 1); map = malloc(pcm->channels + 1);
if (!map) if (!map)
return NULL; return NULL;
*map = pcm->channels; map->channels = pcm->channels;
ret = snd_ctl_hw_open(&ctl, NULL, hw->card, 0); ret = snd_ctl_hw_open(&ctl, NULL, hw->card, 0);
if (ret < 0) { if (ret < 0) {
free(map); free(map);
@ -1171,24 +1171,25 @@ static int *snd_pcm_hw_get_chmap(snd_pcm_t *pcm)
return NULL; return NULL;
} }
for (i = 0; i < pcm->channels; i++) for (i = 0; i < pcm->channels; i++)
map[i + 1] = snd_ctl_elem_value_get_integer(val, i); map->pos[i] = snd_ctl_elem_value_get_integer(val, i);
chmap_caps_set_ok(hw, CHMAP_CTL_GET); chmap_caps_set_ok(hw, CHMAP_CTL_GET);
return map; return map;
} }
static int snd_pcm_hw_set_chmap(snd_pcm_t *pcm, const int *map) static int snd_pcm_hw_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
snd_pcm_hw_t *hw = pcm->private_data; snd_pcm_hw_t *hw = pcm->private_data;
snd_ctl_t *ctl; snd_ctl_t *ctl;
snd_ctl_elem_id_t *id; snd_ctl_elem_id_t *id;
snd_ctl_elem_value_t *val; snd_ctl_elem_value_t *val;
int i, ret; unsigned int i;
int ret;
if (!chmap_caps(hw, CHMAP_CTL_SET)) if (!chmap_caps(hw, CHMAP_CTL_SET))
return -ENXIO; return -ENXIO;
if (*map < 0 || *map > 128) { if (map->channels > 128) {
SYSMSG("Invalid number of channels %d\n", *map); SYSMSG("Invalid number of channels %d\n", map->channels);
return -EINVAL; return -EINVAL;
} }
if (FAST_PCM_STATE(hw) != SNDRV_PCM_STATE_PREPARED) { if (FAST_PCM_STATE(hw) != SNDRV_PCM_STATE_PREPARED) {
@ -1206,8 +1207,8 @@ static int snd_pcm_hw_set_chmap(snd_pcm_t *pcm, const int *map)
snd_ctl_elem_value_alloca(&val); snd_ctl_elem_value_alloca(&val);
fill_chmap_ctl_id(pcm, id); fill_chmap_ctl_id(pcm, id);
snd_ctl_elem_value_set_id(val, id); snd_ctl_elem_value_set_id(val, id);
for (i = 0; i < *map; i++) for (i = 0; i < map->channels; i++)
snd_ctl_elem_value_set_integer(val, i, map[i + 1]); snd_ctl_elem_value_set_integer(val, i, map->pos[i]);
ret = snd_ctl_elem_write(ctl, val); ret = snd_ctl_elem_write(ctl, val);
snd_ctl_close(ctl); snd_ctl_close(ctl);
if (ret >= 0) if (ret >= 0)

View file

@ -710,7 +710,7 @@ static int snd_pcm_ioplug_munmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
return 0; return 0;
} }
static int **snd_pcm_ioplug_query_chmaps(snd_pcm_t *pcm) static snd_pcm_chmap_query_t **snd_pcm_ioplug_query_chmaps(snd_pcm_t *pcm)
{ {
ioplug_priv_t *io = pcm->private_data; ioplug_priv_t *io = pcm->private_data;
@ -720,7 +720,7 @@ static int **snd_pcm_ioplug_query_chmaps(snd_pcm_t *pcm)
return NULL; return NULL;
} }
static int *snd_pcm_ioplug_get_chmap(snd_pcm_t *pcm) static snd_pcm_chmap_t *snd_pcm_ioplug_get_chmap(snd_pcm_t *pcm)
{ {
ioplug_priv_t *io = pcm->private_data; ioplug_priv_t *io = pcm->private_data;
@ -730,7 +730,7 @@ static int *snd_pcm_ioplug_get_chmap(snd_pcm_t *pcm)
return NULL; return NULL;
} }
static int snd_pcm_ioplug_set_chmap(snd_pcm_t *pcm, const int *map) static int snd_pcm_ioplug_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
ioplug_priv_t *io = pcm->private_data; ioplug_priv_t *io = pcm->private_data;

View file

@ -143,9 +143,9 @@ typedef struct {
void (*dump)(snd_pcm_t *pcm, snd_output_t *out); void (*dump)(snd_pcm_t *pcm, snd_output_t *out);
int (*mmap)(snd_pcm_t *pcm); int (*mmap)(snd_pcm_t *pcm);
int (*munmap)(snd_pcm_t *pcm); int (*munmap)(snd_pcm_t *pcm);
int **(*query_chmaps)(snd_pcm_t *pcm); snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_t *pcm);
int *(*get_chmap)(snd_pcm_t *pcm); snd_pcm_chmap_t *(*get_chmap)(snd_pcm_t *pcm);
int (*set_chmap)(snd_pcm_t *pcm, const int *map); int (*set_chmap)(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);
} snd_pcm_ops_t; } snd_pcm_ops_t;
typedef struct { typedef struct {

View file

@ -739,10 +739,10 @@ static int snd_pcm_multi_mmap(snd_pcm_t *pcm)
return 0; return 0;
} }
static int *snd_pcm_multi_get_chmap(snd_pcm_t *pcm) static snd_pcm_chmap_t *snd_pcm_multi_get_chmap(snd_pcm_t *pcm)
{ {
snd_pcm_multi_t *multi = pcm->private_data; snd_pcm_multi_t *multi = pcm->private_data;
int *map; snd_pcm_chmap_t *map;
unsigned int i, idx; unsigned int i, idx;
map = malloc(pcm->channels + 4); map = malloc(pcm->channels + 4);
@ -750,34 +750,37 @@ static int *snd_pcm_multi_get_chmap(snd_pcm_t *pcm)
return NULL; return NULL;
idx = 0; idx = 0;
for (i = 0; i < multi->slaves_count; ++i) { for (i = 0; i < multi->slaves_count; ++i) {
int c, *slave_map; unsigned int c;
snd_pcm_chmap_t *slave_map;
slave_map = snd_pcm_get_chmap(multi->slaves[i].pcm); slave_map = snd_pcm_get_chmap(multi->slaves[i].pcm);
if (!slave_map) { if (!slave_map) {
free(map); free(map);
return NULL; return NULL;
} }
for (c = 0; c < *slave_map; c++) { for (c = 0; c < slave_map->channels; c++) {
if (idx >= pcm->channels) if (idx >= pcm->channels)
break; break;
map[idx++] = slave_map[c + 1]; map->pos[idx++] = slave_map->pos[c];
} }
free(slave_map); free(slave_map);
} }
return map; return map;
} }
static int snd_pcm_multi_set_chmap(snd_pcm_t *pcm, const int *map) static int snd_pcm_multi_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{ {
snd_pcm_multi_t *multi = pcm->private_data; snd_pcm_multi_t *multi = pcm->private_data;
const unsigned int *pos;
unsigned int i, idx, chs; unsigned int i, idx, chs;
int err; int err;
chs = *map; chs = map->channels;
if (chs != pcm->channels) if (chs != pcm->channels)
return -EINVAL; return -EINVAL;
map++; pos = map->pos;
idx = 0;
for (i = 0; i < multi->slaves_count; ++i) { for (i = 0; i < multi->slaves_count; ++i) {
int *slave_map; snd_pcm_chmap_t *slave_map;
unsigned int slave_chs; unsigned int slave_chs;
slave_chs = multi->slaves[i].channels_count; slave_chs = multi->slaves[i].channels_count;
if (idx + slave_chs > chs) if (idx + slave_chs > chs)
@ -785,8 +788,8 @@ static int snd_pcm_multi_set_chmap(snd_pcm_t *pcm, const int *map)
slave_map = malloc(slave_chs * 4 + 4); slave_map = malloc(slave_chs * 4 + 4);
if (!slave_map) if (!slave_map)
return -ENOMEM; return -ENOMEM;
*slave_map = slave_chs; slave_map->channels = slave_chs;
memcpy(slave_map, map + idx, slave_chs * 4); memcpy(slave_map->pos, pos + idx, slave_chs * 4);
err = snd_pcm_set_chmap(multi->slaves[i].pcm, slave_map); err = snd_pcm_set_chmap(multi->slaves[i].pcm, slave_map);
free(slave_map); free(slave_map);
if (err < 0) if (err < 0)

View file

@ -703,10 +703,10 @@ snd_pcm_route_read_areas(snd_pcm_t *pcm,
return size; return size;
} }
static int *snd_pcm_route_get_chmap(snd_pcm_t *pcm) static snd_pcm_chmap_t *snd_pcm_route_get_chmap(snd_pcm_t *pcm)
{ {
snd_pcm_route_t *route = pcm->private_data; snd_pcm_route_t *route = pcm->private_data;
int *map, *slave_map; snd_pcm_chmap_t *map, *slave_map;
unsigned int src, dst; unsigned int src, dst;
slave_map = snd_pcm_generic_get_chmap(pcm); slave_map = snd_pcm_generic_get_chmap(pcm);
@ -717,13 +717,13 @@ static int *snd_pcm_route_get_chmap(snd_pcm_t *pcm)
free(slave_map); free(slave_map);
return NULL; return NULL;
} }
*map = route->schannels; map->channels = route->schannels;
for (dst = 0; dst < route->params.ndsts; dst++) { for (dst = 0; dst < route->params.ndsts; dst++) {
snd_pcm_route_ttable_dst_t *d = &route->params.dsts[dst]; snd_pcm_route_ttable_dst_t *d = &route->params.dsts[dst];
for (src = 0; src < d->nsrcs; src++) { for (src = 0; src < d->nsrcs; src++) {
int c = d->srcs[src].channel; int c = d->srcs[src].channel;
if (c < route->schannels && !map[c + 1]) if (c < route->schannels && !map->pos[c])
map[c + 1] = slave_map[dst + 1]; map->pos[c] = slave_map->pos[dst];
} }
} }
free(slave_map); free(slave_map);

View file

@ -31,13 +31,14 @@ static const char * const chname[] = {
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
static void print_channels(int channels, int *map) static void print_channels(const snd_pcm_chmap_t *map)
{ {
int i; unsigned int i;
printf(" "); printf(" ");
for (i = 0; i < channels; i++) { for (i = 0; i < map->channels; i++) {
unsigned int c = *map++; unsigned int c = map->pos[i];
unsigned int pos = c & SND_CHMAP_POSITION_MASK; unsigned int p = c & SND_CHMAP_POSITION_MASK;
if (c & SND_CHMAP_DRIVER_SPEC) if (c & SND_CHMAP_DRIVER_SPEC)
printf(" %d", p); printf(" %d", p);
else if (p >= ARRAY_SIZE(chname)) else if (p >= ARRAY_SIZE(chname))
@ -80,16 +81,16 @@ static const char *chmap_type(int type)
static int query_chmaps(snd_pcm_t *pcm) static int query_chmaps(snd_pcm_t *pcm)
{ {
int **maps = snd_pcm_query_chmaps(pcm); snd_pcm_chmap_query_t **maps = snd_pcm_query_chmaps(pcm);
int **p, *v; snd_pcm_chmap_query_t **p, *v;
if (!maps) { if (!maps) {
printf("Cannot query maps\n"); printf("Cannot query maps\n");
return 1; return 1;
} }
for (p = maps; (v = *p) != NULL; p++) { for (p = maps; (v = *p) != NULL; p++) {
printf("Type = %s, Channels = %d\n", chmap_type(v[0]), v[1]); printf("Type = %s, Channels = %d\n", chmap_type(v->type), v->map.channels);
print_channels(v[1], v + 2); print_channels(&v->map);
} }
snd_pcm_free_chmaps(maps); snd_pcm_free_chmaps(maps);
return 0; return 0;
@ -132,7 +133,7 @@ static int setup_pcm(snd_pcm_t *pcm, int format, int channels, int rate)
static int get_chmap(snd_pcm_t *pcm, int format, int channels, int rate) static int get_chmap(snd_pcm_t *pcm, int format, int channels, int rate)
{ {
int *map; snd_pcm_chmap_t *map;
if (setup_pcm(pcm, format, channels, rate)) if (setup_pcm(pcm, format, channels, rate))
return 1; return 1;
@ -141,8 +142,8 @@ static int get_chmap(snd_pcm_t *pcm, int format, int channels, int rate)
printf("Cannot get chmap\n"); printf("Cannot get chmap\n");
return 1; return 1;
} }
printf("Channels = %d\n", *map); printf("Channels = %d\n", map->channels);
print_channels(*map, map + 1); print_channels(map);
free(map); free(map);
return 0; return 0;
} }
@ -151,7 +152,7 @@ static int set_chmap(snd_pcm_t *pcm, int format, int channels, int rate,
int nargs, char **arg) int nargs, char **arg)
{ {
int i; int i;
int *map; snd_pcm_chmap_t *map;
if (channels && channels != nargs) { if (channels && channels != nargs) {
printf("Inconsistent channels %d vs %d\n", channels, nargs); printf("Inconsistent channels %d vs %d\n", channels, nargs);
@ -171,9 +172,9 @@ static int set_chmap(snd_pcm_t *pcm, int format, int channels, int rate,
printf("cannot malloc\n"); printf("cannot malloc\n");
return 1; return 1;
} }
*map = channels; map->channels = channels;
for (i = 0; i < channels; i++) for (i = 0; i < channels; i++)
map[i + 1] = to_channel(arg[i]); map->pos[i] = to_channel(arg[i]);
if (snd_pcm_set_chmap(pcm, map) < 0) { if (snd_pcm_set_chmap(pcm, map) < 0) {
printf("Cannot set chmap\n"); printf("Cannot set chmap\n");
return 1; return 1;
@ -185,8 +186,8 @@ static int set_chmap(snd_pcm_t *pcm, int format, int channels, int rate,
printf("Cannot get chmap\n"); printf("Cannot get chmap\n");
return 1; return 1;
} }
printf("Get channels = %d\n", *map); printf("Get channels = %d\n", map->channels);
print_channels(*map, map + 1); print_channels(map);
free(map); free(map);
return 0; return 0;
} }