[alsa-devel] [PATCH 09/25] ASoC: soc-component: add snd_soc_component_pointer()

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Wed Jul 24 03:52:00 CEST 2019


From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>

Current ALSA SoC is directly using component->driver->ops->xxx,
thus, it is deep nested, and makes code difficult to read,
and is not good for encapsulation.
This patch adds new snd_soc_component_pointer() and use it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc-component.h |  2 ++
 sound/soc/soc-component.c     | 10 ++++++++++
 sound/soc/soc-pcm.c           |  9 +++------
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index 48ef43b..c923d04 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -337,5 +337,7 @@ int snd_soc_component_hw_free(struct snd_soc_component *component,
 int snd_soc_component_trigger(struct snd_soc_component *component,
 			      struct snd_pcm_substream *substream,
 			      int cmd);
+int snd_soc_component_pointer(struct snd_soc_component *component,
+			      struct snd_pcm_substream *substream);
 
 #endif /* __SOC_COMPONENT_H */
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index bb06994..7cb936a 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -347,3 +347,13 @@ int snd_soc_component_trigger(struct snd_soc_component *component,
 
 	return 0;
 }
+
+int snd_soc_component_pointer(struct snd_soc_component *component,
+			      struct snd_pcm_substream *substream)
+{
+	if (component->driver->ops &&
+	    component->driver->ops->pointer)
+		return component->driver->ops->pointer(substream);
+
+	return 0;
+}
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 2a1ef4a..7ab68de 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1115,13 +1115,10 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
 	for_each_rtdcom(rtd, rtdcom) {
 		component = rtdcom->component;
 
-		if (!component->driver->ops ||
-		    !component->driver->ops->pointer)
-			continue;
-
+		offset = snd_soc_component_pointer(component, substream);
 		/* FIXME: use 1st pointer */
-		offset = component->driver->ops->pointer(substream);
-		break;
+		if (offset > 0)
+			break;
 	}
 	/* base delay if assigned in pointer callback */
 	delay = runtime->delay;
-- 
2.7.4



More information about the Alsa-devel mailing list