Control API - add TLV support

snd_ctl_elem_tlv_read
snd_ctl_elem_tlv_write
snd_ctl_elem_tlv_command
snd_ctl_elem_info_is_tlv_readable
snd_ctl_elem_info_is_tlv_writable
snd_ctl_elem_info_is_tlv_commandable
snd_hctl_elem_tlv_read
snd_hctl_elem_tlv_write
snd_hctl_elem_tlv_command
This commit is contained in:
Jaroslav Kysela 2006-07-05 17:42:16 +02:00
parent 408697bfe2
commit c7a0708a23
7 changed files with 248 additions and 4 deletions

View file

@ -404,7 +404,9 @@ int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
* \brief Set CTL element value
* \param ctl CTL handle
* \param control CTL element id/value pointer
* \return 0 on success otherwise a negative error code
* \retval 0 on success
* \retval >0 on success when value was changed
* \retval <0 a negative error code
*/
int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
{
@ -412,6 +414,83 @@ int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
return ctl->ops->element_write(ctl, control);
}
static int snd_ctl_tlv_do(snd_ctl_t *ctl, int op_flag,
const snd_ctl_elem_id_t *id,
unsigned int *tlv, unsigned int tlv_size)
{
snd_ctl_elem_info_t *info = NULL;
int err;
if (id->numid == 0) {
info = calloc(1, sizeof(*info));
if (info == NULL)
return -ENOMEM;
info->id = *id;
id = &info->id;
err = snd_ctl_elem_info(ctl, info);
if (err < 0)
goto __err;
if (id->numid == 0) {
err = -ENOENT;
goto __err;
}
}
err = ctl->ops->element_tlv(ctl, op_flag, id->numid, tlv, tlv_size);
__err:
if (info)
free(info);
return err;
}
/**
* \brief Get CTL element TLV value
* \param ctl CTL handle
* \param id CTL element id pointer
* \param tlv TLV array pointer to store
* \param tlv_size TLV array size in bytes
* \return 0 on success otherwise a negative error code
*/
int snd_ctl_elem_tlv_read(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
unsigned int *tlv, unsigned int tlv_size)
{
assert(ctl && id && (id->name[0] || id->numid) && tlv);
return snd_ctl_tlv_do(ctl, 0, id, tlv, tlv_size);
}
/**
* \brief Set CTL element TLV value
* \param ctl CTL handle
* \param id CTL element id pointer
* \param tlv TLV array pointer to store
* \retval 0 on success
* \retval >0 on success when value was changed
* \retval <0 a negative error code
*/
int snd_ctl_elem_tlv_write(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
const unsigned int *tlv)
{
assert(ctl && id && (id->name[0] || id->numid) && tlv);
return snd_ctl_tlv_do(ctl, 1, id, (unsigned int *)tlv, tlv[1] + 2 * sizeof(unsigned int));
}
/**
* \brief Process CTL element TLV command
* \param ctl CTL handle
* \param id CTL element id pointer
* \param tlv TLV array pointer to process
* \retval 0 on success
* \retval >0 on success when value was changed
* \retval <0 a negative error code
*/
int snd_ctl_elem_tlv_command(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
const unsigned int *tlv)
{
assert(ctl && id && (id->name[0] || id->numid) && tlv);
return snd_ctl_tlv_do(ctl, -1, id, (unsigned int *)tlv, tlv[1] + 2 * sizeof(unsigned int));
}
/**
* \brief Lock CTL element
* \param ctl CTL handle
@ -1741,6 +1820,39 @@ int snd_ctl_elem_info_is_user(const snd_ctl_elem_info_t *obj)
return !!(obj->access & SNDRV_CTL_ELEM_ACCESS_USER);
}
/**
* \brief Get info about TLV readability from a CTL element id/info
* \param obj CTL element id/info
* \return 0 if element's TLV is not readable, 1 if element's TLV is readable
*/
int snd_ctl_elem_info_is_tlv_readable(const snd_ctl_elem_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ);
}
/**
* \brief Get info about TLV writeability from a CTL element id/info
* \param obj CTL element id/info
* \return 0 if element's TLV is not writable, 1 if element's TLV is writable
*/
int snd_ctl_elem_info_is_tlv_writable(const snd_ctl_elem_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE);
}
/**
* \brief Get info about TLV command possibility from a CTL element id/info
* \param obj CTL element id/info
* \return 0 if element's TLV command is not possible, 1 if element's TLV command is supported
*/
int snd_ctl_elem_info_is_tlv_commandable(const snd_ctl_elem_info_t *obj)
{
assert(obj);
return !!(obj->access & SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND);
}
/**
* \brief (DEPRECATED) Get info about values passing policy from a CTL element value
* \param obj CTL element id/info