1*4882a593SmuzhiyunFrom 4bfd1f15114550e1be7e43ae37a61906e1bff809 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
3*4882a593SmuzhiyunDate: Sun, 17 Jul 2022 18:59:48 +0200
4*4882a593SmuzhiyunSubject: [PATCH] alsactl/info.c: fix conditionals on __ALSA_PCM_H and
5*4882a593Smuzhiyun __ALSA_RAWMIDI_H
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunCommit bbc74a61ac7c35e506c3d7f76ecf943cb55736a6 ("alsactl: implement
8*4882a593Smuzhiyun'info' command") implemented an alsactl info command. In this
9*4882a593Smuzhiyunimplementation, there was an attempt to properly address optional
10*4882a593Smuzhiyunfeatures from alsa-lib by using conditions on __ALSA_PCM_H,
11*4882a593Smuzhiyun__ALSA_RAWMIDI_H.
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunUnfortunately, this attempt does not work entirely: only the code
14*4882a593Smuzhiyuninside pcm_device_list(), rawmidi_device_list() was conditionally
15*4882a593Smuzhiyuncompiled, but their very prototype also use type definitions provided
16*4882a593Smuzhiyunin pcm.h and rawmidi.h. So really, it's the entire function that needs
17*4882a593Smuzhiyunto be conditionally implemented.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunAlso, snd_rawmidi_stream_name() was not handled properly, for the same
20*4882a593Smuzhiyunreason.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThis commit implements pcm_device_list() only if __ALSA_PCM_H is
23*4882a593Smuzhiyundefined, and implements snd_rawmidi_stream_name() and
24*4882a593Smuzhiyunrawmidi_device_list() only if __ALSA_RAWMIDI_H is defined.
25*4882a593Smuzhiyun
26*4882a593Smuzhiyungeneral_card_info() is modified to not call the PCM or raw MIDI
27*4882a593Smuzhiyunfunctions when support is not available.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunSigned-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
30*4882a593SmuzhiyunUpstream: https://mailman.alsa-project.org/pipermail/alsa-devel/2022-July/203846.html
31*4882a593Smuzhiyun---
32*4882a593Smuzhiyun alsactl/info.c | 14 ++++++++++----
33*4882a593Smuzhiyun 1 file changed, 10 insertions(+), 4 deletions(-)
34*4882a593Smuzhiyun
35*4882a593Smuzhiyundiff --git a/alsactl/info.c b/alsactl/info.c
36*4882a593Smuzhiyunindex 253539d..9bd72af 100644
37*4882a593Smuzhiyun--- a/alsactl/info.c
38*4882a593Smuzhiyun+++ b/alsactl/info.c
39*4882a593Smuzhiyun@@ -22,9 +22,9 @@
40*4882a593Smuzhiyun #include "aconfig.h"
41*4882a593Smuzhiyun #include "alsactl.h"
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun+#ifdef __ALSA_PCM_H
44*4882a593Smuzhiyun static int pcm_device_list(snd_ctl_t *ctl, snd_pcm_stream_t stream, bool *first)
45*4882a593Smuzhiyun {
46*4882a593Smuzhiyun-#ifdef __ALSA_PCM_H
47*4882a593Smuzhiyun 	int err, dev, idx;
48*4882a593Smuzhiyun 	unsigned int count;
49*4882a593Smuzhiyun 	snd_pcm_info_t *pcminfo;
50*4882a593Smuzhiyun@@ -76,10 +76,12 @@ static int pcm_device_list(snd_ctl_t *ctl, snd_pcm_stream_t stream, bool *first)
51*4882a593Smuzhiyun 						idx, snd_pcm_info_get_subdevice_name(pcminfo));
52*4882a593Smuzhiyun 		}
53*4882a593Smuzhiyun 	}
54*4882a593Smuzhiyun-#endif
55*4882a593Smuzhiyun+
56*4882a593Smuzhiyun 	return 0;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun+#endif
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun+#ifdef __ALSA_RAWMIDI_H
61*4882a593Smuzhiyun static const char *snd_rawmidi_stream_name(snd_rawmidi_stream_t stream)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun 	if (stream == SND_RAWMIDI_STREAM_INPUT)
64*4882a593Smuzhiyun@@ -91,7 +93,6 @@ static const char *snd_rawmidi_stream_name(snd_rawmidi_stream_t stream)
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun static int rawmidi_device_list(snd_ctl_t *ctl, snd_rawmidi_stream_t stream, bool *first)
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun-#ifdef __ALSA_RAWMIDI_H
69*4882a593Smuzhiyun 	int err, dev, idx;
70*4882a593Smuzhiyun 	unsigned int count;
71*4882a593Smuzhiyun 	snd_rawmidi_info_t *info;
72*4882a593Smuzhiyun@@ -143,9 +144,10 @@ static int rawmidi_device_list(snd_ctl_t *ctl, snd_rawmidi_stream_t stream, bool
73*4882a593Smuzhiyun 						idx, snd_rawmidi_info_get_subdevice_name(info));
74*4882a593Smuzhiyun 		}
75*4882a593Smuzhiyun 	}
76*4882a593Smuzhiyun-#endif
77*4882a593Smuzhiyun+
78*4882a593Smuzhiyun 	return 0;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun+#endif
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun static int hwdep_device_list(snd_ctl_t *ctl)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun@@ -227,17 +229,21 @@ int general_card_info(int cardno)
85*4882a593Smuzhiyun 	}
86*4882a593Smuzhiyun 	err = card_info(ctl);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun+#ifdef __ALSA_PCM_H
89*4882a593Smuzhiyun 	first = true;
90*4882a593Smuzhiyun 	if (err >= 0)
91*4882a593Smuzhiyun 		err = pcm_device_list(ctl, SND_PCM_STREAM_PLAYBACK, &first);
92*4882a593Smuzhiyun 	if (err >= 0)
93*4882a593Smuzhiyun 		err = pcm_device_list(ctl, SND_PCM_STREAM_CAPTURE, &first);
94*4882a593Smuzhiyun+#endif
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun+#ifdef __ALSA_RAWMIDI_H
97*4882a593Smuzhiyun 	first = true;
98*4882a593Smuzhiyun 	if (err >= 0)
99*4882a593Smuzhiyun 		err = rawmidi_device_list(ctl, SND_PCM_STREAM_PLAYBACK, &first);
100*4882a593Smuzhiyun 	if (err >= 0)
101*4882a593Smuzhiyun 		err = rawmidi_device_list(ctl, SND_PCM_STREAM_CAPTURE, &first);
102*4882a593Smuzhiyun+#endif
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun 	if (err >= 0)
105*4882a593Smuzhiyun 		err = hwdep_device_list(ctl);
106*4882a593Smuzhiyun--
107*4882a593Smuzhiyun2.36.1
108*4882a593Smuzhiyun
109