diff mbox series

[001/113] ALSA: add snd_pcm_is_playback/capture() macro

Message ID 8734nj3j0o.wl-kuninori.morimoto.gx@renesas.com
State New
Headers show
Series ALSA: add snd_pcm_is_playback/capture() macro | expand

Commit Message

Kuninori Morimoto Aug. 5, 2024, 12:33 a.m. UTC
Many drivers are using below code to know the direction.

	if (direction == SNDRV_PCM_STREAM_PLAYBACK)

Add snd_pcm_is_playback/capture() macro to handle it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/pcm.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index ac8f3aef92052..69e535aeb8e82 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -502,6 +502,35 @@  struct snd_pcm_substream {
 
 #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
 
+static inline int snd_pcm_direction_is_playback(const int stream)
+{
+	return stream == SNDRV_PCM_STREAM_PLAYBACK;
+}
+
+static inline int snd_pcm_direction_is_capture(const int stream)
+{
+	return stream == SNDRV_PCM_STREAM_CAPTURE;
+}
+
+static inline int snd_pcm_substream_is_playback(const struct snd_pcm_substream *substream)
+{
+	return snd_pcm_direction_is_playback(substream->stream);
+}
+
+static inline int snd_pcm_substream_is_capture(const struct snd_pcm_substream *substream)
+{
+	return snd_pcm_direction_is_capture(substream->stream);
+}
+
+#define snd_pcm_is_playback(x) _Generic((x), \
+	      struct snd_pcm_substream *: snd_pcm_substream_is_playback, \
+	const struct snd_pcm_substream *: snd_pcm_substream_is_playback, \
+	default				: snd_pcm_direction_is_playback)(x)
+
+#define snd_pcm_is_capture(x) _Generic((x), \
+	      struct snd_pcm_substream *: snd_pcm_substream_is_capture, \
+	const struct snd_pcm_substream *: snd_pcm_substream_is_capture, \
+	default				: snd_pcm_direction_is_capture)(x)
 
 struct snd_pcm_str {
 	int stream;				/* stream (direction) */