sw_params->avail_min = 1; 
sw_params->avail_min = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : runtime->period_size; 
static int snd_pcm_oss_change_params(snd_pcm_substream_t *substream){	snd_pcm_runtime_t *runtime = substream->runtime;	snd_pcm_hw_params_t *params, *sparams;	snd_pcm_sw_params_t *sw_params;	ssize_t oss_buffer_size, oss_period_size;	size_t oss_frame_size;	int err;	int direct;	int format, sformat, n;	snd_mask_t sformat_mask;	snd_mask_t mask;	sw_params = kmalloc(sizeof(*sw_params), GFP_KERNEL);	params = kmalloc(sizeof(*params), GFP_KERNEL);	sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);	if (!sw_params || !params || !sparams) {		snd_printd("No memory\n");		err = -ENOMEM;		goto failure;	}	if (atomic_read(&runtime->mmap_count)) {		direct = 1;	} else {		snd_pcm_oss_setup_t *setup = substream->oss.setup;		direct = (setup != NULL && setup->direct);	}	_snd_pcm_hw_params_any(sparams);	_snd_pcm_hw_param_setinteger(sparams, SNDRV_PCM_HW_PARAM_PERIODS);	_snd_pcm_hw_param_min(sparams, SNDRV_PCM_HW_PARAM_PERIODS, 2, 0);	snd_mask_none(&mask);	if (atomic_read(&runtime->mmap_count))		snd_mask_set(&mask, SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);	else {		snd_mask_set(&mask, SNDRV_PCM_ACCESS_RW_INTERLEAVED);		if (!direct)			snd_mask_set(&mask, SNDRV_PCM_ACCESS_RW_NONINTERLEAVED);	}	err = snd_pcm_hw_param_mask(substream, sparams, SNDRV_PCM_HW_PARAM_ACCESS, &mask);	if (err < 0) {		snd_printd("No usable accesses\n");		err = -EINVAL;		goto failure;	}	choose_rate(substream, sparams, runtime->oss.rate);	snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_CHANNELS, runtime->oss.channels, NULL);	format = snd_pcm_oss_format_from(runtime->oss.format);	sformat_mask = *hw_param_mask(sparams, SNDRV_PCM_HW_PARAM_FORMAT);	if (direct)		sformat = format;	else		sformat = snd_pcm_plug_slave_format(format, &sformat_mask);	if (sformat < 0 || !snd_mask_test(&sformat_mask, sformat)) {		for (sformat = 0; sformat <= SNDRV_PCM_FORMAT_LAST; sformat++) {			if (snd_mask_test(&sformat_mask, sformat) &&			    snd_pcm_oss_format_to(sformat) >= 0)				break;		}		if (sformat > SNDRV_PCM_FORMAT_LAST) {			snd_printd("Cannot find a format!!!\n");			err = -EINVAL;			goto failure;		}	}	err = _snd_pcm_hw_param_set(sparams, SNDRV_PCM_HW_PARAM_FORMAT, sformat, 0);	snd_assert(err >= 0, goto failure);	if (direct) {		memcpy(params, sparams, sizeof(*params));	} else {		_snd_pcm_hw_params_any(params);		_snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_ACCESS,				      SNDRV_PCM_ACCESS_RW_INTERLEAVED, 0);		_snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_FORMAT,				      snd_pcm_oss_format_from(runtime->oss.format), 0);		_snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_CHANNELS,				      runtime->oss.channels, 0);		_snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_RATE,				      runtime->oss.rate, 0);		pdprintf("client: access = %i, format = %i, channels = %i, rate = %i\n",			 params_access(params), params_format(params),			 params_channels(params), params_rate(params));	}	pdprintf("slave: access = %i, format = %i, channels = %i, rate = %i\n",		 params_access(sparams), params_format(sparams),		 params_channels(sparams), params_rate(sparams));	oss_frame_size = snd_pcm_format_physical_width(params_format(params)) *			 params_channels(params) / 8;	snd_pcm_oss_plugin_clear(substream);	if (!direct) {		/* add necessary plugins */		snd_pcm_oss_plugin_clear(substream);		if ((err = snd_pcm_plug_format_plugins(substream,						       params, 						       sparams)) < 0) {			snd_printd("snd_pcm_plug_format_plugins failed: %i\n", err);			snd_pcm_oss_plugin_clear(substream);			goto failure;		}		if (runtime->oss.plugin_first) {			snd_pcm_plugin_t *plugin;			if ((err = snd_pcm_plugin_build_io(substream, sparams, &plugin)) < 0) {				snd_printd("snd_pcm_plugin_build_io failed: %i\n", err);				snd_pcm_oss_plugin_clear(substream);				goto failure;			}			if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {				err = snd_pcm_plugin_append(plugin);			} else {				err = snd_pcm_plugin_insert(plugin);			}			if (err < 0) {				snd_pcm_oss_plugin_clear(substream);				goto failure;			}		}	}	err = snd_pcm_oss_period_size(substream, params, sparams);	if (err < 0)		goto failure;	n = snd_pcm_plug_slave_size(substream, runtime->oss.period_bytes / oss_frame_size);	err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, n, NULL);	snd_assert(err >= 0, goto failure);	err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIODS,				     runtime->oss.periods, NULL);	snd_assert(err >= 0, goto failure);	snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);	if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams)) < 0) {		snd_printd("HW_PARAMS failed: %i\n", err);		goto failure;	}	memset(sw_params, 0, sizeof(*sw_params));	if (runtime->oss.trigger) {		sw_params->start_threshold = 1;	} else {		sw_params->start_threshold = runtime->boundary;	}	if (atomic_read(&runtime->mmap_count) || substream->stream == SNDRV_PCM_STREAM_CAPTURE)		sw_params->stop_threshold = runtime->boundary;	else		sw_params->stop_threshold = runtime->buffer_size;	sw_params->tstamp_mode = SNDRV_PCM_TSTAMP_NONE;	sw_params->period_step = 1;	sw_params->sleep_min = 0;	sw_params->avail_min = 1;	sw_params->xfer_align = 1;	if (atomic_read(&runtime->mmap_count) ||	    (substream->oss.setup && substream->oss.setup->nosilence)) {		sw_params->silence_threshold = 0;		sw_params->silence_size = 0;	} else {		snd_pcm_uframes_t frames;		frames = runtime->period_size + 16;		if (frames > runtime->buffer_size)			frames = runtime->buffer_size;		sw_params->silence_threshold = frames;		sw_params->silence_size = frames;	}	if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_SW_PARAMS, sw_params)) < 0) {		snd_printd("SW_PARAMS failed: %i\n", err);		goto failure;	}	runtime->oss.periods = params_periods(sparams);	oss_period_size = snd_pcm_plug_client_size(substream, params_period_size(sparams));	snd_assert(oss_period_size >= 0, err = -EINVAL; goto failure);	if (runtime->oss.plugin_first) {		err = snd_pcm_plug_alloc(substream, oss_period_size);		if (err < 0)			goto failure;	}	oss_period_size *= oss_frame_size;	oss_buffer_size = oss_period_size * runtime->oss.periods;	snd_assert(oss_buffer_size >= 0, err = -EINVAL; goto failure);	runtime->oss.period_bytes = oss_period_size;	runtime->oss.buffer_bytes = oss_buffer_size;	pdprintf("oss: period bytes = %i, buffer bytes = %i\n",		 runtime->oss.period_bytes,		 runtime->oss.buffer_bytes);	pdprintf("slave: period_size = %i, buffer_size = %i\n",		 params_period_size(sparams),		 params_buffer_size(sparams));	runtime->oss.format = snd_pcm_oss_format_to(params_format(params));	runtime->oss.channels = params_channels(params);	runtime->oss.rate = params_rate(params);	runtime->oss.params = 0;	runtime->oss.prepare = 1;	vfree(runtime->oss.buffer);	runtime->oss.buffer = vmalloc(runtime->oss.period_bytes);	runtime->oss.buffer_used = 0;	if (runtime->dma_area)		snd_pcm_format_set_silence(runtime->format, runtime->dma_area, bytes_to_samples(runtime, runtime->dma_bytes));	runtime->oss.period_frames = snd_pcm_alsa_frames(substream, oss_period_size);	err = 0;failure:	kfree(sw_params);	kfree(params);	kfree(sparams);	return err;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/004e65389714721ce0f52a8f0fc22999d3908a2a/pcm_oss.c/clean/sound/core/oss/pcm_oss.c