From 5b9db5b8889498581a9d719400b1279a3babb444 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 15:57:09 -0800 Subject: Added const specifier to params functions Funtions changed are: - pcm_params_get_mask - pcm_params_get_min - pcm_params_get_max --- include/tinyalsa/pcm.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index 3d9dfaa..1f02e9d 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -223,11 +223,11 @@ struct pcm_params *pcm_params_get(unsigned int card, unsigned int device, void pcm_params_free(struct pcm_params *pcm_params); -struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params, enum pcm_param param); +const struct pcm_mask *pcm_params_get_mask(const struct pcm_params *pcm_params, enum pcm_param param); -unsigned int pcm_params_get_min(struct pcm_params *pcm_params, enum pcm_param param); +unsigned int pcm_params_get_min(const struct pcm_params *pcm_params, enum pcm_param param); -unsigned int pcm_params_get_max(struct pcm_params *pcm_params, enum pcm_param param); +unsigned int pcm_params_get_max(const struct pcm_params *pcm_params, enum pcm_param param); struct pcm; -- cgit v1.2.3 From 2f387d2aa149118bec4c436056fc06d7c2f427c4 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 15:58:16 -0800 Subject: Added const specifier in several functions Functions changed are: - pcm_params_get_mask - pcm_params_get_min - pcm_params_get_max - param_get_mask - param_get_min - param_get_max --- src/pcm.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/pcm.c b/src/pcm.c index 1ce1a54..73debb4 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -64,6 +64,11 @@ static inline int param_is_interval(int p) (p <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL); } +static inline const struct snd_interval *param_get_interval(const struct snd_pcm_hw_params *p, int n) +{ + return &(p->intervals[n - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]); +} + static inline struct snd_interval *param_to_interval(struct snd_pcm_hw_params *p, int n) { return &(p->intervals[n - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]); @@ -94,19 +99,19 @@ static void param_set_min(struct snd_pcm_hw_params *p, int n, unsigned int val) } } -static unsigned int param_get_min(struct snd_pcm_hw_params *p, int n) +static unsigned int param_get_min(const struct snd_pcm_hw_params *p, int n) { if (param_is_interval(n)) { - struct snd_interval *i = param_to_interval(p, n); + const struct snd_interval *i = param_get_interval(p, n); return i->min; } return 0; } -static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n) +static unsigned int param_get_max(const struct snd_pcm_hw_params *p, int n) { if (param_is_interval(n)) { - struct snd_interval *i = param_to_interval(p, n); + const struct snd_interval *i = param_get_interval(p, n); return i->max; } return 0; @@ -696,7 +701,7 @@ static int pcm_param_to_alsa(enum pcm_param param) * Otherwise, the mask associated with @p param is returned. * @ingroup libtinyalsa-pcm */ -struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params, +const struct pcm_mask *pcm_params_get_mask(const struct pcm_params *pcm_params, enum pcm_param param) { int p; @@ -710,7 +715,7 @@ struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params, return NULL; } - return (struct pcm_mask *)param_to_mask(params, p); + return (const struct pcm_mask *)param_to_mask(params, p); } /** Get the minimum of a specified PCM parameter. @@ -719,7 +724,7 @@ struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params, * @returns On success, the parameter minimum. * On failure, zero. */ -unsigned int pcm_params_get_min(struct pcm_params *pcm_params, +unsigned int pcm_params_get_min(const struct pcm_params *pcm_params, enum pcm_param param) { struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params; @@ -741,10 +746,10 @@ unsigned int pcm_params_get_min(struct pcm_params *pcm_params, * @returns On success, the parameter maximum. * On failure, zero. */ -unsigned int pcm_params_get_max(struct pcm_params *pcm_params, +unsigned int pcm_params_get_max(const struct pcm_params *pcm_params, enum pcm_param param) { - struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params; + const struct snd_pcm_hw_params *params = (const struct snd_pcm_hw_params *)pcm_params; int p; if (!params) -- cgit v1.2.3 From 319a84845148f562f21d309b294d8ed1b7d86262 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 15:59:17 -0800 Subject: Added const specifier to mask The changed was brought on by to early commits to the PCM API. --- utils/tinypcminfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/tinypcminfo.c b/utils/tinypcminfo.c index 5b8db1f..0dd381d 100644 --- a/utils/tinypcminfo.c +++ b/utils/tinypcminfo.c @@ -129,7 +129,7 @@ int main(int argc, char **argv) for (i = 0; i < 2; i++) { struct pcm_params *params; - struct pcm_mask *m; + const struct pcm_mask *m; unsigned int min; unsigned int max; -- cgit v1.2.3 From ba285cfbf416af5fbda1040e3c3ce74165e3e11c Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 16:06:29 -0800 Subject: Added const specifier in pcm_open The const specifier was added to the struct pcm_config argument. --- include/tinyalsa/pcm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index 1f02e9d..c2c67bb 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -234,7 +234,7 @@ struct pcm; struct pcm *pcm_open(unsigned int card, unsigned int device, unsigned int flags, - struct pcm_config *config); + const struct pcm_config *config); int pcm_close(struct pcm *pcm); -- cgit v1.2.3 From 94803b005511f8baf3281ec4e922be99f62b4186 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 16:07:14 -0800 Subject: Added const specifier in pcm_open Added const specifier to the struct pcm_config argument. Changed the way default values of the config structure are set and accessed. They're accessed through the pointer from the argument list and set through the pointer in the pcm structure. --- src/pcm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pcm.c b/src/pcm.c index 73debb4..29c69a7 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -808,7 +808,7 @@ int pcm_close(struct pcm *pcm) * @ingroup libtinyalsa-pcm */ struct pcm *pcm_open(unsigned int card, unsigned int device, - unsigned int flags, struct pcm_config *config) + unsigned int flags, const struct pcm_config *config) { struct pcm *pcm; struct snd_pcm_info info; @@ -823,14 +823,14 @@ struct pcm *pcm_open(unsigned int card, unsigned int device, if (config == NULL) { config = &pcm->config; - config->channels = 2; - config->rate = 48000; - config->period_size = 1024; - config->period_count = 4; - config->format = PCM_FORMAT_S16_LE; - config->start_threshold = config->period_count * config->period_size; - config->stop_threshold = config->period_count * config->period_size; - config->silence_threshold = 0; + pcm->config.channels = 2; + pcm->config.rate = 48000; + pcm->config.period_size = 1024; + pcm->config.period_count = 4; + pcm->config.format = PCM_FORMAT_S16_LE; + pcm->config.start_threshold = config->period_count * config->period_size; + pcm->config.stop_threshold = config->period_count * config->period_size; + pcm->config.silence_threshold = 0; } else { pcm->config = *config; } @@ -890,8 +890,8 @@ struct pcm *pcm_open(unsigned int card, unsigned int device, } /* get our refined hw_params */ - config->period_size = param_get_int(¶ms, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); - config->period_count = param_get_int(¶ms, SNDRV_PCM_HW_PARAM_PERIODS); + pcm->config.period_size = param_get_int(¶ms, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); + pcm->config.period_count = param_get_int(¶ms, SNDRV_PCM_HW_PARAM_PERIODS); pcm->buffer_size = config->period_count * config->period_size; if (flags & PCM_MMAP) { -- cgit v1.2.3 From 15d58481e7633281e4d13fdabd12e1cec2605752 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 17:46:29 -0800 Subject: added const specifier in function, pcm_is_ready --- include/tinyalsa/pcm.h | 2 +- src/pcm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index c2c67bb..caa4d1f 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -238,7 +238,7 @@ struct pcm *pcm_open(unsigned int card, int pcm_close(struct pcm *pcm); -int pcm_is_ready(struct pcm *pcm); +int pcm_is_ready(const struct pcm *pcm); int pcm_get_file_descriptor(struct pcm *pcm); diff --git a/src/pcm.c b/src/pcm.c index 29c69a7..c32e8ab 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -979,7 +979,7 @@ fail_close: * Otherwise, the function returns one. * @ingroup libtinyalsa-pcm */ -int pcm_is_ready(struct pcm *pcm) +int pcm_is_ready(const struct pcm *pcm) { return pcm->fd >= 0; } -- cgit v1.2.3 From 147d7adec6ff293be328d6da2eb0d8d2419e9b34 Mon Sep 17 00:00:00 2001 From: Taylor Holberton Date: Thu, 1 Dec 2016 17:50:31 -0800 Subject: Added const specifier in several functions pcm_get_file_descriptor pcm_get_error pcm_get_buffer_size pcm_frames_to_bytes pcm_bytes_to_frames pcm_get_subdevice --- include/tinyalsa/pcm.h | 12 ++++++------ src/pcm.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index caa4d1f..a6c95ce 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -240,21 +240,21 @@ int pcm_close(struct pcm *pcm); int pcm_is_ready(const struct pcm *pcm); -int pcm_get_file_descriptor(struct pcm *pcm); +int pcm_get_file_descriptor(const struct pcm *pcm); -const char *pcm_get_error(struct pcm *pcm); +const char *pcm_get_error(const struct pcm *pcm); unsigned int pcm_format_to_bits(enum pcm_format format); -unsigned int pcm_get_buffer_size(struct pcm *pcm); +unsigned int pcm_get_buffer_size(const struct pcm *pcm); -unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames); +unsigned int pcm_frames_to_bytes(const struct pcm *pcm, unsigned int frames); -unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes); +unsigned int pcm_bytes_to_frames(const struct pcm *pcm, unsigned int bytes); int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail, struct timespec *tstamp); -unsigned int pcm_get_subdevice(struct pcm *pcm); +unsigned int pcm_get_subdevice(const struct pcm *pcm); int pcm_write(struct pcm *pcm, const void *data, unsigned int count); diff --git a/src/pcm.c b/src/pcm.c index c32e8ab..540fd72 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -199,7 +199,7 @@ struct pcm { * @return The buffer size of the PCM. * @ingroup libtinyalsa-pcm */ -unsigned int pcm_get_buffer_size(struct pcm *pcm) +unsigned int pcm_get_buffer_size(const struct pcm *pcm) { return pcm->buffer_size; } @@ -210,7 +210,7 @@ unsigned int pcm_get_buffer_size(struct pcm *pcm) * @return The file descriptor of the PCM. * @ingroup libtinyalsa-pcm */ -int pcm_get_file_descriptor(struct pcm *pcm) +int pcm_get_file_descriptor(const struct pcm *pcm) { return pcm->fd; } @@ -221,7 +221,7 @@ int pcm_get_file_descriptor(struct pcm *pcm) * @return The error message of the last error that occured. * @ingroup libtinyalsa-pcm */ -const char* pcm_get_error(struct pcm *pcm) +const char* pcm_get_error(const struct pcm *pcm) { return pcm->error; } @@ -229,7 +229,7 @@ const char* pcm_get_error(struct pcm *pcm) /** Gets the subdevice on which the pcm has been opened. * @param pcm A PCM handle. * @return The subdevice on which the pcm has been opened */ -unsigned int pcm_get_subdevice(struct pcm *pcm) +unsigned int pcm_get_subdevice(const struct pcm *pcm) { return pcm->subdevice; } @@ -311,7 +311,7 @@ unsigned int pcm_format_to_bits(enum pcm_format format) * @return The number of frames that may fit into @p bytes * @ingroup libtinyalsa-pcm */ -unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes) +unsigned int pcm_bytes_to_frames(const struct pcm *pcm, unsigned int bytes) { return bytes / (pcm->config.channels * (pcm_format_to_bits(pcm->config.format) >> 3)); @@ -323,7 +323,7 @@ unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes) * @return The bytes occupied by @p frames. * @ingroup libtinyalsa-pcm */ -unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames) +unsigned int pcm_frames_to_bytes(const struct pcm *pcm, unsigned int frames) { return frames * pcm->config.channels * (pcm_format_to_bits(pcm->config.format) >> 3); -- cgit v1.2.3