aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2006-04-28 09:13:40 -0400
committerJaroslav Kysela <perex@suse.cz>2006-06-22 15:33:06 -0400
commit2f4ca8e5c7cf6a6f7935483d8ee4aa8b039bdd7d (patch)
treebe79b48cd1d562a17379f0b602034ecacd358446 /sound
parente88e8ae639a4908b903d9406c54e99a729b01a28 (diff)
[ALSA] Clean up ugly hacks in pcm_lib.c
Clean up ugly hacks for sync with alsa-lib code in pcm_lib.c. Also, optimize snd_pcm_hw_params_choose() with a loop. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/core/pcm_lib.c70
1 files changed, 26 insertions, 44 deletions
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 786f88145ee8..a21aa0050e4d 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1163,12 +1163,6 @@ int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
1163 1163
1164EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2); 1164EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);
1165 1165
1166/* To use the same code we have in alsa-lib */
1167#define assert(i) snd_assert((i), return -EINVAL)
1168#ifndef INT_MIN
1169#define INT_MIN ((int)((unsigned int)INT_MAX+1))
1170#endif
1171
1172static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params, 1166static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params,
1173 snd_pcm_hw_param_t var) 1167 snd_pcm_hw_param_t var)
1174{ 1168{
@@ -1228,7 +1222,6 @@ int snd_pcm_hw_param_value(const struct snd_pcm_hw_params *params,
1228 *dir = i->openmin; 1222 *dir = i->openmin;
1229 return snd_interval_value(i); 1223 return snd_interval_value(i);
1230 } 1224 }
1231 assert(0);
1232 return -EINVAL; 1225 return -EINVAL;
1233} 1226}
1234 1227
@@ -1260,10 +1253,8 @@ static int _snd_pcm_hw_param_first(struct snd_pcm_hw_params *params,
1260 changed = snd_mask_refine_first(hw_param_mask(params, var)); 1253 changed = snd_mask_refine_first(hw_param_mask(params, var));
1261 else if (hw_is_interval(var)) 1254 else if (hw_is_interval(var))
1262 changed = snd_interval_refine_first(hw_param_interval(params, var)); 1255 changed = snd_interval_refine_first(hw_param_interval(params, var));
1263 else { 1256 else
1264 assert(0);
1265 return -EINVAL; 1257 return -EINVAL;
1266 }
1267 if (changed) { 1258 if (changed) {
1268 params->cmask |= 1 << var; 1259 params->cmask |= 1 << var;
1269 params->rmask |= 1 << var; 1260 params->rmask |= 1 << var;
@@ -1292,7 +1283,7 @@ int snd_pcm_hw_param_first(struct snd_pcm_substream *pcm,
1292 return changed; 1283 return changed;
1293 if (params->rmask) { 1284 if (params->rmask) {
1294 int err = snd_pcm_hw_refine(pcm, params); 1285 int err = snd_pcm_hw_refine(pcm, params);
1295 assert(err >= 0); 1286 snd_assert(err >= 0, return err);
1296 } 1287 }
1297 return snd_pcm_hw_param_value(params, var, dir); 1288 return snd_pcm_hw_param_value(params, var, dir);
1298} 1289}
@@ -1307,10 +1298,8 @@ static int _snd_pcm_hw_param_last(struct snd_pcm_hw_params *params,
1307 changed = snd_mask_refine_last(hw_param_mask(params, var)); 1298 changed = snd_mask_refine_last(hw_param_mask(params, var));
1308 else if (hw_is_interval(var)) 1299 else if (hw_is_interval(var))
1309 changed = snd_interval_refine_last(hw_param_interval(params, var)); 1300 changed = snd_interval_refine_last(hw_param_interval(params, var));
1310 else { 1301 else
1311 assert(0);
1312 return -EINVAL; 1302 return -EINVAL;
1313 }
1314 if (changed) { 1303 if (changed) {
1315 params->cmask |= 1 << var; 1304 params->cmask |= 1 << var;
1316 params->rmask |= 1 << var; 1305 params->rmask |= 1 << var;
@@ -1339,7 +1328,7 @@ int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm,
1339 return changed; 1328 return changed;
1340 if (params->rmask) { 1329 if (params->rmask) {
1341 int err = snd_pcm_hw_refine(pcm, params); 1330 int err = snd_pcm_hw_refine(pcm, params);
1342 assert(err >= 0); 1331 snd_assert(err >= 0, return err);
1343 } 1332 }
1344 return snd_pcm_hw_param_value(params, var, dir); 1333 return snd_pcm_hw_param_value(params, var, dir);
1345} 1334}
@@ -1356,39 +1345,32 @@ EXPORT_SYMBOL(snd_pcm_hw_param_last);
1356 * first access, first format, first subformat, min channels, 1345 * first access, first format, first subformat, min channels,
1357 * min rate, min period time, max buffer size, min tick time 1346 * min rate, min period time, max buffer size, min tick time
1358 */ 1347 */
1359int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params) 1348int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm,
1360{ 1349 struct snd_pcm_hw_params *params)
1361 int err; 1350{
1362 1351 static int vars[] = {
1363 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_ACCESS, NULL); 1352 SNDRV_PCM_HW_PARAM_ACCESS,
1364 assert(err >= 0); 1353 SNDRV_PCM_HW_PARAM_FORMAT,
1365 1354 SNDRV_PCM_HW_PARAM_SUBFORMAT,
1366 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_FORMAT, NULL); 1355 SNDRV_PCM_HW_PARAM_CHANNELS,
1367 assert(err >= 0); 1356 SNDRV_PCM_HW_PARAM_RATE,
1368 1357 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
1369 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_SUBFORMAT, NULL); 1358 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
1370 assert(err >= 0); 1359 SNDRV_PCM_HW_PARAM_TICK_TIME,
1371 1360 -1
1372 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_CHANNELS, NULL); 1361 };
1373 assert(err >= 0); 1362 int err, *v;
1374
1375 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_RATE, NULL);
1376 assert(err >= 0);
1377
1378 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_PERIOD_TIME, NULL);
1379 assert(err >= 0);
1380
1381 err = snd_pcm_hw_param_last(pcm, params, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, NULL);
1382 assert(err >= 0);
1383
1384 err = snd_pcm_hw_param_first(pcm, params, SNDRV_PCM_HW_PARAM_TICK_TIME, NULL);
1385 assert(err >= 0);
1386 1363
1364 for (v = vars; *v != -1; v++) {
1365 if (*v != SNDRV_PCM_HW_PARAM_BUFFER_SIZE)
1366 err = snd_pcm_hw_param_first(pcm, params, *v, NULL);
1367 else
1368 err = snd_pcm_hw_param_last(pcm, params, *v, NULL);
1369 snd_assert(err >= 0, return err);
1370 }
1387 return 0; 1371 return 0;
1388} 1372}
1389 1373
1390#undef assert
1391
1392static int snd_pcm_lib_ioctl_reset(struct snd_pcm_substream *substream, 1374static int snd_pcm_lib_ioctl_reset(struct snd_pcm_substream *substream,
1393 void *arg) 1375 void *arg)
1394{ 1376{