mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	Add snd_pcm_hw_params_get/set_export_buffer()
Add snd_pcm_hw_params_get/set_export_buffer() API functions. They control to ensure the buffer export to other processes. If this flag is set, the local buffer of a plugin is exported over IPC shm. Otherwise the buffer can be handled only locally (no shm). Also fixed Version file for 1.0.9.
This commit is contained in:
		
							parent
							
								
									18053076e2
								
							
						
					
					
						commit
						4d7c53d280
					
				
					 7 changed files with 65 additions and 12 deletions
				
			
		| 
						 | 
					@ -585,6 +585,8 @@ int snd_pcm_hw_params_set_rate_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params
 | 
				
			||||||
int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
 | 
					int snd_pcm_hw_params_set_rate_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
 | 
				
			||||||
int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
 | 
					int snd_pcm_hw_params_set_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
 | 
				
			||||||
int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
 | 
					int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
 | 
				
			||||||
 | 
					int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
 | 
				
			||||||
 | 
					int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
 | 
					int snd_pcm_hw_params_get_period_time(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
 | 
				
			||||||
int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
 | 
					int snd_pcm_hw_params_get_period_time_min(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -344,6 +344,7 @@ enum sndrv_pcm_hw_param {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SNDRV_PCM_HW_PARAMS_NORESAMPLE	(1<<0)  /* avoid rate resampling */
 | 
					#define SNDRV_PCM_HW_PARAMS_NORESAMPLE	(1<<0)  /* avoid rate resampling */
 | 
				
			||||||
 | 
					#define SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER	(1<<1)  /* export buffer */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct sndrv_interval {
 | 
					struct sndrv_interval {
 | 
				
			||||||
	unsigned int min, max;
 | 
						unsigned int min, max;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -179,6 +179,8 @@ ALSA_1.0.9 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    snd_pcm_hw_params_set_rate_resample;
 | 
					    snd_pcm_hw_params_set_rate_resample;
 | 
				
			||||||
    snd_pcm_hw_params_get_rate_resample;
 | 
					    snd_pcm_hw_params_get_rate_resample;
 | 
				
			||||||
 | 
					    snd_pcm_hw_params_set_export_buffer;
 | 
				
			||||||
 | 
					    snd_pcm_hw_params_get_export_buffer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    snd_pcm_ioplug_create;
 | 
					    snd_pcm_ioplug_create;
 | 
				
			||||||
    snd_pcm_ioplug_delete;
 | 
					    snd_pcm_ioplug_delete;
 | 
				
			||||||
| 
						 | 
					@ -215,4 +217,4 @@ ALSA_1.0.9 {
 | 
				
			||||||
    snd_timer_ginfo_get_resolution_max;
 | 
					    snd_timer_ginfo_get_resolution_max;
 | 
				
			||||||
    snd_timer_ginfo_get_clients;
 | 
					    snd_timer_ginfo_get_clients;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} ALSA_1.0.5;
 | 
					} ALSA_1.0.8;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3959,6 +3959,36 @@ int snd_pcm_hw_params_get_rate_resample(snd_pcm_t *pcm, snd_pcm_hw_params_t *par
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * \brief Restrict a configuration space to allow the buffer accessible from outside
 | 
				
			||||||
 | 
					 * \param pcm PCM handle
 | 
				
			||||||
 | 
					 * \param params Configuration space
 | 
				
			||||||
 | 
					 * \param val 0 = disable, 1 = enable (default) exporting buffer
 | 
				
			||||||
 | 
					 * \return 0 otherwise a negative error code
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int snd_pcm_hw_params_set_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						assert(pcm && params);
 | 
				
			||||||
 | 
						if (val)
 | 
				
			||||||
 | 
							params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							params->flags &= ~SND_PCM_HW_PARAMS_EXPORT_BUFFER;
 | 
				
			||||||
 | 
						return snd_pcm_hw_refine(pcm, params);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * \brief Extract buffer accessibility from a configuration space
 | 
				
			||||||
 | 
					 * \param pcm PCM handle
 | 
				
			||||||
 | 
					 * \param *val 0 = disable, 1 = enable exporting buffer
 | 
				
			||||||
 | 
					 * \return 0 otherwise a negative error code
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int snd_pcm_hw_params_get_export_buffer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						assert(pcm && params && val);
 | 
				
			||||||
 | 
						*val = params->flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER ? 1 : 0;
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * \brief Extract period time from a configuration space
 | 
					 * \brief Extract period time from a configuration space
 | 
				
			||||||
 * \param params Configuration space
 | 
					 * \param params Configuration space
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,11 +92,8 @@ typedef enum sndrv_pcm_hw_param snd_pcm_hw_param_t;
 | 
				
			||||||
/** device can do a kind of synchronized start */
 | 
					/** device can do a kind of synchronized start */
 | 
				
			||||||
#define SND_PCM_INFO_SYNC_START SNDRV_PCM_INFO_SYNC_START
 | 
					#define SND_PCM_INFO_SYNC_START SNDRV_PCM_INFO_SYNC_START
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef SNDRV_PCM_HW_PARAMS_NORESAMPLE
 | 
					 | 
				
			||||||
#define SND_PCM_HW_PARAMS_NORESAMPLE (1<<0)
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
#define SND_PCM_HW_PARAMS_NORESAMPLE SNDRV_PCM_HW_PARAMS_NORESAMPLE
 | 
					#define SND_PCM_HW_PARAMS_NORESAMPLE SNDRV_PCM_HW_PARAMS_NORESAMPLE
 | 
				
			||||||
#endif
 | 
					#define SND_PCM_HW_PARAMS_EXPORT_BUFFER SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct _snd_pcm_rbptr {
 | 
					typedef struct _snd_pcm_rbptr {
 | 
				
			||||||
	snd_pcm_t *master;
 | 
						snd_pcm_t *master;
 | 
				
			||||||
| 
						 | 
					@ -114,7 +111,7 @@ typedef struct _snd_pcm_channel_info {
 | 
				
			||||||
	void *addr;			/* base address of channel samples */
 | 
						void *addr;			/* base address of channel samples */
 | 
				
			||||||
	unsigned int first;		/* offset to first sample in bits */
 | 
						unsigned int first;		/* offset to first sample in bits */
 | 
				
			||||||
	unsigned int step;		/* samples distance in bits */
 | 
						unsigned int step;		/* samples distance in bits */
 | 
				
			||||||
	enum { SND_PCM_AREA_SHM, SND_PCM_AREA_MMAP } type;
 | 
						enum { SND_PCM_AREA_SHM, SND_PCM_AREA_MMAP, SND_PCM_AREA_LOCAL } type;
 | 
				
			||||||
	union {
 | 
						union {
 | 
				
			||||||
		struct {
 | 
							struct {
 | 
				
			||||||
			struct snd_shm_area *area;
 | 
								struct snd_shm_area *area;
 | 
				
			||||||
| 
						 | 
					@ -214,9 +211,9 @@ struct _snd_pcm {
 | 
				
			||||||
	snd_pcm_rbptr_t appl;
 | 
						snd_pcm_rbptr_t appl;
 | 
				
			||||||
	snd_pcm_rbptr_t hw;
 | 
						snd_pcm_rbptr_t hw;
 | 
				
			||||||
	snd_pcm_uframes_t min_align;
 | 
						snd_pcm_uframes_t min_align;
 | 
				
			||||||
	int mmap_rw: 1,
 | 
						unsigned int mmap_rw: 1;
 | 
				
			||||||
	    mmap_shadow: 1,
 | 
						unsigned int mmap_shadow: 1;
 | 
				
			||||||
	    donot_close: 1;
 | 
						unsigned int donot_close: 1;
 | 
				
			||||||
	snd_pcm_channel_info_t *mmap_channels;
 | 
						snd_pcm_channel_info_t *mmap_channels;
 | 
				
			||||||
	snd_pcm_channel_area_t *running_areas;
 | 
						snd_pcm_channel_area_t *running_areas;
 | 
				
			||||||
	snd_pcm_channel_area_t *stopped_areas;
 | 
						snd_pcm_channel_area_t *stopped_areas;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -285,9 +285,12 @@ int snd_pcm_channel_info_shm(snd_pcm_t *pcm, snd_pcm_channel_info_t *info, int s
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	info->addr = 0;
 | 
						info->addr = 0;
 | 
				
			||||||
	info->type = SND_PCM_AREA_SHM;
 | 
						if (pcm->hw_flags & SND_PCM_HW_PARAMS_EXPORT_BUFFER) {
 | 
				
			||||||
	info->u.shm.shmid = shmid;
 | 
							info->type = SND_PCM_AREA_SHM;
 | 
				
			||||||
	info->u.shm.area = NULL;
 | 
							info->u.shm.shmid = shmid;
 | 
				
			||||||
 | 
							info->u.shm.area = NULL;
 | 
				
			||||||
 | 
						} else
 | 
				
			||||||
 | 
							info->type = SND_PCM_AREA_LOCAL;
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}	
 | 
					}	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -347,6 +350,8 @@ int snd_pcm_mmap(snd_pcm_t *pcm)
 | 
				
			||||||
					if (i1->u.shm.shmid != i->u.shm.shmid)
 | 
										if (i1->u.shm.shmid != i->u.shm.shmid)
 | 
				
			||||||
						continue;
 | 
											continue;
 | 
				
			||||||
					break;
 | 
										break;
 | 
				
			||||||
 | 
									case SND_PCM_AREA_LOCAL:
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
				default:
 | 
									default:
 | 
				
			||||||
					assert(0);
 | 
										assert(0);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -368,6 +373,7 @@ int snd_pcm_mmap(snd_pcm_t *pcm)
 | 
				
			||||||
			case SND_PCM_AREA_SHM:
 | 
								case SND_PCM_AREA_SHM:
 | 
				
			||||||
				if (i->u.shm.shmid < 0) {
 | 
									if (i->u.shm.shmid < 0) {
 | 
				
			||||||
					int id;
 | 
										int id;
 | 
				
			||||||
 | 
										/* FIXME: safer permission? */
 | 
				
			||||||
					id = shmget(IPC_PRIVATE, size, 0666);
 | 
										id = shmget(IPC_PRIVATE, size, 0666);
 | 
				
			||||||
					if (id < 0) {
 | 
										if (id < 0) {
 | 
				
			||||||
						SYSERR("shmget failed");
 | 
											SYSERR("shmget failed");
 | 
				
			||||||
| 
						 | 
					@ -409,6 +415,14 @@ int snd_pcm_mmap(snd_pcm_t *pcm)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				i->addr = ptr;
 | 
									i->addr = ptr;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
								case SND_PCM_AREA_LOCAL:
 | 
				
			||||||
 | 
									ptr = malloc(size);
 | 
				
			||||||
 | 
									if (ptr == NULL) {
 | 
				
			||||||
 | 
										SYSERR("malloc failed");
 | 
				
			||||||
 | 
										return -errno;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									i->addr = ptr;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				assert(0);
 | 
									assert(0);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -427,6 +441,8 @@ int snd_pcm_mmap(snd_pcm_t *pcm)
 | 
				
			||||||
				if (i1->u.shm.shmid != i->u.shm.shmid)
 | 
									if (i1->u.shm.shmid != i->u.shm.shmid)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
								case SND_PCM_AREA_LOCAL:
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				assert(0);
 | 
									assert(0);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -494,6 +510,10 @@ int snd_pcm_munmap(snd_pcm_t *pcm)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
							case SND_PCM_AREA_LOCAL:
 | 
				
			||||||
 | 
								free(i->addr);
 | 
				
			||||||
 | 
								i->addr = NULL;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			assert(0);
 | 
								assert(0);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -288,6 +288,7 @@ static int snd_pcm_shm_hw_params_slave(snd_pcm_t *pcm,
 | 
				
			||||||
	snd_pcm_shm_t *shm = pcm->private_data;
 | 
						snd_pcm_shm_t *shm = pcm->private_data;
 | 
				
			||||||
	volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;
 | 
						volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
						params->flags |= SND_PCM_HW_PARAMS_EXPORT_BUFFER;
 | 
				
			||||||
	ctrl->cmd = SNDRV_PCM_IOCTL_HW_PARAMS;
 | 
						ctrl->cmd = SNDRV_PCM_IOCTL_HW_PARAMS;
 | 
				
			||||||
	ctrl->u.hw_params = *params;
 | 
						ctrl->u.hw_params = *params;
 | 
				
			||||||
	err = snd_pcm_shm_action(pcm);
 | 
						err = snd_pcm_shm_action(pcm);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue