mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	New PCM model with fragment concept removal and two interrupt sources
Renamed size_t/ssize_t to snd_pcm_sframes_t/snd_pcm_uframes_t
This commit is contained in:
		
							parent
							
								
									7b06e6f762
								
							
						
					
					
						commit
						cc90e32557
					
				
					 29 changed files with 2433 additions and 1906 deletions
				
			
		| 
						 | 
				
			
			@ -50,16 +50,16 @@ typedef struct {
 | 
			
		|||
	int conv_idx;
 | 
			
		||||
	int src_size;
 | 
			
		||||
	int dst_sfmt;
 | 
			
		||||
	size_t ndsts;
 | 
			
		||||
	unsigned int ndsts;
 | 
			
		||||
	ttable_dst_t *dsts;
 | 
			
		||||
} route_params_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef void (*route_f)(const snd_pcm_channel_area_t *src_areas,
 | 
			
		||||
			size_t src_offset,
 | 
			
		||||
			snd_pcm_uframes_t src_offset,
 | 
			
		||||
			const snd_pcm_channel_area_t *dst_area,
 | 
			
		||||
			size_t dst_offset,
 | 
			
		||||
			size_t frames,
 | 
			
		||||
			snd_pcm_uframes_t dst_offset,
 | 
			
		||||
			snd_pcm_uframes_t frames,
 | 
			
		||||
			const ttable_dst_t *ttable,
 | 
			
		||||
			const route_params_t *params);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -88,10 +88,10 @@ typedef struct {
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
static void route1_zero(const snd_pcm_channel_area_t *src_areas ATTRIBUTE_UNUSED,
 | 
			
		||||
			size_t src_offset ATTRIBUTE_UNUSED,
 | 
			
		||||
			snd_pcm_uframes_t src_offset ATTRIBUTE_UNUSED,
 | 
			
		||||
			const snd_pcm_channel_area_t *dst_area,
 | 
			
		||||
			size_t dst_offset,
 | 
			
		||||
			size_t frames,
 | 
			
		||||
			snd_pcm_uframes_t dst_offset,
 | 
			
		||||
			snd_pcm_uframes_t frames,
 | 
			
		||||
			const ttable_dst_t* ttable ATTRIBUTE_UNUSED,
 | 
			
		||||
			const route_params_t *params)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -105,10 +105,10 @@ static void route1_zero(const snd_pcm_channel_area_t *src_areas ATTRIBUTE_UNUSED
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static void route1_one(const snd_pcm_channel_area_t *src_areas,
 | 
			
		||||
		       size_t src_offset,
 | 
			
		||||
		       snd_pcm_uframes_t src_offset,
 | 
			
		||||
		       const snd_pcm_channel_area_t *dst_area,
 | 
			
		||||
		       size_t dst_offset,
 | 
			
		||||
		       size_t frames,
 | 
			
		||||
		       snd_pcm_uframes_t dst_offset,
 | 
			
		||||
		       snd_pcm_uframes_t frames,
 | 
			
		||||
		       const ttable_dst_t* ttable,
 | 
			
		||||
		       const route_params_t *params)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -150,10 +150,10 @@ static void route1_one(const snd_pcm_channel_area_t *src_areas,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static void route1_many(const snd_pcm_channel_area_t *src_areas,
 | 
			
		||||
			size_t src_offset,
 | 
			
		||||
			snd_pcm_uframes_t src_offset,
 | 
			
		||||
			const snd_pcm_channel_area_t *dst_area,
 | 
			
		||||
			size_t dst_offset,
 | 
			
		||||
			size_t frames,
 | 
			
		||||
			snd_pcm_uframes_t dst_offset,
 | 
			
		||||
			snd_pcm_uframes_t frames,
 | 
			
		||||
			const ttable_dst_t* ttable,
 | 
			
		||||
			const route_params_t *params)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -383,14 +383,14 @@ static void route1_many(const snd_pcm_channel_area_t *src_areas,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static void route_transfer(const snd_pcm_channel_area_t *src_areas,
 | 
			
		||||
			   size_t src_offset,
 | 
			
		||||
			   snd_pcm_uframes_t src_offset,
 | 
			
		||||
			   const snd_pcm_channel_area_t *dst_areas,
 | 
			
		||||
			   size_t dst_offset,
 | 
			
		||||
			   size_t dst_channels,
 | 
			
		||||
			   size_t frames,
 | 
			
		||||
			   snd_pcm_uframes_t dst_offset,
 | 
			
		||||
			   snd_pcm_uframes_t dst_channels,
 | 
			
		||||
			   snd_pcm_uframes_t frames,
 | 
			
		||||
			   route_params_t *params)
 | 
			
		||||
{
 | 
			
		||||
	size_t dst_channel;
 | 
			
		||||
	unsigned int dst_channel;
 | 
			
		||||
	ttable_dst_t *dstp;
 | 
			
		||||
	const snd_pcm_channel_area_t *dst_area;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -411,7 +411,7 @@ static int snd_pcm_route_close(snd_pcm_t *pcm)
 | 
			
		|||
	snd_pcm_route_t *route = pcm->private;
 | 
			
		||||
	route_params_t *params = &route->params;
 | 
			
		||||
	int err = 0;
 | 
			
		||||
	size_t dst_channel;
 | 
			
		||||
	unsigned int dst_channel;
 | 
			
		||||
	if (route->plug.close_slave)
 | 
			
		||||
		err = snd_pcm_close(route->plug.slave);
 | 
			
		||||
	if (params->dsts) {
 | 
			
		||||
| 
						 | 
				
			
			@ -430,56 +430,63 @@ static int snd_pcm_route_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
 | 
			
		|||
	snd_pcm_route_t *route = pcm->private;
 | 
			
		||||
	snd_pcm_t *slave = route->plug.slave;
 | 
			
		||||
	int err;
 | 
			
		||||
	unsigned int cmask, lcmask;
 | 
			
		||||
	snd_pcm_hw_params_t sparams;
 | 
			
		||||
	unsigned int links = (SND_PCM_HW_PARBIT_RATE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_FRAGMENTS |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_FRAGMENT_SIZE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_FRAGMENT_LENGTH |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_PERIODS |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_PERIOD_SIZE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_PERIOD_TIME |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_BUFFER_SIZE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_BUFFER_LENGTH);
 | 
			
		||||
			      SND_PCM_HW_PARBIT_BUFFER_TIME |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_TICK_TIME);
 | 
			
		||||
	mask_t *access_mask = alloca(mask_sizeof());
 | 
			
		||||
	mask_t *format_mask = alloca(mask_sizeof());
 | 
			
		||||
	mask_t *saccess_mask = alloca(mask_sizeof());
 | 
			
		||||
	mask_load(access_mask, SND_PCM_ACCBIT_PLUGIN);
 | 
			
		||||
	mask_load(format_mask, SND_PCM_FMTBIT_LINEAR);
 | 
			
		||||
	mask_load(saccess_mask, SND_PCM_ACCBIT_MMAP);
 | 
			
		||||
	err = _snd_pcm_hw_param_mask(params, 1, SND_PCM_HW_PARAM_ACCESS,
 | 
			
		||||
	cmask = params->cmask;
 | 
			
		||||
	params->cmask = 0;
 | 
			
		||||
	err = _snd_pcm_hw_param_mask(params, SND_PCM_HW_PARAM_ACCESS,
 | 
			
		||||
				      access_mask);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	err = _snd_pcm_hw_param_mask(params, 1, SND_PCM_HW_PARAM_FORMAT,
 | 
			
		||||
	err = _snd_pcm_hw_param_mask(params, SND_PCM_HW_PARAM_FORMAT,
 | 
			
		||||
				      format_mask);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	err = _snd_pcm_hw_param_min(params, 1, SND_PCM_HW_PARAM_CHANNELS, 1);
 | 
			
		||||
	err = _snd_pcm_hw_param_min(params, SND_PCM_HW_PARAM_CHANNELS, 1, 0);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	lcmask = params->cmask;
 | 
			
		||||
	params->cmask |= cmask;
 | 
			
		||||
 | 
			
		||||
	_snd_pcm_hw_params_any(&sparams);
 | 
			
		||||
	_snd_pcm_hw_param_mask(&sparams, 0, SND_PCM_HW_PARAM_ACCESS,
 | 
			
		||||
	_snd_pcm_hw_param_mask(&sparams, SND_PCM_HW_PARAM_ACCESS,
 | 
			
		||||
				saccess_mask);
 | 
			
		||||
	if (route->sformat >= 0) {
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, 0, SND_PCM_HW_PARAM_FORMAT,
 | 
			
		||||
				       route->sformat);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, 0, SND_PCM_HW_PARAM_SUBFORMAT,
 | 
			
		||||
				       SND_PCM_SUBFORMAT_STD);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, SND_PCM_HW_PARAM_FORMAT,
 | 
			
		||||
				      route->sformat, 0);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, SND_PCM_HW_PARAM_SUBFORMAT,
 | 
			
		||||
				      SND_PCM_SUBFORMAT_STD, 0);
 | 
			
		||||
	} else
 | 
			
		||||
		links |= (SND_PCM_HW_PARBIT_FORMAT | 
 | 
			
		||||
			  SND_PCM_HW_PARBIT_SUBFORMAT |
 | 
			
		||||
			  SND_PCM_HW_PARBIT_SAMPLE_BITS);
 | 
			
		||||
	if (route->schannels >= 0) {
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, 0, SND_PCM_HW_PARAM_CHANNELS,
 | 
			
		||||
				       route->schannels);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, SND_PCM_HW_PARAM_CHANNELS,
 | 
			
		||||
				      route->schannels, 0);
 | 
			
		||||
	} else {
 | 
			
		||||
		links |= SND_PCM_HW_PARBIT_CHANNELS;
 | 
			
		||||
		if (route->sformat < 0)
 | 
			
		||||
			links |= (SND_PCM_HW_PARBIT_FRAME_BITS |
 | 
			
		||||
				  SND_PCM_HW_PARBIT_FRAGMENT_BYTES |
 | 
			
		||||
				  SND_PCM_HW_PARBIT_PERIOD_BYTES |
 | 
			
		||||
				  SND_PCM_HW_PARBIT_BUFFER_BYTES);
 | 
			
		||||
	}
 | 
			
		||||
		
 | 
			
		||||
	err = snd_pcm_hw_refine2(params, &sparams,
 | 
			
		||||
				 snd_pcm_hw_refine, slave, links);
 | 
			
		||||
				 snd_pcm_generic_hw_link, slave, links);
 | 
			
		||||
	params->cmask |= lcmask;
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	params->info &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
 | 
			
		||||
| 
						 | 
				
			
			@ -492,49 +499,56 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
 | 
			
		|||
	snd_pcm_t *slave = route->plug.slave;
 | 
			
		||||
	int err;
 | 
			
		||||
	snd_pcm_hw_params_t sparams;
 | 
			
		||||
	unsigned int links = (SND_PCM_HW_PARBIT_FRAGMENTS |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_FRAGMENT_SIZE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_FRAGMENT_LENGTH |
 | 
			
		||||
	unsigned int links = (SND_PCM_HW_PARBIT_PERIODS |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_PERIOD_SIZE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_PERIOD_TIME |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_BUFFER_SIZE |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_BUFFER_LENGTH);
 | 
			
		||||
			      SND_PCM_HW_PARBIT_BUFFER_TIME |
 | 
			
		||||
			      SND_PCM_HW_PARBIT_TICK_TIME);
 | 
			
		||||
	unsigned int src_format, dst_format;
 | 
			
		||||
	mask_t *saccess_mask = alloca(mask_sizeof());
 | 
			
		||||
	mask_load(saccess_mask, SND_PCM_ACCBIT_MMAP);
 | 
			
		||||
 | 
			
		||||
	_snd_pcm_hw_params_any(&sparams);
 | 
			
		||||
	_snd_pcm_hw_param_mask(&sparams, 0, SND_PCM_HW_PARAM_ACCESS,
 | 
			
		||||
	_snd_pcm_hw_param_mask(&sparams, SND_PCM_HW_PARAM_ACCESS,
 | 
			
		||||
				saccess_mask);
 | 
			
		||||
	if (route->sformat >= 0) {
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, 0, SND_PCM_HW_PARAM_FORMAT,
 | 
			
		||||
				       route->sformat);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, 0, SND_PCM_HW_PARAM_SUBFORMAT,
 | 
			
		||||
				       SND_PCM_SUBFORMAT_STD);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, SND_PCM_HW_PARAM_FORMAT,
 | 
			
		||||
				      route->sformat, 0);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, SND_PCM_HW_PARAM_SUBFORMAT,
 | 
			
		||||
				      SND_PCM_SUBFORMAT_STD, 0);
 | 
			
		||||
	} else
 | 
			
		||||
		links |= (SND_PCM_HW_PARBIT_FORMAT | 
 | 
			
		||||
			  SND_PCM_HW_PARBIT_SUBFORMAT |
 | 
			
		||||
			  SND_PCM_HW_PARBIT_SAMPLE_BITS);
 | 
			
		||||
	if (route->schannels >= 0) {
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, 0, SND_PCM_HW_PARAM_CHANNELS,
 | 
			
		||||
				      route->schannels);
 | 
			
		||||
		_snd_pcm_hw_param_set(&sparams, SND_PCM_HW_PARAM_CHANNELS,
 | 
			
		||||
				      route->schannels, 0);
 | 
			
		||||
	} else {
 | 
			
		||||
		links |= SND_PCM_HW_PARBIT_CHANNELS;
 | 
			
		||||
		if (route->sformat < 0)
 | 
			
		||||
			links |= (SND_PCM_HW_PARBIT_FRAME_BITS |
 | 
			
		||||
				  SND_PCM_HW_PARBIT_FRAGMENT_BYTES |
 | 
			
		||||
				  SND_PCM_HW_PARBIT_PERIOD_BYTES |
 | 
			
		||||
				  SND_PCM_HW_PARBIT_BUFFER_BYTES);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = snd_pcm_hw_params2(params, &sparams, 
 | 
			
		||||
				 snd_pcm_hw_params, slave, links);
 | 
			
		||||
	err = snd_pcm_hw_params_refine(&sparams, links, params);
 | 
			
		||||
	assert(err >= 0);
 | 
			
		||||
	err = _snd_pcm_hw_refine(&sparams);
 | 
			
		||||
	assert(err >= 0);
 | 
			
		||||
	err = snd_pcm_hw_params(slave, &sparams);
 | 
			
		||||
	params->cmask = 0;
 | 
			
		||||
	sparams.cmask = ~0U;
 | 
			
		||||
	snd_pcm_hw_params_refine(params, links, &sparams);
 | 
			
		||||
	if (err < 0)
 | 
			
		||||
		return err;
 | 
			
		||||
	params->info &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
 | 
			
		||||
	if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
 | 
			
		||||
		src_format = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT);
 | 
			
		||||
		src_format = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0);
 | 
			
		||||
		dst_format = slave->format;
 | 
			
		||||
	} else {
 | 
			
		||||
		src_format = slave->format;
 | 
			
		||||
		dst_format = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT);
 | 
			
		||||
		dst_format = snd_pcm_hw_param_value(params, SND_PCM_HW_PARAM_FORMAT, 0);
 | 
			
		||||
	}
 | 
			
		||||
	route->params.get_idx = get_index(src_format, SND_PCM_FORMAT_U16);
 | 
			
		||||
	route->params.put_idx = put_index(SND_PCM_FORMAT_U32, dst_format);
 | 
			
		||||
| 
						 | 
				
			
			@ -552,28 +566,28 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
 | 
			
		|||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static ssize_t snd_pcm_route_write_areas(snd_pcm_t *pcm,
 | 
			
		||||
static snd_pcm_sframes_t snd_pcm_route_write_areas(snd_pcm_t *pcm,
 | 
			
		||||
					 const snd_pcm_channel_area_t *areas,
 | 
			
		||||
					 size_t offset,
 | 
			
		||||
					 size_t size,
 | 
			
		||||
					 size_t *slave_sizep)
 | 
			
		||||
					 snd_pcm_uframes_t offset,
 | 
			
		||||
					 snd_pcm_uframes_t size,
 | 
			
		||||
					 snd_pcm_uframes_t *slave_sizep)
 | 
			
		||||
{
 | 
			
		||||
	snd_pcm_route_t *route = pcm->private;
 | 
			
		||||
	snd_pcm_t *slave = route->plug.slave;
 | 
			
		||||
	size_t xfer = 0;
 | 
			
		||||
	ssize_t err = 0;
 | 
			
		||||
	snd_pcm_uframes_t xfer = 0;
 | 
			
		||||
	snd_pcm_sframes_t err = 0;
 | 
			
		||||
	if (slave_sizep && *slave_sizep < size)
 | 
			
		||||
		size = *slave_sizep;
 | 
			
		||||
	assert(size > 0);
 | 
			
		||||
	while (xfer < size) {
 | 
			
		||||
		size_t frames = snd_pcm_mmap_playback_xfer(slave, size - xfer);
 | 
			
		||||
		snd_pcm_uframes_t frames = snd_pcm_mmap_playback_xfer(slave, size - xfer);
 | 
			
		||||
		route_transfer(areas, offset, 
 | 
			
		||||
			       snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
 | 
			
		||||
			       slave->channels, frames, &route->params);
 | 
			
		||||
		err = snd_pcm_mmap_forward(slave, frames);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			break;
 | 
			
		||||
		assert((size_t)err == frames);
 | 
			
		||||
		assert((snd_pcm_uframes_t)err == frames);
 | 
			
		||||
		offset += err;
 | 
			
		||||
		xfer += err;
 | 
			
		||||
		snd_pcm_mmap_hw_forward(pcm, err);
 | 
			
		||||
| 
						 | 
				
			
			@ -586,28 +600,28 @@ static ssize_t snd_pcm_route_write_areas(snd_pcm_t *pcm,
 | 
			
		|||
	return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static ssize_t snd_pcm_route_read_areas(snd_pcm_t *pcm,
 | 
			
		||||
static snd_pcm_sframes_t snd_pcm_route_read_areas(snd_pcm_t *pcm,
 | 
			
		||||
					 const snd_pcm_channel_area_t *areas,
 | 
			
		||||
					 size_t offset,
 | 
			
		||||
					 size_t size,
 | 
			
		||||
					 size_t *slave_sizep)
 | 
			
		||||
					 snd_pcm_uframes_t offset,
 | 
			
		||||
					 snd_pcm_uframes_t size,
 | 
			
		||||
					 snd_pcm_uframes_t *slave_sizep)
 | 
			
		||||
{
 | 
			
		||||
	snd_pcm_route_t *route = pcm->private;
 | 
			
		||||
	snd_pcm_t *slave = route->plug.slave;
 | 
			
		||||
	size_t xfer = 0;
 | 
			
		||||
	ssize_t err = 0;
 | 
			
		||||
	snd_pcm_uframes_t xfer = 0;
 | 
			
		||||
	snd_pcm_sframes_t err = 0;
 | 
			
		||||
	if (slave_sizep && *slave_sizep < size)
 | 
			
		||||
		size = *slave_sizep;
 | 
			
		||||
	assert(size > 0);
 | 
			
		||||
	while (xfer < size) {
 | 
			
		||||
		size_t frames = snd_pcm_mmap_capture_xfer(slave, size - xfer);
 | 
			
		||||
		snd_pcm_uframes_t frames = snd_pcm_mmap_capture_xfer(slave, size - xfer);
 | 
			
		||||
		route_transfer(snd_pcm_mmap_areas(slave), snd_pcm_mmap_offset(slave),
 | 
			
		||||
			       areas, offset, 
 | 
			
		||||
			       pcm->channels, frames, &route->params);
 | 
			
		||||
		err = snd_pcm_mmap_forward(slave, frames);
 | 
			
		||||
		if (err < 0)
 | 
			
		||||
			break;
 | 
			
		||||
		assert((size_t)err == frames);
 | 
			
		||||
		assert((snd_pcm_uframes_t)err == frames);
 | 
			
		||||
		offset += err;
 | 
			
		||||
		xfer += err;
 | 
			
		||||
		snd_pcm_mmap_hw_forward(pcm, err);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue