Skip to contentSkip to conversation

pcm: add mmap_begin callback to snd_pcm_fast_ops_t api

PATCH In review Adam Miartus 1 participant 1 message May 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 pcm: add mmap_begin callback to snd_pcm_fast_ops_t api

main motivation for adding the callback is to use it to enable operation on mmaped buffer before user access for pcm_file plugin

support for MMAP read access with masking by data from input file is not implemented for pcm_file plugin, by adding this callback implementing such feature can be done by rewriting next continuous portion of buffer on each mmap_begin call

plugins like softvol use pcm_plugin interface and overwrite the buffer by looping around it in avail_update callback, this patch hopes to simplify the task by adding new api callback, removing the need for rewriting pcm_file (to use pcm_plugin callbacks) and careful checking when looping around whole mmaped buffer

src/pcm/pcm.c +6 -0
index 3a71d79..323926e 100644
@@ -7129,7 +7129,13 @@ int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
 	snd_pcm_uframes_t f;
 	snd_pcm_uframes_t avail;
 	const snd_pcm_channel_area_t *xareas;
+
 	assert(pcm && areas && offset && frames);
+
+	if (pcm->fast_ops->mmap_begin)
+		return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames);
+
+	/* fallback for plugins that do not specify new callback */
 	xareas = snd_pcm_mmap_areas(pcm);
 	if (xareas == NULL)
 		return -EBADFD;
src/pcm/pcm_dmix.c +1 -0
index 274726e..96049e0 100644
@@ -990,6 +990,7 @@ static const snd_pcm_fast_ops_t snd_pcm_dmix_fast_ops = {
 	.poll_descriptors = snd_pcm_direct_poll_descriptors,
 	.poll_descriptors_count = NULL,
 	.poll_revents = snd_pcm_dmix_poll_revents,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_dshare.c +1 -0
index b75809c..328ef83 100644
@@ -667,6 +667,7 @@ static const snd_pcm_fast_ops_t snd_pcm_dshare_fast_ops = {
 	.poll_descriptors = snd_pcm_direct_poll_descriptors,
 	.poll_descriptors_count = NULL,
 	.poll_revents = snd_pcm_direct_poll_revents,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_dsnoop.c +1 -0
index 58b1e53..5b9d9f5 100644
@@ -544,6 +544,7 @@ static const snd_pcm_fast_ops_t snd_pcm_dsnoop_fast_ops = {
 	.poll_descriptors = snd_pcm_direct_poll_descriptors,
 	.poll_descriptors_count = NULL,
 	.poll_revents = snd_pcm_direct_poll_revents,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_file.c +1 -0
index dcaa41d..10d227b 100644
@@ -773,6 +773,7 @@ static const snd_pcm_fast_ops_t snd_pcm_file_fast_ops = {
 	.poll_descriptors = snd_pcm_generic_poll_descriptors,
 	.poll_revents = snd_pcm_generic_poll_revents,
 	.htimestamp = snd_pcm_generic_htimestamp,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_generic.h +0 -1
index dfbe21a..683e60b 100644
@@ -161,4 +161,3 @@ snd_pcm_chmap_query_t **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm);
 snd_pcm_chmap_t *snd_pcm_generic_get_chmap(snd_pcm_t *pcm);
 int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);
 int snd_pcm_generic_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail);
-
src/pcm/pcm_hooks.c +1 -0
index 4416d36..14396fa 100644
@@ -200,6 +200,7 @@ static const snd_pcm_fast_ops_t snd_pcm_hooks_fast_ops = {
 	.poll_descriptors = snd_pcm_generic_poll_descriptors,
 	.poll_revents = snd_pcm_generic_poll_revents,
 	.may_wait_for_avail_min = snd_pcm_generic_may_wait_for_avail_min,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_hw.c +2 -0
index 91370a8..8ee1d69 100644
@@ -1481,6 +1481,7 @@ static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = {
 	.poll_descriptors = NULL,
 	.poll_descriptors_count = NULL,
 	.poll_revents = NULL,
+	.mmap_begin = NULL,
 };
 
 static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops_timer = {
@@ -1512,6 +1513,7 @@ static const snd_pcm_fast_ops_t snd_pcm_hw_fast_ops_timer = {
 	.poll_descriptors = snd_pcm_hw_poll_descriptors,
 	.poll_descriptors_count = snd_pcm_hw_poll_descriptors_count,
 	.poll_revents = snd_pcm_hw_poll_revents,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_ioplug.c +1 -0
index a437ca3..3e19499 100644
@@ -940,6 +940,7 @@ static const snd_pcm_fast_ops_t snd_pcm_ioplug_fast_ops = {
 	.poll_descriptors_count = snd_pcm_ioplug_poll_descriptors_count,
 	.poll_descriptors = snd_pcm_ioplug_poll_descriptors,
 	.poll_revents = snd_pcm_ioplug_poll_revents,
+	.mmap_begin = NULL,
 };
 
 #endif /* !DOC_HIDDEN */
src/pcm/pcm_local.h +1 -0
index d52229d..d5726eb 100644
@@ -184,6 +184,7 @@ typedef struct {
 	int (*poll_descriptors)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space); /* locked */
 	int (*poll_revents)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents); /* locked */
 	int (*may_wait_for_avail_min)(snd_pcm_t *pcm, snd_pcm_uframes_t avail);
+	int (*mmap_begin)(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames); /* locked */
 } snd_pcm_fast_ops_t;
 
 struct _snd_pcm {
src/pcm/pcm_meter.c +1 -0
index 20b4187..28bb578 100644
@@ -548,6 +548,7 @@ static const snd_pcm_fast_ops_t snd_pcm_meter_fast_ops = {
 	.poll_descriptors = snd_pcm_generic_poll_descriptors,
 	.poll_revents = snd_pcm_generic_poll_revents,
 	.may_wait_for_avail_min = snd_pcm_generic_may_wait_for_avail_min,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_mmap_emul.c +1 -0
index 009cebb..6fa5fe6 100644
@@ -401,6 +401,7 @@ static const snd_pcm_fast_ops_t snd_pcm_mmap_emul_fast_ops = {
 	.poll_descriptors_count = snd_pcm_generic_poll_descriptors_count,
 	.poll_revents = snd_pcm_generic_poll_revents,
 	.may_wait_for_avail_min = snd_pcm_generic_may_wait_for_avail_min,
+	.mmap_begin = NULL,
 };
 
 #ifndef DOC_HIDDEN
src/pcm/pcm_multi.c +1 -0
index 53c414d..069d224 100644
@@ -1042,6 +1042,7 @@ static const snd_pcm_fast_ops_t snd_pcm_multi_fast_ops = {
 	.poll_descriptors = snd_pcm_multi_poll_descriptors,
 	.poll_revents = snd_pcm_multi_poll_revents,
 	.may_wait_for_avail_min = snd_pcm_multi_may_wait_for_avail_min,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_null.c +1 -0
index 1d81548..e6fa049 100644
@@ -361,6 +361,7 @@ static const snd_pcm_fast_ops_t snd_pcm_null_fast_ops = {
 	.avail_update = snd_pcm_null_avail_update,
 	.mmap_commit = snd_pcm_null_mmap_commit,
 	.htimestamp = snd_pcm_generic_real_htimestamp,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_plugin.c +1 -0
index ea60eb9..0714d2c 100644
@@ -646,6 +646,7 @@ const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops = {
 	.poll_descriptors = snd_pcm_generic_poll_descriptors,
 	.poll_revents = snd_pcm_generic_poll_revents,
 	.may_wait_for_avail_min = snd_pcm_plugin_may_wait_for_avail_min,
+	.mmap_begin = NULL,
 };
 
 #endif
src/pcm/pcm_rate.c +1 -0
index 5dc8a92..f29739b 100644
@@ -1217,6 +1217,7 @@ static const snd_pcm_fast_ops_t snd_pcm_rate_fast_ops = {
 	.poll_descriptors = snd_pcm_generic_poll_descriptors,
 	.poll_revents = snd_pcm_rate_poll_revents,
 	.may_wait_for_avail_min = snd_pcm_plugin_may_wait_for_avail_min,
+	.mmap_begin = NULL,
 };
 
 static const snd_pcm_ops_t snd_pcm_rate_ops = {
src/pcm/pcm_share.c +1 -0
index 5a540c4..b803a82 100644
@@ -1346,6 +1346,7 @@ static const snd_pcm_fast_ops_t snd_pcm_share_fast_ops = {
 	.avail_update = snd_pcm_share_avail_update,
 	.htimestamp = snd_pcm_share_htimestamp,
 	.mmap_commit = snd_pcm_share_mmap_commit,
+	.mmap_begin = NULL,
 };
 
 /**
src/pcm/pcm_shm.c +1 -0
index 26a27a5..a18720f 100644
@@ -629,6 +629,7 @@ static const snd_pcm_fast_ops_t snd_pcm_shm_fast_ops = {
 	.avail_update = snd_pcm_shm_avail_update,
 	.mmap_commit = snd_pcm_shm_mmap_commit,
 	.htimestamp = snd_pcm_shm_htimestamp,
+	.mmap_begin = NULL,
 };
 
 static int make_local_socket(const char *filename)
Signature · 1 line
2.7.4