All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 01/34] pcm: change code formatting for snd_pcm_set_params()
Date: Thu, 14 Jul 2016 23:07:18 +0900	[thread overview]
Message-ID: <1468505271-5769-2-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1468505271-5769-1-git-send-email-o-takashi@sakamocchi.jp>

This commit applies code format according to typical and moderate rule,
for snd_pcm_set_params().

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/pcm/pcm.c | 193 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 114 insertions(+), 79 deletions(-)

diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
index 6c34719..64f841d 100644
--- a/src/pcm/pcm.c
+++ b/src/pcm/pcm.c
@@ -8291,142 +8291,177 @@ int snd_pcm_set_params(snd_pcm_t *pcm,
                        int soft_resample,
                        unsigned int latency)
 {
-        snd_pcm_hw_params_t *params, params_saved;
-        snd_pcm_sw_params_t *swparams;
-        const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
-        snd_pcm_uframes_t buffer_size, period_size;
-        unsigned int rrate, period_time;
-        int err;
+	snd_pcm_hw_params_t *params, params_saved;
+	snd_pcm_sw_params_t *swparams;
+	const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
+	snd_pcm_uframes_t buffer_size, period_size;
+	unsigned int rrate, period_time;
+	int err;
 
-        snd_pcm_hw_params_alloca(&params);
-        snd_pcm_sw_params_alloca(&swparams);
+	snd_pcm_hw_params_alloca(&params);
+	snd_pcm_sw_params_alloca(&swparams);
 
 	assert(pcm);
 	/* choose all parameters */
 	err = snd_pcm_hw_params_any(pcm, params);
 	if (err < 0) {
-	        SNDERR("Broken configuration for %s: no configurations available", s);
-	        return err;
-        }
-        /* set software resampling */
-        err = snd_pcm_hw_params_set_rate_resample(pcm, params, soft_resample);
-        if (err < 0) {
-                SNDERR("Resampling setup failed for %s: %s", s, snd_strerror(err));
-                return err;
+		SNDERR("Broken configuration for %s: no configurations available",
+		       s);
+		return err;
         }
+	/* set software resampling */
+	err = snd_pcm_hw_params_set_rate_resample(pcm, params, soft_resample);
+	if (err < 0) {
+		SNDERR("Resampling setup failed for %s: %s",
+		       s, snd_strerror(err));
+		return err;
+	}
 	/* set the selected read/write format */
 	err = snd_pcm_hw_params_set_access(pcm, params, access);
 	if (err < 0) {
-		SNDERR("Access type not available for %s: %s", s, snd_strerror(err));
+		SNDERR("Access type not available for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
 	/* set the sample format */
 	err = snd_pcm_hw_params_set_format(pcm, params, format);
 	if (err < 0) {
-		SNDERR("Sample format not available for %s: %s", s, snd_strerror(err));
+		SNDERR("Sample format not available for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
 	/* set the count of channels */
 	err = snd_pcm_hw_params_set_channels(pcm, params, channels);
 	if (err < 0) {
-		SNDERR("Channels count (%i) not available for %s: %s", channels, s, snd_strerror(err));
+		SNDERR("Channels count (%i) not available for %s: %s",
+		       channels, s, snd_strerror(err));
 		return err;
 	}
 	/* set the stream rate */
 	rrate = rate;
 	err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, params, &rrate, 0);
 	if (err < 0) {
-		SNDERR("Rate %iHz not available for playback: %s", rate, snd_strerror(err));
+		SNDERR("Rate %iHz not available for playback: %s",
+		       rate, snd_strerror(err));
 		return err;
 	}
 	if (rrate != rate) {
-		SNDERR("Rate doesn't match (requested %iHz, get %iHz)", rate, rrate);
+		SNDERR("Rate doesn't match (requested %iHz, get %iHz)",
+		       rate, rrate);
 		return -EINVAL;
 	}
 	/* set the buffer time */
 	params_saved = *params;
-	err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params, &latency, NULL);
+	err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params,
+							&latency, NULL);
 	if (err < 0) {
-	        /* error path -> set period size as first */
+		/* error path -> set period size as first */
 		*params = params_saved;
-        	/* set the period time */
-        	period_time = latency / 4;
-        	err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL);
-        	if (err < 0) {
-        		SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err));
-        		return err;
-        	}
-                err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &period_size, NULL);
-                if (err < 0) {
-                	SNDERR("Unable to get period size for %s: %s", s, snd_strerror(err));
-                	return err;
-        	}
-        	buffer_size = period_size * 4;
-        	err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm, params, &buffer_size);
-                if (err < 0) {
-                	SNDERR("Unable to set buffer size %lu %s: %s", buffer_size, s, snd_strerror(err));
-                	return err;
-        	}
-        	err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &buffer_size);
-        	if (err < 0) {
-        		SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err));
-        		return err;
-        	}
+		/* set the period time */
+		period_time = latency / 4;
+		err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
+						params, &period_time, NULL);
+		if (err < 0) {
+			SNDERR("Unable to set period time %i for %s: %s",
+			       period_time, s, snd_strerror(err));
+			return err;
+		}
+		err = INTERNAL(snd_pcm_hw_params_get_period_size)(params,
+							&period_size, NULL);
+		if (err < 0) {
+			SNDERR("Unable to get period size for %s: %s",
+							s, snd_strerror(err));
+			return err;
+		}
+		buffer_size = period_size * 4;
+		err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
+							params, &buffer_size);
+		if (err < 0) {
+			SNDERR("Unable to set buffer size %lu %s: %s",
+					buffer_size, s, snd_strerror(err));
+			return err;
+		}
+		err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params,
+								&buffer_size);
+		if (err < 0) {
+			SNDERR("Unable to get buffer size for %s: %s",
+			       s, snd_strerror(err));
+			return err;
+		}
 	} else {
-	        /* standard configuration buffer_time -> periods */
-        	err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &buffer_size);
-        	if (err < 0) {
-        		SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err));
-        		return err;
-        	}
-        	err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(params, &latency, NULL);
-        	if (err < 0) {
-        		SNDERR("Unable to get buffer time (latency) for %s: %s", s, snd_strerror(err));
-        		return err;
-        	}
-        	/* set the period time */
-        	period_time = latency / 4;
-        	err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL);
-        	if (err < 0) {
-        		SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err));
-        		return err;
-        	}
-                err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &period_size, NULL);
-                if (err < 0) {
-                	SNDERR("Unable to get period size for %s: %s", s, snd_strerror(err));
-                	return err;
-        	}
-        }
+		/* standard configuration buffer_time -> periods */
+		err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params,
+								&buffer_size);
+		if (err < 0) {
+			SNDERR("Unable to get buffer size for %s: %s",
+							s, snd_strerror(err));
+			return err;
+		}
+		err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(params,
+							&latency, NULL);
+		if (err < 0) {
+			SNDERR("Unable to get buffer time (latency) for %s: %s",
+			       s, snd_strerror(err));
+			return err;
+		}
+		/* set the period time */
+		period_time = latency / 4;
+		err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
+						params, &period_time, NULL);
+		if (err < 0) {
+			SNDERR("Unable to set period time %i for %s: %s",
+			       period_time, s, snd_strerror(err));
+			return err;
+		}
+		err = INTERNAL(snd_pcm_hw_params_get_period_size)(params,
+							&period_size, NULL);
+		if (err < 0) {
+			SNDERR("Unable to get period size for %s: %s",
+			       s, snd_strerror(err));
+			return err;
+		}
+	}
 	/* write the parameters to device */
 	err = snd_pcm_hw_params(pcm, params);
 	if (err < 0) {
-		SNDERR("Unable to set hw params for %s: %s", s, snd_strerror(err));
+		SNDERR("Unable to set hw params for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
 
 	/* get the current swparams */
 	err = snd_pcm_sw_params_current(pcm, swparams);
 	if (err < 0) {
-		SNDERR("Unable to determine current swparams for %s: %s", s, snd_strerror(err));
+		SNDERR("Unable to determine current swparams for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
-	/* start the transfer when the buffer is almost full: */
-	/* (buffer_size / avail_min) * avail_min */
-	err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, (buffer_size / period_size) * period_size);
+	/*
+	 * start the transfer when the buffer is almost full:
+	 * (buffer_size / avail_min) * avail_min
+	 */
+	err = snd_pcm_sw_params_set_start_threshold(pcm, swparams,
+				(buffer_size / period_size) * period_size);
 	if (err < 0) {
-		SNDERR("Unable to set start threshold mode for %s: %s", s, snd_strerror(err));
+		SNDERR("Unable to set start threshold mode for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
-	/* allow the transfer when at least period_size samples can be processed */
+	/*
+	 * allow the transfer when at least period_size samples can be
+	 * processed
+	 */
 	err = snd_pcm_sw_params_set_avail_min(pcm, swparams, period_size);
 	if (err < 0) {
-		SNDERR("Unable to set avail min for %s: %s", s, snd_strerror(err));
+		SNDERR("Unable to set avail min for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
 	/* write the parameters to the playback device */
 	err = snd_pcm_sw_params(pcm, swparams);
 	if (err < 0) {
-		SNDERR("Unable to set sw params for %s: %s", s, snd_strerror(err));
+		SNDERR("Unable to set sw params for %s: %s",
+		       s, snd_strerror(err));
 		return err;
 	}
 	return 0;
-- 
2.7.4

  reply	other threads:[~2016-07-14 14:08 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14 14:07 [alsa-lib][PATCH 00/34] pcm/conf/alisp: replace usage of alloca() with automatic variables Takashi Sakamoto
2016-07-14 14:07 ` Takashi Sakamoto [this message]
2016-07-14 14:07 ` [PATCH 02/34] pcm: remove alloca() from snd_pcm_set_params() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 03/34] pcm: change code formatting for snd_pcm_get_params() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 04/34] pcm: remove alloca() from snd_pcm_get_params Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 05/34] pcm: change code formatting for snd_pcm_direct_initialize_slave() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 06/34] pcm: remove alloca() from snd_pcm_direct_initialize_slave Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 07/34] pcm: change code formatting for snd_pcm_direct_initialize_poll_fd() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 08/34] pcm: remove alloca() from snd_pcm_direct_initialize_poll_fd() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 09/34] pcm: change code formatting for snd_pcm_direct_set_timer_params() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 10/34] pcm: remove alloca() from snd_pcm_direct_set_timer_params Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 11/34] pcm: remove alloca() from _snd_pcm_hook_ctl_elems_install() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 12/34] pcm: change code formatting for snd_pcm_hw_change_timer() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 13/34] pcm: remove alloca() from snd_pcm_hw_change_timer() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 14/34] pcm: remove alloca() from snd_pcm_query_chmaps_from_hw() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 15/34] pcm: remove alloca() from snd_pcm_hw_get_chmap() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 16/34] pcm: remove alloca() from snd_pcm_hw_set_chmap() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 17/34] pcm: remove alloca() from snd_spcm_init() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 18/34] pcm: remove alloca() from snd_spcm_init_duplex() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 19/34] pcm: change code formatting for softvol_load_control() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 20/34] pcm: remove alloca() from softvol_load_control() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 21/34] pcm: change code formatting for _snd_pcm_softvol_open() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 22/34] pcm: remove alloca() from _snd_pcm_softvol_open() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 23/34] conf: remove alloca() from snd_determine_driver() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 24/34] conf: remove alloca() from snd_func_card_id() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 25/34] conf: remove alloca() from snd_func_card_name() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 26/34] conf: remove alloca() from snd_func_pcm_id() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 27/34] conf: remove alloca() from snd_func_pcm_args_by_class() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 28/34] conf: remove alloca() from snd_func_private_pcm_subdevice() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 29/34] alisp: remove alloca() from FA_card_info() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 30/34] alisp: remove alloca() from FA_hctl_find_elem() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 31/34] alisp: remove alloca() from FA_hctl_elem_info() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 32/34] alisp: remove alloca() from FA_hctl_elem_read() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 33/34] alisp: remove alloca() from FA_hctl_elem_write() Takashi Sakamoto
2016-07-14 14:07 ` [PATCH 34/34] alisp: remove alloca() from FA_pcm_info() Takashi Sakamoto
2016-07-14 16:02 ` [alsa-lib][PATCH 00/34] pcm/conf/alisp: replace usage of alloca() with automatic variables Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468505271-5769-2-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.