On 7/19/2024 1:34 AM, Kuninori Morimoto wrote:
Many drivers are using below code to know the direction.
if (direction == SNDRV_PCM_STREAM_PLAYBACK)
Add snd_stream_is_playback/capture() macro to handle it.
It also adds snd_substream_is_playback/capture() to handle
snd_pcm_substream.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>
---
include/sound/pcm.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 3edd7a7346daa..024dc2b337154 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -501,6 +501,25 @@ struct snd_pcm_substream {
#define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
+static inline int snd_stream_is_playback(int stream)
+{
+ return stream == SNDRV_PCM_STREAM_PLAYBACK;
+}
+
+static inline int snd_stream_is_capture(int stream)
+{
+ return stream == SNDRV_PCM_STREAM_CAPTURE;
+}
+
+static inline int snd_substream_is_playback(const struct snd_pcm_substream *substream)
+{
+ return snd_stream_is_playback(substream->stream);
+}
+
+static inline int snd_substream_is_capture(const struct snd_pcm_substream *substream)
+{
+ return snd_stream_is_capture(substream->stream);
+}
struct snd_pcm_str {
int stream; /* stream (direction) */
Perhaps you could use generics here, so you could have one caller for
both cases?
Something like:
#define snd_pcm_is_playback(x) _Generic((x), \
int : (x == SNDRV_PCM_STREAM_PLAYBACK), \
struct snd_pcm_substream *substream * : (x->stream ==
SNDRV_PCM_STREAM_PLAYBACK))(x)
or just call the above functions in it?